- Timestamp:
- Feb 18, 2000, 2:33:49 PM (24 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- e6189d7d94063f84c1afeb64ccf22c4873faa388
- Parents:
- f3929a22e27e0ec2f0392fd4d0f481110133cffc
- Location:
- modules/modgen
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/modgen/creat_top.cc
rf3929a r664898 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: creat_top.cc,v 1. 5 2000-02-14 21:44:39krueger Exp $ */4 /* $Id: creat_top.cc,v 1.6 2000-02-18 13:33:47 krueger Exp $ */ 5 5 /* 6 6 * ABSTRACT: lib parsing … … 32 32 void write_enter_id(FILE *fp) 33 33 { 34 fprintf(fp, " idhdl enter_id(char *name, char *value, idtyp t)\n");34 fprintf(fp, "\nidhdl enter_id(char *name, char *value, idtyp t)\n"); 35 35 fprintf(fp, "{\n"); 36 36 fprintf(fp, " idhdl h;\n"); … … 39 39 fprintf(fp, " if(h!=NULL) {\n"); 40 40 fprintf(fp, " switch(t) {\n"); 41 fprintf(fp, " case STRING_CMD: IDSTRING(h) = mstrdup(value);break\n");42 fprintf(fp, " case PACKAGE_CMD: break;\n");43 fprintf(fp, " case PROC_CMD: break;\n");41 fprintf(fp, " case STRING_CMD: IDSTRING(h) = mstrdup(value);break;\n"); 42 fprintf(fp, " case PACKAGE_CMD: break;\n"); 43 fprintf(fp, " case PROC_CMD: break;\n"); 44 44 fprintf(fp, " }\n"); 45 45 fprintf(fp, " }\n"); … … 51 51 void write_add_singular_proc(FILE *fp) 52 52 { 53 fprintf(fp, " idhdl add_singular_proc(char *procname, int line,\n");53 fprintf(fp, "\nidhdl add_singular_proc(char *procname, int line,\n"); 54 54 fprintf(fp, " long pos, long end, BOOLEAN pstatic)\n"); 55 55 fprintf(fp, "{\n"); 56 56 fprintf(fp, " idhdl h;\n"); 57 57 fprintf(fp, " procinfov pi;\n\n"); 58 fprintf(fp, " h = enter_id( name, NULL, PROC_CMD);\n");58 fprintf(fp, " h = enter_id(procname, NULL, PROC_CMD);\n"); 59 59 fprintf(fp, " if(h == NULL) return NULL;\n"); 60 60 fprintf(fp, "\n"); … … 117 117 fclose(module->fmtfp); 118 118 if(create_tmpfile(module)) return -1; 119 119 if(create_tmpfile(module, 1)) return -1; 120 if(create_tmpfile(module, 2)) return -1; 121 if(module->fmtfp2 == NULL) { printf("Cannot write HELP\n"); return -1; } 122 if(module->fmtfp3 == NULL) { printf("Cannot write EXAMPLE\n"); return -1; } 123 printf("%p %p %p\n", module->fmtfp, module->fmtfp2, module->fmtfp3); 124 125 120 126 sprintf(filename, "tmp/%s.h", module->name); 121 127 if( (module->modfp_h = fopen(filename, "w")) == NULL) { … … 128 134 free(filename); 129 135 // write_enter_id(module->modfp); 136 return 0; 130 137 } -
modules/modgen/grammar.y
rf3929a r664898 1 1 /* 2 * $Id: grammar.y,v 1. 6 2000-02-14 21:41:59krueger Exp $2 * $Id: grammar.y,v 1.7 2000-02-18 13:33:47 krueger Exp $ 3 3 */ 4 4 … … 88 88 part1: initmod sect1 sect1end 89 89 { 90 if(write_intro(&module_def)) 91 myyyerror("Error while creating files\n"); 90 mod_create_makefile(&module_def); 91 if(write_intro(&module_def)) { 92 myyyerror("Error while creating files\n"); 93 return 1; 94 } 92 95 }; 93 96 … … 151 154 switch(sectnum) { 152 155 case 1: /* pass 1: */ 156 Add2files(&module_def, $3); 153 157 break; 154 158 case 2: /* pass 2: procedure declaration */ … … 231 235 { 232 236 printf(">>>>>>>>files '%s' , '%s'\n", $1, $3); 237 Add2files(&module_def, $1); 238 Add2files(&module_def, $3); 233 239 free($1); 234 240 free($3); … … 293 299 { 294 300 write_singular_parameter(&module_def, yylineno, "list", "#"); 301 procedure_decl.lineno_other = yylineno; 295 302 } 296 303 | procdecl1 '(' ')' 297 304 { 298 305 write_singular_parameter(&module_def, yylineno, "list", "#"); 306 procedure_decl.lineno_other = yylineno; 299 307 } 300 308 ; … … 331 339 { 332 340 procedure_decl.help_string = $1; 333 printf("\t\thelp=%p, %d\n", procedure_decl.help_string, strlen($1)); 341 printf("\t\thelp at %d\n", yylineno); 342 write_help(&module_def, &procedure_decl); 334 343 } 335 344 ; … … 353 362 }; 354 363 355 procdeclexample: EXAMPLETOK '{' examplecodeline MCODETOK 356 { 357 printf("Example\n"); 358 if(procedure_decl.procname != NULL) { 359 //write_example(&module_def, &procedure_decl); 360 } else { 364 procdeclexample: examplestart '{' examplecodeline MCODETOK 365 { 366 write_example(&module_def, &procedure_decl); 367 } 368 ; 369 370 examplestart: EXAMPLETOK 371 { 372 if(procedure_decl.procname == NULL) { 361 373 myyyerror("example without proc-declaration at line %d\n", 362 374 yylineno); 363 375 } 364 } 365 ; 366 376 printf("Example at %d\n", yylineno); 377 procedure_decl.lineno_other = yylineno; 378 }; 379 367 380 examplecodeline: CODEPART 368 381 { 369 printf(">>1\n");370 procedure_decl.example_len = strlen($1);371 procedure_decl.example_string = (char *)malloc( strlen($1)+1);372 memset(procedure_decl.example_string, 0, strlen($1)+1);373 memcpy(procedure_decl.example_string, $1, strlen($1));382 int len = strlen($1); 383 procedure_decl.example_len = len; 384 procedure_decl.example_string = (char *)malloc(len+1); 385 memset(procedure_decl.example_string, 0, len+1); 386 memcpy(procedure_decl.example_string, $1, len); 374 387 } 375 388 | examplecodeline CODEPART 376 389 { 377 long newlen = procedure_decl.example_len + strlen($2); 378 //procedure_decl.example_len += strlen($2); 379 printf(">>2 (%d+%d) %p\n", procedure_decl.example_len, strlen($2), 380 procedure_decl.example_string); 390 long len = strlen($2); 391 long newlen = procedure_decl.example_len + len; 392 381 393 procedure_decl.example_string = 382 (char *)realloc((void *)procedure_decl.example_string, newlen); 383 printf(">>2 (%d)\n", procedure_decl.example_len); 394 (char *)realloc((void *)procedure_decl.example_string, newlen+1); 384 395 memset(procedure_decl.example_string+procedure_decl.example_len, 385 0, strlen($2));396 0, len+1); 386 397 memcpy(procedure_decl.example_string+procedure_decl.example_len, 387 $2, strlen($2));388 398 $2, len); 399 procedure_decl.example_len = newlen; 389 400 //strncat(procedure_decl.example_string, $2, strlen($2)); 390 401 //procedure_decl.example_string[procedure_decl.example_len] = '\0'; 391 printf(">>2b\n");392 402 }; 393 403 -
modules/modgen/makefile.cc
rf3929a r664898 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: makefile.cc,v 1. 1 1999-11-23 21:30:21krueger Exp $ */4 /* $Id: makefile.cc,v 1.2 2000-02-18 13:33:48 krueger Exp $ */ 5 5 /* 6 6 * ABSTRACT: lib parsing … … 22 22 #include "pathnames.h" 23 23 24 void build_head_section(FILE *fp, moddefv module); 25 void build_compile_section(FILE *fp, moddefv module); 26 void build_clean_section(FILE *fp, moddefv module); 27 void build_install_section(FILE *fp, moddefv module); 24 extern void mod_create_makefile(moddefv module); 25 extern void build_head_section(FILE *fp, moddefv module); 26 extern void build_clean_section(FILE *fp, moddefv module); 27 extern void build_install_section(FILE *fp, moddefv module); 28 extern void build_compile_section(FILE *fp, moddefv module); 29 28 30 static char *object_name(char *p); 31 /*========================================================================*/ 32 /* 33 run mod_create_makefile(); 34 35 */ 36 /*========================================================================*/ 29 37 30 38 … … 33 41 { 34 42 FILE *fp; 35 fp = fopen(" Makefile", "w");43 fp = fopen("tmp/Makefile", "w"); 36 44 cfilesv cf = module->files; 37 45 int i; … … 40 48 write_header(fp, module->name, "#"); 41 49 build_head_section(fp, module); 42 fprintf(fp, "SRCS\t= ");50 fprintf(fp, "SRCS\t= %s.cc", module->name); 43 51 44 52 for(i=0; i<module->filecnt; i++) 45 fprintf(fp, " %s", cf[i].filename);46 47 fprintf(fp, "\nOBJS\t= ");53 fprintf(fp, " %s", cf[i].filename); 54 55 fprintf(fp, "\nOBJS\t= %s.o", module->name); 48 56 for(i=0; i<module->filecnt; i++) 49 fprintf(fp, " %s", object_name(cf[i].filename));57 fprintf(fp, " %s", object_name(cf[i].filename)); 50 58 51 59 fprintf(fp, "\n\n"); … … 69 77 fprintf(fp, "CC\t= gcc\n"); 70 78 fprintf(fp, "CXX\t= gcc\n"); 71 fprintf(fp, "CFLAGS\t= -DNDEBUG -DBUILD_MODULE -I. -I../ include\n");79 fprintf(fp, "CFLAGS\t= -DNDEBUG -DBUILD_MODULE -I. -I../../include\n"); 72 80 fprintf(fp, "#LD\t=\n"); 73 81 fprintf(fp, "\n"); … … 163 171 164 172 /*========================================================================*/ 165 # ifdef 68k_MPW173 # ifdef m68k_MPW 166 174 void build_compile_section( 167 175 FILE *fp, -
modules/modgen/modgen.h
rf3929a r664898 1 1 /* 2 * $Id: modgen.h,v 1. 6 2000-02-14 21:43:32krueger Exp $2 * $Id: modgen.h,v 1.7 2000-02-18 13:33:48 krueger Exp $ 3 3 * 4 4 */ … … 52 52 language_defs language; 53 53 int lineno; 54 int lineno_other; 54 55 int is_static; 55 56 paramdef return_val; … … 76 77 FILE * modfp_h; /* header file */ 77 78 FILE * fmtfp; /* temporary file */ 79 FILE * fmtfp2; /* temporary file */ 80 FILE * fmtfp3; /* temporary file */ 78 81 FILE * binfp; /* include singular procedures are stored 79 82 in an extra file */ … … 138 141 void AddParam(procdefv p, paramdefv vnew, char *name = NULL); 139 142 140 extern int create_tmpfile(moddefv module_def); 143 /* from makefile.cc */ 144 extern void mod_create_makefile(moddefv module); 145 extern void build_head_section(FILE *fp, moddefv module); 146 extern void build_clean_section(FILE *fp, moddefv module); 147 extern void build_install_section(FILE *fp, moddefv module); 148 static char *object_name(char *p); 149 extern void build_compile_section(FILE *fp, moddefv module); 150 151 /* from utils.cc */ 152 extern int create_tmpfile(moddefv module_def, int which = 0); 141 153 142 154 /* from proc_setup.cc */ … … 144 156 145 157 /* from proc.cc */ 146 extern void write_example(moddefv module, procdefv proc);147 148 158 extern void write_procedure_typecheck(moddefv module, procdefv pi, FILE *fmtfp); 149 159 extern void write_procedure_return(moddefv module, procdefv pi, FILE *fmtfp); … … 152 162 extern void write_function_return(moddefv module, procdefv pi, void *arg = NULL); 153 163 extern void write_function_errorhandling(moddefv module, procdefv pi); 164 extern void write_help(moddefv module, procdefv pi); 165 extern void write_example(moddefv module, procdefv pi); 154 166 extern int write_singular_procedures(moddefv module, procdefv proc); 155 167 extern void write_singular_parameter(moddefv module,int lineno, -
modules/modgen/proc.cc
rf3929a r664898 1 1 /* 2 * $Id: proc.cc,v 1. 6 2000-02-14 21:44:40krueger Exp $2 * $Id: proc.cc,v 1.7 2000-02-18 13:33:48 krueger Exp $ 3 3 */ 4 4 … … 51 51 } 52 52 53 printf("iiAddCproc %s is C\n", proc->procname);54 53 /* write call to add procname to list */ 55 54 fprintf(module->modfp, " iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n", … … 57 56 proc->is_static ? "TRUE" : "FALSE", 58 57 proc->procname); 58 59 59 if(proc->help_string!=NULL) { 60 fprintf(module->modfp, " namespaceroot->push( IDPACKAGE(helphdl) ,"); 61 fprintf(module->modfp, " IDID(helphdl));\n"); 62 fprintf(module->modfp, " enter_id(\"%s\",", proc->procname); 63 fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->help_string); 64 fprintf(module->modfp, " namespaceroot->push();\n"); 60 printf("WRITE HELP\n"); 61 // fprintf(module->modfp, " namespaceroot->push( IDPACKAGE(helphdl) ,"); 62 // fprintf(module->modfp, " IDID(helphdl));\n"); 63 fprintf(module->fmtfp2, " enter_id(\"%s\",", proc->procname); 64 fprintf(module->fmtfp2, " \"%s\", STRING_CMD);\n", proc->help_string); 65 // fprintf(module->modfp, " namespaceroot->push();\n"); 66 } 67 if(proc->example_string!=NULL) { 68 printf("WRITE EXAMPLE\n"); 69 fprintf(module->fmtfp3, " enter_id(\"%s\",", proc->procname); 70 fprintf(module->fmtfp3, " \"%s\", STRING_CMD);\n", 71 proc->example_string); 65 72 } 66 73 fprintf(module->modfp, "\n"); … … 73 80 case LANG_SINGULAR: 74 81 fprintf(module->modfp, 75 " h = add_singular_proc( %s, %d, %ld, %ld, %s);\n",82 " h = add_singular_proc(\"%s\", %d, %ld, %ld, %s);\n", 76 83 proc->procname, proc->lineno, 77 84 proc->sing_start, proc->sing_end, … … 83 90 } 84 91 85 /*========================================================================*/86 void write_example(87 moddefv module,88 procdefv proc89 )90 {91 /* if proc is NULL, just return */92 if( proc == NULL ) return;93 94 if(proc->example_string!=NULL) {95 fprintf(module->modfp, " namespaceroot->push( IDPACKAGE(examplehdl) ,");96 fprintf(module->modfp, " IDID(examplehdl));\n");97 fprintf(module->modfp, " enter_id(\"%s\",", proc->procname);98 fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->example_string);99 fprintf(module->modfp, " namespaceroot->push();\n");100 }101 }102 92 /*========================================================================*/ 103 93 /* … … 265 255 fprintf(module->modfp, " return 0;\n}\n\n"); 266 256 fflush(module->modfp); 267 257 258 fprintf(module->modfp, "#if 0 /* Help section */\n"); 259 mod_copy_tmp(module->modfp, module->fmtfp2); 260 fprintf(module->modfp, "#endif /* End of Help section */\n\n"); 261 fprintf(module->modfp, "#if 0 /* Example section */\n"); 262 mod_copy_tmp(module->modfp, module->fmtfp3); 263 fprintf(module->modfp, "#endif /* End of Example section */\n\n"); 268 264 mod_copy_tmp(module->modfp, module->fmtfp); 269 265 printf(" done.\n");fflush(stdout); 270 266 fclose(module->fmtfp); 267 fclose(module->fmtfp2); 268 fclose(module->fmtfp3); 271 269 return; 272 270 } … … 402 400 break; 403 401 } 404 402 } 403 404 /*========================================================================*/ 405 void write_help( 406 moddefv module, 407 procdefv pi 408 ) 409 { 410 if(pi->help_string!=NULL) { 411 fprintf(module->fmtfp2, "#line %d \"%s\"\n", pi->lineno_other, 412 module->filename); 413 // fprintf(module->modfp, " namespaceroot->push( IDPACKAGE(helphdl) ,"); 414 // fprintf(module->modfp, " IDID(helphdl));\n"); 415 fprintf(module->fmtfp2, " enter_id(\"%s\",", pi->procname); 416 fprintf(module->fmtfp2, " \"%s\", STRING_CMD);\n\n", pi->help_string); 417 // fprintf(module->modfp, " namespaceroot->push();\n"); 418 } 419 } 420 421 /*========================================================================*/ 422 void write_example( 423 moddefv module, 424 procdefv pi 425 ) 426 { 427 /* if proc is NULL, just return */ 428 if( pi == NULL ) return; 429 430 if(pi->example_string!=NULL) { 431 fprintf(module->fmtfp3, "#line %d \"%s\"\n", pi->lineno_other, 432 module->filename); 433 fprintf(module->fmtfp3, " enter_id(\"%s\",\n", pi->procname); 434 fprintf(module->fmtfp3, " \"%s\", STRING_CMD);\n\n", pi->example_string); 435 } 436 437 #if 0 438 fprintf(module->modfp, " namespaceroot->push( IDPACKAGE(examplehdl) ,"); 439 fprintf(module->modfp, " IDID(examplehdl));\n"); 440 fprintf(module->modfp, " enter_id(\"%s\",", proc->procname); 441 fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->example_string); 442 fprintf(module->modfp, " namespaceroot->push();\n"); 443 #endif 405 444 } 406 445 -
modules/modgen/scanner.l
rf3929a r664898 3 3 * Computer Algebra System SINGULAR * 4 4 ****************************************/ 5 /* $Id: scanner.l,v 1. 6 2000-02-14 21:47:10krueger Exp $ */5 /* $Id: scanner.l,v 1.7 2000-02-18 13:33:49 krueger Exp $ */ 6 6 #include <stdio.h> 7 7 #include <string.h> … … 13 13 #include "grammar.h" 14 14 15 #define DEBUG 3 15 /* #define DEBUG 3 */ 16 16 17 17 # define YYLP_ERR_NONE 0 … … 49 49 int read_string(char **buffer, long *start, long end); 50 50 int libread(FILE* f, char* buf, int max_size); 51 add_action(char *new_text);51 void add_action(char *new_text); 52 52 53 53 void push_state(int state, int new_state, char *name); … … 231 231 232 232 <COMMENT>{ 233 "*/" /*ACTION_ECHO;*/pop_state(); yymore();234 "*" /*ACTION_ECHO;*/yymore();233 "*/" ACTION_ECHO; pop_state(); yymore(); 234 "*" ACTION_ECHO; yymore(); 235 235 {NL} { yylineno++; yymore(); } 236 236 . { yymore(); } … … 261 261 } 262 262 example { 263 #if DEBUG > 1 263 264 printf(">>>EXAMPLE\n"); 265 #endif 264 266 brace1 = 0; /* { */ 265 267 brace2 = 0; /* ( */ … … 389 391 } else { 390 392 yymore(); 391 /*yylineno++;*/392 393 } 393 394 } … … 484 485 } 485 486 486 add_action(char *new_text)487 void add_action(char *new_text) 487 488 { 488 489 printf("%s", new_text); 490 } 489 return; 490 switch(sectnum) { 491 case 1: 492 printf("1>%s", new_text); 493 break; 494 case 2: 495 printf("2>%s", new_text); 496 break; 497 case 3: 498 printf("3>%s", new_text); 499 break; 500 } 501 } -
modules/modgen/utils.cc
rf3929a r664898 1 1 /* 2 * $Id: utils.cc,v 1. 4 2000-01-27 12:40:53krueger Exp $2 * $Id: utils.cc,v 1.5 2000-02-18 13:33:49 krueger Exp $ 3 3 */ 4 4 … … 46 46 /*========================================================================*/ 47 47 int create_tmpfile( 48 moddefv module_def 48 moddefv module_def, 49 int which 49 50 ) 50 51 { 51 52 char tmpfile[64]; 52 53 FILE *fp; 54 53 55 memset(tmpfile, '\0', sizeof(tmpfile)); 54 56 snprintf(tmpfile, sizeof(tmpfile), "tmp/modgen.tmpXXXXXX"); 55 57 mktemp(tmpfile); 56 58 59 printf("create_tmpfile (%d\n", which ); 60 57 61 if (close(creat(tmpfile, 0600)) < 0) { 58 62 (void) unlink (tmpfile); /* Blow it away!! */ 59 63 return -1; 60 } else if (( module_def->fmtfp = fopen(tmpfile, "a+")) == NULL) {64 } else if ((fp = fopen(tmpfile, "a+")) == NULL) { 61 65 (void) unlink (tmpfile); /* Blow it away!! */ 62 66 return -1; … … 64 68 (void) unlink (tmpfile); /* delete now to avoid turds... */ 65 69 } 70 71 printf("2)create_tmpfile (%d\n", which ); 72 switch(which) { 73 case 0: module_def->fmtfp = fp; break; 74 case 1: module_def->fmtfp2 = fp; break; 75 case 2: module_def->fmtfp3 = fp; break; 76 default: 77 fclose(fp); 78 return -1; 79 } 80 66 81 return 0; 67 68 82 } 69 83
Note: See TracChangeset
for help on using the changeset viewer.