Removed glib dependancy
[freeglut] / genfonts / genstroke.c
1 /*
2  * main.c
3  *
4  * A simple utility to generate the stroke fonts to be used in freeglut.
5  *
6  * Copyright (c) 1999-2000 by Pawel W. Olszta
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8  * Creation date: czw sty 06 19:42:30 CET 2000
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software")
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Sotware.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27
28
29 #ifdef HAVE_CONFIG_H
30     #include <config.h>
31 #endif
32
33 #include <string.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <assert.h>
37
38 /*
39  * Define the log domain
40  */
41 #undef   G_LOG_DOMAIN
42 #define  G_LOG_DOMAIN  "genstroke"
43
44 /*
45  * The alphabet we want to export.
46  */
47 char* g_Alphabet = " abcdefghijklmnopqrstuwvxyzABCDEFGHIJKLMNOPQRSTUWVXYZ0123456789`~!@#$%^&*()-_=+[{}];:,.<>/?\\\"";
48 int   g_AlphabetLength = 0;
49
50 /*
51  * All undefined characters will get replaced by this one:
52  */
53 char  g_NoChar = '*';
54
55 /*
56  * The stream we want to redirect our output to
57  */
58 FILE*  g_Output = NULL;
59
60 /*
61  * Our argv[0]
62  */
63 char *g_ProgName = "";
64
65 /*
66  * This function outputs the font file prologue
67  */
68 void OutputPrologue( char* fileName )
69 {
70     /*
71      * Output the copyright and permission notices:
72      */
73     fprintf( g_Output, "/*\n * %s\n *\n * This file has been automatically generated by the genfonts utility.\n *\n", fileName );
74     fprintf( g_Output, " * Copyright (c) 1999-2000 by Pawel W. Olszta\n * Written by Pawel W. Olszta, <olszta@sourceforge.net>\n * \n" );
75     fprintf( g_Output, " * Permission is hereby granted, free of charge, to any person obtaining a\n" );
76     fprintf( g_Output, " * copy of this software and associated documentation files (the \"Software\"),\n" );
77     fprintf( g_Output, " * to deal in the Software without restriction, including without limitation\n" );
78     fprintf( g_Output, " * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n" );
79     fprintf( g_Output, " * and/or sell copies of the Software, and to permit persons to whom the\n" );
80     fprintf( g_Output, " * Software is furnished to do so, subject to the following conditions:\n *\n" );
81     fprintf( g_Output, " * The above copyright notice and this permission notice shall be included\n" );
82     fprintf( g_Output, " * in all copies or substantial portions of the Sotware.\n *\n" );
83     fprintf( g_Output, " * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n" );
84     fprintf( g_Output, " * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n" );
85     fprintf( g_Output, " * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n" );
86     fprintf( g_Output, " * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n" );
87     fprintf( g_Output, " * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n" );
88     fprintf( g_Output, " * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n" );
89
90     /*
91      * The obvious include headers
92      */
93     fprintf( g_Output, "\n#ifdef HAVE_CONFIG_H\n#include \"config.h\"\n#endif\n\n#include \"../include/GL/freeglut.h\"\n#include \"../include/GL/freeglut_internal.h\"\n" );
94 }
95
96 /*
97  * This function outputs a font set
98  */
99 void OutputFont( char* freeglutFontName, char* fontName )
100 {
101     /*
102      * This is an easy one. I just have to write a parser for the SRC files
103      * and dump their contents to the output file. Expect this to be done
104      * this weekend. The output data should be organized just like the bitmap
105      * fonts data, as it shown to be good.
106      */
107 }
108
109 /*
110  * This function outputs the font file epilogue
111  */
112 void OutputEpilogue( void )
113 {
114     fprintf( g_Output, "/*** END OF FILE ***/\n" );
115 }
116
117 /*
118  * The main function processes the command line arguments
119  * and outputs all the fonts we need to have rasterized.
120  */
121 int main( int argc, char** argv )
122 {
123     char ourCharacter[ 2 ] = { 0, 0 };
124     char* outputFileName = NULL;
125     int i = 1;
126
127     g_ProgName = argv[0];
128
129     /*
130      * Initialize the alphabet's length
131      */
132     g_AlphabetLength = strlen( g_Alphabet );
133
134     /*
135      * Make sure that the no-character character is in the alphabet
136      */
137     ourCharacter[ 0 ] = g_NoChar;
138          
139     if( strstr( g_Alphabet, ourCharacter ) == NULL )
140     {
141         fprintf( stderr,
142                  "%s: the g_NoChar `%c' character not found in the alphabet `%s'\n",
143                  g_ProgName, g_NoChar, g_Alphabet );
144         exit( 1 );
145     }
146  
147     /*
148      * Define the default output file name
149      */
150     outputFileName = strdup( "freeglut_font_stroke.c" );
151
152     /*
153      * Process the command line arguments now. Command line arguments expected:
154      *
155      *      -file    <FILENAME>         -- the destination file name
156      */
157     while( i < argc )
158     {
159         /*
160          * See what the current token is
161          */
162         if( strcasecmp( argv[ i ], "-file" ) == 0 )
163         {
164             assert( (i + 1) < argc );
165             free( outputFileName );
166
167             /*
168              * The next token is expected to contain the destination file name
169              */
170             outputFileName = strdup( argv[ ++i ] );
171         }
172
173         /*
174          * Get to the next argument
175          */
176         i++;
177     }
178
179     /*
180      * Have the destination file opened
181      */
182     g_Output = fopen( outputFileName, "wt" );
183     assert( g_Output != NULL );
184
185     /*
186      * Output the file header first
187      */
188     OutputPrologue( outputFileName );
189
190     /*
191      * Output all of the fonts we want to output
192      */
193     OutputFont( "Roman",     "Roman.src"   );
194     OutputFont( "RomanMono", "Roman_M.src" );
195
196     /*
197      * Finally, have the file epilogue outputted
198      */
199     OutputEpilogue();
200
201     /*
202      * Close the output stream
203      */
204     fclose( g_Output );
205
206     /*
207      * Clean up all the rest of the mess
208      */
209     free( outputFileName );
210
211     /*
212      * Return successful!
213      */
214     return( EXIT_SUCCESS );
215 }
216
217 /*** END OF FILE ***/