Changeset ca83227 for libcfa


Ignore:
Timestamp:
Aug 31, 2021, 5:08:10 PM (3 years ago)
Author:
Jacob Prud'homme <jafprudhomme@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
Children:
b0f225f
Parents:
45b772c
Message:

Changed API of parse_config to accept parse function

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/parseconfig.cfa

    r45b772c rca83227  
    7777
    7878
    79 // TODO: Replace KVPairs with vector2 when it's fully functional
    80 struct KVPairs {
    81         size_t size, max_size;
    82         * [ * char, * char ] data;
    83 };
    84 
    8579[ void ] ?{}( & KVPairs kvp ) with ( kvp ) {                            // default constructor
    8680        size = 0; max_size = 0; data = 0p;
     
    157151
    158152// 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 );
    165160
    166161        int entries_so_far = 0;
  • libcfa/src/parseconfig.hfa

    r45b772c rca83227  
    66// *********************************** initial declarations ***********************************
    77
    8 
    9 enum config_format {
    10         TABULAR_CONFIG
    11 };
    128
    139struct config_entry {
     
    5450}
    5551
     52// TODO: Replace KVPairs with vector2 when it's fully functional
     53struct 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
    5660
    5761// *********************************** exceptions ***********************************
     
    8286
    8387
    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);
    8596
    8697bool parse( const char *, const char * & );
Note: See TracChangeset for help on using the changeset viewer.