home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / SPIDER / MASTER / MULTITAN.CH < prev    next >
Encoding:
Text File  |  1987-12-07  |  2.6 KB  |  108 lines

  1. @x 423
  2. output:
  3. @y
  4. output.
  5. We have made some modifications to \.{TANGLE} so it will write output
  6. on multiple files.
  7. We do this very simply: if a module name is introduced by \.{@@(}
  8. instead of \.{@@<}, we treat it as the name of a file.
  9. All these special modules are saved on a stack, |output_files|.
  10. We write them out after we've done the unnamed module.
  11. @z
  12. @x 425
  13. @c
  14. @y
  15. @d max_files 256
  16. @<Glob...@>=
  17. name_pointer output_files[max_files];
  18. name_pointer *cur_file, *end_output_files;
  19. char cur_module_char; /* is it |'<'| or |'('| */
  20. char output_file_name[longest_name]; /* name of the file */
  21.  
  22. @ We make |end_output_files| point jsut beyond the end of
  23. |output_files|.
  24. |cur_file| starts out there. Every time we see a new file, we
  25. decrement |cur_file| and then write it in.
  26. @<Set initial...@>=
  27. cur_file=end_output_files=output_files+max_files;
  28.  
  29. @ @<Add |cur_module| to the output file stack, or complain we're out
  30. of room@>=
  31. {
  32. if (cur_file>output_files) 
  33.     *--curfile=cur_module;
  34. else {
  35.     overflow("output files");
  36. }
  37. }
  38.  
  39. @ Here is the output switch, then...
  40.  
  41. @c
  42. @z
  43. @x 434
  44.     printf("\nWriting the output file"); update_terminal;
  45. @y
  46.     printf("\nWriting the output files: (%s)",C_file_name); update_terminal;
  47. @z
  48. @x 438
  49.     printf("\nDone.");
  50. @y
  51.     @<Write all the named output files@>
  52.     printf("\nDone.");
  53. @z
  54. @x 442
  55. @ First we go through the list of replacement texts and copy the ones
  56. @y
  57. @ To write the named output files, we proceed as for the unnamed
  58. module.
  59. The only subtlety is that we have to open each one.
  60. @<Write all the named output files@>=
  61. for (;cur_file<end_output_files; cur_file++) {
  62.     strncpy(output_file_name,(*curfile)->byte_start, longest_name);
  63.     output_file_name[length(*curfile)]='\0';
  64.     fclose(C_file);
  65.     C_file=fopen(output_file_name,"w");
  66.     if (C_file <=0) {
  67.         fatal("! Cannot open output file:",output_file_name)
  68.     } else {
  69.         printf("(%s)",output_file_name); update_terminal;
  70.     }
  71.     stack_ptr=stack+1;
  72.     cur_name= (*cur_file);
  73.     cur_repl= cur_name->equiv_or_xref;
  74.     cur_byte=cur_repl->tok_start;
  75.     cur_end=(cur_repl+1)->tok_start;
  76.     /* cur_mod=  it */;
  77.     while (stack_ptr > stack) get_output();
  78.     flush_buffer();
  79. }    
  80.  
  81.  
  82.  
  83. @ First we go through the list of replacement texts and copy the ones
  84. @z
  85. @x 575
  86.   ccode['&']=join; ccode['<']=module_name;
  87. @y
  88.   ccode['&']=join; 
  89.   ccode['<']=ccode['(']=module_name; 
  90. @z
  91. @x 778
  92.     case module_name: @<Scan the module name and make |cur_module|
  93.       point to it@>;
  94. @y
  95.     case module_name: 
  96.     cur_module_char=*(loc-1);
  97.     @<Scan the module name and make |cur_module| point to it@>;
  98. @z
  99. @x 803
  100.   return(module_name);
  101. @y
  102.   if (cur_module_char=='(') {
  103.     @<Add |cur_module| to the output file stack, or complain we're out
  104.     of room@>
  105.   }
  106.   return(module_name);
  107. @z
  108.