Explorar el Código

ncd: NCDObject: add NCDObject_ResolveObjExprCompact()

ambrop7 hace 13 años
padre
commit
c2674d7077
Se han modificado 2 ficheros con 25 adiciones y 0 borrados
  1. 24 0
      ncd/NCDObject.c
  2. 1 0
      ncd/NCDObject.h

+ 24 - 0
ncd/NCDObject.c

@@ -131,6 +131,30 @@ int NCDObject_ResolveObjExpr (NCDObject *o, char **names, NCDObject *out_object)
     return 1;
     return 1;
 }
 }
 
 
+int NCDObject_ResolveObjExprCompact (NCDObject *o, const char *names, int num_names, NCDObject *out_object)
+{
+    ASSERT(num_names == 0 || names)
+    ASSERT(num_names >= 0)
+    ASSERT(out_object)
+    
+    NCDObject object = dig_into_object(*o);
+    
+    while (num_names > 0) {
+        NCDObject obj2;
+        if (!NCDObject_GetObj(&object, names, &obj2)) {
+            return 0;
+        }
+        
+        object = dig_into_object(obj2);
+        
+        names += strlen(names) + 1;
+        num_names--;
+    }
+    
+    *out_object = object;
+    return 1;
+}
+
 int NCDObject_ResolveVarExpr (NCDObject *o, char **names, NCDValue *out_value)
 int NCDObject_ResolveVarExpr (NCDObject *o, char **names, NCDValue *out_value)
 {
 {
     ASSERT(names)
     ASSERT(names)

+ 1 - 0
ncd/NCDObject.h

@@ -60,6 +60,7 @@ const char * NCDObject_Type (NCDObject *o);
 int NCDObject_GetObj (NCDObject *o, const char *name, NCDObject *out_object) WARN_UNUSED;
 int NCDObject_GetObj (NCDObject *o, const char *name, NCDObject *out_object) WARN_UNUSED;
 int NCDObject_GetVar (NCDObject *o, const char *name, NCDValue *out_value) WARN_UNUSED;
 int NCDObject_GetVar (NCDObject *o, const char *name, NCDValue *out_value) WARN_UNUSED;
 int NCDObject_ResolveObjExpr (NCDObject *o, char **names, NCDObject *out_object) WARN_UNUSED;
 int NCDObject_ResolveObjExpr (NCDObject *o, char **names, NCDObject *out_object) WARN_UNUSED;
+int NCDObject_ResolveObjExprCompact (NCDObject *o, const char *names, int num_names, NCDObject *out_object) WARN_UNUSED;
 int NCDObject_ResolveVarExpr (NCDObject *o, char **names, NCDValue *out_value) WARN_UNUSED;
 int NCDObject_ResolveVarExpr (NCDObject *o, char **names, NCDValue *out_value) WARN_UNUSED;
 
 
 #endif
 #endif