A quad is now a file
[henge/webcc.git] / src / apc / irmem.c
index 28234d8..958910d 100644 (file)
@@ -29,8 +29,6 @@ struct set*
 curr_set(void);
 struct ref*
 prev_ref(void);
-struct quad
-curr_quad(void);
 struct model
 curr_model(void);
 void
@@ -48,10 +46,10 @@ inc_posts(void);
 #define CURR_MODEL (CURR_VDAT->model_list[CURR_VDAT->num_models])
 #define CURR_LINK (link_buf[num_links])
 #define CURR_POST (post_buf[num_posts])
-#define CURR_QUAD (CURR_ODAT->quad_list[CURR_ODAT->num_quads])
+#define CURR_QUAD (CURR_ODAT->quad_file)
 
 
-int num_cdats = -1;
+int num_cdats = 0;
 int curr_max_cdats = PTRS_IN_PAGE;
 
 struct cdat* cdat_buf[PTRS_IN_PAGE];
@@ -85,20 +83,54 @@ struct link* link_buf[PTRS_IN_PAGE];
 
 
 /* The initalization function of the IR. */
-void
+int
 ir_init()
 {
 
   /* Init root cdat and stack */
   char root[4] = "root";
 
-  cdat_buf[num_cdats] = (struct cdat*) malloc(sizeof(struct cdat) );
-  cdat_buf[num_cdats]->idx = 0;
+  if( (cdat_buf[num_cdats] = (struct cdat*) malloc(sizeof(struct cdat))) == NULL)
+    {
+      perror("malloc root class failed\n");
+      return -1;
+    }
+  cdat_buf[num_cdats]->idx = num_cdats;
   memmove(cdat_buf[num_cdats]->name, root, 4);
 
   cdat_stackp = cdat_stack;
   *cdat_stackp++ = cdat_buf[num_cdats++];
 
+    return 0;
+
+}
+
+void
+ir_quit()
+{
+  int i;
+
+  for(i = 0; i <= num_odats ; i++)
+    {
+      free(odat_buf[i]);
+    }
+  for(i = 0; i <= num_cdats; i++)
+    {
+      free(cdat_buf[i]);
+    }
+  for(i = 0; i <= num_vdats; i++)
+    {
+      free(vdat_buf[i]);
+    }
+  for(i = 0; i <= num_refs; i++)
+    {
+      free(ref_buf[i]);
+    }
+  for(i = 0; i<= num_links; i++)
+    {
+      free(link_buf[i]);
+    }
+
 }
 
 //TODO: FREE MEMORY!
@@ -240,13 +272,6 @@ prev_ref
 {
   return PREV_REF;
 }
-
-struct quad
-curr_quad
-()
-{
-  return CURR_QUAD;
-}
 struct model
 curr_model
 ()