ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

cmd.c
Go to the documentation of this file.
00001 /*
00002  * ReactOS log2lines
00003  * Written by Jan Roeloffzen
00004  *
00005  * - Cli for escape commands
00006  */
00007 
00008 #include <stdio.h>
00009 #include <string.h>
00010 #include <stdlib.h>
00011 
00012 #include "util.h"
00013 #include "cmd.h"
00014 #include "options.h"
00015 #include "log2lines.h"
00016 #include "help.h"
00017 
00018 /* When you edit the cmd line and/or use the history instead of just typing,
00019  * a bunch of editing BS and space characters
00020  * is inserted, so the string looks right on the console but still
00021  * contains the original string, plus other garbage:
00022  */
00023 static char 
00024 *backSpaceEdit(char *s)
00025 {
00026     char c;
00027     char *edit = s;
00028     char *text = s;
00029 
00030     while (( c = *edit++ ))
00031     {
00032         switch (c)
00033         {
00034         case KDBG_BS_CHAR:
00035             if (text > s)
00036                 text --;
00037             break;
00038         default:
00039             *text++ = c;
00040         }
00041     }
00042     *text = '\0';
00043 
00044     return s;
00045 }
00046 
00047 static int
00048 handle_switch(FILE *outFile, int *sw, char *arg, char *desc)
00049 {
00050     int changed =0;
00051     int x = 0;
00052 
00053     if (arg && (strcmp(arg,"") != 0))
00054     {
00055         x = atoi(arg);
00056         if (x != *sw)
00057         {
00058             *sw = x;
00059             changed = 1;
00060         }
00061     } 
00062     if (desc)
00063     {
00064         esclog(outFile, "%s is %d (%s)\n", desc, *sw, changed ? "changed":"unchanged");
00065         if (!arg)
00066             esclog(outFile, "(readonly)\n");
00067     }
00068 
00069     return changed;
00070 }
00071 
00072 static int
00073 handle_switch_str(FILE *outFile, char *sw, char *arg, char *desc)
00074 {
00075     int changed =0;
00076 
00077     if (arg)
00078     {
00079         if (strcmp(arg,"") != 0)
00080         {
00081             if (strcmp(arg,KDBG_ESC_OFF) == 0)
00082             {
00083                 if (*sw)
00084                     changed = 1;
00085                 *sw = '\0';
00086             }
00087             else if (strcmp(arg, sw) != 0)
00088             {
00089                 strcpy(sw, arg);
00090                 changed = 1;
00091             }
00092         }
00093     } 
00094     if (desc)
00095     {
00096         esclog(outFile, "%s is \"%s\" (%s)\n", desc, sw, changed ? "changed":"unchanged");
00097         if (!arg)
00098             esclog(outFile, "(readonly)\n");
00099     }
00100         
00101     return changed;
00102 }
00103 
00104 static int
00105 handle_switch_pstr(FILE *outFile, char **psw, char *arg, char *desc)
00106 {
00107     int changed =0;
00108 
00109     if (arg)
00110     {
00111         if (strcmp(arg,"") != 0)
00112         {
00113             if (strcmp(arg,KDBG_ESC_OFF) == 0)
00114             {
00115                 if (*psw)
00116                     changed = 1;
00117                 free(*psw);
00118                 *psw = NULL;
00119             }
00120             else
00121             {
00122                 if (!*psw)
00123                 {
00124                     *psw = malloc(LINESIZE);
00125                     **psw = '\0';
00126                 }
00127 
00128                 if (strcmp(arg, *psw) != 0)
00129                 {
00130                     strcpy(*psw, arg);
00131                     changed = 1;
00132                 }
00133             }
00134         }
00135     } 
00136     if (desc)
00137     {
00138         esclog(outFile, "%s is \"%s\" (%s)\n", desc, *psw, changed ? "changed":"unchanged");
00139         if (!arg)
00140             esclog(outFile, "(readonly)\n");
00141     }
00142         
00143     return changed;
00144 }
00145 
00146 static int
00147 handle_address_cmd(FILE *outFile, char *arg)
00148 {
00149     PLIST_MEMBER plm;
00150     char Image[NAMESIZE];
00151     DWORD Offset;
00152     int cnt;
00153     char *s;
00154 
00155     if(( s = strchr(arg, ':') ))
00156     {
00157         *s = ' ';
00158         if ( (cnt = sscanf(arg,"%20s %lx", Image, &Offset)) == 2)
00159         {
00160             if (( plm = entry_lookup(&cache, Image) ))
00161             {
00162                 if (plm->RelBase != INVALID_BASE)
00163                     esclog(outFile, "Address: 0x%lx\n", plm->RelBase + Offset)
00164                 else
00165                     esclog(outFile, "Relocated base missing for '%s' ('mod' will update)\n", Image);
00166             }
00167             else
00168                 esclog(outFile, "Image '%s' not found\n", Image);
00169         }
00170         else
00171             esclog(outFile, "usage: `a <Image>:<offset>\n");
00172     }
00173     else
00174         esclog(outFile, "':' expected\n");
00175 
00176     return 1;
00177 }
00178 
00179 char
00180 handle_escape_cmd(FILE *outFile, char *Line, char *path, char *LineOut)
00181 {
00182     char cmd;
00183     char sep = '\n';
00184     char *arg;
00185     char *l = Line;
00186     int res = 1;
00187     int cnt = 0;
00188     int changed = 0;
00189 
00190     l = backSpaceEdit(l);
00191     if (l[1] != KDBG_ESC_CHAR)
00192         return l[1]; //for reprocessing as not escaped
00193 
00194     log(outFile, "\n");
00195 
00196     l += 2; //skip space+escape character
00197     if ( (cnt=sscanf(l,"%c%c",&cmd,&sep)) < 1)
00198     {
00199         esclog(outFile, "Command expected\n");
00200         res = 0;
00201     }
00202 
00203     if (res && cnt==2 && sep != ' ')
00204     {
00205         esclog(outFile, "' ' expected\n");
00206         res = 0;
00207     }
00208     l++; //skip cmd
00209     while ( *l == ' ')l++; //skip more spaces
00210     arg = l;
00211     opt_cli = 1;
00212     switch (cmd)
00213     {
00214     case 'a':
00215         handle_address_cmd(outFile, arg);
00216         break;
00217     case 'h':
00218         usage(1);
00219         break;
00220     case 'b':
00221         if (handle_switch(outFile, &opt_buffered, arg, "-b Logfile buffering"))
00222             set_LogFile(&logFile); //re-open same logfile
00223         break;
00224     case 'c':
00225         handle_switch(outFile, &opt_console, NULL, "-c Console option");
00226         break;
00227     case 'd':
00228         handle_switch_str(outFile, opt_dir, NULL, "-d Directory option");
00229         break;
00230     case 'l':
00231         if (handle_switch_str(outFile, opt_logFile, arg, "-l logfile") || (strcmp(opt_mod,"a")!=0))
00232         {
00233             opt_mod = "a";
00234             set_LogFile(&logFile); //open new logfile
00235         }
00236         break;
00237     case 'L':
00238         if (handle_switch_str(outFile, opt_logFile, arg, "-L logfile") || (strcmp(opt_mod,"w")!=0))
00239         {
00240             opt_mod = "w";
00241             set_LogFile(&logFile); //open new logfile
00242         }
00243         break;
00244     case 'm':
00245         handle_switch(outFile, &opt_Mark, arg, "-m mark (*)");
00246         break;
00247     case 'M':
00248         handle_switch(outFile, &opt_Mark, arg, "-M Mark (?)");
00249         break;
00250     case 'P':
00251         handle_switch_str(outFile, opt_Pipe, NULL, "-P Pipeline option");
00252         break;
00253     case 'q':
00254         opt_quit = 1;
00255         esclog(outFile, "Bye!\n");
00256         break;
00257     case 'r':
00258         handle_switch(outFile, &opt_raw, arg, "-r Raw");
00259         break;
00260     case 'R':
00261         changed = handle_switch_pstr(outFile, &opt_Revision, arg, NULL);
00262         opt_Revision_check = 0;
00263         if (opt_Revision)
00264         {
00265             opt_Revision_check = 1;
00266             if (strstr(opt_Revision, "check") == opt_Revision)
00267             {
00268                 esclog(outFile, "-R is \"%s\" (%s)\n", opt_Revision, changed ? "changed":"unchanged");
00269             }
00270             else if (strstr(opt_Revision, "regscan") == opt_Revision)
00271             {
00272                 char *s = strchr(opt_Revision, ',');
00273 
00274                 revinfo.range = DEF_RANGE;
00275                 if (s)
00276                 {
00277                     *s++ = '\0';
00278                     revinfo.range = atoi(s);
00279                 }
00280                 regscan(outFile);
00281             }
00282             else if (strstr(opt_Revision, "regclear") == opt_Revision)
00283             {
00284                 list_clear(&sources);
00285                 summ.regfound = 0;
00286                 esclog(outFile, "cleared regression scan results\n");
00287             }
00288         }
00289         break;
00290     case 's':
00291         if (strcmp(arg,"clear") == 0)
00292         {
00293             memset(&summ, 0, sizeof(SUMM));
00294             esclog(outFile, "Statistics cleared\n");
00295         } 
00296         else
00297             stat_print(outFile, &summ);
00298         break;
00299     case 'S':
00300         cnt = sscanf(arg, "%d+%d", &opt_Source, &opt_SrcPlus);
00301         if (opt_Source)
00302         {
00303             handle_switch(outFile, &opt_undo, "1", "-u Undo");
00304             handle_switch(outFile, &opt_redo, "1", "-U Undo and reprocess");
00305             opt_Revision_check = 1;
00306         }
00307         esclog(outFile, "-S Sources option is %d+%d,\"%s\"\n", opt_Source, opt_SrcPlus, opt_SourcesPath);
00308         esclog(outFile, "(Setting source tree not implemented)\n");
00309         break;
00310     case 't':
00311         handle_switch(outFile, &opt_twice, arg, "-t Translate twice");
00312         break;
00313     case 'T':
00314         handle_switch(outFile, &opt_twice, arg, NULL);
00315         handle_switch(outFile, &opt_Twice, arg, "-T Translate for (address-1)");
00316         break;
00317     case 'u':
00318         handle_switch(outFile, &opt_undo, arg, "-u undo");
00319         break;
00320     case 'U':
00321         handle_switch(outFile, &opt_undo, arg, NULL);
00322         handle_switch(outFile, &opt_redo, arg, "-U Undo and reprocess");
00323         break;
00324     case 'v':
00325         handle_switch(outFile, &opt_verbose, arg, "-v Verbosity");
00326         break;
00327     case 'z':
00328         handle_switch_str(outFile, opt_7z, NULL, "-z 7z path");
00329         break;
00330     default:
00331         if (strchr(optchars, cmd))
00332             esclog(outFile, "Command not implemented in cli: %c %s\n",cmd, arg)
00333         else
00334             esclog(outFile, "Unknown command: %c %s\n",cmd, arg);
00335     }
00336     opt_cli = 0;
00337 
00338     memset(Line, '\0', LINESIZE);  // flushed
00339 
00340     return KDBG_ESC_CHAR; //handled escaped command
00341 }
00342 
00343 /* EOF */

Generated on Sun May 27 2012 04:18:10 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.