blob: a62a944b75f9264c3191e3b3006ff6dceecc2512 [file] [log] [blame]
Patrick Georgi3b77b722011-07-07 15:41:53 +02001/***********************************************************************/
2/* MANEXT - Extract manual pages from C source code. */
3/***********************************************************************/
4/*
5 * MANEXT - A program to extract manual pages from C source code.
6 * Copyright (C) 1991-1996 Mark Hessling
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * If you make modifications to this software that you feel increases
19 * it usefulness for the rest of the community, please email the
20 * changes, enhancements, bug fixes as well as any and all ideas to me.
21 * This software is going to be maintained and enhanced as deemed
22 * necessary by the community.
23 *
24 * Mark Hessling <mark@rexx.org>
25 */
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30
31#define MAX_LINE 255
32
Elyes Haouas37ccd232023-08-25 18:51:45 +020033void display_info(void)
Patrick Georgi3b77b722011-07-07 15:41:53 +020034{
35 fprintf(stderr, "\nMANEXT 1.03 Copyright (C) 1991-1996 Mark Hessling\n"
36 "All rights reserved.\n"
37 "MANEXT is distributed under the terms of the GNU\n"
38 "General Public License and comes with NO WARRANTY.\n"
39 "See the file COPYING for details.\n"
40 "\nUsage: manext sourcefile [...]\n\n");
41}
42
43int main(int argc, char **argv)
44{
45 char s[MAX_LINE + 1]; /* input line */
46 int i;
47 FILE *fp;
48
49#ifdef __EMX__
50 _wildcard(&argc, &argv);
51#endif
52 if (strcmp(argv[1], "-h") == 0)
53 {
54 display_info();
55 exit(1);
56 }
57
58 for (i = 1; i < argc; i++)
59 {
60 if ((fp = fopen(argv[i], "r")) == NULL)
61 {
62 fprintf(stderr, "\nCould not open %s\n", argv[i]);
63 continue;
64 }
65
66 while (!feof(fp))
67 {
68 if (fgets(s, (int)sizeof(s), fp) == NULL)
69 {
70 if (ferror(fp) != 0)
71 {
72 fprintf(stderr, "*** Error reading %s. Exiting.\n",
73 argv[i]);
74 exit(1);
75 }
76
77 break;
78 }
79
80 /* check for manual entry marker at beginning of line */
81
82 if (strncmp(s, "/*man-start*", 12) != 0)
83 continue;
84
85 /* inner loop */
86
87 for (;;)
88 {
89 /* read next line of manual entry */
90
91 if (fgets(s, (int)sizeof(s), fp) == NULL)
92 {
93 if (ferror(fp) != 0)
94 {
95 fprintf(stderr, "*** Error reading %s. Exiting.\n",
96 argv[i]);
97 exit(1);
98 }
99
100 break;
101 }
102
103 /* check for end of entry marker */
104
105 if (strncmp(s, "**man-end", 9) == 0)
106 break;
107
108 printf("%s", s);
109 }
110
111 printf("\n\n-----------------------------------"
112 "---------------------------------------\n\n");
113 }
114
115 fclose(fp);
116 }
117
118 return 0;
119}