Index: modules/modgen/creat_top.cc
===================================================================
--- modules/modgen/creat_top.cc	(revision f3929a22e27e0ec2f0392fd4d0f481110133cffc)
+++ modules/modgen/creat_top.cc	(revision 66489890b067f36baef258936ca2fe62676920ba)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: creat_top.cc,v 1.5 2000-02-14 21:44:39 krueger Exp $ */
+/* $Id: creat_top.cc,v 1.6 2000-02-18 13:33:47 krueger Exp $ */
 /*
 * ABSTRACT: lib parsing
@@ -32,5 +32,5 @@
 void write_enter_id(FILE *fp)
 {
-  fprintf(fp, "idhdl enter_id(char *name, char *value, idtyp t)\n");
+  fprintf(fp, "\nidhdl enter_id(char *name, char *value, idtyp t)\n");
   fprintf(fp, "{\n");
   fprintf(fp, "  idhdl h;\n");
@@ -39,7 +39,7 @@
   fprintf(fp, "  if(h!=NULL) {\n");
   fprintf(fp, "     switch(t) {\n");
-  fprintf(fp, "       case STRING_CMD: IDSTRING(h) = mstrdup(value);break\n");
-  fprintf(fp, "       case PACKAGE_CMD: break;\n");
-  fprintf(fp, "       case PROC_CMD: break;\n");
+  fprintf(fp, "         case STRING_CMD: IDSTRING(h) = mstrdup(value);break;\n");
+  fprintf(fp, "         case PACKAGE_CMD: break;\n");
+  fprintf(fp, "         case PROC_CMD: break;\n");
   fprintf(fp, "     }\n");
   fprintf(fp, "  }\n");
@@ -51,10 +51,10 @@
 void write_add_singular_proc(FILE *fp)
 {
-  fprintf(fp, "idhdl add_singular_proc(char *procname, int line,\n");
+  fprintf(fp, "\nidhdl add_singular_proc(char *procname, int line,\n");
   fprintf(fp, "                       long pos, long end, BOOLEAN pstatic)\n");
   fprintf(fp, "{\n");
   fprintf(fp, "  idhdl h;\n");
   fprintf(fp, "  procinfov pi;\n\n");
-  fprintf(fp, "  h = enter_id(name, NULL, PROC_CMD);\n");
+  fprintf(fp, "  h = enter_id(procname, NULL, PROC_CMD);\n");
   fprintf(fp, "  if(h == NULL) return NULL;\n");
   fprintf(fp, "\n");
@@ -117,5 +117,11 @@
   fclose(module->fmtfp);
   if(create_tmpfile(module)) return -1;
-
+  if(create_tmpfile(module, 1)) return -1;
+  if(create_tmpfile(module, 2)) return -1;
+  if(module->fmtfp2 == NULL) { printf("Cannot write HELP\n"); return -1; }
+  if(module->fmtfp3 == NULL) { printf("Cannot write EXAMPLE\n"); return -1; }
+  printf("%p %p %p\n", module->fmtfp, module->fmtfp2, module->fmtfp3);
+  
+  
   sprintf(filename, "tmp/%s.h", module->name);
   if( (module->modfp_h = fopen(filename, "w")) == NULL) {
@@ -128,3 +134,4 @@
   free(filename);
 //  write_enter_id(module->modfp);
+  return 0;
 }
Index: modules/modgen/grammar.y
===================================================================
--- modules/modgen/grammar.y	(revision f3929a22e27e0ec2f0392fd4d0f481110133cffc)
+++ modules/modgen/grammar.y	(revision 66489890b067f36baef258936ca2fe62676920ba)
@@ -1,4 +1,4 @@
 /*
- * $Id: grammar.y,v 1.6 2000-02-14 21:41:59 krueger Exp $
+ * $Id: grammar.y,v 1.7 2000-02-18 13:33:47 krueger Exp $
  */
 
@@ -88,6 +88,9 @@
 part1: initmod sect1 sect1end
         {
-         if(write_intro(&module_def))
-           myyyerror("Error while creating files\n");
+          mod_create_makefile(&module_def);
+          if(write_intro(&module_def)) {
+            myyyerror("Error while creating files\n");
+            return 1;
+          }
         };
 
@@ -151,4 +154,5 @@
           switch(sectnum) {
               case 1: /* pass 1: */
+                Add2files(&module_def, $3);
                 break;
               case 2: /* pass 2: procedure declaration */
@@ -231,4 +235,6 @@
         {
           printf(">>>>>>>>files '%s' , '%s'\n", $1, $3);
+          Add2files(&module_def, $1);
+          Add2files(&module_def, $3);
           free($1);
           free($3);
@@ -293,8 +299,10 @@
          {
            write_singular_parameter(&module_def, yylineno, "list", "#");
+           procedure_decl.lineno_other = yylineno;
          }
         | procdecl1 '(' ')'
          {
            write_singular_parameter(&module_def, yylineno, "list", "#");
+           procedure_decl.lineno_other = yylineno;
          }
         ;
@@ -331,5 +339,6 @@
         {
           procedure_decl.help_string = $1;
-          printf("\t\thelp=%p, %d\n", procedure_decl.help_string, strlen($1));
+          printf("\t\thelp at %d\n", yylineno);
+          write_help(&module_def, &procedure_decl);
         }
         ;
@@ -353,41 +362,42 @@
         };
 
-procdeclexample: EXAMPLETOK '{' examplecodeline MCODETOK
-        {
-          printf("Example\n");
-          if(procedure_decl.procname != NULL) {
-            //write_example(&module_def, &procedure_decl);
-          } else {
+procdeclexample: examplestart '{' examplecodeline MCODETOK
+        {
+          write_example(&module_def, &procedure_decl);
+        }
+        ;
+
+examplestart: EXAMPLETOK
+        {
+          if(procedure_decl.procname == NULL) {
             myyyerror("example without proc-declaration at line %d\n",
                      yylineno);
           }
-        }
-        ;
-
+          printf("Example at %d\n", yylineno);
+          procedure_decl.lineno_other = yylineno;
+        };
+  
 examplecodeline: CODEPART
         {
-          printf(">>1\n");
-          procedure_decl.example_len = strlen($1);
-          procedure_decl.example_string = (char *)malloc(strlen($1)+1);
-          memset(procedure_decl.example_string, 0, strlen($1)+1);
-          memcpy(procedure_decl.example_string, $1, strlen($1));
+          int len = strlen($1);
+          procedure_decl.example_len = len;
+          procedure_decl.example_string = (char *)malloc(len+1);
+          memset(procedure_decl.example_string, 0, len+1);
+          memcpy(procedure_decl.example_string, $1, len);
         }
         | examplecodeline CODEPART
         {
-          long newlen = procedure_decl.example_len + strlen($2);
-          //procedure_decl.example_len += strlen($2);
-          printf(">>2 (%d+%d) %p\n", procedure_decl.example_len, strlen($2),
-                 procedure_decl.example_string);
+          long len = strlen($2);
+          long newlen = procedure_decl.example_len + len;
+          
           procedure_decl.example_string =
-            (char *)realloc((void *)procedure_decl.example_string, newlen);
-          printf(">>2 (%d)\n", procedure_decl.example_len);
+            (char *)realloc((void *)procedure_decl.example_string, newlen+1);
           memset(procedure_decl.example_string+procedure_decl.example_len,
-                 0, strlen($2));
+                 0, len+1);
           memcpy(procedure_decl.example_string+procedure_decl.example_len,
-                 $2, strlen($2));
-          
+                 $2, len);
+          procedure_decl.example_len = newlen;
           //strncat(procedure_decl.example_string, $2, strlen($2));
           //procedure_decl.example_string[procedure_decl.example_len] = '\0';
-          printf(">>2b\n");
         };
 
Index: modules/modgen/makefile.cc
===================================================================
--- modules/modgen/makefile.cc	(revision f3929a22e27e0ec2f0392fd4d0f481110133cffc)
+++ modules/modgen/makefile.cc	(revision 66489890b067f36baef258936ca2fe62676920ba)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: makefile.cc,v 1.1 1999-11-23 21:30:21 krueger Exp $ */
+/* $Id: makefile.cc,v 1.2 2000-02-18 13:33:48 krueger Exp $ */
 /*
 * ABSTRACT: lib parsing
@@ -22,9 +22,17 @@
 #include "pathnames.h"
 
-void build_head_section(FILE *fp, moddefv module);
-void build_compile_section(FILE *fp, moddefv module);
-void build_clean_section(FILE *fp, moddefv module);
-void build_install_section(FILE *fp, moddefv module);
+extern void mod_create_makefile(moddefv module);
+extern void build_head_section(FILE *fp, moddefv module);
+extern void build_clean_section(FILE *fp, moddefv module);
+extern void build_install_section(FILE *fp, moddefv module);
+extern void build_compile_section(FILE *fp, moddefv module);
+
 static char *object_name(char *p);
+/*========================================================================*/
+/*
+  run mod_create_makefile();
+   
+ */
+/*========================================================================*/
 
 
@@ -33,5 +41,5 @@
 {
   FILE *fp;
-  fp = fopen("Makefile", "w");
+  fp = fopen("tmp/Makefile", "w");
   cfilesv cf = module->files;
   int i;
@@ -40,12 +48,12 @@
   write_header(fp, module->name, "#");
   build_head_section(fp, module);
-  fprintf(fp, "SRCS\t= ");
+  fprintf(fp, "SRCS\t= %s.cc", module->name);
   
   for(i=0; i<module->filecnt; i++)
-    fprintf(fp, "%s ", cf[i].filename);
-
-  fprintf(fp, "\nOBJS\t= ");
+    fprintf(fp, " %s", cf[i].filename);
+
+  fprintf(fp, "\nOBJS\t= %s.o", module->name);
   for(i=0; i<module->filecnt; i++)
-    fprintf(fp, "%s ", object_name(cf[i].filename));
+    fprintf(fp, " %s", object_name(cf[i].filename));
 
   fprintf(fp, "\n\n");
@@ -69,5 +77,5 @@
   fprintf(fp, "CC\t= gcc\n");
   fprintf(fp, "CXX\t= gcc\n");
-  fprintf(fp, "CFLAGS\t= -DNDEBUG -DBUILD_MODULE -I. -I../include\n");
+  fprintf(fp, "CFLAGS\t= -DNDEBUG -DBUILD_MODULE -I. -I../../include\n");
   fprintf(fp, "#LD\t=\n");
   fprintf(fp, "\n");
@@ -163,5 +171,5 @@
 
 /*========================================================================*/
-#  ifdef 68k_MPW
+#  ifdef m68k_MPW
 void build_compile_section(
   FILE *fp,
Index: modules/modgen/modgen.h
===================================================================
--- modules/modgen/modgen.h	(revision f3929a22e27e0ec2f0392fd4d0f481110133cffc)
+++ modules/modgen/modgen.h	(revision 66489890b067f36baef258936ca2fe62676920ba)
@@ -1,4 +1,4 @@
 /*
- *  $Id: modgen.h,v 1.6 2000-02-14 21:43:32 krueger Exp $
+ *  $Id: modgen.h,v 1.7 2000-02-18 13:33:48 krueger Exp $
  *
  */
@@ -52,4 +52,5 @@
   language_defs language;
   int          lineno;
+  int          lineno_other;
   int          is_static;
   paramdef     return_val;
@@ -76,4 +77,6 @@
   FILE * modfp_h;         /* header file */
   FILE * fmtfp;           /* temporary file */
+  FILE * fmtfp2;          /* temporary file */
+  FILE * fmtfp3;          /* temporary file */
   FILE * binfp;           /* include singular procedures are stored
                              in an extra file */
@@ -138,5 +141,14 @@
 void AddParam(procdefv p, paramdefv vnew, char *name = NULL);
 
-extern int create_tmpfile(moddefv module_def);
+/* from makefile.cc */
+extern void mod_create_makefile(moddefv module);
+extern void build_head_section(FILE *fp, moddefv module);
+extern void build_clean_section(FILE *fp, moddefv module);
+extern void build_install_section(FILE *fp, moddefv module);
+static char *object_name(char *p);
+extern void build_compile_section(FILE *fp, moddefv module);
+
+/* from utils.cc */
+extern int create_tmpfile(moddefv module_def, int which = 0);
 
 /* from proc_setup.cc */
@@ -144,6 +156,4 @@
 
 /* from proc.cc */
-extern void write_example(moddefv module, procdefv proc);
-
 extern void write_procedure_typecheck(moddefv module, procdefv pi, FILE *fmtfp);
 extern void write_procedure_return(moddefv module, procdefv pi, FILE *fmtfp);
@@ -152,4 +162,6 @@
 extern void write_function_return(moddefv module, procdefv pi, void *arg = NULL);
 extern void write_function_errorhandling(moddefv module, procdefv pi);
+extern void write_help(moddefv module, procdefv pi);
+extern void write_example(moddefv module, procdefv pi);
 extern int  write_singular_procedures(moddefv module, procdefv proc);
 extern void write_singular_parameter(moddefv module,int lineno,
Index: modules/modgen/proc.cc
===================================================================
--- modules/modgen/proc.cc	(revision f3929a22e27e0ec2f0392fd4d0f481110133cffc)
+++ modules/modgen/proc.cc	(revision 66489890b067f36baef258936ca2fe62676920ba)
@@ -1,4 +1,4 @@
 /*
- * $Id: proc.cc,v 1.6 2000-02-14 21:44:40 krueger Exp $
+ * $Id: proc.cc,v 1.7 2000-02-18 13:33:48 krueger Exp $
  */
 
@@ -51,5 +51,4 @@
         }
   
-        printf("iiAddCproc %s is C\n", proc->procname);
         /* write call to add procname to list */
         fprintf(module->modfp, "  iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n",
@@ -57,10 +56,18 @@
                 proc->is_static ? "TRUE" : "FALSE",
                 proc->procname);
+        
         if(proc->help_string!=NULL) {
-          fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(helphdl) ,");
-          fprintf(module->modfp, " IDID(helphdl));\n");
-          fprintf(module->modfp, "  enter_id(\"%s\",", proc->procname);
-          fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->help_string);
-          fprintf(module->modfp, "  namespaceroot->push();\n");
+          printf("WRITE HELP\n");
+//          fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(helphdl) ,");
+//          fprintf(module->modfp, " IDID(helphdl));\n");
+          fprintf(module->fmtfp2, "  enter_id(\"%s\",", proc->procname);
+          fprintf(module->fmtfp2, " \"%s\", STRING_CMD);\n", proc->help_string);
+//          fprintf(module->modfp, "  namespaceroot->push();\n");
+        }
+        if(proc->example_string!=NULL) {
+          printf("WRITE EXAMPLE\n");
+          fprintf(module->fmtfp3, "  enter_id(\"%s\",", proc->procname);
+          fprintf(module->fmtfp3, " \"%s\", STRING_CMD);\n",
+                  proc->example_string);
         }
         fprintf(module->modfp, "\n");
@@ -73,5 +80,5 @@
       case LANG_SINGULAR:
         fprintf(module->modfp,
-                "  h = add_singular_proc(%s, %d, %ld, %ld, %s);\n",
+                "  h = add_singular_proc(\"%s\", %d, %ld, %ld, %s);\n",
                 proc->procname, proc->lineno,
                 proc->sing_start, proc->sing_end,
@@ -83,21 +90,4 @@
 }
 
-/*========================================================================*/
-void write_example(
-  moddefv module,
-  procdefv proc
-  )
-{
-  /* if proc is NULL, just return */
-  if( proc == NULL ) return;
-
-  if(proc->example_string!=NULL) {
-    fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(examplehdl) ,");
-    fprintf(module->modfp, " IDID(examplehdl));\n");
-    fprintf(module->modfp, "  enter_id(\"%s\",", proc->procname);
-    fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->example_string);
-    fprintf(module->modfp, "  namespaceroot->push();\n");
-  }
-}
 /*========================================================================*/
 /*
@@ -265,8 +255,16 @@
   fprintf(module->modfp, "  return 0;\n}\n\n");
   fflush(module->modfp);
-  
+
+  fprintf(module->modfp, "#if 0 /* Help section */\n");
+  mod_copy_tmp(module->modfp, module->fmtfp2);
+  fprintf(module->modfp, "#endif /* End of Help section */\n\n");
+  fprintf(module->modfp, "#if 0 /* Example section */\n");
+  mod_copy_tmp(module->modfp, module->fmtfp3);
+  fprintf(module->modfp, "#endif /* End of Example section */\n\n");
   mod_copy_tmp(module->modfp, module->fmtfp);
   printf("  done.\n");fflush(stdout);
   fclose(module->fmtfp);
+  fclose(module->fmtfp2);
+  fclose(module->fmtfp3);
   return;
 }
@@ -402,5 +400,46 @@
         break;
   }
-  
+}
+
+/*========================================================================*/
+void write_help(
+  moddefv module,
+  procdefv pi
+  )
+{
+  if(pi->help_string!=NULL) {
+    fprintf(module->fmtfp2, "#line %d \"%s\"\n", pi->lineno_other,
+            module->filename);
+//     fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(helphdl) ,");
+//     fprintf(module->modfp, " IDID(helphdl));\n");
+    fprintf(module->fmtfp2, "  enter_id(\"%s\",", pi->procname);
+    fprintf(module->fmtfp2, " \"%s\", STRING_CMD);\n\n", pi->help_string);
+//     fprintf(module->modfp, "  namespaceroot->push();\n");
+  }
+}
+
+/*========================================================================*/
+void write_example(
+  moddefv module,
+  procdefv pi
+  )
+{
+  /* if proc is NULL, just return */
+  if( pi == NULL ) return;
+
+  if(pi->example_string!=NULL) {
+    fprintf(module->fmtfp3, "#line %d \"%s\"\n", pi->lineno_other,
+            module->filename);
+    fprintf(module->fmtfp3, "  enter_id(\"%s\",\n", pi->procname);
+    fprintf(module->fmtfp3, " \"%s\", STRING_CMD);\n\n", pi->example_string);
+  }
+  
+#if 0
+    fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(examplehdl) ,");
+    fprintf(module->modfp, " IDID(examplehdl));\n");
+    fprintf(module->modfp, "  enter_id(\"%s\",", proc->procname);
+    fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->example_string);
+    fprintf(module->modfp, "  namespaceroot->push();\n");
+#endif
 }
 
Index: modules/modgen/scanner.l
===================================================================
--- modules/modgen/scanner.l	(revision f3929a22e27e0ec2f0392fd4d0f481110133cffc)
+++ modules/modgen/scanner.l	(revision 66489890b067f36baef258936ca2fe62676920ba)
@@ -3,5 +3,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: scanner.l,v 1.6 2000-02-14 21:47:10 krueger Exp $ */
+/* $Id: scanner.l,v 1.7 2000-02-18 13:33:49 krueger Exp $ */
 #include <stdio.h>
 #include <string.h>
@@ -13,5 +13,5 @@
 #include "grammar.h"
 
-#define DEBUG 3
+/* #define DEBUG 3 */
  
 #  define YYLP_ERR_NONE    0
@@ -49,5 +49,5 @@
   int read_string(char **buffer, long *start, long end);
   int libread(FILE* f, char* buf, int max_size);
-  add_action(char *new_text);
+  void add_action(char *new_text);
  
   void push_state(int state, int new_state, char *name);
@@ -231,6 +231,6 @@
 
 <COMMENT>{
-        "*/"            /*ACTION_ECHO;*/ pop_state(); yymore();
-        "*"             /*ACTION_ECHO;*/ yymore();
+        "*/"            ACTION_ECHO; pop_state(); yymore();
+        "*"             ACTION_ECHO; yymore();
         {NL}          { yylineno++; yymore(); }
         .             { yymore(); }
@@ -261,5 +261,7 @@
                 }
         example {
+#if DEBUG > 1
 	          printf(">>>EXAMPLE\n");
+#endif
                   brace1 = 0; /* { */
                   brace2 = 0; /* ( */
@@ -389,5 +391,4 @@
                    } else {
                      yymore();
-                     /*yylineno++;*/
 		   }
                  }
@@ -484,7 +485,17 @@
 }
 
-add_action(char *new_text)
+void add_action(char *new_text)
 {
-
-   printf("%s", new_text);
-}
+  return;
+  switch(sectnum) {
+    case 1:
+      printf("1>%s", new_text);
+      break;
+    case 2:
+      printf("2>%s", new_text);
+      break;
+    case 3:
+      printf("3>%s", new_text);
+      break;
+  }
+}
Index: modules/modgen/utils.cc
===================================================================
--- modules/modgen/utils.cc	(revision f3929a22e27e0ec2f0392fd4d0f481110133cffc)
+++ modules/modgen/utils.cc	(revision 66489890b067f36baef258936ca2fe62676920ba)
@@ -1,4 +1,4 @@
 /*
- * $Id: utils.cc,v 1.4 2000-01-27 12:40:53 krueger Exp $
+ * $Id: utils.cc,v 1.5 2000-02-18 13:33:49 krueger Exp $
  */
 
@@ -46,17 +46,21 @@
 /*========================================================================*/
 int create_tmpfile(
-  moddefv module_def
+  moddefv module_def,
+  int which
 )
 {
   char tmpfile[64];
-
+  FILE *fp;
+  
   memset(tmpfile, '\0', sizeof(tmpfile));
   snprintf(tmpfile, sizeof(tmpfile), "tmp/modgen.tmpXXXXXX");
   mktemp(tmpfile);
 
+  printf("create_tmpfile (%d\n", which );
+  
   if (close(creat(tmpfile, 0600)) < 0) {
     (void) unlink (tmpfile);        /*  Blow it away!!  */
     return -1;
-  } else if ((module_def->fmtfp = fopen(tmpfile, "a+")) == NULL) {
+  } else if ((fp = fopen(tmpfile, "a+")) == NULL) {
     (void) unlink (tmpfile);        /*  Blow it away!!  */
     return -1;
@@ -64,6 +68,16 @@
     (void) unlink (tmpfile); /* delete now to avoid turds... */
   }
+
+  printf("2)create_tmpfile (%d\n", which );
+  switch(which) {
+      case 0: module_def->fmtfp  = fp; break;
+      case 1: module_def->fmtfp2 = fp; break;
+      case 2: module_def->fmtfp3 = fp; break;
+      default:
+        fclose(fp);
+        return -1;
+  }
+  
   return 0;
-  
 }
 
