Command Line Args

From Msim

Jump to: navigation, search

Command Line Arguments are processed by M-Sim through the use of .arg files.

Format

<num> # <exe> <arguments>

Quote Problem

Quotes are handled properly through the actual command line but are processed as characters through loader.c. Therefore, quotes around phrases would not be respected. The following change to loader.c (ld_load_prog) respects quotes. (These must begin a word and end the last word - any other usage of quotes may not be supported).

Additional code added to the start of ld_load_prog:

       //Quote handling:
       //If "two words" is part of the command line, it is read as two parameters instead of one (with quotes). This handles that problem
       bool quote = false;
       for(int i=0;i<argc;i++)
       {
               if(quote)
               {
                       argv[i-1] += std::string(" ") + argv[i];
                       argv.erase(argv.begin()+i);
                       i--;
                       argc--;
                       if(argv[i][argv[i].size()-1]=='\"')
                       {
                               argv[i].erase(argv[i].begin() + argv[i].size() - 1);
                               quote = false;
                       }
               }
               if(argv[i][0]=='\"')
               {
                       assert(!quote);
                       quote = true;
                       argv[i].erase(argv[i].begin());
               }
       }
       assert(!quote);
Personal tools