simplify setcrawl
[henge/apc.git] / src / ir.c
index 341028e..6355654 100644 (file)
--- a/src/ir.c
+++ b/src/ir.c
@@ -666,49 +666,47 @@ static void crawl_set(struct ir_set_t*,int);
 void     ir_test(void)\r
 { uprintf("IR From Directory: %s\n",getcwd(NULL,255));\r
   crawl_class(&root_class);\r
+  if (root_class.root_set != NULL)\r
+    crawl_set(root_class.root_set, 0);\r
 }\r
 \r
-#define pspace(num) for (i = 0; i < (num); i++) putchar('.')\r
 static\r
 void crawl_class\r
 ( struct ir_class_t* class )\r
-{ wprintf("%U/\n", class->name);\r
-  if(chdir((char*)class->name))\r
-    eprintf("CHDIR %U from %s\n",class->name,getcwd(NULL,255));\r
-  if (class->nextchild != NULL)\r
-      crawl_class(class->nextchild);\r
-  if (class->root_set != NULL)\r
-    crawl_set(class->root_set, 0);\r
-  if (class->nextsib != NULL)\r
-    { if (chdir(".."))\r
+{ struct ir_class_t* iter;\r
+  for (iter = class->nextchild; iter != NULL; iter = iter->nextsib)\r
+    { wprintf("%U/\n", iter->name);\r
+      if(chdir((char*)iter->name))\r
+       eprintf("CHDIR %U from %s\n",iter->name,getcwd(NULL,255));\r
+      crawl_class(iter);\r
+      if (iter->root_set != NULL)\r
+        crawl_set(iter->root_set, 0);\r
+      uprintf("%U\\\n",iter->name);\r
+      if (chdir(".."))\r
        eprintf("CHDIR ..\n");\r
-      crawl_class(class->nextsib);\r
-      if(chdir((char*)class->name))\r
-       eprintf("CHDIR %U from %s\n",class->name,getcwd(NULL,255));\r
     }\r
-  uprintf("%U\\\n",class->name);\r
-  if (chdir(".."))\r
-    eprintf("CHDIR ..\n");\r
 }\r
 \r
+#define push_setp(setp) (*(struct ir_set_t**)stack_alloc(sizeof(struct ir_set_t*)) = setp)\r
+#define pop_setp()      (*(struct ir_set_t**)pagelist_pop(&datapages, sizeof(struct ir_set_t*)))\r
 static\r
 void crawl_set\r
 ( struct ir_set_t* set,\r
   int depth\r
 )\r
-{ struct ir_set_t* setlist[64], ** slp, * iter;\r
+{ struct ir_set_t* iter;\r
   int i;\r
-  pspace(depth * 12);\r
+  i = depth * 12;\r
+  while (i--)\r
+    putchar('.');\r
   i = depth;\r
-  slp = setlist;\r
   for(iter = set; iter != NULL; iter = iter->nextchild)\r
     { uprintf("[%10U]", iter->name);\r
-      *slp++ = iter;\r
+      push_setp(iter);\r
       i++;\r
     }\r
-  --i;\r
   putchar('\n');\r
-  for(iter = *--slp; slp >= setlist; iter = *--slp, --i)\r
-    if (iter->nextsib != NULL)\r
+  while (--i >= depth)\r
+    if (((iter = pop_setp())->nextsib) != NULL)\r
       crawl_set(iter->nextsib,i);\r
 }\r