version 1.6, 2001/11/24 19:19:59 |
version 1.7, 2001/12/05 09:50:31 |
|
|
#endif |
#endif |
|
|
/* |
/* |
* rpc_util.c, Utility routines for the RPC protocol compiler |
* rpc_util.c, Utility routines for the RPC protocol compiler |
*/ |
*/ |
#include <sys/cdefs.h> |
#include <sys/cdefs.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <ctype.h> |
#include <ctype.h> |
|
#include <unistd.h> |
#include "rpc_scan.h" |
#include "rpc_scan.h" |
#include "rpc_parse.h" |
#include "rpc_parse.h" |
#include "rpc_util.h" |
#include "rpc_util.h" |
|
|
list *defined; /* list of defined things */ |
list *defined; /* list of defined things */ |
|
|
/* |
/* |
* Reinitialize the world |
* Reinitialize the world |
*/ |
*/ |
|
void |
reinitialize() |
reinitialize() |
{ |
{ |
memset(curline, 0, MAXLINESIZE); |
memset(curline, 0, MAXLINESIZE); |
|
|
} |
} |
|
|
/* |
/* |
* string equality |
* string equality |
*/ |
*/ |
|
int |
streq(a, b) |
streq(a, b) |
char *a; |
char *a; |
char *b; |
char *b; |
|
|
} |
} |
|
|
/* |
/* |
* find a value in a list |
* find a value in a list |
*/ |
*/ |
definition * |
definition * |
findval(lst, val, cmp) |
findval(lst, val, cmp) |
|
|
int (*cmp) (); |
int (*cmp) (); |
|
|
{ |
{ |
|
|
for (; lst != NULL; lst = lst->next) { |
for (; lst != NULL; lst = lst->next) { |
if ((*cmp) (lst->val, val)) { |
if ((*cmp) (lst->val, val)) { |
return (lst->val); |
return (lst->val); |
|
|
} |
} |
|
|
/* |
/* |
* store a value in a list |
* store a value in a list |
*/ |
*/ |
void |
void |
storeval(lstp, val) |
storeval(lstp, val) |
|
|
list **l; |
list **l; |
list *lst; |
list *lst; |
|
|
|
|
for (l = lstp; *l != NULL; l = (list **) & (*l)->next); |
for (l = lstp; *l != NULL; l = (list **) & (*l)->next); |
lst = ALLOC(list); |
lst = ALLOC(list); |
lst->val = val; |
lst->val = val; |
|
|
*l = lst; |
*l = lst; |
} |
} |
|
|
static |
static int |
findit(def, type) |
findit(def, type) |
definition *def; |
definition *def; |
char *type; |
char *type; |
|
|
} |
} |
} |
} |
|
|
static |
static int |
typedefed(def, type) |
typedefed(def, type) |
definition *def; |
definition *def; |
char *type; |
char *type; |
|
|
} |
} |
} |
} |
|
|
|
int |
isvectordef(type, rel) |
isvectordef(type, rel) |
char *type; |
char *type; |
relation rel; |
relation rel; |
|
|
static char buf[100]; |
static char buf[100]; |
char *p = buf; |
char *p = buf; |
|
|
while (c = *str++) { |
while ((c = *str++)) { |
*p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; |
*p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; |
} |
} |
*p = 0; |
*p = 0; |
|
|
} |
} |
|
|
/* |
/* |
* print a useful (?) error message, and then die |
* print a useful (?) error message, and then die |
*/ |
*/ |
void |
void |
error(msg) |
error(msg) |
|
|
|
|
/* |
/* |
* Something went wrong, unlink any files that we may have created and then |
* Something went wrong, unlink any files that we may have created and then |
* die. |
* die. |
*/ |
*/ |
|
void |
crash() |
crash() |
{ |
{ |
int i; |
int i; |
|
|
static char *toktostr(); |
static char *toktostr(); |
|
|
/* |
/* |
* error, token encountered was not the expected one |
* error, token encountered was not the expected one |
*/ |
*/ |
void |
void |
expected1(exp1) |
expected1(exp1) |
|
|
} |
} |
|
|
/* |
/* |
* error, token encountered was not one of two expected ones |
* error, token encountered was not one of two expected ones |
*/ |
*/ |
void |
void |
expected2(exp1, exp2) |
expected2(exp1, exp2) |
|
|
} |
} |
|
|
/* |
/* |
* error, token encountered was not one of 3 expected ones |
* error, token encountered was not one of 3 expected ones |
*/ |
*/ |
void |
void |
expected3(exp1, exp2, exp3) |
expected3(exp1, exp2, exp3) |
|
|
} |
} |
} |
} |
|
|
|
|
static token tokstrings[] = { |
static token tokstrings[] = { |
{TOK_IDENT, "identifier"}, |
{TOK_IDENT, "identifier"}, |
{TOK_CONST, "const"}, |
{TOK_CONST, "const"}, |
|
|
return (sp->str); |
return (sp->str); |
} |
} |
|
|
static |
static void |
printbuf() |
printbuf() |
{ |
{ |
char c; |
char c; |
|
|
|
|
# define TABSIZE 4 |
# define TABSIZE 4 |
|
|
for (i = 0; c = curline[i]; i++) { |
for (i = 0; (c = curline[i]); i++) { |
if (c == '\t') { |
if (c == '\t') { |
cnt = 8 - (i % TABSIZE); |
cnt = 8 - (i % TABSIZE); |
c = ' '; |
c = ' '; |
|
|
(void) fputc('\n', stderr); |
(void) fputc('\n', stderr); |
} |
} |
|
|
char * |
char * |
make_argname(pname, vname) |
make_argname(pname, vname) |
char *pname; |
char *pname; |
char *vname; |
char *vname; |
{ |
{ |
char *name; |
char *name; |
|
|
name = (char *)malloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3); |
name = (char *)malloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3); |
if (!name) { |
if (!name) { |
fprintf(stderr, "failed in malloc"); |
fprintf(stderr, "failed in malloc"); |
|
|
{ |
{ |
bas_type * ptr; |
bas_type * ptr; |
|
|
ptr=typ_list_h; |
ptr = typ_list_h; |
|
|
|
|
while (ptr != NULL) { |
while (ptr != NULL) { |
if (strcmp(ptr->name,type) == 0) |
if (strcmp(ptr->name,type) == 0) |