source: git/modules/modgen/creat_top.cc @ 014db1

spielwiese
Last change on this file since 014db1 was 014db1, checked in by Kai Krüger <krueger@…>, 24 years ago
Added trace and debug mode exit on error while parsing\n variable of procedures as declared (same name and type)\n git-svn-id: file:///usr/local/Singular/svn/trunk@4235 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: creat_top.cc,v 1.10 2000-03-30 06:35:44 krueger Exp $ */
5/*
6* ABSTRACT: lib parsing
7*/
8
9#include <mod2.h>
10
11#include "modgen.h"
12extern int yylineno;
13
14void enter_id(FILE *fp, char *name, char *value);
15/*========================================================================*/
16void  mod_copy_tmp(
17  FILE *fp_out,
18  FILE *fp_in
19  )
20{
21  int nread;
22  char buf[1024];
23 
24  fseek(fp_in, 0L, 0);
25  do {
26    memset(buf, 0, sizeof(buf));
27    fgets(buf, sizeof(buf), fp_in);
28    modlineno++;
29    //nread = fread (buf, sizeof (char), sizeof(buf)-1, fp_in);
30    if(strncmp(buf, "#line @d ", 8)==0) {
31      buf[6]='%';
32      fprintf(fp_out, buf, modlineno);
33    }
34    else
35      fwrite(buf, sizeof(char), strlen(buf)/*nread*/, fp_out);
36  } while(!feof(fp_in));
37  fputs("\n", fp_out);
38}
39
40/*========================================================================*/
41void write_enter_id(FILE *fp)
42{
43  fprintf(fp, "\nidhdl enter_id(char *name, char *value, idtyp t)\n");
44  fprintf(fp, "{\n");
45  fprintf(fp, "  idhdl h;\n");
46  fprintf(fp, "\n");
47  fprintf(fp, "  h=enterid(mstrdup(name),0, t, &IDROOT, TRUE/*FALSE*/);\n");
48  fprintf(fp, "  if(h!=NULL) {\n");
49  fprintf(fp, "     switch(t) {\n");
50  fprintf(fp, "         case STRING_CMD: IDSTRING(h) = mstrdup(value);break;\n");
51  fprintf(fp, "         case PACKAGE_CMD: break;\n");
52  fprintf(fp, "         case PROC_CMD: break;\n");
53  fprintf(fp, "     }\n");
54  fprintf(fp, "  } else \n");
55  fprintf(fp, "      Warn(\"Cannot create '%%s'\\n\", name);\n");
56  fprintf(fp, "  return(h);\n");
57  fprintf(fp, "}\n");
58  modlineno+=16;
59}
60
61/*========================================================================*/
62void write_add_singular_proc(FILE *fp)
63{
64  fprintf(fp, "\nidhdl add_singular_proc(char *procname, int line,\n");
65  fprintf(fp, "                       long pos, long end, BOOLEAN pstatic)\n");
66  fprintf(fp, "{\n");
67  fprintf(fp, "  idhdl h;\n");
68  fprintf(fp, "  procinfov pi;\n\n");
69  fprintf(fp, "  h = enter_id(procname, NULL, PROC_CMD);\n");
70  fprintf(fp, "  if(h == NULL) return NULL;\n");
71  fprintf(fp, "\n");
72//  fprintf(fp, "  pi->libname = mstrdup(libname);\n");
73  fprintf(fp, "  pi->procname = mstrdup(procname);\n");
74  fprintf(fp, "  pi->language = LANG_SINGULAR;\n");
75  fprintf(fp, "  pi->ref = 1;\n");
76  fprintf(fp, "  pi->is_static = pstatic;\n");
77  fprintf(fp, "  pi->data.s.proc_start = pos;\n");
78  fprintf(fp, "  pi->data.s.def_end    = pos;\n");
79  fprintf(fp, "  pi->data.s.help_start = 0L;\n");
80  fprintf(fp, "  pi->data.s.help_end   = 0L;\n");
81  fprintf(fp, "  pi->data.s.body_start = pos;\n");
82  fprintf(fp, "  pi->data.s.body_end   = end;\n");
83  fprintf(fp, "  pi->data.s.proc_end   = end;\n");
84  fprintf(fp, "  pi->data.s.example_start = 0L;\n");
85  fprintf(fp, "  pi->data.s.proc_lineno = line;\n");
86  fprintf(fp, "  pi->data.s.body_lineno = line;\n");
87  fprintf(fp, "  pi->data.s.example_lineno = 0;\n");
88  fprintf(fp, "  pi->data.s.body = NULL;\n");
89  fprintf(fp, "  pi->data.s.help_chksum = 0;\n");
90  fprintf(fp, \n");
91  fprintf(fp, "  return(h);\n");
92  fprintf(fp, "}\n");
93  modlineno+=30;
94}
95
96/*========================================================================*/
97void write_mod_init(
98  moddefv module,
99  FILE *fp
100  )
101{
102  fprintf(fp, "\n\n");
103  fprintf(fp, "#line @d \"%s.cc\"\n", module->name);
104  fprintf(fp, "extern \"C\"\n");
105  fprintf(fp, "int mod_init(int(*iiAddCproc)())\n{\n");
106  fprintf(fp, "  idhdl h;\n");
107  fprintf(fp, "  idhdl helphdl = enter_id(\"Help\", NULL, PACKAGE_CMD);\n");
108  fprintf(fp, "  idhdl examplehdl = enter_id(\"Example\", NULL, PACKAGE_CMD);\n\n");
109  fprintf(fp, \n");
110  fprintf(fp, "   if( helphdl == NULL)\n");
111  fprintf(fp, "     Warn(\"Cannot create help-package\\n\");\n");
112  fprintf(fp, "   else fill_help_package(helphdl);\n");
113  fprintf(fp, \n");
114  fprintf(fp, "   if( examplehdl == NULL)\n");
115  fprintf(fp, "     Warn(\"Cannot create example-package\\n\");\n");
116  fprintf(fp, "   else fill_example_package(examplehdl);\n");
117}
118
119/*========================================================================*/
120int write_intro(
121    moddefv module
122    )
123{
124  char filename[512];
125
126  mkdir(module->name, 0755);
127  strcpy(filename, build_filename(module, module->name, 1));
128 
129  fflush(module->fmtfp);
130
131  if( (module->modfp = fopen(filename, "w")) == NULL) {
132    //free(filename);
133    return -1;
134  }
135  if(trace)printf("Creating %s, ", filename);fflush(stdout);
136  mod_write_header(module->modfp, module->name, 'c');
137  mod_copy_tmp(module->modfp, module->fmtfp);
138  if(trace)printf("\n");fflush(stdout);
139  fclose(module->fmtfp);
140  if(create_tmpfile(module)) return -1;
141  if(create_tmpfile(module, 1)) return -1;
142  if(create_tmpfile(module, 2)) return -1;
143  if(module->fmtfp2 == NULL) { printf("Cannot write HELP\n"); return -1; }
144  if(module->fmtfp3 == NULL) { printf("Cannot write EXAMPLE\n"); return -1; }
145 
146  strcpy(filename, build_filename(module, module->name, 2));
147  //sprintf(filename, "%s/%s.h", module->name, module->name);
148  if( (module->modfp_h = fopen(filename, "w")) == NULL) {
149    //free(filename);
150    return -1;
151  }
152  if(trace)printf("Creating %s, ", filename);fflush(stdout);
153  mod_write_header(module->modfp_h, module->name, 'h');
154  if(trace)printf("\n");fflush(stdout);
155
156  //free(filename);
157//  write_enter_id(module->modfp);
158  return 0;
159}
Note: See TracBrowser for help on using the repository browser.