/* @(#)rpc_scan.c 2.1 88/08/01 4.0 RPCSRC */
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
* Mountain View, California 94043
static char sccsid
[] = "@(#)rpc_scan.c 1.6 87/06/24 (C) 1987 SMI";
* rpc_scan.c, Scanner for the RPC protocol compiler
* Copyright (C) 1987, Sun Microsystems, Inc.
#define startcomment(where) (where[0] == '/' && where[1] == '*')
#define endcomment(where) (where[-1] == '*' && where[0] == '/')
static int pushed
= 0; /* is a token pushed */
static token lasttok
; /* last token, if pushed */
* scan expecting 1 given token
if (tokp
->kind
!= expect
) {
* scan expecting 2 given tokens
scan2(expect1
, expect2
, tokp
)
if (tokp
->kind
!= expect1
&& tokp
->kind
!= expect2
) {
expected2(expect1
, expect2
);
* scan expecting 3 given token
scan3(expect1
, expect2
, expect3
, tokp
)
if (tokp
->kind
!= expect1
&& tokp
->kind
!= expect2
&& tokp
->kind
!= expect3
) {
expected3(expect1
, expect2
, expect3
);
* scan expecting a constant, possibly symbolic
error("constant or identifier expected");
* Peek at the next token and scan it if it matches what you expect
if (tokp
->kind
== expect
) {
* Get the next token, printing out any directive that are encountered.
if (!fgets(curline
, MAXLINESIZE
, fin
)) {
} else if (cppline(curline
)) {
docppline(curline
, &linenum
,
} else if (directive(curline
)) {
} else if (isspace(*where
)) {
while (isspace(*where
)) {
} else if (startcomment(where
)) {
* 'where' is not whitespace, comment or directive Must be a token!
tokp
->kind
= TOK_SEMICOLON
;
tokp
->kind
= TOK_LBRACKET
;
tokp
->kind
= TOK_RBRACKET
;
tokp
->kind
= TOK_STRCONST
;
findstrconst(&where
, &tokp
->str
);
findconst(&where
, &tokp
->str
);
if (!(isalpha(*where
) || *where
== '_')) {
s_print(buf
, "illegal character in file: ");
s_print(p
, "%c", *where
);
s_print(p
, "%d", *where
);
} while (*p
&& *p
!= '"');
error("unterminated string constant");
(void) strncpy(*val
, *str
, size
);
if (*p
== '0' && *(p
+ 1) == 'x') {
(void) strncpy(*val
, *str
, size
);
static token symbols
[] = {
{TOK_DEFAULT
, "default"},
{TOK_TYPEDEF
, "typedef"},
{TOK_UNSIGNED
, "unsigned"},
{TOK_PROGRAM
, "program"},
{TOK_VERSION
, "version"},
for (s
= symbols
; s
->kind
!= TOK_EOF
; s
++) {
if (strncmp(str
, s
->str
, len
) == 0) {
if (!isalnum(str
[len
]) && str
[len
] != '_') {
for (len
= 0; isalnum(str
[len
]) || str
[len
] == '_'; len
++);
tokp
->str
= alloc(len
+ 1);
(void) strncpy(tokp
->str
, str
, len
);
return (line
== curline
&& *line
== '#');
return (line
== curline
&& *line
== '%');
f_print(fout
, "%s", line
+ 1);
docppline(line
, lineno
, fname
)
error("preprocessor error");
p
= file
= alloc(strlen(line
) + 1);
while (*line
&& *line
!= '"') {
error("preprocessor error");