Re: Creating script support for console application

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Use CreateFileMapping() and MapViewOfFile() to eliminate reading into
buffers like:

char buf[BUFFER_OVERFLOW_VULERABILITY];

After mapping the file into memory, you may want to allocate a new buffer
and convert the text-file from CR , LF , CR/LF-deliminated to
null-terminated lines.

You may actual want to make all tokens null-terminated strings, and
double-terminate the lines, and triple-terminate the buffer.

This way you eliminate any fread() into fixed-size buffers, and treat the
script as a simply memory-buffer of asciiz-strings.

Of course, a decent script will keep track of line-numbers, so syntax errors
can be generated, which means an additional structure mapping the converted
line-numbers into their original line numbers in the text-file.

But, since you plan on providing looping-constructs in the script, you need
to keep track of line numbers anyway.




"ern" <erniedude@xxxxxxxxx> wrote in message
news:1137508850.925672.51300@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> [Putting this in comp.lang.c also...]
>
> My command-line application must be able to run text scripts (macros).
> The scripts have commands, comments, and flags. Comments are ignored
> (maybe they are any line beginning with " ; ") Commands are executed
> as if the user *manually* typed them in the console. Flags are special
> commands that tell the program where to BREAK, LOOP, START. A typical
> script may look like this:
>
> ; This is my script. It will test my mp3 player...
> START:
>
> set battery voltage 1.5
> begin thread
>
> LOOP: ; here I will test individual tracks
> play
> skip track
>
> BREAK: ; at this point, I go back up to find "LOOP"
>
> To launch the script, the user will type:
>
> "script <pathname>"
>
> where pathname is where the script lives. So far, I have the entire
> text file in a char * buffer.
>
> Now I need to do several things....
>
> 1. After the script begins, the USER needs a way to halt execution of
> the script. I was thinking any key press would do. Pseudocode looks
> like this:
>
> while("user hasn't pressed any key"){ //continue executing script...
>
> I want the script to stop immediately after the user presses a key, so
> I 'm not sure a while loop is the best way... perhaps some kind of
> thread...
>
> Need help implementing that logic....
>
> 2. I need a way to seperate each line in the text file. I was
> thinking of putting each line in an element of an array. I could have
> two arrays:
>
> char * start[SIZE];
> char * loop[SIZE];
>
> The first holds the commands to execute once, and the second holds the
> commands to repeat (not sure if the syntax is correct there... ? I
> need an array of strings...). Once I have the commands, I can just
> execute them one at a time until I get the flag to stop (#1). But how
> would I parse the commands into the arrays from the "buffer" ?
>


.



Relevant Pages

  • Re: making $_cmd work
    ... I have an array of commands to be executed. ... I want the script to execute ... Chopped down/modified script with my last 2 failed attempts so far. ...
    (comp.unix.shell)
  • pyodbc.Error Crash
    ... I believe this bug is also related to the other problem I just reported. ... DB = Microsoft Access XP ... # or buffer length ') ... The broke.py script has 4 select statements but only one is executed. ...
    (comp.lang.python)
  • * Need help Implementing a script (or macro)
    ... The scripts have commands, comments, and flags. ... ; This is my script. ... thinking of putting each line in an element of an array. ...
    (comp.lang.c)
  • Creating script support for console application
    ... The scripts have commands, comments, and flags. ... ; This is my script. ... thinking of putting each line in an element of an array. ...
    (microsoft.public.vc.language)
  • Re: Numeric or character ?
    ... > anno4000@xxxxxxxxxxxxxxxxxxxxxxx (Anno Siegel) wrote: ... >> when the script happens to do mass IO via STDOUT. ... the buffer just doesn't fill up so much. ... "Reply" at the bottom of the article headers. ...
    (comp.lang.perl.misc)