Exemplo n.º 1
0
static void enum_item(const char *s)
{
  newline();
  directive("@item ");
  literal(s);
  newline();
}
Exemplo n.º 2
0
static void table_item(const char *s)
{
  directive("@item");
  newline();
  content(s);
  newline();
}
Exemplo n.º 3
0
static void begintable_markup(char const *markup)
{
  newline();
  directive("@table ");
  literal(markup);
  newline();
}
Exemplo n.º 4
0
// ParsePreprocessorDirective
//------------------------------------------------------------------------------
bool BFFParser::ParsePreprocessorDirective( BFFIterator & iter )
{
	const BFFIterator directiveStart( iter );

	// skip directive start token
	ASSERT( *iter == BFF_PREPROCESSOR_START );
	iter++;

	// allow whitepace before directive name
	iter.SkipWhiteSpace();

	// start of directive name
	BFFIterator directiveStartIter( iter );

	// find end of directive
	while ( iter.IsAtValidDirectiveNameCharacter() )
	{
		iter++;
	}
	BFFIterator directiveEndIter( iter );

	iter.SkipWhiteSpace();

	// determine directive
	AStackString< MAX_DIRECTIVE_NAME_LENGTH > directive( directiveStartIter.GetCurrent(), directiveEndIter.GetCurrent() );
	if ( directive == "include" )
	{
		return ParseIncludeDirective( iter );
	}
	else if ( directive == "once" )
	{
		FBuild::Get().GetDependencyGraph().SetCurrentFileAsOneUse();
		return true;
	}
	else if ( directive == "define" )
	{
		return ParseDefineDirective( iter );
	}
	else if ( directive == "undef" )
	{
		return ParseUndefDirective( iter );
	}
	else if ( directive == "if" )
	{
		return ParseIfDirective( directiveStart, iter );
	}
	else if ( directive == "endif" )
	{
		return ParseEndIfDirective( directiveStartIter );
	}
	else if ( directive == "import" )
	{
		return ParseImportDirective( directiveStart, iter );
	}

	// unknown
	Error::Error_1030_UnknownDirective( directiveStartIter, directive );
	return false;
}
Exemplo n.º 5
0
response & operator<<(
    response & message,
    Directive const & directive
    )
{
    directive(message);
    return message;
}
Exemplo n.º 6
0
 basic_request<Tag> & operator<<(
     basic_request<Tag> & message,
     Directive const & directive
     )
 {
     directive(message);
     return message;
 }
Exemplo n.º 7
0
static void begin_subsection(const char *name,
			  const char *next,
			  const char *prev,
			  const char *up)
{
  newline();
  
  directive("@node ");
  content(name);
  content(" regular expression syntax");
  newline();
  
  directive("@subsection ");
  output("@samp{", 0);
  content(name);
  output("}", 0);
  content(" regular expression syntax");
  newline();
}
Exemplo n.º 8
0
Tok *
pp()
{
	Tok *t;

	t = ppnoexpand();
	if(t->k == '#' && t->nl) {
		directive();
		return pp();
	}
	return t;
}
void NETLIST_EXPORTER_PSPICE::UpdateDirectives( unsigned aCtl )
{
    const SCH_SHEET_LIST& sheetList = g_RootSheet;

    m_directives.clear();

    for( unsigned i = 0; i < sheetList.size(); i++ )
    {
        for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
        {
            if( item->Type() != SCH_TEXT_T )
                continue;

            wxString text = static_cast<SCH_TEXT*>( item )->GetText();

            if( text.IsEmpty() )
                continue;

            if( text.GetChar( 0 ) == '.' )
            {
                wxStringTokenizer tokenizer( text, "\r\n" );

                while( tokenizer.HasMoreTokens() )
                {
                    wxString directive( tokenizer.GetNextToken() );

                    if( directive.StartsWith( ".inc" ) )
                    {
                        wxString lib = directive.AfterFirst( ' ' );

                        if( !lib.IsEmpty() )
                            m_libraries.insert( lib );
                    }
                    else
                    {
                        m_directives.push_back( directive );
                    }
                }
            }
        }
    }
}
Exemplo n.º 10
0
void Parameters::parseLine(string line)
{ line = cleanLine(line);

  // check for include directive
  string directive("include ");
  if (line.substr(0,directive.size())==directive)
  {
    parseSettingsFile(line.substr(directive.size(),string::npos));
    return;
  }

  // what's left has to have a space as separator
  string::size_type space = line.find(' ');
  if (space == string::npos)
    return;
  string key(line,0,space);
  string val(line,space+1);
  cout << key << "=" << val << endl;
  set(key,val);
}
Exemplo n.º 11
0
/*
 * Get the next token, printing out any directive that are encountered.
 */
void
get_token(token *tokp)
{
	int commenting;
	int stat = 0;
	
	
	if (pushed) {
		pushed = 0;
		*tokp = lasttok;
		return;
	}
	commenting = 0;
	for (;;) {
		if (*where == 0) {
			for (;;) {
				if (!fgets(curline, MAXLINESIZE, fin)) {
					tokp->kind = TOK_EOF;
					/* now check if cpp returned non NULL value */
					waitpid(childpid, &stat, WUNTRACED);
					if (stat > 0) {
					/* Set return value from rpcgen */
						nonfatalerrors = stat >> 8;
					}
					*where = 0;
					return;
				}
				linenum++;
				if (commenting) {
					break;
				} else if (cppline(curline)) {
					docppline(curline, &linenum,
						  &infilename);
				} else if (directive(curline)) {
					printdirective(curline);
				} else {
					break;
				}
			}
			where = curline;
		} else if (isspace(*where)) {
Exemplo n.º 12
0
static void endenum()
{
  newline();
  directive("@end enumerate");
  newline();
}
Exemplo n.º 13
0
/*
 *  preprocesses input tokens to form the output list
 */
void (proc_prep)(void)
{
    lex_t *t = lst_nexti();

    while (1) {
        switch(state) {
            case SINIT:
            case SAFTRNL:
                while (1) {
                    SKIPSP(t);
                    switch(t->id) {
                        case LEX_NEWLINE:
                            lst_flush(1);
                            t = lst_nexti();
                            continue;
                        case LEX_SHARP:
                            state++;
                            assert(state == SIDIREC || state == SDIREC);
                            lex_direc = 1;
                            goto loop;
                        default:
                            state = SNORM;
                            goto loop;
                        case LEX_EOI:
                            if (mg_state == MG_SENDIF && state == SINIT)
                                mg_once();
                            cond_finalize();
                            if (inc_isffile()) {
                                lst_flush(1);
                                return;
                            }
                            if (main_opt()->pponly) {
                                lex_t *u = lst_copy(t, 0, strg_line);
                                u->id = LEX_NEWLINE;
                                u->f.sync = 2;
                                u = lst_append(u, lex_make(0, NULL, 0));
                                lst_output(u);
                                lst_discard(1);    /* discards EOI */
                                in_switch(NULL, 0);    /* pop */
                                t = lst_nexti();
                                u->pos = t->pos;
                            } else {
                                lst_discard(1);    /* discards EOI */
                                in_switch(NULL, 0);    /* pop */
                                t = lst_nexti();
                            }
                            setdirecst(t);
                            assert(state == SAFTRNL || state == SINIT);
                            goto loop;
                    }
                }
                /* assert(!"impossible control flow - should never reach here");
                   break; */
            case SIDIREC:
            case SDIREC:
                directive(t);
                t = lst_nexti();    /* token after newline */
                setdirecst(t);
                break;
            case SNORM:
                while (t->id != LEX_NEWLINE) {
                    assert(t->id != LEX_EOI);
                    if (t->id == LEX_ID && !t->f.blue)
                        mcr_expand(t);
                    t = lst_nexti();
                }
                lst_flush(1);
                state = SAFTRNL;
                return;    /* at least newline flushed */
            case SIGN:
                do {
                    SKIPSP(t);
                    if (t->id == LEX_SHARP) {
                        state = SDIREC;
                        lex_direc = 1;
                        goto loop;
                    }
                    SKIPNL(t);
                    t = lst_nexti();
                } while(t->id != LEX_EOI);
                state = SAFTRNL;
                break;
            default:
                assert(!"invalid state -- should never reach here");
                break;
        }
        loop:
            ;
    }
}
Exemplo n.º 14
0
int eel_call(int handle, int pos)
{
	int res = 1;
	int depth = 0;
	eel_push_context();
	eel_current.script = handle;
	eel_current.bio = bio_open(eel_scripttab[handle].data,
			eel_scripttab[handle].len);
	if(!eel_current.bio)
	{
		eel_error("INTERNAL ERROR: Couldn't read script!");
		eel_pop_context();
		return -1;
	}
	bio_seek(eel_current.bio, pos, SEEK_SET);
	
	eel_current.lval = NULL;
	while(res > 0)
	{
		/* Start of statement */
		eel_clear_args(0);
		eel_current.arg = 0;
		switch(eel_lex(0))
		{
		  case 0:
			/* End of script */
			res = 0;
			break;
		  case ';':
			/* Empty statement */
			res = 1;
			break;
		  case '{':
			/* Begin scope */
			eel_push_scope();
			++depth;
			res = 1;
			break;
		  case '}':
			/* End scope */
			if(depth)
			{
				eel_pop_scope();
				--depth;
			}
			else
				res = 0;
			break;
		  case TK_NEWSYM:
			res = assignment(TK_NEWSYM);
			break;
		  case TK_SYMREF:
			switch(eel_current.lval->value.sym->type)
			{
			  case EST_CONSTANT:	/* Just to get a more
			  			 * sensible error message...
						 */
			  case EST_UNDEFINED:
			  case EST_VARIABLE:
				res = assignment(TK_SYMREF);
				break;
/*			  case EST_COMMAND:
				res = command();
				break;*/
			  case EST_FUNCTION:
				res = function();
				break;
			  case EST_DIRECTIVE:
			  case EST_SPECIAL:
				res = directive();
				break;
			  case EST_ENUM:
			  case EST_LABEL:
				eel_error("Syntax error!");
				res = -1;
				break;
			  case EST_OPERATOR:
				res = command();
				break;
			  default:
				eel_error("INTERNAL ERROR: Lexer returned"
						" symbol of illegal type!");
				res = -1;
				break;
			}
			break;
		  default:
			eel_error("Unexpected character!");
			res = -1;
			break;
		}
	}
	eel_current.arg = 0;
	bio_close(eel_current.bio);
	eel_pop_context();
	return res;
}
Exemplo n.º 15
0
message_base& operator<<(message_base& msg, Directive directive) {
  directive(msg);
  return msg;
}
Exemplo n.º 16
0
/*
 * Get the next token, printing out any directive that are encountered.
 */
void
get_token (token *tokp)
{
  int commenting;

  if (pushed)
    {
      pushed = 0;
      *tokp = lasttok;
      return;
    }
  commenting = 0;
  for (;;)
    {
      if (*where == 0)
	{
	  for (;;)
	    {
	      if (!fgets (curline, MAXLINESIZE, fin))
		{
		  tokp->kind = TOK_EOF;
		  *curline = 0;
		  where = curline;
		  return;
		}
	      linenum++;
	      if (commenting)
		{
		  break;
		}
	      else if (cppline (curline))
		{
		  docppline (curline, &linenum,
			     &infilename);
		}
	      else if (directive (curline))
		{
		  printdirective (curline);
		}
	      else
		{
		  break;
		}
	    }
	  where = curline;
	}
      else if (isspace (*where))
	{
	  while (isspace (*where))
	    {
	      where++;		/* eat */
	    }
	}
      else if (commenting)
	{
	  for (where++; *where; where++)
	    {
	      if (endcomment (where))
		{
		  where++;
		  commenting--;
		  break;
		}
	    }
	}
      else if (startcomment (where))
	{
	  where += 2;
	  commenting++;
	}
      else
	{
	  break;
	}
    }

  /*
   * 'where' is not whitespace, comment or directive Must be a token!
   */
  switch (*where)
    {
    case ':':
      tokp->kind = TOK_COLON;
      where++;
      break;
    case ';':
      tokp->kind = TOK_SEMICOLON;
      where++;
      break;
    case ',':
      tokp->kind = TOK_COMMA;
      where++;
      break;
    case '=':
      tokp->kind = TOK_EQUAL;
      where++;
      break;
    case '*':
      tokp->kind = TOK_STAR;
      where++;
      break;
    case '[':
      tokp->kind = TOK_LBRACKET;
      where++;
      break;
    case ']':
      tokp->kind = TOK_RBRACKET;
      where++;
      break;
    case '{':
      tokp->kind = TOK_LBRACE;
      where++;
      break;
    case '}':
      tokp->kind = TOK_RBRACE;
      where++;
      break;
    case '(':
      tokp->kind = TOK_LPAREN;
      where++;
      break;
    case ')':
      tokp->kind = TOK_RPAREN;
      where++;
      break;
    case '<':
      tokp->kind = TOK_LANGLE;
      where++;
      break;
    case '>':
      tokp->kind = TOK_RANGLE;
      where++;
      break;

    case '"':
      tokp->kind = TOK_STRCONST;
      findstrconst (&where, &tokp->str);
      break;
    case '\'':
      tokp->kind = TOK_CHARCONST;
      findchrconst (&where, &tokp->str);
      break;

    case '-':
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      tokp->kind = TOK_IDENT;
      findconst (&where, &tokp->str);
      break;

    default:
      if (!(isalpha (*where) || *where == '_'))
	{
	  char buf[100];
	  char *p;

	  s_print (buf, ("illegal character in file: "));
	  p = buf + strlen (buf);
	  if (isprint (*where))
	    {
	      s_print (p, "%c", *where);
	    }
	  else
	    {
	      s_print (p, "%d", *where);
	    }
	  error (buf);
	}
      findkind (&where, tokp);
      break;
    }
}
Exemplo n.º 17
0
Arquivo: pmcpp.c Projeto: Aconex/pcp
int
main(int argc, char **argv)
{
    int		c;
    int		skip_if_false = 0;
    int		incomment = 0;
    char	*ip;

    currfile = &file_ctl[0];

    while ((c = pmgetopt_r(argc, argv, &opts)) != EOF) {
	switch (c) {

	case 'D':	/* define */
	    for (ip = opts.optarg; *ip; ip++) {
		if (*ip == '=')
		    *ip = ' ';
	    }
	    snprintf(ibuf, sizeof(ibuf), "#define %s\n", opts.optarg);
	    currfile->fname = "<arg>";
	    currfile->lineno = opts.optind;
	    directive();
	    break;

	case '?':
	default:
	    opts.errors++;
	    break;
	}
    }

    if (opts.errors || opts.optind < argc - 1) {
	pmUsageMessage(&opts);
	exit(1);
    }

    currfile->lineno = 0;
    if (opts.optind == argc) {
	currfile->fname = "<stdin>";
	currfile->fin = stdin;
    }
    else {
	currfile->fname = argv[opts.optind];
	currfile->fin = openfile(currfile->fname);
	if (currfile->fin == NULL) {
	    err((char *)pmErrStr(-oserror()));
	    /*NOTREACHED*/
	}
    }
    printf("# %d \"%s\"\n", currfile->lineno+1, currfile->fname);

    for ( ; ; ) {
	if (fgets(ibuf, sizeof(ibuf), currfile->fin) == NULL) {
	    fclose(currfile->fin);
	    if (currfile == &file_ctl[0])
		break;
	    free(currfile->fname);
	    currfile--;
	    printf("# %d \"%s\"\n", currfile->lineno+1, currfile->fname);
	    continue;
	}
	currfile->lineno++;
 
	/* strip comments ... */
	for (ip = ibuf; *ip ; ip++) {
	    if (incomment) {
		if (*ip == '*' && ip[1] == '/') {
		    /* end of comment */
		    incomment = 0;
		    *ip++ = ' ';
		    *ip = ' ';
		}
		else
		    *ip = ' ';
	    }
	    else {
		if (*ip == '/' && ip[1] == '*') {
		    /* start of comment */
		    incomment = currfile->lineno;
		    *ip++ = ' ';
		    *ip = ' ';
		}
	    }
	}
	ip--;
	while (ip >= ibuf && isspace((int)*ip)) ip--;
	*++ip = '\n';
	*++ip = '\0';
	if (incomment && ibuf[0] == '\n') {
	    printf("\n");
	    continue;
	}

	if (ibuf[0] == '#') {
	    /* cpp control line */
	    if (strncmp(ibuf, "#include", strlen("#include")) == 0) {
		char		*p;
		char		*pend;
		char		c;
		FILE		*f;
		static char	tmpbuf[MAXPATHLEN];

		if (skip_if_false) {
		    printf("\n");
		    continue;
		}
		p = &ibuf[strlen("#include")];
		while (*p && isblank((int)*p)) p++;
		if (*p != '"' && *p != '<') {
		    err("Expected \" or < after #include");
		    /*NOTREACHED*/
		}
		pend = ++p;
		while (*pend && *pend != '\n' &&
		       ((p[-1] != '"' || *pend != '"') &&
		        (p[-1] != '<' || *pend != '>'))) pend++;
		if (p[-1] == '"' && *pend != '"') {
		    err("Expected \" after file name");
		    /*NOTREACHED*/
		}
		if (p[-1] == '<' && *pend != '>') {
		    err("Expected > after file name");
		    /*NOTREACHED*/
		}
		if (currfile == &file_ctl[MAXLEVEL-1]) {
		    err("#include nesting too deep");
		    /*NOTREACHED*/
		}
		if (pend[1] != '\n' && pend[1] != '\0') {
		    err("Unexpected extra text in #include line");
		    /*NOTREACHED*/
		}
		c = *pend;
		*pend = '\0';
		f = openfile(p);
		if (f == NULL && file_ctl[0].fin != stdin) {
		    /* check in directory of file from command line */
		    static int	sep;
		    static char	*dir = NULL;
		    if (dir == NULL) {
			/*
			 * some versions of dirname() clobber the input
			 * argument, some do not ... hence the obscurity
			 * here
			 */
			static char	*dirbuf;
			dirbuf = strdup(file_ctl[0].fname);
			if (dirbuf == NULL) {
			    __pmNoMem("pmcpp: dir name alloc", strlen(file_ctl[0].fname)+1, PM_FATAL_ERR);
			    /*NOTREACHED*/
			}
			dir = dirname(dirbuf);
			sep = __pmPathSeparator();
		    }
		    snprintf(tmpbuf, sizeof(tmpbuf), "%s%c%s", dir, sep, p);
		    f = openfile(tmpbuf);
		    if (f != NULL)
			p = tmpbuf;
		}
		if (f == NULL) {
		    /* check in $PCP_VAR_DIR/pmns */
		    static int	sep;
		    static char	*var_dir = NULL;
		    if (var_dir == NULL) {
			var_dir = pmGetConfig("PCP_VAR_DIR");
			sep = __pmPathSeparator();
		    }
		    snprintf(tmpbuf, sizeof(tmpbuf), "%s%cpmns%c%s", var_dir, sep, sep, p);
		    f = openfile(tmpbuf);
		    if (f != NULL)
			p = tmpbuf;
		}
		if (f == NULL) {
		    *pend = c;
		    err("Cannot open file for #include");
		    /*NOTREACHED*/
		}
		currfile++;
		currfile->lineno = 0;
		currfile->fin = f;
		currfile->fname = strdup(p);
		*pend = c;
		if (currfile->fname == NULL) {
		    __pmNoMem("pmcpp: file name alloc", strlen(p)+1, PM_FATAL_ERR);
		    /*NOTREACHED*/
		}
		printf("# %d \"%s\"\n", currfile->lineno+1, currfile->fname);
	    }
	    else {
		/* expect other cpp control ... */
		skip_if_false = directive();
		printf("\n");
	    }
	    continue;
	}
	if (skip_if_false)
	    printf("\n");
	else {
	    if (nmacro > 0)
		do_macro();
	    printf("%s", ibuf);
	}
    }

    /* EOF for the top level file */
    if (incomment) {
	char	msgbuf[80];
	snprintf(msgbuf, sizeof(msgbuf), "Comment at line %d not terminated before end of file", incomment);
	currfile->lineno = 0;
	err(msgbuf);
	exit(1);
    }

    exit(0);
}
Exemplo n.º 18
0
static void code(const char *s)
{
  directive("@code{");
  content(s);
  directive("}");
}
Exemplo n.º 19
0
request_base & operator<< (request_base & request,
                           Directive const & directive) {
    directive(request);
    return request;
}
Exemplo n.º 20
0
static void mcpp_main( void)
/*
 * Main process for mcpp -- copies tokens from the current input stream
 * (main file or included file) to the output file.
 */
{
    int     c;                      /* Current character            */
    char *  wp;                     /* Temporary pointer            */
    DEFBUF *    defp;               /* Macro definition             */
    int     line_top;       /* Is in the line top, possibly spaces  */
    LINE_COL    line_col;   /* Location of macro call in source     */

    keep_comments = option_flags.c && !no_output;
    keep_spaces = option_flags.k;       /* Will be turned off if !compiling */
    line_col.col = line_col.line = 0L;

    /*
     * This loop is started "from the top" at the beginning of each line.
     * 'wrong_line' is set TRUE in many places if it is necessary to write
     * a #line record.  (But we don't write them when expanding macros.)
     *
     * 'newlines' variable 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.
     * 'newlines' will be cleared on end of an included file by get_ch().
     */
    while (1) {                             /* For the whole input  */
        newlines = 0;                       /* Count empty lines    */

        while (1) {                         /* For each line, ...   */
            out_ptr = output;               /* Top of the line buf  */
            c = get_ch();
            if (src_col)
                break;  /* There is a residual tokens on the line   */
            while (char_type[ c] & HSP) {   /* ' ' or '\t'          */
                if (c != COM_SEP)
                    *out_ptr++ = c; /* Retain line top white spaces */
                                    /* Else skip 0-length comment   */
                c = get_ch();
            }
            if (c == '#') {                 /* Is 1st non-space '#' */
                directive();                /* Do a #directive      */
            } else if (mcpp_mode == STD && option_flags.dig && c == '%') {
                    /* In POST_STD digraphs are already converted   */
                if (get_ch() == ':') {      /* '%:' i.e. '#'        */
                    directive();            /* Do a #directive      */
                } else {
                    unget_ch();
                    if (! compiling) {
                        skip_nl();
                        newlines++;
                    } else {
                        break;
                    }
                }
            } else if (c == CHAR_EOF) {     /* End of input         */
                break;
            } else if (! compiling) {       /* #ifdef false?        */
                skip_nl();                  /* Skip to newline      */
                newlines++;                 /* Count it, too.       */
            } else if (in_asm && ! no_output) { /* In #asm block    */
                put_asm();                  /* Put out as it is     */
            } else if (c == '\n') {         /* Blank line           */
                if (keep_comments)
                    mcpp_fputc( '\n', OUT); /* May flush comments   */
                else
                    newlines++;             /* Wait for a token     */
            } else {
                break;                      /* Actual token         */
            }
        }

        if (c == CHAR_EOF)                  /* Exit process at      */
            break;                          /*   end of input       */

        /*
         * 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.  newlines has the number we skipped.
         */
        if (no_output) {
            wrong_line = FALSE;
        } else {
            if (wrong_line || newlines > 10) {
                sharp( NULL, 0);            /* Output # line number */
                if (keep_spaces && src_col) {
                    while (src_col--)       /* Adjust columns       */
                        mcpp_fputc( ' ', OUT);
                    src_col = 0;
                }
            } else {                        /* If just a few, stuff */
                while (newlines-- > 0)      /* them out ourselves   */
                    mcpp_fputc('\n', OUT);
            }
        }

        /*
         * Process each token on this line.
         */
        line_top = TRUE;
        while (c != '\n' && c != CHAR_EOF) {    /* For the whole line   */
            /*
             * has_pragma is set to TRUE so as to execute _Pragma() operator
             * when the psuedo macro _Pragma() is found.
             */
            int     has_pragma;

            if ((mcpp_debug & MACRO_CALL) && ! in_directive) {
                line_col.line = src_line;       /* Location in source   */
                line_col.col = infile->bptr - infile->buffer - 1;
            }
            if (scan_token( c, (wp = out_ptr, &wp), out_wend) == NAM
                    && (defp = is_macro( &wp)) != NULL) {   /* A macro  */
                wp = expand_macro( defp, out_ptr, out_wend, line_col
                        , & has_pragma);    /* Expand it completely */
                if (line_top) {     /* The first token is a macro   */
                    char *  tp = out_ptr;
                    while (char_type[ *tp & UCHARMAX] & HSP)
                        tp++;           /* Remove excessive spaces  */
                    memmove( out_ptr, tp, strlen( tp) + 1);
                    wp -= (tp - out_ptr);
                }
                if (has_pragma) {           /* Found _Pramga()      */
                    do_pragma_op();         /* Do _Pragma() operator*/
                    out_ptr = output;       /* Do the rest of line  */
                    wrong_line = TRUE;      /* Line-num out of sync */
                } else {
                    out_ptr = wp;
                }
                if (keep_spaces && wrong_line && infile
                        && *(infile->bptr) != '\n' && *(infile->bptr) != EOS) {
                    src_col = infile->bptr - infile->buffer;
                    /* Remember the current colums  */
                    break;                  /* Do sharp() now       */
                }
            } else {                        /* Not a macro call     */
                out_ptr = wp;               /* Advance the place    */
                if (wrong_line)             /* is_macro() swallowed */
                    break;                  /*      the newline     */
            }
            while (char_type[ c = get_ch()] & HSP) {    /* Horizontal space */
                if (c != COM_SEP)           /* Skip 0-length comment*/
                    *out_ptr++ = c;
            }
            line_top = FALSE;               /* Read over some token */
        }                                   /* Loop for line        */

        putout( output);                    /* Output the line      */
    }                                       /* Continue until EOF   */
}
Exemplo n.º 21
0
static void endtable()
{
  newline();
  directive("@end table");
  newline();
}
void Preprocessor::RecursivePreprocess( std::string filename, FileLoader& file_source, LexemList& lexems, DefineTable& define_table )
{
    unsigned int start_line = CurrentLine;
    LinesThisFile = 0;
    CurrentFile = filename;
    SetFileMacro( define_table, CurrentFile );
    SetLineMacro( define_table, LinesThisFile );

    // Path formatting must be done in main application
    std::string CurrentFileRoot = RootPath + CurrentFile;
    if( std::find( FilesPreprocessed.begin(), FilesPreprocessed.end(), CurrentFileRoot ) == FilesPreprocessed.end() )
        FilesPreprocessed.push_back( CurrentFileRoot );

    std::vector<char> data;
    bool              loaded = file_source.LoadFile( RootPath, filename, data );
    if( !loaded )
    {
        PrintErrorMessage( std::string( "Could not open file " ) + RootPath + filename );
        return;
    }

    if( data.size() == 0 )
        return;
    char* d_end = &data[data.size() - 1];
    ++d_end;
    Lex( &data[0], d_end, lexems );

    LexemList::iterator itr = lexems.begin();
    LexemList::iterator end = lexems.end();
    LLITR               old = end;
    while( itr != end )
    {
        if( itr->Type == Lexem::NEWLINE )
        {
            if( itr != old )
            {
                CurrentLine++;
                LinesThisFile++;
                SetLineMacro( define_table, LinesThisFile );
            }
            old = itr;
            ++itr;
        }
        else if( itr->Type == Lexem::PREPROCESSOR )
        {
            LLITR     start_of_line = itr;
            LLITR     end_of_line = ParsePreprocessor( lexems, itr, end );

            LexemList directive( start_of_line, end_of_line );

            if( SkipPragmas && directive.begin()->Value == "#pragma" )
            {
                itr = end_of_line;
                Lexem wspace;
                wspace.Type = Lexem::WHITESPACE;
                wspace.Value = " ";
                for( LLITR it = start_of_line; it != end_of_line;)
                {
                    ++it;
                    it = lexems.insert( it, wspace );
                    ++it;
                }
                continue;
            }

            itr = lexems.erase( start_of_line, end_of_line );

            std::string value = directive.begin()->Value;
            if( value == "#define" )
            {
                ParseDefine( define_table, directive );
            }
            else if( value == "#ifdef" )
            {
                std::string           def_name;
                ParseIf( directive, def_name );
                DefineTable::iterator dti = define_table.find( def_name );
                if( dti == define_table.end() )
                {
                    LLITR splice_to = ParseIfDef( itr, end );
                    itr = lexems.erase( itr, splice_to );
                }
            }
            else if( value == "#ifndef" )
            {
                std::string           def_name;
                ParseIf( directive, def_name );
                DefineTable::iterator dti = define_table.find( def_name );
                if( dti != define_table.end() )
                {
                    LLITR splice_to = ParseIfDef( itr, end );
                    itr = lexems.erase( itr, splice_to );
                }
            }
            else if( value == "#if" )
            {
                bool satisfied = EvaluateExpression( define_table, directive ) != 0;
                if( !satisfied )
                {
                    LLITR splice_to = ParseIfDef( itr, end );
                    itr = lexems.erase( itr, splice_to );
                }
            }
            else if( value == "#endif" )
            {
                // ignore
            }
            else if( value == "#include" )
            {
                if( LNT )
                    LNT->AddLineRange( PrependRootPath( filename ), start_line, CurrentLine - LinesThisFile );
                unsigned int save_lines_this_file = LinesThisFile;
                std::string  file_name;
                ParseIf( directive, file_name );

                std::string file_name_ = RemoveQuotes( file_name );
                if( IncludeTranslator )
                    IncludeTranslator->Call( file_name_ );
                if( std::find( FileDependencies.begin(), FileDependencies.end(), file_name_ ) == FileDependencies.end() )
                    FileDependencies.push_back( file_name_ );

                LexemList next_file;
                RecursivePreprocess( AddPaths( filename, file_name_ ), file_source, next_file, define_table );
                lexems.splice( itr, next_file );
                start_line = CurrentLine;
                LinesThisFile = save_lines_this_file;
                CurrentFile = filename;
                SetFileMacro( define_table, CurrentFile );
                SetLineMacro( define_table, LinesThisFile );
            }
            else if( value == "#pragma" )
            {
                ParsePragma( directive );
            }
            else if( value == "#message" )
            {
                std::string message;
                ParseTextLine( directive, message );
                PrintMessage( message );
            }
            else if( value == "#warning" )
            {
                std::string warning;
                ParseTextLine( directive, warning );
                PrintWarningMessage( warning );
            }
            else if( value == "#error" )
            {
                std::string error;
                ParseTextLine( directive, error );
                PrintErrorMessage( error );
            }
            else
            {
                PrintErrorMessage( "Unknown directive '" + value + "'." );
            }
        }
        else if( itr->Type == Lexem::IDENTIFIER )
        {
            itr = ExpandDefine( itr, end, lexems, define_table );
        }
        else
        {
            ++itr;
        }
    }

    if( LNT )
        LNT->AddLineRange( PrependRootPath( filename ), start_line, CurrentLine - LinesThisFile );
}
Exemplo n.º 23
0
static void begintable_asis()
{
  newline();
  directive("@table @asis");
  newline();
}
Exemplo n.º 24
0
int main() {

    /*DECLARATIONS*/
    struct command *L[100];
    char *cmdLine = calloc(100,sizeof(char)); //command line
    int *groupD;                              //keep track of directives
    char c;
    int numLists = 0;                         //number of lists created
    int listNum=0;                            //specific list to deal with
    int i;

    signal(SIGCHLD, bg_handler);    //allow children to die
    signal(SIGALRM, alarm_handler); //check efficiency

    L[numLists] = (struct command *)calloc(1, sizeof(struct command));
    initialize_list(L[numLists]);
    
    printf("My Shell > ");
    fflush(stdout);
    
    while(1) {
        c = getchar();
        
        switch(c) {
            case'\n':
                if (cmdLine[0] == '\0') {
                    printf("My Shell > ");
                }
                else { /*execute command line*/
                    
                    groupD = parse_cmdline(L[numLists], cmdLine);
                    if (groupD[0] == 0){
                        exec_cmdline(L[numLists]);
                    }
                    else {
                        /*directives*/
                        for (i=0; i<numLists+1; i++){
                            if (L[i]->group == groupD[1]){
                                directive(L[i], groupD[0]);
                            }
                        }
                    }
                    printf("My Shell > ");
                    
                    numLists++;
                    L[numLists] = (struct command *)calloc(1, sizeof(struct command));
                    initialize_list(L[numLists]);
                    reset_cmdline(cmdLine);
                }
            break;
            
            default:
                strncat(cmdLine, &c, 1);
                break;
        }
    }
    for (i=0; i<numLists+1; i++)
        free_proclist(L[i]);
    free_listofproclist(L);
    free(cmdLine);
return -1;
}
Exemplo n.º 25
0
 inline basic_message<Tag> &
 operator<< (basic_message<Tag> & message_, Directive const & directive) {
     directive(message_);
     return message_;
 }