Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Duncan White
C-datadec
Commits
2fc0bb95
Commit
2fc0bb95
authored
Jan 07, 1993
by
dcw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added begin section
parent
b681a4a5
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
77 additions
and
38 deletions
+77
-38
datadec.c
datadec.c
+6
-3
decs.c
decs.c
+34
-17
decs.h
decs.h
+1
-1
lexer.c
lexer.c
+5
-2
lexer.h
lexer.h
+1
-1
m2decs.c
m2decs.c
+15
-11
parser.c
parser.c
+14
-2
parser.h
parser.h
+1
-1
No files found.
datadec.c
View file @
2fc0bb95
...
...
@@ -34,6 +34,8 @@
#define CHUNKSIZE 10000
typedef
char
bigstr
[
CHUNKSIZE
];
void
main
(
argc
,
argv
)
int
argc
;
char
**
argv
;
{
...
...
@@ -42,7 +44,7 @@ void main( argc, argv ) int argc; char **argv;
declnlist
declns
;
int
len
;
int
arg
;
cha
r
exports
[
CHUNKSIZE
],
globals
[
CHUNKSIZE
]
;
bigst
r
exports
,
globals
,
begin
;
arg
=
1
;
NEED_ANOTHER_ARG
;
...
...
@@ -89,7 +91,7 @@ void main( argc, argv ) int argc; char **argv;
REQUIRE_NO_MORE_ARGS
;
if
(
parse_data
(
exports
,
globals
,
&
declns
)
)
if
(
parse_data
(
exports
,
globals
,
begin
,
&
declns
)
)
{
if
(
verbose
)
{
...
...
@@ -97,9 +99,10 @@ void main( argc, argv ) int argc; char **argv;
print_declnlist
(
declns
);
printf
(
"exports = {%s}
\n
"
,
exports
);
printf
(
"globals = {%s}
\n
"
,
globals
);
printf
(
"begin = {%s}
\n
"
,
begin
);
}
optimize
(
declns
);
make_declns
(
exports
,
globals
,
declns
,
basename
);
make_declns
(
exports
,
globals
,
begin
,
declns
,
basename
);
}
else
{
fprintf
(
stderr
,
"datadec: can't parse input properly
\n
"
);
...
...
decs.c
View file @
2fc0bb95
...
...
@@ -12,12 +12,12 @@ stat %
#ifdef HASPROTOS
static
void
line
(
char
*
,
long
,
long
,
long
,
long
);
static
void
h_declns
(
char
*
,
char
*
,
declnlist
);
static
void
c_declns
(
char
*
,
char
*
,
declnlist
);
static
void
h_declns
(
char
*
,
char
*
,
BOOL
,
declnlist
);
static
void
c_declns
(
char
*
,
char
*
,
char
*
,
declnlist
);
static
void
data_decls
(
declnlist
);
static
void
declare_type
(
decln
);
static
void
declfields
(
paramlist
);
static
void
protos
(
declnlist
,
BOOL
);
static
void
protos
(
BOOL
,
char
*
,
declnlist
,
BOOL
);
static
void
proto_type
(
decln
,
BOOL
);
static
void
cons_fns
(
declnlist
);
static
void
cons_fn_proto
(
decln
,
shapelist
,
BOOL
);
...
...
@@ -27,12 +27,12 @@ static void decons_fns_type( decln );
static
void
deconskind_proto
(
decln
,
BOOL
);
static
void
deconskind_fn
(
decln
);
static
void
decons_fn_proto
(
decln
,
shapelist
,
BOOL
);
static
void
decons_fn
(
decln
,
char
*
,
shapelist
);
static
void
decons_fn
(
decln
,
shapelist
);
static
void
print_fn_proto
(
char
*
,
BOOL
);
static
void
print_fns
(
declnlist
);
static
void
print_fn_shape
(
declnlist
,
shapelist
);
static
void
print_all_params
(
declnlist
,
shapelist
);
static
void
print_param
(
c
ha
r
*
,
paramlist
,
BOOL
);
static
void
print_param
(
s
ha
pelist
,
paramlist
,
BOOL
);
#else
static
void
line
();
static
void
h_declns
();
...
...
@@ -83,21 +83,21 @@ static void line( fmt, a, b, c, d ) char *fmt; long a, b, c, d;
}
void
make_declns
(
exports
,
globals
,
d
,
base
name
)
declnlist
d
;
char
*
exports
,
*
globals
,
*
b
asenam
e
;
void
make_declns
(
exports
,
globals
,
begin
,
d
,
base
)
declnlist
d
;
char
*
exports
,
*
globals
,
*
b
egin
,
*
bas
e
;
{
printf
(
"datadec: Making data declarations in %s.[ch]
\n
"
,
base
name
);
h_declns
(
base
name
,
exports
,
d
);
c_declns
(
base
name
,
globals
,
d
);
printf
(
"datadec: Making data declarations in %s.[ch]
\n
"
,
base
);
h_declns
(
base
,
exports
,
*
begin
!=
'\0'
,
d
);
c_declns
(
base
,
globals
,
begin
,
d
);
}
static
void
h_declns
(
base
name
,
exports
,
d
)
char
*
base
name
,
*
exports
;
declnlist
d
;
static
void
h_declns
(
base
,
exports
,
init
,
d
)
char
*
base
,
*
exports
;
BOOL
init
;
declnlist
d
;
{
char
tempname
[
256
];
char
*
exportptr
;
FILE
*
hfile
;
sprintf
(
tempname
,
"%s.h"
,
base
name
);
sprintf
(
tempname
,
"%s.h"
,
base
);
hfile
=
fopen
(
tempname
,
"w"
);
ASSERT
(
hfile
!=
NULL
,
(
"datadec: can't create '%s'
\n
"
,
tempname
)
);
...
...
@@ -134,9 +134,9 @@ static void h_declns( basename, exports, d ) char *basename, *exports; declnlist
line
(
"
\n
/* Prototypes for all types */
\n
"
);
line
(
"#ifdef HASPROTOS"
);
protos
(
d
,
TRUE
);
protos
(
init
,
base
,
d
,
TRUE
);
line
(
"#else"
);
protos
(
d
,
FALSE
);
protos
(
init
,
base
,
d
,
FALSE
);
line
(
"#endif"
);
if
(
*
exportptr
!=
'\0'
)
...
...
@@ -151,13 +151,13 @@ static void h_declns( basename, exports, d ) char *basename, *exports; declnlist
}
static
void
c_declns
(
base
name
,
globals
,
d
)
char
*
base
name
,
*
globals
;
declnlist
d
;
static
void
c_declns
(
base
,
globals
,
begin
,
d
)
char
*
base
,
*
globals
,
*
begin
;
declnlist
d
;
{
char
tempname
[
256
];
FILE
*
cfile
;
char
*
globalptr
;
sprintf
(
tempname
,
"%s.c"
,
base
name
);
sprintf
(
tempname
,
"%s.c"
,
base
);
cfile
=
fopen
(
tempname
,
"w"
);
ASSERT
(
cfile
!=
NULL
,
(
"datadec: can't create '%s'
\n
"
,
tempname
)
);
...
...
@@ -168,7 +168,7 @@ static void c_declns( basename, globals, d ) char *basename, *globals; declnlist
line
(
" */
\n
"
);
line
(
"#include <stdio.h>"
);
line
(
"#include <malloc.h>"
);
line
(
"#include
\"
%s.h
\"\n\n
"
,
base
name
);
line
(
"#include
\"
%s.h
\"\n\n
"
,
base
);
if
(
*
globals
!=
'\0'
)
{
...
...
@@ -201,6 +201,14 @@ static void c_declns( basename, globals, d ) char *basename, *globals; declnlist
nl
();
}
if
(
*
begin
!=
'\0'
)
{
line
(
"/* Contents of BEGIN section */"
);
line
(
"void init_%s()"
,
base
);
line
(
"{"
);
line
(
begin
);
line
(
"}"
);
}
fclose
(
cfile
);
}
...
...
@@ -314,12 +322,21 @@ static void declfields( p ) paramlist p;
/* ---------------------- Declare all prototypes -------------------------- */
static
void
protos
(
d
,
prot
)
declnlist
d
;
BOOL
prot
;
static
void
protos
(
init
,
base
,
d
,
prot
)
BOOL
init
;
char
*
base
;
declnlist
d
;
BOOL
prot
;
{
for
(
;
d
!=
NULL
;
d
=
d
->
next
)
{
proto_type
(
d
,
prot
);
}
if
(
init
)
{
fprintf
(
outfile
,
"extern void init_%s( "
,
base
);
if
(
prot
)
{
fputs
(
"void "
,
outfile
);
}
fputs
(
");
\n
"
,
outfile
);
}
}
...
...
decs.h
View file @
2fc0bb95
#ifdef HASPROTOS
extern
void
make_declns
(
char
*
,
char
*
,
declnlist
,
char
*
);
extern
void
make_declns
(
char
*
,
char
*
,
char
*
,
declnlist
,
char
*
);
#else
extern
void
make_declns
();
#endif
lexer.c
View file @
2fc0bb95
...
...
@@ -11,7 +11,7 @@
******* Tokens:
*
* tERROR tEOF tSEMI tID tEQ tOR tOPENBR tCOMMA tCLOSEBR
* tSTR tNUM tEXPORT tGLOBAL tOPENCURLY tCLOSECURLY tTYPE
* tSTR tNUM tEXPORT tGLOBAL
tBEGIN
tOPENCURLY tCLOSECURLY tTYPE
*/
...
...
@@ -24,7 +24,7 @@
static
char
*
tokenname
[]
=
{
"tERROR"
,
"tEOF"
,
"tSEMI"
,
"tID"
,
"tEQ"
,
"tOR"
,
"tOPENBR"
,
"tCOMMA"
,
"tCLOSEBR"
,
"tSTR"
,
"tNUM"
,
"tEXPORT"
,
"tGLOBAL"
,
"tOPENCURLY"
,
"tCLOSECURLY"
,
"tTYPE"
"tBEGIN"
,
"tOPENCURLY"
,
"tCLOSECURLY"
,
"tTYPE"
};
#endif
...
...
@@ -137,6 +137,9 @@ TOKEN nexttok()
}
else
if
(
streq
(
curid
,
"GLOBAL"
)
)
{
curtok
=
tGLOBAL
;
}
else
if
(
streq
(
curid
,
"BEGIN"
)
)
{
curtok
=
tBEGIN
;
}
else
if
(
streq
(
curid
,
"TYPE"
)
)
{
curtok
=
tTYPE
;
...
...
lexer.h
View file @
2fc0bb95
...
...
@@ -15,7 +15,7 @@
typedef
enum
{
tERROR
,
tEOF
,
tSEMI
,
tID
,
tEQ
,
tOR
,
tOPENBR
,
tCOMMA
,
tCLOSEBR
,
tSTR
,
tNUM
,
tEXPORT
,
tGLOBAL
,
tOPENCURLY
,
tCLOSECURLY
,
tTYPE
tEXPORT
,
tGLOBAL
,
tBEGIN
,
tOPENCURLY
,
tCLOSECURLY
,
tTYPE
}
TOKEN
;
...
...
m2decs.c
View file @
2fc0bb95
...
...
@@ -17,7 +17,7 @@ stat %
static
void
line
(
char
*
,
long
,
long
,
long
,
long
);
static
void
defn_declns
(
char
*
,
char
*
,
declnlist
);
static
void
defn_onetype
(
decln
);
static
void
impln_declns
(
char
*
,
char
*
,
declnlist
);
static
void
impln_declns
(
char
*
,
char
*
,
char
*
,
declnlist
);
static
void
impln_onetype
(
decln
);
static
void
variantfields
(
decln
);
static
void
normalfields
(
decln
);
...
...
@@ -70,27 +70,26 @@ static int predefined_type();
#endif
static
int
numtabs
=
0
;
static
FILE
*
outfile
;
/* ------------------------- PUBLIC PROCEDURES --------------------------- */
void
make_declns
(
exports
,
globals
,
d
,
base
name
)
declnlist
d
;
char
*
exports
,
*
globals
,
*
b
asenam
e
;
void
make_declns
(
exports
,
globals
,
begin
,
d
,
base
)
declnlist
d
;
char
*
exports
,
*
globals
,
*
b
egin
,
*
bas
e
;
{
printf
(
"m2datadec: Making data declarations in %s.{def,mod}
\n
"
,
basename
);
printf
(
"m2datadec: Making data declarations in %s.{def,mod}
\n
"
,
base
);
defn_declns
(
exports
,
base
name
,
d
);
defn_declns
(
exports
,
base
,
d
);
impln_declns
(
globals
,
b
asenam
e
,
d
);
impln_declns
(
globals
,
b
egin
,
bas
e
,
d
);
}
/* ------------------------- PRIVATE PROCEDURES -------------------------- */
static
int
numtabs
=
0
;
static
FILE
*
outfile
;
#define indent() numtabs++
#define outdent() numtabs--
...
...
@@ -252,7 +251,7 @@ static void defn_onetype( d ) decln d;
/* ----------------------- Implementation module ------------------------- */
static
void
impln_declns
(
globals
,
modulename
,
decs
)
char
*
globals
,
*
modulename
;
declnlist
decs
;
static
void
impln_declns
(
globals
,
begin
,
modulename
,
decs
)
char
*
globals
,
*
begin
,
*
modulename
;
declnlist
decs
;
{
FILE
*
implnfile
;
char
tempname
[
256
];
...
...
@@ -330,6 +329,11 @@ static void impln_declns( globals, modulename, decs ) char *globals, *modulename
}
line
(
"BEGIN"
);
if
(
*
begin
!=
'\0'
)
{
line
(
"
\t
(* Contents of BEGIN section *)"
);
line
(
begin
);
}
line
(
"END %s."
,
modulename
);
fclose
(
implnfile
);
}
...
...
parser.c
View file @
2fc0bb95
...
...
@@ -12,6 +12,7 @@
*
* data = [ tEXPORT chunk ]
* [ tGLOBAL chunk ]
* [ tBEGIN chunk ]
* tTYPE tOPENCURLY declns tCLOSECURLY
* chunk = tOPENCURLY list_of_lines tCLOSECURLY
* declns = list*( decln ) tEOF
...
...
@@ -68,10 +69,11 @@ static BOOL parse_param();
/*
* data = [ tEXPORT tOPENCURLY crap_to_} ]
* [ tGLOBAL tOPENCURLY crap_to_} ]
* [ tBEGIN tOPENCURLY crap_to_} ]
* tTYPE tOPENCURLY declns tCLOSECURLY
*/
BOOL
parse_data
(
exports
,
globals
,
dp
)
char
*
exports
,
*
globals
;
declnlist
*
dp
;
BOOL
parse_data
(
exports
,
globals
,
begin
,
dp
)
char
*
exports
,
*
globals
,
*
begin
;
declnlist
*
dp
;
{
if
(
nexttok
()
==
tEXPORT
)
{
...
...
@@ -90,7 +92,17 @@ BOOL parse_data( exports, globals, dp ) char *exports, *globals; declnlist *dp;
*
globals
=
'\0'
;
ungettok
();
}
MUSTBE
(
tTYPE
,
"TYPE/EXPORT/GLOBAL expected"
);
if
(
nexttok
()
==
tBEGIN
)
{
if
(
!
parse_chunk
(
begin
)
)
return
FALSE
;
}
else
{
*
begin
=
'\0'
;
ungettok
();
}
MUSTBE
(
tTYPE
,
"TYPE/EXPORT/GLOBAL/BEGIN expected"
);
MUSTBE
(
tOPENCURLY
,
"{ expected"
);
if
(
!
parse_declns
(
dp
)
)
return
FALSE
;
MUSTBE
(
tCLOSECURLY
,
"{ expected"
);
...
...
parser.h
View file @
2fc0bb95
#ifdef HASPROTOS
extern
BOOL
parse_data
(
char
*
,
char
*
,
declnlist
*
);
extern
BOOL
parse_data
(
char
*
,
char
*
,
char
*
,
declnlist
*
);
#else
extern
BOOL
parse_data
();
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment