> I do not understand what you are suggesting.  Do you mean the printing 
 > either the DELIMITER or not after all the if-then-else statements?  That 
 > wouldn't work since each value type will have to read the values 
 > separately and then loop through the values and print them (with %s, 
 > %lld, etc).  The looping is basically printing the "value," if it is not 
 > the last item and just the "value" if it is the last item in the list.

I mean something like this:
    
   static void
   output_prop_val(const char *prop_name, nwam_value_t value, FILE *wf,
       boolean_t quoted_strings)
   {
        int                     i;
        uint_t                  num;
        nwam_value_type_t       value_type;
        nwam_error_t            ret;
        void                    *vals;
        tostr_func_t            func;
   
        if (nwam_value_get_type(value, &value_type) != NWAM_SUCCESS) {
                nerr("Get value type error");
                return;
        }
        
        switch (value_type) {
        case NWAM_VALUE_TYPE_STRING:
                if (nwam_value_get_string_array(value, &vals, &num) !=
                    NWAM_SUCCESS) {
                        nerr("Get string array error");
                        return;
                }
                func = quoted_strings ? str2qstr : str2str; 
                break;
        case NWAM_VALUE_TYPE_INT64:
                if (nwam_value_get_int64_array(value, &vals, &num) !=
                    NWAM_SUCCESS) {
                        nerr("Get int64 array error");
                        return;
                }
                
                func = int2str;
                break;
        /*  ... */
        case NWAM_VALUE_TYPE_BOOLEAN):
                if (nwam_value_get_boolean_array(value, &vals, &num) !=
                    NWAM_SUCCESS) {
                        nerr("Get boolean array error");
                        return;
                }
                
                func = bool2str;
                break;
        }
   
        for (i = 0; i < num; i++) {
                (void) fprintf(wf, "%s%s", func(vals[i]),
                    i != num-1 ? NWAM_VALUE_DELIMITER_STR : "");
        }
   }    
   

But maybe that's too hard to do without defeating type safety.

-- 
meem

Reply via email to