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