rify.clu_0 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. str = string;
  2. as = array[str];
  3. ac = array[char];
  4. rify = proc (s: str);
  5. line: ac := str$s2ac(s);
  6. dir: str := get_option(line);
  7. f: file := get_outfile(line);
  8. a: as := as$predict(1, 100);
  9. first: bool := true;
  10. for s in all_filestrings(line) do
  11. inf: file := get_infile(dir, s);
  12. except when open_failed: continue; end;
  13. file$puts(f, ".sr _name ");
  14. file$puts(f, s);
  15. file$puts(f, "\n.nr _page 0");
  16. if first
  17. then first := false;
  18. else file$puts(f, "\n.bp");
  19. end;
  20. s := "";
  21. while true do
  22. while s = "" do
  23. file$putc(f, '\n');
  24. s := file$gets(inf, '\n');
  25. end;
  26. while s = "" cor s[1] = '%' cor s[1] = ';' do
  27. as$addh(a, s);
  28. s := file$gets(inf, '\n');
  29. end;
  30. while s ~= "" do
  31. as$addh(a, s);
  32. s := file$gets(inf, '\n');
  33. end;
  34. output(f, a);
  35. end;
  36. except when eof: output(f, a); end;
  37. file$close(inf);
  38. end;
  39. file$close(f);
  40. end rify;
  41. get_outfile = proc (line: ac) returns (file);
  42. while ac$size(line) > 0 cand ac$top(line) <= ' ' do
  43. ac$remh(line);
  44. end;
  45. h: int := ac$high(line);
  46. l: int := ac$low(line);
  47. for i: int in int$from_to_by(h - 1, l, -1) do
  48. c: char := line[i];
  49. if c = ','
  50. then break;
  51. elseif line[i] = '>'
  52. then fs: ac := ac$predict(1, h - i);
  53. for n: int in int$from_to_by(i + 1, h, 1) do
  54. ac$addh(fs, line[n]);
  55. end;
  56. ac$trim(line, l, i - l);
  57. scan$deblank(fs);
  58. fss: str := str$ac2s(fs);
  59. return(get_output_file(fss));
  60. except when open_failed: break; end;
  61. end;
  62. end;
  63. i: int := 1;
  64. while file$exists("text" || int$unparse(i) || " >") do
  65. i := i + 1;
  66. end;
  67. return(get_output_file("text" || int$unparse(i) || " r"));
  68. end get_outfile;
  69. get_output_file = proc (fs: str) returns (file) signals (open_failed);
  70. f: file := file$open_write(fs);
  71. except when open_failed: tyo: file := file$tyo();
  72. file$puts(tyo, "Can't open ");
  73. file$puts(tyo, fs);
  74. file$putc(tyo, '\n');
  75. signal open_failed;
  76. end;
  77. file$puts(f, ".dv xgp\n.fo 0 20fg\n.de hd\n.ev header\n.rs\n.nf\n");
  78. file$puts(f, ".nr _page \\\016+_page\n.vp 0.5i\n");
  79. file$puts(f, "\003- \\\016_page -\022\\\023_name\n");
  80. file$puts(f, ".ev\n'vp 1i\n'sp\n.ns\n.em\n");
  81. file$puts(f, ".de ft\n'bp\n.em\n");
  82. file$puts(f, ".st hd 0\n.st ft 10.5i\n.eo .75i\n.oo .75i\n.ll 7.25i\n");
  83. file$puts(f, "'nf\n");
  84. return(f);
  85. end get_output_file;
  86. output = proc (f: file, a: as);
  87. n: int := as$size(a);
  88. if n <= 70
  89. then file$puts(f, ".ne ");
  90. file$puti(f, n);
  91. file$putc(f, '\n');
  92. end;
  93. for s: str in as$elements(a) do
  94. if s ~= "" cand s[1] = '.'
  95. then file$putc(f, '\021'); end;
  96. while str$indexc('\\', s) > 0 do
  97. n := str$indexc('\\', s);
  98. file$puts(f, str$substr(s, 1, n - 1));
  99. file$puts(f, "\021\\");
  100. s := str$rest(s, n + 1);
  101. end;
  102. file$puts(f, s);
  103. file$putc(f, '\n');
  104. end;
  105. as$trim(a, 1, 0);
  106. end output;
  107. all_filestrings = iter (line: ac) yields (str);
  108. a: ac := ac$predict(1, 10);
  109. while true do
  110. if ' ' = scan$deblank(line)
  111. then return; end;
  112. while ac$bottom(line) ~= ',' do
  113. c: char := ac$reml(line);
  114. if c >= 'a' cand c <= 'z'
  115. then c := char$i2c(char$c2i(c) - 32); end;
  116. ac$addh(a, c);
  117. end;
  118. except when bounds: yield(str$ac2s(a));
  119. return;
  120. end;
  121. ac$reml(line);
  122. yield(str$ac2s(a));
  123. ac$trim(a, 1, 0);
  124. end;
  125. end all_filestrings;
  126. get_infile = proc (dir, s: str) returns (file) signals (open_failed);
  127. if str$indexc(';', s) = 0 cand str$indexc(':', s) = 0
  128. then s := dir || s; end;
  129. fs: str;
  130. if str$indexc(' ', s) = 0
  131. then fs := s || " clu";
  132. else fs := s;
  133. end;
  134. return(file$open_read(fs));
  135. except when open_failed: ; end;
  136. if str$indexc(' ', s) = 0
  137. then return(file$open_read(s));
  138. end; except when open_failed: ; end;
  139. file$puts(file$tyo(), "Couldn't open " || s || "\n");
  140. signal open_failed;
  141. end get_infile;
  142. get_option = proc (line: ac) returns (str);
  143. if '-' ~= scan$deblank(line)
  144. then return(""); end;
  145. ac$reml(line);
  146. a: ac := ac$predict(1, 10);
  147. while ac$bottom(line) ~= ' ' do
  148. ac$addh(a, ac$reml(line));
  149. end;
  150. except when bounds: ; end;
  151. s: str := str$ac2s(a);
  152. z: int := str$size(s);
  153. si: int := str$indexc(';', s);
  154. ci: int := str$indexc(':', s);
  155. if si = 0 cand ci < z
  156. then return(str$append(s, ';'));
  157. elseif ci = 0 cand si < z
  158. then return(str$append(s, ':'));
  159. else return(s); end;
  160. end get_option;