Deleted Added
full compact
misc.c (8874) misc.c (16519)
1/* misc - miscellaneous flex routines */
2
3/*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Vern Paxson.
1/* misc - miscellaneous flex routines */
2
3/*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Vern Paxson.
9 *
9 *
10 * The United States Government has rights in this work pursuant
11 * to contract no. DE-AC03-76SF00098 between the United States
12 * Department of Energy and the University of California.
13 *
14 * Redistribution and use in source and binary forms are permitted provided
15 * that: (1) source distributions retain this entire copyright notice and
16 * comment, and (2) distributions including binaries display the following
17 * acknowledgement: ``This product includes software developed by the
18 * University of California, Berkeley and its contributors'' in the
19 * documentation or other materials provided with the distribution and in
20 * all advertising materials mentioning features or use of this software.
21 * Neither the name of the University nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 */
28
10 * The United States Government has rights in this work pursuant
11 * to contract no. DE-AC03-76SF00098 between the United States
12 * Department of Energy and the University of California.
13 *
14 * Redistribution and use in source and binary forms are permitted provided
15 * that: (1) source distributions retain this entire copyright notice and
16 * comment, and (2) distributions including binaries display the following
17 * acknowledgement: ``This product includes software developed by the
18 * University of California, Berkeley and its contributors'' in the
19 * documentation or other materials provided with the distribution and in
20 * all advertising materials mentioning features or use of this software.
21 * Neither the name of the University nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 */
28
29/* $Header: /home/ncvs/src/usr.bin/lex/misc.c,v 1.1.1.1 1994/08/24 13:10:32 csgr Exp $ */
29/* $Header: /home/ncvs/src/usr.bin/lex/misc.c,v 1.1.1.2 1996/06/19 20:26:19 nate Exp $ */
30
31#include "flexdef.h"
32
33
30
31#include "flexdef.h"
32
33
34void action_define( defname, value )
35char *defname;
36int value;
37 {
38 char buf[MAXLINE];
34
39
35/* declare functions that have forward references */
40 if ( (int) strlen( defname ) > MAXLINE / 2 )
41 {
42 format_pinpoint_message( _( "name \"%s\" ridiculously long" ),
43 defname );
44 return;
45 }
36
46
37void dataflush PROTO((void));
38int otoi PROTO((Char []));
47 sprintf( buf, "#define %s %d\n", defname, value );
48 add_action( buf );
49 }
39
40
41void add_action( new_text )
42char *new_text;
43 {
44 int len = strlen( new_text );
45
46 while ( len + action_index >= action_size - 10 /* slop */ )
47 {
50
51
52void add_action( new_text )
53char *new_text;
54 {
55 int len = strlen( new_text );
56
57 while ( len + action_index >= action_size - 10 /* slop */ )
58 {
48 action_size *= 2;
59 int new_size = action_size * 2;
60
61 if ( new_size <= 0 )
62 /* Increase just a little, to try to avoid overflow
63 * on 16-bit machines.
64 */
65 action_size += action_size / 8;
66 else
67 action_size = new_size;
68
49 action_array =
50 reallocate_character_array( action_array, action_size );
51 }
52
53 strcpy( &action_array[action_index], new_text );
54
55 action_index += len;
56 }
57
58
59/* allocate_array - allocate memory for an integer array of the given size */
60
61void *allocate_array( size, element_size )
69 action_array =
70 reallocate_character_array( action_array, action_size );
71 }
72
73 strcpy( &action_array[action_index], new_text );
74
75 action_index += len;
76 }
77
78
79/* allocate_array - allocate memory for an integer array of the given size */
80
81void *allocate_array( size, element_size )
62int size, element_size;
82int size;
83size_t element_size;
63 {
64 register void *mem;
84 {
85 register void *mem;
86 size_t num_bytes = element_size * size;
65
87
66 /* On 16-bit int machines (e.g., 80286) we might be trying to
67 * allocate more than a signed int can hold, and that won't
68 * work. Cheap test:
69 */
70 if ( element_size * size <= 0 )
71 flexfatal( "request for < 1 byte in allocate_array()" );
88 mem = flex_alloc( num_bytes );
89 if ( ! mem )
90 flexfatal(
91 _( "memory allocation failed in allocate_array()" ) );
72
92
73 mem = flex_alloc( element_size * size );
74
75 if ( mem == NULL )
76 flexfatal( "memory allocation failed in allocate_array()" );
77
78 return mem;
79 }
80
81
82/* all_lower - true if a string is all lower-case */
83
84int all_lower( str )
85register char *str;

--- 60 unchanged lines hidden (view full) ---

146 * we're expecting. If not, generates fatal error message
147 * and exits.
148 */
149
150void check_char( c )
151int c;
152 {
153 if ( c >= CSIZE )
93 return mem;
94 }
95
96
97/* all_lower - true if a string is all lower-case */
98
99int all_lower( str )
100register char *str;

--- 60 unchanged lines hidden (view full) ---

161 * we're expecting. If not, generates fatal error message
162 * and exits.
163 */
164
165void check_char( c )
166int c;
167 {
168 if ( c >= CSIZE )
154 lerrsf( "bad character '%s' detected in check_char()",
169 lerrsf( _( "bad character '%s' detected in check_char()" ),
155 readable_form( c ) );
156
157 if ( c >= csize )
170 readable_form( c ) );
171
172 if ( c >= csize )
158 lerrsf( "scanner requires -8 flag to use the character '%s'",
173 lerrsf(
174 _( "scanner requires -8 flag to use the character %s" ),
159 readable_form( c ) );
160 }
161
162
163
164/* clower - replace upper-case letter to lower-case */
165
166Char clower( c )
167register int c;
168 {
169 return (Char) ((isascii( c ) && isupper( c )) ? tolower( c ) : c);
170 }
171
172
173/* copy_string - returns a dynamically allocated copy of a string */
174
175char *copy_string( str )
175 readable_form( c ) );
176 }
177
178
179
180/* clower - replace upper-case letter to lower-case */
181
182Char clower( c )
183register int c;
184 {
185 return (Char) ((isascii( c ) && isupper( c )) ? tolower( c ) : c);
186 }
187
188
189/* copy_string - returns a dynamically allocated copy of a string */
190
191char *copy_string( str )
176register char *str;
192register const char *str;
177 {
193 {
178 register char *c;
194 register const char *c1;
195 register char *c2;
179 char *copy;
196 char *copy;
197 unsigned int size;
180
181 /* find length */
198
199 /* find length */
182 for ( c = str; *c; ++c )
200 for ( c1 = str; *c1; ++c1 )
183 ;
184
201 ;
202
185 copy = (char *) flex_alloc( (c - str + 1) * sizeof( char ) );
203 size = (c1 - str + 1) * sizeof( char );
204 copy = (char *) flex_alloc( size );
186
187 if ( copy == NULL )
205
206 if ( copy == NULL )
188 flexfatal( "dynamic memory failure in copy_string()" );
207 flexfatal( _( "dynamic memory failure in copy_string()" ) );
189
208
190 for ( c = copy; (*c++ = *str++); )
209 for ( c2 = copy; (*c2++ = *str++) != 0; )
191 ;
192
193 return copy;
194 }
195
196
197/* copy_unsigned_string -
198 * returns a dynamically allocated copy of a (potentially) unsigned string

--- 6 unchanged lines hidden (view full) ---

205 Char *copy;
206
207 /* find length */
208 for ( c = str; *c; ++c )
209 ;
210
211 copy = allocate_Character_array( c - str + 1 );
212
210 ;
211
212 return copy;
213 }
214
215
216/* copy_unsigned_string -
217 * returns a dynamically allocated copy of a (potentially) unsigned string

--- 6 unchanged lines hidden (view full) ---

224 Char *copy;
225
226 /* find length */
227 for ( c = str; *c; ++c )
228 ;
229
230 copy = allocate_Character_array( c - str + 1 );
231
213 for ( c = copy; (*c++ = *str++); )
232 for ( c = copy; (*c++ = *str++) != 0; )
214 ;
215
216 return copy;
217 }
218
219
220/* cshell - shell sort a character array in increasing order
221 *

--- 48 unchanged lines hidden (view full) ---

270/* dataend - finish up a block of data declarations */
271
272void dataend()
273 {
274 if ( datapos > 0 )
275 dataflush();
276
277 /* add terminator for initialization; { for vi */
233 ;
234
235 return copy;
236 }
237
238
239/* cshell - shell sort a character array in increasing order
240 *

--- 48 unchanged lines hidden (view full) ---

289/* dataend - finish up a block of data declarations */
290
291void dataend()
292 {
293 if ( datapos > 0 )
294 dataflush();
295
296 /* add terminator for initialization; { for vi */
278 puts( " } ;\n" );
297 outn( " } ;\n" );
279
280 dataline = 0;
281 datapos = 0;
282 }
283
284
285/* dataflush - flush generated data statements */
286
287void dataflush()
288 {
298
299 dataline = 0;
300 datapos = 0;
301 }
302
303
304/* dataflush - flush generated data statements */
305
306void dataflush()
307 {
289 putchar( '\n' );
308 outc( '\n' );
290
291 if ( ++dataline >= NUMDATALINES )
292 {
293 /* Put out a blank line so that the table is grouped into
294 * large blocks that enable the user to find elements easily.
295 */
309
310 if ( ++dataline >= NUMDATALINES )
311 {
312 /* Put out a blank line so that the table is grouped into
313 * large blocks that enable the user to find elements easily.
314 */
296 putchar( '\n' );
315 outc( '\n' );
297 dataline = 0;
298 }
299
300 /* Reset the number of characters written on the current line. */
301 datapos = 0;
302 }
303
304
305/* flexerror - report an error message and terminate */
306
307void flexerror( msg )
316 dataline = 0;
317 }
318
319 /* Reset the number of characters written on the current line. */
320 datapos = 0;
321 }
322
323
324/* flexerror - report an error message and terminate */
325
326void flexerror( msg )
308char msg[];
327const char msg[];
309 {
310 fprintf( stderr, "%s: %s\n", program_name, msg );
311 flexend( 1 );
312 }
313
314
315/* flexfatal - report a fatal error message and terminate */
316
317void flexfatal( msg )
328 {
329 fprintf( stderr, "%s: %s\n", program_name, msg );
330 flexend( 1 );
331 }
332
333
334/* flexfatal - report a fatal error message and terminate */
335
336void flexfatal( msg )
318char msg[];
337const char msg[];
319 {
338 {
320 fprintf( stderr, "%s: fatal internal error, %s\n", program_name, msg );
339 fprintf( stderr, _( "%s: fatal internal error, %s\n" ),
340 program_name, msg );
321 exit( 1 );
322 }
323
324
341 exit( 1 );
342 }
343
344
345/* htoi - convert a hexadecimal digit string to an integer value */
346
347int htoi( str )
348Char str[];
349 {
350 unsigned int result;
351
352 (void) sscanf( (char *) str, "%x", &result );
353
354 return result;
355 }
356
357
325/* lerrif - report an error message formatted with one integer argument */
326
327void lerrif( msg, arg )
358/* lerrif - report an error message formatted with one integer argument */
359
360void lerrif( msg, arg )
328char msg[];
361const char msg[];
329int arg;
330 {
331 char errmsg[MAXLINE];
332 (void) sprintf( errmsg, msg, arg );
333 flexerror( errmsg );
334 }
335
336
337/* lerrsf - report an error message formatted with one string argument */
338
339void lerrsf( msg, arg )
362int arg;
363 {
364 char errmsg[MAXLINE];
365 (void) sprintf( errmsg, msg, arg );
366 flexerror( errmsg );
367 }
368
369
370/* lerrsf - report an error message formatted with one string argument */
371
372void lerrsf( msg, arg )
340char msg[], arg[];
373const char msg[], arg[];
341 {
342 char errmsg[MAXLINE];
343
344 (void) sprintf( errmsg, msg, arg );
345 flexerror( errmsg );
346 }
347
348
374 {
375 char errmsg[MAXLINE];
376
377 (void) sprintf( errmsg, msg, arg );
378 flexerror( errmsg );
379 }
380
381
349/* htoi - convert a hexadecimal digit string to an integer value */
382/* line_directive_out - spit out a "#line" statement */
350
383
351int htoi( str )
352Char str[];
384void line_directive_out( output_file, do_infile )
385FILE *output_file;
386int do_infile;
353 {
387 {
354 unsigned int result;
388 char directive[MAXLINE], filename[MAXLINE];
389 char *s1, *s2, *s3;
390 static char line_fmt[] = "#line %d \"%s\"\n";
355
391
356 (void) sscanf( (char *) str, "%x", &result );
392 if ( ! gen_line_dirs )
393 return;
357
394
358 return result;
359 }
395 if ( (do_infile && ! infilename) || (! do_infile && ! outfilename) )
396 /* don't know the filename to use, skip */
397 return;
360
398
399 s1 = do_infile ? infilename : outfilename;
400 s2 = filename;
401 s3 = &filename[sizeof( filename ) - 2];
361
402
362/* is_hex_digit - returns true if a character is a valid hex digit, false
363 * otherwise
364 */
365
366int is_hex_digit( ch )
367int ch;
368 {
369 if ( isdigit( ch ) )
370 return 1;
371
372 switch ( clower( ch ) )
403 while ( s2 < s3 && *s1 )
373 {
404 {
374 case 'a':
375 case 'b':
376 case 'c':
377 case 'd':
378 case 'e':
379 case 'f':
380 return 1;
405 if ( *s1 == '\\' )
406 /* Escape the '\' */
407 *s2++ = '\\';
381
408
382 default:
383 return 0;
409 *s2++ = *s1++;
384 }
410 }
385 }
386
411
412 *s2 = '\0';
387
413
388/* line_directive_out - spit out a "# line" statement */
389
390void line_directive_out( output_file )
391FILE *output_file;
392 {
393 if ( infilename && gen_line_dirs )
414 if ( do_infile )
415 sprintf( directive, line_fmt, linenum, filename );
416 else
394 {
417 {
395 char directive[MAXLINE];
396 sprintf( directive, "# line %d \"%s\"\n", linenum, infilename );
418 if ( output_file == stdout )
419 /* Account for the line directive itself. */
420 ++out_linenum;
397
421
398 /* If output_file is nil then we should put the directive in
399 * the accumulated actions.
400 */
401 if ( output_file )
402 fputs( directive, output_file );
403 else
404 add_action( directive );
422 sprintf( directive, line_fmt, out_linenum, filename );
405 }
423 }
424
425 /* If output_file is nil then we should put the directive in
426 * the accumulated actions.
427 */
428 if ( output_file )
429 {
430 fputs( directive, output_file );
431 }
432 else
433 add_action( directive );
406 }
407
408
409/* mark_defs1 - mark the current position in the action array as
410 * representing where the user's section 1 definitions end
411 * and the prolog begins
412 */
413void mark_defs1()

--- 20 unchanged lines hidden (view full) ---

434 *
435 * Generates a data statement initializing the current 2-D array to "value".
436 */
437void mk2data( value )
438int value;
439 {
440 if ( datapos >= NUMDATAITEMS )
441 {
434 }
435
436
437/* mark_defs1 - mark the current position in the action array as
438 * representing where the user's section 1 definitions end
439 * and the prolog begins
440 */
441void mark_defs1()

--- 20 unchanged lines hidden (view full) ---

462 *
463 * Generates a data statement initializing the current 2-D array to "value".
464 */
465void mk2data( value )
466int value;
467 {
468 if ( datapos >= NUMDATAITEMS )
469 {
442 putchar( ',' );
470 outc( ',' );
443 dataflush();
444 }
445
446 if ( datapos == 0 )
447 /* Indent. */
471 dataflush();
472 }
473
474 if ( datapos == 0 )
475 /* Indent. */
448 fputs( " ", stdout );
476 out( " " );
449
450 else
477
478 else
451 putchar( ',' );
479 outc( ',' );
452
453 ++datapos;
454
480
481 ++datapos;
482
455 printf( "%5d", value );
483 out_dec( "%5d", value );
456 }
457
458
459/* mkdata - generate a data statement
460 *
461 * Generates a data statement initializing the current array element to
462 * "value".
463 */
464void mkdata( value )
465int value;
466 {
467 if ( datapos >= NUMDATAITEMS )
468 {
484 }
485
486
487/* mkdata - generate a data statement
488 *
489 * Generates a data statement initializing the current array element to
490 * "value".
491 */
492void mkdata( value )
493int value;
494 {
495 if ( datapos >= NUMDATAITEMS )
496 {
469 putchar( ',' );
497 outc( ',' );
470 dataflush();
471 }
472
473 if ( datapos == 0 )
474 /* Indent. */
498 dataflush();
499 }
500
501 if ( datapos == 0 )
502 /* Indent. */
475 fputs( " ", stdout );
503 out( " " );
476 else
504 else
477 putchar( ',' );
505 outc( ',' );
478
479 ++datapos;
480
506
507 ++datapos;
508
481 printf( "%5d", value );
509 out_dec( "%5d", value );
482 }
483
484
485/* myctoi - return the integer represented by a string of digits */
486
487int myctoi( array )
488char array[];
489 {

--- 15 unchanged lines hidden (view full) ---

505 switch ( array[1] )
506 {
507 case 'b': return '\b';
508 case 'f': return '\f';
509 case 'n': return '\n';
510 case 'r': return '\r';
511 case 't': return '\t';
512
510 }
511
512
513/* myctoi - return the integer represented by a string of digits */
514
515int myctoi( array )
516char array[];
517 {

--- 15 unchanged lines hidden (view full) ---

533 switch ( array[1] )
534 {
535 case 'b': return '\b';
536 case 'f': return '\f';
537 case 'n': return '\n';
538 case 'r': return '\r';
539 case 't': return '\t';
540
513#ifdef __STDC__
541#if __STDC__
514 case 'a': return '\a';
515 case 'v': return '\v';
516#else
517 case 'a': return '\007';
518 case 'v': return '\013';
519#endif
520
521 case '0':
522 case '1':
523 case '2':
524 case '3':
525 case '4':
526 case '5':
527 case '6':
528 case '7':
542 case 'a': return '\a';
543 case 'v': return '\v';
544#else
545 case 'a': return '\007';
546 case 'v': return '\013';
547#endif
548
549 case '0':
550 case '1':
551 case '2':
552 case '3':
553 case '4':
554 case '5':
555 case '6':
556 case '7':
529 case '8':
530 case '9':
531 { /* \<octal> */
532 int sptr = 1;
533
534 while ( isascii( array[sptr] ) &&
535 isdigit( array[sptr] ) )
536 /* Don't increment inside loop control
537 * because if isdigit() is a macro it might
538 * expand into multiple increments ...

--- 10 unchanged lines hidden (view full) ---

549 return esc_char;
550 }
551
552 case 'x':
553 { /* \x<hex> */
554 int sptr = 2;
555
556 while ( isascii( array[sptr] ) &&
557 { /* \<octal> */
558 int sptr = 1;
559
560 while ( isascii( array[sptr] ) &&
561 isdigit( array[sptr] ) )
562 /* Don't increment inside loop control
563 * because if isdigit() is a macro it might
564 * expand into multiple increments ...

--- 10 unchanged lines hidden (view full) ---

575 return esc_char;
576 }
577
578 case 'x':
579 { /* \x<hex> */
580 int sptr = 2;
581
582 while ( isascii( array[sptr] ) &&
557 is_hex_digit( (char) array[sptr] ) )
583 isxdigit( (char) array[sptr] ) )
558 /* Don't increment inside loop control
559 * because if isdigit() is a macro it might
560 * expand into multiple increments ...
561 */
562 ++sptr;
563
564 c = array[sptr];
565 array[sptr] = '\0';

--- 18 unchanged lines hidden (view full) ---

584 {
585 unsigned int result;
586
587 (void) sscanf( (char *) str, "%o", &result );
588 return result;
589 }
590
591
584 /* Don't increment inside loop control
585 * because if isdigit() is a macro it might
586 * expand into multiple increments ...
587 */
588 ++sptr;
589
590 c = array[sptr];
591 array[sptr] = '\0';

--- 18 unchanged lines hidden (view full) ---

610 {
611 unsigned int result;
612
613 (void) sscanf( (char *) str, "%o", &result );
614 return result;
615 }
616
617
618/* out - various flavors of outputing a (possibly formatted) string for the
619 * generated scanner, keeping track of the line count.
620 */
621
622void out( str )
623const char str[];
624 {
625 fputs( str, stdout );
626 out_line_count( str );
627 }
628
629void out_dec( fmt, n )
630const char fmt[];
631int n;
632 {
633 printf( fmt, n );
634 out_line_count( fmt );
635 }
636
637void out_dec2( fmt, n1, n2 )
638const char fmt[];
639int n1, n2;
640 {
641 printf( fmt, n1, n2 );
642 out_line_count( fmt );
643 }
644
645void out_hex( fmt, x )
646const char fmt[];
647unsigned int x;
648 {
649 printf( fmt, x );
650 out_line_count( fmt );
651 }
652
653void out_line_count( str )
654const char str[];
655 {
656 register int i;
657
658 for ( i = 0; str[i]; ++i )
659 if ( str[i] == '\n' )
660 ++out_linenum;
661 }
662
663void out_str( fmt, str )
664const char fmt[], str[];
665 {
666 printf( fmt, str );
667 out_line_count( fmt );
668 out_line_count( str );
669 }
670
671void out_str3( fmt, s1, s2, s3 )
672const char fmt[], s1[], s2[], s3[];
673 {
674 printf( fmt, s1, s2, s3 );
675 out_line_count( fmt );
676 out_line_count( s1 );
677 out_line_count( s2 );
678 out_line_count( s3 );
679 }
680
681void out_str_dec( fmt, str, n )
682const char fmt[], str[];
683int n;
684 {
685 printf( fmt, str, n );
686 out_line_count( fmt );
687 out_line_count( str );
688 }
689
690void outc( c )
691int c;
692 {
693 putc( c, stdout );
694
695 if ( c == '\n' )
696 ++out_linenum;
697 }
698
699void outn( str )
700const char str[];
701 {
702 puts( str );
703 out_line_count( str );
704 ++out_linenum;
705 }
706
707
592/* readable_form - return the the human-readable form of a character
593 *
594 * The returned string is in static storage.
595 */
596
597char *readable_form( c )
598register int c;
599 {

--- 4 unchanged lines hidden (view full) ---

604 switch ( c )
605 {
606 case '\b': return "\\b";
607 case '\f': return "\\f";
608 case '\n': return "\\n";
609 case '\r': return "\\r";
610 case '\t': return "\\t";
611
708/* readable_form - return the the human-readable form of a character
709 *
710 * The returned string is in static storage.
711 */
712
713char *readable_form( c )
714register int c;
715 {

--- 4 unchanged lines hidden (view full) ---

720 switch ( c )
721 {
722 case '\b': return "\\b";
723 case '\f': return "\\f";
724 case '\n': return "\\n";
725 case '\r': return "\\r";
726 case '\t': return "\\t";
727
612#ifdef __STDC__
728#if __STDC__
613 case '\a': return "\\a";
614 case '\v': return "\\v";
615#endif
616
617 default:
618 (void) sprintf( rform, "\\%.3o",
619 (unsigned int) c );
620 return rform;

--- 12 unchanged lines hidden (view full) ---

633 }
634 }
635
636
637/* reallocate_array - increase the size of a dynamic array */
638
639void *reallocate_array( array, size, element_size )
640void *array;
729 case '\a': return "\\a";
730 case '\v': return "\\v";
731#endif
732
733 default:
734 (void) sprintf( rform, "\\%.3o",
735 (unsigned int) c );
736 return rform;

--- 12 unchanged lines hidden (view full) ---

749 }
750 }
751
752
753/* reallocate_array - increase the size of a dynamic array */
754
755void *reallocate_array( array, size, element_size )
756void *array;
641int size, element_size;
757int size;
758size_t element_size;
642 {
643 register void *new_array;
759 {
760 register void *new_array;
761 size_t num_bytes = element_size * size;
644
762
645 /* Same worry as in allocate_array(): */
646 if ( size * element_size <= 0 )
647 flexfatal(
648 "attempt to increase array size by less than 1 byte" );
763 new_array = flex_realloc( array, num_bytes );
764 if ( ! new_array )
765 flexfatal( _( "attempt to increase array size failed" ) );
649
766
650 new_array = flex_realloc( array, size * element_size );
651
652 if ( new_array == NULL )
653 flexfatal( "attempt to increase array size failed" );
654
655 return new_array;
656 }
657
658
659/* skelout - write out one section of the skeleton file
660 *
661 * Description
662 * Copies skelfile or skel array to stdout until a line beginning with

--- 5 unchanged lines hidden (view full) ---

668 char *buf = buf_storage;
669 int do_copy = 1;
670
671 /* Loop pulling lines either from the skelfile, if we're using
672 * one, or from the skel[] array.
673 */
674 while ( skelfile ?
675 (fgets( buf, MAXLINE, skelfile ) != NULL) :
767 return new_array;
768 }
769
770
771/* skelout - write out one section of the skeleton file
772 *
773 * Description
774 * Copies skelfile or skel array to stdout until a line beginning with

--- 5 unchanged lines hidden (view full) ---

780 char *buf = buf_storage;
781 int do_copy = 1;
782
783 /* Loop pulling lines either from the skelfile, if we're using
784 * one, or from the skel[] array.
785 */
786 while ( skelfile ?
787 (fgets( buf, MAXLINE, skelfile ) != NULL) :
676 ((buf = skel[skel_ind++]) != 0) )
788 ((buf = (char *) skel[skel_ind++]) != 0) )
677 { /* copy from skel array */
678 if ( buf[0] == '%' )
679 { /* control line */
680 switch ( buf[1] )
681 {
682 case '%':
683 return;
684

--- 6 unchanged lines hidden (view full) ---

691 break;
692
693 case '*':
694 do_copy = 1;
695 break;
696
697 default:
698 flexfatal(
789 { /* copy from skel array */
790 if ( buf[0] == '%' )
791 { /* control line */
792 switch ( buf[1] )
793 {
794 case '%':
795 return;
796

--- 6 unchanged lines hidden (view full) ---

803 break;
804
805 case '*':
806 do_copy = 1;
807 break;
808
809 default:
810 flexfatal(
699 "bad line in skeleton file" );
811 _( "bad line in skeleton file" ) );
700 }
701 }
702
703 else if ( do_copy )
704 {
705 if ( skelfile )
706 /* Skeleton file reads include final
707 * newline, skel[] array does not.
708 */
812 }
813 }
814
815 else if ( do_copy )
816 {
817 if ( skelfile )
818 /* Skeleton file reads include final
819 * newline, skel[] array does not.
820 */
709 fputs( buf, stdout );
821 out( buf );
710 else
822 else
711 printf( "%s\n", buf );
823 outn( buf );
712 }
713 }
714 }
715
716
717/* transition_struct_out - output a yy_trans_info structure
718 *
719 * outputs the yy_trans_info structure with the two elements, element_v and
720 * element_n. Formats the output with spaces and carriage returns.
721 */
722
723void transition_struct_out( element_v, element_n )
724int element_v, element_n;
725 {
824 }
825 }
826 }
827
828
829/* transition_struct_out - output a yy_trans_info structure
830 *
831 * outputs the yy_trans_info structure with the two elements, element_v and
832 * element_n. Formats the output with spaces and carriage returns.
833 */
834
835void transition_struct_out( element_v, element_n )
836int element_v, element_n;
837 {
726 printf( "%7d, %5d,", element_v, element_n );
838 out_dec2( " {%4d,%4d },", element_v, element_n );
727
728 datapos += TRANS_STRUCT_PRINT_LENGTH;
729
839
840 datapos += TRANS_STRUCT_PRINT_LENGTH;
841
730 if ( datapos >= 75 )
842 if ( datapos >= 79 - TRANS_STRUCT_PRINT_LENGTH )
731 {
843 {
732 putchar( '\n' );
844 outc( '\n' );
733
734 if ( ++dataline % 10 == 0 )
845
846 if ( ++dataline % 10 == 0 )
735 putchar( '\n' );
847 outc( '\n' );
736
737 datapos = 0;
738 }
739 }
740
741
742/* The following is only needed when building flex's parser using certain
743 * broken versions of bison.
744 */
745void *yy_flex_xmalloc( size )
746int size;
747 {
848
849 datapos = 0;
850 }
851 }
852
853
854/* The following is only needed when building flex's parser using certain
855 * broken versions of bison.
856 */
857void *yy_flex_xmalloc( size )
858int size;
859 {
748 void *result = flex_alloc( size );
860 void *result = flex_alloc( (size_t) size );
749
750 if ( ! result )
861
862 if ( ! result )
751 flexfatal( "memory allocation failed in yy_flex_xmalloc()" );
863 flexfatal(
864 _( "memory allocation failed in yy_flex_xmalloc()" ) );
752
753 return result;
754 }
755
756
757/* zero_out - set a region of memory to 0
758 *
759 * Sets region_ptr[0] through region_ptr[size_in_bytes - 1] to zero.
760 */
761
762void zero_out( region_ptr, size_in_bytes )
763char *region_ptr;
865
866 return result;
867 }
868
869
870/* zero_out - set a region of memory to 0
871 *
872 * Sets region_ptr[0] through region_ptr[size_in_bytes - 1] to zero.
873 */
874
875void zero_out( region_ptr, size_in_bytes )
876char *region_ptr;
764int size_in_bytes;
877size_t size_in_bytes;
765 {
766 register char *rp, *rp_end;
767
768 rp = region_ptr;
769 rp_end = region_ptr + size_in_bytes;
770
771 while ( rp < rp_end )
772 *rp++ = 0;
773 }
878 {
879 register char *rp, *rp_end;
880
881 rp = region_ptr;
882 rp_end = region_ptr + size_in_bytes;
883
884 while ( rp < rp_end )
885 *rp++ = 0;
886 }