Changeset e7e5b81
- 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:
- eb2413d3
- Parents:
- d5cfc7e
- git-author:
- Jacob Prud'homme <jafprudhomme@…> (07/13/21 12:40:14)
- git-committer:
- Jacob Prud'homme <jafprudhomme@…> (08/31/21 01:49:09)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/parseconfig.cfa
rd5cfc7e re7e5b81 66 66 close( in ); 67 67 // *** WE MUST ALLOW SOME SORT OF VALIDATION FUNCTIONALITY TOO!!! *** 68 69 int entries_so_far = 0; 70 for ( i; kv_pairs.size ) { 71 if ( entries_so_far == num_entries ) break; 72 73 char * src_key, * src_value; 74 [ src_key, src_value ] = kv_pairs.data[i]; 75 76 for ( j; num_entries ) { 77 if ( strcmp( src_key, entries[j].key ) != 0 ) continue; 78 if ( entries[j].parse( src_value, entries[j].variable ) ) { 79 ++entries_so_far; 80 break; 81 } 82 83 serr | "Value " | src_value | " for key " | dest_key | " could not be parsed"; 84 } 85 } 68 86 } // processConfigFile 87 88 89 //----------------------------------------------------------------------------- 90 // Typed argument parsing 91 92 bool parse( const char * arg, const char * & value ) { 93 value = arg; 94 return true; 95 } 96 97 bool parse( const char * arg, int & value ) { 98 char * end; 99 int r = strtoll( arg, &end, 10 ); 100 if ( *end != '\0' ) return false; 101 102 value = r; 103 return true; 104 } 105 106 bool parse( const char * arg, unsigned & value ) { 107 char * end; 108 unsigned long long int r = strtoull( arg, &end, 10 ); 109 if ( *end != '\0' ) return false; 110 if ( r > (unsigned)MAX ) return false; 111 112 value = r; 113 return true; 114 } 115 116 bool parse( const char * arg, unsigned long & value ) { 117 char * end; 118 unsigned long long int r = strtoull( arg, &end, 10 ); 119 if ( *end != '\0' ) return false; 120 if ( r > (unsigned long)MAX ) return false; 121 122 value = r; 123 return true; 124 } 125 126 bool parse( const char * arg, unsigned long long & value ) { 127 char * end; 128 unsigned long long int r = strtoull( arg, &end, 10 ); 129 if ( *end != '\0' ) return false; 130 if ( r > (unsigned long long)MAX ) return false; 131 132 value = r; 133 return true; 134 } 135 136 bool parse( const char * arg, float & value ) { 137 char * end; 138 float r = strtof( arg, &end ); 139 if ( *end != '\0' ) return false; 140 141 value = r; 142 return true; 143 } 144 145 bool parse( const char * arg, double & value ) { 146 char * end; 147 double r = strtod( arg, &end ); 148 if ( *end != '\0' ) return false; 149 150 value = r; 151 return true; 152 } 153 69 154 70 155 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.