misc: remove GNU Indent directives
[vpp.git] / src / vppinfra / macros.c
index bc6df55..b8644b2 100644 (file)
@@ -40,7 +40,7 @@ builtin_eval (clib_macro_main_t * mm, i8 * varname, i32 complain)
   return (*fp) (mm, complain);
 }
 
-int
+__clib_export int
 clib_macro_unset (clib_macro_main_t * mm, char *name)
 {
   hash_pair_t *p;
@@ -60,7 +60,7 @@ clib_macro_unset (clib_macro_main_t * mm, char *name)
   return 0;
 }
 
-int
+__clib_export int
 clib_macro_set_value (clib_macro_main_t * mm, char *name, char *value)
 {
   u8 *key_copy, *value_copy;
@@ -91,13 +91,21 @@ clib_macro_get_value (clib_macro_main_t * mm, char *name)
  * eval: takes a string, returns a vector.
  * looks up $foobar in the variable table.
  */
-i8 *
-clib_macro_eval (clib_macro_main_t * mm, i8 * s, i32 complain)
+__clib_export i8 *
+clib_macro_eval (clib_macro_main_t * mm, i8 * s, i32 complain, u16 level,
+                u16 max_level)
 {
   i8 *rv = 0;
   i8 *varname, *varvalue;
   i8 *ts;
 
+  if (level >= max_level)
+    {
+      if (complain)
+       clib_warning ("circular definition, level %d", level);
+      return (i8 *) format (0, " CIRCULAR ");
+    }
+
   while (*s)
     {
       switch (*s)
@@ -161,12 +169,13 @@ clib_macro_eval (clib_macro_main_t * mm, i8 * s, i32 complain)
          if (varvalue)
            {
              /* recursively evaluate */
-             ts = clib_macro_eval (mm, varvalue, complain);
+             ts = clib_macro_eval (mm, varvalue, complain, level + 1,
+                                   max_level);
              vec_free (varvalue);
              /* add results to answer */
              vec_append (rv, ts);
              /* Remove NULL termination or the results are sad */
-             _vec_len (rv) = vec_len (rv) - 1;
+             vec_set_len (rv, vec_len (rv) - 1);
              vec_free (ts);
            }
          else
@@ -174,8 +183,7 @@ clib_macro_eval (clib_macro_main_t * mm, i8 * s, i32 complain)
              if (complain)
                clib_warning ("Undefined Variable Reference: %s\n", varname);
              vec_append (rv, format (0, "UNSET "));
-             _vec_len (rv) = vec_len (rv) - 1;
-
+             vec_set_len (rv, vec_len (rv) - 1);
            }
          vec_free (varname);
        }
@@ -188,19 +196,19 @@ clib_macro_eval (clib_macro_main_t * mm, i8 * s, i32 complain)
  * eval: takes a string, returns a vector.
  * looks up $foobar in the variable table.
  */
-i8 *
-clib_macro_eval_dollar (clib_macro_main_t * mm, i8 * s, i32 complain)
+__clib_export i8 *
+clib_macro_eval_dollar (clib_macro_main_t *mm, i8 *s, i32 complain)
 {
   i8 *s2;
   i8 *rv;
 
   s2 = (i8 *) format (0, "$(%s)%c", s, 0);
-  rv = clib_macro_eval (mm, s2, complain);
+  rv = clib_macro_eval (mm, s2, complain, 0 /* level */ , 8 /* max_level */ );
   vec_free (s2);
   return (rv);
 }
 
-void
+__clib_export void
 clib_macro_add_builtin (clib_macro_main_t * mm, char *name, void *eval_fn)
 {
   hash_set_mem (mm->the_builtin_eval_hash, name, (uword) eval_fn);
@@ -217,7 +225,7 @@ eval_hostname (clib_macro_main_t * mm, i32 complain)
 }
 #endif
 
-void
+__clib_export void
 clib_macro_init (clib_macro_main_t * mm)
 {
   if (mm->the_builtin_eval_hash != 0)
@@ -234,7 +242,7 @@ clib_macro_init (clib_macro_main_t * mm)
 #endif
 }
 
-void
+__clib_export void
 clib_macro_free (clib_macro_main_t * mm)
 {
   hash_pair_t *p;
@@ -243,13 +251,11 @@ clib_macro_free (clib_macro_main_t * mm)
 
   hash_free (mm->the_builtin_eval_hash);
 
-  /* *INDENT-OFF* */
   hash_foreach_pair (p, mm->the_value_table_hash,
   ({
     vec_add1 (strings_to_free, (u8 *) (p->key));
     vec_add1 (strings_to_free, (u8 *) (p->value[0]));
   }));
-  /* *INDENT-ON* */
 
   for (i = 0; i < vec_len (strings_to_free); i++)
     vec_free (strings_to_free[i]);
@@ -273,7 +279,7 @@ name_compare (void *a1, void *a2)
 }
 
 
-u8 *
+__clib_export u8 *
 format_clib_macro_main (u8 * s, va_list * args)
 {
   clib_macro_main_t *mm = va_arg (*args, clib_macro_main_t *);
@@ -282,14 +288,12 @@ format_clib_macro_main (u8 * s, va_list * args)
   name_sort_t *nses = 0, *ns;
   int i;
 
-  /* *INDENT-OFF* */
   hash_foreach_pair (p, mm->the_value_table_hash,
   ({
     vec_add2 (nses, ns, 1);
     ns->name = (u8 *)(p->key);
     ns->value = (u8 *)(p->value[0]);
   }));
-  /* *INDENT-ON* */
 
   if (vec_len (nses) == 0)
     return s;