35
35
/* Number of levels to draw the fractal */
36
static int num_levels = 0 ;
36
static int num_levels = 4 ;
38
38
/* The definition of the fractal */
39
39
static int num_trans ;
40
40
static AffineTrans *affine ;
42
/* Flag telling us to keep executing the main loop */
43
static int continue_in_main_loop = 1;
42
45
/* the window title */
43
46
char window_title [ 80 ] ;
215
checkedFGets ( char *s, int size, FILE *stream )
217
if ( fgets ( s, size, stream ) == NULL ) {
218
fprintf ( stderr, "fgets failed\n");
219
exit ( EXIT_FAILURE );
211
224
void readConfigFile ( char *fnme )
213
226
FILE *fptr = fopen ( fnme, "rt" ) ;
215
char inputline [ 256 ] , *line ;
228
char inputline [ 256 ] ;
219
232
/* Read a header line */
220
line = fgets ( inputline, 256, fptr ) ;
233
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
222
235
/* Read a comment line */
223
line = fgets ( inputline, 256, fptr ) ;
236
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
225
238
/* Read the window title */
226
line = fgets ( inputline, 256, fptr ) ;
239
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
227
240
/* We assume here that this line will not exceed 79 characters plus a
228
241
newline (window_title is 80 characters long). That'll cause a buffer
229
242
overflow. For a simple program like this, though, we're letting it
232
245
sscanf ( inputline, "%[a-zA-Z0-9!@#$%^&*()+=/\\_-\" ]", window_title ) ;
234
247
/* Read a comment line */
235
line = fgets ( inputline, 256, fptr ) ;
248
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
237
250
/* Read the number of affine transformations */
238
line = fgets ( inputline, 256, fptr ) ;
251
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
239
252
sscanf ( inputline, "%d", &num_trans ) ;
241
254
affine = (AffineTrans *)malloc ( num_trans * sizeof(AffineTrans) ) ;
243
256
/* Read a comment line */
244
line = fgets ( inputline, 256, fptr ) ;
257
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
246
259
for ( i = 0; i < num_trans; i++ )
248
261
/* Read an affine transformation definition */
249
line = fgets ( inputline, 256, fptr ) ;
262
checkedFGets ( inputline, sizeof ( inputline ), fptr ) ;
250
263
sscanf ( inputline, "%lf %lf %lf %lf %lf %lf", &affine[i].a00, &affine[i].a01,
251
264
&affine[i].a10, &affine[i].a11, &affine[i].b0, &affine[i].b1 ) ;