* Need help Implementing a script (or macro)

Discussion in 'C Programming' started by ern, Jan 17, 2006.

  1. ern

    ern Guest

    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" ?
    ern, Jan 17, 2006
    #1
    1. Advertising

  2. On 17 Jan 2006 06:42:51 -0800, in comp.lang.c , "ern"
    <> wrote:

    >My command-line application must be able to run text scripts (macros).


    >1. After the script begins, the USER needs a way to halt execution of
    >the script.


    Suspend or terminate? The latter is easy...

    >I was thinking any key press would do.


    you can't do this in standard C, as there's no way to do a continuous
    background check for something else happening in parallel to your main
    thread. Ask in a newsgroup specific to your platform for information
    on threading.

    >2. I need a way to seperate each line in the text file.


    read up on strtok and sscanf.

    Mark McIntyre
    --

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Mark McIntyre, Jan 17, 2006
    #2
    1. Advertising

  3. ern

    Chuck F. Guest

    Re: [OT]* Need help Implementing a script (or macro)

    ern wrote:
    >
    > 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:


    Just use the innate script ability of your shell. In on Linux you
    probably need to read up on bash. If on Windoze read up on batch
    language, or better install 4dos for a better system.

    This is all OT on c.l.c.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
    Chuck F., Jan 17, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dead RAM
    Replies:
    20
    Views:
    1,092
    John Harrison
    Jul 14, 2004
  2. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    564
    Jack Klein
    Sep 21, 2003
  3. sounak

    to get macro name from macro value

    sounak, Nov 22, 2005, in forum: C Programming
    Replies:
    17
    Views:
    486
    Mark McIntyre
    Nov 22, 2005
  4. Patrick Kowalzick
    Replies:
    5
    Views:
    458
    Patrick Kowalzick
    Mar 14, 2006
  5. Mike Manilone

    macro inside macro

    Mike Manilone, Oct 3, 2011, in forum: C Programming
    Replies:
    8
    Views:
    439
    Mike Manilone
    Oct 6, 2011
Loading...

Share This Page