Ejemplo n.º 1
0
static int
process_command(int serial, int cid, char *cmd)
{
  /*char *opt, *opt2; */
  char *p, *opt;
  int ret;

  if ((p = strchr(cmd, '\n')))
	*p = '\0';
  else
	return -1;

  if ((opt = strchr(cmd, ' '))) {
	*opt = '\0';
	opt ++;
  } else {
	opt = NULL;
  }

  debug_printf(DEBUG_NOTE, "cmd: %s\n", cmd);

  if (strcmp(cmd, "RELEASE") == 0)
	ret = cmd_release(cid);
  else if (strcmp(cmd, "UNFOCUSED") == 0)
	ret = cmd_unfocused(cid);
  else if (strcmp(cmd, "FOCUSED") == 0)
	ret = cmd_focused(cid);
  else if (strcmp(cmd, "HIDE") == 0)
	ret = cmd_hide(cid);
  else if (strcmp(cmd, "SHOW") == 0)
	ret = cmd_show(cid);
  else if (strcmp(cmd, "NEW") == 0)
  	ret = cmd_new(cid, opt);
  else if (strcmp(cmd, "RESET") == 0)
	ret = cmd_reset(cid);
  else if (strcmp(cmd, "CHANGE") == 0)
  	ret = cmd_change(cid, opt);
  else if (strcmp(cmd, "PROP") == 0)
  	ret = cmd_prop(cid, opt);
  else if (strcmp(cmd, "LABEL") == 0)
  	ret = cmd_label(cid);
  else if (strcmp(cmd, "HELPER") == 0)
	ret = cmd_helper(cid, opt);
  else if (strcmp(cmd, "NOP") == 0)
  	ret = cmd_nop(cid);
  else if (strcmp(cmd, "LIST") == 0)
  	ret = cmd_list();
  else if (strcmp(cmd, "SETENC") == 0)
  	ret = cmd_setenc(opt);
  else if (strcmp(cmd, "GETENC") == 0)
  	ret = cmd_getenc(opt); /* for debug */
  else
	ret = cmd_error();

  return ret;
}
Ejemplo n.º 2
0
Archivo: s2.cpp Proyecto: dCache/s2
/********************************************************************
 * Parse command-line arguments (non -+ options)
 *
 * Returns:
 *   ERR_OK: if success
 *   >= ERR_OK: otherwise
 ********************************************************************/
static int
s2_run(int argc, char **argv, int i)
{
  int rval = ERR_OK, lval;
  int i_1 = i;
  Node *root = NULL;
  Process *proc = NULL;
  BOOL tp_created = FALSE;

  /* init progress bar */
  Process::progress(-1,proc);

#if defined(HAVE_SRM21) || defined(HAVE_SRM22)
  srm_init();
#endif

  lval = parse(opts.scr_fname, &root);
  DM_DBG(DM_N(1), "parser return value=%d\n", lval);
  UPDATE_MAX(rval, lval);
  if(rval > opts.s2_eval) {
    /* stop evaluation */
    UPDATE_MAX(rval, ERR_NEXEC);
    goto cleanup;
  }

  /* create thread pool */
  if(!tp_created) tp_init(opts.tp_size);
  tp_created = TRUE;

  /* pretty-print S2 tree ($ENV{VAR} are evaluated) */
  if(opts.pp_fname) lval = pp_print(root);
  DM_DBG(DM_N(1), "pretty-printer return value=%d\n", lval);
  UPDATE_MAX(rval, lval);

  if(root) {
    Process::threads_init();
    proc = new Process(root, NULL, NULL);

    if(!proc) {
      DM_ERR(ERR_SYSTEM, _("failed to create a Process: %s\n"), _(strerror(errno)));
      UPDATE_MAX(rval, ERR_SYSTEM);
      goto cleanup;
    }

    /* write ${0}..${n} variables */
    const char *name = cmd_label();
    proc->WriteVariable("0", name, TRUE);
    for(; i < argc; i++) {
      proc->WriteVariable(i2str(i - i_1 + 1).c_str(), argv[i], TRUE);
    }

    setenv("CLIENT_INFO", build_client_info(name), 1);

    lval = proc->eval();
    Process::threads_destroy();
    DM_DBG(DM_N(1), "evaluation return value=%d\n", lval);
    UPDATE_MAX(rval, lval);
  }

  /* after-evaluation print of the tree */
  if(opts.e2_fname) lval = e2_print(root);
  DM_DBG(DM_N(2), "after-evaluation print return value=%d\n", lval);
  UPDATE_MAX(rval, lval);

cleanup:
  /* cleanup */
  DELETE(proc);	/* free proc *first*, then root */
  DELETE(root);

  /* destroy thread pool */
  if(tp_created) tp_cleanup();

  /* hide progress bar */
  Process::progress(0,proc);

  DM_DBG(DM_N(1), "s2_run return value=%d\n", rval);
  return rval;
}