Exemplo n.º 1
0
void sc_changeFile(char *s)               /* name of source file to open */
{
    register int slen;

    if (*s)                                 /* any filename ? */
    {
        if (!gs_fileSp--)                          /* no more entries ? */
            rss_fatal(0, 0, "more than 10 nested #include directives");

                                            /* save the name and line nr. 
                                               of the file */
        gs_fileStack[gs_fileSp].fname = rss_strdup(s); 
        gs_fileStack[gs_fileSp].former_linenr = yylineno;

        gs_filenames = rss_realloc(gs_filenames, /* room for new filename */
                        filenames_len +
                        (slen = strlen(s)) +
                        2);
                                            /* append name */
        sprintf(gs_filenames + filenames_len, "%s\n", s);
        filenames_len += slen + 1;          /* new length of string */

        yylineno = 0;                       /* start at new file */
    }

    util_setSourceName(gs_fileStack[gs_fileSp].fname);
}
Exemplo n.º 2
0
SemVal *p_execute(SemVal *arr)
{
    register size_t count;
    SemVal
        tmp,
        *argp,                              /* pointer to args */
        e;

    count = arr->type;                      /* get argument count */

    if (count < 6)                          /* to few arguments */
    {
        util_semantic(gp_illegalArgCount, "execute");
        return (arr);                       /* dummy  args return */
    }

    argp = codestruc(arr, 0);               /* point to first arg */
    e = *(argp + 2);                        /* cmd head info at e */

    p_callRss(&e, f_cmd_head);                /* code for cmd_head at e */

    p_callRss(argp + 3, f_arg_head);          /* code for arg_head */
    p_catCode(&e, argp + 3);                  /* code appended to e*/

    p_callRss(&argp[count - 2], f_arg_tail);  /* code for arg_tail */
    p_catCode(&e, &argp[count - 2]);          /* code appended to e*/

    p_callRss(&argp[count - 1], f_cmd_tail);  /* code for cmd_tail */
    p_catCode(&e, &argp[count - 1]);          /* code appended to e*/

                                            /* keep variable # of args */
    memmove(argp + 2, argp + 4, (count - 2) * sizeof(SemVal));
    arr->type -= 4;                         /* remove 4 arguments */

    p_catCode(&e, p_specials(f_exec, arr));     /* catenate call-code */

    free(gp_stringbuf);                        /* make sure empty string */
    gp_stringbuf = rss_strdup("");              /* is pushed */

    tmp = *p_stackFrame(e_str | e_const);     /* empty string argument */

    p_expr2stack(&tmp);
    p_catCode(&e, &tmp);                      /* empty string on the stack */

    p_generateCode(&e, op_call_rss, f_cmd_tail);   /* used with cmd_tail..cmd_head */
    p_generateCode(&e, op_call_rss, f_arg_tail);
    p_generateCode(&e, op_call_rss, f_arg_head);

    p_callRss(&e, f_cmd_head);

    *arr = e;
    return arr;
}
Exemplo n.º 3
0
VarIndex st_addVar(ExprType type)
{
    VarInfo *vi;
    unsigned idx = st_nextVarIdx(&vi);

    vi->name = rss_strdup(util_string());      /* set the name of the var */
    vi->type = type | e_var;          /* set the type of the var */
    vi->value = 0;

    VarIndex ret = {idx, st_nestingOffset() > 0};
    return ret;
}
Exemplo n.º 4
0
void OptionsCons(int argc, char **argv)
{
    regComp(&sopts.d_icmconfRE, 
            "^[ \t]*#define[ \t]*"
                    "([^ \t]+)"     //      #1: key 
                    "[ \t]*\""
                    "([^\"]+)?"     //      #2: value (opt)
                    "\"");        

    sopts.d_classes    = "CLASSES";
    sopts.d_icmconf    = "icmconf";
    sopts.d_mainih     = "main.ih";
    sopts.d_ih         = ".ih";

    sopts.d_use_all    = (char *)UNSPECIFIED;  // by default: read icmconf
    sopts.d_gch        = UNSPECIFIED;
    sopts.d_go         = UNSPECIFIED;

    int showVersion = 0;
    int sawOptions = 0;

    while (1)
    {
        int opt = getopt_long(argc, argv, "cdimhvV", longOpts, NULL);

        sawOptions |= opt != -1;

        switch (opt)
        {
            case 'c':
                sopts.d_classes = rss_strdup(optarg);
            break;

            case 'G':
                sopts.d_gch = GCH;
                optMsg(2, "inspecting .gch files");
            break;

            case 'h':
                usage(argv[0]);
            break;                  // usage exits

            case 'i':
                sopts.d_icmconf = rss_strdup(optarg);
                optMsg(2, "using icmconf `%s'", optarg);
            break;

            case 'm':
                sopts.d_mainih = rss_strdup(optarg);
                optMsg(2, "using main.ih `%s'", optarg);
            break;

            case 'u':
                sopts.d_use_all = rss_strdup(optarg);
                optMsg(2, "using USE_ALL filename `%s'", optarg);
            break;

            case 'U':
                sopts.d_use_all = NULL;
                optMsg(2, "not inspecting USE_ALL files");
            break;

            case 'v':
                showVersion = 1;
            break;

            case 'V':
                ++sopts.d_verbose;
            break;

            case '?':
                printf("no option '-%c'\n", (char)opt);
                exit(1);
            break;

            case -1:
                if (showVersion)
                {
                    printf("V %s\n", version);
                    exit(0);
                }

                if (argc != optind)
                    sopts.d_go = strcmp(argv[optind], "go") == 0 ? GO : DRY;
                else
                {
                    if (!sawOptions)
                        usage(argv[0]);
                    sopts.d_go = DRY;
                }

                if (!rss_exists(sopts.d_classes))
                {
                    optMsg(2, "No file '%s'", sopts.d_classes);
                    exit(0);
                }

                oIcmconf(argv[0]);
            return;
        }
    }
}