rpc_scan.c revision a2f144d1eca25f33af1e19affd8eda208f547108
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
/*
* rpc_scan.c, Scanner for the RPC protocol compiler
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "rpc_scan.h"
#include "rpc_parse.h"
#include "rpc_util.h"
static int pushed = 0; /* is a token pushed */
static void unget_token(token *);
static void findstrconst(char **, char **);
static void findchrconst(char **, char **);
static void findconst(char **, char **);
static int cppline(char *);
static int directive(char *);
static void printdirective(char *);
static void docppline(char *, int *, char **);
/*
* scan expecting 1 given token
*/
void
{
}
/*
* scan expecting any of the 2 given tokens
*/
void
{
}
/*
* scan expecting any of the 3 given token
*/
void
{
}
/*
* scan expecting a constant, possibly symbolic
*/
void
{
case TOK_IDENT:
break;
default:
error("constant or identifier expected");
}
}
/*
* Peek at the next token
*/
void
{
}
/*
* Peek at the next token and scan it if it matches what you expect
*/
int
{
return (1);
}
return (0);
}
/*
* Get the next token, printing out any directive that are encountered.
*/
void
{
int commenting;
int stat = 0;
if (pushed) {
pushed = 0;
return;
}
commenting = 0;
for (;;) {
if (*where == 0) {
for (;;) {
/*
* now check if cpp returned
* non NULL value
*/
if (stat > 0) {
/* Set return value from rpcgen */
}
*where = 0;
return;
}
linenum++;
if (commenting) {
break;
&infilename);
} else {
break;
}
}
where++; /* eat */
}
} else if (commenting) {
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 ':':
where++;
break;
case ';':
where++;
break;
case ',':
where++;
break;
case '=':
where++;
break;
case '*':
where++;
break;
case '[':
where++;
break;
case ']':
where++;
break;
case '{':
where++;
break;
case '}':
where++;
break;
case '(':
where++;
break;
case ')':
where++;
break;
case '<':
where++;
break;
case '>':
where++;
break;
case '"':
break;
case '\'':
break;
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
break;
default:
char buf[100];
char *p;
"illegal character in file: ");
"%c", *where);
} else {
"%d", *where);
}
}
break;
}
}
static void
{
pushed = 1;
}
static void
{
char *p;
int size;
p = *str;
do {
p++;
} while (*p && *p != '"');
if (*p == 0) {
error("unterminated string constant");
}
p++;
*str = p;
}
static void
{
char *p;
int size;
p = *str;
do {
p++;
} while (*p && *p != '\'');
if (*p == 0)
error("unterminated string constant");
p++;
if (size != 3)
error("empty char string");
*str = p;
}
static void
{
char *p;
int size;
p = *str;
if (*p == '0' && *(p + 1) == 'x') {
p++;
do {
p++;
} while (isxdigit(*p));
} else {
do {
p++;
} while (isdigit(*p));
}
*str = p;
}
{TOK_CONST, "const"},
{TOK_UNION, "union"},
{TOK_SWITCH, "switch"},
{TOK_CASE, "case"},
{TOK_DEFAULT, "default"},
{TOK_STRUCT, "struct"},
{TOK_TYPEDEF, "typedef"},
{TOK_ENUM, "enum"},
{TOK_OPAQUE, "opaque"},
{TOK_BOOL, "bool"},
{TOK_VOID, "void"},
{TOK_ONEWAY, "oneway"},
{TOK_CHAR, "char"},
{TOK_INT, "int"},
{TOK_UNSIGNED, "unsigned"},
{TOK_SHORT, "short"},
{TOK_LONG, "long"},
{TOK_HYPER, "hyper"},
{TOK_FLOAT, "float"},
{TOK_DOUBLE, "double"},
{TOK_QUAD, "quadruple"},
{TOK_STRING, "string"},
{TOK_PROGRAM, "program"},
{TOK_VERSION, "version"},
{TOK_EOF, "??????"},
};
static void
{
int len;
token *s;
char *str;
return;
}
}
}
/* LOOP */;
}
static int
{
}
static int
{
}
static void
printdirective(char *line)
{
}
static void
{
char *file;
int num;
char *p;
line++;
line++;
line++;
line++;
if (*line != '"')
error("preprocessor error");
line++;
*p++ = *line++;
if (*line == 0)
error("preprocessor error");
*p = 0;
if (*file == 0)
else
}