* Copyright (c) 1983 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)makedefs.c 5.5 (Berkeley) %G%";
* Create a definitions file (e.g. .h) from an implementation file (e.g. .c).
* Usage is "makedefs source.c source.h" where source.h is to be created.
* Lines beginning with "public" or within a "#ifndef public ... #endif"
* block are copied to the new file. Initializations (e.g. "int x = 3") are
* omitted ("int x;" is output).
* Normally a temporary definitions file is created and compared to
* the given destination. If they are different, the temporary file
* is copied on top of the destination. This is so that dependencies
* when using "make" are not triggered.
* The "-f" option overrides this and forces the destination file to be created.
#define streqn(s1, s2, n) (strncmp(s1, s2, n) == 0)
if (streq(argv
[1], "-f")) {
fatal("usage: makedefs [ -f ] file.c [ file.h ]\n");
if (freopen(argv
[index
], "r", stdin
) == NULL
) {
fatal("can't read %s", argv
[index
]);
tmpname
= argv
[index
+ 1];
tmpname
= mktemp(_PATH_TMP
);
tmp
= freopen(tmpname
, "w", stdout
);
fatal("can't write %s", tmpname
);
name
= modulename(argv
[index
]);
printf("#ifndef %s\n", name
);
printf("#define %s\n", name
);
if (tmp
!= NULL
and not force
) {
r
= call("cmp", stdin
, stderr
, "-s", tmpname
, argv
[2], nil
);
r
= call("cp", stdin
, stderr
, tmpname
, argv
[2], nil
);
fprintf(stderr
, "can't create %s\n", argv
[2]);
if (j
> i
&& *--j
== 'c') {
while (gets(line
) != NULL
) {
if (streqn(line
, "#ifndef public", 14)) {
} else if (streqn(line
, "public", 6)) {
if (streqn(line
, "#ifdef", 6) or streqn(line
, "#ifndef", 7)) {
} else if (streqn(line
, "#endif", 6)) {
streqn(line
, "#ifdef", 6) or
streqn(line
, "#ifndef", 7) or
streqn(line
, "#else", 5) or
streqn(line
, "#endif", 6)
for (p
= &s
[7]; *p
!= '\0' and *p
!= '='; p
++) {
} else if (*p
== ')' and isproc
and *(p
+1) == '\0') {
if (isproc
or *p
== '=') {
* No special error recovery strategy.