Example #1
0
static void
parse_command_line(int argc, char ** argv,
                   struct cmdline_info *cmdline_p) {
/*----------------------------------------------------------------------------
   Note that the file spec array we return is stored in the storage that
   was passed to us as the argv array.
-----------------------------------------------------------------------------*/
    optStruct *option_def = malloc(100*sizeof(optStruct));
        /* Instructions to OptParseOptions2 on how to parse our options.
         */
    optStruct2 opt;

    unsigned int option_def_index;

    option_def_index = 0;   /* incremented by OPTENTRY */
    OPTENTRY(0,   "alphaout",   OPT_STRING, &cmdline_p->alpha_filename, 0);
    OPTENTRY(0,   "verbose",    OPT_FLAG,   &cmdline_p->verbose,        0);

    cmdline_p->alpha_filename = NULL;
    cmdline_p->verbose = FALSE;

    opt.opt_table = option_def;
    opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
    opt.allowNegNum = TRUE;  /* We may have parms that are negative numbers */

    optParseOptions2(&argc, argv, opt, 0);
        /* Uses and sets argc, argv, and some of *cmdline_p and others. */

    if (argc - 1 == 0)
        cmdline_p->input_filespec = NULL;  /* he wants stdin */
    else if (argc - 1 == 1)
        cmdline_p->input_filespec = strdup(argv[1]);
    else 
        pm_error("Too many arguments.  The only argument accepted\n"
                 "is the input file specification");

    if (cmdline_p->alpha_filename && 
        STREQ(cmdline_p->alpha_filename, "-"))
        cmdline_p->alpha_stdout = TRUE;
    else 
        cmdline_p->alpha_stdout = FALSE;

}
Example #2
0
static void
parse_command_line(int argc, char ** argv,
                   struct cmdline_info *cmdline_p) {
/*----------------------------------------------------------------------------
   Note that the file spec array we return is stored in the storage that
   was passed to us as the argv array.
-----------------------------------------------------------------------------*/
    optStruct *option_def = malloc(100*sizeof(optStruct));
        /* Instructions to OptParseOptions2 on how to parse our options.
         */
    optStruct2 opt;

    unsigned int option_def_index;

    option_def_index = 0;   /* incremented by OPTENTRY */
    OPTENTRY(0,   "left",       OPT_INT,    &cmdline_p->left,           0);
    OPTENTRY(0,   "right",      OPT_INT,    &cmdline_p->right,          0);
    OPTENTRY(0,   "top",        OPT_INT,    &cmdline_p->top,            0);
    OPTENTRY(0,   "bottom",     OPT_INT,    &cmdline_p->bottom,         0);
    OPTENTRY(0,   "width",      OPT_INT,    &cmdline_p->width,          0);
    OPTENTRY(0,   "height",     OPT_INT,    &cmdline_p->height,         0);
    OPTENTRY(0,   "pad",        OPT_FLAG,   &cmdline_p->pad,            0);
    OPTENTRY(0,   "verbose",    OPT_FLAG,   &cmdline_p->verbose,        0);

    /* Set the defaults */
    cmdline_p->left = UNSPEC;
    cmdline_p->right = UNSPEC;
    cmdline_p->top = UNSPEC;
    cmdline_p->bottom = UNSPEC;
    cmdline_p->width = UNSPEC;
    cmdline_p->height = UNSPEC;
    cmdline_p->pad = FALSE;
    cmdline_p->verbose = FALSE;

    opt.opt_table = option_def;
    opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
    opt.allowNegNum = TRUE;  /* We may have parms that are negative numbers */

    optParseOptions2(&argc, argv, opt, 0);
        /* Uses and sets argc, argv, and some of *cmdline_p and others. */

    if (cmdline_p->width < 0)
        pm_error("-width may not be negative.");
    if (cmdline_p->height < 0)
        pm_error("-height may not be negative.");

    if ((argc-1) != 0 && (argc-1) != 1 && (argc-1) != 4 && (argc-1) != 5)
        pm_error("Wrong number of arguments.  "
                 "Must be 0, 1, 4, or 5 arguments.");

    switch (argc-1) {
    case 0:
        cmdline_p->input_filespec = "-";
        break;
    case 1:
        cmdline_p->input_filespec = argv[1];
        break;
    case 4:
    case 5: {
        int warg, harg;  /* The "width" and "height" command line arguments */

        if (sscanf(argv[1], "%d", &cmdline_p->left) != 1)
            pm_error("Invalid number for left column argument");
        if (sscanf(argv[2], "%d", &cmdline_p->top) != 1)
            pm_error("Invalid number for top row argument");
        if (sscanf(argv[3], "%d", &warg) != 1)
            pm_error("Invalid number for width argument");
        if (sscanf(argv[4], "%d", &harg) != 1)
            pm_error("Invalid number for height argument");

        if (warg > 0) {
            cmdline_p->width = warg;
            cmdline_p->right = UNSPEC;
        } else {
            cmdline_p->width = UNSPEC;
            cmdline_p->right = warg -1;
        }
        if (harg > 0) {
            cmdline_p->height = harg;
            cmdline_p->bottom = UNSPEC;
        } else {
            cmdline_p->height = UNSPEC;
            cmdline_p->bottom = harg - 1;
        }

        if (argc-1 == 4)
            cmdline_p->input_filespec = "-";
        else
            cmdline_p->input_filespec = argv[5];
        break;
    }
    }
}
Example #3
0
void genobj( void )
{
    short int *symbol, *target;
    short int *p, *q, *r;
    short int action;
    set_size *mp;
    a_sym *sym;
    a_pro *pro;
    an_item *item;
    a_state *x;
    a_shift_action *tx;
    a_reduce_action *rx;
    int i, j, savings;

    for( i = nterm; i < nsym; ++i )
        symtab[i]->token = i - nterm;

    label = OPTENTRY( nstate - 1 );

    emitins( JMP, TOKENTRY( startstate->sidx ) );

    target = CALLOC( nsym, short int );
    for( i = 0; i < nsym; ++i )
        target[i] = DEFAULT;
    symbol = CALLOC( nsym, short int );
    for( i = 0; i < nstate; ++i ) {
        x = statetab[i];
        q = symbol;
        for( tx = x->trans; (sym = tx->sym) != NULL; ++tx ) {
            if( sym == eofsym ) {
                action = ACCEPT;
            } else if( sym->idx < nterm ) {
                action = TOKENTRY(tx->state->sidx);
            } else {
                action = OPTENTRY(tx->state->sidx);
            }
            *q++ = sym->idx;
            target[sym->idx] = action;
        }
        savings = 0;
        for( rx = x->redun; (pro = rx->pro) != NULL; ++rx ) {
            action = PROENTRY( pro->pidx );
            mp = Members( rx->follow );
            if( mp - setmembers > savings ) {
                savings = mp - setmembers;
                r = q;
            }
            while( --mp >= setmembers ) {
                *q++ = *mp;
                target[*mp] = action;
            }
        }
        action = DEFAULT;
        if( savings ) {
            action = target[*r];
            p = r;
            while( --savings >= 0 ) {
                target[*p++] = DEFAULT;
            }
        }

        emitins( LBL, TOKENTRY( x->sidx ) );
        emitins( SCAN, 0 );
        emitins( LBL, OPTENTRY( x->sidx ) );
        emitins( CALL, VBLENTRY( x->sidx ) );
        q = symbol;
        for( j = nterm; j < nsym; ++j ) {
            if( target[j] != DEFAULT ) {
                *q++ = j;
            }
        }
        if( q != symbol ) {
            emitv( symbol, target, q - symbol );
            for( p = symbol; p < q; ++p ) {
                target[*p] = DEFAULT;
            }
        }
        emitins( LBL, VBLENTRY( x->sidx ) );

        q = symbol;
        for( j = 0; j < nterm; ++j ) {
            if( target[j] != DEFAULT ) {
                *q++ = j;
            }
        }
        emitt( symbol, target, q - symbol, action );
        for( p = symbol; p < q; ++p ) {
            target[*p] = DEFAULT;
        }
    }

    FREE( target );
    FREE( symbol );

    for( i = 0; i < npro; ++i ) {
        pro = protab[i];
        if( pro != startpro ) {
            for( item = pro->item; item->p.sym != NULL; ) {
                ++item;
            }
            emitins( LBL, PROENTRY( pro->pidx ) );
            emitins( ACTION, PROPACK( item - pro->item, i ) );
            emitins( REDUCE, PROPACK( item - pro->item, pro->sym->token ) );
        }
    }

    writeobj( label + 1 );
}