Thread View: alt.sources.patches
1 messages
1 total messages
Started by Graham Stoney
Wed, 09 Sep 1992 08:48
c2man: generate man pages from C comments; patch v1.6 -> v1.7
Author: Graham Stoney
Date: Wed, 09 Sep 1992 08:48
Date: Wed, 09 Sep 1992 08:48
1183 lines
32928 bytes
32928 bytes
Archive-name: c2man/patch.1.6-1.7
Submitted-by: greyham@research.canon.oz.au
This official patch brings c2man v1.6 up to v1.7.
Time for another patch I reckon!. This one makes c2man cross-reference (or
group) all the files specified in any run, fixes a bug where a string constant
was being free'd after c2man had finished everything, and adds a few more
features.
See the CHANGES file for more details.
As before, any feedback, comments or tips are greatly appreciated.
Graham
*** 1.8 1992/08/31 05:03:31
--- CHANGES 1992/09/09 08:41:27
***************
*** 78,80 ****
--- 78,92 ----
Version 1.6:
Don't reduce pointer-to-pointers down to a single indirection level;
eg: "char **argv" got output as "char *argv". Ugh!.
+
+ Version 1.7:
+ Don't try to free a string constant right at the very end!.
+
+ Rename old -i option to -H, and add new -i option so user can specify
+ extra #include lines for the SYNOPSIS section, and prerequisites for .h
+ file compilation.
+
+ Work around Sun acc -E problem where .h files were ignored.
+
+ Semantic change: multiple input files all get cross-referenced in the
+ SEE ALSO section (or grouped together if -g or -G).
*** 1.11 1992/08/25 07:04:48
--- Makefile 1992/09/09 08:41:28
***************
*** 1,4 ****
! # $Id: Makefile,v 1.11 1992/08/25 07:04:48 greyham Exp $
#
# UNIX makefile for manual page generator
#
--- 1,4 ----
! # $Id: Makefile,v 1.12 1992/09/09 08:39:39 greyham Exp $
#
# UNIX makefile for manual page generator
#
***************
*** 47,53 ****
#CC=/usr/local/lang/acc
#WARN=
#BSD=-DBSD
! #CPP=gcc -E
# HPUX:
#DEFINES= -Aa -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_XOPEN_SOURCE \
--- 47,54 ----
#CC=/usr/local/lang/acc
#WARN=
#BSD=-DBSD
! #CPP=/usr/local/lang/acc -E
! #DEFINES=-DCPP_IGNORES_H_FILES
# HPUX:
#DEFINES= -Aa -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_XOPEN_SOURCE \
*** 1.7 1992/08/31 05:03:31
--- README 1992/09/09 08:41:26
***************
*** 1,4 ****
! This is c2man (Version 1.6), a program for generating Unix style manual pages
in nroff/troff -man format directly from ordinary comments embedded in C source
code. It owes a huge debt to the public domain program cproto, by Chin Huang,
from which much of the code is derived.
--- 1,4 ----
! This is c2man (Version 1.7), a program for generating Unix style manual pages
in nroff/troff -man format directly from ordinary comments embedded in C source
code. It owes a huge debt to the public domain program cproto, by Chin Huang,
from which much of the code is derived.
*** 1.9 1992/08/25 06:41:02
--- c2man.1 1992/09/09 08:41:27
***************
*** 1,4 ****
! .\" $Id: c2man.1,v 1.9 1992/08/25 06:41:02 greyham Exp $
.de EX \"Begin example
.ne 5
.if n .sp 1
--- 1,4 ----
! .\" $Id: c2man.1,v 1.10 1992/09/09 08:39:39 greyham Exp $
.de EX \"Begin example
.ne 5
.if n .sp 1
***************
*** 59,65 ****
.SH DESCRIPTION
.B c2man
reads C source code files in which comments have been strategically placed,
! and outputs a manual page for each function defined or declared (via
a prototype), and optionally each variable with global scope.
Function definitions may be in the old style or ANSI style.
If no
--- 59,65 ----
.SH DESCRIPTION
.B c2man
reads C source code files in which comments have been strategically placed,
! and outputs manual page(s) documenting each function defined or declared (via
a prototype), and optionally each variable with global scope.
Function definitions may be in the old style or ANSI style.
If no
***************
*** 87,93 ****
.so example.inc
.IE
.LP
! The manual page starts with a
.B NAME
section, listing the name(s) of the identifier(s) documented, along with a
terse description.
--- 87,93 ----
.so example.inc
.IE
.LP
! Each manual page starts with a
.B NAME
section, listing the name(s) of the identifier(s) documented, along with a
terse description.
***************
*** 167,174 ****
.LP
Finally, a
.B "SEE ALSO"
! section is generated, referencing all the other manual pages generated from
! the same source file, if any.
.LP
The
.BR RETURNS ,
--- 167,173 ----
.LP
Finally, a
.B "SEE ALSO"
! section is generated, referencing all the other manual pages generated, if any.
.LP
The
.BR RETURNS ,
***************
*** 292,298 ****
.B .c
or
.B .h
! files. If a
.B .h
file is written as a formal interface description when preparing an
interface spec,
--- 291,303 ----
.B .c
or
.B .h
! files.
! If the input is a header file, any files specified by
! .B \-i
! options are
! assumed to be prerequisites, and get parsed before the input file.
! .LP
! If a
.B .h
file is written as a formal interface description when preparing an
interface spec,
***************
*** 343,352 ****
functions).
.TP
.B \-g
! Group all info generated from the same file together into a single
page (ala ctype(3)), reading the terse description for the
.B NAME
! section from the first comment in the file. A link to
the output file is made for each identifier documented.
.TP
.BI \-G terse
--- 348,360 ----
functions).
.TP
.B \-g
! Group all the info generated together into a single
page (ala ctype(3)), reading the terse description for the
.B NAME
! section from the first comment in the file, where the description is preceded
! by a
! .RB `` \- '' and runs to the end of the line. If multiple files are specified,
! the first such suitable comment encountered is used. A link to
the output file is made for each identifier documented.
.TP
.BI \-G terse
***************
*** 354,366 ****
.BR \-g ,
but using the specified terse description rather than reading it from the
file.
.TP
! .BI \-i dirprefix
! Use
! .B dirprefix
! as a directory prefix when a
.B #include
! line is generated in the
.B SYNOPSIS
section.
.TP
--- 362,388 ----
.BR \-g ,
but using the specified terse description rather than reading it from the
file.
+ .LP
+ .BI \-i file
+ .LP
+ \fB\-i\fI\{"file"\}
.TP
! .BI \-i <file>
! Insert a
! .B #include
! line referencing the specified file in the
! .B SYNOPSIS
! section, using the ``<file>'' form by default.
! Any number of
! .B \-i
! options may be specified to build up a list of prerequisites.
! .TP
! .BI \-H header-path
! Prepend
! .B header-path
! to the name of the header file when an
.B #include
! line is automatically generated in the
.B SYNOPSIS
section.
.TP
***************
*** 476,486 ****
.LP
Comments aren't legal in some of the more obscure places that they
would be in 'C'.
- .LP
- Some cpp's (Sun's acc -E is one example) won't process .h files passed on
- the command line; so they shouldn't be used with
- .B c2man
- since it will appear to ignore them entirely.
.LP
Comment placement (particularly with respect to comma positioning) is more
the result of the author's personal style than of any defined logic.
--- 498,503 ----
*** 1.6 1992/08/31 05:03:31
--- c2man.c 1992/09/09 08:41:31
***************
*** 1,15 ****
! /* $Id: c2man.c,v 1.6 1992/08/31 05:03:31 greyham Exp $
*
! * C Manual page.
* Reads C source code and outputs manual pages.
*/
#ifndef lint
! static char *rcsid = "$Id: c2man.c,v 1.6 1992/08/31 05:03:31 greyham Exp $";
#endif
#include <stdio.h>
#include <ctype.h>
#include "c2man.h"
#include "strconcat.h"
/* getopt declarations */
extern int getopt();
--- 1,16 ----
! /* $Id: c2man.c,v 1.7 1992/09/09 08:39:39 greyham Exp $
*
! * C Manual page generator.
* Reads C source code and outputs manual pages.
*/
#ifndef lint
! static char *rcsid = "$Id: c2man.c,v 1.7 1992/09/09 08:39:39 greyham Exp $";
#endif
#include <stdio.h>
#include <ctype.h>
#include "c2man.h"
#include "strconcat.h"
+ #include "manpage.h"
/* getopt declarations */
extern int getopt();
***************
*** 58,65 ****
char *manual_name = NULL;
/* prefix for generated #include lines */
! char *include_prefix = NULL;
/* do we group related stuff into one file? */
boolean group_together;
--- 59,70 ----
char *manual_name = NULL;
/* prefix for generated #include lines */
! char *header_prefix = NULL;
+ /* list of include file specified by user */
+ IncludeFile *first_include;
+ static IncludeFile **last_next_include = &first_include;
+
/* do we group related stuff into one file? */
boolean group_together;
***************
*** 81,86 ****
--- 86,98 ----
/* total number of errors encountered */
int errors;
+ /* name of the base file being processed */
+ char *basefile;
+ boolean inbasefile; /* are we parsing in that base file? */
+
+ /* is the base file a header file? */
+ boolean header_file;
+
#ifdef CPP
char *cpp_cmd = CPP;
char *cpp_opts;
***************
*** 98,103 ****
--- 110,149 ----
fprintf(stderr, "%s:%d: ", cur_file, line_num);
}
+ /* write the #include lines as specified by the user */
+ void output_includes(FILE *f)
+ {
+ IncludeFile *incfile;
+
+ for (incfile = first_include; incfile; incfile=incfile->next)
+ {
+ char *name = incfile->name;
+ boolean surrounded = *name == '"' || *name == '<';
+
+ fputs("#include ", f);
+ if (!surrounded) fputc('<',f);
+ fputs(name, f);
+ if (!surrounded) fputc('>',f);
+ fputc('\n',f);
+ }
+ }
+
+ void outmem(void)
+ {
+ fprintf(stderr,"Out of memory!\n");
+ exit(1);
+ }
+
+ void *safe_malloc(size_t size)
+ {
+ void *mem;
+
+ if ((mem = malloc(size)) == NULL)
+ outmem();
+
+ return mem;
+ }
+
/* Replace any character escape sequences in a string with the actual
* characters. Return a pointer to malloc'ed memory containing the result.
* This function knows only a few escape sequences.
***************
*** 145,161 ****
fputs(" -p disable prototype promotion\n", stderr);
fputs(" -s output static declarations\n", stderr);
fputs(" -v output variable declarations\n", stderr);
! fputs(" -m nam set name of macro guarding prototypes\n", stderr);
! fputs(" -d omit prototype macro definition\n", stderr);
! fputs(" -i prefix specify prefix for #include in SYNOPSIS\n", stderr);
! fputs(" -G terse Group info from each file into a single page\n", stderr);
! fputs(" -M name set name of the manual in which the page goes\n", stderr);
fputs(" -D name[=value]\n", stderr);
fputs(" -U name\n", stderr);
fputs(" -I directory\n", stderr);
fputs(" C preprocessor options\n", stderr);
! fputs(" -F fmt set prototype template in the form \"int main (a, b)\"\n",
! stderr);
fputs(" -V be verbose and print version information\n", stderr);
exit(1);
}
--- 191,212 ----
fputs(" -p disable prototype promotion\n", stderr);
fputs(" -s output static declarations\n", stderr);
fputs(" -v output variable declarations\n", stderr);
! fputs(" -i includefile\n", stderr);
! fputs(" -i \"includefile\"\n", stderr);
! fputs(" -i <includefile>\n", stderr);
! fputs(" add #include for includefile to SYNOPSIS\n", stderr);
! fputs(" -H prefix\n",stderr);
! fputs(" specify prefix for #include in SYNOPSIS\n", stderr);
! fputs(" -G terse\n", stderr);
! fputs(" group info from each file into a single page\n", stderr);
! fputs(" -M name set name of the manual in which the page goes\n",
! stderr);
fputs(" -D name[=value]\n", stderr);
fputs(" -U name\n", stderr);
fputs(" -I directory\n", stderr);
fputs(" C preprocessor options\n", stderr);
! fputs(" -F fmt set prototype template in the form "
! "\"int main (a, b)\"\n",stderr);
fputs(" -V be verbose and print version information\n", stderr);
exit(1);
}
***************
*** 165,172 ****
#ifdef CPP
char *cmd = strconcat(cpp_cmd, " ", cpp_opts, NULL);
#endif
! strcpy(cur_file, name ? name : "stdin");
#ifdef CPP
if (name)
{
char *new_cmd = strconcat(cmd, " ", name, NULL);
--- 216,272 ----
#ifdef CPP
char *cmd = strconcat(cpp_cmd, " ", cpp_opts, NULL);
#endif
! boolean use_tmpfile = FALSE;
! char *period;
!
! header_file = name &&
! ((period = strrchr(name,'.')) && (!strcmp(period+1,"h")));
! basefile = name ? name : "stdin";
!
#ifdef CPP
+ /* should we do this via a temporary file? */
+ if (header_file
+ #ifndef CPP_IGNORES_H_FILES
+ && first_include
+ #endif
+ )
+ {
+ FILE *tmpfile;
+
+ use_tmpfile = TRUE;
+ if (verbose) fputs("preprocessing via temporary file:\n", stderr);
+
+ name = "c2mantmp0.c";
+ if ((tmpfile = fopen(name, "w")) == NULL)
+ {
+ fprintf(stderr,"%s: error opening temp file ");
+ perror(name);
+ free(cmd);
+ return 0;
+ }
+
+ output_includes(tmpfile);
+ if (verbose) output_includes(stderr);
+
+ fprintf(tmpfile,"#include \"%s\"\n", basefile);
+ if (verbose) fprintf(stderr,"#include \"%s\"\n", basefile);
+
+ if (fclose(tmpfile) == EOF)
+ {
+ fprintf(stderr,"%s: error closing temp file ");
+ perror(name);
+ free(cmd);
+ return 0;
+ }
+ inbasefile = 0;
+ strcpy(cur_file, name);
+ }
+ else
+ {
+ inbasefile = 1;
+ strcpy(cur_file, basefile);
+ }
+
if (name)
{
char *new_cmd = strconcat(cmd, " ", name, NULL);
***************
*** 178,187 ****
if ((yyin = popen(cmd, "r")) == NULL) {
fprintf(stderr, "%s: error running %s\n", progname, cmd);
return 0;
}
#else
! if (verbose) fprintf(stderr,"reading %s\n", cur_file);
if (name && freopen(name, "r", yyin) == NULL)
{
--- 278,288 ----
if ((yyin = popen(cmd, "r")) == NULL) {
fprintf(stderr, "%s: error running %s\n", progname, cmd);
+ free(cmd);
return 0;
}
#else
! if (verbose) fprintf(stderr,"reading %s\n", basefile);
if (name && freopen(name, "r", yyin) == NULL)
{
***************
*** 194,202 ****
--- 295,305 ----
#ifdef CPP
pclose(yyin);
free(cmd);
+ if (use_tmpfile) unlink(name); /* nuke temp file, if any */
#else
fclose(yyin);
#endif
+
return !errors;
}
***************
*** 207,212 ****
--- 310,316 ----
{
int i, c;
char *s, *new_opts, cbuf[2];
+ IncludeFile *includefile;
#ifdef YYDEBUG
extern int yydebug;
#endif
***************
*** 215,221 ****
cpp_opts = strconcat("-C", NULL);
#endif
/* Scan command line options. */
! while ((c = getopt(argc, argv, "D:F:I:psU:Vvo:M:i:G:g")) != EOF) {
switch (c) {
case 'I':
case 'D':
--- 319,325 ----
cpp_opts = strconcat("-C", NULL);
#endif
/* Scan command line options. */
! while ((c = getopt(argc, argv, "D:F:I:psU:Vvo:M:H:G:gi:")) != EOF) {
switch (c) {
case 'I':
case 'D':
***************
*** 295,302 ****
case 'M':
manual_name = optarg;
break;
case 'i':
! include_prefix = optarg;
break;
case '?':
default:
--- 399,413 ----
case 'M':
manual_name = optarg;
break;
+ case 'H':
+ header_prefix = optarg;
+ break;
case 'i':
! *last_next_include = includefile =
! safe_malloc(sizeof *includefile);
! includefile->name = optarg;
! includefile->next = NULL;
! last_next_include = &includefile->next;
break;
case '?':
default:
***************
*** 317,324 ****
for (i = optind; i < argc; ++i)
if (!process_file(argv[i])) break;
fclose(stdout); /* close last output file */
! free(cpp_cmd);
#ifdef MALLOC_DEBUG
wait(NULL);
--- 428,445 ----
for (i = optind; i < argc; ++i)
if (!process_file(argv[i])) break;
+ if (!errors) output_manual_pages(firstpage);
+ free_manual_pages(firstpage);
+
fclose(stdout); /* close last output file */
! free(cpp_opts);
!
! for (includefile = first_include; includefile;)
! {
! IncludeFile *next = includefile->next;
! free(includefile);
! includefile = next;
! }
#ifdef MALLOC_DEBUG
wait(NULL);
*** 1.4 1992/08/25 06:41:02
--- c2man.h 1992/09/09 08:41:30
***************
*** 1,7 ****
! /* $Id: c2man.h,v 1.4 1992/08/25 06:41:02 greyham Exp $
*
* Definitions for C language manual page generator
*/
#include "config.h"
#include "symbol.h"
--- 1,8 ----
! /* $Id: c2man.h,v 1.5 1992/09/09 08:39:39 greyham Exp $
*
* Definitions for C language manual page generator
*/
+ #include <stdio.h>
#include "config.h"
#include "symbol.h"
***************
*** 89,94 ****
--- 90,102 ----
boolean boolean;
} yystype;
+ /* include files specified by user */
+ typedef struct _includefile
+ {
+ char *name;
+ struct _includefile *next;
+ } IncludeFile;
+
#define YYSTYPE yystype
/* Program options */
***************
*** 101,107 ****
extern char *inc_dir[];
extern char *manual_name;
extern char *progname;
! extern char *include_prefix;
extern char *group_terse;
extern boolean group_together;
--- 109,116 ----
extern char *inc_dir[];
extern char *manual_name;
extern char *progname;
! extern char *header_prefix;
! extern IncludeFile *first_include;
extern char *group_terse;
extern boolean group_together;
***************
*** 112,117 ****
--- 121,129 ----
/* Global declarations */
extern int line_num;
extern char cur_file[];
+ extern char *basefile;
+ boolean inbasefile;
+ extern boolean header_file;
extern SymbolTable *typedef_names;
extern void output_error();
extern void parse_file();
***************
*** 122,126 ****
--- 134,139 ----
void *safe_malloc(size_t size);
void outmem(void);
+ void output_includes(FILE *f); /* write #include lines */
void yyerror (char *format, ...);
*** 1.3 1992/07/28 06:34:30
--- config.h 1992/09/09 08:41:29
***************
*** 1,4 ****
! /* $Id: config.h,v 1.3 1992/07/28 06:34:30 greyham Exp $
*
* c2man configuration and system dependencies
*/
--- 1,4 ----
! /* $Id: config.h,v 1.4 1992/09/09 08:39:39 greyham Exp $
*
* c2man configuration and system dependencies
*/
***************
*** 29,34 ****
--- 29,41 ----
#include <strings.h>
#define strchr index
#define strrchr rindex
+ #endif
+
+ #ifdef NeXT
+ #include <libc.h>
+ #undef ECHO /* lex generates ECHO */
+ #else
+ #include <unistd.h>
#endif
#ifndef MSDOS
*** 1.2 1992/08/25 06:41:02
--- enum.c 1992/09/09 08:41:33
***************
*** 1,4 ****
! /* $Id: enum.c,v 1.2 1992/08/25 06:41:02 greyham Exp $
* enumerator operations
*/
#include "c2man.h"
--- 1,4 ----
! /* $Id: enum.c,v 1.3 1992/09/09 08:39:39 greyham Exp $
* enumerator operations
*/
#include "c2man.h"
***************
*** 15,21 ****
* symbol, in which case it is referenced from the typedef_table or
* enum_table repectively more than once.
*/
! EnumeratorList *first_list, **last_next_list;
/* Initialize a list of enumerators.*/
EnumeratorList *
--- 15,21 ----
* symbol, in which case it is referenced from the typedef_table or
* enum_table repectively more than once.
*/
! EnumeratorList *first_list = NULL, **last_next_list = &first_list;
/* Initialize a list of enumerators.*/
EnumeratorList *
***************
*** 128,147 ****
return NULL;
}
! void create_enum_symbol_table(void)
{
- enum_table = create_symbol_table();
- first_list = NULL;
- last_next_list = &first_list;
- }
-
- void destroy_enum_symbol_table(void)
- {
EnumeratorList *list, *next;
! destroy_symbol_table(enum_table);
!
! /* now free all the enumerator lists */
for (list = first_list; list; list = next)
{
next = list->next;
--- 128,138 ----
return NULL;
}
! void destroy_enum_lists(void)
{
EnumeratorList *list, *next;
! /* free all the enumerator lists */
for (list = first_list; list; list = next)
{
next = list->next;
*** 1.1 1992/07/07 09:24:32
--- enum.h 1992/09/09 08:41:31
***************
*** 1,5 ****
! /* $Id: enum.h,v 1.1 1992/07/07 09:24:32 greyham Exp $ */
/* Initialize a list of enumerators.*/
EnumeratorList *
new_enumerator_list (Enumerator *enumerator);
--- 1,7 ----
! /* $Id: enum.h,v 1.2 1992/09/09 08:39:39 greyham Exp $ */
+ SymbolTable *enum_table; /* enum symbol table */
+
/* Initialize a list of enumerators.*/
EnumeratorList *
new_enumerator_list (Enumerator *enumerator);
***************
*** 30,37 ****
/* look for the first enumerator associated with the symbol */
EnumeratorList *find_enum_symbol(char *name);
! void create_enum_symbol_table(void);
! void destroy_enum_symbol_table(void);
/* create new typedef symbols */
void new_typedef_symbols(DeclSpec *decl_spec, DeclaratorList *decl_list);
--- 32,38 ----
/* look for the first enumerator associated with the symbol */
EnumeratorList *find_enum_symbol(char *name);
! void destroy_enum_lists(void);
/* create new typedef symbols */
void new_typedef_symbols(DeclSpec *decl_spec, DeclaratorList *decl_list);
*** 1.6 1992/08/31 05:06:03
--- grammar.y 1992/09/09 08:41:29
***************
*** 1,4 ****
! /* $Id: grammar.y,v 1.6 1992/08/31 05:06:03 greyham Exp $
*
* yacc grammar for C manual page generator
* This was derived from the grammar given in Appendix A of
--- 1,4 ----
! /* $Id: grammar.y,v 1.7 1992/09/09 08:39:39 greyham Exp $
*
* yacc grammar for C manual page generator
* This was derived from the grammar given in Appendix A of
***************
*** 88,95 ****
/* Table of typedef names */
SymbolTable *typedef_names;
- char *basefile; /* the name of the base file we are parsing */
- boolean inbasefile; /* are we parsing in that base file? */
boolean first_comment; /* are we still looking for the first comment? */
%}
%%
--- 88,93 ----
***************
*** 696,724 ****
{
char *s;
! basefile = strdup(cur_file);
! inbasefile = 1;
!
! if (strlen(cur_file) > 2) {
! s = cur_file + strlen(cur_file) - 2;
if (strcmp(s, ".l") == 0 || strcmp(s, ".y") == 0)
BEGIN LEXYACC;
}
typedef_names = create_symbol_table();
! create_enum_symbol_table();
line_num = 1;
ly_count = 0;
first_comment = group_together && !terse_specified;
yyparse();
- if (!errors) output_manual_pages(firstpage);
- free_manual_pages(firstpage);
-
- firstpage = NULL;
- lastpagenext = &firstpage;
! destroy_enum_symbol_table();
! destroy_symbol_table(typedef_names,NULL);
! free(basefile);
}
--- 694,714 ----
{
char *s;
! if (strlen(basefile) > 2) {
! s = basefile + strlen(basefile) - 2;
if (strcmp(s, ".l") == 0 || strcmp(s, ".y") == 0)
BEGIN LEXYACC;
}
typedef_names = create_symbol_table();
! enum_table = create_symbol_table();
!
line_num = 1;
ly_count = 0;
first_comment = group_together && !terse_specified;
yyparse();
! destroy_symbol_table(enum_table);
! destroy_symbol_table(typedef_names);
}
*** 1.7 1992/08/17 06:18:38
--- lex.l 1992/09/09 08:41:29
***************
*** 1,5 ****
%{
! /* $Id: lex.l,v 1.7 1992/08/17 06:18:38 greyham Exp $
*
* C manual page generator
* Lexical analyzer specification
--- 1,5 ----
%{
! /* $Id: lex.l,v 1.8 1992/09/09 08:39:39 greyham Exp $
*
* C manual page generator
* Lexical analyzer specification
***************
*** 89,99 ****
BEGIN INITIAL;
}
<CPP1>[0-9]+{WS}+\".*$ {
! char new_file[MAX_TEXT_LENGTH];
sscanf(yytext, "%d \"%[^\"]\"", &line_num,
new_file);
--line_num;
BEGIN INITIAL;
/* return BASEFILE token only when file changes */
if (strcmp(cur_file, new_file))
--- 89,105 ----
BEGIN INITIAL;
}
<CPP1>[0-9]+{WS}+\".*$ {
! char new_name[MAX_TEXT_LENGTH];
! char *new_file = new_name;
!
sscanf(yytext, "%d \"%[^\"]\"", &line_num,
new_file);
--line_num;
BEGIN INITIAL;
+
+ /* strip leading ./ that Sun acc prepends */
+ if (!strncmp(new_file,"./",2))
+ new_file += 2;
/* return BASEFILE token only when file changes */
if (strcmp(cur_file, new_file))
*** 1.10 1992/08/25 06:41:02
--- manpage.c 1992/09/09 08:41:32
***************
*** 1,4 ****
! /* $Id: manpage.c,v 1.10 1992/08/25 06:41:02 greyham Exp $
* stuff to do with manual page outputing
*/
--- 1,4 ----
! /* $Id: manpage.c,v 1.11 1992/09/09 08:39:39 greyham Exp $
* stuff to do with manual page outputing
*/
***************
*** 8,18 ****
#include <errno.h>
#include <time.h>
#include <stdlib.h>
- #ifdef NeXT
- #include <libc.h>
- #else
- #include <unistd.h>
- #endif
#include <ctype.h>
#include "c2man.h"
#include "manpage.h"
--- 8,13 ----
***************
*** 25,66 ****
ManualPage *firstpage = NULL;
ManualPage **lastpagenext = &firstpage;
- void outmem(void)
- {
- fprintf(stderr,"Out of memory!\n");
- exit(1);
- }
-
- void *safe_malloc(size_t size)
- {
- void *mem;
-
- if ((mem = malloc(size)) == NULL)
- outmem();
-
- return mem;
- }
-
- /* says if cur_file is a header file */
- boolean header_file()
- {
- char *period;
-
- return ((period = strrchr(cur_file,'.')) && (!strcmp(period+1,"h")));
- }
-
void
new_manual_page(char *comment, DeclSpec *decl_spec, Declarator *declarator)
{
ManualPage *newpage;
! extern int inbasefile;
!
/* check that we really want a man page for this */
if ((!comment) ||
!inbasefile ||
(!variables_out && declarator->func_def == FUNC_NONE) ||
(decl_spec->flags & DE_JUNK) ||
! (!static_out && (decl_spec->flags & DE_STATIC) && !header_file()))
{
free_decl_spec(decl_spec);
free_declarator(declarator);
--- 20,36 ----
ManualPage *firstpage = NULL;
ManualPage **lastpagenext = &firstpage;
void
new_manual_page(char *comment, DeclSpec *decl_spec, Declarator *declarator)
{
ManualPage *newpage;
!
/* check that we really want a man page for this */
if ((!comment) ||
!inbasefile ||
(!variables_out && declarator->func_def == FUNC_NONE) ||
(decl_spec->flags & DE_JUNK) ||
! (!static_out && (decl_spec->flags & DE_STATIC) && !header_file))
{
free_decl_spec(decl_spec);
free_declarator(declarator);
***************
*** 133,141 ****
/* remember the terse description from the first comment in a file */
void remember_terse(char *comment)
{
! char *c = strchr(comment,'-');
! if (c)
{
while (*c == '-')
c++;
--- 103,112 ----
/* remember the terse description from the first comment in a file */
void remember_terse(char *comment)
{
! char *c;
! /* only remember it the first time though */
! if (!group_terse && (c = strchr(comment,'-')))
{
while (*c == '-')
c++;
***************
*** 413,419 ****
return
(first->decl_spec.flags == second->decl_spec.flags &&
!strcmp(first->decl_spec.text, second->decl_spec.text) &&
- first->decl_spec.enum_list == second->decl_spec.enum_list &&
((!first->declarator.text && !second->declarator.text) ||
(first->declarator.text && second->declarator.text &&
!strcmp(first->declarator.text, second->declarator.text))
--- 384,389 ----
***************
*** 527,536 ****
if (grouped)
{
! char *c, *last = strrchr(cur_file, '.');
/* use the file name as the manual page name */
! for (c = cur_file; *c && c != last;c++)
putchar(*c);
}
else
--- 497,506 ----
if (grouped)
{
! char *c, *last = strrchr(basefile, '.');
/* use the file name as the manual page name */
! for (c = basefile; *c && c != last;c++)
putchar(*c);
}
else
***************
*** 543,551 ****
#ifdef HENRY /* As per Henry Spencer's "How to write a manual page" */
if (manual_name) printf(" \"%s\"", manual_name);
putchar('\n');
! printf(".BY \"%s %s\"\n",progname, cur_file);
#else /* How Sun and NeXT seem to do it */
! printf(" \"%s %s\"",progname, cur_file);
if (manual_name) printf(" \"%s\"", manual_name);
putchar('\n');
#endif
--- 513,521 ----
#ifdef HENRY /* As per Henry Spencer's "How to write a manual page" */
if (manual_name) printf(" \"%s\"", manual_name);
putchar('\n');
! printf(".BY \"%s %s\"\n",progname, basefile);
#else /* How Sun and NeXT seem to do it */
! printf(" \"%s %s\"",progname, basefile);
if (manual_name) printf(" \"%s\"", manual_name);
putchar('\n');
#endif
***************
*** 578,593 ****
put_string(".ft B\n");
/* if it's a header file, say to #include it */
! if (header_file())
{
put_string("#include <");
! if (include_prefix) printf("%s/", include_prefix);
! printf("%s>\n\n",cur_file);
}
for (page = firstpage; page; page = page->next)
{
output_format_string(decl_spec_prefix);
/* make sure variables are prefixed extern */
--- 548,567 ----
put_string(".ft B\n");
+ /* list the include files the user asked us to */
+ output_includes(stdout);
+
/* if it's a header file, say to #include it */
! if (header_file)
{
put_string("#include <");
! if (header_prefix) printf("%s/", header_prefix);
! printf("%s>\n",basefile);
}
for (page = firstpage; page; page = page->next)
{
+ put_string(".LP\n");
output_format_string(decl_spec_prefix);
/* make sure variables are prefixed extern */
***************
*** 603,615 ****
output_declarator(page->declarator,
page->declarator->params.first != page->declarator->params.last);
! put_string(";");
if (!grouped) break;
- if (page->next) put_string("\n\n");
}
! put_string("\n.ft R\n");
/* only output paramaters if there actually are some,
* not including merely (void)
--- 577,588 ----
output_declarator(page->declarator,
page->declarator->params.first != page->declarator->params.last);
! put_string(";\n");
if (!grouped) break;
}
! put_string(".ft R\n");
/* only output paramaters if there actually are some,
* not including merely (void)
***************
*** 706,714 ****
char *filename = NULL;
/* stat the file to check the relevant date */
! if (stat(cur_file,&statbuf) != 0)
{
! perror(cur_file);
exit(-1);
}
--- 679,687 ----
char *filename = NULL;
/* stat the file to check the relevant date */
! if (stat(basefile,&statbuf) != 0)
{
! perror(basefile);
exit(-1);
}
--
Graham Stoney. Ph: +61-2-805-2909. Totally unrelated message follows:
Since 1900, there are 23 known cases of innocent people being put to death in
the USA; but since the execution ends any effort to investigate possible
misscarriages of justice, the real figure is certainly much higher.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads