[BACK]Return to config.y CVS log [TXT][DIR] Up to [contributed] / dgamelaunch-openbsd

Annotation of dgamelaunch-openbsd/config.y, Revision 1.1

1.1     ! rubenllo    1: %{
        !             2:
        !             3: #define YYSTACK_USE_ALLOCA 0
        !             4:
        !             5: #include <sys/types.h>
        !             6:
        !             7: #include <grp.h>
        !             8: #include <pwd.h>
        !             9: #include <stdlib.h>
        !            10: #include <stdio.h>
        !            11: #include <string.h>
        !            12:
        !            13: #include "dgamelaunch.h"
        !            14: #include "ttyrec.h"
        !            15:
        !            16: extern int yylex(void);
        !            17: extern void yyerror(const char*);
        !            18: extern char *yytext;
        !            19: extern unsigned int line, col;
        !            20:
        !            21: extern int num_games;
        !            22: int ncnf = 0;
        !            23: struct dg_cmdpart *curr_cmdqueue = NULL;
        !            24: struct dg_menu *curr_menu = NULL;
        !            25:
        !            26: static struct dg_watchcols *curr_watch_columns[DGL_MAXWATCHCOLS];
        !            27: static int curr_n_watch_columns = 0;
        !            28:
        !            29: int cmdqueue_num = -1;
        !            30:
        !            31: static const char* lookup_token (int t);
        !            32:
        !            33: static int sortmode_number(const char *sortmode_name) {
        !            34:     int tmpi;
        !            35:     if (!*sortmode_name)
        !            36:         return SORTMODE_NONE;
        !            37:     for (tmpi = SORTMODE_NONE; tmpi < NUM_SORTMODES; tmpi++)
        !            38:         if (!strcasecmp(SORTMODE_NAME[tmpi], sortmode_name ))
        !            39:             return tmpi;
        !            40:     return -1;
        !            41: }
        !            42:
        !            43:
        !            44: %}
        !            45:
        !            46: %union {
        !            47:        char* s;
        !            48:        int kt;
        !            49:        unsigned long i;
        !            50: }
        !            51:
        !            52: %token TYPE_SUSER TYPE_SGROUP TYPE_SGID TYPE_SUID TYPE_MAX TYPE_MAXNICKLEN
        !            53: %token TYPE_GAME_SHORT_NAME TYPE_WATCH_SORTMODE TYPE_BANNERVARS
        !            54: %token TYPE_ALLOW_REGISTRATION TYPE_WATCH_COLUMNS TYPE_GAME_ID
        !            55: %token TYPE_PATH_GAME TYPE_NAME_GAME TYPE_PATH_DGLDIR TYPE_PATH_SPOOL
        !            56: %token TYPE_PATH_BANNER TYPE_PATH_CANNED TYPE_PATH_CHROOT
        !            57: %token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE TYPE_PATH_TTYREC
        !            58: %token TYPE_MALSTRING TYPE_PATH_INPROGRESS TYPE_GAME_ARGS TYPE_RC_FMT
        !            59: %token TYPE_CMDQUEUE TYPE_DEFINE_MENU TYPE_BANNER_FILE TYPE_CURSOR
        !            60: %token TYPE_POSTCMDQUEUE TYPE_TIMEFORMAT
        !            61: %token TYPE_MAX_IDLE_TIME TYPE_MENU_MAX_IDLE_TIME TYPE_EXTRA_INFO_FILE
        !            62: %token TYPE_ENCODING TYPE_LOCALE TYPE_UTF8ESC TYPE_FILEMODE TYPE_DEFTERM
        !            63: %token TYPE_FLOWCTRL
        !            64: %token <s> TYPE_VALUE
        !            65: %token <i> TYPE_NUMBER TYPE_CMDQUEUENAME
        !            66: %type  <kt> KeyType
        !            67: %token <i> TYPE_DGLCMD0 TYPE_DGLCMD1 TYPE_DGLCMD2
        !            68: %token TYPE_DEFINE_GAME
        !            69: %token <i> TYPE_BOOL
        !            70:
        !            71: %%
        !            72:
        !            73: Configuration: KeyPairs
        !            74:        | { if (!silent) fprintf(stderr, "%s: no settings, proceeding with defaults\n", config); }
        !            75:        ;
        !            76:
        !            77: KeyPairs: KeyPairs KeyPair
        !            78:        | KeyPair
        !            79:        ;
        !            80:
        !            81: KeyPair: TYPE_CMDQUEUE '[' TYPE_CMDQUEUENAME ']'
        !            82:        {
        !            83:            int qnum = $<i>3;
        !            84:
        !            85:            if (globalconfig.cmdqueue[qnum]) {
        !            86:                fprintf(stderr, "%s:%d: command queue defined twice, bailing out\n",
        !            87:                        config, line);
        !            88:                exit(1);
        !            89:            }
        !            90:            cmdqueue_num = qnum;
        !            91:        }
        !            92:        '=' cmdlist
        !            93:        {
        !            94:            /*
        !            95:            struct dg_cmdpart *tmp = curr_cmdqueue;
        !            96:            while (tmp) {
        !            97:                fprintf(stderr, "cmd=%i, p1=%s, p2=%s\n", tmp->cmd, tmp->param1, tmp->param2);
        !            98:                tmp = tmp->next;
        !            99:            }
        !           100:            */
        !           101:            globalconfig.cmdqueue[cmdqueue_num] = curr_cmdqueue;
        !           102:            curr_cmdqueue = NULL;
        !           103:        }
        !           104:        | definemenu
        !           105:        {
        !           106:            /* nothing */
        !           107:        }
        !           108:        | definegame
        !           109:        {
        !           110:            /* nothing */
        !           111:        }
        !           112:        | KeyType '=' TYPE_VALUE {
        !           113:   struct group* gr;
        !           114:   struct passwd* usr;
        !           115:
        !           116:   switch ($1)
        !           117:   {
        !           118:     case TYPE_SGROUP:
        !           119:       if (globalconfig.shed_gid != (gid_t)-1)
        !           120:         break;
        !           121:
        !           122:       globalconfig.shed_group = strdup($3);
        !           123:       if ((gr = getgrnam($3)) != NULL)
        !           124:       {
        !           125:        globalconfig.shed_gid = gr->gr_gid;
        !           126:        if (!silent)
        !           127:          fprintf(stderr, "%s:%d: suggest replacing 'shed_group = \"%s\"' line with 'shed_gid = %d'\n",
        !           128:          config, line, $3, gr->gr_gid);
        !           129:       }
        !           130:       else
        !           131:       {
        !           132:         if (!silent)
        !           133:           fprintf(stderr, "%s:%d: no such group '%s'\n", config, line, $3);
        !           134:       }
        !           135:
        !           136:       break;
        !           137:     case TYPE_SUSER:
        !           138:       if (globalconfig.shed_uid != (uid_t)-1)
        !           139:         break;
        !           140:
        !           141:       if (!strcmp($3, "root"))
        !           142:       {
        !           143:         fprintf(stderr, "%s:%d: I refuse to run as root! Aborting.\n", config, line);
        !           144:        graceful_exit(8);
        !           145:       }
        !           146:       globalconfig.shed_user = strdup($3);
        !           147:       if ((usr = getpwnam($3)) != NULL)
        !           148:       {
        !           149:         if (usr->pw_uid != 0)
        !           150:        {
        !           151:           globalconfig.shed_uid = usr->pw_uid;
        !           152:          if (!silent)
        !           153:            fprintf(stderr, "%s:%d: suggest replacing 'shed_user = \"%s\"' line with 'shed_uid = %d'\n",
        !           154:              config, line, $3, usr->pw_uid);
        !           155:        }
        !           156:        else
        !           157:        {
        !           158:          fprintf(stderr, "%s:%d: I refuse to run as %s (uid 0!) Aborting.\n", config, line, $3);
        !           159:          graceful_exit(9);
        !           160:        }
        !           161:       }
        !           162:       else
        !           163:       {
        !           164:         if (!silent)
        !           165:           fprintf(stderr, "%s:%d: no such user '%s'\n", config, line, $3);
        !           166:       }
        !           167:       break;
        !           168:
        !           169:     case TYPE_PATH_CHROOT:
        !           170:       if (globalconfig.chroot) free(globalconfig.chroot);
        !           171:       globalconfig.chroot = strdup ($3);
        !           172:       break;
        !           173:
        !           174:   case TYPE_WATCH_SORTMODE:
        !           175:       {
        !           176:           const int sortmode_num = sortmode_number($3);
        !           177:          if (sortmode_num <= SORTMODE_NONE)
        !           178:              fprintf(stderr, "%s:%d: unknown sortmode '%s'\n", config,
        !           179:                       line, $3);
        !           180:           else
        !           181:               globalconfig.sortmode = sortmode_num;
        !           182:       }
        !           183:       break;
        !           184:
        !           185:     case TYPE_PATH_DGLDIR:
        !           186:       if (globalconfig.dglroot) free(globalconfig.dglroot);
        !           187:       globalconfig.dglroot = strdup($3);
        !           188:       break;
        !           189:
        !           190:     case TYPE_PATH_BANNER:
        !           191:       if (globalconfig.banner) free(globalconfig.banner);
        !           192:       globalconfig.banner = strdup($3);
        !           193:       break;
        !           194:
        !           195:     case TYPE_PATH_LOCKFILE:
        !           196:       if (globalconfig.lockfile) free (globalconfig.lockfile);
        !           197:       globalconfig.lockfile = strdup($3);
        !           198:       break;
        !           199:
        !           200:     case TYPE_PATH_PASSWD:
        !           201:       if (globalconfig.passwd) free(globalconfig.passwd);
        !           202:       globalconfig.passwd = strdup($3);
        !           203:       break;
        !           204:
        !           205:     case TYPE_LOCALE:
        !           206:       if (globalconfig.locale) free(globalconfig.locale);
        !           207:       globalconfig.locale = strdup($3);
        !           208:       break;
        !           209:
        !           210:     case TYPE_DEFTERM:
        !           211:       if (globalconfig.defterm) free(globalconfig.defterm);
        !           212:       globalconfig.defterm = strdup($3);
        !           213:       break;
        !           214:
        !           215:     case TYPE_FILEMODE:
        !           216:       default_fmode = strtoul($3, NULL, 8);
        !           217:       break;
        !           218:
        !           219:     default:
        !           220:       fprintf(stderr, "%s:%d: token %s does not take a string, bailing out\n",
        !           221:         config, line, lookup_token($1));
        !           222:       exit(1);
        !           223:
        !           224:   }
        !           225:
        !           226:   free($3);
        !           227: }
        !           228:        | KeyType '=' TYPE_MALSTRING {}
        !           229:        | KeyType '=' TYPE_BOOL {
        !           230:            switch ($1) {
        !           231:            case TYPE_ALLOW_REGISTRATION:
        !           232:                globalconfig.allow_registration = $<i>3;
        !           233:                break;
        !           234:            case TYPE_UTF8ESC:
        !           235:                globalconfig.utf8esc = $<i>3;
        !           236:                break;
        !           237:            case TYPE_FLOWCTRL:
        !           238:                globalconfig.flowctrl = $<i>3;
        !           239:                break;
        !           240:            default:
        !           241:                fprintf(stderr, "%s:%d: token %s does not take a boolean, bailing out\n",
        !           242:                        config, line, lookup_token($1));
        !           243:                exit(1);
        !           244:            }
        !           245:        }
        !           246:        | KeyType '=' TYPE_NUMBER {
        !           247:
        !           248:   switch ($1)
        !           249:   {
        !           250:     case TYPE_SUID:
        !           251:       if (!silent && globalconfig.shed_uid != (uid_t)-1 && globalconfig.shed_uid != $3)
        !           252:         fprintf(stderr, "%s:%d: 'shed_uid = %lu' entry overrides old setting %d\n",
        !           253:          config, line, $3, globalconfig.shed_uid);
        !           254:
        !           255:       /* Naive user protection - do not allow running as user root */
        !           256:       if ($3 == 0)
        !           257:       {
        !           258:         fprintf(stderr, "%s:%d: I refuse to run as uid 0 (root)! Aborting.\n", config, line);
        !           259:         graceful_exit(11);
        !           260:       }
        !           261:
        !           262:       globalconfig.shed_uid = $3;
        !           263:       break;
        !           264:
        !           265:     case TYPE_SGID:
        !           266:       if (!silent && globalconfig.shed_gid != (gid_t)-1 && globalconfig.shed_gid != $3)
        !           267:         fprintf(stderr, "%s:%d: 'shed_gid = %lu' entry overrides old setting %d\n",
        !           268:          config, line, $3, globalconfig.shed_gid);
        !           269:
        !           270:       globalconfig.shed_gid = $3;
        !           271:       break;
        !           272:
        !           273:     case TYPE_MAX:
        !           274:       globalconfig.max = $3;
        !           275:       break;
        !           276:
        !           277:   case TYPE_MAXNICKLEN:
        !           278:       globalconfig.max_newnick_len = $3;
        !           279:       if (globalconfig.max_newnick_len > DGL_PLAYERNAMELEN) {
        !           280:          fprintf(stderr, "%s:%d: max_newnick_len > DGL_PLAYERNAMELEN\n", config, line);
        !           281:          globalconfig.max_newnick_len = DGL_PLAYERNAMELEN;
        !           282:       }
        !           283:       break;
        !           284:
        !           285:   case TYPE_MENU_MAX_IDLE_TIME:
        !           286:       globalconfig.menu_max_idle_time = $3;
        !           287:       break;
        !           288:
        !           289:     default:
        !           290:       fprintf(stderr, "%s:%d: token %s does not take a number, bailing out\n",
        !           291:         config, line, lookup_token($1));
        !           292:       exit(1);
        !           293:   }
        !           294: }
        !           295:        | TYPE_BANNERVARS '=' '[' banner_vars ']'
        !           296:        {
        !           297:        }
        !           298:        | TYPE_WATCH_COLUMNS '=' '[' watch_columns ']' {
        !           299:             memcpy(globalconfig.watch_columns,
        !           300:                    curr_watch_columns,
        !           301:                    curr_n_watch_columns * sizeof(*curr_watch_columns));
        !           302:             globalconfig.n_watch_columns = curr_n_watch_columns;
        !           303:             memset(curr_watch_columns, 0, sizeof curr_watch_columns);
        !           304:             curr_n_watch_columns = 0;
        !           305:           };
        !           306:
        !           307:
        !           308: banner_vars : banner_vars ',' banner_var
        !           309:        | banner_var;
        !           310:
        !           311: banner_var : TYPE_VALUE '=' TYPE_VALUE
        !           312:        {
        !           313:            banner_var_add($1, $3, 0);
        !           314:        }
        !           315:        | TYPE_VALUE '=' TYPE_TIMEFORMAT '(' TYPE_VALUE ')'
        !           316:        {
        !           317:            banner_var_add($1, $5, 1);
        !           318:        };
        !           319:
        !           320: watch_columns: watch_columns ',' watch_column
        !           321:                | watch_column;
        !           322:
        !           323: watch_column: '[' TYPE_VALUE ',' TYPE_VALUE ',' TYPE_NUMBER ',' TYPE_VALUE ']' {
        !           324:     if (curr_n_watch_columns >= DGL_MAXWATCHCOLS) {
        !           325:         fprintf(stderr, "%s:%d too many watch column defs (max %d)\n",
        !           326:                 config, line, DGL_MAXWATCHCOLS);
        !           327:         exit(1);
        !           328:     }
        !           329:
        !           330:     {
        !           331:         struct dg_watchcols watch_column, *new_watch_column = NULL;
        !           332:         watch_column.sortmode = sortmode_number($4);
        !           333:         if (watch_column.sortmode == -1) {
        !           334:             fprintf(stderr, "%s:%d invalid sort mode '%s'.\n",
        !           335:                     config, line, $4);
        !           336:             exit(1);
        !           337:         }
        !           338:         watch_column.dat = watch_column.sortmode;
        !           339:         watch_column.x = $6;
        !           340:         watch_column.colname = strdup($2);
        !           341:         watch_column.fmt = strdup($8);
        !           342:
        !           343:         new_watch_column = (struct dg_watchcols *) malloc(sizeof watch_column);
        !           344:         memcpy(new_watch_column, &watch_column, sizeof watch_column);
        !           345:
        !           346:         curr_watch_columns[curr_n_watch_columns++] = new_watch_column;
        !           347:     }
        !           348: };
        !           349:
        !           350: menu_definition : TYPE_BANNER_FILE '=' TYPE_VALUE
        !           351:          {
        !           352:            if (curr_menu->banner_fn) {
        !           353:                fprintf(stderr, "%s:%d: banner file already defined.\n", config, line);
        !           354:                exit(1);
        !           355:            }
        !           356:            curr_menu->banner_fn = strdup( $3 );
        !           357:          }
        !           358:        | TYPE_CURSOR '=' '(' TYPE_NUMBER ',' TYPE_NUMBER ')'
        !           359:          {
        !           360:            if (curr_menu->cursor_x != -1) {
        !           361:                fprintf(stderr, "%s:%d: cursor position already defined.\n", config, line);
        !           362:                exit(1);
        !           363:            }
        !           364:            curr_menu->cursor_x = $4;
        !           365:            curr_menu->cursor_y = $6;
        !           366:          }
        !           367:        | TYPE_CMDQUEUE '[' TYPE_VALUE ']'
        !           368:          {
        !           369:              struct dg_menuoption *tmp;
        !           370:              struct dg_menuoption *tmpmenuopt;
        !           371:              if (curr_cmdqueue) {
        !           372:                  fprintf(stderr, "%s:%d: command queue already in use?\n", config, line);
        !           373:                  exit(1);
        !           374:              }
        !           375:              tmp = malloc(sizeof(struct dg_menuoption));
        !           376:              tmp->keys = strdup( $3 );
        !           377:              tmp->cmdqueue = NULL;
        !           378:              tmp->next = curr_menu->options;
        !           379:             curr_menu->options = tmp;
        !           380:          }
        !           381:        '=' cmdlist
        !           382:          {
        !           383:             curr_menu->options->cmdqueue = curr_cmdqueue;
        !           384:              curr_cmdqueue = NULL;
        !           385:          }
        !           386:        ;
        !           387:
        !           388:
        !           389: menu_definitions : menu_definition
        !           390:        | menu_definition menu_definitions
        !           391:        ;
        !           392:
        !           393:
        !           394: definemenu : TYPE_DEFINE_MENU '[' TYPE_VALUE ']'
        !           395:        {
        !           396:           struct dg_menulist *tmp_menulist = globalconfig.menulist;
        !           397:
        !           398:           while (tmp_menulist) {
        !           399:               if (!strcmp(tmp_menulist->menuname, $<s>3 )) {
        !           400:                    fprintf(stderr, "%s:%d: menu \"%s\" already defined.\n", config, line, $<s>3 );
        !           401:                    exit(1);
        !           402:               }
        !           403:               tmp_menulist = tmp_menulist->next;
        !           404:           }
        !           405:
        !           406:            tmp_menulist = malloc(sizeof(struct dg_menulist));
        !           407:            tmp_menulist->menuname = strdup( $<s>3 );
        !           408:            tmp_menulist->next = globalconfig.menulist;
        !           409:
        !           410:           globalconfig.menulist = tmp_menulist;
        !           411:
        !           412:            tmp_menulist->menu = malloc(sizeof(struct dg_menu));
        !           413:           curr_menu = tmp_menulist->menu;
        !           414:
        !           415:           curr_menu->options = NULL;
        !           416:           curr_menu->cursor_x = curr_menu->cursor_y = -1;
        !           417:           curr_menu->banner_fn = NULL;
        !           418:        }
        !           419:        '{' menu_definitions '}'
        !           420:        {
        !           421:            curr_menu = NULL;
        !           422:        }
        !           423:        ;
        !           424:
        !           425:
        !           426:
        !           427: game_definition : TYPE_CMDQUEUE
        !           428:        {
        !           429:            if (myconfig[ncnf]->cmdqueue) {
        !           430:                fprintf(stderr, "%s:%d: command queue defined twice, bailing out\n",
        !           431:                        config, line);
        !           432:                exit(1);
        !           433:            }
        !           434:        }
        !           435:        '=' cmdlist
        !           436:        {
        !           437:            myconfig[ncnf]->cmdqueue = curr_cmdqueue;
        !           438:            curr_cmdqueue = NULL;
        !           439:        }
        !           440:        | TYPE_POSTCMDQUEUE
        !           441:        {
        !           442:            if (myconfig[ncnf]->postcmdqueue) {
        !           443:                fprintf(stderr, "%s:%d: postcommand queue defined twice, bailing out\n",
        !           444:                        config, line);
        !           445:                exit(1);
        !           446:            }
        !           447:        }
        !           448:        '=' cmdlist
        !           449:        {
        !           450:            myconfig[ncnf]->postcmdqueue = curr_cmdqueue;
        !           451:            curr_cmdqueue = NULL;
        !           452:        }
        !           453:
        !           454:        | TYPE_GAME_ARGS '=' game_args_list
        !           455:        {
        !           456:            /* nothing */
        !           457:        }
        !           458:        | TYPE_EXTRA_INFO_FILE '=' TYPE_VALUE
        !           459:        {
        !           460:             myconfig[ncnf]->extra_info_file = strdup($3);
        !           461:         }
        !           462:         | TYPE_MAX_IDLE_TIME '=' TYPE_NUMBER
        !           463:         {
        !           464:             myconfig[ncnf]->max_idle_time = $3;
        !           465:         }
        !           466:        | KeyType '=' TYPE_VALUE
        !           467:        {
        !           468:            switch ( $1 ) {
        !           469:            case TYPE_PATH_CANNED:
        !           470:                if (myconfig[ncnf]->rcfile) free(myconfig[ncnf]->rcfile);
        !           471:                myconfig[ncnf]->rcfile = strdup($3);
        !           472:                break;
        !           473:
        !           474:            case TYPE_PATH_SPOOL:
        !           475:                if (myconfig[ncnf]->spool) free (myconfig[ncnf]->spool);
        !           476:                myconfig[ncnf]->spool = strdup($3);
        !           477:                break;
        !           478:
        !           479:            case TYPE_PATH_TTYREC:
        !           480:                if (myconfig[ncnf]->ttyrecdir) free(myconfig[ncnf]->ttyrecdir);
        !           481:                myconfig[ncnf]->ttyrecdir = strdup($3);
        !           482:                break;
        !           483:
        !           484:            case TYPE_PATH_GAME:
        !           485:                if (myconfig[ncnf]->game_path) free(myconfig[ncnf]->game_path);
        !           486:                myconfig[ncnf]->game_path = strdup ($3);
        !           487:                break;
        !           488:
        !           489:            case TYPE_NAME_GAME:
        !           490:                if (myconfig[ncnf]->game_name) free (myconfig[ncnf]->game_name);
        !           491:                myconfig[ncnf]->game_name = strdup($3);
        !           492:                break;
        !           493:
        !           494:            case TYPE_GAME_SHORT_NAME:
        !           495:                if (myconfig[ncnf]->shortname) free (myconfig[ncnf]->shortname);
        !           496:                myconfig[ncnf]->shortname = strdup($3);
        !           497:                break;
        !           498:
        !           499:            case TYPE_GAME_ID:
        !           500:                if (myconfig[ncnf]->game_id) free (myconfig[ncnf]->game_id);
        !           501:                myconfig[ncnf]->game_id = strdup($3);
        !           502:                break;
        !           503:
        !           504:            case TYPE_RC_FMT:
        !           505:                if (myconfig[ncnf]->rc_fmt) free(myconfig[ncnf]->rc_fmt);
        !           506:                myconfig[ncnf]->rc_fmt = strdup($3);
        !           507:                break;
        !           508:
        !           509:            case TYPE_PATH_INPROGRESS:
        !           510:                if (myconfig[ncnf]->inprogressdir) free(myconfig[ncnf]->inprogressdir);
        !           511:                myconfig[ncnf]->inprogressdir = strdup($3);
        !           512:                break;
        !           513:
        !           514:             case TYPE_ENCODING:
        !           515:                 if (!strcasecmp($3, "ask"))
        !           516:                     myconfig[ncnf]->encoding = -1;
        !           517:                 else if ((myconfig[ncnf]->encoding = encoding_by_name($3)) == -1)
        !           518:                 {
        !           519:                     fprintf(stderr, "%s:%d: invalid value for encoding: \"%s\"\n",
        !           520:                             config, line, $3);
        !           521:                     exit(1);
        !           522:                 }
        !           523:                 break;
        !           524:
        !           525:            default:
        !           526:                fprintf(stderr, "%s:%d: token does not belong into game definition, bailing out\n",
        !           527:                        config, line);
        !           528:                exit(1);
        !           529:            }
        !           530:        }
        !           531:        ;
        !           532:
        !           533: game_arg : TYPE_VALUE
        !           534:        {
        !           535:            char **tmpargs;
        !           536:            if (myconfig[ncnf]->bin_args) {
        !           537:                myconfig[ncnf]->num_args++;
        !           538:                tmpargs = calloc((myconfig[ncnf]->num_args+1), sizeof(char *));
        !           539:                memcpy(tmpargs, myconfig[ncnf]->bin_args, (myconfig[ncnf]->num_args * sizeof(char *)));
        !           540:                free(myconfig[ncnf]->bin_args);
        !           541:                myconfig[ncnf]->bin_args = tmpargs;
        !           542:            } else {
        !           543:                myconfig[ncnf]->num_args = 1;
        !           544:                myconfig[ncnf]->bin_args = calloc(2, sizeof(char *));
        !           545:            }
        !           546:            myconfig[ncnf]->bin_args[(myconfig[ncnf]->num_args)-1] = strdup($1);
        !           547:            myconfig[ncnf]->bin_args[(myconfig[ncnf]->num_args)] = 0;
        !           548:        }
        !           549:        ;
        !           550:
        !           551: game_args_list : game_arg
        !           552:        | game_arg ',' game_args_list
        !           553:        ;
        !           554:
        !           555: game_definitions : game_definition
        !           556:        | game_definition game_definitions
        !           557:        ;
        !           558:
        !           559: definegame : TYPE_DEFINE_GAME '{'
        !           560:        {
        !           561:            struct dg_config **tmpconfig = NULL;
        !           562:
        !           563:            tmpconfig = calloc(ncnf + 1, sizeof(myconfig[0]));
        !           564:            if (!tmpconfig) {
        !           565:                fprintf(stderr, "%s:%d: could not allocate memory for config, bailing out\n",
        !           566:                        config, line);
        !           567:                exit(1);
        !           568:            }
        !           569:
        !           570:            if (myconfig) {
        !           571:                int tmp;
        !           572:                for (tmp = 0; tmp < ncnf; tmp++) {
        !           573:                    tmpconfig[tmp] = myconfig[tmp];
        !           574:                }
        !           575:                free(myconfig);
        !           576:            }
        !           577:
        !           578:            tmpconfig[ncnf] = calloc(1, sizeof(struct dg_config));
        !           579:            myconfig = tmpconfig;
        !           580:        }
        !           581:        game_definitions '}'
        !           582:        {
        !           583:            if (myconfig[ncnf]->game_id == NULL && myconfig[ncnf]->shortname)
        !           584:                myconfig[ncnf]->game_id = strdup(myconfig[ncnf]->shortname);
        !           585:            ncnf++;
        !           586:            num_games = ncnf;
        !           587:        }
        !           588:        ;
        !           589:
        !           590: cmdlist : cmdlist ',' dglcmd
        !           591:        | dglcmd
        !           592:        ;
        !           593:
        !           594: dglcmd : TYPE_DGLCMD1 TYPE_VALUE
        !           595:          {
        !           596:              struct dg_cmdpart *tmp = malloc(sizeof(struct dg_cmdpart));
        !           597:              if (tmp) {
        !           598:                  struct dg_cmdpart *foo = curr_cmdqueue;
        !           599:                  if (foo) {
        !           600:                      while (foo->next) foo = foo->next;
        !           601:                      foo->next = tmp;
        !           602:                  } else curr_cmdqueue = tmp;
        !           603:                  tmp->next = NULL;
        !           604:                  tmp->param1 = strdup( $2 );
        !           605:                  tmp->param2 = NULL;
        !           606:                  tmp->cmd = $<i>1;
        !           607:
        !           608:              }
        !           609:          }
        !           610:        | TYPE_DGLCMD0
        !           611:          {
        !           612:              struct dg_cmdpart *tmp = malloc(sizeof(struct dg_cmdpart));
        !           613:              if (tmp) {
        !           614:                  struct dg_cmdpart *foo = curr_cmdqueue;
        !           615:                  if (foo) {
        !           616:                      while (foo->next) foo = foo->next;
        !           617:                      foo->next = tmp;
        !           618:                  } else curr_cmdqueue = tmp;
        !           619:                  tmp->next = NULL;
        !           620:                  tmp->param1 = NULL;
        !           621:                  tmp->param2 = NULL;
        !           622:                  tmp->cmd = $<i>1;
        !           623:              }
        !           624:          }
        !           625:        | TYPE_DGLCMD2 TYPE_VALUE TYPE_VALUE
        !           626:          {
        !           627:              struct dg_cmdpart *tmp = malloc(sizeof(struct dg_cmdpart));
        !           628:              if (tmp) {
        !           629:                  struct dg_cmdpart *foo = curr_cmdqueue;
        !           630:                  if (foo) {
        !           631:                      while (foo->next) foo = foo->next;
        !           632:                      foo->next = tmp;
        !           633:                  } else curr_cmdqueue = tmp;
        !           634:                  tmp->next = NULL;
        !           635:                  tmp->param1 = strdup( $2 );
        !           636:                  tmp->param2 = strdup( $3 );
        !           637:                  tmp->cmd = $<i>1;
        !           638:              }
        !           639:          }
        !           640:        ;
        !           641:
        !           642: KeyType : TYPE_SUSER   { $$ = TYPE_SUSER; }
        !           643:        | TYPE_SGROUP   { $$ = TYPE_SGROUP; }
        !           644:        | TYPE_SUID     { $$ = TYPE_SUID; }
        !           645:        | TYPE_SGID     { $$ = TYPE_SGID; }
        !           646:        | TYPE_MAX      { $$ = TYPE_MAX; }
        !           647:        | TYPE_MAXNICKLEN       { $$ = TYPE_MAXNICKLEN; }
        !           648:         | TYPE_MENU_MAX_IDLE_TIME      { $$ = TYPE_MENU_MAX_IDLE_TIME; }
        !           649:        | TYPE_PATH_CHROOT      { $$ = TYPE_PATH_CHROOT; }
        !           650:        | TYPE_ALLOW_REGISTRATION       { $$ = TYPE_ALLOW_REGISTRATION; }
        !           651:        | TYPE_PATH_GAME        { $$ = TYPE_PATH_GAME; }
        !           652:         | TYPE_NAME_GAME        { $$ = TYPE_NAME_GAME; }
        !           653:        | TYPE_GAME_SHORT_NAME  { $$ = TYPE_GAME_SHORT_NAME; }
        !           654:        | TYPE_GAME_ID  { $$ = TYPE_GAME_ID; }
        !           655:        | TYPE_PATH_DGLDIR      { $$ = TYPE_PATH_DGLDIR; }
        !           656:        | TYPE_PATH_SPOOL       { $$ = TYPE_PATH_SPOOL; }
        !           657:        | TYPE_PATH_BANNER      { $$ = TYPE_PATH_BANNER; }
        !           658:        | TYPE_PATH_CANNED      { $$ = TYPE_PATH_CANNED; }
        !           659:        | TYPE_PATH_TTYREC      { $$ = TYPE_PATH_TTYREC; }
        !           660:        | TYPE_PATH_PASSWD      { $$ = TYPE_PATH_PASSWD; }
        !           661:        | TYPE_PATH_LOCKFILE    { $$ = TYPE_PATH_LOCKFILE; }
        !           662:        | TYPE_PATH_INPROGRESS  { $$ = TYPE_PATH_INPROGRESS; }
        !           663:        | TYPE_ENCODING         { $$ = TYPE_ENCODING; }
        !           664:        | TYPE_LOCALE           { $$ = TYPE_LOCALE; }
        !           665:        | TYPE_DEFTERM          { $$ = TYPE_DEFTERM; }
        !           666:        | TYPE_UTF8ESC          { $$ = TYPE_UTF8ESC; }
        !           667:        | TYPE_FLOWCTRL         { $$ = TYPE_FLOWCTRL; }
        !           668:        | TYPE_RC_FMT           { $$ = TYPE_RC_FMT; }
        !           669:        | TYPE_WATCH_SORTMODE   { $$ = TYPE_WATCH_SORTMODE; }
        !           670:        | TYPE_FILEMODE         { $$ = TYPE_FILEMODE; }
        !           671:        ;
        !           672:
        !           673: %%
        !           674:
        !           675: const char* lookup_token (int t)
        !           676: {
        !           677:   switch (t)
        !           678:   {
        !           679:     case TYPE_SUSER: return "shed_user";
        !           680:     case TYPE_SGROUP: return "shed_group";
        !           681:     case TYPE_SUID: return "shed_uid";
        !           682:     case TYPE_SGID: return "shed_gid";
        !           683:     case TYPE_MAX: return "maxusers";
        !           684:     case TYPE_MAXNICKLEN: return "maxnicklen";
        !           685:     case TYPE_MENU_MAX_IDLE_TIME: return "menu_max_idle_time";
        !           686:     case TYPE_PATH_CHROOT: return "chroot_path";
        !           687:     case TYPE_PATH_GAME: return "game_path";
        !           688:     case TYPE_NAME_GAME: return "game_name";
        !           689:     case TYPE_ALLOW_REGISTRATION: return "allow_new_nicks";
        !           690:     case TYPE_GAME_SHORT_NAME: return "short_name";
        !           691:     case TYPE_GAME_ID: return "game_id";
        !           692:     case TYPE_PATH_DGLDIR: return "dglroot";
        !           693:     case TYPE_PATH_SPOOL: return "spooldir";
        !           694:     case TYPE_PATH_BANNER: return "banner";
        !           695:     case TYPE_PATH_CANNED: return "rc_template";
        !           696:     case TYPE_PATH_TTYREC: return "ttyrecdir";
        !           697:     case TYPE_PATH_INPROGRESS: return "inprogressdir";
        !           698:     case TYPE_GAME_ARGS: return "game_args";
        !           699:     case TYPE_MAX_IDLE_TIME: return "max_idle_time";
        !           700:     case TYPE_RC_FMT: return "rc_fmt";
        !           701:     case TYPE_WATCH_SORTMODE: return "sortmode";
        !           702:     case TYPE_WATCH_COLUMNS: return "watch_columns";
        !           703:     case TYPE_BANNERVARS: return "bannervars";
        !           704:     case TYPE_LOCALE: return "locale";
        !           705:     case TYPE_DEFTERM: return "default_term";
        !           706:     case TYPE_UTF8ESC: return "utf8esc";
        !           707:     case TYPE_FLOWCTRL: return "flowcontrol";
        !           708:     case TYPE_FILEMODE: return "filemode";
        !           709:     default: abort();
        !           710:   }
        !           711: }
        !           712:
        !           713: void yyerror(char const* s)
        !           714: {
        !           715:   if (!silent)
        !           716:     fprintf(stderr, "%s:%d:%d: couldn't parse \"%s\": %s\n", config, line, col, yytext, s);
        !           717: }

CVSweb