misc.c (99112) | misc.c (179549) |
---|---|
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. --- 14 unchanged lines hidden (view full) --- 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/daffy/u0/vern/flex/RCS/misc.c,v 2.47 95/04/28 11:39:39 vern Exp $ */ 30#include <sys/cdefs.h> | 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. --- 14 unchanged lines hidden (view full) --- 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/daffy/u0/vern/flex/RCS/misc.c,v 2.47 95/04/28 11:39:39 vern Exp $ */ 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/usr.bin/lex/misc.c 99112 2002-06-30 05:25:07Z obrien $"); | 31__FBSDID("$FreeBSD: head/usr.bin/lex/misc.c 179549 2008-06-04 19:50:34Z dwmalone $"); |
32 33#include "flexdef.h" 34 35 36void action_define( defname, value ) 37char *defname; 38int value; 39 { --- 39 unchanged lines hidden (view full) --- 79 80 81/* allocate_array - allocate memory for an integer array of the given size */ 82 83void *allocate_array( size, element_size ) 84int size; 85size_t element_size; 86 { | 32 33#include "flexdef.h" 34 35 36void action_define( defname, value ) 37char *defname; 38int value; 39 { --- 39 unchanged lines hidden (view full) --- 79 80 81/* allocate_array - allocate memory for an integer array of the given size */ 82 83void *allocate_array( size, element_size ) 84int size; 85size_t element_size; 86 { |
87 register void *mem; | 87 void *mem; |
88 size_t num_bytes = element_size * size; 89 90 mem = flex_alloc( num_bytes ); 91 if ( ! mem ) 92 flexfatal( 93 _( "memory allocation failed in allocate_array()" ) ); 94 95 return mem; 96 } 97 98 99/* all_lower - true if a string is all lower-case */ 100 101int all_lower( str ) | 88 size_t num_bytes = element_size * size; 89 90 mem = flex_alloc( num_bytes ); 91 if ( ! mem ) 92 flexfatal( 93 _( "memory allocation failed in allocate_array()" ) ); 94 95 return mem; 96 } 97 98 99/* all_lower - true if a string is all lower-case */ 100 101int all_lower( str ) |
102register char *str; | 102char *str; |
103 { 104 while ( *str ) 105 { 106 if ( ! isascii( (Char) *str ) || ! islower( *str ) ) 107 return 0; 108 ++str; 109 } 110 111 return 1; 112 } 113 114 115/* all_upper - true if a string is all upper-case */ 116 117int all_upper( str ) | 103 { 104 while ( *str ) 105 { 106 if ( ! isascii( (Char) *str ) || ! islower( *str ) ) 107 return 0; 108 ++str; 109 } 110 111 return 1; 112 } 113 114 115/* all_upper - true if a string is all upper-case */ 116 117int all_upper( str ) |
118register char *str; | 118char *str; |
119 { 120 while ( *str ) 121 { 122 if ( ! isascii( (Char) *str ) || ! isupper( *str ) ) 123 return 0; 124 ++str; 125 } 126 --- 14 unchanged lines hidden (view full) --- 141 * passed 142 * v - the array to be sorted 143 * n - the number of elements of 'v' to be sorted 144 */ 145 146void bubble( v, n ) 147int v[], n; 148 { | 119 { 120 while ( *str ) 121 { 122 if ( ! isascii( (Char) *str ) || ! isupper( *str ) ) 123 return 0; 124 ++str; 125 } 126 --- 14 unchanged lines hidden (view full) --- 141 * passed 142 * v - the array to be sorted 143 * n - the number of elements of 'v' to be sorted 144 */ 145 146void bubble( v, n ) 147int v[], n; 148 { |
149 register int i, j, k; | 149 int i, j, k; |
150 151 for ( i = n; i > 1; --i ) 152 for ( j = 1; j < i; ++j ) 153 if ( v[j] > v[j + 1] ) /* compare */ 154 { 155 k = v[j]; /* exchange */ 156 v[j] = v[j + 1]; 157 v[j + 1] = k; --- 19 unchanged lines hidden (view full) --- 177 readable_form( c ) ); 178 } 179 180 181 182/* clower - replace upper-case letter to lower-case */ 183 184Char clower( c ) | 150 151 for ( i = n; i > 1; --i ) 152 for ( j = 1; j < i; ++j ) 153 if ( v[j] > v[j + 1] ) /* compare */ 154 { 155 k = v[j]; /* exchange */ 156 v[j] = v[j + 1]; 157 v[j + 1] = k; --- 19 unchanged lines hidden (view full) --- 177 readable_form( c ) ); 178 } 179 180 181 182/* clower - replace upper-case letter to lower-case */ 183 184Char clower( c ) |
185register int c; | 185int c; |
186 { 187 return (Char) ((isascii( c ) && isupper( c )) ? tolower( c ) : c); 188 } 189 190 191/* copy_string - returns a dynamically allocated copy of a string */ 192 193char *copy_string( str ) | 186 { 187 return (Char) ((isascii( c ) && isupper( c )) ? tolower( c ) : c); 188 } 189 190 191/* copy_string - returns a dynamically allocated copy of a string */ 192 193char *copy_string( str ) |
194register const char *str; | 194const char *str; |
195 { | 195 { |
196 register const char *c1; 197 register char *c2; | 196 const char *c1; 197 char *c2; |
198 char *copy; 199 unsigned int size; 200 201 /* find length */ 202 for ( c1 = str; *c1; ++c1 ) 203 ; 204 205 size = (c1 - str + 1) * sizeof( char ); --- 9 unchanged lines hidden (view full) --- 215 } 216 217 218/* copy_unsigned_string - 219 * returns a dynamically allocated copy of a (potentially) unsigned string 220 */ 221 222Char *copy_unsigned_string( str ) | 198 char *copy; 199 unsigned int size; 200 201 /* find length */ 202 for ( c1 = str; *c1; ++c1 ) 203 ; 204 205 size = (c1 - str + 1) * sizeof( char ); --- 9 unchanged lines hidden (view full) --- 215 } 216 217 218/* copy_unsigned_string - 219 * returns a dynamically allocated copy of a (potentially) unsigned string 220 */ 221 222Char *copy_unsigned_string( str ) |
223register Char *str; | 223Char *str; |
224 { | 224 { |
225 register Char *c; | 225 Char *c; |
226 Char *copy; 227 228 /* find length */ 229 for ( c = str; *c; ++c ) 230 ; 231 232 copy = allocate_Character_array( c - str + 1 ); 233 --- 416 unchanged lines hidden (view full) --- 650 { 651 printf( fmt, x ); 652 out_line_count( fmt ); 653 } 654 655void out_line_count( str ) 656const char str[]; 657 { | 226 Char *copy; 227 228 /* find length */ 229 for ( c = str; *c; ++c ) 230 ; 231 232 copy = allocate_Character_array( c - str + 1 ); 233 --- 416 unchanged lines hidden (view full) --- 650 { 651 printf( fmt, x ); 652 out_line_count( fmt ); 653 } 654 655void out_line_count( str ) 656const char str[]; 657 { |
658 register int i; | 658 int i; |
659 660 for ( i = 0; str[i]; ++i ) 661 if ( str[i] == '\n' ) 662 ++out_linenum; 663 } 664 665void out_str( fmt, str ) 666const char fmt[], str[]; --- 41 unchanged lines hidden (view full) --- 708 709 710/* readable_form - return the the human-readable form of a character 711 * 712 * The returned string is in static storage. 713 */ 714 715char *readable_form( c ) | 659 660 for ( i = 0; str[i]; ++i ) 661 if ( str[i] == '\n' ) 662 ++out_linenum; 663 } 664 665void out_str( fmt, str ) 666const char fmt[], str[]; --- 41 unchanged lines hidden (view full) --- 708 709 710/* readable_form - return the the human-readable form of a character 711 * 712 * The returned string is in static storage. 713 */ 714 715char *readable_form( c ) |
716register int c; | 716int c; |
717 { 718 static char rform[10]; 719 720 if ( (c >= 0 && c < 32) || c >= 127 ) 721 { 722 switch ( c ) 723 { 724 case '\b': return "\\b"; --- 29 unchanged lines hidden (view full) --- 754 755/* reallocate_array - increase the size of a dynamic array */ 756 757void *reallocate_array( array, size, element_size ) 758void *array; 759int size; 760size_t element_size; 761 { | 717 { 718 static char rform[10]; 719 720 if ( (c >= 0 && c < 32) || c >= 127 ) 721 { 722 switch ( c ) 723 { 724 case '\b': return "\\b"; --- 29 unchanged lines hidden (view full) --- 754 755/* reallocate_array - increase the size of a dynamic array */ 756 757void *reallocate_array( array, size, element_size ) 758void *array; 759int size; 760size_t element_size; 761 { |
762 register void *new_array; | 762 void *new_array; |
763 size_t num_bytes = element_size * size; 764 765 new_array = flex_realloc( array, num_bytes ); 766 if ( ! new_array ) 767 flexfatal( _( "attempt to increase array size failed" ) ); 768 769 return new_array; 770 } --- 102 unchanged lines hidden (view full) --- 873 * 874 * Sets region_ptr[0] through region_ptr[size_in_bytes - 1] to zero. 875 */ 876 877void zero_out( region_ptr, size_in_bytes ) 878char *region_ptr; 879size_t size_in_bytes; 880 { | 763 size_t num_bytes = element_size * size; 764 765 new_array = flex_realloc( array, num_bytes ); 766 if ( ! new_array ) 767 flexfatal( _( "attempt to increase array size failed" ) ); 768 769 return new_array; 770 } --- 102 unchanged lines hidden (view full) --- 873 * 874 * Sets region_ptr[0] through region_ptr[size_in_bytes - 1] to zero. 875 */ 876 877void zero_out( region_ptr, size_in_bytes ) 878char *region_ptr; 879size_t size_in_bytes; 880 { |
881 register char *rp, *rp_end; | 881 char *rp, *rp_end; |
882 883 rp = region_ptr; 884 rp_end = region_ptr + size_in_bytes; 885 886 while ( rp < rp_end ) 887 *rp++ = 0; 888 } | 882 883 rp = region_ptr; 884 rp_end = region_ptr + size_in_bytes; 885 886 while ( rp < rp_end ) 887 *rp++ = 0; 888 } |