Ejemplo n.º 1
0
void main( string str ) {
  string *names;
  string name;
  string value;
  int i;

  if( !str || str == "" ) {
    /* Print out the list */
    names = this_player()->query_env_indices();
    for( i = 0; i < sizeof( names ); i++ ) {
      out_unmod( names[i] + "=" + this_player()->query_env( names[i] ) + "\n" ); 
    }
  } else {
    if( sscanf( str, "%s %s", name, value ) != 2 ) {
      write( "Usage: set <variable> <value>\n" );
      return;
    } else {
      if( str2val( value ) != -1 ) {
	/* We've got a value */
	this_player()->set_env( name, str2val(value) );
      } else {
	this_player()->set_env( name, value );
      }
    }
  }
}
Ejemplo n.º 2
0
/*
 * Convert a row from result into db API representation
 */
int convert_row(db_con_t* _h, db_res_t* _res, db_row_t* _r)
{
	unsigned long* lengths;
	int i;
#ifndef PARANOID
	if ((!_h) || (!_r) || (!_n)) {
		log(L_ERR, "convert_row(): Invalid parameter value\n");
		return -1;
	}
#endif

	ROW_VALUES(_r) = (db_val_t*)pkg_malloc(sizeof(db_val_t) * RES_COL_N(_res));
	ROW_N(_r) = RES_COL_N(_res);
	if (!ROW_VALUES(_r)) {
		LOG(L_ERR, "convert_row(): No memory left\n");
		return -1;
	}

	lengths = mysql_fetch_lengths(CON_RESULT(_h));

	for(i = 0; i < RES_COL_N(_res); i++) {
		if (str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]), 
			    ((MYSQL_ROW)CON_ROW(_h))[i], lengths[i]) < 0) {
			LOG(L_ERR, "convert_row(): Error while converting value\n");
			free_row(_r);
			return -3;
		}
	}
	return 0;
}
Ejemplo n.º 3
0
static int _epgcfg_from_str(const char *str)
{
  static struct strtab cfgs[] = {
    { "0",                 MM_EPG_DISABLE },
    { "none",              MM_EPG_DISABLE },
    { "disable",           MM_EPG_DISABLE },
    { "off",               MM_EPG_DISABLE },
    { "1",                 MM_EPG_ENABLE },
    { "all",               MM_EPG_ENABLE },
    { "enable",            MM_EPG_ENABLE },
    { "on",                MM_EPG_ENABLE },
    { "force",             MM_EPG_FORCE },
    { "eit",               MM_EPG_ONLY_EIT },
    { "uk_freesat",        MM_EPG_ONLY_UK_FREESAT },
    { "uk_freeview",       MM_EPG_ONLY_UK_FREEVIEW },
    { "viasat_baltic",     MM_EPG_ONLY_VIASAT_BALTIC },
    { "opentv_sky_uk",     MM_EPG_ONLY_OPENTV_SKY_UK },
    { "opentv_sky_italia", MM_EPG_ONLY_OPENTV_SKY_ITALIA },
    { "opentv_sky_ausat",  MM_EPG_ONLY_OPENTV_SKY_AUSAT },
    { "bulsatcom_39e",     MM_EPG_ONLY_BULSATCOM_39E },
    { "psip",              MM_EPG_ONLY_PSIP },
    { NULL }
  };
  return str ? str2val(str, cfgs) : -1;
}
bool
AsciiProcessor::emp_cmd( const char * buf,
                         BuilderBase * build,
                         const char * & next )
{
    int fref;

    if ( ! str2val( buf, fref, next ) )
    {
        P_ERROR( "EMP no frame reference" );
        return CMD_ERR;
    }

    buf = next;

    if ( ! strskip( buf, DELIMITER_CHAR, next ) )
    {
        P_ERROR( "wrong delimiter char" );
        return CMD_ERR;
    }

    build->set_cmd_empty_frame( fref );

    P_MSG( "build->set_cmd_empty_frame(" << fref << ");" );

    return CMD_OK;
}
bool
AsciiProcessor::visible_cmd( const char * buf,
                             BuilderBase * build,
                             const char * & next,
                             int visible )
{
    int fref;

    if ( ! str2val( buf, fref, next ) )
    {
        P_ERROR( "no frame reference" );
        return CMD_ERR;
    }

    buf = next;

    if ( ! strskip( buf, DELIMITER_CHAR, next ) )
    {
        P_ERROR( "wrong delimiter char" );
        return CMD_ERR;
    }

    P_MSG( "build->set_cmd_set_frame_visible(" << fref << ");" );

    if ( ! build->set_cmd_set_frame_visible( fref, visible ) )
    {
        P_ERROR( "wrong frame reference" );
    }

    return CMD_OK;
}
Ejemplo n.º 6
0
muxer_cache_type_t
muxer_cache_txt2type(const char *str)
{
  int r = str2val(str, cache_types);
  if (r < 0)
    r = MC_CACHE_UNKNOWN;
  return r;
}
Ejemplo n.º 7
0
/**
 * Convert a mime-string to a container type
 */
muxer_container_type_t
muxer_container_mime2type(const char *str)
{
  muxer_container_type_t mc;

  if(!str)
    return MC_UNKNOWN;

  mc = str2val(str, container_video_mime);
  if(mc == -1)
    mc = str2val(str, container_audio_mime);

  if(mc == -1)
    return MC_UNKNOWN;

  return mc;
}
bool
AsciiProcessor::del_cmd( const char * buf,
                         BuilderBase * build,
                         const char* & next )
{
    int fref;

    if ( ! str2val( buf, fref, next ) )
    {
        P_ERROR( "DEL no frame or object reference" );
        return CMD_ERR;
    }

    buf = next;

    int oref;

    if ( str2val( buf, oref, next ) )
    {
        buf = next;

        if ( ! strskip( buf, DELIMITER_CHAR, next ) )
        {
            P_ERROR( "wrong delimiter char" );
            return CMD_ERR;
        }

        build->set_cmd_remove_object( fref, oref );

        P_MSG( "build->set_cmd_remove_object(fref,oref);" );
        return CMD_OK;
    }

    if ( ! strskip( buf, DELIMITER_CHAR, next ) )
    {
        P_ERROR( "wrong delimiter char" );
        return CMD_ERR;
    }

    build->set_cmd_remove_frame( fref );

    P_MSG( "build->set_cmd_remove_frame(fref);" );

    return CMD_OK;
}
Ejemplo n.º 9
0
static void set_prime(BIGNUM *p, char *str)
{
    size_t len = 0;
    unsigned char *prime;

    prime = (unsigned char *)str2val(str, 16, &len);
    if (prime == NULL)
	errx(1, "failed to parse %s", str);
    BN_bin2bn(prime, len, p);
}
Ejemplo n.º 10
0
static int
glw_segway_set_rstr_unresolved(glw_t *w, const char *a, rstr_t *value,
                               glw_style_t *gs)
{
  if(!strcmp(a, "direction")) {
    glw_segway_t *s = (glw_segway_t *)w;
    s->direction = str2val(rstr_get(value), segway_directions);
    return GLW_SET_RERENDER_REQUIRED;
  }
  return GLW_SET_NOT_RESPONDING;
}
Ejemplo n.º 11
0
static int
set_align(glw_view_eval_context_t *ec, const token_attrib_t *a, 
	  struct token *t)
{
  int v;
  if(t->type != TOKEN_IDENTIFIER || (v = str2val(rstr_get(t->t_rstring), aligntab)) < 0)
    return glw_view_seterr(ec->ei, t, "Invalid assignment for attribute %s",
			    a->name);
  ec->w->glw_alignment = v;
  return 0;
}
Ejemplo n.º 12
0
static int
set_transition_effect(glw_view_eval_context_t *ec, const token_attrib_t *a, 
		      struct token *t)
{
  int v;
  if(t->type != TOKEN_IDENTIFIER || (v = str2val(rstr_get(t->t_rstring),
						 transitiontab)) < 0)
    return glw_view_seterr(ec->ei, t, "Invalid assignment for attribute %s",
			    a->name);
  glw_set(ec->w, GLW_ATTRIB_TRANSITION_EFFECT, v, NULL);
  return 0;
}
bool
AsciiProcessor::mov_cmd( const char * buf,
                         BuilderBase * build,
                         const char* & next )
{
    int fref;
    Point2d pos;
    Angle ang;

    if ( ! str2val( buf, fref, next ) )
    {
        P_ERROR( "MOV no frame reference specified" );
        return CMD_ERR;
    }

    buf = next;

    int res = get_frame( buf, pos, ang, next );

    if ( res < 1 )
    {
        return CMD_ERR;
    }

    if ( ! strskip( next, DELIMITER_CHAR, next ) )
    {
        return CMD_ERR;
    }

    switch ( res )
    {

    case 3:
        build->set_cmd_set_frame_pos_ang( fref, pos, ang );
        P_MSG( "build->set_cmd_set_frame_pos_ang(fref,(" << pos.x << "," << pos.y << ")," << ang.get_value() << ");" );
        break;

    case 2:
        build->set_cmd_set_frame_pos( fref, pos );
        P_MSG( "build->set_cmd_set_frame_pos(fref,pos)" );
        break;

    case 1:
        build->set_cmd_set_frame_ang( fref, ang );
        P_MSG( "build->set_cmd_set_frame_ang(fref,ang);" );
        break;
    }

    return CMD_OK;
}
Ejemplo n.º 14
0
/**
 * Convert a container name to a container type
 */
muxer_container_type_t
muxer_container_txt2type(const char *str)
{
  muxer_container_type_t mc;
  
  if(!str)
    return MC_UNKNOWN;

  mc = str2val(str, container_name);
  if(mc == -1)
    return MC_UNKNOWN;

  return mc;
}
Ejemplo n.º 15
0
static ssize_t log_proc_write(struct file *f, const char *buf, size_t cnt, loff_t *pos) {
    int i;
#define MAX_ARGS 5
#define MAX_ARG_SIZE 32
    typedef char arg_t[MAX_ARG_SIZE];
    arg_t arg[MAX_ARGS];
    int argc;
    char cmd;
    bcmLogModuleInfo_t *pModInfo;
#define LOG_WR_KBUF_SIZE 128
    char kbuf[LOG_WR_KBUF_SIZE];

    if ((cnt > LOG_WR_KBUF_SIZE-1) || (copy_from_user(kbuf, buf, cnt) != 0))
        return -EFAULT;

    kbuf[cnt]=0;

    argc = sscanf(kbuf, "%c %s %s %s %s %s", &cmd, arg[0], arg[1], arg[2], arg[3], arg[4]);

    for (i=0; i<MAX_ARGS; ++i) {
        arg[i][MAX_ARG_SIZE-1] = '\0';
    }

    BCM_LOG_INFO(BCM_LOG_ID_LOG, "WRITE: cmd: %c, argc: %d", cmd, argc);
    for (i=0; i<argc-1; ++i) {
        BCM_LOG_INFO(BCM_LOG_ID_LOG, "arg[%d]: %s ", i, arg[i]);
    }

    switch ( cmd ) {
        BCM_LOGCODE(
            case 'g':
            {
                bcmLogLevel_t logLevel = str2val(arg[0]);
                if(argc == 2 && logLevel >= 0 && logLevel < BCM_LOG_LEVEL_MAX)
                    globalLogLevel = logLevel;
                else
                    BCM_LOG_ERROR(BCM_LOG_ID_LOG, "Invalid Parameter '%s'\n", arg[0]);
                break;
            } )

        BCM_LOGCODE(
            case 'r':
            {
                bcmPrint ("Global Log Level : %d\n", globalLogLevel);
                break;
            } )
Ejemplo n.º 16
0
main (int argc, char *argv[]) {

  int i, j, k, c;
  struct HRAW hraw, hraw2;
  struct HSTR hstr, hstr2;
  struct HVAL hval, hval2;
  char *pname, *fin, *fout;
  char fgas[100];
  FILE *infid, *outfid;
  FILE *gasfid[MAXGAS];

  /* options defaults */
  int 	  gasid  = 0;
  int     isonum = 0;
  double  wL     = 0;
  double  wU     = 30000;
  double  smin   = 0;
  int     bflag  = 0;
  int     outfmt = 0;
  int     debug  = 1;

  extern int getopt();
  extern char *optarg;
  extern int   optind;
  extern char *sbase();

  pname = argv[0];

  while ((c=getopt(argc, argv, "g:i:L:U:s:brd")) != EOF)
    switch (c) {

    case 'g':    /* select a particular gas id */
      gasid = atoi(optarg);
      break;

    case 'i':    /* select a particular isotope */
      isonum = atoi(optarg);
      break;

    case 'L':    /* wavenumber lower bound */
      wL = atof(optarg);
      break;

    case 'U':    /* wavenumber upper bound */
      wU = atof(optarg);
      break;

    case 's':    /* specify a line strength threshold */
      smin = atof(optarg);
      break;

    case 'b':    /* break database into individual gasses */
      bflag = 1;
      break;

    case 'r':    /* readable output */
      outfmt = 1;
      break;

    case 'd':    /* debugging info */
      debug = 1;
      break;

    case '?':    /* bad command */
      exit(1);
      break;
    }

  if (argc - optind < 1) {
    fprintf(stderr, "%s: error -- no input file specified\n", pname);
    exit(1);
  }
  fin = argv[optind++];

  if (argc - optind == 1)
    fout = argv[optind++];
  else
    fout = "-";

  if (debug) {
    fprintf(stderr, "fin = %s, fout = %s\n", fin, fout);
    fprintf(stderr, "bflag = %d, gasid = %d, smin = %g, L = %g, U = %g\n", 
	    bflag, gasid, smin, wL, wU);
  }

  /* open input file
   */
  if (strcmp(fin, "-") == 0) 
    infid = stdin;
  else if ((infid = fopen(fin, "r")) == NULL) {
    fprintf(stderr, "%s: can't open input file %s", pname, fin);
    exit(0);
  }

  if (!bflag) {

    /*  SELECT MODE: write a selected subset of the input file 
     *  to the output file
     */
    if (strcmp(fout, "-") == 0) 
      outfid = stdout;
    else if ((outfid = fopen(fout, "w")) == NULL) {
      fprintf(stderr, "%s: can't open output file %s", pname, fout);
      exit(0);
    }

    while (fread(&hraw, sizeof(hraw), 1, infid) == 1) {

      raw2str(&hraw, &hstr);
      str2val(&hstr, &hval);

      if ((gasid == 0 || hval.IGAS == gasid) &&
	  (isonum == 0 || hval.ISO == isonum) &&
	  hval.WNUM >= wL &&
	  hval.WNUM <= wU &&
	  hval.STREN >= smin) {
	if (outfmt == 0) 
	  write_hraw(&hraw, outfid);
	else if (outfmt == 1)
	  write_hval(&hval, outfid);
      }
    }
    fclose(outfid);
  }
  else {

    /*  SPLIT MODE: separate input file into componant gasses, 
     *  one gas per file, in a common directory
     */
    if (strcmp(fout, "-") == 0) {
      fprintf(stderr, "%s: output directory can't be stdout!\n", pname);
      exit(127);
    }
    else if (mkdir(fout, 0755) == -1) {
      fprintf(stderr, 
	      "%s: can't create output directory %s\n", 
	      pname, fout);
      exit(127);
    }
    
     for (i=0; i<MAXGAS; i++) gasfid[i] = NULL;

     while (fread(&hraw, sizeof(hraw), 1, infid) == 1) {

       raw2str(&hraw, &hstr);
       str2val(&hstr, &hval);

       if (gasfid[hval.IGAS] == NULL) {

	 /* open output file for new gas  
	  */
	 sprintf(fgas, "%s/g%d.dat", fout, hval.IGAS);
          
	 if ((gasfid[hval.IGAS] = fopen(fgas, "w")) == NULL) {
	   fprintf(stderr, "%s: can't open output file %s\n", pname, fgas);
	   exit(0);
	 }
       }

       if ((isonum == 0 || hval.ISO == isonum) &&
	   hval.WNUM >= wL &&
	   hval.WNUM <= wU &&
	   hval.STREN >= smin) {
	 if (outfmt == 0) 
	   write_hraw(&hraw, gasfid[hval.IGAS]);
	 else if (outfmt == 1)
	   write_hval(&hval, gasfid[hval.IGAS]);
       }
     }
     for (i=0; i<MAXGAS; i++)
       if (gasfid[i] != NULL)
	 fclose(gasfid[i]);
  } 
}
bool
AsciiProcessor:: get_obj_attr( const char * buf,
                               int & id,
                               int & lay,
                               RGBcolor & col,
                               int & fil,
                               char const * & next )
{
    next = buf;
    bool got_attr[4] = { false, false, false, false };

    while ( next )
    {
        if ( strskip( buf, "id", next ) )
        {
            if ( got_attr[0] )
            {
                return false;
            }

            got_attr[0] = true;

            buf = next;

            if ( ! strskip( buf, "=", next ) )
            {
                return false;
            }

            buf = next;

            if ( ! str2val( buf, id, next ) )
            {
                return false;
            }

            buf = next;
        }
        else if ( strskip( buf, "lay", next ) )
        {
            if ( got_attr[1] )
            {
                return false;
            }

            got_attr[1] = true;

            buf = next;

            if ( ! strskip( buf, "=", next ) )
            {
                return false;
            }

            buf = next;

            if ( ! str2val( buf, lay, next ) )
            {
                return false;
            }

            buf = next;
        }
        else if ( strskip( buf, "col", next ) )
        {
            if ( got_attr[2] )
            {
                return false;
            }

            got_attr[2] = true;

            buf = next;

            if ( ! strskip( buf, "=", next ) )
            {
                return false;
            }

#if 0
            buf = next;

            if ( ! strskip( buf, "#", next ) )
            {
                return false;
            }

#endif
            buf = next;

            if ( ! get_col( buf, col, next ) )
            {
                P_ERROR( "wrong color [" << buf << "]" );
                return false;
            }

            buf = next;

            //if ( !strconv(buf,col,next) )
            //return false;
            buf = next;
        }
        else if ( strskip( buf, "fil", next ) )
        {
            if ( got_attr[3] )
            {
                return false;
            }

            got_attr[3] = true;

            buf = next;

            if ( ! strskip( buf, "=", next ) )
            {
                return false;
            }

            buf = next;

            bool b;

            if ( ! str2val( buf, b, next ) )
            {
                return false;
            }

            fil = b;

            buf = next;
        }
        else
        {
            next = buf;
            return true;
        }
    }

    next = buf;

    return true;
}
Ejemplo n.º 18
0
int
dvb_str_to_adaptertype(const char *str)
{
  return str2val(str, adaptertype);
}
Ejemplo n.º 19
0
int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
{
    if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
        ipmi_set_usage();
        return -1;
    }

    /* these options can have no arguments */
    if (strncmp(argv[0], "verbose", 7) == 0) {
        verbose = (argc > 1) ? atoi(argv[1]) : verbose+1;
        return 0;
    }
    if (strncmp(argv[0], "csv", 3) == 0) {
        csv_output = (argc > 1) ? atoi(argv[1]) : 1;
        return 0;
    }

    /* the rest need an argument */
    if (argc == 1) {
        ipmi_set_usage();
        return -1;
    }

    if (strncmp(argv[0], "host", 4) == 0 ||
            strncmp(argv[0], "hostname", 8) == 0) {
        ipmi_intf_session_set_hostname(intf, argv[1]);
        printf("Set session hostname to %s\n", intf->session->hostname);
    }
    else if (strncmp(argv[0], "user", 4) == 0 ||
             strncmp(argv[0], "username", 8) == 0) {
        ipmi_intf_session_set_username(intf, argv[1]);
        printf("Set session username to %s\n", intf->session->username);
    }
    else if (strncmp(argv[0], "pass", 4) == 0 ||
             strncmp(argv[0], "password", 8) == 0) {
        ipmi_intf_session_set_password(intf, argv[1]);
        printf("Set session password\n");
    }
    else if (strncmp(argv[0], "authtype", 8) == 0) {
        int authtype;
        authtype = str2val(argv[1], ipmi_authtype_session_vals);
        if (authtype == 0xFF) {
            lprintf(LOG_ERR, "Invalid authtype: %s", argv[1]);
        } else {
            ipmi_intf_session_set_authtype(intf, authtype);
            printf("Set session authtype to %s\n",
                   val2str(intf->session->authtype_set, ipmi_authtype_session_vals));
        }
    }
    else if (strncmp(argv[0], "privlvl", 7) == 0) {
        int privlvl;
        privlvl = str2val(argv[1], ipmi_privlvl_vals);
        if (privlvl == 0xFF) {
            lprintf(LOG_ERR, "Invalid privilege level: %s", argv[1]);
        } else {
            ipmi_intf_session_set_privlvl(intf, privlvl);
            printf("Set session privilege level to %s\n",
                   val2str(intf->session->privlvl, ipmi_privlvl_vals));
        }
    }
    else if (strncmp(argv[0], "port", 4) == 0) {
        int port = atoi(argv[1]);
        ipmi_intf_session_set_port(intf, port);
        printf("Set session port to %d\n", intf->session->port);
    }
    else if (strncmp(argv[0], "localaddr", 9) == 0) {
        intf->my_addr = (uint8_t)strtol(argv[1], NULL, 0);
        printf("Set local IPMB address to 0x%02x\n", intf->my_addr);
    }
    else if (strncmp(argv[0], "targetaddr", 10) == 0) {
        intf->target_addr = (uint8_t)strtol(argv[1], NULL, 0);
        printf("Set remote IPMB address to 0x%02x\n", intf->target_addr);
    }
    else {
        ipmi_set_usage();
        return -1;
    }
    return 0;
}
bool
AsciiProcessor::scan_and_parse( BuilderBase * build,
                                const char * buf )
{
    while ( buf )
    {
        while ( *buf == ' ' || *buf == '\n' || *buf == '\t' )
        {
            buf++;
        }

        if ( *buf == '\0' )
        {
            break;
        }

        const char * next = buf;

        bool res = false;

        int fref = 0;

        switch ( buf[0] )
        {
            //------------------------------------------------------------------------

        case 'B':

            if ( buf[1] == 'G' )
            {
                if ( background_color_cmd( buf + 2, build, next ) )
                {
                    res = true;
                    buf = next;
                    //cout << "col set" << flush;
                }
            }

            break;

            //------------------------------------------------------------------------

        case 'M':

            if ( buf[1] == 'O' && buf[2] == 'V' )
            {
                if ( mov_cmd( buf + 3, build, next ) )
                {
                    res = true;
                    buf = next;
                }
            }

            break;

            //------------------------------------------------------------------------

        case  'S':

            if ( buf[1] == 'L' )
            {
                if ( status_line_cmd( buf + 2, build, next ) )
                {
                    res = true;
                    buf = next;
                }
            }
            else if ( buf[1] == 'H' && buf[2] == 'O' && buf[3] == 'W' )
            {
                if ( visible_cmd( buf + 4, build, next, 1 ) )
                {
                    res = true;
                    buf = next;
                    //cout << "\nSHOW";
                }
            }

            break;

            //------------------------------------------------------------------------

        case  'H':

            if ( buf[1] == 'I' && buf[2] == 'D' && buf[3] == 'E' )
            {
                if ( visible_cmd( buf + 4, build, next, 0 ) )
                {
                    res = true;
                    buf = next;
                }
            }

            break;

            //------------------------------------------------------------------------

        case  'D':

            if ( buf[1] == 'E' && buf[2] == 'L' )
            {
                if ( del_cmd( buf + 3, build, next ) )
                {
                    res = true;
                    buf = next;
                }
            }

            break;

            //------------------------------------------------------------------------

        case  'E':

            if ( buf[1] == 'M' && buf[2] == 'P' )
            {
                if ( emp_cmd( buf + 3, build, next ) )
                {
                    res = true;
                    buf = next;
                }
            }

            break;

            //------------------------------------------------------------------------

        case 'I':

            if ( buf[1] == 'N' && buf[2] == 'S' )
            {
                buf += 3;
                fref = 0;

                if ( str2val( buf, fref, next ) )
                    buf = next;

                if ( ins_obj( buf, fref, build, next ) )
                {
                    res = true;
                    buf = next;
                }
            }

            break;

            //------------------------------------------------------------------------

        case  'V':

            if ( buf[1] == 'A' )
                if ( visual_area_cmd( buf + 2, build, next ) )
                {
                    res = true;
                    buf = next;
                }

            break;

            //------------------------------------------------------------------------
        }

        if ( !res )
        {
            P_ERROR( "unrecognized command "
                     << "\nmsg= [" << buf << "]"
                     << "\nerr= [" << next << "]" );
            return false;//break;
        }

        //P_MSG("buf [" << buf << "]");
    }

    return true;
}
/*!

  \retval 0 a empty tuple was received "()"
  \retval 1 a one tuple "( <num> )"
  \retval 2,3,4,5 analogous with 1
  \retval -1: the was no tuple at all, i.e. the string doesn't begin with a '('
  \retval -2: some failure occured
*/
int
AsciiProcessor::get_max5_tuple( const char * buf,
                                int num,
                                double & d0,
                                double & d1,
                                double & d2,
                                double & d3,
                                double & d4,
                                char const * & next )
{
    if ( ! strskip( buf, '(', next ) )
    {
        return -1;
    }

    buf = next;

    if ( ! str2val( buf, d0, next ) )
    {
        if ( strskip( buf, ')', next ) )
        {
            return 0;
        }

        return -2;
    }

    if ( num < 1 ) return -2;

    buf = next;

    if ( ! strskip( buf, ',', next ) )
    {
        if ( strskip( buf, ')', next ) )
        {
            return 1;
        }

        return -2;
    }

    if ( num < 2 ) return -2;

    buf = next;

    if ( ! str2val( buf, d1, next ) )
    {
        return -2;
    }

    buf = next;

    if ( !strskip( buf, ',', next ) )
    {
        if ( strskip( buf, ')', next ) )
        {
            return 2;
        }

        return -2;
    }

    if ( num < 3 ) return -2;

    buf = next;

    if ( !str2val( buf, d2, next ) )
    {
        return -2;
    }

    buf = next;

    if ( ! strskip( buf, ',', next ) )
    {
        if ( strskip( buf, ')', next ) )
        {
            return 3;
        }

        return -2;
    }

    if ( num < 4 ) return -2;

    buf = next;

    if ( ! str2val( buf, d3, next ) )
    {
        return -2;
    }

    buf = next;

    if ( ! strskip( buf, ',', next ) )
    {
        if ( strskip( buf, ')', next ) )
        {
            return 4;
        }

        return -2;
    }

    if ( num < 5 ) return -2;

    buf = next;

    if ( ! str2val( buf, d4, next ) )
    {
        return -2;
    }

    buf = next;

    if ( ! strskip( buf, ')', next ) )
    {
        return -2;
    }

    return 5;
}
bool
AsciiProcessor::ins_string_grid( const char * buf,
                                 int fref,
                                 BuilderBase * build,
                                 const char * & next )
{
    int id = 0, lay = 0, fil = 0;
    RGBcolor col( 0, 0, 0 );

    if ( ! get_obj_attr( buf, id, lay, col, fil, next ) )
    {
        return CMD_ERR;
    }

    while ( true )
    {
        double p_x, p_y, v1_x, v1_y, v2_x, v2_y, d3, d4, d5;
        int num_v1 = 1, num_v2 = 1;

        if ( ! strskip( next, '(', next ) )
        {
            return CMD_ERR;
        }

        if ( get_max5_tuple( next, 2, p_x, p_y, d3, d4, d5, next ) != 2 )
        {
            return CMD_ERR;
        }

        if ( get_max5_tuple( next, 2, v1_x, v1_y, d3, d4, d5, next ) != 2 )
        {
            return CMD_ERR;
        }

        if ( strskip( next, ':', next ) )
        {
            if ( ! str2val( next, num_v1, next ) )
            {
                return CMD_ERR;
            }
        }

        if ( get_max5_tuple( next, 2, v2_x, v2_y, d3, d4, d5, next ) != 2 )
        {
            return CMD_ERR;
        }

        if ( strskip( next, ':', next ) )
        {
            if ( ! str2val( next, num_v2, next ) )
            {
                return CMD_ERR;
            }
        }

        const double  d1 = 1.0 / double( num_v1 );

        const double  d2 = 1.0 / double( num_v2 );

        bool early_stop = false;

        for ( int i = 0; i < num_v2; ++i )
        {
            Point2d point;
            point.x = p_x + i * v2_x * d2 ;
            point.y = p_y + i * v2_y * d2 ;

            for ( int j = 0; j < num_v1; j++ )
            {
                int offset;

                if ( strskip( next, ')', next ) )
                {
                    early_stop = true;
                    break;
                }

                buf = next;

                int res = get_string( buf, offset, next );

                if ( res < 0 )
                {
                    return CMD_ERR;
                }

                VisualObject2d * string2d = new VisualString2d( id, lay, col, point, res, buf + offset );

                build->set_cmd_insert_visobject( fref, string2d );

                point.x += v1_x * d1;
                point.y += v1_y * d1;
            }

            if ( early_stop )
            {
                break;
            }
        }

        if ( ! early_stop )
        {
            if ( ! strskip( next, ')', next ) )
            {
                return CMD_ERR;
            }
        }

        if ( strskip( next, DELIMITER_CHAR, next ) )
        {
            break;
        }
    }

    return CMD_OK;
}
bool
AsciiProcessor::ins_grid( const char * buf,
                          int fref,
                          BuilderBase * build,
                          const char * & next )
{
    int id = 0, lay = 0, fil = 0;
    RGBcolor col( 0, 0, 0 );

    if ( ! get_obj_attr( buf, id, lay, col, fil, next ) )
    {
        return CMD_ERR;
    }

    int idx = 0;

    while ( true ) //accept more then one grid!
    {
        double p_x, p_y, v1_x, v1_y, v2_x, v2_y, d3, d4, d5;
        int num_v1 = 1, num_v2 = 1;

        if ( ! strskip( next, '(', next ) )
        {
            return CMD_ERR;
        }

        if ( get_max5_tuple( next, 2, p_x, p_y, d3, d4, d5, next ) != 2 )
        {
            return CMD_ERR;
        }

        if ( get_max5_tuple( next, 2, v1_x, v1_y, d3, d4, d5, next ) != 2 )
        {
            return CMD_ERR;
        }

        if ( strskip( next, ':', next ) )
        {
            if ( ! str2val( next, num_v1, next ) )
            {
                return CMD_ERR;
            }
        }

        if ( get_max5_tuple( next, 2, v2_x, v2_y, d3, d4, d5, next ) != 2 )
        {
            return CMD_ERR;
        }

        if ( strskip( next, ':', next ) )
        {
            if ( ! str2val( next, num_v2, next ) )
            {
                return CMD_ERR;
            }
        }

        if ( ! strskip( next, ')', next ) )
        {
            return CMD_ERR;
        }

        lines.set_cur_size( idx );

        lines.set_max_size_and_preserve_cur_size( idx + num_v1 + num_v2 + 2 );

        const double  d1 = 1.0 / double( num_v1 );

        const double  d2 = 1.0 / double( num_v2 );

        for ( int i = 0; i < num_v2 + 1; ++i )
        {
            Line2d & l = lines.tab[idx];
            l.p1.x = p_x + i * v2_x * d2 ;
            l.p1.y = p_y + i * v2_y * d2 ;
            l.p2.x = l.p1.x + v1_x;
            l.p2.y = l.p1.y + v1_y;
            idx++;
        }

        for ( int i = 0; i < num_v1 + 1; ++i )
        {
            Line2d & l = lines.tab[idx];
            l.p1.x = p_x + i * v1_x * d1 ;
            l.p1.y = p_y + i * v1_y * d1 ;
            l.p2.x = l.p1.x + v2_x;
            l.p2.y = l.p1.y + v2_y;
            idx++;
        }

        if ( strskip( next, DELIMITER_CHAR, next ) )
        {
            break;
        }
    }

    build->set_cmd_insert_lines( fref, id, idx, lines.tab, lay, col );

    return CMD_OK;
}
bool
AsciiProcessor::ins_string( const char * buf,
                            int fref,
                            BuilderBase * build,
                            const char * & next )
{
    int id = 0, lay = 0, fil = 0;
    RGBcolor col( 0, 0, 0 );

    Point2d point;

    if ( ! get_obj_attr( buf, id, lay, col, fil, next ) )
    {
        return CMD_ERR;
    }

    while ( true ) //accept more then one string!
    {
        if ( ! strskip( next, '(', next ) )
        {
            return CMD_ERR;
        }

        if ( ! str2val( next, point.x, next ) )
        {
            return CMD_ERR;
        }

        if ( ! strskip( next, ',', next ) )
        {
            return CMD_ERR;
        }

        if ( ! str2val( next, point.y, next ) )
        {
            return CMD_ERR;
        }

        if ( ! strskip( next, ',', next ) )
        {
            return CMD_ERR;
        }

        buf = next;

        int offset;

        int res = get_string( buf, offset, next );

        if ( res < 0 )
        {
            return CMD_ERR;
        }

        if ( ! strskip( next, ')', next ) )
        {
            return CMD_ERR;
        }

        VisualObject2d * string2d = new VisualString2d( id, lay, col, point, res, buf + offset );

        build->set_cmd_insert_visobject( fref, string2d );

        if ( strskip( next, DELIMITER_CHAR, next ) )
        {
            break;
        }
    }

    return CMD_OK;
}
Ejemplo n.º 25
0
streaming_component_type_t
streaming_component_txt2type(const char *s)
{
  return s ? str2val(s, streamtypetab) : SCT_UNKNOWN;
}
bool
AsciiProcessor:: get_frame_attr( const char * buf,
                                 int & id,
                                 int & lay,
                                 int & vis,
                                 char const * & next )
{
    next = buf;
    bool got_attr[4] = { false, false, false, false };

    while ( next )
    {
        if ( strskip( buf, "id", next ) )
        {
            if ( got_attr[0] )
            {
                return false;
            }

            got_attr[0] = true;

            buf = next;

            if ( ! strskip( buf, "=", next ) )
            {
                return false;
            }

            buf = next;

            if ( ! str2val( buf, id, next ) )
            {
                return false;
            }

            buf = next;
        }
        else if ( strskip( buf, "lay", next ) )
        {
            if ( got_attr[1] )
            {
                return false;
            }

            got_attr[1] = true;

            buf = next;

            if ( ! strskip( buf, "=", next ) )
            {
                return false;
            }

            buf = next;

            if ( ! str2val( buf, lay, next ) )
            {
                return false;
            }

            buf = next;
        }
        else if ( strskip( buf, "vis", next ) )
        {
            bool b;

            if ( got_attr[1] )
            {
                return false;
            }

            got_attr[1] = true;

            buf = next;

            if ( ! strskip( buf, "=", next ) )
            {
                return false;
            }

            buf = next;

            if ( ! str2val( buf, b, next ) )
            {
                return false;
            }

            vis = b;

            buf = next;
        }
        else
        {
            next = buf;
            return true;
        }
    }

    next = buf;

    return true;
}
Ejemplo n.º 27
0
action_type_t
action_str2code(const char *str)
{
  return str2val(str, actionnames);
}
Ejemplo n.º 28
0
uint16_t
descrambler_name2caid(const char *s)
{
  int i = str2val(s, caidnametab);
  return (i < 0) ? strtol(s, NULL, 0) : i;
}
Ejemplo n.º 29
0
int
ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
{
	struct ipmi_rs * rsp;
	struct ipmi_rq req;
	uint8_t netfn, cmd, lun;
	int i;
	uint8_t data[256];

	if (argc < 2 || strncmp(argv[0], "help", 4) == 0) {
		lprintf(LOG_NOTICE, "RAW Commands:  raw <netfn> <cmd> [data]");
		print_valstr(ipmi_netfn_vals, "Network Function Codes", LOG_NOTICE);
		lprintf(LOG_NOTICE, "(can also use raw hex values)");
		return -1;
	}
	else if (argc > sizeof(data))
	{
		lprintf(LOG_NOTICE, "Raw command input limit (256 bytes) exceeded");
		return -1;
	}

	ipmi_intf_session_set_timeout(intf, 15);
	ipmi_intf_session_set_retry(intf, 1);

	lun = intf->target_lun;
	netfn = str2val(argv[0], ipmi_netfn_vals);
	if (netfn == 0xff) {
		netfn = (uint8_t)strtol(argv[0], NULL, 0);
	}

	cmd = (uint8_t)strtol(argv[1], NULL, 0);

	memset(data, 0, sizeof(data));
	memset(&req, 0, sizeof(req));
	req.msg.netfn = netfn;
	req.msg.lun = lun;
	req.msg.cmd = cmd;
	req.msg.data = data;

	for (i=2; i<argc; i++) {
		uint8_t val = (uint8_t)strtol(argv[i], NULL, 0);
		req.msg.data[i-2] = val;
		req.msg.data_len++;
	}

	lprintf(LOG_INFO, 
           "RAW REQ (channel=0x%x netfn=0x%x lun=0x%x cmd=0x%x data_len=%d)",
           intf->target_channel & 0x0f, req.msg.netfn,req.msg.lun , 
           req.msg.cmd, req.msg.data_len);

	printbuf(req.msg.data, req.msg.data_len, "RAW REQUEST");

	rsp = intf->sendrecv(intf, &req);

	if (rsp == NULL) {
		lprintf(LOG_ERR, "Unable to send RAW command "
			"(channel=0x%x netfn=0x%x lun=0x%x cmd=0x%x)",
			intf->target_channel & 0x0f, req.msg.netfn, req.msg.lun, req.msg.cmd);
		return -1;
	}
	if (rsp->ccode > 0) {
		lprintf(LOG_ERR, "Unable to send RAW command "
			"(channel=0x%x netfn=0x%x lun=0x%x cmd=0x%x rsp=0x%x): %s",
			intf->target_channel & 0x0f, req.msg.netfn, req.msg.lun, req.msg.cmd, rsp->ccode,
			val2str(rsp->ccode, completion_code_vals));
		return -1;
	}

	lprintf(LOG_INFO, "RAW RSP (%d bytes)", rsp->data_len);

	/* print the raw response buffer */
	for (i=0; i<rsp->data_len; i++) {
		if (((i%16) == 0) && (i != 0))
			printf("\n");
		printf(" %2.2x", rsp->data[i]);
	}
	printf("\n");

	return 0;
}
Ejemplo n.º 30
0
void wrap_message(string str, varargs int chat_flag) {
   string msg;
   string *words;
   string *lines;
   int width, i, j, sz;

   if (!str || str == "") {
      return;
   }

   width = -1;
   /* Get the width from the player */
   if (player) {
      catch(width = str2val((string) player->query_env("width")));
   }

   if (width < 0) {
      width = DEFAULT_WIDTH;
   }

   rlimits(MAX_DEPTH; MAX_TICKS * MAX_TICKS) {
      /* Split the string into lines */
      lines = explode(str, "\n");

      /* Parse each line */
      for (j = 0; j < sizeof(lines); j++) {
	 str = lines[j];
	 msg = str;
	 if (strlen(ansid->strip_colors(str)) > width) {
	    int adding;
	    string word_todo;

	    sz = 0;
	    words = explode(str, " ");
	    msg = "";

	    for (i = 0; i < sizeof(words); i++) {
	       word_todo = nil;
	       if (strlen(words[i]) > 4 && (strstr(words[i], "%^") != -1)) {
		  word_todo = ansid->strip_colors(words[i]);
	       }
	       /* word_todo is the word stripped from ansi codes */
	       word_todo = !word_todo ? words[i] : word_todo;

	       if (sz + strlen(word_todo) + adding > width) {
		  msg += "\n";

		  if (chat_flag) {
		     msg += "  ";
		  }

                  /* add length of word without ansi codes */
		  sz = strlen(word_todo) + 2;

                  /* add word with ansi codes */
		  msg += words[i];
	       } else {
		  msg += (adding ? " " : "") + words[i];
		  sz += strlen(word_todo) + adding;
	       }
	       /* determine how many spaces will be added next run */
	       adding = sz == 0 ? 0 : 1;
	    }
	 }
	 if (query_player()->query_ansi()) {
	    msg = ansid->parse_colors(msg);
	 } else {
	    msg = ansid->strip_colors(msg);
         }

	 send_message(msg + "\n");
      }
   }
}