make this compile under NetBSD.

This commit is contained in:
mrg 1998-11-11 05:26:57 +00:00
parent 8ed3c420dc
commit 843b0a05b3
2 changed files with 49 additions and 60 deletions

View File

@ -1,20 +1,8 @@
# $NetBSD: Makefile,v 1.1 1998/10/31 18:14:53 eeh Exp $ # $NetBSD: Makefile,v 1.2 1998/11/11 05:26:57 mrg Exp $
CURDIR= ${.CURDIR} PROG= fgen
S= ${CURDIR}/../../../.. SRCS= fgen.l
MAN= fgen.1
#
# Override normal settings
#
CC=cc
LORDER=lorder
TSORT=tsort
NM=nm
PROG= fgen
SRCS= fgen.l
NOMAN=
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -49,12 +49,15 @@ white [ \t\n\r\f]
tail {white} tail {white}
%{ %{
#include <errno.h> #include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "fgen.h" #include "fgen.h"
TOKEN token; TOKEN token;
@ -81,12 +84,14 @@ int tokenizer = 0;
Cell parse_stack[PSTKSIZ]; Cell parse_stack[PSTKSIZ];
int parse_stack_ptr = 0; int parse_stack_ptr = 0;
/* define prototype */ int main __P((int, char *[]));
YY_DECL; YY_DECL;
int debug = 0; int debug = 0;
#define ASSERT if (debug) assert #define ASSERT if (debug) assert
#define STATE(y, x) do { if (debug) printf( "%ld State %s: token `%s'\n", outpos, x, y); } while (0) #define STATE(y, x) do { if (debug) printf( "%ld State %s: token `%s'\n", outpos, x, y); } while (0)
#define YY_NO_UNPUT
%} %}
%% %%
@ -278,10 +283,10 @@ int aadd __P((struct macro *, struct macro *));
struct macro *alookup __P((struct macro *, char *)); struct macro *alookup __P((struct macro *, char *));
void initdic __P((void)); void initdic __P((void));
void usage __P((char *)); void usage __P((char *));
TOKEN* tokenize __P((YY_BUFFER_STATE)); void tokenize __P((YY_BUFFER_STATE));
int emit __P((char *)); int emit __P((char *));
int spit __P((long)); int spit __P((long));
int sspit __P((char *)); void sspit __P((char *));
int apply_macros __P((YY_BUFFER_STATE, char *)); int apply_macros __P((YY_BUFFER_STATE, char *));
int main __P((int argc, char *argv[])); int main __P((int argc, char *argv[]));
@ -799,7 +804,7 @@ char *str;
*/ */
int int
aadd(dict, new) aadd(dict, new)
struct macro *dict, *new; struct macro *dict, *new;
{ {
int res = strcmp(dict->name, new->name); int res = strcmp(dict->name, new->name);
@ -922,19 +927,16 @@ apply_macros(input, str)
void void
usage(me) usage(me)
char *me; char *me;
{ {
(void)printf( (void)fprintf(stderr, "%s: [-o <outfile>] <infile>\n", me);
"%s: [-o <outfile>] <infile>\n",
me);
exit(1); exit(1);
} }
int int
main(argc, argv) main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
@ -955,7 +957,7 @@ char *argv[];
debug = atol(optarg); debug = atol(optarg);
break; break;
case 'o': case 'o':
if ((outf = open(optarg, O_WRONLY|O_CREAT|O_TRUNC, 666)) == NULL) { if ((outf = open(optarg, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == NULL) {
(void)printf( (void)printf(
"%s: %s: %s\n", "%s: %s: %s\n",
myname, optarg, strerror(errno)); myname, optarg, strerror(errno));
@ -995,7 +997,7 @@ char *argv[];
inbuf = yy_create_buffer( inf, YY_BUF_SIZE ); inbuf = yy_create_buffer( inf, YY_BUF_SIZE );
yy_switch_to_buffer(inbuf); yy_switch_to_buffer(inbuf);
(void)tokenize(inbuf); tokenize(inbuf);
yy_delete_buffer(inbuf); yy_delete_buffer(inbuf);
fclose(inf); fclose(inf);
emit("end0"); emit("end0");
@ -1023,7 +1025,7 @@ char *argv[];
* be called recursively to parse mutiple levels of include files. * be called recursively to parse mutiple levels of include files.
*/ */
TOKEN* void
tokenize(input) tokenize(input)
YY_BUFFER_STATE input; YY_BUFFER_STATE input;
{ {
@ -1031,8 +1033,6 @@ tokenize(input)
YY_BUFFER_STATE inbuf; YY_BUFFER_STATE inbuf;
TOKEN *token; TOKEN *token;
struct fcode *fcode; struct fcode *fcode;
struct macro *macro;
int lastof = 0; /* Offset of last `endof' */
int pos, off; int pos, off;
while ((token = yylex()) != NULL) { while ((token = yylex()) != NULL) {
@ -1071,7 +1071,7 @@ tokenize(input)
spit(0); spit(0);
spit(0); spit(0);
spit(token->text[1]); spit(token->text[1]);
break; break;
case TOK_STRING_LIT: case TOK_STRING_LIT:
STATE(token->text, "TOK_STRING_LIT:"); STATE(token->text, "TOK_STRING_LIT:");
{ {
@ -1135,7 +1135,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in colon definition\n"); (void)printf( "EOF in colon definition\n");
return (token); return;
} }
/* Add new code to dictionary */ /* Add new code to dictionary */
@ -1188,7 +1188,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in alias definition\n"); (void)printf( "EOF in alias definition\n");
return (token); return;
} }
if (token->type != TOK_OTHER) { if (token->type != TOK_OTHER) {
(void)printf( "ENDCOMMENT aliasing weird token type %d\n", (void)printf( "ENDCOMMENT aliasing weird token type %d\n",
@ -1199,7 +1199,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in alias definition\n"); (void)printf( "EOF in alias definition\n");
return (token); return;
} }
alias->equiv = strdup(token->text); alias->equiv = strdup(token->text);
if (!aadd(aliases, alias)) { if (!aadd(aliases, alias)) {
@ -1216,7 +1216,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in [']\n"); (void)printf( "EOF in [']\n");
return (token); return;
} }
if ((fcode = flookup(dictionary, token->text)) == NULL) { if ((fcode = flookup(dictionary, token->text)) == NULL) {
(void)printf( "[']: %s not found\n", token->text); (void)printf( "[']: %s not found\n", token->text);
@ -1248,7 +1248,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in colon definition\n"); (void)printf( "EOF in colon definition\n");
return (token); return;
} }
/* Add new code to dictionary */ /* Add new code to dictionary */
@ -1281,7 +1281,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in constant definition\n"); (void)printf( "EOF in constant definition\n");
return (token); return;
} }
/* Add new code to dictionary */ /* Add new code to dictionary */
@ -1322,7 +1322,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in create definition\n"); (void)printf( "EOF in create definition\n");
return (token); return;
} }
/* Add new code to dictionary */ /* Add new code to dictionary */
@ -1360,7 +1360,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF after d#\n"); (void)printf( "EOF after d#\n");
return (token); return;
} }
if (token->type == TOK_OTHER) { if (token->type == TOK_OTHER) {
if (strcmp("-1", token->text) == 0) { if (strcmp("-1", token->text) == 0) {
@ -1391,7 +1391,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in colon definition\n"); (void)printf( "EOF in colon definition\n");
return (token); return;
} }
/* Add new code to dictionary */ /* Add new code to dictionary */
@ -1460,7 +1460,7 @@ tokenize(input)
pos = outpos; pos = outpos;
outpos = off; outpos = off;
off = pos - off; off = pos - off;
if (offsetsize == 16) { if (offsetsize == 16) {
spit(0); /* Place holder for later */ spit(0); /* Place holder for later */
} }
spit(0); /* Place holder for later */ spit(0); /* Place holder for later */
@ -1527,7 +1527,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in field definition\n"); (void)printf( "EOF in field definition\n");
return (token); return;
} }
/* Add new code to dictionary */ /* Add new code to dictionary */
@ -1566,7 +1566,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF after h#\n"); (void)printf( "EOF after h#\n");
return (token); return;
} }
value = strtol(token->text, &end, 16); value = strtol(token->text, &end, 16);
if (*end != 0) { if (*end != 0) {
@ -1655,7 +1655,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF after o#\n"); (void)printf( "EOF after o#\n");
return (token); return;
} }
value = strtol(token->text, &end, 8); value = strtol(token->text, &end, 8);
if (*end != 0) { if (*end != 0) {
@ -1756,7 +1756,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in value definition\n"); (void)printf( "EOF in value definition\n");
return (token); return;
} }
/* Add new code to dictionary */ /* Add new code to dictionary */
@ -1784,7 +1784,7 @@ tokenize(input)
token = yylex(); token = yylex();
if (token == NULL) { if (token == NULL) {
(void)printf( "EOF in variable definition\n"); (void)printf( "EOF in variable definition\n");
return (token); return;
} }
/* Add new code to dictionary */ /* Add new code to dictionary */
@ -1870,7 +1870,7 @@ tokenize(input)
default: default:
} }
} }
return (NULL); return;
} }
/* /*
@ -1904,7 +1904,7 @@ emit(str)
*/ */
int int
spit(n) spit(n)
long n; long n;
{ {
int count = 1; int count = 1;
@ -1914,7 +1914,7 @@ long n;
while (outpos >= outbufsiz) outbufsiz += BUFCLICK; while (outpos >= outbufsiz) outbufsiz += BUFCLICK;
if (!(outbuf = realloc(outbuf, outbufsiz))) { if (!(outbuf = realloc(outbuf, outbufsiz))) {
(void)printf( "realloc of %ld bytes failed -- out of memory\n", (void)printf( "realloc of %ld bytes failed -- out of memory\n",
outbufsiz); (long)outbufsiz);
exit(1); exit(1);
} }
} }
@ -1925,7 +1925,7 @@ long n;
/* /*
* Spit out an FCode string. * Spit out an FCode string.
*/ */
int void
sspit(s) sspit(s)
char *s; char *s;
{ {
@ -1933,19 +1933,20 @@ sspit(s)
if (len > 255) { if (len > 255) {
(void)printf( "string length %d too long\n", len); (void)printf( "string length %d too long\n", len);
return (0); return;
} }
#ifdef DEBUG #ifdef DEBUG
if (debug > 1) if (debug > 1)
(void)printf( "sspit: len %d str `%s'\n", len, s); (void)printf( "sspit: len %d str `%s'\n", len, s);
#endif #endif
spit(len); spit(len);
while (*s) spit(*s++); while (*s)
return (len); spit(*s++);
} }
int int
yywrap() { yywrap()
{
/* Always generate EOF */ /* Always generate EOF */
return (1); return (1);
} }