Logo Search packages:      
Sourcecode: eresi version File versions  Download package

int revm_parseopt ( int  argc,
char **  argv 
)

Parse the commands

Definition at line 159 of file parser.c.

References bzero(), revm_getvarparams(), and revm_parseopt().

Referenced by ke2dbg_keyb_enter(), revm_exec_str(), revm_loop(), revm_parseopt(), and revm_source().

{
  u_int                 index;
  int             ret;
  volatile revmcmd_t    *actual;
  volatile revmargv_t   *loopstart;
  char                  *name;
  char                  label[16];
  char                  c;
  char                  cmdline;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

  /* We are at command line */
  cmdline = ((world.state.revm_mode == REVM_STATE_CMDLINE 
           || world.state.revm_mode == REVM_STATE_TRACER)
           && !world.state.revm_net);

  /* Main option reading loop : using the command hash table */
  for (index = 1; index < argc; index++)
    {

      /* Allocate command descriptor */
      bzero(label, sizeof(label));
      if (!pendinglabel)
      {
        XALLOC(__FILE__, __FUNCTION__, __LINE__,
             newcmd, sizeof(revmargv_t), -1);
        world.curjob->curcmd = newcmd;
        if (world.curjob->script[world.curjob->sourced] == NULL)
          world.curjob->script[world.curjob->sourced] = newcmd;
      }
      else
      pendinglabel = 0;
      
      /* Retreive command descriptor in the hash table */
      name = argv[index] + cmdline;
      actual = hash_get(&cmd_hash, name);
    
      /* We matched a command : call the registration handler */
      if (actual != NULL)
      {

        /* If there is a forend/matchend label waiting, insert it here */
        /* The forend label must point on the -following- command */
        /* Annotate meta-command foreach, case, and default with  the "end label" */
        if (nextlabel)
          {
            hash_add(&labels_hash[world.curjob->sourced], endlabl, newcmd);
            loopstart = hash_get(&labels_hash[world.curjob->sourced], looplabels[curnest]);

            /* If we are executing "default", we search for the loop start in the parent scope */
            /*
            if (world.curjob->sourced && isdefault)
            for (ret = 0; world.curjob->sourced >= ret; ret++)
              {
                loopstart = hash_get(&labels_hash[world.curjob->sourced - ret], looplabels[curnest]);
                if (loopstart)
                  break;
              }
            */

            if (!loopstart)
            PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                       "Invalid nesting of language construct", -1);
            loopstart->endlabel = strdup(endlabl);
            /* isdefault = */ nextlabel = 0;
          }

        /* Dont call registration handler if there is not (0 param commands) */
        if (actual->reg != NULL)
          {
            ret = actual->reg(index, argc, argv);
            if (ret < 0)
            PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                       "Command not found", 
                       (revm_doerror(revm_badparam, argv[index])));
          }
        else ret = 0;

        /* Handle control flow constructs of the eresi script */
        if (revm_parse_construct(argv[index]) < 0)
          PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                   "Invalid eresi program nesting construct", -1);
        index += ret;
      }

      /* We did -NOT- match command */
      else if (world.state.revm_mode == REVM_STATE_SCRIPT)
      {
        /* Try to match a label */
        ret = sscanf(name, "%15[^:]%c", label, &c);
        if (ret == 2 && c == ':')
          {
            hash_add(&labels_hash[world.curjob->sourced], 
                   strdup(label), newcmd); 
            pendinglabel = 1;
            continue;
          }
        
        /* No command matched, enable runtime lookup : module could be loaded later */
        ret = revm_getvarparams(index - 1, argc, argv);
        index += ret;
      }
      
      /* We matched nothing known, error */
      else
      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                 "Unknown parsing error", 
                 (revm_doerror(revm_unknown, argv[index])));

      /* Put the newcmd command at the end of the list */
      newcmd->name = name;
      newcmd->cmd  = (revmcmd_t *) actual;      
      if (!world.curjob->lstcmd[world.curjob->sourced])
      world.curjob->lstcmd[world.curjob->sourced] = newcmd;
      else
      {
        world.curjob->lstcmd[world.curjob->sourced]->next = newcmd;
        newcmd->prev = world.curjob->lstcmd[world.curjob->sourced];
        world.curjob->lstcmd[world.curjob->sourced] = newcmd;
      }
    }

  /* Return success */
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
}


Generated by  Doxygen 1.6.0   Back to index