Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dthelp / parser / canon1 / helptag / special.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: special.c /main/3 1995/11/08 09:32:32 rswiston $ */
24 /****************************************************************************/
25 /*                                                                          */
26 /*   This program generates either one or both of two include files needed  */
27 /*   for other programs.                                                    */
28 /*                                                                          */
29 /*   For the portion of HP Tag/Vectra that transforms characters into       */
30 /*   their TeX equivalents, this program produces a file with entries that  */
31 /*   consist of a comment field and either a 0 or a string entry.  Within   */
32 /*   the comment field is the character's eight-bit character code plus     */
33 /*   the name of the character, as:                                         */
34 /*                                                                          */
35 /*       0: ^@  NUL                                                         */
36 /*       60: <                                                              */
37 /*       65: A                                                              */
38 /*      159: undefined                                                      */
39 /*      161: A   grave                                                      */
40 /*                                                                          */
41 /*   and so on.  The string entry is of the form:                           */
42 /*                                                                          */
43 /*     "\`A",                                                               */
44 /*     "\^A",                                                               */
45 /*    "{\bslash}",                                                          */
46 /*                                                                          */
47 /*   and so on.                                                             */
48 /*                                                                          */
49 /*   For the collating program used with indexing, this program produces a  */
50 /*   file with entries that consist of a comment field, a number            */
51 /*   representing the collating position of the character, a "handling"     */
52 /*   field, and the character code of the lowercase representation of       */
53 /*   those characters that also have uppercase representations.  The        */
54 /*   "handling" field is one of NORMAL, SPECIAL, or UNSUPP.  Here are       */
55 /*   examples showing the fields:                                           */
56 /*                                                                          */
57 /*   *  63: ?                               *  54, SPECIAL,  63,            */
58 /*   *  64: @                               *  55, SPECIAL,  64,            */
59 /*   *  65: A                               *  92, NORMAL,  97,             */
60 /*   * 161: A   grave                       *  94, NORMAL, 200,             */
61 /*   * 162: A   circumflex                  *  93, NORMAL, 192,             */
62 /*   * 200: a   grave                       *  86, NORMAL, 200,             */
63 /*                                                                          */
64 /*   The question mark has ROMAN8 character code 63.  Its collating         */
65 /*   position as defined for the indexing program is 54.  (That is, it      */
66 /*   collates just before the at-sign.)  It is given SPECIAL handling by    */
67 /*   the collating program.  Since it has no lowercase representation, the  */
68 /*   number in this position is the same as its ROMAN8 character code.      */
69 /*   The uppercase A has ROMAN8 character code 65.  Its collating position  */
70 /*   as defined for the indexing program is 92.  (That is, it collates      */
71 /*   just before A circumflex.)  It is given NORMAL handling by the         */
72 /*   collating program.  Its lowercase representation is 200, the same as   */
73 /*   lowercase a grave.                                                     */
74 /*                                                                          */
75 /*   The collating order for this program is specified in SPECIAL.H.  The   */
76 /*   collating order to be used by the indexing program can be changed by   */
77 /*   modifying SPECIAL.H and recompiling and rerunning this program.  For   */
78 /*   example, at the moment, two of the lines in SPECIAL.H are:             */
79 /*                                                                          */
80 /*    162, "A   circumflex",                  NORMAL, "\\^A", 192,          */
81 /*    161, "A   grave",                       NORMAL, "\\`A", 200,          */
82 /*                                                                          */
83 /*   Thus, A circumflex is specified to collate before A grave.  If this    */
84 /*   changes, and it is determined that A grave should collate first, it    */
85 /*   would be necessary only to switch the lines, so they look like this:   */
86 /*                                                                          */
87 /*    161, "A   grave",                       NORMAL, "\\`A", 200,          */
88 /*    162, "A   circumflex",                  NORMAL, "\\^A", 192,          */
89 /*                                                                          */
90 /*   In SPECIAL.H, only those characters that have ROMAN8 representations   */
91 /*   are listed.  The program generates the undefined positions in both     */
92 /*   outputs.                                                               */
93 /*                                                                          */
94 /*   To output only the include file for generating TeX characters, run     */
95 /*   this program with the "s" switch:                                      */
96 /*                                                                          */
97 /*     SPECIAL S > output_file_name                                         */
98 /*                                                                          */
99 /*   To output only the include file for generating the collating           */
100 /*   sequence, run this program with the "c" switch:                        */
101 /*                                                                          */
102 /*     SPECIAL C > output_file_name                                         */
103 /*                                                                          */
104 /*   To output both, run this program with the "b" switch, or with no       */
105 /*   specification:                                                         */
106 /*                                                                          */
107 /*     SPECIAL B > output_file_name                                         */
108 /*     SPECIAL > output_file_name                                           */
109 /*                                                                          */
110 /*   In all cases, if you specify no redirected file name, the output goes  */
111 /*   to the Vectra's screen.                                                */
112 /*                                                                          */
113 /****************************************************************************/
114
115 #define NORMAL  1
116 #define SPECIAL 2
117 #define UNSUPP  3
118
119 #define TRUE    1
120 #define FALSE   0
121
122 #include <stdio.h>
123 #include <stdlib.h>
124
125 typedef wchar_t M_WCHAR;
126
127 struct {
128   int charcode;
129   char *name ;
130   int handling;
131   char *texexpand ;
132   int lower;
133   } specials[] = {
134 #include "special.h"
135     } ;
136
137 #define NOSPECIALS sizeof(specials)/sizeof(specials[0])
138 #define NO8BITCHARS 256
139 int invert[NO8BITCHARS], emptycell;
140
141 main(argc, argv)
142 int argc;
143 char *argv[];
144 {
145 int i, both = FALSE, spec = FALSE, coll = FALSE, error = FALSE ;
146
147 if (argc < 3)
148     { /*  Either one argument or none; not more */
149     if (argc == 2)
150         {
151         if (!stricmp(argv[1], "b")) both = TRUE;
152         else if (!stricmp(argv[1], "s")) spec = TRUE;
153         else if (!stricmp(argv[1], "c")) coll = TRUE;
154         else error = TRUE;
155         }
156     else both = TRUE;
157     }
158 else error = TRUE;
159 if (error)
160     {
161     fprintf(stderr,"Usage: SPECIAL [b | s | c]\n");
162     exit (0);
163     }
164 for (i = 0 ; i < NOSPECIALS ; i++)
165 invert[specials[i].charcode] = i + 1;
166 if (both || spec)
167     {
168     printf("/* Char Name                        TeX Expansion */\n");     
169     printf("/*                                                */\n");     
170     for (i = 0 ; i < NO8BITCHARS ; i++)
171         {
172         if (invert[i])
173             {
174             printf("/* %3d: %-31s */ ", i, specials[invert[i] - 1].name) ;
175             if (specials[invert[i] - 1].texexpand)
176                 printf("\"%s\"", specials[invert[i] - 1].texexpand) ;
177             else putchar('0') ;
178             }
179         else printf("/* %3d: undefined                       */ 0", i) ;
180         if (i < NO8BITCHARS - 1) putchar(',') ;
181         putchar('\n') ;
182         }
183     }
184 if (both || coll)
185     {
186     printf(
187     "/*                                                             */\n");     
188     printf(
189     "/* Char Name                               Coll Status   Lower */\n");     
190     printf(
191     "/*                                                             */\n");     
192     for (i = 0, emptycell = NOSPECIALS + 1; i < NO8BITCHARS ; i++)
193         {
194         if (invert[i])
195             {
196             printf("/* %3d: %-31s */ %3d, ",
197               specials[invert[i] - 1].charcode,
198               specials[invert[i] - 1].name, invert[i]) ;
199             switch (specials[invert[i] - 1].handling)
200                 {
201                     case NORMAL:   
202                         printf("NORMAL,");
203                         break;
204                     case SPECIAL:   
205                         printf("SPECIAL,");
206                         break;
207                     case UNSUPP:   
208                         printf("UNSUPP,");
209                         break;
210                 }
211             if (specials[invert[i] - 1].lower)
212                 printf(" %3d", specials[invert[i] - 1].lower);
213             else    
214                 printf(" %3d", specials[invert[i] - 1].charcode);
215             }
216         else
217             printf(
218               "/* %3d: undefined                       */ %3d, UNSUPP, %3d",
219                    i,
220                    emptycell++,
221                    i) ;
222         if (i < NO8BITCHARS - 1) putchar(',') ;
223         putchar('\n') ;
224         }
225     }
226 return 0;
227 }