~ubuntu-branches/debian/sid/alpine/sid

1 by Asheesh Laroia
Import upstream version 0.82+dfsg
1
#if !defined(lint) && !defined(DOS)
1.1.8 by Asheesh Laroia
Import upstream version 2.02
2
static char rcsid[] = "$Id: helpindx.c 769 2007-10-24 00:15:40Z hubert@u.washington.edu $";
1 by Asheesh Laroia
Import upstream version 0.82+dfsg
3
#endif
4
5
/*
6
 * ========================================================================
7
 * Copyright 2006-2007 University of Washington
1.1.12 by Unit 193
Import upstream version 2.20+dfsg1
8
 * Copyright 2013-2015 Eduardo Chappa
1 by Asheesh Laroia
Import upstream version 0.82+dfsg
9
 *
10
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13
 *
14
 *     http://www.apache.org/licenses/LICENSE-2.0
15
 *
16
 * ========================================================================
17
 */
18
19
/*
20
 * very short, very specialized
21
 *
22
 *
23
 *
24
 */
25
26
#include "system.h"
27
28
#define	HELP_KEY_MAX	64		/* maximum length of a key */
29
30
struct hindx {
31
    char  key[HELP_KEY_MAX];		/* name of help section */
32
    long  offset;			/* where help text starts */
33
    short lines;			/* how many lines there are */
34
};
35
1.1.3 by Asheesh Laroia
Import upstream version 0.9999+dfsg
36
int
1 by Asheesh Laroia
Import upstream version 0.82+dfsg
37
main(int argc, char **argv)
38
{
39
    char *p, s[1024];
40
    long index;
41
    int  section, 
42
	 len, 
43
	 line,
44
	 i; 
45
    FILE *hp,
46
	 *hip,					/* help index ptr */
47
    	 *hhp;					/* help header ptr */
48
    struct hindx irec;
49
50
    if(argc < 4){
51
	fprintf(stderr,
52
		"usage: helpindx <help_file> <index_file> <header_file>\n");
53
	exit(-1);
54
    }
55
56
    if((hp = fopen(argv[1], "rb")) == NULL){	/* problems */
57
	perror(argv[1]);
58
        exit(-1);
59
    }
60
61
    if((hip = fopen(argv[2], "wb")) == NULL){	/* problems */
62
	perror(argv[2]);
63
        exit(-1);
64
    }
65
66
    if((hhp = fopen(argv[3], "w")) == NULL){	/* problems */
67
	perror(argv[3]);
68
        exit(-1);
69
    }
70
71
    fprintf(hhp,"/*\n * Alpine Help text header file\n */\n");
72
    fprintf(hhp,"\n#ifndef PITH_HELPTEXT_INCLUDED\n#define PITH_HELPTEXT_INCLUDED\n");
73
    fprintf(hhp,"\n#define\tHELP_KEY_MAX\t%d\n", HELP_KEY_MAX);
74
    fprintf(hhp,"\ntypedef\tshort\tHelpType;\n");
75
    fprintf(hhp,"\n#define\tNO_HELP\t(-1)\n");
76
    fprintf(hhp,"struct hindx {\n    char  key[HELP_KEY_MAX];");
77
    fprintf(hhp,"\t\t/* name of help section */\n");
78
    fprintf(hhp,"    long  offset;\t\t\t/* where help text starts */\n");
79
    fprintf(hhp,"    short lines;\t\t\t/* how many lines there are */\n");
80
    fprintf(hhp,"};\n\n\n/*\n * defs for help section titles\n */\n");
81
82
    index = 0L;
83
    line  = section = 0;
84
85
    while(fgets(s, sizeof(s) - 1, hp) != NULL){
86
	line++;
87
	len = strlen(s);
88
	if(s[0] == '='){			/* new section? */
89
	    i = 0;
90
	    while((s[i] == '=' || isspace((unsigned char)s[i])) && i < len)
91
		i++;
92
93
	    if(section)
94
	        fwrite(&irec, sizeof(struct hindx), 1, hip);
95
96
	    irec.offset = index + (long)i;	/* save where name starts */
97
	    irec.lines = 0;
98
	    p = &irec.key[0];			/* save name field */
99
	    while(!isspace((unsigned char)s[i]) && i < len)
100
		*p++ = s[i++];
101
	    *p = '\0';
102
	
103
	    if(irec.key[0] == '\0'){
104
		fprintf(stderr,"Invalid help line %d: %s", line, s);
105
		exit(-1);
106
	    }
107
	    else
108
	      fprintf(hhp, "#define\t%s\t%d\n", irec.key, section++);
109
110
	}
111
	else if(s[0] == '#' && section){
112
	    fprintf(stderr,"Comments not allowed in help text: line %d", line);
113
	    exit(-1);
114
	}
115
	else{
116
	    irec.lines++;
117
	}
118
	index += len;
119
    }
120
121
    if(section)				/* write last entry */
122
      fwrite(&irec, sizeof(struct hindx), 1, hip);
123
124
    fprintf(hhp, "#define\tLASTHELP\t%d\n", section);
125
126
    fprintf(hhp,"\n#endif /* PITH_HELPTEXT_INCLUDED */\n");
127
128
    fclose(hp);
129
    fclose(hip);
130
    fclose(hhp);
1.1.3 by Asheesh Laroia
Import upstream version 0.9999+dfsg
131
    exit(0);
1 by Asheesh Laroia
Import upstream version 0.82+dfsg
132
}