void Film::read(std::ifstream &f){
    int i;
    Media::read(f);
    f>>num; skipnl(f);
    for (i=0;i<num-1;i++)
        f>>tab[i];skipnl(f);
}
Exemple #2
0
Fichier : cmd.c Projet : 8l/FUZIX
static REGPTR syncase(register int esym)
{
	skipnl();
	if (wdval == esym) {
		return (0);
	} else {
		register REGPTR r = (REGPTR) getstak(REGTYPE);
		r->regptr = 0;
		for (;;) {
			wdarg->argnxt = r->regptr;
			r->regptr = wdarg;
			if (wdval || (word() != ')' && wdval != '|')) {
				synbad();
			}
			if (wdval == '|') {
				word();
			} else {
				break;
			}
		}
		r->regcom = cmd(0, NLFLG | MTFLG);
		if (wdval == ECSYM) {
			r->regnxt = syncase(esym);
		} else {
			chksym(esym);
			r->regnxt = 0;
		}
		return (r);
	}
}
Exemple #3
0
FILE_LOCAL
void dump_line(struct Global *global, int *counter)
{
    skipnl( global );         /* Ignore rest of line  */

    (*counter)++;
}
Exemple #4
0
Fichier : cmd.c Projet : 8l/FUZIX
static TREPTR term(int flg)
{
	register TREPTR t;

	reserv++;
	if (flg & NLFLG)
		skipnl();
	else
		word();

	if ((t = item(TRUE)) && (wdval == '^' || wdval == '|')) {
		return (makelist(TFIL, makefork(FPOU, t),
			 makefork(FPIN | FPCL, term(NLFLG))));
	} else
		return (t);
}
Exemple #5
0
FILE_LOCAL
void doif(int hash)
/*
 * Process an #if, #ifdef, or #ifndef.  The latter two are straightforward,
 * while #if needs a subroutine of its own to evaluate the expression.
 *
 * doif() is called only if compiling is TRUE.  If false, compilation
 * is always supressed, so we don't need to evaluate anything.  This
 * supresses unnecessary warnings.
 */
{
        register int            c;
        register int            found;

        if ((c = skipws()) == '\n' || c == EOF_CHAR) {
            unget();
            goto badif;
        }
        if (hash == L_if) {
            unget();
            found = (eval() != 0);      /* Evaluate expr, != 0 is  TRUE */
            hash = L_ifdef;             /* #if is now like #ifdef       */
        }
        else {
            if (type[c] != LET)         /* Next non-blank isn't letter  */
                goto badif;             /* ... is an error              */
            found = (lookid(c) != NULL); /* Look for it in symbol table */
        }
        if (found == (hash == L_ifdef)) {
            compiling = TRUE;
            *ifptr |= TRUE_SEEN;
        }
        else {
            compiling = FALSE;
        }
        return;

badif:  cerror("#if, #ifdef, or #ifndef without an argument", NULLST);
#if !OLD_PREPROCESSOR
        skipnl();                               /* Prevent an extra     */
        unget();                                /* Error message        */
#endif
        return;
}
Exemple #6
0
/*
 * Process an #if, #ifdef, or #ifndef.  The latter two are straightforward,
 * while #if needs a subroutine of its own to evaluate the expression.
 *
 * doif() is called only if compiling is TRUE.  If false, compilation
 * is always suppressed, so we don't need to evaluate anything.  This
 * suppresses unnecessary warnings.
 */
FILE_LOCAL void doif(int hash)
{
    int c;
    int found;

    if ((c = skipws()) == '\n' || c == EOF_CHAR)
    {
        unget();
        goto badif;
    }
    if (hash == L_if)
    {
        unget();
        found = (eval() != 0);      /* Evaluate expr, != 0 is  TRUE */
        hash = L_ifdef;             /* #if is now like #ifdef       */
    }
    else
    {
        if (type[c] != LET)         /* Next non-blank isn't letter  */
            goto badif;             /* ... is an error              */
        found = (lookid(c) != NULL); /* Look for it in symbol table */
    }
    if (found == (hash == L_ifdef))
    {
        compiling = TRUE;
        *ifptr |= TRUE_SEEN;
    }
    else
    {
        compiling = FALSE;
    }
    return;

  badif:  cerror("#if, #ifdef, or #ifndef without an argument", NULLST);
    skipnl();                               /* Prevent an extra     */
    unget();                                /* Error message        */
    return;
}
Exemple #7
0
int
control(int counter)
/*
 * Process #control lines.  Simple commands are processed inline,
 * while complex commands have their own subroutines.
 *
 * The counter is used to force out a newline before #line, and
 * #pragma commands.  This prevents these commands from ending up at
 * the end of the previous line if cpp is invoked with the -C option.
 */
{
        register int            c;
        register char           *tp;
        register int            hash;
        char                    *ep;

        c = skipws();
        if (c == '\n' || c == EOF_CHAR)
            return (counter + 1);
        if (!isdigit(c))
            scanid(c);                  /* Get #word to token[]         */
        else {
            unget();                    /* Hack -- allow #123 as a      */
            strcpy(token, "line");      /* synonym for #line 123        */
        }
        hash = (token[1] == EOS) ? L_nogood : (token[0] + (token[2] << 1));
        switch (hash) {
        case L_assert:  tp = "assert";          break;
        case L_define:  tp = "define";          break;
        case L_elif:    tp = "elif";            break;
        case L_else:    tp = "else";            break;
        case L_endif:   tp = "endif";           break;
        case L_if:      tp = "if";              break;
        case L_ifdef:   tp = "ifdef";           break;
        case L_ifndef:  tp = "ifndef";          break;
        case L_include: tp = "include";         break;
        case L_line:    tp = "line";            break;
        case L_pragma:  tp = "pragma";          break;
        case L_undef:   tp = "undef";           break;
        case L_error:   tp = "error";           break;
#if OSL_DEBUG_LEVEL > 1
        case L_debug:   tp = "debug";           break;
        case L_nodebug: tp = "nodebug";         break;
#endif
        default:        hash = L_nogood;
        case L_nogood:  tp = "";                break;
        }
        if (!streq(tp, token))
            hash = L_nogood;
        /*
         * hash is set to a unique value corresponding to the
         * control keyword (or L_nogood if we think it's nonsense).
         */
        if (infile->fp == NULL)
            cwarn("Control line \"%s\" within macro expansion", token);
        if (!compiling) {                       /* Not compiling now    */
            switch (hash) {
            case L_if:                          /* These can't turn     */
            case L_ifdef:                       /*  compilation on, but */
            case L_ifndef:                      /*   we must nest #if's */
                if (++ifptr >= &ifstack[BLK_NEST])
                    goto if_nest_err;
                *ifptr = 0;                     /* !WAS_COMPILING       */
            case L_line:                        /* Many                 */
            /*
             * Are pragma's always processed?
             */
            case L_pragma:                      /*  options             */
            case L_include:                     /*   are uninteresting  */
            case L_define:                      /*    if we             */
            case L_undef:                       /*     aren't           */
            case L_assert:                      /*      compiling.      */
            case L_error:                       /* BP 5.3.92, #error */
dump_line:      skipnl();                       /* Ignore rest of line  */
                return (counter + 1);
            }
        }
        /*
         * Make sure that #line and #pragma are output on a fresh line.
         */
        if (counter > 0 && (hash == L_line || hash == L_pragma)) {
            PUTCHAR('\n');
            counter--;
        }
        switch (hash) {
        case L_line:
            /*
             * Parse the line to update the line number and "progname"
             * field and line number for the next input line.
             * Set wrongline to force it out later.
             */
            c = skipws();
            workp = work;                       /* Save name in work    */
            while (c != '\n' && c != EOF_CHAR) {
                save(c);
                c = get();
            }
            unget();
            save(EOS);
            /*
             * Split #line argument into <line-number> and <name>
             * We subtract 1 as we want the number of the next line.
             */
            line = atoi(work) - 1;              /* Reset line number    */
            for (tp = work; isdigit(*tp) || type[(int)*tp] == SPA; tp++)
                ;                               /* Skip over digits     */
            if (*tp != EOS) {                   /* Got a filename, so:  */
                if (*tp == '"' && (ep = strrchr(tp + 1, '"')) != NULL) {
                    tp++;                       /* Skip over left quote */
                    *ep = EOS;                  /* And ignore right one */
                }
                if (infile->progname != NULL)   /* Give up the old name */
                    free(infile->progname);     /* if it's allocated.   */
                infile->progname = savestring(tp);
            }
            wrongline = TRUE;                   /* Force output later   */
            break;

        case L_include:
            doinclude();
            break;

        case L_define:
            dodefine();
            break;

        case L_undef:
            doundef();
            break;

        case L_else:
            if (ifptr == &ifstack[0])
                goto nest_err;
            else if ((*ifptr & ELSE_SEEN) != 0)
                goto else_seen_err;
            *ifptr |= ELSE_SEEN;
            if ((*ifptr & WAS_COMPILING) != 0) {
                if (compiling || (*ifptr & TRUE_SEEN) != 0)
                    compiling = FALSE;
                else {
                    compiling = TRUE;
                }
            }
            break;

        case L_elif:
            if (ifptr == &ifstack[0])
                goto nest_err;
            else if ((*ifptr & ELSE_SEEN) != 0) {
else_seen_err:  cerror("#%s may not follow #else", token);
                goto dump_line;
            }
            if ((*ifptr & (WAS_COMPILING | TRUE_SEEN)) != WAS_COMPILING) {
                compiling = FALSE;              /* Done compiling stuff */
                goto dump_line;                 /* Skip this clause     */
            }
            doif(L_if);
            break;

        case L_if:
        case L_ifdef:
        case L_ifndef:
            if (++ifptr >= &ifstack[BLK_NEST])
if_nest_err:    cfatal("Too many nested #%s statements", token);
            *ifptr = WAS_COMPILING;
            doif(hash);
            break;

        case L_endif:
            if (ifptr == &ifstack[0]) {
nest_err:       cerror("#%s must be in an #if", token);
                goto dump_line;
            }
            if (!compiling && (*ifptr & WAS_COMPILING) != 0)
                wrongline = TRUE;
            compiling = ((*ifptr & WAS_COMPILING) != 0);
            --ifptr;
            break;

        case L_assert:
            if (eval() == 0)
                cerror("Preprocessor assertion failure", NULLST);
            break;

        case L_pragma:
            /*
             * #pragma is provided to pass "options" to later
             * passes of the compiler.  cpp doesn't have any yet.
             */
            fprintf( pCppOut, "#pragma ");
            while ((c = get()) != '\n' && c != EOF_CHAR)
                cput(c);
            unget();
            break;

#if OSL_DEBUG_LEVEL > 1
        case L_debug:
            if (debug == 0)
                dumpdef("debug set on");
            debug++;
            break;

        case L_nodebug:
            debug--;
            break;
#endif
        case L_error:                       /* BP 5.3.92, #error */
        {
            fprintf( pCppOut, "cpp: line %u, Error directive: ", line );
            while ((c = get()) != '\n' && c != EOF_CHAR)
                cput(c);
            fprintf( pCppOut, "\n" );
            exit( 1 );
            break;
        }
        default:
            /*
             * Undefined #control keyword.
             * Note: the correct behavior may be to warn and
             * pass the line to a subsequent compiler pass.
             * This would allow #asm or similar extensions.
             */
            cerror("Illegal # command \"%s\"", token);
            break;
        }
        if (hash != L_include) {
#if OLD_PREPROCESSOR
            /*
             * Ignore the rest of the #control line so you can write
             *          #if     foo
             *          #endif  foo
             */
            goto dump_line;                     /* Take common exit     */
#else
            if (skipws() != '\n') {
                cwarn("Unexpected text in #control line ignored", NULLST);
                skipnl();
            }
#endif
        }
        return (counter + 1);
}
//    Load the Harmonic Constant Invariants
TC_Error_Code TCDS_Ascii_Harmonic::LoadHarmonicConstants(const wxString &data_file_path)
{
    FILE *fp;
    char linrec[linelen];
    char junk[80];
    int a, b;

    free_data();

    fp = fopen (data_file_path.mb_str(), "r");
    if (NULL == fp)
        return TC_FILE_NOT_FOUND;

    read_next_line (fp, linrec, 0);
    sscanf (linrec, "%d", &num_csts);

    m_cst_speeds = (double *) malloc (num_csts * sizeof (double));
    m_work_buffer = (double *) malloc (num_csts * sizeof (double));

    /* Load constituent speeds */
    for (a=0; a<num_csts; a++) {
        read_next_line (fp, linrec, 0);
        sscanf (linrec, "%s %lf", junk, &(m_cst_speeds[a]));
        m_cst_speeds[a] *= M_PI / 648000; /* Convert to radians per second */
    }

    /* Get first year for nodes and epochs */
    read_next_line (fp, linrec, 0);
    sscanf (linrec, "%d", &m_first_year);

    /* Load epoch table */
    read_next_line (fp, linrec, 0);
    sscanf (linrec, "%d", &num_epochs);

    m_cst_epochs = (double **) malloc (num_csts * sizeof (double *));
    for (int i=0; i<num_csts; i++)
        m_cst_epochs[i] = (double *) malloc (num_epochs * sizeof (double));

    for (int i=0; i<num_csts; i++)
    {
        if(EOF == fscanf (fp, "%s", linrec))
            return TC_HARM_FILE_CORRUPT;
        for (int b=0; b<num_epochs; b++)
        {
            if(EOF == fscanf (fp, "%lf", &(m_cst_epochs[i][b])))
                return TC_HARM_FILE_CORRUPT;
            m_cst_epochs[i][b] *= M_PI / 180.0;
        }
    }


    /* Sanity check */
    if(EOF == fscanf (fp, "%s", linrec))
        return TC_HARM_FILE_CORRUPT;
    skipnl (fp);

    /* Load node factor table */
    read_next_line (fp, linrec, 0);
    sscanf (linrec, "%d", &num_nodes);

    m_cst_nodes = (double **) malloc (num_csts * sizeof (double *));
    for (int a=0; a<num_csts; a++)
        m_cst_nodes[a] = (double *) malloc (num_nodes * sizeof (double));

    for (int a=0; a<num_csts; a++) {
        int ignore = fscanf (fp, "%s", linrec);
        for (b=0; b<num_nodes; b++)
            ignore = fscanf (fp, "%lf", &(m_cst_nodes[a][b]));
    }

    fclose(fp);

    return TC_NO_ERROR;
}
Exemple #9
0
ReturnCode control( struct Global *global,
    int *counter )  /* Pending newline counter */
{
    /*
     * Process #control lines.  Simple commands are processed inline,
     * while complex commands have their own subroutines.
     *
     * The counter is used to force out a newline before #line, and
     * #pragma commands.  This prevents these commands from ending up at
     * the end of the previous line if cpp is invoked with the -C option.
     */

    int c;
    char *tp;
    int hash;
    char *ep;
    ReturnCode ret;

    c = skipws( global );

    if( c == '\n' || c == EOF_CHAR )
        {
        (*counter)++;

        return(FPP_OK);
        }

    if( !isdigit(c) )
        scanid( global, c );                  /* Get #word to tokenbuf        */
    else
        {
        unget( global );                    /* Hack -- allow #123 as a      */

        strcpy( global->tokenbuf, "line" );   /* synonym for #line 123        */
        }

    hash = (global->tokenbuf[1] == EOS) ? L_nogood : (global->tokenbuf[0] + (global->tokenbuf[2] << 1));

    switch( hash )
        {
        case L_assert:
            tp = "assert";
            break;
        case L_define:
            tp = "define";
            break;
        case L_elif:
            tp = "elif";
            break;
        case L_else:
            tp = "else";
            break;
        case L_endif:
            tp = "endif";
            break;
        case L_error:
            tp = "error";
            break;
        case L_if:
            tp = "if";
            break;
        case L_ifdef:
            tp = "ifdef";
            break;
        case L_ifndef:
            tp = "ifndef";
            break;
        case L_include:
            tp = "include";
            break;
        case L_line:
            tp = "line";
            break;
        case L_pragma:
            tp = "pragma";
            break;
        case L_undef:
            tp = "undef";
            break;
        default:
            hash = L_nogood;
        case L_nogood:
            tp = "";
            break;
        }

    if( !streq( tp, global->tokenbuf ) )
        hash = L_nogood;

    /*
     * hash is set to a unique value corresponding to the
     * control keyword (or L_nogood if we think it's nonsense).
     */
    if( global->infile->fp == NULL )
        cwarn( global, WARN_CONTROL_LINE_IN_MACRO, global->tokenbuf );

    if( !compiling )
        {                       /* Not compiling now    */
        switch( hash )
            {
            case L_if:              /* These can't turn     */
            case L_ifdef:           /*  compilation on, but */
            case L_ifndef:          /*   we must nest #if's */
                if( ++global->ifptr >= &global->ifstack[BLK_NEST] )
                    {
                    cfatal( global, FATAL_TOO_MANY_NESTINGS, global->tokenbuf );

                    return( FPP_TOO_MANY_NESTED_STATEMENTS );
                    }

                *global->ifptr = 0;       /* !WAS_COMPILING   */

            case L_line:            /* Many         */
                /*
                 * Are pragma's always processed?
                 */
            case L_pragma:          /*  options     */
            case L_include:         /*   are uninteresting  */
            case L_define:          /*    if we     */
            case L_undef:           /*     aren't           */
            case L_assert:          /*  compiling.  */
            case L_error:
                dump_line( global, counter );       /* Ignore rest of line  */
                return(FPP_OK);
            }
        }
    /*
     * Make sure that #line and #pragma are output on a fresh line.
     */
    if( *counter > 0 && (hash == L_line || hash == L_pragma) )
        {
        Putchar( global, '\n' );

        (*counter)--;
        }

    switch( hash )
        {
        case L_line:
            /*
             * Parse the line to update the line number and "progname"
             * field and line number for the next input line.
             * Set wrongline to force it out later.
             */
            c = skipws( global );

            global->workp = global->work;       /* Save name in work    */

            while( c != '\n' && c != EOF_CHAR )
                {
                if( (ret = save( global, c )) )
                    return(ret);

                c = get( global );
                }

            unget( global );

            if( (ret = save( global, EOS )) )
                return(ret);

            /*
             * Split #line argument into <line-number> and <name>
             * We subtract 1 as we want the number of the next line.
             */
            global->line = atoi(global->work) - 1;     /* Reset line number    */

            for( tp = global->work; isdigit(*tp) || type[(unsigned)*tp] == SPA; tp++)
                ;             /* Skip over digits */

            if( *tp != EOS )
                {
                /* Got a filename, so:  */

                if( *tp == '"' && (ep = strrchr(tp + 1, '"')) != NULL )
                    {
                    tp++;           /* Skip over left quote */

                    *ep = EOS;      /* And ignore right one */
                    }

                if( global->infile->progname != NULL )
                    /* Give up the old name if it's allocated.   */
                    free( global->infile->progname );

                global->infile->progname = savestring( global, tp );
                }

            global->wrongline = TRUE;           /* Force output later   */
            break;

        case L_include:
            ret = doinclude( global );
            if( ret )
                return(ret);
            break;

        case L_define:
            ret = dodefine( global );
            if( ret )
                return(ret);
            break;

        case L_undef:
            doundef( global );
            break;

        case L_else:
            if( global->ifptr == &global->ifstack[0] )
                {
                cerror( global, ERROR_STRING_MUST_BE_IF, global->tokenbuf );

                dump_line( global, counter );

                return( FPP_OK );
                }
            else if( (*global->ifptr & ELSE_SEEN) != 0 )
                {
                cerror( global, ERROR_STRING_MAY_NOT_FOLLOW_ELSE, global->tokenbuf );

                dump_line( global, counter );

                return( FPP_OK );
                }

            *global->ifptr |= ELSE_SEEN;

            if( (*global->ifptr & WAS_COMPILING) != 0 )
                {
                if( compiling || (*global->ifptr & TRUE_SEEN) != 0 )
                    compiling = FALSE;
                else
                    {
                    compiling = TRUE;
                    }
                }
            break;

        case L_elif:
            if( global->ifptr == &global->ifstack[0] )
                {
                cerror( global, ERROR_STRING_MUST_BE_IF, global->tokenbuf );

                dump_line( global, counter );

                return( FPP_OK );
                }
            else if( (*global->ifptr & ELSE_SEEN) != 0 )
                {
                cerror( global, ERROR_STRING_MAY_NOT_FOLLOW_ELSE, global->tokenbuf );

                dump_line( global, counter );

                return( FPP_OK );
                }

            if( (*global->ifptr & (WAS_COMPILING | TRUE_SEEN)) != WAS_COMPILING )
                {
                compiling = FALSE;        /* Done compiling stuff */

                dump_line( global, counter );   /* Skip this clause */

                return( FPP_OK );
                }

            ret = doif( global, L_if );

            if( ret )
                return(ret);

            break;

        case L_error:
            cerror(global, ERROR_ERROR);
            break;

        case L_if:
        case L_ifdef:
        case L_ifndef:
            if( ++global->ifptr < &global->ifstack[BLK_NEST] )
                {
                *global->ifptr = WAS_COMPILING;

                ret = doif( global, hash );

                if( ret )
                    return(ret);

                break;
                }

            cfatal( global, FATAL_TOO_MANY_NESTINGS, global->tokenbuf );

            return( FPP_TOO_MANY_NESTED_STATEMENTS );

        case L_endif:
            if( global->ifptr == &global->ifstack[0] )
                {
                cerror( global, ERROR_STRING_MUST_BE_IF, global->tokenbuf );

                dump_line( global, counter );

                return(FPP_OK);
                }

            if( !compiling && (*global->ifptr & WAS_COMPILING) != 0 )
                global->wrongline = TRUE;

            compiling = ((*global->ifptr & WAS_COMPILING) != 0);

            --global->ifptr;

            break;

        case L_assert:
            {
            int result;

            ret = eval( global, &result );

            if(ret)
                return(ret);

            if( result == 0 )
                cerror( global, ERROR_PREPROC_FAILURE );
            }
            break;

        case L_pragma:
            /*
             * #pragma is provided to pass "options" to later
             * passes of the compiler.  cpp doesn't have any yet.
             */
            Putstring( global, "#pragma " );

            while( (c = get( global ) ) != '\n' && c != EOF_CHAR )
                Putchar( global, c );

            unget( global );

            Putchar( global, '\n' );

            break;

        default:
            /*
             * Undefined #control keyword.
             * Note: the correct behavior may be to warn and
             * pass the line to a subsequent compiler pass.
             * This would allow #asm or similar extensions.
             */
            if( global->warnillegalcpp )
                cwarn( global, WARN_ILLEGAL_COMMAND, global->tokenbuf );

            Putchar( global, '#' );
            Putstring( global, global->tokenbuf );
            Putchar( global, ' ' );

            while( (c = get( global ) ) != '\n' && c != EOF_CHAR )
                Putchar( global, c );

            unget( global );

            Putchar( global, '\n' );

            break;
        }

    if( hash != L_include )
        {
        #if OLD_PREPROCESSOR
        /*
         * Ignore the rest of the #control line so you can write
         *      #if foo
         *      #endif  foo
         */
        dump_line( global, counter );         /* Take common exit */

        return( FPP_OK );
        #else
          if (skipws(global) != '\n')
            {
            cwarn( global, WARN_UNEXPECTED_TEXT_IGNORED );

            skipnl( global );
            }
        #endif
        }

    (*counter)++;

    return( FPP_OK );
}
Exemple #10
0
FILE_LOCAL
ReturnCode doif(struct Global *global, int hash)
{
    /*
     * Process an #if, #ifdef, or #ifndef. The latter two are straightforward,
     * while #if needs a subroutine of its own to evaluate the expression.
     *
     * doif() is called only if compiling is TRUE.  If false, compilation
     * is always supressed, so we don't need to evaluate anything.  This
     * supresses unnecessary warnings.
     */

    int c;
    int found;
    ReturnCode ret;

    if( (c = skipws( global ) ) == '\n' || c == EOF_CHAR )
        {
        unget( global );

        cerror( global, ERROR_MISSING_ARGUMENT );

        #if !OLD_PREPROCESSOR
        skipnl( global );               /* Prevent an extra     */

        unget( global );                /* Error message        */
        #endif

        return(FPP_OK);
        }

    if( hash == L_if )
        {
        unget( global );

        ret = eval( global, &found );

        if( ret )
            return( ret );

        found = (found != 0);     /* Evaluate expr, != 0 is  TRUE */

        hash = L_ifdef;       /* #if is now like #ifdef */
        }
    else
        {
        if( type[c] != LET )
            {         /* Next non-blank isn't letter  */
                          /* ... is an error          */
            cerror( global, ERROR_MISSING_ARGUMENT );

            #if !OLD_PREPROCESSOR
            skipnl( global );             /* Prevent an extra     */

            unget( global );              /* Error message        */
            #endif

            return(FPP_OK);
            }

        found = ( lookid( global, c ) != NULL ); /* Look for it in symbol table */
        }

    if( found == (hash == L_ifdef) )
        {
        compiling = TRUE;

        *global->ifptr |= TRUE_SEEN;
        }
    else
        compiling = FALSE;

    return(FPP_OK);
}
Exemple #11
0
/*
 * Main process for cpp -- copies tokens from the current input
 * stream (main file, include file, or a macro) to the output
 * file.
 */
void cppmain()
{
    int c;              /* Current character    */
    int counter;        /* newlines and spaces  */

    /*
     * Explicitly output a #line at the start of cpp output so
     * that lint (etc.) knows the name of the original source
     * file.  If we don't do this explicitly, we may get
     * the name of the first #include file instead.
     * We also seem to need a blank line following that first #line.
     */
#ifdef EVALDEFS
    if ( !bIsInEval )
#endif
    {
        sharp();
        PUTCHAR('\n');
    }
    /*
     * This loop is started "from the top" at the beginning of each line
     * wrongline is set TRUE in many places if it is necessary to write
     * a #line record.  (But we don't write them when expanding macros.)
     *
     * The counter variable has two different uses:  at
     * the start of a line, it counts the number of blank lines that
     * have been skipped over.  These are then either output via
     * #line records or by outputting explicit blank lines.
     * When expanding tokens within a line, the counter remembers
     * whether a blank/tab has been output.  These are dropped
     * at the end of the line, and replaced by a single blank
     * within lines.
     */
    for (;;)
    {
        counter = 0;                        /* Count empty lines    */
        for (;;)
        {                                   /* For each line, ...   */
            while (type[(c = get())] == SPA) /* Skip leading blanks */
                ;                           /* in this line.        */
            if (c == '\n')                  /* If line's all blank, */
                ++counter;                  /* Do nothing now       */
            else if (c == '#')
            {            /* Is 1st non-space '#' */
                keepcomments = FALSE;       /* Don't pass comments  */
                counter = control(counter); /* Yes, do a #command   */
                keepcomments = (cflag && compiling);
            }
            else if (c == EOF_CHAR)         /* At end of file?      */
            {
                break;
            }
            else if (!compiling)
            {                               /* #ifdef false?        */
                skipnl();                   /* Skip to newline      */
                counter++;                  /* Count it, too.       */
            }
            else
            {
                break;                      /* Actual token         */
            }
        }
        if (c == EOF_CHAR)                  /* Exit process at      */
            break;                          /* End of file          */
        /*
         * If the loop didn't terminate because of end of file, we
         * know there is a token to compile.  First, clean up after
         * absorbing newlines.  counter has the number we skipped.
         */
        if ((wrongline && infile->fp != NULL) || counter > 4)
            sharp();                        /* Output # line number */
        else
        {                                   /* If just a few, stuff */
            while (--counter >= 0)          /* them out ourselves   */
                PUTCHAR('\n');
        }
        /*
         * Process each token on this line.
         */
        unget();                            /* Reread the char.     */
        for (;;)
        {                                   /* For the whole line,  */
            do
            {                            /* Token concat. loop   */
                for (counter = 0; type[(c = get())] == SPA;)
                {
#if COMMENT_INVISIBLE
                    if (c != COM_SEP)
#endif
                    counter++;              /* Skip over blanks     */

                }
                if (c == EOF_CHAR || c == '\n')
                    goto end_line;          /* Exit line loop       */
                else if (counter > 0)       /* If we got any spaces */
                    PUTCHAR(' ');           /* Output one space     */
                c = macroid(c);             /* Grab the token       */
            }
            while (type[c] == LET && catenate());

            if (c == EOF_CHAR || c == '\n') /* From macro exp error */
                goto end_line;              /* Exit line loop       */

            switch (type[c])
            {
            case LET:
                fputs(token, pCppOut);       /* Quite ordinary token */
#ifdef EVALDEFS
                {
                    int len;
                    if ( bIsInEval
                         && nEvalOff + (len=strlen(token)) < NEVALBUF )
                    {
                        strcpy( &EvalBuf[nEvalOff], token );
                        nEvalOff += len;
                    }
                }
#endif
                break;


            case DIG:                       /* Output a number      */
            case DOT:                       /* Dot may begin floats */
#ifdef EVALDEFS
                if ( bIsInEval )
                    scannumber(c, outputEval);
                else
                    scannumber(c, output);
#else
                scannumber(c, output);
#endif
                break;

            case QUO:                       /* char or string const */
                scanstring(c, output);      /* Copy it to output    */
                break;

            default:                        /* Some other character */
                cput(c);                    /* Just output it       */
#ifdef EVALDEFS
                if ( bIsInEval && nEvalOff < NEVALBUF )
                    EvalBuf[nEvalOff++] = c;
#endif
                break;
            }                               /* Switch ends          */
        }                                   /* Line for loop        */
      end_line:
        if (c == '\n')
        {                                   /* Compiling at EOL?    */
            PUTCHAR('\n');                  /* Output newline, if   */
            if (infile->fp == NULL)         /* Expanding a macro,   */
                wrongline = TRUE;           /* Output # line later  */
        }
    }                                       /* Continue until EOF   */
#ifdef EVALDEFS
    if ( bIsInEval )
        EvalBuf[nEvalOff++] = '\0';
#endif
}
Exemple #12
0
INLINE FILE_LOCAL
ReturnCode cppmain(struct Global *global)
{
  /*
   * Main process for cpp -- copies tokens from the current input
   * stream (main file, include file, or a macro) to the output
   * file.
   */

  int c;        /* Current character    */
  int counter;  /* newlines and spaces  */
  ReturnCode ret; /* return code variable type */

  long bracelevel = 0;
  long parenlevel = 0;
  long bracketlevel = 0;
  int fake = 0;

#define MAX_FUNC_LENGTH 50

  char tempfunc[MAX_FUNC_LENGTH + 1];
  char tempfunc2[MAX_FUNC_LENGTH + 1];
  char define = 0; /* probability of a function define phase in the program */
  char prev = 0; /* previous type */
  char go = 0;
  char include = 0;
  char initfunc = 0;

  /* Initialize for reading tokens */
  global->tokenbsize = 50;
  global->tokenbuf = malloc(global->tokenbsize + 1);
  if(!global->tokenbuf)
    return(FPP_OUT_OF_MEMORY);

  global->functionname = malloc(global->tokenbsize + 1);
  if(!global->functionname)
    return(FPP_OUT_OF_MEMORY);
  global->functionname[0] = '\0';

  if(global->showspace) {
    global->spacebuf = (char *)malloc(MAX_SPACE_SIZE);
    if(!global->spacebuf)
      return(FPP_OUT_OF_MEMORY);
  }

  if(global->showversion)
      Error(global, VERSION_TEXT);

  /*
   * Explicitly output a #line at the start of cpp output so
   * that lint (etc.) knows the name of the original source
   * file.  If we don't do this explicitly, we may get
   * the name of the first #include file instead.
   */
  if(global->linelines) /* if #line lines are wanted! */
    sharp(global);
  /*
   * This loop is started "from the top" at the beginning of each line
   * wrongline is set TRUE in many places if it is necessary to write
   * a #line record.  (But we don't write them when expanding macros.)
   *
   * The counter variable has two different uses:  at
   * the start of a line, it counts the number of blank lines that
   * have been skipped over. These are then either output via
   * #line records or by outputting explicit blank lines.
   * When expanding tokens within a line, the counter remembers
   * whether a blank/tab has been output.  These are dropped
   * at the end of the line, and replaced by a single blank
   * within lines.
   */

  include = global->included;

  while(include--) {
    openinclude(global, global->include[include], TRUE);
  }
  
  for (;;) {
    counter = 0;                        /* Count empty lines    */
    for (;;) {                          /* For each line, ...   */
      global->comment = FALSE;          /* No comment yet!      */
      global->chpos = 0;                /* Count whitespaces    */
      while (type[(c = get(global))] == SPA)  /* Skip leading blanks */
	if(global->showspace) {
	  if(global->chpos<MAX_SPACE_SIZE-1)
	    /* we still have buffer to store this! */
	    global->spacebuf[global->chpos++]=(char)c;
	}
      if (c == '\n') {                  /* If line's all blank, */
	if(global->comment) {
	  /* A comment was output! */
	  Putchar(global, '\n');
	}
	else
	  ++counter;                    /* Do nothing now       */
      }
      else if (c == '#') {              /* Is 1st non-space '#' */
	global->keepcomments = FALSE;   /* Don't pass comments  */
	ret = control(global, &counter); /* Yes, do a #command   */
	if(ret)
	  return(ret);
	global->keepcomments = (global->cflag && compiling);
      }
      else if (c == EOF_CHAR)           /* At end of file?      */
	break;
      else if (!compiling) {            /* #ifdef false?        */
	skipnl(global);                 /* Skip to newline      */
	counter++;                      /* Count it, too.       */
      } else {
	break;                          /* Actual token         */
      }
    }
    if (c == EOF_CHAR)                  /* Exit process at      */
      break;                            /* End of file          */
    /*
     * If the loop didn't terminate because of end of file, we
     * know there is a token to compile.  First, clean up after
     * absorbing newlines.  counter has the number we skipped.
     */
    if(global->linelines) { /* if #line lines are wanted! */
      if ((global->wrongline && global->infile->fp != NULL) || counter > 4)
        sharp(global);                    /* Output # line number */
      else {                              /* If just a few, stuff */
        while (--counter >= 0)            /* them out ourselves   */
	  Putchar(global, (int)'\n');
      }
    }
    if(global->showspace) {
      /* Show all whitespaces! */
      global->spacebuf[global->chpos] = '\0';
      Putstring(global, global->spacebuf);
    }
    
    /*
     * Process each token on this line.
     */
    unget(global);                      /* Reread the char.     */
    for (;;) {                          /* For the whole line,  */
      do {                              /* Token concat. loop   */
	for (global->chpos = counter = 0; (type[(c = get(global))] == SPA);) {
#if COMMENT_INVISIBLE
	  if (c != COM_SEP)
	    counter++;
#else
	  if(global->showspace && global->chpos < MAX_SPACE_SIZE-1) {
	    global->spacebuf[global->chpos++]=(char)c;
	  }
	  counter++;            /* Skip over blanks     */
#endif
	}
	if (c == EOF_CHAR || c == '\n')
	  break;                      /* Exit line loop       */
	else if (counter > 0) {       /* If we got any spaces */
	  if(!global->showspace)      /* We don't output all spaces */
	    Putchar(global, (int)' ');/* Output one space     */
	  else {
	    global->spacebuf[global->chpos] = '\0';
	    Putstring(global, global->spacebuf); /* Output all whitespaces */
	  }
	}
	if(ret=macroid(global, &c))   /* Grab the token       */
	  return(ret);
      } while (type[c] == LET && catenate(global, &ret) && !ret);
      if(ret)
	/* If the loop was broken because of a fatal error! */
	return(ret);
      if (c == EOF_CHAR || c == '\n') /* From macro exp error */
	break;                        /* Exit line loop       */
      go++;
      switch (type[c]) {
      case LET:
	go =0;
	/* Quite ordinary token */
	Putstring(global, global->tokenbuf);
	
	if(!define) {
	  /* Copy the name */
	  strncpy(tempfunc, global->tokenbuf, MAX_FUNC_LENGTH);
          tempfunc[MAX_FUNC_LENGTH]=0;
	}
	/* fputs(global->tokenbuf, stdout); */
	break;
      case DIG:                 /* Output a number      */
      case DOT:                 /* Dot may begin floats */
	go = 0;
	ret=scannumber(global, c, (ReturnCode(*)(struct Global *, int))output);
	if(ret)
	  return(ret);
	break;
      case QUO:                 /* char or string const */
	go = 0;
	/* Copy it to output */
        if(!global->webmode) {
          ret=scanstring(global, c,
                         (ReturnCode(*)(struct Global *, int))output);
          if(ret)
            return(ret);
          break;
        }
        /* FALLTHROUGH */
      default:                  /* Some other character */
	
	define++;
	switch(c) {
	case '{':
	  if(! bracelevel++ && define > 2) {
	    /*
	     * This is a starting brace. If there is a probability of a
	     * function defining, we copy the `tempfunc' function name to
	     * `global->functionname'.
	     */
	    strcpy(global->functionname, tempfunc2);
	    global->funcline = global->line;

		if(global->outputfunctions) {
			/*
			 * Output the discovered function name to stderr!
			 */
			Error(global, "#> Function defined at line %d: %s <#\n",
				  global->line,
				  global->functionname);
		}

	    if(global->initialfunc) {
		int a;
		for(a=0; a<global->excluded; a++) {
		    /* check for excluded functions */
		    if(!strcmp(global->functionname,
			       global->excludedinit[a]))
			break;
		}
		if(a==global->excluded) {
		    expstuff(global, "__brace__", "{");
		    expstuff(global, "__init_func__", global->initialfunc);
		    initfunc = TRUE;
		}
	    }

	  }
	  break;
	case '}':
	  go = 0;
	  if( (--bracelevel == initfunc) &&
	     strcmp(global->infile->filename, "__init_func__") ) {
	    /* we just stepped out of the function! */
	    global->functionname[0] = '\0';
	    global->funcline = 0;
	    define = 1;

	    if(initfunc) {
	      Putchar(global, '}');
	      bracelevel--;
	      initfunc=0;
	    }
	  }
	  fake = 0;
	  break;
	  
	case ';':
	case ',':
	  if(go == 2) {
	    define = 1;
	    fake = 0;
	    go--;
	    break;
	  }
	  break;
	case '(':
	  if(! parenlevel++ && !bracelevel) {
	    if(go == 2) {
	      /* foobar(text) -> "(" is found. This can't be a
		 function */
	      go--;
	      define = 1;
	      break;
	    }
	    if( define < 2 && prev == LET) {
	      /* This is the first parenthesis on the ground brace
		 level, and we did previously not have a probable
		 function name */
	      strncpy(tempfunc2, global->tokenbuf, MAX_FUNC_LENGTH);
              tempfunc2[MAX_FUNC_LENGTH]=0;
	      define++;
	    }
	    else {
	      /* we have a fake start */
	      fake++;
	    }
	  }
	  break;
	case ')':
	  if(! --parenlevel && !bracelevel && define>1 && !fake) {
	    /*
	     * The starting parentheses level and
	     * the starting brace level.
	     * This might be the start of a function defining coming
	     * up!
	     */
	    define++; /* increase probability */
	    fake = 0;
	    go = 1;
	  }
	  break;
	case '[':
	  bracketlevel++;
	  break;
	case ']':
	  bracketlevel--;
	  break;
	}
	define--; /* decrease function probability */
	
	Putchar(global, c);     /* Just output it       */
	break;
      }                         /* Switch ends          */
      prev = type[c];
    }                           /* Line for loop        */
    
    if (c == '\n') {  /* Compiling at EOL?    */
      Putchar(global, '\n');              /* Output newline, if   */
      if (global->infile->fp == NULL)     /* Expanding a macro,   */
	global->wrongline = TRUE; /* Output # line later        */
    }
  }                             /* Continue until EOF   */

  if(global->showbalance) {
    if(bracketlevel) {
      cwarn(global, WARN_BRACKET_DEPTH, bracketlevel);
    }
    if(parenlevel) {
      cwarn(global, WARN_PAREN_DEPTH, parenlevel);
    }
    if(bracelevel) {
      cwarn(global, WARN_BRACE_DEPTH, bracelevel);
    }
  }
  if (global->wflag) {
    global->out = TRUE;         /* enable output */
    outdefines(global);         /* Write out #defines   */
  }
  return(FPP_OK);
}
Exemple #13
0
Fichier : cmd.c Projet : 8l/FUZIX
static TREPTR item(BOOL flag)
{
	register TREPTR t;
	register IOPTR io;

	if (flag)
		io = inout((IOPTR) 0);
	else
		io = 0;

	switch (wdval) {
	case CASYM:
	{
		t = (TREPTR) getstak(SWTYPE);
		chkword();
		((SWPTR) t)->swarg = wdarg->argval;
		skipnl();
		chksym(INSYM | BRSYM);
		((SWPTR) t)->swlst = syncase(wdval == INSYM ? ESSYM : KTSYM);
		((SWPTR) t)->swtyp = TSW;
		break;
	}
	case IFSYM:
	{
		register int w;
		t = (TREPTR) getstak(IFTYPE);
		((IFPTR) t)->iftyp = TIF;
		((IFPTR) t)->iftre = cmd(THSYM, NLFLG);
		((IFPTR) t)->thtre = cmd(ELSYM | FISYM | EFSYM, NLFLG);
		((IFPTR) t)->eltre = ((w = wdval) == ELSYM ?
				cmd(FISYM, NLFLG) :
				(w == EFSYM ? (wdval = IFSYM, item(0)) : 0));
		if (w == EFSYM)
			return (t);
		break;
	}

	case FORSYM:
	{
		t = (TREPTR) getstak(FORTYPE);
		((FORPTR) t)->fortyp = TFOR;
		((FORPTR) t)->forlst = 0;
		chkword();
		((FORPTR) t)->fornam = wdarg->argval;
		if (skipnl() == INSYM) {
			chkword();
			((FORPTR) t)->forlst = (COMPTR) item(0);
			if (wdval != NL && wdval != ';')
				synbad();
			chkpr(wdval);
			skipnl();
		}
		chksym(DOSYM | BRSYM);
		((FORPTR) t)->fortre =
			    cmd(wdval == DOSYM ? ODSYM : KTSYM, NLFLG);
		break;
	}

	case WHSYM:
	case UNSYM:
	{
		t = (TREPTR) getstak(WHTYPE);
		((WHPTR) t)->whtyp = (wdval == WHSYM ? TWH : TUN);
		((WHPTR) t)->whtre = cmd(DOSYM, NLFLG);
		((WHPTR) t)->dotre = cmd(ODSYM, NLFLG);
		break;
	}

	case BRSYM:
		t = cmd(KTSYM, NLFLG);
		break;

	case '(':
	{
		register PARPTR p;
		p = (PARPTR) getstak(PARTYPE);
		p->partre = cmd(')', NLFLG);
		p->partyp = TPAR;
		t = makefork(0, /*FIXME*/(void *)p);
		break;
	}

	default:
		if (io == 0)
			return (0);

	case 0:
	{
		register ARGPTR argp;
		register ARGPTR *argtail;
		register ARGPTR *argset = 0;
		int keywd = 1;
		t = (TREPTR) getstak(COMTYPE);
		((COMPTR) t)->comio = io;	/*initial io chain */
		argtail = &(((COMPTR) t)->comarg);
		while (wdval == 0) {
			argp = wdarg;
			if (wdset && keywd) {
				argp->argnxt = (ARGPTR) argset;
				argset = (ARGPTR *) argp;
			} else {
				*argtail = argp;
				argtail = &(argp->argnxt);
				keywd = flags & keyflg;
			}
			word();
			if (flag)
				((COMPTR) t)->comio = inout(((COMPTR) t)->comio);
		}

		((COMPTR) t)->comtyp = TCOM;
		((COMPTR) t)->comset = (ARGPTR) argset;
		*argtail = 0;
		return (t);
	}

	}
	reserv++;
	word();
	if (io = inout(io)) {
		t = makefork(0, t);
		t->treio = io;
	}
	return t;
}