Changeset ca83227
- Timestamp:
- Aug 31, 2021, 5:08:10 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
- Children:
- b0f225f
- Parents:
- 45b772c
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/parseconfig.cfa
r45b772c rca83227 77 77 78 78 79 // TODO: Replace KVPairs with vector2 when it's fully functional80 struct KVPairs {81 size_t size, max_size;82 * [ * char, * char ] data;83 };84 85 79 [ void ] ?{}( & KVPairs kvp ) with ( kvp ) { // default constructor 86 80 size = 0; max_size = 0; data = 0p; … … 157 151 158 152 // Parse configuration values from intermediate format 159 [ void ] parse_config( [] const char config_file, [] config_entry entries, size_t num_entries, config_format format ) { 160 * KVPairs kv_pairs = 0p; 161 choose ( format ) { 162 case TABULAR_CONFIG: 163 kv_pairs = parse_tabular_config_format( config_file, num_entries ); 164 } 153 [ void ] parse_config( 154 [] const char config_file, 155 [] config_entry entries, 156 size_t num_entries, 157 KVPairs * (*parser)(const char [], size_t) 158 ) { 159 * KVPairs kv_pairs = parser( config_file, num_entries ); 165 160 166 161 int entries_so_far = 0; -
libcfa/src/parseconfig.hfa
r45b772c rca83227 6 6 // *********************************** initial declarations *********************************** 7 7 8 9 enum config_format {10 TABULAR_CONFIG11 };12 8 13 9 struct config_entry { … … 54 50 } 55 51 52 // TODO: Replace KVPairs with vector2 when it's fully functional 53 struct KVPairs { 54 size_t size, max_size; 55 * [ * char, * char ] data; 56 }; 57 58 [ void ] add_kv_pair( & KVPairs kv_pairs, [] char key, [] char value ); 59 56 60 57 61 // *********************************** exceptions *********************************** … … 82 86 83 87 84 void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format ); 88 [ * KVPairs ] parse_tabular_config_format( [] const char config_file, size_t num_entries ); 89 90 [ void ] parse_config( 91 [] const char config_file, 92 [] config_entry entries, 93 size_t num_entries, 94 KVPairs * (*parser)(const char [], size_t) 95 ); 85 96 86 97 bool parse( const char *, const char * & ); -
tests/parseconfig.cfa
r45b772c rca83227 50 50 sout | "Different types of destination addresses"; 51 51 52 parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, TABULAR_CONFIG);52 parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, parse_tabular_config_format ); 53 53 54 54 sout | "Stop cost: " | config_params.stop_cost; … … 68 68 sout | "Open_Failure thrown when config file does not exist"; 69 69 try { 70 parse_config( xstr(IN_DIR) "doesnt-exist.txt", entries, NUM_ENTRIES, TABULAR_CONFIG);70 parse_config( xstr(IN_DIR) "doesnt-exist.txt", entries, NUM_ENTRIES, parse_tabular_config_format ); 71 71 } catch( Open_Failure * ex ) { 72 72 sout | "Failed to open the config file"; … … 77 77 sout | "Missing_Config_Entries thrown when config file is missing entries we want"; 78 78 try { 79 parse_config( xstr(IN_DIR) "parseconfig-missing.txt", entries, NUM_ENTRIES, TABULAR_CONFIG);79 parse_config( xstr(IN_DIR) "parseconfig-missing.txt", entries, NUM_ENTRIES, parse_tabular_config_format ); 80 80 } catch( Missing_Config_Entries * ex ) { 81 81 msg( ex ); … … 92 92 93 93 try { 94 parse_config( xstr(IN_DIR) "parseconfig-errors.txt", entry, 1, TABULAR_CONFIG);94 parse_config( xstr(IN_DIR) "parseconfig-errors.txt", entry, 1, parse_tabular_config_format ); 95 95 } catch( Parse_Failure * ex ) { 96 96 msg( ex ); … … 106 106 107 107 try { 108 parse_config( xstr(IN_DIR) "parseconfig-errors.txt", entries, NUM_ENTRIES, TABULAR_CONFIG);108 parse_config( xstr(IN_DIR) "parseconfig-errors.txt", entries, NUM_ENTRIES, parse_tabular_config_format ); 109 109 } catch( Validation_Failure * ex ) { 110 110 msg( ex ); … … 115 115 sout | "No error is thrown when validation succeeds"; 116 116 config_params.stop_cost = -1; // Reset value 117 parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, TABULAR_CONFIG);117 parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, parse_tabular_config_format ); 118 118 sout | "Stop cost: " | config_params.stop_cost; 119 119 sout | nl; … … 126 126 127 127 config_params.stop_cost = -1; // Reset value 128 parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, TABULAR_CONFIG);128 parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, parse_tabular_config_format ); 129 129 130 130 sout | "Stop cost: " | config_params.stop_cost; … … 139 139 140 140 config_params.stop_cost = -1; // Reset value 141 parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, TABULAR_CONFIG);141 parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, parse_tabular_config_format ); 142 142 143 143 sout | "Stop cost: " | config_params.stop_cost;
Note: See TracChangeset
for help on using the changeset viewer.