Просмотр исходного кода

ncd: NCDValueGenerator: remove the NCDValue interface, leaving only the NCDVal interface

ambrop7 13 лет назад
Родитель
Сommit
5b713bcadf
5 измененных файлов с 15 добавлено и 167 удалено
  1. 1 1
      examples/CMakeLists.txt
  2. 13 2
      examples/ncd_parser_test.c
  3. 1 1
      ncd/CMakeLists.txt
  4. 0 159
      ncd/NCDValueGenerator.c
  5. 0 4
      ncd/NCDValueGenerator.h

+ 1 - 1
examples/CMakeLists.txt

@@ -30,7 +30,7 @@ if (BUILD_NCD)
     target_link_libraries(ncd_tokenizer_test ncdtokenizer)
     target_link_libraries(ncd_tokenizer_test ncdtokenizer)
 
 
     add_executable(ncd_parser_test ncd_parser_test.c)
     add_executable(ncd_parser_test ncd_parser_test.c)
-    target_link_libraries(ncd_parser_test ncdconfigparser ncdvaluegenerator ncdsugar)
+    target_link_libraries(ncd_parser_test ncdconfigparser ncdvaluegenerator ncdsugar ncdvalcompat)
 
 
     add_executable(ncd_value_parser_test ncd_value_parser_test.c)
     add_executable(ncd_value_parser_test ncd_value_parser_test.c)
     target_link_libraries(ncd_value_parser_test ncdvalueparser ncdvaluegenerator)
     target_link_libraries(ncd_value_parser_test ncdvalueparser ncdvaluegenerator)

+ 13 - 2
examples/ncd_parser_test.c

@@ -37,6 +37,7 @@
 #include <ncd/NCDConfigParser.h>
 #include <ncd/NCDConfigParser.h>
 #include <ncd/NCDValueGenerator.h>
 #include <ncd/NCDValueGenerator.h>
 #include <ncd/NCDSugar.h>
 #include <ncd/NCDSugar.h>
+#include <ncd/NCDValCompat.h>
 
 
 int error;
 int error;
 
 
@@ -50,9 +51,18 @@ static void print_indent (unsigned int indent)
 
 
 static void print_value (NCDValue *v, unsigned int indent)
 static void print_value (NCDValue *v, unsigned int indent)
 {
 {
-    char *str = NCDValueGenerator_Generate(v);
+    NCDValMem mem;
+    NCDValMem_Init(&mem);
+    
+    NCDValRef vref;
+    if (!NCDValCompat_ValueToVal(v, &mem, &vref)) {
+        DEBUG("NCDValCompat_ValueToVal failed");
+        exit(1);
+    }
+    
+    char *str = NCDValGenerator_Generate(vref);
     if (!str) {
     if (!str) {
-        DEBUG("NCDValueGenerator_Generate failed");
+        DEBUG("NCDValGenerator_Generate failed");
         exit(1);
         exit(1);
     }
     }
     
     
@@ -60,6 +70,7 @@ static void print_value (NCDValue *v, unsigned int indent)
     printf("%s\n", str);
     printf("%s\n", str);
     
     
     free(str);
     free(str);
+    NCDValMem_Free(&mem);
 }
 }
 
 
 static void print_block (NCDBlock *block, unsigned int indent)
 static void print_block (NCDBlock *block, unsigned int indent)

+ 1 - 1
ncd/CMakeLists.txt

@@ -43,7 +43,7 @@ target_link_libraries(ncdvalcompat ncdvalue ncdval)
 add_library(ncdvaluegenerator
 add_library(ncdvaluegenerator
     NCDValueGenerator.c
     NCDValueGenerator.c
 )
 )
-target_link_libraries(ncdvaluegenerator base ncdvalue ncdval)
+target_link_libraries(ncdvaluegenerator base ncdval)
 
 
 add_library(ncdvalueparser
 add_library(ncdvalueparser
     NCDValueParser.c
     NCDValueParser.c

+ 0 - 159
ncd/NCDValueGenerator.c

@@ -39,135 +39,6 @@
 
 
 #include <generated/blog_channel_NCDValueGenerator.h>
 #include <generated/blog_channel_NCDValueGenerator.h>
 
 
-static int generate_value (NCDValue *value, ExpString *out_str)
-{
-    switch (NCDValue_Type(value)) {
-        case NCDVALUE_STRING: {
-            const char *str = NCDValue_StringValue(value);
-            size_t len = NCDValue_StringLength(value);
-            
-            if (!ExpString_AppendChar(out_str, '"')) {
-                BLog(BLOG_ERROR, "ExpString_AppendChar failed");
-                goto fail;
-            }
-            
-            for (size_t i = 0; i < len; i++) {
-                if (str[i] == '\0') {
-                    char buf[5];
-                    snprintf(buf, sizeof(buf), "\\x%02"PRIx8, (uint8_t)str[i]);
-                    
-                    if (!ExpString_Append(out_str, buf)) {
-                        BLog(BLOG_ERROR, "ExpString_Append failed");
-                        goto fail;
-                    }
-                    
-                    continue;
-                }
-                
-                if (str[i] == '"' || str[i] == '\\') {
-                    if (!ExpString_AppendChar(out_str, '\\')) {
-                        BLog(BLOG_ERROR, "ExpString_AppendChar failed");
-                        goto fail;
-                    }
-                }
-                
-                if (!ExpString_AppendChar(out_str, str[i])) {
-                    BLog(BLOG_ERROR, "ExpString_AppendChar failed");
-                    goto fail;
-                }
-            }
-            
-            if (!ExpString_AppendChar(out_str, '"')) {
-                BLog(BLOG_ERROR, "ExpString_AppendChar failed");
-                goto fail;
-            }
-        } break;
-        
-        case NCDVALUE_LIST: {
-            if (!ExpString_AppendChar(out_str, '{')) {
-                BLog(BLOG_ERROR, "ExpString_AppendChar failed");
-                goto fail;
-            }
-            
-            int is_first = 1;
-            
-            for (NCDValue *e = NCDValue_ListFirst(value); e; e = NCDValue_ListNext(value, e)) {
-                if (!is_first) {
-                    if (!ExpString_Append(out_str, ", ")) {
-                        BLog(BLOG_ERROR, "ExpString_Append failed");
-                        goto fail;
-                    }
-                }
-                
-                if (!generate_value(e, out_str)) {
-                    goto fail;
-                }
-                
-                is_first = 0;
-            }
-            
-            if (!ExpString_AppendChar(out_str, '}')) {
-                BLog(BLOG_ERROR, "ExpString_AppendChar failed");
-                goto fail;
-            }
-        } break;
-        
-        case NCDVALUE_MAP: {
-            if (!ExpString_AppendChar(out_str, '[')) {
-                BLog(BLOG_ERROR, "ExpString_AppendChar failed");
-                goto fail;
-            }
-            
-            int is_first = 1;
-            
-            for (NCDValue *ekey = NCDValue_MapFirstKey(value); ekey; ekey = NCDValue_MapNextKey(value, ekey)) {
-                NCDValue *eval = NCDValue_MapKeyValue(value, ekey);
-                
-                if (!is_first) {
-                    if (!ExpString_Append(out_str, ", ")) {
-                        BLog(BLOG_ERROR, "ExpString_Append failed");
-                        goto fail;
-                    }
-                }
-                
-                if (!generate_value(ekey, out_str)) {
-                    goto fail;
-                }
-                
-                if (!ExpString_AppendChar(out_str, ':')) {
-                    BLog(BLOG_ERROR, "ExpString_AppendChar failed");
-                    goto fail;
-                }
-                
-                if (!generate_value(eval, out_str)) {
-                    goto fail;
-                }
-                
-                is_first = 0;
-            }
-            
-            if (!ExpString_AppendChar(out_str, ']')) {
-                BLog(BLOG_ERROR, "ExpString_AppendChar failed");
-                goto fail;
-            }
-        } break;
-        
-        case NCDVALUE_VAR: {
-            if (!ExpString_Append(out_str, NCDValue_VarName(value))) {
-                BLog(BLOG_ERROR, "ExpString_AppendChar failed");
-                goto fail;
-            }
-        } break;
-        
-        default: ASSERT(0);
-    }
-    
-    return 1;
-    
-fail:
-    return 0;
-}
-
 static int generate_val (NCDValRef value, ExpString *out_str)
 static int generate_val (NCDValRef value, ExpString *out_str)
 {
 {
     ASSERT(!NCDVal_IsInvalid(value))
     ASSERT(!NCDVal_IsInvalid(value))
@@ -291,36 +162,6 @@ fail:
     return 0;
     return 0;
 }
 }
 
 
-char * NCDValueGenerator_Generate (NCDValue *value)
-{
-    NCDValue_Type(value);
-    
-    ExpString str;
-    if (!ExpString_Init(&str)) {
-        BLog(BLOG_ERROR, "ExpString_Init failed");
-        goto fail0;
-    }
-    
-    if (!generate_value(value, &str)) {
-        goto fail1;
-    }
-    
-    return ExpString_Get(&str);
-    
-fail1:
-    ExpString_Free(&str);
-fail0:
-    return NULL;
-}
-
-int NCDValueGenerator_AppendGenerate (NCDValue *value, ExpString *str)
-{
-    NCDValue_Type(value);
-    ASSERT(str)
-    
-    return generate_value(value, str);
-}
-
 char * NCDValGenerator_Generate (NCDValRef value)
 char * NCDValGenerator_Generate (NCDValRef value)
 {
 {
     ASSERT(!NCDVal_IsInvalid(value))
     ASSERT(!NCDVal_IsInvalid(value))

+ 0 - 4
ncd/NCDValueGenerator.h

@@ -32,12 +32,8 @@
 
 
 #include <misc/debug.h>
 #include <misc/debug.h>
 #include <misc/expstring.h>
 #include <misc/expstring.h>
-#include <ncd/NCDValue.h>
 #include <ncd/NCDVal.h>
 #include <ncd/NCDVal.h>
 
 
-char * NCDValueGenerator_Generate (NCDValue *value);
-int NCDValueGenerator_AppendGenerate (NCDValue *value, ExpString *str) WARN_UNUSED;
-
 char * NCDValGenerator_Generate (NCDValRef value);
 char * NCDValGenerator_Generate (NCDValRef value);
 int NCDValGenerator_AppendGenerate (NCDValRef value, ExpString *str) WARN_UNUSED;
 int NCDValGenerator_AppendGenerate (NCDValRef value, ExpString *str) WARN_UNUSED;