rogue > parse_opts(char*)


※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

rogue/main()

/*
 * parse_opts:
 *      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.
 */

parse_opts:

文字列からオプションを解析し、通常は環境変数からオプションは設定される

文字列はカンマ区切りで、"name=true" or"name=false"の値を取る。


void
parse_opts(char *str)
{
    char *sp;
    const OPTION *op;
    int len;
    const char **i;
    char *start;

    while (*str)
    {
        /*
         * Get option name
         */
        for (sp = str; isalpha((int)*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;        /* 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((int)*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, (size_t)(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;   /* NOSTRICT */
                break;
            }

        /*
         * skip to start of next option name
         */
        while (*sp && !isalpha((int)*sp))
            sp++;
        str = sp;
    }
}