예제 #1
0
파일: set-bool.c 프로젝트: 0day-ci/xen
int main(int argc, char **argv)
{
	int err = 0;
	xc_interface *xch;
	int value;

	if (argc != 3)
		usage(argv);

	value = str2bool(argv[2]);

	xch = xc_interface_open(0,0,0);
	if ( !xch )
	{
		fprintf(stderr, "Unable to create interface to xenctrl: %s\n",
				strerror(errno));
		err = 1;
		goto done;
	}

	err = xc_flask_setbool(xch, argv[1], value, 1);
	if (err) {
		fprintf(stderr, "xc_flask_setbool: Unable to set boolean %s=%s: %s (%d)",
			argv[1], argv[2], strerror(errno), err);
		err = 2;
		goto done;
	}

 done:
	if ( xch )
		xc_interface_close(xch);

	return err;
}
예제 #2
0
파일: dofigure.c 프로젝트: kurino/flow
void	doFigure ( char *pList ) {
	char	name[ NAME_SIZE ];
	int		params;
	char	flag[ FLAG_SIZE ];
	Coord	size;
	char	line[ LINE_LEN ];
	StrList	*slp = allocStrList();
    int		l;

	sscanf ( pList, "%s %lf %lf %s %d", name, &size.x, &size.y, flag, &params );

	while ( readline_infile ( line, LINE_LEN ) != NULL ) {
		if ( isspace ( line[ 0 ] ) ) {
			appendStrList ( slp, line + 1 );
		} else {
			unget_infile ( line );
			break;
		}
	}

	if ( top == NULL ) {
		top = allocFigureList();
	}

	insertFigureList (
		top,
		allocFigure (
			name, 
			allocFlowCom ( name, params, size, str2bool(flag), DRAW ),
			slp
		)
	 );

}
예제 #3
0
파일: scriptlib.c 프로젝트: intgr/sc2-uqm
bool
scr_GetBooleanDef (const char *key, bool def)
{
	const char *v;
	check_map_init ();
	
	v = scr_GetString (key);
	return v ? str2bool (v) : def;
}
예제 #4
0
Manager::Manager(int argc, char *argv[]) {
    seach_peak_first = str2bool(argv[1]);
    c_line = stoi(argv[2]);
    c_f_valley = stod(argv[3]);
    c_f_peak = stod(argv[4]);
    c_def_valley = stod(argv[5]);
    c_def_peak = stod(argv[6]);
    output = argv[7];
    writer = new ofstream(output, ios_base::trunc);
    // writing headers
    *writer << "forca, tempo, cod, deformacao1, deformacao2, deformacao3, deformacao4, queda, segmento" << endl;
    for (int index = 8; index < argc; index++) {
        files.push_back(argv[index]);
    }
}
예제 #5
0
/**
 * Get an environment variable and convert it to a boolean.
 *
 * Supported values are those of str2bool(), namely "yes", "no" as well as "1"
 * and "0". All other values are treated as false and a diagnostic message is
 * printed to stderr.
 **/
static bool getenv_bool(const char *name)
{
	const char *str_value = getenv(name);
	bool value;
	if (str2bool(str_value, &value) < 0) {
		if (errno == EINVAL) {
			fprintf(stderr,
				"WARNING: unrecognized value of environment variable %s (expected yes/no or 1/0)\n",
				name);
			return false;
		} else {
			die("cannot convert value of environment variable %s to a boolean", name);
		}
	}
	return value;
}
예제 #6
0
int bench(int argc, char **argv, bool main_bench) {
    for (int arg = 0; arg < argc; ++arg) {
        if (!strncmp("--batch=", argv[arg], 8))
            SAFE(batch(argv[arg] + 8, bench), CRIT);
        else if (!strncmp("--cfg=", argv[arg], 6))
            cfg = str2cfg(argv[arg] + 6);
        else if (!strncmp("--match=", argv[arg], 8))
            pattern = argv[arg] + 8;
        else if (!strncmp("--mb=", argv[arg], 5))
            mb = atoi(argv[arg] + 5);
        else if (!strncmp("--dir=", argv[arg], 6))
            dir = str2dir(argv[arg] + 6);
        else if (!strncmp("--alg=", argv[arg], 6))
            alg = str2alg(argv[arg] + 6);
        else if (!strncmp("--attr=", argv[arg], 7))
            SAFE(str2attr(&attr, argv[arg] + 7), CRIT);
        else if (!strncmp("--skip-impl=", argv[arg], 12))
            skip_impl = argv[arg] + 12;
        else if (!strncmp("--allow-unimpl=", argv[arg], 15))
            allow_unimpl = str2bool(argv[arg] + 15);
        else if (!strncmp("--perf-template=", argv[arg], 16))
            perf_template = argv[arg] + 16;
        else if (!strcmp("--reset", argv[arg]))
            reset_parameters();
        else if (!strncmp("--mode=", argv[arg], 7))
            bench_mode = str2bench_mode(argv[arg] + 7);
        else if (!strncmp("-v", argv[arg], 2))
            verbose = atoi(argv[arg] + 2);
        else if (!strncmp("--verbose=", argv[arg], 10))
            verbose = atoi(argv[arg] + 10);
        else {
            desc_t c;
            bool is_deconv = 0;
            if (str2desc(&c, argv[arg], is_deconv) == FAIL) {
                fprintf(stderr, "driver: unknown option: `%s`, exiting...\n",
                        argv[arg]);
                exit(2);
            }
            check_correctness(&c);
        }
    }

    return OK;
}
예제 #7
0
int  GetBoolParam(config_item_t block, const char *block_name,
                  const char *var_name, param_flags_t flags, bool *target,
                  char ***extra_args_tab, unsigned int *nb_extra_args,
                  char *err_msg )
{
    config_item_t  curr_item;
    int            rc, extra;
    char          *name;
    char          *value;
    int            tmp_bool;

    err_msg[0] = '\0';

    rc = get_cfg_param(block, block_name, var_name, flags, &name, &value,
                       &extra, &curr_item, err_msg);
    if (rc)
        return rc;

    tmp_bool = str2bool(value);
    if (tmp_bool == -1)
    {
        sprintf(err_msg,
                "Invalid value for '%s::%s', line %d: boolean expected (0, 1, true, false, yes, no, enabled, disabled)",
                block_name, var_name, rh_config_GetItemLine(curr_item));
        return EINVAL;
    }
    *target = (tmp_bool != 0);

    if ( extra )
    {
        if ( !extra_args_tab || !nb_extra_args )
        {
            sprintf( err_msg, "Unexpected options for parameter '%s::%s', line %d", block_name,
                     var_name, rh_config_GetItemLine( curr_item ) );
            return EINVAL;
        }
        else
        {
            *nb_extra_args = rh_config_GetExtraArgs( curr_item, extra_args_tab );
        }
    }

    return 0;
}
예제 #8
0
파일: xb300.c 프로젝트: 2ephyr/bladeRF
static int set_enable(struct cli_state *state,
                      bladerf_xb300_amplifier amp, const char *enable_str)
{
    int status;
    bool enable;

    status = str2bool(enable_str, &enable);
    if (status != 0) {
        cli_err(state, enable_str, "Invalid enable/disable string.\n\n");
        return CLI_RET_INVPARAM;
    }

    status = bladerf_xb300_set_amplifier_enable(state->dev, amp, enable);
    if (status != 0) {
        state->last_lib_error = status;
        status = CLI_RET_LIBBLADERF;
    }

    return status;
}
예제 #9
0
static void test_str2bool()
{
	int err;
	bool value;

	err = str2bool("yes", &value);
	g_assert_cmpint(err, ==, 0);
	g_assert_true(value);

	err = str2bool("1", &value);
	g_assert_cmpint(err, ==, 0);
	g_assert_true(value);

	err = str2bool("no", &value);
	g_assert_cmpint(err, ==, 0);
	g_assert_false(value);

	err = str2bool("0", &value);
	g_assert_cmpint(err, ==, 0);
	g_assert_false(value);

	err = str2bool("", &value);
	g_assert_cmpint(err, ==, 0);
	g_assert_false(value);

	err = str2bool(NULL, &value);
	g_assert_cmpint(err, ==, 0);
	g_assert_false(value);

	err = str2bool("flower", &value);
	g_assert_cmpint(err, ==, -1);
	g_assert_cmpint(errno, ==, EINVAL);

	err = str2bool("yes", NULL);
	g_assert_cmpint(err, ==, -1);
	g_assert_cmpint(errno, ==, EFAULT);
}
예제 #10
0
bool UFunctionSeq::handleCommand(UServerInMsg * msg, void * extra)
{ // extract parameters
  bool result = true;
  // decode vars
  char attName[MAX_SML_NAME_LENGTH];
  const int VAL_BUFF_LNG = 1000;
  char attValue[VAL_BUFF_LNG];
  // camera and source image variables
  bool ask4help = false;
  bool loadFile = false;
  bool appendFile = false;
  bool getMissions = false;
  bool getStatus = false;
  bool getPgm = false;
  const char * label = NULL;
  bool sendReply = false;
  const int MNL = MAX_FILENAME_LENGTH;
  char loadName[MNL];
  FILE * errLog = NULL;
  const char * errLogName = "loadPlanErr.log";
  const int MELL = 300;
  char se[MELL];
  int i, n;
  FILE * mf;
  char * pMf;
  const int MFL = 100;
  char mfn[MFL];
  USeqLine * line;
  const int MRL = 300;
  char reply[MRL];
  char lineXml[MRL];
  //
  // extract parameters
  while (msg->tag.getNextAttribute(attName, attValue, VAL_BUFF_LNG))
  { // camera device
    if (strcasecmp(attName, "help") == 0)
      ask4help = true;
    else if (strcasecmp(attName, "load") == 0)
    {
      strncpy(loadName, attValue, MNL);
      loadFile = true;
    }
    else if (strcasecmp(attName, "append") == 0)
    {
      strncpy(loadName, attValue, MNL);
      appendFile = true;
    }
    else if (strcasecmp(attName, "add") == 0)
    { // new mission line
      sendReply = addCmdLine(msg, attValue);
    }
    else if (strcasecmp(attName, "goto") == 0)
    { // new mission line
      if (label == NULL)
        label = seq->addLabel();
      sendReply = addCmdLine(msg, attValue);
    }
    else if (strcasecmp(attName, "clear") == 0)
    { // clear current pgm
      seq->clear();
    }
    else if (strcasecmp(attName, "sim") == 0)
    { // set simulation flag - if true, logfile must be set from cmd-line
      seq->setSimulated(str2bool(attValue));
    }
    else if (strcasecmp(attName, "missions") == 0)
      getMissions = true;
    else if (strcasecmp(attName, "status") == 0)
      getStatus = true;
    else if (strcasecmp(attName, "pgm") == 0)
      getPgm = true;
    else if (strcasecmp(attName, "list") == 0)
      getPgm = true;
    else
      // unknown attribute
      result = false;
  }
  //
  if (ask4help)
  {
    sendHelpStart(msg, "SEQ");
    sendText(msg, "---- Available SEQ options:\n");
    sendText(msg, "missions           Get list of all mission files\n");
    sendText(msg, "status             Get plan sequencer status\n");
    sendText(msg, "pgm | list         Get list of all loaded statements\n");
    sendText(msg, "goto=\"cmd\"         Give a manual mission line (in quotes), and skip to this\n");
    sendText(msg, "load=\"file\"        Load a mission file, and skip to this\n");
    sendText(msg, "append=\"file\"      Append a mission file, and skip to this\n");
    sendText(msg, "add=\"command\"      Add a manual command line\n");
    sendText(msg, "stop               Stop current mission (goto end of mission)\n");
    sendText(msg, "clear              remove all mission lines\n");
    sendText(msg, "sim=true | false   Set simulation flag (not implemented yet)\n");
    sendMsg(msg, "</help>\n");
    sendHelpDone(msg);
  }
  else
  {
    if (loadFile or appendFile)
    {
      errLog = fopen(errLogName, "w");
      if (seq->loadPlan(loadName, errLog, appendFile))
      { // loaded OK
        sendInfo(msg, "Loaded without errors");
      }
      else
      {
        if (errLog != NULL)
        {
          fclose(errLog);
          errLog = fopen(errLogName, "r");
          if (errLog != NULL)
          { // there is a file
            sendInfo(msg, "Load error list:");
            while (fgets(se, MELL, errLog) != NULL)
            { // return all filenames in separate frames
              i = strlen(se);
              if (i > 1)
              { // cut off the linefeed at end of line
                se[i-1] = 0;
                result = sendInfo(msg, se);
              }
              if (not result)
                break;
            }
          }
          else
            result = sendWarning(msg, "Could not read error file");
          if (errLog != NULL)
            fclose(errLog);
        }
        else
          sendWarning(msg, "There were errors, but could not create a logfile");
        sendReply = true;
      }
    }
    if (label != NULL)
    { // start execution from label
      result = seq->skipToLabel(label, false);
    }
  }
  if (getMissions)
  {  // return a list of available missions
    n = system("ls *.txt >missions.list");
    if (n >= 0)
    { // there should be a file
      mf = fopen("missions.list", "r");
      n = -1;
      if (mf != NULL)
      { // there is a file
        while (true)
        { // return all filenames in separate frames
          pMf = fgets(mfn, MFL, mf);
          if (pMf == NULL)
            break;
          if (n < 0)
            sendInfo(msg, "List of mission files:");
          i = strlen(pMf);
          if (i > 1)
          { // cut off the linefeed at end of line
            pMf[i-1] = 0;
            result = sendInfo(msg, pMf);
            n++;
          }
          if (not result)
            break;
        }
        if (n < 0)
          result = sendWarning(msg, "No mission files in default dir");
      }
      else
        result = sendWarning(msg, "Could not create listing of mission files");
      if (mf != NULL)
        fclose(mf);
      sendReply = true;
    }
  }
  if (getStatus)
  {
    sendStatusMessage(msg, msg->tag.getTagName());
    sendReply = true;
  }
    // last if - if noone else has send a reply ...
  if (getPgm)
  {
    if (seq->getLineCnt() > 0)
    { // make start tag for lines
      snprintf(reply, MRL,
               "<%s lineCnt=\"%d\" cmdLineNum=\"%d\" file=\"%s\">\n",
               msg->tag.getTagName(),
               seq->getLineCnt(),
               seq->getActiveLine(),
               seq->getPlanName());
      sendMsg(msg, reply);
      for (i = 0; i < seq->getLineCnt(); i++)
      {
        line = seq->getLine(i);
        str2xml(lineXml, MRL, line->getCmdLine());
        snprintf(reply, MRL,
                 "<seqLine ln=\"%d\" cmd=\"%s\"/>\n",
                 i, lineXml);
        result = sendMsg(msg, reply);
        if (not result)
            // stop if line-buffers are full
          break;
      }
        // and end tag (always try)
      snprintf(reply, MRL, "</%s>\n", msg->tag.getTagName());
      result = sendMsg(msg, reply);
    }
    else
    { // no plan lines - send status only
      snprintf(reply, MRL,
               "<%s lineCnt=\"%d\" cmdLineNum=\"%d\"/>\n",
               msg->tag.getTagName(),
               seq->getLineCnt(),
               seq->getActiveLine());
      sendMsg(msg, reply);
    }
    sendReply = true;
  }
  if (result and not sendReply)
    sendInfo(msg, "done");
  if (not result)
    sendWarning(msg, "One or more attributes to SEQ is not used!");
  return result;
}
예제 #11
0
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
int main(int argc, char *argv[])
{
	int rc;


	if (argc != 1)
	{
		if
		(
			(strcmp(argv[1], "-h")     == 0) ||
			(strcmp(argv[1], "-help")  == 0) ||
			(strcmp(argv[1], "--help") == 0)
		)
		{
			printf("example: %s\n", argv[0]);
			return 0;
		}
	}


	rc = uint2str();
	if (rc == -1) return 1;

	rc = sint2str();
	if (rc == -1) return 1;

	rc = is_hex();
	if (rc == -1) return 1;

	rc = is_udec();
	if (rc == -1) return 1;

	rc = is_sdec();
	if (rc == -1) return 1;

	rc = is_uint_string_overflow();
	if (rc == -1) return 1;

	rc = is_sint_string_overflow();
	if (rc == -1) return 1;

	rc = hex2uint();
	if (rc == -1) return 1;

	rc = hex2sint();
	if (rc == -1) return 1;

	rc = sign_expand();
	if (rc == -1) return 1;


/*
// convert dec string to uint
	bool dec2uint(uint64_t &result, uint64_t default_value, const char *pstr, size_t size);
	bool dec2uint(uint64_t &result, uint64_t default_value, const char *pstr);
	bool dec2uint(uint64_t &result, uint64_t default_value, const std::string &str);
	bool dec2uint(uint64_t &result, const char *pstr, size_t size);
	bool dec2uint(uint64_t &result, const char *pstr);
	bool dec2uint(uint64_t &result, const std::string &str);
*/

	rc = dec2sint();
	if (rc == -1) return 1;

	rc = str2uint();
	if (rc == -1) return 1;

	rc = str2bool();
	if (rc == -1) return 1;

/*
// convert byte to hex string
	const char *bin2hex(const uint8_t byte, bool flag_up = false);

// convert sibmol to number, example: '0' -> 0, 'F' -> 15
	bool hex2bin(uint8_t source, uint8_t &target);

// block read from handle
	size_t blk_read(int handle, off64_t offset, void *pdata, size_t size);

// block write to handle
	size_t blk_write(int handle, off64_t offset, const void *pdata, size_t size, bool flag_sync = false);

// block recv from handle
	size_t blk_recv(int handle, void *pdata, size_t size);

// block send to handle
	size_t blk_send(int handle, const void *pdata, size_t size);

// file open read only
	int file_open_ro(const char *pfilename);

// file open read/write
	int file_open_rw(const char *pfilename, bool flag_truncate = false, bool flag_excl = false);

// file close
	int file_close(int handle, bool flag_sync = false);

// read data from exist file
	int file_get(const char *pfilename, off_t offset, void *pdata, size_t data_size);
	int file_get(const char *pfilename, void **pdata, size_t *data_size);
	int file_get(const char *pfilename, std::string &data);

// write data to exist file
	int file_set(const char *pfilename, off_t offset, const void *pdata, size_t data_size, bool flag_sync = false, bool flag_truncate = false, bool flag_excl = false);
	int file_set(const char *pfilename, off_t offset, const std::string &data, bool flag_sync = false, bool flag_truncate = false, bool flag_excl = false);
	int file_set(const char *pfilename, const std::string &data, bool flag_sync = false, bool flag_truncate = false, bool flag_excl = false);

// return (concat str1 and str2) or NULL
	char *concat_str(const char *pstr1, const char *pstr2);

// get env var and convert to bool
	bool env2bool(bool &result, bool value_default, const char *pname);
*/

	rc = get_signal_name();
	if (rc == -1) return 1;

	rc = flip();
	if (rc == -1) return 1;

	rc = remove_file_ext();
	if (rc == -1) return 1;

/*
// check ipv4 string like '127.0.0.1'
	bool is_ipaddress(const char *str);

// set signal
	bool set_signal(int signo, void (*sig_handler)(int));

// string to lower
	void strtolower(const std::string &source, std::string &target);

// check pointer and strlen
	size_t strlen(const char *pstr);
*/

	rc = find();
	if (rc == -1) return 1;

	rc = bin2print();
	if (rc == -1) return 1;

	rc = rnd();
	if (rc == -1) return 1;


	return 0;
}
예제 #12
0
파일: commands.c 프로젝트: sahne/vitunes
int
cmd_set(int argc, char *argv[])
{
   const char *err;
   char *property;
   char *value;
   bool  tf;
   int   max_w, max_h, new_width;   /* lwidth */
   bool  player_is_setup;

   if (argc != 2) {
      paint_error("usage: %s <property>=<value>", argv[0]);
      return 1;
   }

   /* determine if the player has been setup (needed for redraws below) */
   player_is_setup = (player.name  != NULL)
                  && (*player.name != NULL);

   /* extract property and value */
   property = argv[1];
   if ((value = strchr(property, '=')) == NULL) {
      paint_error("usage: %s <property>=<value>", argv[0]);
      return 2;
   }
   *value = '\0';
   value++;

   /* handle property */

   if (strcasecmp(property, "lwidth") == 0) {
      /* get max width and height */
      getmaxyx(stdscr, max_h, max_w);

      /* validate and convert width user provided */
      new_width = (int)strtonum(value, 1, max_w, &err);
      if (err != NULL) {
         paint_error("%s %s: bad width: '%s' %s",
            argv[0], property, value, err);
         return 3;
      }

      /* resize & redraw (if we're past setup & curses is running) */
      ui.lwidth = new_width;
      ui_resize();
      if(player_is_setup && ui_is_init()) {
         ui_clear();
         paint_all();
      }

   } else if (strcasecmp(property, "lhide") == 0) {
      if (str2bool(value, &tf) < 0) {
         paint_error("%s %s: value must be boolean",
            argv[0], property);
         return 4;
      }
      ui.lhide = tf;
      if (ui.lhide) {
         if (ui.active == ui.playlist)
            ui_hide_library();
         if (player_is_setup && ui_is_init()) {
            ui_clear();
            paint_all();
            paint_message("library window hidden");
         }
      } else {
         if (ui.library->cwin == NULL) ui_unhide_library();
         if (player_is_setup && ui_is_init()) paint_all();
         paint_message("library window un-hidden");
      }

   } else if (strcasecmp(property, "match-fname") == 0) {
      if (str2bool(value, &tf) < 0) {
         paint_error("%s %s: value must be boolean",
            argv[0], property);
         return 5;
      }
      mi_query_match_filename = tf;
      if (mi_query_match_filename)
         paint_message("filenames will be matched against");
      else
         paint_message("filenames will NOT be matched against");

   } else if (strcasecmp(property, "save-sorts") == 0) {
      if (str2bool(value, &tf) < 0) {
         paint_error("%s %s: value must be boolean",
            argv[0], property);
         return 6;
      }
      sorts_need_saving = tf;
      if (sorts_need_saving)
         paint_message("changing sort will be prompted for saving");
      else
         paint_message("changing sort will NOT be prompted for saving");

   } else {
      paint_error("%s: unknown property '%s'", argv[0], property);
      return 7;
   }

   return 0;
}
예제 #13
0
파일: scriptlib.c 프로젝트: intgr/sc2-uqm
bool
scr_GetBoolean (const char *key)
{
	check_map_init ();
	return str2bool (scr_GetString (key));
}
예제 #14
0
void UClientFuncPath::handlePathPolygonData(USmlTag * iTag)
{
  bool result;
  USmlTag tag;
  const int MSL = 100;
  char att[MAX_SML_NAME_LENGTH];
  char val[MSL];
  int n, cnt = 0;
  //bool hasEdge = false;
  UPosition * pos;
  UTime t;
  bool * isObst;
  //
  iTag->getNextTag(&tag, 200);
  result = tag.isTagA("UProbPoly");
  if (not result)
  { // unknown tag
    printReply(&tag, "UClientFuncPath::handlePathPolygonData: not mine?");
    // skip the rest until endtag.
    if (tag.isAStartTag())
      tag.skipToEndTag(200);
  }
  if (result and not tag.isAStartTag())
  { // is just a message or a false
    result = false;
    tag.print("");
  }
  if (result)
  { // read size
    while (tag.getNextAttribute(att, val, MSL))
    {
      if (strcasecmp(att, "count") == 0)
        n = sscanf(val, "%d", &cnt);
      else if (strcasecmp(att, "obstFlags") == 0)
        ; //hasEdge = str2bool(val);
    }
    result = (cnt > 0);
  }
  if (result)
  { // now get the guts of the message
    // that is either time or polygon data
    pos = poly->getPoints();
    isObst = poly->getIsObst();
    n = 0;
    while (iTag->getNextTag(&tag, 200))
    {
      if (tag.isTagA("pos2db"))
      {
        pos->z=0.0;
        while (tag.getNextAttribute(att, val, MSL))
        { // read 2d position with obstacle flag
          if (strcasecmp(att, "x") == 0)
            sscanf(val, "%le", &pos->x);
          if (strcasecmp(att, "y") == 0)
            sscanf(val, "%le", &pos->y);
          if (strcasecmp(att, "obst") == 0)
            *isObst = str2bool(val);
        }
        // debug
        //if (verboseMessages)
        //  printf("Got %d pos2db at %f,%f obst(%s)\n",
        //    n, pos->x, pos->y, bool2str(*isObst));
        // debug
        if (n < poly->getPointsMax())
        { // advance --- if space
          n++;
          pos++;
          isObst++;
        }
      }
      else if (tag.isTagA("time"))
      {
        tag.getTime(&t);
        poly->setTime(t);
        // debug
        //if (verboseMessages)
        //  printf("Got time\n");
        // debug end
      }
      else
      { // either an unknown extra information or an end tag
        if (tag.isAnEndTag())
          break;
        if (tag.isAStartTag())
          // extra grouped info
          tag.skipToEndTag(200);
      }
    }
    poly->setPointsCnt(n);
    result = n > 0;
    // debug
    //if (verboseMessages)
    //  printf("Got %d positions in polygon\n", n);
    // debug end
  }
  if (result)
    newDataAvailable(poly);
}
예제 #15
0
// read tags for a standard menu item
UserMenuItem *UserMenuTree::readXmlMenuentry(const QDomElement &element)
{
	QString menutypename = element.attribute("type");
	UserMenuData::MenuType menutype = UserMenuData::xmlMenuType(menutypename);

	UserMenuItem *menuentryitem = new UserMenuItem(menutype, QString()) ;

	// default values
	QString title;
	QString plaintext;
	QString filename;
	QString parameter;
	QString icon;
	QString shortcut;
	bool needsSelection = false;
	bool useContextMenu = false;
	bool replaceSelection = false;
	bool selectInsertion = false;
	bool insertOutput = false;

	// read values
	if ( element.hasChildNodes() ) {
		QDomElement e = element.firstChildElement();
		while ( !e.isNull()) {
			QString tag = e.tagName();
			QString text = e.text();

			int index = UserMenuData::xmlMenuTag(tag);
			switch (index) {
				case  UserMenuData::XML_TITLE:            title = text;                       break;
				case  UserMenuData::XML_PLAINTEXT:        plaintext = text;                   break;
				case  UserMenuData::XML_FILENAME:         filename = text;                    break;
				case  UserMenuData::XML_PARAMETER:        parameter = text;                   break;
				case  UserMenuData::XML_ICON:             icon = text;                        break;
				case  UserMenuData::XML_SHORTCUT:         shortcut = text;                    break;
				case  UserMenuData::XML_NEEDSSELECTION:   needsSelection   = str2bool(text);  break;
				case  UserMenuData::XML_USECONTEXTMENU:   useContextMenu   = str2bool(text);  break;
				case  UserMenuData::XML_REPLACESELECTION: replaceSelection = str2bool(text);  break;
				case  UserMenuData::XML_SELECTINSERTION:  selectInsertion  = str2bool(text);  break;
				case  UserMenuData::XML_INSERTOUTPUT:     insertOutput     = str2bool(text);  break;
			}

			e = e.nextSiblingElement();
		}

		// save values
		menuentryitem->setMenutitle(title);

		// add code newline
		plaintext.replace("\\n","\n");
		menuentryitem->setPlaintext(plaintext);

		menuentryitem->setFilename(filename);
		menuentryitem->setParameter(parameter);
		if ( !icon.isEmpty() ) {
			menuentryitem->setMenuicon(icon);
			menuentryitem->setIcon(0,KIcon(icon));
		}
		if ( !shortcut.isEmpty() ) {
			QKeySequence seq = QKeySequence::fromString(shortcut,QKeySequence::PortableText);
			shortcut = seq.toString(QKeySequence::NativeText);

			menuentryitem->setShortcut(shortcut);
			menuentryitem->setText(1,shortcut);
		}
		menuentryitem->setNeedsSelection(needsSelection);
		menuentryitem->setUseContextMenu(useContextMenu);
		menuentryitem->setReplaceSelection(replaceSelection);
		menuentryitem->setSelectInsertion(selectInsertion);
		menuentryitem->setInsertOutput(insertOutput);

		menuentryitem->setText(0,title);
	}

	return menuentryitem;
}
예제 #16
0
static int
execQuery(char const *vserver, VserverTag tag, int argc, char *argv[])
{
  char const *		res = 0;
  char 			buf[sizeof(xid_t)*4 + 1024 + strlen(vserver)];

  memset(buf, 0, sizeof buf);
  switch (tag) {
    case tgNAME		:  res = vc_getVserverName(vserver, vcCFG_AUTO); break;
    case tgVDIR		:
      res = vc_getVserverVdir(vserver, vcCFG_AUTO, argc>0 && atoi(argv[0]));
      break;
    case tgCFGDIR	:  res = vc_getVserverCfgDir(vserver, vcCFG_AUTO);     break;
    case tgAPPDIR	:
      res = vc_getVserverAppDir(vserver, vcCFG_AUTO, argc==0 ? "" : argv[0]);
      break;
      
    case tgRUNNING	: {
      signed long		xid;	// type is a small hack, but should be ok...
      struct vc_vx_info		info;
	
      if (isNumber(vserver, &xid, true) && xid>=0)
	res = (vc_get_vx_info(xid, &info)==-1) ? 0 : "1";
      else
	res = (vc_getVserverCtx(vserver, vcCFG_AUTO, false, 0, vcCTX_XID)==VC_NOCTX) ? 0 : "1";
      
      break;
    }

    case tgCANONIFY	:
      strcpy(buf, vserver);
      if (canonifyVserverName(buf)>0) res = buf;
      break;
      
    case tgCONTEXT	:  res = getContext(buf, vserver,
					    argc==0 || str2bool(argv[0])); break;
    case tgINITPID_PID	:  res = getInitPidPid(buf, vserver);  break;
    case tgAPIVER	:  res = getAPIVer(buf);               break;
    case tgXID		:  res = getXid(buf, vserver);         break;
    case tgPXID		:  res = getPXid(buf, vserver);        break;
    case tgSYSINFO	:  return printSysInfo(buf);           break;
    case tgFEATURE	:  return testFeature(argc,argv);      break;
    case tgVERIFYCAP	:  return verifyCap() ? 0 : 1;         break;
    case tgVERIFYPROC	:  return verifyProc() ? 0 : 1;        break;
    case tgNID		:  res = getNid(buf, vserver);         break;
    case tgTAG		:  res = getTag(buf, vserver);         break;


    default		: {
      xid_t		xid = *vserver!='\0' ? vc_xidopt2xid(vserver,true,0) : VC_SAMECTX;

      switch (tag) {
	case tgID	:  res = vc_getVserverByCtx(xid,0,0);  break;
	case tgINITPID	:  res = getInitPid(buf, xid);         break;
	case tgUTS	:  res = getUTS(buf, xid, argc, argv); break;
	case tgXIDTYPE	:  res = getXIDType(xid, argc, argv);  break;
    
	default		:  assert(false); abort();  // TODO
      }
    }
  }

  if (res==0) return EXIT_FAILURE;
  WRITE_STR(1, res);
  WRITE_MSG(1, "\n");
  return EXIT_SUCCESS;
}
예제 #17
0
static smcp_status_t
smcp_group_variable_handler(
	smcp_variable_handler_t node,
	uint8_t action,
	uint8_t i,
	char* value
) {
	smcp_status_t ret = SMCP_STATUS_OK;
	smcp_group_t group = (smcp_group_t)node;

	if (i >= I_COUNT) {
		ret = SMCP_STATUS_NOT_FOUND;
		goto bail;
	}

	if (action == SMCP_VAR_GET_KEY) {
		strcpy(value, names[i]);

	} else if (action == SMCP_VAR_GET_LF_TITLE) {
		strcpy(value, lf_title[i]);

	} else if (action == SMCP_VAR_GET_OBSERVABLE) {
		switch (i) {
		case I_STABLE:
		case I_ENABLED:
			ret = SMCP_STATUS_OK;
			break;
		case I_FQDN:
		case I_ADDR:
			ret = SMCP_STATUS_NOT_IMPLEMENTED;
			break;
		}

	} else if (action == SMCP_VAR_GET_VALUE) {
		switch (i) {
		case I_STABLE:
			int32_to_dec_cstr(value, group->stable);
			break;
		case I_ENABLED:
			int32_to_dec_cstr(value, group->enabled);
			break;
		case I_FQDN:
			strcpy(value, group->fqdn);
			break;
		case I_ADDR:
			SMCP_ADDR_NTOP(value, SMCP_VARIABLE_MAX_VALUE_LENGTH, &group->addr);
			break;
		}

	} else if (action == SMCP_VAR_SET_VALUE) {
		switch (i) {
		case I_STABLE:
			ret = smcp_group_set_stable(group, str2bool(value));
			break;
		case I_ENABLED:
			ret = smcp_group_set_enabled(group, str2bool(value));
			break;
		case I_FQDN:
		case I_ADDR:
			ret = SMCP_STATUS_NOT_IMPLEMENTED;
			break;
		}

	} else {
		ret = SMCP_STATUS_NOT_IMPLEMENTED;
	}

bail:
	return ret;
}