Exemple #1
0
static int
action_type (const char *actionstr)
{
	if (EQSTR (actionstr, "save"))
		return SAVE;
	else if (EQSTR (actionstr, "open"))
		return OPEN;
	else if (EQSTR (actionstr, "temp"))
		return TEMP;
	else
		return INVALID_ACTION;
}
Exemple #2
0
static unsigned
compose_type (const char *typestr)
{
	if (EQSTR (typestr, "reply"))
		return REPLY;
	else if (EQSTR (typestr, "forward"))
		return FORWARD;
	else if (EQSTR (typestr, "edit"))
		return EDIT;
	else if (EQSTR (typestr, "new"))
		return NEW;
	else
		return INVALID_TYPE;
}
Exemple #3
0
void
parse_opts(char *str)
{
    char *sp;
    OPTION *op;
    int len;
    char **i;
    char *start;

    while (*str)
    {
	/*
	 * Get option name
	 */
	for (sp = str; isalpha(*sp); sp++)
	    continue;
	len = (int)(sp - str);
	/*
	 * Look it up and deal with it
	 */
	for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
	    if (EQSTR(str, op->o_name, len))
	    {
		if (op->o_putfunc == put_bool)	/* if option is a boolean */
		    *(bool *)op->o_opt = TRUE;	/* NOSTRICT */
		else				/* string option */
		{
		    /*
		     * Skip to start of string value
		     */
		    for (str = sp + 1; *str == '='; str++)
			continue;
		    if (*str == '~')
		    {
			strcpy((char *) op->o_opt, home);	  /* NOSTRICT */
			start = (char *) op->o_opt + strlen(home);/* NOSTRICT */
			while (*++str == '/')
			    continue;
		    }
		    else
			start = (char *) op->o_opt;	/* NOSTRICT */
		    /*
		     * Skip to end of string value
		     */
		    for (sp = str + 1; *sp && *sp != ','; sp++)
			continue;
		    /*
		     * check for type of inventory
		     */
		    if (op->o_putfunc == put_inv_t)
		    {
			if (islower(*str))
			    *str = (char) toupper(*str);
			for (i = inv_t_name; i <= &inv_t_name[INV_CLEAR]; i++)
			    if (strncmp(str, *i, sp - str) == 0)
			    {
				inv_type = (int)(i - inv_t_name);
				break;
			    }
		    }
		    else
			strucpy(start, str, (int)(sp - str));
		}
		break;
	    }
	    /*
	     * check for "noname" for booleans
	     */
	    else if (op->o_putfunc == put_bool
	      && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2))
	    {
		*(bool *)op->o_opt = FALSE;	/* NOSTRICT */
		break;
	    }

	/*
	 * skip to start of next option name
	 */
	while (*sp && !isalpha(*sp))
	    sp++;
	str = sp;
    }
}
Exemple #4
0
void
parse_opts(char *str)
{
    char *sp;
    OPTION *op;
    int len;

    while (*str)
    {
	/*
	 * Get option name
	 */
	for (sp = str; isalpha(*sp); sp++)
	    continue;
	len = (int)(sp - str);
	/*
	 * Look it up and deal with it
	 */
	for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
	    if (EQSTR(str, op->o_name, len))
	    {
		if (op->o_putfunc == put_bool)	/* if option is a boolean */
		    *(int *)op->o_opt = TRUE;
		else				/* string option */
		{
		    char *start;
		    /*
		     * Skip to start of string value
		     */
		    for (str = sp + 1; *str == '='; str++)
			continue;
		    if (*str == '~')
		    {
			strcpy((char *) op->o_opt, home);
			start = (char *) op->o_opt + strlen(home);
			while (*++str == '/')
			    continue;
		    }
		    else
			start = (char *) op->o_opt;
		    /*
		     * Skip to end of string value
		     */
		    for (sp = str + 1; *sp && *sp != ','; sp++)
			continue;
		    strucpy(start, str, sp - str);
		}
		break;
	    }
	    /*
	     * check for "noname" for booleans
	     */
	    else if (op->o_putfunc == put_bool
	      && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2))
	    {
		*(int *)op->o_opt = FALSE;
		break;
	    }

	/*
	 * skip to start of next option name
	 */
	while (*sp && !isalpha(*sp))
	    sp++;
	str = sp;
    }
}
 /*
  * parse options from string, usually taken from the environment.
  * the string is a series of comma seperated values, with booleans
  * being stated as "name" (true) or "noname" (false), and strings
  * being "name=....", with the string being defined up to a comma
  * or the end of the entire option string.
  */
 void
 parse_opts(char *str)
 {
     register char *sp;
     register OPTION *op;
     register int len;
 
     while (*str)
     {
 	/*
 	 * Get option name
 	 */
 	for (sp = str; isalpha(*sp); sp++)
 	    continue;
 	len = (int)(sp - str);
 	/*
 	 * Look it up and deal with it
 	 */
 	for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
 	    if (EQSTR(str, op->o_name, len))
 	    {
 		if (op->o_putfunc == put_bool)	/* if option is a boolean */
 		    *(int *)op->o_opt = TRUE;
 		else				/* string option */
 		{
 		    register char *start;
 		    char value[80];
 
 		    /*
 		     * Skip to start of string value
 		     */
 		    for (str = sp + 1; *str == '='; str++)
 			continue;
 		    if (*str == '~')
 		    {
 			strcpy((char *) value, home);
 			start = (char *) value + strlen(home);
 			while (*++str == '/')
 			    continue;
 		    }
 		    else
 			start = (char *) value;
 		    /*
 		     * Skip to end of string value
 		     */
 		    for (sp = str + 1; *sp && *sp != ','; sp++)
 			continue;
 		    strucpy(start, str, (int)(sp - str));
 
 		    /* Put the value into the option field */
 		    if (op->o_putfunc != put_abil) 
 			strcpy(op->o_opt, value);
 
 		    else if (*(int *)op->o_opt == -1) { /* Only init ability once */
 			register size_t len = strlen(value);
 
 			if (isupper(value[0])) value[0] = (char) tolower(value[0]);
 			if (EQSTR(value, "fighter", len))
 				*(int *)op->o_opt = C_FIGHTER;
 			else if (EQSTR(value, "magic", min(len, 5)))
 				*(int *)op->o_opt = C_MAGICIAN;
 			else if (EQSTR(value, "cleric", len))
 				*(int *)op->o_opt = C_CLERIC;
 			else if (EQSTR(value, "thief", len))
 				*(int *)op->o_opt = C_THIEF;
 		    }
 		}
 		break;
 	    }
 	    /*
 	     * check for "noname" for booleans
 	     */
 	    else if (op->o_putfunc == put_bool
 	      && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2))
 	    {
 		*(int *)op->o_opt = FALSE;
 		break;
 	    }
 
 	/*
 	 * skip to start of next option name
 	 */
 	while (*sp && !isalpha(*sp))
 	    sp++;
 	str = sp;
     }
 }