summaryrefslogtreecommitdiff
path: root/indexing/glo+idxtex/glotex.c
blob: 1c5d1a55d4b9d3c85057567281222989c286b548 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* #module    GloTeX    "2-001"
 ***********************************************************************
 *                                                                     *
 * The software was developed at the Monsanto Company and is provided  *
 * "as-is".  Monsanto Company and the auther disclaim all warranties   *
 * on the software, including without limitation, all implied warran-  *
 * ties of merchantabilitiy and fitness.                               *
 *                                                                     *
 * This software does not contain any technical data or information    *
 * that is proprietary in nature.  It may be copied, modified, and     *
 * distributed on a non-profit basis and with the inclusion of this    *
 * notice.                                                             *
 *                                                                     *
 ***********************************************************************
 */
/*
 * Module Name:	GloTeX
 *
 * Author:	R L Aurbach	CR&DS MIS Group    17-Aug-1986
 *
 * Function:
 *	Main Line for the GloTeX program.  This program processes .glo files
 *	produced by LaTeX and generates files which will produce a properly
 *	formatted glossary, using definitions extracted from one or more
 *	glossary definition files.
 *
 * Modification History:
 *
 * Version     Initials	   Date		Description
 * ------------------------------------------------------------------------
 * 1-001	RLA	17-Aug-1986	Original Code
 * 1-001	RLA	25-Aug-1986	Improve handling of error when there
 *					  is no gdf file to process.
 * 2-001	F.H.	17-May-1991	converted to portable C
 */
/*
 * Module GloTeX - Module-Wide Data Description Section
 *
 * Include Files:
 */
#ifdef MSDOS
#include <stdlib.h>
#include <io.h>
#define F_OK		0	/* access(): File exists */
#else
#include <sys/file.h>
#endif
#include <stdio.h>
#include "GloDef.h"
/*
 * Module Definitions:
 */
/*
 * Global Declarations:
 */
#ifdef MSDOS
main(int argc, char *argv[]);
#else
main();
#endif
    STRING_PTR	    filelist = 0;   /* Listhead for glossary filespecs	*/
    NODE_PTR	    root = 0;	    /* Listhead for definitions		*/
    int		    flag = 0;	    /* /TOC options flag		*/
    char	    infile[256];    /* Input filespec string		*/
    STRING_PTR	    labels = 0;	    /* Listhead for labels		*/
/*
 * Static Declarations:
 */
/*
 * External References:
 */
#ifdef MSDOS
extern void Glo_Command(int argc, char *argv[]);
extern int Glo_Build_LabLst(void);
extern int Glo_Scan_File(STRING_PTR file);
extern int Glo_Report_Missing(void);
extern int Glo_Build_File(void);
#else
extern void Glo_Command();
extern int Glo_Build_LabLst();
extern int Glo_Scan_File();
extern int Glo_Report_Missing();
extern int Glo_Build_File();
#endif
/*
 * Functions Called:
 */
/*
 * Function GloTeX - Documentation Section
 *
 * Discussion:
 *	This is the main line of the GloTeX program.  
 *
 *	It reads the input file and creates from it a list of items to be 
 *	defined.  
 *
 *	It then reads one or more glossary definition files, searching for 
 *	definitions which match the items specified.  If it finds an item, it 
 *	copies the definition into an internal data structure and removes the 
 *	item from the list.  In this way, the first definition seen for an 
 *	item is always used.
 *
 *	Once the list of definition files is exhausted, the internal data
 *	structures hold a complete list of all definitions.  Any items remaining
 *	in the item list represent items for which no definitions were found.
 *	These are reported.
 *
 *	Finally, the internal data structures are used to build a text file
 *	which will be processed by LaTeX to generate the glossary.
 *
 * Calling Synopsis:
 *	$ GloTeX :== $Crl_Public:GloTeX
 *	$ GloTeX filespec [/STYLE:{ARTICLE | REPORT | SPECIAL}] 
 *			    [/GLOSSARY=(file1,file2,...)]
 *
 * Inputs:
 *	filespec    ->	Name of the input file to be processed.  The default
 *			filespec SYS$DISK:[].GLO is processed against this
 *			specification.  This is the file generated by LaTeX
 *			by the \makeglossary command.
 *
 *	/STYLE	    ->  The /STYLE qualifier indicates the type of document for
 *			which the glossary is to be generated.  Options are:
 *			    * ARTICLE - a standard LaTeX "article" documentstyle
 *			    * REPORT  - a standard LaTeX "report" or "book"
 *					documentstyle
 *			    * SPECIAL - any of the CR&DS special documentstyles
 *			If the qualifier is not specified, SPECIAL is assumed.
 *
 *	/GLOSSARY   ->	The /GLOSSARY qualifier defines one or more glossary 
 *			definition files.  Each value in the list is the file
 *			specification of a glossary definition file.  These
 *			files are the basis for the list of glossary files
 *			managed by the program.  
 *
 *			If using a document style which does not define the 
 *			\glossaryfile command (i.e., a standard LaTeX document
 *			style), then this qualifier is the only means 
 *			available to specify the files to be searched for 
 *			definitions.  
 *
 *			If using a CR&DS document style, then this qualifier 
 *			is used to specify definition files to be searched 
 *			before any specified by the \glossaryfile command.  
 *
 *			The qualifier is optional.  However, at least one 
 *			definition file must be specified to the program.
 *
 * Outputs:
 *	filespec    ->	The program produces an output file which is the 
 *			resultant filespec from processing .GLS as the primary
 *			file specification and the fully-qualified input 
 *			filespec as the default.
 *
 * Return Value:
 *	returns SUCCESS
 *
 * Global Data:
 *	All commonly-used data structures, such as the file list, the label 
 *	list, the node list, etc., are declared globally.
 *
 * Files Used:
 *	reads the specified input file and one or more glossary definition files
 *	as described above.  Produces an output file.
 *
 * Assumed Entry State:
 *	Called from DCL level
 *
 * Normal Exit State:
 *	Returns to DCL level
 *
 * Error Conditions:
 *	Error messages are generated for all errors.  Any significant ones
 *	cause the program to exit with an appropriate message.
 *
 * Algorithm:
 *	A. Process the command line.
 *	B. Process the input file.
 *	    1. Glossary label entries are placed on a list.
 *	    2. Glossary file entries are added to the file list.
 *	C. For each file in the file list,
 *	    1. Scan the glossary file for definitions which match a label in
 *	       the label list.
 *	    2. If found,
 *		a. Copy the definition to a node in the data structure.
 *	D. For any labels for which the definition was not found,
 *	    1. Report it.
 *	E. Generate the output file.
 *
 * Special Notes:
 *	none
 */
/*
 * Function GloTeX - Code Section
 */
main(argc,argv)
int argc;
char *argv[];
{
/*
 * Local Declarations
 */
  int		    status;
  STRING_PTR	    file;
/*
 * Module Body
 */
/* Process the command line.  The routine will exit on error */
  Glo_Command(argc, argv);
  (void)printf("\nGloTeX, the automatic glossary processor for LaTeX, version 1.0\n");
  if (argc < 2) {
    (void) printf("usage: glotex file [/STYLE={Article | Report | Special}] \\ \n");
    (void) printf("                   [/GLOSSARY=(def1[,def2[,...]])]\n");
    exit(1);
  }  
/*
 * Process the list of definitions referenced:
 *  Open the input file.
 *  For each entry record in the file,
 *      Build a label entry in the label list.
 *  For each file record in the file,
 *	Build a file entry in the file list.
 *  Close the input file.
 */
  status = Glo_Build_LabLst();
  if (!(status & TRUE)) {
    (void)printf("\nFatal error processing the input file...aborting\n");
    exit(1);
  }
  if (labels == 0) {
    (void)printf("\nFatal error.  No glossary entries found in the .glo file");
    (void)printf("...aborting\n");
    exit(1);
  }
/*
 * For each file in the file list,
 *  Scan the file for entries which match labels with label list entries.
 *  For each one, build a node containing the definition.
 */
  if (filelist == 0) {
    (void)Glo_Report_Missing();
    (void)printf("\nNo glossary definition files specified...aborting\n");
    exit(1);
  }
  file = filelist;
  while (file != 0) {
    status = Glo_Scan_File(file);
    if (!(status & TRUE)) {
      (void)printf("\nFatal error scanning glossary definition file...aborting\n");
      exit(1);
    }
    file = file->next;
  }
/*
 * Report all labels for which no definitions were found.
 *  Write the information to SYS$OUTPUT.
 *  Write the information to a glossary log file.
 */
  status = Glo_Report_Missing();
  if (!(status & TRUE)) {
    (void)printf("\nFatal error while reporting the list of undefined terms");
    (void)printf("...aborting\n");
    exit(1);
  }
/*
 * Generate a formatted output file containing the definitions.
 * The file format will be dependent on whether the glossary is being built
 *  for a LaTeX "article", a LaTeX "report" or "book", or a CR&DS defined
 *  documentstyle.
 */
  status = Glo_Build_File();
  if (!(status & TRUE))
    (void)printf("\nFatal error while building the output file\n");
  (void)printf("\nDone.\n");
}