static char *congestion_key_info(ib_portid_t * dest, char **argv, int argc)
{
	uint8_t rcv[IB_CC_DATA_SZ] = { 0 };
	uint8_t payload[IB_CC_DATA_SZ] = { 0 };
	uint64_t cc_key;
	uint32_t cc_keyprotectbit;
	uint32_t cc_keyleaseperiod;
	uint32_t cc_keyviolations;
	char *errstr;

	if (argc != 4)
		return "invalid number of parameters for CongestionKeyInfo";

	if ((errstr = parselonglongint(argv[0], &cc_key)))
		return errstr;
	if ((errstr = parseint(argv[1], &cc_keyprotectbit, 0)))
		return errstr;
	if ((errstr = parseint(argv[2], &cc_keyleaseperiod, 0)))
		return errstr;
	if ((errstr = parseint(argv[3], &cc_keyviolations, 0)))
		return errstr;

	if (cc_keyprotectbit != 0 && cc_keyprotectbit != 1)
		return "invalid cc_keyprotectbit value";

	if (cc_keyleaseperiod > USHRT_MAX)
		return "invalid cc_keyleaseperiod value";

	if (cc_keyviolations > USHRT_MAX)
		return "invalid cc_keyviolations value";

	mad_set_field64(payload,
			0,
			IB_CC_CONGESTION_KEY_INFO_CC_KEY_F,
			cc_key);

	mad_encode_field(payload,
			 IB_CC_CONGESTION_KEY_INFO_CC_KEY_PROTECT_BIT_F,
			 &cc_keyprotectbit);

	mad_encode_field(payload,
			 IB_CC_CONGESTION_KEY_INFO_CC_KEY_LEASE_PERIOD_F,
			 &cc_keyleaseperiod);

	/* spec says "setting the counter to a value other than zero results
	 * in the counter being left unchanged.  So if user wants no change,
	 * they gotta input non-zero
	 */
        mad_encode_field(payload,
			 IB_CC_CONGESTION_KEY_INFO_CC_KEY_VIOLATIONS_F,
			 &cc_keyviolations);
	
	if (!cc_config_status_via(payload, rcv, dest, IB_CC_ATTR_CONGESTION_KEY_INFO,
				  0, 0, NULL, srcport, cckey))
		return "congestion key info config failed";

	return NULL;
}
示例#2
0
void rdjoint(int *n, int *t, char *v1, char *v2, char *v3)
{
    checkragdoll;
    ragdollskel::joint &j = ragdoll->joints.add();
    j.bone = *n;
    j.tri = *t;
    j.vert[0] = v1[0] ? parseint(v1) : -1;
    j.vert[1] = v2[0] ? parseint(v2) : -1;
    j.vert[2] = v3[0] ? parseint(v3) : -1;
}
static char *congestion_control_table(ib_portid_t * dest, char **argv, int argc)
{
	uint8_t rcv[IB_CC_DATA_SZ] = { 0 };
	uint8_t payload[IB_CC_DATA_SZ] = { 0 };
	uint32_t ccti_limit;
	uint32_t index;
	uint32_t cctshifts[64];
	uint32_t cctmults[64];
	char *errstr;
	int i;

	if (argc < 2 || argc > 66)
		return "invalid number of parameters for CongestionControlTable";

	if ((errstr = parseint(argv[0], &ccti_limit, 0)))
		return errstr;

	if ((errstr = parseint(argv[1], &index, 0)))
		return errstr;

	if (ccti_limit && (ccti_limit + 1) != (index * 64 + (argc - 2)))
		return "invalid number of cct entries input given ccti_limit and index";

	for (i = 0; i < (argc - 2); i++) {
		if ((errstr = parsecct(argv[i + 2], &cctshifts[i], &cctmults[i])))
			return errstr;
	}

	mad_encode_field(payload,
			 IB_CC_CONGESTION_CONTROL_TABLE_CCTI_LIMIT_F,
			 &ccti_limit);

	for (i = 0; i < (argc - 2); i++) {
		mad_encode_field(payload + 4 + i * 2,
				 IB_CC_CONGESTION_CONTROL_TABLE_ENTRY_CCT_SHIFT_F,
				 &cctshifts[i]);

		mad_encode_field(payload + 4 + i * 2,
				 IB_CC_CONGESTION_CONTROL_TABLE_ENTRY_CCT_MULTIPLIER_F,
				 &cctmults[i]);
	}

	if (!cc_config_status_via(payload, rcv, dest, IB_CC_ATTR_CONGESTION_CONTROL_TABLE,
				  index, 0, NULL, srcport, cckey))
		return "congestion control table config failed";	

	return NULL;
}
示例#4
0
文件: stabs.c 项目: 00001/plan9port
/*
	bound ::= 
		'A' offset			(bound is on stack by ref at offset offset from arg list)
		| 'T' offset			(bound is on stack by val at offset offset from arg list)
		| 'a' regnum		(bound passed by reference in register)
		| 't' regnum		(bound passed by value in register)
		| 'J'				(no bound)
		| bigint
*/
static int
parsebound(char **pp)
{
	char *p;
	int n;

	n = 0;
	p = *pp;
	switch(*p){
	case 'A':	/* bound is on stack by reference at offset n from arg list */
	case 'T':	/* bound is on stack by value at offset n from arg list */
	case 'a':	/* bound is passed by reference in register n */
	case 't':	/* bound is passed by value in register n */
		p++;
		parseint(&p);
		break;
	case 'J':	/* no bound */
		p++;
		break;
	default:
		n = parsebigint(&p);
		break;
	}
	*pp = p;
	return n;
}
示例#5
0
    int getweapon(const char *name)
    {
////////////////////////////////////////////////////////////////////////////
        const char *abbrevs[] = { "FI", "SG", "CG", "RL", "RI", "GL", "PI", "FB", "IB", "SB", "BI", "BA", "SW", "CB", "BW" };
////////////////////////////////////////////////////////////////////////////
        if(isdigit(name[0])) return parseint(name);
        else loopi(sizeof(abbrevs)/sizeof(abbrevs[0])) if(!strcasecmp(abbrevs[i], name)) return i;
        return -1;
    }
示例#6
0
static PyObject *setVariable(PyObject *self, PyObject *args)
{
    char *variableName;
    char *value;
    if(!PyArg_ParseTuple(args, "ss", &variableName, &value))
    	return 0;
    static string scmdval; scmdval[0] = 0;
    ident *id = idents->access(variableName);
    if(id)
    {
        switch(id->type)
        {
			case ID_VAR:
			{
                int ret = parseint(value);
                if(ret < id->minval || ret > id->maxval)
                {
                	PyErr_Format(PyExc_ValueError,
                        id->flags&IDF_HEX ?
                                (id->minval <= 255 ? "valid range for %s is %d..0x%X" : "valid range for %s is 0x%X..0x%X") :
                                "valid range for %s is %d..%d", variableName, id->minval, id->maxval);
                    return 0;
                }
                setvar(variableName, ret);
				break;
			}
			case ID_FVAR:
			{
                float ret = parsefloat(value);
                if(ret < id->minvalf || ret > id->maxvalf)
                {
                	PyErr_Format(PyExc_ValueError, "valid range for %s is %s..%s", variableName, floatstr(id->minvalf), floatstr(id->maxvalf));
                    return 0;
                }
                setfvar(variableName, ret);
                break;
			}
			case ID_SVAR:
			{
                setsvar(variableName, value);
				break;
			}
			default:
			{
				PyErr_SetString(PyExc_ValueError, "Unknown server variable type");
				return 0;
				break;
			}
        }
        printf("hopefully to set: %s to %s\n", variableName, value);
    	Py_INCREF(Py_None);
    	return Py_None;
    }
	PyErr_SetString(PyExc_ValueError, "Invalid variable specified");
	return 0;
}
static char *parsecct(char *arg, uint32_t *shift, uint32_t *multiplier)
{
	char buf[1024] = { 0 };
	char *errstr;
	char *ptr;

	strcpy(buf, arg);

	if (!(ptr = strchr(buf, ':')))
		return "ccts are formatted shift:multiplier";

	*ptr = '\0';
	ptr++;

	if ((errstr = parseint(buf, shift, 0)))
		return errstr;

	if ((errstr = parseint(ptr, multiplier, 0)))
		return errstr;

	return NULL;	
}
示例#8
0
int
parse_short_option(char opt, char *next, void *opaque)
{
    struct option_data *data = opaque;
    long int num;
    int isNum = next ? parseint(next, &num) : 0;

    if (opt == 'h') {
        print_help(data->basename);
        data->done = 1;
        return 0;
    }

    if (opt == 'v') {
        print_version();
        data->done = 1;
        return 0;
    }

    if (opt == 'T') {
        data->show_time = 1;
        return 1;
    }

    /* options requiring value */
    /* FIXME: add validation */

    if (opt == 'n' && isNum) {
        data->max_nesting = num;
        return 2;
    }

    if (opt == 't' && isNum) {
        data->toc_level = num;
        return 2;
    }

    if (opt == 'i' && isNum) {
        data->iunit = num;
        return 2;
    }

    if (opt == 'o' && isNum) {
        data->ounit = num;
        return 2;
    }

    fprintf(stderr, "Wrong option '-%c' found.\n", opt);
    return 0;
}
/* parse like it's a hypothetical 256 bit hex code */
static char *parse256(char *arg, uint8_t *buf)
{
	int numdigits = 0;
	int startindex;
	char *ptr;
	int i;

	if (!strncmp(arg, "0x", 2) || !strncmp(arg, "0X", 2))
		arg += 2;

	for (ptr = arg; *ptr; ptr++) {
		if (!isxdigit(*ptr))
			return "invalid hex digit read";
		numdigits++;
	}

	if (numdigits > 64)
		return "hex code too long";

	/* we need to imagine that this is like a 256-bit int stored
	 * in big endian.  So we need to find the first index
	 * point where the user's input would start in our array.
	 */
	startindex = 32 - ((numdigits - 1) / 2) - 1;

	for (i = startindex; i <= 31; i++) {
		char tmp[3] = { 0 };
		uint32_t tmpint;
		char *errstr;

		/* I can't help but think there is a strtoX that
		 * will do this for me, but I can't find it.
		 */
		if (i == startindex && numdigits % 2) {
			memcpy(tmp, arg, 1);
			arg++;
		}
		else {
			memcpy(tmp, arg, 2);
			arg += 2;
		}

		if ((errstr = parseint(tmp, &tmpint, 1)))
			return errstr;
		buf[i] = tmpint;
	}

	return NULL;
}
static char *ca_congestion_setting(ib_portid_t * dest, char **argv, int argc)
{
	uint8_t rcv[IB_CC_DATA_SZ] = { 0 };
	uint8_t payload[IB_CC_DATA_SZ] = { 0 };
	uint32_t port_control;
	uint32_t control_map;
	uint32_t ccti_timer;
	uint32_t ccti_increase;
	uint32_t trigger_threshold;
	uint32_t ccti_min;
	char *errstr;
	int i;

	if (argc != 6)
		return "invalid number of parameters for CACongestionSetting";

	if ((errstr = parseint(argv[0], &port_control, 0)))
		return errstr;
	
	if ((errstr = parseint(argv[1], &control_map, 0)))
		return errstr;

	if ((errstr = parseint(argv[2], &ccti_timer, 0)))
		return errstr;

	if ((errstr = parseint(argv[3], &ccti_increase, 0)))
		return errstr;

	if ((errstr = parseint(argv[4], &trigger_threshold, 0)))
		return errstr;

	if ((errstr = parseint(argv[5], &ccti_min, 0)))
		return errstr;

	mad_encode_field(payload,
			 IB_CC_CA_CONGESTION_SETTING_PORT_CONTROL_F,
			 &port_control);

	mad_encode_field(payload,
			 IB_CC_CA_CONGESTION_SETTING_CONTROL_MAP_F,
			 &control_map);

	for (i = 0; i < 16; i++) {
		uint8_t *ptr;

		if (!(control_map & (0x1 << i)))
			continue;

		ptr = payload + 2 + 2 + i * 8;

		mad_encode_field(ptr,
				 IB_CC_CA_CONGESTION_ENTRY_CCTI_TIMER_F,
				 &ccti_timer);

		mad_encode_field(ptr,
				 IB_CC_CA_CONGESTION_ENTRY_CCTI_INCREASE_F,
				 &ccti_increase);

		mad_encode_field(ptr,
				 IB_CC_CA_CONGESTION_ENTRY_TRIGGER_THRESHOLD_F,
				 &trigger_threshold);

		mad_encode_field(ptr,
				 IB_CC_CA_CONGESTION_ENTRY_CCTI_MIN_F,
				 &ccti_min);
	}
			 
	if (!cc_config_status_via(payload, rcv, dest, IB_CC_ATTR_CA_CONGESTION_SETTING,
				  0, 0, NULL, srcport, cckey))
		return "ca congestion setting config failed";

	return NULL;
}
static char *switch_port_congestion_setting(ib_portid_t * dest, char **argv, int argc)
{
	uint8_t rcv[IB_CC_DATA_SZ] = { 0 };
	uint8_t payload[IB_CC_DATA_SZ] = { 0 };
	uint8_t data[IB_CC_DATA_SZ] = { 0 };
	uint32_t portnum;
	uint32_t valid;
	uint32_t control_type;
	uint32_t threshold;
	uint32_t packet_size;
	uint32_t cong_parm_marking_rate;
	uint32_t type;
	uint32_t numports;
	uint8_t *ptr;
	char *errstr;

	if (argc != 6)
		return "invalid number of parameters for SwitchPortCongestion";

	if ((errstr = parseint(argv[0], &portnum, 0)))
		return errstr;

	if ((errstr = parseint(argv[1], &valid, 0)))
		return errstr;

	if ((errstr = parseint(argv[2], &control_type, 0)))
		return errstr;

	if ((errstr = parseint(argv[3], &threshold, 0)))
		return errstr;

	if ((errstr = parseint(argv[4], &packet_size, 0)))
		return errstr;

	if ((errstr = parseint(argv[5], &cong_parm_marking_rate, 0)))
		return errstr;

	/* Figure out number of ports first */
	if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
		return "node info config failed";

	mad_decode_field((uint8_t *)data, IB_NODE_TYPE_F, &type);
	mad_decode_field((uint8_t *)data, IB_NODE_NPORTS_F, &numports);

	if (type != IB_NODE_SWITCH)
		return "destination not a switch";

	if (portnum > numports)
		return "invalid port number specified";

	/* We are modifying only 1 port, so get the current config */
	if (!cc_query_status_via(payload, dest, IB_CC_ATTR_SWITCH_PORT_CONGESTION_SETTING,
				 portnum / 32, 0, NULL, srcport, cckey))
		return "switch port congestion setting query failed";

	ptr = payload + (((portnum % 32) * 4));

	mad_encode_field(ptr,
			 IB_CC_SWITCH_PORT_CONGESTION_SETTING_ELEMENT_VALID_F,
			 &valid);

	mad_encode_field(ptr,
			 IB_CC_SWITCH_PORT_CONGESTION_SETTING_ELEMENT_CONTROL_TYPE_F,
			 &control_type);

	mad_encode_field(ptr,
			 IB_CC_SWITCH_PORT_CONGESTION_SETTING_ELEMENT_THRESHOLD_F,
			 &threshold);

	mad_encode_field(ptr,
			 IB_CC_SWITCH_PORT_CONGESTION_SETTING_ELEMENT_PACKET_SIZE_F,
			 &packet_size);

	mad_encode_field(ptr,
			 IB_CC_SWITCH_PORT_CONGESTION_SETTING_ELEMENT_CONG_PARM_MARKING_RATE_F,
			 &cong_parm_marking_rate);

	if (!cc_config_status_via(payload, rcv, dest, IB_CC_ATTR_SWITCH_PORT_CONGESTION_SETTING,
				  portnum / 32, 0, NULL, srcport, cckey))
		return "switch port congestion setting config failed";

	return NULL;
}
static char *switch_congestion_setting(ib_portid_t * dest, char **argv, int argc)
{
	uint8_t rcv[IB_CC_DATA_SZ] = { 0 };
	uint8_t payload[IB_CC_DATA_SZ] = { 0 };
	uint32_t control_map;
	uint8_t victim_mask[32] = { 0 };
	uint8_t credit_mask[32] = { 0 };
	uint32_t threshold;
	uint32_t packet_size;
	uint32_t cs_threshold;
	uint32_t cs_returndelay_s;
	uint32_t cs_returndelay_m;
	uint32_t cs_returndelay;
	uint32_t marking_rate;
	char *errstr;

	if (argc != 8)
		return "invalid number of parameters for SwitchCongestionSetting";

	if ((errstr = parseint(argv[0], &control_map, 0)))
		return errstr;

	if ((errstr = parse256(argv[1], victim_mask)))
		return errstr;

	if ((errstr = parse256(argv[2], credit_mask)))
		return errstr;

	if ((errstr = parseint(argv[3], &threshold, 0)))
		return errstr;

	if ((errstr = parseint(argv[4], &packet_size, 0)))
		return errstr;

	if ((errstr = parseint(argv[5], &cs_threshold, 0)))
		return errstr;

	if ((errstr = parsecct(argv[6], &cs_returndelay_s, &cs_returndelay_m)))
		return errstr;

	cs_returndelay = cs_returndelay_m;
	cs_returndelay |= (cs_returndelay_s << 14);

	if ((errstr = parseint(argv[7], &marking_rate, 0)))
		return errstr;

	mad_encode_field(payload,
			 IB_CC_SWITCH_CONGESTION_SETTING_CONTROL_MAP_F,
			 &control_map);

	mad_set_array(payload,
		      0,
		      IB_CC_SWITCH_CONGESTION_SETTING_VICTIM_MASK_F,
		      victim_mask);

	mad_set_array(payload,
		      0,
		      IB_CC_SWITCH_CONGESTION_SETTING_CREDIT_MASK_F,
		      credit_mask);

	mad_encode_field(payload,
			 IB_CC_SWITCH_CONGESTION_SETTING_THRESHOLD_F,
			 &threshold);

	mad_encode_field(payload,
			 IB_CC_SWITCH_CONGESTION_SETTING_PACKET_SIZE_F,
			 &packet_size);

	mad_encode_field(payload,
			 IB_CC_SWITCH_CONGESTION_SETTING_CS_THRESHOLD_F,
			 &cs_threshold);

	mad_encode_field(payload,
			 IB_CC_SWITCH_CONGESTION_SETTING_CS_RETURN_DELAY_F,
			 &cs_returndelay);

	mad_encode_field(payload,
			 IB_CC_SWITCH_CONGESTION_SETTING_MARKING_RATE_F,
			 &marking_rate);

	if (!cc_config_status_via(payload, rcv, dest, IB_CC_ATTR_SWITCH_CONGESTION_SETTING,
				  0, 0, NULL, srcport, cckey))
		return "switch congestion setting config failed";

	return NULL;
}
示例#13
0
int
parse_long_option(char *opt, char *next, void *opaque)
{
    struct option_data *data = opaque;
    long int num;
    int isNum = next ? parseint(next, &num) : 0;

    if (strcmp(opt, "help")==0) {
        print_help(data->basename);
        data->done = 1;
        return 0;
    }

    if (strcmp(opt, "version")==0) {
        print_version();
        data->done = 1;
        return 0;
    }

    if (strcmp(opt, "time")==0) {
        data->show_time = 1;
        return 1;
    }

    /* FIXME: validation */

    if (strcmp(opt, "max-nesting")==0 && isNum) {
        data->max_nesting = num;
        return 2;
    }
    if (strcmp(opt, "toc-level")==0 && isNum) {
        data->toc_level = num;
        return 2;
    }
    if (strcmp(opt, "input-unit")==0 && isNum) {
        data->iunit = num;
        return 2;
    }
    if (strcmp(opt, "output-unit")==0 && isNum) {
        data->ounit = num;
        return 2;
    }

    if (strcmp(opt, "html")==0) {
        data->renderer = RENDERER_HTML;
        return 1;
    }
    if (strcmp(opt, "html-toc")==0) {
        data->renderer = RENDERER_HTML_TOC;
        return 1;
    }
    /* this is intentionally omitted from usage, since it's for testing only */
    if (strcmp(opt, "context-test")==0) {
        data->renderer = RENDERER_CONTEXT_TEST;
        return 1;
    }

    if (strcmp(opt, "link-attributes-test")==0) {
        data->link_attributes = 1;
        return 1;
    }

    if (parse_category_option(opt, data) || parse_flag_option(opt, data) || parse_negative_option(opt, data))
        return 1;

    fprintf(stderr, "Wrong option '--%s' found.\n", opt);
    return 0;
}
示例#14
0
文件: problem.c 项目: 376473984/fftw3
static const char *parsetensor(const char *s, bench_tensor **tp,
			       r2r_kind_t **k)
{
     struct dimlist *l = 0, *m;
     bench_tensor *t;
     int rnk = 0;

 L1:
     m = (struct dimlist *)bench_malloc(sizeof(struct dimlist));
     /* nconc onto l */
     m->cdr = l; l = m;
     ++rnk; 

     s = parseint(s, &m->car.n);

     if (*s == ':') {
	  /* read input stride */
	  ++s;
	  s = parseint(s, &m->car.is);
	  if (*s == ':') {
	       /* read output stride */
	       ++s;
	       s = parseint(s, &m->car.os);
	  } else {
	       /* default */
	       m->car.os = m->car.is;
	  }
     } else {
	  m->car.is = 0;
	  m->car.os = 0;
     }

     if (*s == 'f' || *s == 'F') {
	  m->k = R2R_R2HC;
	  ++s;
     }
     else if (*s == 'b' || *s == 'B') {
	  m->k = R2R_HC2R;
	  ++s;
     }
     else if (*s == 'h' || *s == 'H') {
	  m->k = R2R_DHT;
	  ++s;
     }
     else if (*s == 'e' || *s == 'E' || *s == 'o' || *s == 'O') {
	  char c = *(s++);
	  int ab;

	  s = parseint(s, &ab);

	  if (c == 'e' || c == 'E') {
	       if (ab == 0)
		    m->k = R2R_REDFT00;
	       else if (ab == 1)
		    m->k = R2R_REDFT01;
	       else if (ab == 10)
		    m->k = R2R_REDFT10;
	       else if (ab == 11)
		    m->k = R2R_REDFT11;
	       else
		    BENCH_ASSERT(0);
	  }
	  else {
	       if (ab == 0)
		    m->k = R2R_RODFT00;
	       else if (ab == 1)
		    m->k = R2R_RODFT01;
	       else if (ab == 10)
		    m->k = R2R_RODFT10;
	       else if (ab == 11)
		    m->k = R2R_RODFT11;
	       else
		    BENCH_ASSERT(0);
	  }
     }
     else
	  m->k = R2R_R2HC;

     if (*s == 'x' || *s == 'X') {
	  ++s;
	  goto L1;
     }
     
     /* now we have a dimlist.  Build bench_tensor, etc. */

     if (k && rnk > 0) {
	  int i;
	  *k = (r2r_kind_t *) bench_malloc(sizeof(r2r_kind_t) * rnk);
	  for (m = l, i = rnk - 1; i >= 0; --i, m = m->cdr) {
	       BENCH_ASSERT(m);
	       (*k)[i] = m->k;
	  }
     }

     t = mktensor(rnk);
     while (--rnk >= 0) {
	  bench_iodim *d = t->dims + rnk;
	  BENCH_ASSERT(l);
	  m = l; l = m->cdr;
	  d->n = m->car.n;
	  d->is = m->car.is;
	  d->os = m->car.os;
	  bench_free(m);
     }

     *tp = t;
     return s;
}
示例#15
0
文件: stabs.c 项目: 00001/plan9port
static Type*
parsedefn(char *p, Type *t, char **pp)
{
	char c, *name;
	int ischar, namelen, n, wid, offset, bits, sign;
	long val;
	Type *tt;

	if(*p == '(' || isdigit((uchar)*p)){
		t->ty = Defer;
		t->sub = parseinfo(p, pp);
		return t;
	}

	switch(c = *p){
	case '-':	/* builtin */
		n = strtol(p+1, &p, 10);
		if(n >= nelem(baseints) || n < 0)
			n = 0;
		t->ty = Base;
		t->xsizeof = baseints[n].size;
		t->printfmt = baseints[n].fmt;
		break;
	case 'b':	/* builtin */
		p++;
		if(*p != 'u' && *p != 's')
			oops();
		sign = (*p == 's');
		p++;
		ischar = 0;
		if(*p == 'c'){
			ischar = 1;
			p++;
		}
		wid = parseint(&p);
		semi(&p);
		offset = parseint(&p);
		semi(&p);
		bits = parseint(&p);
		semi(&p);
		t->ty = Base;
		t->xsizeof = wid;
		if(sign == 1)
			t->printfmt = 'd';
		else
			t->printfmt = 'x';
		USED(bits);
		USED(ischar);
		break;
	case 'R':	/* fp type */
		n = parseint(&p);
		semi(&p);
		wid = parseint(&p);
		semi(&p);
		t->ty = Base;
		t->xsizeof = wid;
		if(n < 0 || n >= nelem(basefloats))
			n = 0;
		t->xsizeof = basefloats[n].size;
		t->printfmt = basefloats[n].fmt;
		break;
	case 'r':	/* subrange */
		t->ty = Range;
		t->sub = parseinfo(p+1, &p);
		if(*(p-1) == ';' && *p != ';')
			p--;
		semi(&p);
		t->lo = parsebound(&p);
		semi(&p);
		t->hi = parsebound(&p);
		semi(&p);
		break;
	case 'B':	/* volatile */
	case 'k':	/* const */
		t->ty = Defer;
		t->sub = parseinfo(p+1, &p);
		break;
	case '*':	/* pointer */
	case 'A':	/* open array */
	case '&':	/* reference */	/* guess - C++? (rob) */
		t->ty = Pointer;
		t->sub = parseinfo(p+1, &p);
		break;
	case 'a':	/* array */		
	case 'P':	/* packed array */
		t->ty = Pointer;
		tt = newtype();
		parsedefn(p+1, tt, &p);	/* index type */
		if(*p == ';')
			p++;
		tt = newtype();
		t->sub = tt;
		parsedefn(p, tt, &p);	/* element type */
		break;
	case 'e':	/* enum listing */
		p++;
		t->sue = 'e';
		t->ty = Enum;
		while(*p != ';'){
			name = p;
			p = findcolon(p)+1;
			namelen = (p-name)-1;
			val = parsebigint(&p);
			comma(&p);
			if(t->n%32 == 0){
				t->tname = erealloc(t->tname, (t->n+32)*sizeof(t->tname[0]));
				t->val = erealloc(t->val, (t->n+32)*sizeof(t->val[0]));
			}
			t->tname[t->n] = estrndup(name, namelen);
			t->val[t->n] = val;
			t->n++;
		}
		semi(&p);
		break;
		
	case 's':	/* struct */
	case 'u':	/* union */
		p++;
		t->sue = c;
		t->ty = Aggr;
		n = parseint(&p);
		while(*p != ';'){
			name = p;
			p = findcolon(p)+1;
			namelen = (p-name)-1;
			tt = parseinfo(p, &p);
			comma(&p);
			offset = parseint(&p);
			comma(&p);
			bits = parseint(&p);
			semi(&p);
			if(t->n%32 == 0){
				t->tname = erealloc(t->tname, (t->n+32)*sizeof(t->tname[0]));
				t->val = erealloc(t->val, (t->n+32)*sizeof(t->val[0]));
				t->t = erealloc(t->t, (t->n+32)*sizeof(t->t[0]));
			}
			t->tname[t->n] = estrndup(name, namelen);
			t->val[t->n] = offset;
			t->t[t->n] = tt;
			t->n++;
		}
		semi(&p);
		break;

	case 'x':	/* struct, union, enum reference */
		p++;
		t->ty = Defer;
		if(*p != 's' && *p != 'u' && *p != 'e')
			oops();
		c = *p;
		name = p+1;
		p = findcolon(p+1);
		name = estrndup(name, p-name);
		t->sub = typebysue(c, name);
		p++;
		break;

#if 0	/* AIX */
	case 'f':	/* function */
	case 'p':	/* procedure */
	case 'F':	/* Pascal function */
	/* case 'R':	/* Pascal procedure */
		/*
		 * Even though we don't use the info, we have
		 * to parse it in case it is embedded in other descriptions.
		 */
		t->ty = Function;
		p++;
		if(c == 'f' || c == 'F'){
			t->sub = parseinfo(p, &p);
			if(*p != ','){
				if(*p == ';')
					p++;
				break;
			}
			comma(&p);
		}
		n = parseint(&p);	/* number of params */
		semi(&p);
		while(*p != ';'){
			if(c == 'F' || c == 'R'){
				name = p;		/* parameter name */
				p = findcolon(p)+1;
			}
			parseinfo(p, &p);	/* param type */
			comma(&p);
			parseint(&p);	/* bool: passed by value? */
			semi(&p);
		}
		semi(&p);
		break;
#endif

	case 'f':	/* static function */
	case 'F':	/* global function */
		t->ty = Function;
		p++;
		t->sub = parseinfo(p, &p);
		break;

	/*
	 * We'll never see any of this stuff.
	 * When we do, we can worry about it.
	 */
	case 'D':	/* n-dimensional array */
	case 'E':	/* subarray of n-dimensional array */
	case 'M':	/* fortran multiple instance type */
	case 'N':	/* pascal string ptr */
	case 'S':	/* set */
	case 'c':	/* aix complex */
	case 'd':	/* file of */
	case 'g':	/* aix float */
	case 'n':	/* max length string */
	case 'w':	/* aix wide char */
	case 'z':	/* another max length string */
	default:
		fprint(2, "unsupported type char %c (%d)\n", *p, *p);
		oops();
	}
	*pp = p;
	return t;
}
示例#16
0
int
main(int argc, char **argv)
{
	int show_time = 0;
	//struct timespec start, end;

	/* buffers */
	hoedown_buffer *ib, *ob;
	size_t iunit = DEF_IUNIT, ounit = DEF_OUNIT;

	/* files */
	FILE *in = NULL;

	/* renderer */
	int toc_level = 0;
	int renderer_type = RENDERER_HTML;

	/* document */
	hoedown_document *document;
	unsigned int extensions = 0;
	size_t max_nesting = DEF_MAX_NESTING;

	/* HTML renderer-specific */
	unsigned int html_flags = 0;


	/* option parsing */
	int just_args = 0;
	int i, j;
	for (i = 1; i < argc; i++) {
		char *arg = argv[i];
		if (!arg[0]) continue;

		if (just_args || arg[0] != '-') {
			/* regular argument */
			in = fopen(arg, "r");
			if (!in) {
				fprintf(stderr, "Unable to open input file \"%s\": %s\n", arg, strerror(errno));
				return 5;
			}
			continue;
		}

		if (!arg[1]) {
			/* arg is "-" */
			in = stdin;
			continue;
		}

		if (arg[1] != '-') {
			/* parse short options */
			char opt;
			const char *val;
			for (j = 1; (opt = arg[j]); j++) {
				if (opt == 'h') {
					print_help(argv[0]);
					return 1;
				}

				if (opt == 'v') {
					print_version();
					return 1;
				}

				if (opt == 'T') {
					show_time = 1;
					continue;
				}

				/* options requiring value */
				if (arg[++j]) val = arg+j;
				else if (argv[++i]) val = argv[i];
				else {
					fprintf(stderr, "Wrong option '-%c' found.\n", opt);
					return 1;
				}

				long int num;
				int isNum = parseint(val, &num);

				if (opt == 'n' && isNum) {
					max_nesting = num;
					break;
				}

				if (opt == 't' && isNum) {
					toc_level = num;
					break;
				}

				if (opt == 'i' && isNum) {
					iunit = num;
					break;
				}

				if (opt == 'o' && isNum) {
					ounit = num;
					break;
				}

				fprintf(stderr, "Wrong option '-%c' found.\n", opt);
				return 1;
			}
			continue;
		}

		if (!arg[2]) {
			/* arg is "--" */
			just_args = 1;
			continue;
		}

		/* parse long option */
		char opt [100];
		strncpy(opt, arg+2, 100);
		opt[99] = 0;

		char *val = strchr(opt, '=');

		long int num = 0;
		int isNum = 0;

		if (val) {
			*val = 0;
			val++;

			if (*val)
				isNum = parseint(val, &num);
		}

		int opt_parsed = 0;

		if (strcmp(opt, "help")==0) {
			print_help(argv[0]);
			return 1;
		}

		if (strcmp(opt, "version")==0) {
			print_version();
			return 1;
		}

		if (strcmp(opt, "max-nesting")==0 && isNum) {
			opt_parsed = 1;
			max_nesting = num;
		}
		if (strcmp(opt, "toc-level")==0 && isNum) {
			opt_parsed = 1;
			toc_level = num;
		}
		if (strcmp(opt, "input-unit")==0 && isNum) {
			opt_parsed = 1;
			iunit = num;
		}
		if (strcmp(opt, "output-unit")==0 && isNum) {
			opt_parsed = 1;
			ounit = num;
		}

		if (strcmp(opt, "html")==0) {
			opt_parsed = 1;
			renderer_type = RENDERER_HTML;
		}
		if (strcmp(opt, "html-toc")==0) {
			opt_parsed = 1;
			renderer_type = RENDERER_HTML_TOC;
		}
		if (strcmp(opt, "null")==0) {
			opt_parsed = 1;
			renderer_type = RENDERER_NULL;
		}

		const char *name;
		size_t i;

		/* extension categories */
		if ((name = strprefix(opt, category_prefix))) {
			for (i = 0; i < count_of(categories_info); i++) {
				struct extension_category_info *category = categories_info+i;
				if (strcmp(name, category->option_name)==0) {
					opt_parsed = 1;
					extensions |= category->flags;
					break;
				}
			}
		}

		/* extensions */
		for (i = 0; i < count_of(extensions_info); i++) {
			struct extension_info *extension = extensions_info+i;
			if (strcmp(opt, extension->option_name)==0) {
				opt_parsed = 1;
				extensions |= extension->flag;
				break;
			}
		}

		/* html flags */
		for (i = 0; i < count_of(html_flags_info); i++) {
			struct html_flag_info *html_flag = html_flags_info+i;
			if (strcmp(opt, html_flag->option_name)==0) {
				opt_parsed = 1;
				html_flags |= html_flag->flag;
				break;
			}
		}

		/* negations */
		if ((name = strprefix(opt, negative_prefix))) {
			for (i = 0; i < count_of(categories_info); i++) {
				struct extension_category_info *category = categories_info+i;
				if (strcmp(name, category->option_name)==0) {
					opt_parsed = 1;
					extensions &= ~(category->flags);
					break;
				}
			}
			for (i = 0; i < count_of(extensions_info); i++) {
				struct extension_info *extension = extensions_info+i;
				if (strcmp(name, extension->option_name)==0) {
					opt_parsed = 1;
					extensions &= ~(extension->flag);
					break;
				}
			}
			for (i = 0; i < count_of(html_flags_info); i++) {
				struct html_flag_info *html_flag = html_flags_info+i;
				if (strcmp(name, html_flag->option_name)==0) {
					opt_parsed = 1;
					html_flags &= ~(html_flag->flag);
					break;
				}
			}
		}

		if (strcmp(opt, "time")==0) {
			opt_parsed = 1;
			show_time = 1;
		}

		if (!opt_parsed) {
			fprintf(stderr, "Wrong option '%s' found.\n", arg);
			return 1;
		}
	}

	if (!in)
		in = stdin;


	/* reading everything */
	ib = hoedown_buffer_new(iunit);

	while (!feof(in)) {
		if (ferror(in)) {
			fprintf(stderr, "I/O errors found while reading input.\n");
			return 5;
		}
		hoedown_buffer_grow(ib, ib->size + iunit);
		ib->size += fread(ib->data + ib->size, 1, iunit, in);
	}

	if (in != stdin)
		fclose(in);


	/* creating the renderer */
	hoedown_renderer *renderer = NULL;
	void (*renderer_free)(hoedown_renderer*) = NULL;

	switch (renderer_type) {
		case RENDERER_HTML:
			renderer = hoedown_html_renderer_new(html_flags, toc_level);
			renderer_free = hoedown_html_renderer_free;
			break;
		case RENDERER_HTML_TOC:
			renderer = hoedown_html_toc_renderer_new(toc_level);
			renderer_free = hoedown_html_renderer_free;
			break;
		case RENDERER_NULL:
			renderer = null_renderer_new();
			renderer_free = null_renderer_free;
			break;
	};


	/* performing markdown rendering */
	ob = hoedown_buffer_new(ounit);
	document = hoedown_document_new(renderer, extensions, max_nesting);

	//clock_gettime(CLOCK_MONOTONIC, &start);
	hoedown_document_render(document, ob, ib->data, ib->size);
	//clock_gettime(CLOCK_MONOTONIC, &end);


	/* writing the result to stdout */
	(void)fwrite(ob->data, 1, ob->size, stdout);


	/* showing rendering time */
	if (show_time) {
		//TODO: enable this
		//long long elapsed = (  end.tv_sec*1000000000 +   end.tv_nsec)
		//                  - (start.tv_sec*1000000000 + start.tv_nsec);
		//if (elapsed < 1000000000)
		//	fprintf(stderr, "Time spent on rendering: %.2f ms.\n", ((double)elapsed)/1000000);
		//else
		//	fprintf(stderr, "Time spent on rendering: %.3f s.\n", ((double)elapsed)/1000000000);
	}


	/* cleanup */
	hoedown_buffer_free(ib);
	hoedown_buffer_free(ob);

	hoedown_document_free(document);
	renderer_free(renderer);

	if (ferror(stdout)) {
		fprintf(stderr, "I/O errors found while writing output.\n");
		return 5;
	}

	return 0;
}
示例#17
0
int
main(int argc, char *argv[])
{
    struct rtprio rtp;
    char *p;
    pid_t proc;

    /* find basename */
    if ((p = rindex(argv[0], '/')) == NULL)
        p = argv[0];
    else
        ++p;
    proc = 0;

    if (!strcmp(p, "rtprio"))
        rtp.type = RTP_PRIO_REALTIME;
    else if (!strcmp(p, "idprio"))
        rtp.type = RTP_PRIO_IDLE;

    switch (argc) {
    case 2:
        proc = parseint(argv[1], "pid");
        proc = abs(proc);
    /* FALLTHROUGH */
    case 1:
        if (rtprio(RTP_LOOKUP, proc, &rtp) != 0)
            err(1, "RTP_LOOKUP");
        printf("%s: ", p);
        switch (rtp.type) {
        case RTP_PRIO_REALTIME:
        case RTP_PRIO_FIFO:
            printf("realtime priority %d\n", rtp.prio);
            break;
        case RTP_PRIO_NORMAL:
            printf("normal priority\n");
            break;
        case RTP_PRIO_IDLE:
            printf("idle priority %d\n", rtp.prio);
            break;
        default:
            printf("invalid priority type %d\n", rtp.type);
            break;
        }
        exit(0);
    default:
        if (argv[1][0] == '-' || isdigit(argv[1][0])) {
            if (argv[1][0] == '-') {
                if (strcmp(argv[1], "-t") == 0) {
                    rtp.type = RTP_PRIO_NORMAL;
                    rtp.prio = 0;
                } else {
                    usage();
                    break;
                }
            } else
                rtp.prio = parseint(argv[1], "priority");
        } else {
            usage();
            break;
        }

        if (argv[2][0] == '-')
            proc = parseint(argv[2] + 1, "pid");
        if (rtprio(RTP_SET, proc, &rtp) != 0)
            err(1, "RTP_SET");

        if (proc == 0) {
            execvp(argv[2], &argv[2]);
            err(1, "%s", argv[2]);
        }
        exit(0);
    }
    exit(1);
}