コード例 #1
0
ファイル: rpc_scan.c プロジェクト: holme-r/libarpc
/*
 * 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)) {
コード例 #2
0
ファイル: rpc_scan.c プロジェクト: mchalain/makeroot
/*
 * 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;
    }
}