- 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:
- 8f01cb04
- Parents:
- 7582458
- git-author:
- Jacob Prud'homme <jafprudhomme@…> (07/16/21 15:06:54)
- git-committer:
- Jacob Prud'homme <jafprudhomme@…> (08/31/21 01:49:09)
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/parseconfig.cfa
r7582458 r58ebd78 7 7 * [ char *, char * ] data; 8 8 }; 9 void ?{}( VLA & vla ) with ( vla) { // default constructor9 void ?{}( KVPairs & kvp ) with ( kvp ) { // default constructor 10 10 size = 0; max_size = 0; data = 0p; 11 11 } 12 void ?{}( VLA & vla, int size, char fill = ['\0', '\0'] ) { // initialization 13 vla.[ size, max_size, data ] = [ 0, max_size, alloc( size, fill ) ]; 12 void ?{}( KVPairs & kvp, int size ) { // initialization 13 kvp.[ size, max_size ] = [ 0, size ]; 14 kvp.data = alloc( size ); 14 15 } 15 void ?{}( VLA & vla, VLA val ) with( val ) { // copy, deep 16 vla.[ size, max_size, data ] = [ size, max_size, alloc( size, data ) ]; 17 } 18 void ^?{}( VLA & vla ) with ( vla ) { // destructor 16 void ^?{}( KVPairs & kvp ) with ( kvp ) { // destructor 19 17 free( data ); 20 18 size = 0; max_size = 0; data = 0p; 21 19 } 22 20 23 void add_kv_pair( KVPairs kv_pairs, char * k, char * v ) with ( kv_pairs ) {21 void add_kv_pair( KVPairs kv_pairs, char * k, char * v ) with ( kv_pairs ) { 24 22 if ( size == max_size ) { 25 max_size = max_size *2;23 max_size *= 2; 26 24 data = resize( data, max_size ); 27 25 } … … 42 40 43 41 // Parse configuration from a file formatted in shell style 44 KVPairs & parse_shell_config_format( const char * config_file ) {45 KVPairs kv_pairs { num_entries };42 KVPairs & parse_shell_config_format( const char * config_file, size_t num_entries ) { 43 KVPairs kv_pairs = { num_entries }; 46 44 47 45 ifstream in; … … 69 67 } 70 68 71 // P rocess the configuration file to set the simulation parameters.69 // Parse configuration values from intermediate format 72 70 void parse_config( const char * config_file, config_entry entries[], size_t num_entries ) { 73 KVPairs kv_pairs = parse_shell_config_format( config_file );71 KVPairs kv_pairs = parse_shell_config_format( config_file, num_entries ); 74 72 75 // *** WE MUST ALLOW SOME SORT OF VALIDATION FUNCTIONALITY TOO!!! ***76 73 int entries_so_far = 0; 77 74 for ( i; kv_pairs.size ) { … … 88 85 } 89 86 90 serr | "Value " | src_value | " for key " | dest_key | "could not be parsed";87 serr | "Value '" | src_value | "' for key '" | src_key | "' could not be parsed"; 91 88 } 92 89 } -
libcfa/src/parseconfig.hfa
r7582458 r58ebd78 4 4 const char * key; 5 5 void * variable; 6 bool (*parse)( const char *, void *);6 bool (*parse)( const char *, void * ); 7 7 }; 8 8 9 9 static inline void ?{}( config_entry & this ) {} 10 10 11 forall(T & | { bool parse( const char *, T & ); })11 forall(T & | { bool parse( const char *, T & ); }) 12 12 static inline void ?{}( config_entry & this, const char * key, T & variable ) { 13 13 this.key = key;
Note: See TracChangeset
for help on using the changeset viewer.