summaryrefslogtreecommitdiff
path: root/payloads/libpayload/curses/PDCurses/doc/manext.c
blob: 4ce7cbf5722321d531bee6c97a5c788cb8a45e4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/***********************************************************************/
/* MANEXT - Extract manual pages from C source code.                   */
/***********************************************************************/
/*
 * MANEXT - A program to extract manual pages from C source code.
 * Copyright (C) 1991-1996 Mark Hessling
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * If you make modifications to this software that you feel increases
 * it usefulness for the rest of the community, please email the
 * changes, enhancements, bug fixes as well as any and all ideas to me.
 * This software is going to be maintained and enhanced as deemed
 * necessary by the community.
 *
 * Mark Hessling <mark@rexx.org>
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LINE 255

void display_info()
{
    fprintf(stderr, "\nMANEXT 1.03 Copyright (C) 1991-1996 Mark Hessling\n"
                    "All rights reserved.\n"
                    "MANEXT is distributed under the terms of the GNU\n"
                    "General Public License and comes with NO WARRANTY.\n"
                    "See the file COPYING for details.\n"
                    "\nUsage: manext sourcefile [...]\n\n");
}

int main(int argc, char **argv)
{
    char s[MAX_LINE + 1];       /* input line */
    int i;
    FILE *fp;

#ifdef __EMX__
    _wildcard(&argc, &argv);
#endif
    if (strcmp(argv[1], "-h") == 0)
    {
        display_info();
        exit(1);
    }

    for (i = 1; i < argc; i++)
    {
        if ((fp = fopen(argv[i], "r")) == NULL)
        {
            fprintf(stderr, "\nCould not open %s\n", argv[i]);
            continue;
        }

        while (!feof(fp))
        {
            if (fgets(s, (int)sizeof(s), fp) == NULL)
            {
                if (ferror(fp) != 0)
                {
                    fprintf(stderr, "*** Error reading %s.  Exiting.\n",
                            argv[i]);
                    exit(1);
                }

                break;
            }

            /* check for manual entry marker at beginning of line */

            if (strncmp(s, "/*man-start*", 12) != 0)
                continue;

            /* inner loop */

            for (;;)
            {
                /* read next line of manual entry */

                if (fgets(s, (int)sizeof(s), fp) == NULL)
                {
                    if (ferror(fp) != 0)
                    {
                        fprintf(stderr, "*** Error reading %s.  Exiting.\n",
                                argv[i]);
                        exit(1);
                    }

                    break;
                }

                /* check for end of entry marker */

                if (strncmp(s, "**man-end", 9) == 0)
                    break;

                printf("%s", s);
            }

            printf("\n\n-----------------------------------"
                   "---------------------------------------\n\n");
        }

        fclose(fp);
    }

    return 0;
}