Source language: Translate to:

Dealing with exclamation points in text variables

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Dealing with exclamation points in text variables

Postby Enigman » Fri Feb 24, 2012 6:44 pm

I am writing a large scale encryption program in NB 5.7.1

I am having a lot of difficulty when it comes to reading and manipulating exclamation points that occur in a text variable. For example, the SearchStr action will not find the exclamation point in the text. The following command appears in a loop that counts through ascii numbers, where [iter] is the current ascii number:

SearchStr "[#[iter]]" "[message]" "[offset]" "CaseSensitive"

... it always returns "0" in the offset when [iter] = 33, the ascii equivalent of the "!". If I add an exclamation point in the command, like this:

SearchStr "![#[iter]]" "[message]" "[offset]" "CaseSensitive"

... then it returns the true offset.

This apparently afflicts many other action commands to the point that I cannot figure out all the places that I need to embed a "!" in a variable definition.

The commands I need to work most are StrDel, StrIns, SetVar, SearchStr and other string manipulators. I need to push and pull the entire ascii character set from variable to variable.

Does anyone know a workaround for correctly manipulating exclamation points that occur inside variables?

Thanks.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Try this

Postby virger » Fri Feb 24, 2012 9:48 pm

setvar "[bs]" "![#33]"
SearchStr "![bs]" "Hi! From !Costa Rica!" "[ps]" "CaseSensitive"

PURA VIDA
User avatar
virger
 
Posts: 518
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Postby Enigman » Fri Feb 24, 2012 10:10 pm

Thank you.

Yes, I am aware of the fix for SetVar and SearchStr, but my issue is with the other action commands for string manipulation. I am exclusively using ascii values to obtain characters and push characters.

For example, I might have a loop running from 32 through 255 and then use the current iteration to extract the text value of something like [#[iter]]. All the characters can be dealt with normally except the exclamation point.

I also do reverse comparisons where I loop through all characters in a variable and then determine the ascii value of each. Exclamation points act up in that case also.

It would seem that all the other string actions have issues with the exclamation, but I cannot be certain without knowing which parameters of which action react to the exclamation.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Postby Gaev » Sat Feb 25, 2012 7:18 am

Enigman:

The Exclamation character is not associated with any particular NeoBook command ... rather, it can be used at the start of any parameter (of any command) as a 'directive to the command interpreter' to tell it NOT to perform any kind of math (or other expression resolution) on the specified parameter text ... i.e. to accept the parameter string AS IS.

See my detailed explanation of it here ... http://www.scriptedlogic.com/neoTIP1.htm.

Of course, since the 'method used to so direct the command interpreter' is to 'place an Exclamation character at the start of the parameter string' ... how does one accomodate situations where the Exclamation point happens to be the first letter of the parameter value ? ... just like with 'escape codes used in other languages', you place two Exclamation characters e.g. ...
Code: Select all
AlertBox "!!! OMG OMG OMG !!" "NeoBook Rocks !!!"
... which will display ...

- the title as !! OMG OMG OMG !! ... notice that it only displays two Exclamation characters at the start

- the message as NeoBook Rocks !!! ... starting Exclamation character was not needed in the parameter

Since you are iterating through the visible ascii character set (including the Exclamation character ... and math operatives like plus, minus, multiply, divide and others) ... you should place the additional Exclamation character in every parameter where such characters are a possibility.

As mentioned on my website ... when in doubt, use the ! character.


Hope that clears up things.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Enigman » Sat Feb 25, 2012 10:43 am

Gaev,

Thanks for the details.

Actually, before I wrote the original post I went though the commands in my code and added the ! to the front of the parameters of all concerned commands. Oddly, it actually made the problem worse.

Before that, the program would read the input file and the program would end up ignoring the ! characters as if they never existed. The program goes through the input and accumulates a list of all characters used in the input, then it randomizes the list order. Here is where the problem came in after adding the ! to all parameters. The ! now appears in the list, but the randomized list always had a length mismatch compared to the non-randomized list. The randomizer reads the character list and uses combinations of StrDel and StrIns to push the characters into another list in random locations until all characters have been placed. So I figured that StrDel or StrIns might have "other issues" when it comes to the !.

I backed out all the !'s from the parameters and it runs fine again, but ignores the existence of the ! in the input text.

Soooo... I'll go back to the randomizer code and see if I can find another reason for the mis-processing of the !

Thanks again for the pointers.

By the way, looking at your applications, ... have you found a way to do binary file writes? I always thought only plain text writes could be done from NB.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Postby Gaev » Sat Feb 25, 2012 3:32 pm

Enigman:
Soooo... I'll go back to the randomizer code and see if I can find another reason for the mis-processing of the !
Why don't you post the code you are using.
By the way, looking at your applications, ... have you found a way to do binary file writes? I always thought only plain text writes could be done from NB.
Yes, my understanding is that the FileWrite command was not designed to handle all binary characters ... and I have never had a need to do this ... but you could check if 'there is a Plugin for that' (hope iApple doesn't sue me for using that phrase) ... if there isn't, I am sure dec can whip one up in a few hours :-)
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby dec » Sat Feb 25, 2012 3:41 pm

Hi there,

Gaev wrote:[...] if there isn't, I am sure dec can whip one up in a few hours :-)


In two minutes! Joking apart... maybe Dave can say if can be possible, since NeoBook don't have a "binary type" in order to be write on a file or else where. But maybe it's possible... (I can't imagine now) ever when Gaev have reason when say this is not a common needed.
.
Enhance your NeoBook applications!
.
58 plugins, 1131 actions and 233 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Postby Gaev » Sat Feb 25, 2012 4:54 pm

dec:
(I can't imagine now) ever when Gaev have reason when say this is not a common needed.
I didn't say others don't need it ... just that the type of Apps I developed did not need it ... so I have no idea if the FileRead/FileWrite commands will/will not work (all the time).
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby dec » Sat Feb 25, 2012 5:04 pm

Hi Gaev,

I say the same thing that you: is not a thing I need on my own applications nor plugins. But anyway, I can't imagine how to deal with binary data if cannot have a binary type. In other words, you have strings, integers, arrays variables, and can deal with it. But if you not have a binary type variable, I cannot imagine how to deal with binary data. But I believe Dave can surprise us another time. :)
.
Enhance your NeoBook applications!
.
58 plugins, 1131 actions and 233 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Postby Enigman » Sat Feb 25, 2012 5:24 pm

Gaev and Dec,

I asked about binary data because it looked like one of Gaev's apps wrote out image files, and they are usually binary only.

I just remembered that NB has a screen capture function, though.

On the original topic, I am still debugging the exclamation issue and making some headway, but I have discovered that the only place you can put the ! in action commands is on the input variable, Actions command always have one parameter that is for input. The rest are counts, offsets, or output variables. For example in the SetVar command in various forms:

SetVar "[char]" "[#[count]]" - Where [count] = 33, [char] is null

SetVar "[char]" "![#[count]]" - Where [count] = 33, [char] = !

SetVar "![char]" "![#[count]]" - Where [count] is anything, [char] is null

The next thing I learned is that action commands will act on the ! in strange ways when it is inside a variable. If it is the first character in a string, it is ignored or dropped from the string, I can't be sure which. For example when I read in my input text, if the ! is the first character, it is ignored, but if it is further into the input string, then it is visible and acted upon.

I'm still debugging....
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Postby Gaev » Sat Feb 25, 2012 5:54 pm

dec:
I can't imagine how to deal with binary data if cannot have a binary type. In other words, you have strings, integers, arrays variables, and can deal with it. But if you not have a binary type variable, I cannot imagine how to deal with binary data.
At the risk of hijacking this post ... sorry Enigman ... you don't need to interact with NeoBook's Variable-Model ... if people need to read/write files with binary ... meaning bytes with (Hex) values 00 to FF ... you can create a set of commands that ...

- accept character values as "Hex:[nn]" or use NeoBook's built-in facility "[#nn]"

- Read contents of files into {plugin variables} e.g. ...
decBinaryFileRead "file name" "byte range" "{decBinaryVariableName}"

- same for decBinaryFileWrite and other byte manipulation commands like ...

decBinarySearchStr
decBinaryStrIns
decBinaryStrDel
decBinaryStrReplace
decBinarySubStr
decBinaryStrLen

I would think that most people who need this kind of facility usually need to read image/exe files, search/replace specific bytes and write the results back to a file.

Here http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm is a standalone utility I use on the rarest of occasions that I need to peek into binary files ... I have only used its "Main Window" ... but I see that it has its own script commands ... you might get some ideas from them.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby dec » Sat Feb 25, 2012 6:04 pm

Hi there,

Thanks Gaev (sorry too Enigman), I'll take a look when have some time. ;)
.
Enhance your NeoBook applications!
.
58 plugins, 1131 actions and 233 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Postby Gaev » Sat Feb 25, 2012 6:54 pm

Enigman:

Oops, just saw your followup post (which I missed earlier).
SetVar "[char]" "[#[count]]" - Where [count] = 33, [char] is null
The null result is as expected ... and should not be so coded ... "[#[count]]" will first resolve to [#33] ... which will resolve to !... the leading ! will be interpreted by NeoBook as a directive ... and since there is nothing else, it will return null.
SetVar "[char]" "![#[count]]" - Where [count] = 33, [char] = !
This is the correct syntax ... "![#[count]]" will first resolve to ![#33] ... then to !! ... the first ! tells NeoBook to use the remaining content AS IS ... giving you !.
SetVar "![char]" "![#[count]]" - Where [count] is anything, [char] is null
This is because you are asking to store the result in ![char] ... which is different from telling it to store the result in a variable called [char] ... so no, don't use the ! when referencing a (output) variable name ... only when you are specifying an (input) expression that needs to be resolved (or directed to use AS IS).
The next thing I learned is that action commands will act on the ! in strange ways when it is inside a variable. If it is the first character in a string, it is ignored or dropped from the string, I can't be sure which. For example when I read in my input text, if the ! is the first character, it is ignored, but if it is further into the input string, then it is visible and acted upon.
Again, I would need to see the exact command you are using.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Enigman » Sat Feb 25, 2012 10:15 pm

Gaev,

Thanks for your help. I have solved the problem by going through a "different door" Since the exclamation point is a "directive" I have taken it out of the equation by treating it as a non-printing character.

Originally I looped through the non-printing ascii characters 0 through 32 and traded them for printing characters higher in the ascii set. Those characters were recorded, and then I scanned the input for printing characters from 33 to 191 and recorded those, After that I processed the characters and that's where all the trouble started.

So to fix it, I now treat ascii 0 through 33 as non-printing characters, which includes the exclamation, and that strips them out of the processing. I then continue with ascii 34 through 191.

Presto ... problem "avoided". The decryption function will not have the same problems with the exclamation directive.

Thanks again.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron