Changeset ba61cd9 for libcfa/src/parseconfig.cfa
- Timestamp:
- Aug 31, 2021, 1:49:09 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
- Children:
- 45729a8
- Parents:
- 02a22a2
- git-author:
- Jacob Prud'homme <jafprudhomme@…> (07/27/21 12:40:01)
- git-committer:
- Jacob Prud'homme <jafprudhomme@…> (08/31/21 01:49:09)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/parseconfig.cfa
r02a22a2 rba61cd9 55 55 } 56 56 57 58 struct StringBuilder { 59 int size, max_size; 60 * char string; 61 }; 62 void ?{}( StringBuilder & sb ) with ( sb ) { // default constructor 63 size = 1; max_size = 1; string = alloc( 1 ); 64 string[0] = '\0'; 65 } 66 void ?{}( StringBuilder & sb, int size ) { // initialization 67 sb.[ size, max_size ] = [ 1, size+1 ]; 68 sb.string = alloc( size ); 69 sb.string[0] = '\0'; 70 } 71 void ^?{}( StringBuilder & sb ) with ( sb ) { // destructor 72 free( string ); 73 size = 0; max_size = 0; string = 0p; 74 } 75 76 void add_char( StringBuilder & sb, char c ) with ( sb ) { 77 if ( size == max_size ) { 78 max_size *= 2; 79 string = resize( string, max_size ); 80 } 81 82 string[size-1] = c; 83 string[size] = '\0'; 84 ++size; 85 } 86 87 57 88 bool comments( ifstream & in, char * name ) { 89 StringBuilder sb; 90 91 char c; 58 92 while () { 59 in | name; 60 if ( fail( in ) ) return true; 61 if ( name[0] != '#' ) break; 93 in | c; 94 add_char( sb, c ); 95 96 if ( fail( in ) ) { 97 name = alloc( sb.size ); 98 strcpy( name, sb.string ); 99 100 return true; 101 } 102 if ( c != '#' ) break; 62 103 in | nl; // ignore remainder of line 63 104 } // for 105 106 name = alloc( sb.size ); 107 strcpy( name, sb.string ); 108 64 109 return false; 65 110 } // comments
Note: See TracChangeset
for help on using the changeset viewer.