Changeset d8db0af


Ignore:
Timestamp:
Aug 31, 2021, 1:49:10 AM (5 months ago)
Author:
Jacob Prud'homme <jafprudhomme@…>
Branches:
jacob/cs343-translation, master
Children:
a434e92
Parents:
ad78e08
git-author:
Jacob Prud'homme <jafprudhomme@…> (08/05/21 23:25:24)
git-committer:
Jacob Prud'homme <jafprudhomme@…> (08/31/21 01:49:10)
Message:

Allowed config format to be specified

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/parseconfig.cfa

    rad78e08 rd8db0af  
    6666
    6767// Parse configuration from a file formatted in shell style
    68 KVPairs & parse_tabular_config_format( const char * config_file, size_t num_entries ) {
     68KVPairs * parse_tabular_config_format( const char * config_file, size_t num_entries ) {
    6969        * KVPairs kv_pairs = new( num_entries );
    7070
     
    9393        close( in );
    9494
    95         return *kv_pairs;
     95        return kv_pairs;
    9696}
    9797
    9898// Parse configuration values from intermediate format
    99 void parse_config( const char * config_file, config_entry entries[], size_t num_entries ) {
    100         KVPairs & kv_pairs = parse_tabular_config_format( config_file, num_entries );
     99void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format ) {
     100        KVPairs * kv_pairs;
     101        choose ( format ) {
     102                case TABULAR_CONFIG:
     103                        kv_pairs = parse_tabular_config_format( config_file, num_entries );
     104                default:
     105                        exit | "Error: config file format " | format | " is not supported";
     106        }
    101107
    102108        int entries_so_far = 0;
    103         for ( i; kv_pairs.size ) {
     109        for ( i; kv_pairs->size ) {
    104110          if ( entries_so_far == num_entries ) break;
    105111
    106112                char * src_key, * src_value;
    107                 [ src_key, src_value ] = kv_pairs.data[i];
     113                [ src_key, src_value ] = kv_pairs->data[i];
    108114
    109115                for ( j; num_entries ) {
     
    123129                }
    124130        }
     131
     132        ^(*kv_pairs){};
    125133} // processConfigFile
    126134
  • libcfa/src/parseconfig.hfa

    rad78e08 rd8db0af  
    66// *********************************** initial declarations ***********************************
    77
     8
     9enum config_format {
     10        TABULAR_CONFIG
     11};
    812
    913struct config_entry {
     
    6367
    6468
    65 void parse_config( const char * config_file, config_entry entries[], size_t num_entries );
     69void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format );
    6670
    6771bool parse( const char *, const char * & );
Note: See TracChangeset for help on using the changeset viewer.