LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-21-2015, 02:28 PM   #16
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309

Quote:
The program does in fact work, the problem is in getting the input line to go through without being messed with by bash.
If that's correct, then it's easy to investigate. Have the assembly language program print out the arguments passed to it. Then you know what it expects and what it's getting instead.

Last edited by dugan; 05-21-2015 at 03:02 PM.
 
1 members found this post helpful.
Old 05-21-2015, 02:34 PM   #17
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by billvance View Post
At least the string is getting through now, but I wish I could get rid of the, "dumps".
It sounds like it was always getting through, but the NAddr program had (and still has) some bugs. I think the rest of the script is just a distraction. You should focus on testing NAddr by itself.

Code:
# run these and check that the output is what you expect
./NAddr 'a-string'
./NAddr 'a string with spaces'
./NAddr '<an-angle-bracket-enclosed-string>'
./NAddr 'a string with space <and angle brackets>'
# etc etc
 
1 members found this post helpful.
Old 05-21-2015, 03:21 PM   #18
billvance
Member
 
Registered: Sep 2013
Location: Bothell, Washington USA
Distribution: Kubuntu 12.04
Posts: 60

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
It sounds like it was always getting through, but the NAddr program had (and still has) some bugs.
Not allways. The redirection problem was apparently just the top layer.

Quote:
Originally Posted by ntubski View Post

I think the rest of the script is just a distraction. You should focus on testing NAddr by itself.
Perhaps, though as you and the others have pointed out, it was up for a little fine tuning.

Quote:
Originally Posted by ntubski View Post
Code:
# run these and check that the output is what you expect
./NAddr 'a-string'
./NAddr 'a string with spaces'
./NAddr '<an-angle-bracket-enclosed-string>'
./NAddr 'a string with space <and angle brackets>'
# etc etc
Ok, I'll get on it. Gotta go get some groceries right now though. I'll try to get back to it in a few hours. Thanks everyone for helping to clarify the situation.

Bill
 
Old 05-21-2015, 03:27 PM   #19
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by billvance View Post
Not allways. The redirection problem was apparently just the top layer.
Bash doesn't interpret redirection characters inside variables, there have been lots of threads started by people who expected it to. So my guess is, you just misinterpreted the error message. Since you declined to share the error message, we can't say for sure...
 
1 members found this post helpful.
Old 05-22-2015, 12:23 AM   #20
billvance
Member
 
Registered: Sep 2013
Location: Bothell, Washington USA
Distribution: Kubuntu 12.04
Posts: 60

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
Bash doesn't interpret redirection characters inside variables, there have been lots of threads started by people who expected it to. So my guess is, you just misinterpreted the error message. Since you declined to share the error message, we can't say for sure...
Really? There have only been two. Hows, "Error near unexpected newline", grab ya? The other you've allready seen.
 
Old 05-22-2015, 12:29 AM   #21
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Read this: http://www.catb.org/esr/faqs/smart-questions.html
 
1 members found this post helpful.
Old 05-22-2015, 07:25 AM   #22
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by billvance View Post
Hows, "Error near unexpected newline", grab ya?
Doesn't sound like a redirection problem. Is that the whole message? Usually there is prefix indicating which program and line number it's from, eg: "bash: line 42: Error near unexpected newline". Though perhaps the message is from msmtp, indicating that NAddr added a newline to its output (and therefore the $To variable).
 
1 members found this post helpful.
Old 05-22-2015, 09:15 AM   #23
billvance
Member
 
Registered: Sep 2013
Location: Bothell, Washington USA
Distribution: Kubuntu 12.04
Posts: 60

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
Doesn't sound like a redirection problem. Is that the whole message? Usually there is prefix indicating which program and line number it's from, eg: "bash: line 42: Error near unexpected newline". Though perhaps the message is from msmtp, indicating that NAddr added a newline to its output (and therefore the $To variable).
Nope, just, "Error near unexpected newline", and nothing else.

NAddr only outputs a newline after the string is printed out. It wasn't printed when these errors occured.
 
Old 05-22-2015, 05:58 PM   #24
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by billvance View Post
Possibly, but I was trying to do a solution that would _allways_ work, regardless of what mailer I might wind up playing with, and whatever characteristics they might have in their output.
So, is that why you wrote 60 lines of code in assembly, whose sole purpose is to print the argument that starts with '<' and which segfaults whenever called with

a/ no argument
b/ arguments none of which starts with '<'
c/ arguments one of which starts with '<' but doesn't contain the closing '>'
d/ arguments that start with '<' but is longer than 127 bytes

How about
Code:
To="${ToParm#*<}"; To="<${To%>*}>"
 
1 members found this post helpful.
Old 05-23-2015, 01:06 AM   #25
billvance
Member
 
Registered: Sep 2013
Location: Bothell, Washington USA
Distribution: Kubuntu 12.04
Posts: 60

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by millgates View Post
So, is that why you wrote 60 lines of code in assembly,
Actually, its closer to 30 lines of code, not counting labels, comments, and linefeeds. I also wrote it as an exercise in dealling with cli parameters in future programming. Whats your problem with assembly?

Quote:
Originally Posted by millgates View Post
starts with '<' and which segfaults whenever called with

a/ no argument
b/ arguments none of which starts with '<'
c/ arguments one of which starts with '<' but doesn't contain the closing '>'
d/ arguments that start with '<' but is longer than 127 bytes
Well, it's apparently down to that one error, which
is a deal better than anyone can do in C. C is a language in which a single typo generates 60,000 pages of arcane, indecipherable, error messages.


Quote:
Originally Posted by millgates View Post
How about
Code:
To="${ToParm#*<}"; To="<${To>*}>"
Now that's interesting. How does that work?

Last edited by billvance; 05-23-2015 at 03:25 AM.
 
Old 05-23-2015, 04:03 AM   #26
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by billvance View Post
I also wrote it as an exercise in dealling with cli parameters in future programming. Whats your problem with assembly?
OK, if you do it for sake of practice, it's OK. There's no problem with assembly, it's just that it's really not the best tool for this job. Neither is C, actually.
This is a simple string manipulation which is exactly what the command line utilities like grep, sed, and awk were designed for. This one is even simple enough to be done directly in bash with builtin string manipulations, avoiding the need to execute external programs. The problem with your code is that it expects very specific input and crashes when it gets anything else. You loop over command line arguments but you discard argc and don't check whether you have reached the end of argv. You loop over the string until you find '>', but you don't check for a null char terminating the string.

Quote:
Originally Posted by billvance View Post
Well, it's apparently down to that one error, which is a deal better than anyone can do in C. C is a language in which a single typo generates 60,000 pages of arcane, indecipherable, error messages.
If you're referring to the gcc compiler messages then yes, they have a tendency to be slightly cryptic sometimes (especially to people new to C), but I don't think debugging C code is more difficult than debugging assembly, especially when it's somebody else's code.


Quote:
Originally Posted by billvance View Post
Now that's interesting. How does that work?
Those are bash builtin string manipulations.
${varname#expr} removes expr form the beginning of the string
${varname##expr} does the same thing but is greedy.
Analogically,
${varname%expr} removes expr from the end of the string
${varname%%expr} is the greedy variant.
 
1 members found this post helpful.
Old 05-23-2015, 11:48 AM   #27
billvance
Member
 
Registered: Sep 2013
Location: Bothell, Washington USA
Distribution: Kubuntu 12.04
Posts: 60

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by millgates View Post
OK, if you do it for sake of practice, it's OK. There's no problem with assembly, it's just that it's really not the best tool for this job. Neither is C, actually.
This is a simple string manipulation which is exactly what the command line utilities like grep, sed, and awk were designed for. This one is even simple enough to be done directly in bash with builtin string manipulations, avoiding the need to execute external programs. The problem with your code is that it expects very specific input and crashes when it gets anything else. You loop over command line arguments but you discard argc and don't check whether you have reached the end of argv. You loop over the string until you find '>', but you don't check for a null char terminating the string.
In this particular instance, I've only been interested in getting one exact kind of parameter.
Once it's been found, there's no point in sticking around. That being said, NAddr is allready several versions along from where it was. It still needs work, but no longer seg faults.

Quote:
Originally Posted by millgates View Post

If you're referring to the gcc compiler messages then yes, they have a tendency to be slightly cryptic sometimes (especially to people new to C), but I don't think debugging C code is more difficult than debugging assembly, especially when it's somebody else's code.
In my case, C represents a long term, many versions, on many machines, nightmare, complete with many iterations of the quest for the non-existant dependencies. I refuse to go beyond, ./configure && make && make install. C stands for Cuneiform. I'll program in _sanscrit_ before I program in C.

Quote:
Originally Posted by millgates View Post

Those are bash builtin string manipulations.
${varname#expr} removes expr form the beginning of the string
${varname##expr} does the same thing but is greedy.
Analogically,
${varname%expr} removes expr from the end of the string
${varname%%expr} is the greedy variant.
Bash really can do some amazing things.
 
Old 05-23-2015, 06:42 PM   #28
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
Quote:
Originally Posted by billvance View Post

Code:
GetParam:
   pop     ecx           ; $2, now we can go to work
   mov     esi,ecx       ; put string starting addr in esi
                         ; (source index)
   mov     edi,storage   ; put output addr in edi, (destination
                         ; index)
   cld                   ; clr direction flag for incrementing
   lodsb                 ; mov contents of esi (source index) addr
                         ; to eax (accumulator) and increment esi
   stosb                 ; Put char in addr pointed to by edi,
                         ; (destination index) i.e. "storage" and
                         ; increment addr in edi
   cmp     eax,60        ; is it a, "<", enclosure char
   jne     GetParam      ; if not, get next cli parameter
Bill
popping ecx repeatedly inside a loop w/o a corresponding push is bound to goof up your stack, i think
 
1 members found this post helpful.
Old 05-24-2015, 02:56 AM   #29
billvance
Member
 
Registered: Sep 2013
Location: Bothell, Washington USA
Distribution: Kubuntu 12.04
Posts: 60

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by millgates View Post
OK, if you do it for sake of practice, it's OK. There's no problem with assembly, it's just that it's really not the best tool for this job. Neither is C, actually.
This is a simple string manipulation which is exactly what the command line utilities like grep, sed, and awk were designed for. This one is even simple enough to be done directly in bash with builtin string manipulations, avoiding the need to execute external programs. The problem with your code is that it expects very specific input and crashes when it gets anything else. You loop over command line arguments but you discard argc and don't check whether you have reached the end of argv. You loop over the string until you find '>', but you don't check for a null char terminating the string.



If you're referring to the gcc compiler messages then yes, they have a tendency to be slightly cryptic sometimes (especially to people new to C), but I don't think debugging C code is more difficult than debugging assembly, especially when it's somebody else's code.




Those are bash builtin string manipulations.
${varname#expr} removes expr form the beginning of the string
${varname##expr} does the same thing but is greedy.
Analogically,
${varname%expr} removes expr from the end of the string
${varname%%expr} is the greedy variant.
Thanks, Millgates, That really does the trick. Thanks, as well to everyone who has helped to get NAddr into more workable shape. I'll keep working on it, but for now, I'll declare it, tentatively at least, solved. Thanks again.

Bill
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Search string on pattern of special characters Bash rbees Programming 10 03-23-2015 04:59 PM
[SOLVED] Bash - escape all special characters in variable string? arashi256 Linux - Newbie 10 01-23-2012 09:43 AM
[SOLVED] Remove special characters from a string ajeesh.tr Programming 2 01-31-2011 12:12 AM
search and replace string having multiple special characters say_hi_ravi Linux - Newbie 4 08-26-2009 07:43 AM
bash command for removing special characters from string kkpal Linux - Newbie 5 05-26-2008 08:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration