| 1 |
% Changes to adapt tie to web2c. |
| 2 |
% Created 2001 by Olaf Weber |
| 3 |
% Updated 2020 by Andreas Scherer |
| 4 |
% This file is in the Public Domain. |
| 5 |
|
| 6 |
Limbo |
| 7 |
|
| 8 |
@x l.42 |
| 9 |
\centerline{(CWEB Version 2.4)} |
| 10 |
@y |
| 11 |
\centerline{(CWEB Version 2.4 [\TeX~Live])} |
| 12 |
@z |
| 13 |
|
| 14 |
@x l.44 -- reformat 'covernote' on table-of-contents page |
| 15 |
\def\botofcontents{ |
| 16 |
\null\vfill |
| 17 |
\item{$\copyright$}1989, 1992 |
| 18 |
by Technische Hochschule Darmstadt,\hfill\break |
| 19 |
Fachbereich Informatik, Institut f\"ur Theoretische Informatik\hfill\break |
| 20 |
All rights reserved.\hfill\break |
| 21 |
This program is distributed WITHOUT ANY WARRANTY, express or implied. |
| 22 |
\hfill\break |
| 23 |
Permission is granted to make and distribute verbatim copies of this |
| 24 |
program provided that the copyright notice and this permission notice |
| 25 |
are preserved on all copies. |
| 26 |
\hfill\break |
| 27 |
Permission is granted to copy and distribute modified versions of this |
| 28 |
program under the conditions for verbatim copying, provided that the |
| 29 |
entire resulting derived work is distributed under the terms of a |
| 30 |
permission notice identical to this one. |
| 31 |
} |
| 32 |
@y |
| 33 |
\let\maybe=\iftrue |
| 34 |
\def\covernote{\vbox{\noindent |
| 35 |
Copyright \copyright~1989, 1992 |
| 36 |
by Technische Hochschule Darmstadt,\hfill\break |
| 37 |
Fachbereich Informatik, Institut f\"ur Theoretische Informatik |
| 38 |
\smallskip\noindent |
| 39 |
All rights reserved. |
| 40 |
\bigskip\noindent |
| 41 |
This program is distributed WITHOUT ANY WARRANTY, express or implied. |
| 42 |
\smallskip\noindent |
| 43 |
Permission is granted to make and distribute verbatim copies of this |
| 44 |
program provided that the copyright notice and this permission notice |
| 45 |
are preserved on all copies. |
| 46 |
\smallskip\noindent |
| 47 |
Permission is granted to copy and distribute modified versions of this |
| 48 |
program under the conditions for verbatim copying, provided that the |
| 49 |
entire resulting derived work is distributed under the terms of a |
| 50 |
permission notice identical to this one. |
| 51 |
}} |
| 52 |
\datecontentspage |
| 53 |
@z |
| 54 |
|
| 55 |
Section 1. |
| 56 |
|
| 57 |
@x l.96 |
| 58 |
E.g.\ it will not use the |enum| type declarations. |
| 59 |
@y |
| 60 |
@z |
| 61 |
|
| 62 |
@x l.105 |
| 63 |
@d banner "This is TIE, CWEB Version 2.4." |
| 64 |
@y |
| 65 |
@d banner "This is TIE, CWEB Version 2.4" |
| 66 |
/* will be extended by the \TeX~Live |versionstring| */ |
| 67 |
@z |
| 68 |
|
| 69 |
Section 2 |
| 70 |
|
| 71 |
@x l.113 -- improve typography |
| 72 |
@<Global |#include|s@>@; |
| 73 |
@y |
| 74 |
@<Global \&{\#include}s@>@; |
| 75 |
@z |
| 76 |
|
| 77 |
Section 3 |
| 78 |
|
| 79 |
@x l.123 -- Already in cpascal.h. |
| 80 |
@d incr(v) v+=1 /* increase a variable by unity */ |
| 81 |
@d decr(v) v-=1 /* decrease a variable by unity */ |
| 82 |
@y |
| 83 |
@z |
| 84 |
|
| 85 |
Section 4 |
| 86 |
|
| 87 |
@x l.130 |
| 88 |
@ Furthermore we include the additional types |boolean| and |string|. |
| 89 |
@d false 0 |
| 90 |
@d true 1 |
| 91 |
@<Global types@>= |
| 92 |
typedef int boolean; |
| 93 |
typedef char* string; |
| 94 |
@y |
| 95 |
@ The types |@!boolean| (with values |@!false| and |@!true|) and |
| 96 |
|@!string| come from \.{<kpathsea/simpletypes.h>}. |
| 97 |
@s boolean int |
| 98 |
@s string int |
| 99 |
@z |
| 100 |
|
| 101 |
Section 5 |
| 102 |
|
| 103 |
@x l.144 -- we need more input files. |
| 104 |
#define max_file_index 9 |
| 105 |
/* we don't think that anyone needs more than 9 change files, |
| 106 |
@y |
| 107 |
#define max_file_index 32 |
| 108 |
/* we don't think that anyone needs more than 32 change files, |
| 109 |
@z |
| 110 |
|
| 111 |
Section 6 |
| 112 |
|
| 113 |
@x l.155 -- replace preprocessor macros |
| 114 |
@d spotless 0 |
| 115 |
@d troublesome 1 |
| 116 |
@d fatal 2 |
| 117 |
|
| 118 |
@<Global variables@>= |
| 119 |
static int history=spotless; |
| 120 |
@y |
| 121 |
@<Global variables@>= |
| 122 |
typedef enum { |
| 123 |
@!spotless, |
| 124 |
@!troublesome, |
| 125 |
@!fatal } return_code; |
| 126 |
static return_code history=spotless; |
| 127 |
@z |
| 128 |
|
| 129 |
Section 15 |
| 130 |
|
| 131 |
@x l.461 |
| 132 |
@d print(a) fprintf(term_out,a) /* `|print|' means write on the terminal */ |
| 133 |
@y |
| 134 |
@d print(a) fprintf(term_out,"%s",a) /* `|print|' means write on the terminal */ |
| 135 |
@z |
| 136 |
|
| 137 |
@x l.463 -- function used only for error messages |
| 138 |
@d print3(a,b,c) fprintf(term_out,a,b,c) /* same with three arguments */ |
| 139 |
@y |
| 140 |
@d print3(a,b,c) fprintf(stderr,a,b,c) /* same with three arguments */ |
| 141 |
@z |
| 142 |
|
| 143 |
@x l.468 |
| 144 |
@d print_ln(v) {fprintf(term_out,v);term_new_line;} |
| 145 |
@y |
| 146 |
@d print_ln(v) {fprintf(term_out,"%s",v);term_new_line;} |
| 147 |
@z |
| 148 |
|
| 149 |
@x l.471 -- used only for error reporting |
| 150 |
@d print3_ln(a,b,c) {print3(a,b,c);term_new_line;} |
| 151 |
@y |
| 152 |
@d print3_ln(a,b,c) {print3(a,b,c);new_line(stderr);} |
| 153 |
@z |
| 154 |
|
| 155 |
@x l.478 -- add to global includes. |
| 156 |
@<Global |#include|s@>= |
| 157 |
#include <stdio.h> |
| 158 |
@y |
| 159 |
@<Global \&{\#include}s@>= |
| 160 |
#include "cpascal.h" /* |@!decr| and |@!incr| */ |
| 161 |
#include <kpathsea/kpathsea.h> |
| 162 |
#define usage tieusage /* Also redefine |usage| to avoid clash with function from lib. */ |
| 163 |
@z |
| 164 |
|
| 165 |
Section 16 |
| 166 |
|
| 167 |
@x l.483 -- Remove redundant #include directives. |
| 168 |
This should cause no trouble in any \Cl\ program. |
| 169 |
@^system dependencies@> |
| 170 |
|
| 171 |
@<Global |#include|s@>= |
| 172 |
#ifdef __STDC__ |
| 173 |
#include <stdlib.h> |
| 174 |
#else |
| 175 |
#include <malloc.h> |
| 176 |
#endif |
| 177 |
@y |
| 178 |
This should cause no trouble in any \Cl\ program. |
| 179 |
The \.{kpathsea} include files handle the definition of |@!malloc|, too. |
| 180 |
@^system dependencies@> |
| 181 |
@z |
| 182 |
|
| 183 |
Sections 18 and 19: use enum as requested in tie.w |
| 184 |
|
| 185 |
@x l.522 |
| 186 |
\leavevmode |file_types| is used to describe whether a file |
| 187 |
@y |
| 188 |
\leavevmode \&{file\_types} is used to describe whether a file |
| 189 |
@z |
| 190 |
|
| 191 |
@x l.526 Fix case glitch. |
| 192 |
the kind of output. (this would even be necessary if we |
| 193 |
@y |
| 194 |
the kind of output. (This would even be necessary if we |
| 195 |
@z |
| 196 |
|
| 197 |
@x l.530 |
| 198 |
#define search 0 |
| 199 |
#define test 1 |
| 200 |
#define reading 2 |
| 201 |
#define ignore 3 |
| 202 |
typedef int in_file_modes; /* should be |enum(search,test,reading,ignore)| */ |
| 203 |
#define unknown 0 |
| 204 |
#define master 1 |
| 205 |
#define chf 2 |
| 206 |
typedef int file_types; /* should be |enum(unknown,master,chf)| */ |
| 207 |
@y |
| 208 |
typedef enum { |
| 209 |
@!search, |
| 210 |
@!test, |
| 211 |
@!reading, |
| 212 |
@!ignore } in_file_modes; |
| 213 |
typedef enum { |
| 214 |
@!unknown, |
| 215 |
@!master, |
| 216 |
@!chf } file_types; |
| 217 |
@z |
| 218 |
|
| 219 |
@x l.541 |
| 220 |
@ A variable of type |out_md_type| will tell us in what state the output |
| 221 |
@y |
| 222 |
@ A variable of type \&{out\_md\_type} will tell us in what state the output |
| 223 |
@z |
| 224 |
|
| 225 |
@x l.548 |
| 226 |
#define normal 0 |
| 227 |
#define pre 1 |
| 228 |
#define post 2 |
| 229 |
typedef int out_md_type; /* should be |enum(normal,pre,post)| */ |
| 230 |
@y |
| 231 |
typedef enum { |
| 232 |
@!normal, |
| 233 |
@!pre, |
| 234 |
@!post } out_md_type; |
| 235 |
@z |
| 236 |
|
| 237 |
Section 24 |
| 238 |
|
| 239 |
@x l.617 |
| 240 |
void get_line(i) |
| 241 |
file_index i; |
| 242 |
@y |
| 243 |
static void |
| 244 |
get_line (file_index i) |
| 245 |
@z |
| 246 |
|
| 247 |
Section 27 |
| 248 |
|
| 249 |
@x l.650 -- fix typo |
| 250 |
replacement part of a change file, or in an incomplerte check if the |
| 251 |
@y |
| 252 |
replacement part of a change file, or in an incomplete check if the |
| 253 |
@z |
| 254 |
|
| 255 |
@x l.663 |
| 256 |
@<Check |c| for |EOF|, |return| if line was empty, otherwise |
| 257 |
@y |
| 258 |
@<Check \9{c}|c| for |EOF|, |return| if line was empty, otherwise |
| 259 |
@z |
| 260 |
|
| 261 |
@x l.667 |
| 262 |
if (c!=@' ' && c!=tab_mark) |
| 263 |
@y |
| 264 |
if (c!=@' ' && c!=tab_mark && c!=@'\r') |
| 265 |
@z |
| 266 |
|
| 267 |
Section 29 |
| 268 |
|
| 269 |
@x l.688 |
| 270 |
@ There may be incomplete lines of the editor used does |
| 271 |
@y |
| 272 |
@ There may be incomplete lines if the editor used does |
| 273 |
@z |
| 274 |
|
| 275 |
@x l.691 |
| 276 |
final line. Of the current line is empty, we just can \&{return}. |
| 277 |
@y |
| 278 |
final line. If the current line is empty, we just can \&{return}. |
| 279 |
@z |
| 280 |
|
| 281 |
@x l.696 |
| 282 |
@<Check |c| for |EOF|...@>= |
| 283 |
@y |
| 284 |
@<Check \9{c}|c| for |EOF|...@>= |
| 285 |
@z |
| 286 |
|
| 287 |
Section 31 |
| 288 |
|
| 289 |
@x l.742 -- print errors on 'stderr' |
| 290 |
@d err_print(m) { @+ print_nl(m); error_loc |
| 291 |
@y |
| 292 |
@d err_print(m) { @+ new_line(stderr); fprintf(stderr,"%s",m); error_loc |
| 293 |
@z |
| 294 |
|
| 295 |
@x l.745 |
| 296 |
void err_loc(i) /* prints location of error */ |
| 297 |
int i; |
| 298 |
@y |
| 299 |
static void |
| 300 |
err_loc (int i) /* prints location of error */ |
| 301 |
@z |
| 302 |
|
| 303 |
Section 32 |
| 304 |
|
| 305 |
@x l.761 -- print errors on 'stderr' |
| 306 |
print(m); print_c('.'); history=fatal; |
| 307 |
term_new_line; jump_out(); |
| 308 |
@y |
| 309 |
fprintf(stderr,"%s",m); |
| 310 |
fputc('.',stderr); history=fatal; |
| 311 |
new_line(stderr); jump_out(); |
| 312 |
@z |
| 313 |
|
| 314 |
Section 33 |
| 315 |
|
| 316 |
@x l.771 |
| 317 |
@d jump_out() exit(1) |
| 318 |
@y |
| 319 |
@d jump_out() exit(EXIT_FAILURE) |
| 320 |
@z |
| 321 |
|
| 322 |
Section 34 |
| 323 |
|
| 324 |
@x l.790 Use binary mode for output files |
| 325 |
out_file=fopen(out_name,"w"); |
| 326 |
@y |
| 327 |
out_file=fopen(out_name,"wb"); |
| 328 |
@z |
| 329 |
|
| 330 |
Section 36 |
| 331 |
|
| 332 |
@x l.811 |
| 333 |
fopen(input_organization[0]->name_of_file,"r"); |
| 334 |
@y |
| 335 |
kpse_open_file(input_organization[0]->name_of_file, kpse_web_format); |
| 336 |
@z |
| 337 |
|
| 338 |
Section 37 |
| 339 |
|
| 340 |
@x l.830 |
| 341 |
fopen(input_organization[i]->name_of_file,"r"); |
| 342 |
@y |
| 343 |
kpse_open_file(input_organization[i]->name_of_file, kpse_web_format); |
| 344 |
@z |
| 345 |
|
| 346 |
Section 38 |
| 347 |
|
| 348 |
@x l.851 |
| 349 |
boolean lines_dont_match(i,j) |
| 350 |
file_index i,j; |
| 351 |
@y |
| 352 |
static boolean |
| 353 |
lines_dont_match (file_index i, file_index j) |
| 354 |
@z |
| 355 |
|
| 356 |
Section 39 |
| 357 |
|
| 358 |
@x l.872 |
| 359 |
void init_change_file(i,b) |
| 360 |
file_index i; boolean b; |
| 361 |
@y |
| 362 |
static void |
| 363 |
init_change_file (file_index i, boolean b) |
| 364 |
@z |
| 365 |
|
| 366 |
Section 42 |
| 367 |
|
| 368 |
@x l.919 |
| 369 |
void put_line(j) |
| 370 |
file_index j; |
| 371 |
@y |
| 372 |
static void |
| 373 |
put_line (file_index j) |
| 374 |
@z |
| 375 |
|
| 376 |
Section 43 |
| 377 |
|
| 378 |
@x l.935 |
| 379 |
boolean e_of_ch_module(i) |
| 380 |
file_index i; |
| 381 |
@y |
| 382 |
static boolean |
| 383 |
e_of_ch_module (file_index i) |
| 384 |
@z |
| 385 |
|
| 386 |
Section 44 |
| 387 |
|
| 388 |
@x l.955 |
| 389 |
boolean e_of_ch_preamble(i) |
| 390 |
file_index i; |
| 391 |
@y |
| 392 |
static boolean |
| 393 |
e_of_ch_preamble (file_index i) |
| 394 |
@z |
| 395 |
|
| 396 |
Section 47 |
| 397 |
|
| 398 |
@x l.1005 -- fix typo |
| 399 |
a line to write and |test_input| ist set to |none|. |
| 400 |
@y |
| 401 |
a line to write and |test_input| is set to |none|. |
| 402 |
@z |
| 403 |
|
| 404 |
Section 48: fix indentation of nested loop. |
| 405 |
|
| 406 |
@x l.1044 |
| 407 |
if (prod_chf==chf) { |
| 408 |
loop @+ { |
| 409 |
@<Test for normal, |break| when done@>@; |
| 410 |
@<Test for pre, |break| when done@>@; |
| 411 |
@<Test for post, |break| when done@>@; |
| 412 |
} |
| 413 |
} else |
| 414 |
@y |
| 415 |
if (prod_chf==chf) |
| 416 |
loop @+ { |
| 417 |
@<Test for normal, |break| when done@>@; |
| 418 |
@<Test for pre, |break| when done@>@; |
| 419 |
@<Test for post, |break| when done@>@; |
| 420 |
} |
| 421 |
else |
| 422 |
@z |
| 423 |
|
| 424 |
Section 53. |
| 425 |
|
| 426 |
@x l.1133 |
| 427 |
if (out_mode==post) { /* last line has been changed */ |
| 428 |
fputc(map_xchr(@'@@'),out_file); fputc(map_xchr(@'z'),out_file); |
| 429 |
new_line(out_file); |
| 430 |
} |
| 431 |
@y |
| 432 |
if (out_mode==pre) { /* last line has been deleted */ |
| 433 |
fputc(map_xchr(@'@@'),out_file); fputc(map_xchr(@'y'),out_file); |
| 434 |
new_line(out_file); out_mode=post; |
| 435 |
} |
| 436 |
if (out_mode==post) { /* last line has been changed */ |
| 437 |
fputc(map_xchr(@'@@'),out_file); fputc(map_xchr(@'z'),out_file); |
| 438 |
new_line(out_file); |
| 439 |
} |
| 440 |
@z |
| 441 |
|
| 442 |
Section 55 |
| 443 |
|
| 444 |
@x l.1158 |
| 445 |
void usage() |
| 446 |
{ |
| 447 |
print("Usage: tie -[mc] outfile master changefile(s)"); |
| 448 |
@y |
| 449 |
static |
| 450 |
void usage (void) |
| 451 |
{ |
| 452 |
print("Usage: tie -m|-c outfile master changefile(s)"); |
| 453 |
@z |
| 454 |
|
| 455 |
Section 56 |
| 456 |
|
| 457 |
@x l.1169 -- fix typo |
| 458 |
change files. The names fo the file parameters will be inserted into |
| 459 |
@y |
| 460 |
change files. The names of the file parameters will be inserted into |
| 461 |
@z |
| 462 |
|
| 463 |
Section 59 |
| 464 |
|
| 465 |
@x l.1233 |
| 466 |
\noindent Here is where \.{TIE} starts, and where it ends. |
| 467 |
@y |
| 468 |
\noindent Here is where \.{TIE} starts, and where it ends. |
| 469 |
\def\Kpathsea/{{\mc KPATHSEA\spacefactor1000}} |
| 470 |
|
| 471 |
This version of the \.{TIE} program uses the \Kpathsea/ library for searching |
| 472 |
files. Firstly, we use the |kpse_web_format| when opening input files, which |
| 473 |
triggers the inspection of the \.{WEBINPUTS} environment variable. Secondly, |
| 474 |
we set |kpse_program_name| to `\.{tie}'. This means if the variable |
| 475 |
\.{WEBINPUTS.tie} is present in \.{texmf.cnf} (or \.{WEBINPUTS\_tie} in the |
| 476 |
environment) its value will be used as the search path for filenames. This |
| 477 |
allows different flavors of \.{TIE} (or other \.{WEB} programs) to have |
| 478 |
different search [email protected]@> In all, the directories to be searched for |
| 479 |
come from at least two sources: |
| 480 |
\smallskip |
| 481 |
{\parindent1.5em |
| 482 |
\item{(a)} a user-set environment variable \.{WEBINPUTS} |
| 483 |
(overridden by \.{WEBINPUTS\_tie}); |
| 484 |
\item{(b)} a line in \Kpathsea/ configuration file \.{texmf.cnf},\hfil\break |
| 485 |
e.g., \.{WEBINPUTS=\$TEXMFDOTDIR:\$TEXMF/texmf/web//}\hfil\break |
| 486 |
or \.{WEBINPUTS.tie=\$TEXMFDOTDIR:\$TEXMF/texmf/web//}.\par} |
| 487 |
\smallskip |
| 488 |
Note that, although \.{WEBINPUTS} might suggest otherwise, \.{TIE} is more or |
| 489 |
less language-agnostic and that it is perfectly capable of handling \.{CWEB} |
| 490 |
files as input as well, as long as the ``change files'' adhere to the general |
| 491 |
\.{@@x}, \.{@@y}, \.{@@z} convention. |
| 492 |
@z |
| 493 |
|
| 494 |
@x l.1236 |
| 495 |
main(argc,argv) |
| 496 |
int argc; string *argv; |
| 497 |
@y |
| 498 |
int main (int argc, string *argv) |
| 499 |
@z |
| 500 |
|
| 501 |
@x l.1241 |
| 502 |
print_ln(banner); /* print a ``banner line'' */ |
| 503 |
print_ln(copyright); /* include the copyright notice */ |
| 504 |
@y |
| 505 |
kpse_set_program_name(argv[0], "tie"); |
| 506 |
print(banner); /* print a ``banner line'' */ |
| 507 |
print_ln(versionstring); /* Web2C version */ |
| 508 |
print_ln(copyright); /* include the copyright notice */ |
| 509 |
@z |
| 510 |
|
| 511 |
Section 60 |
| 512 |
|
| 513 |
@x l.1256 -- fix typo |
| 514 |
Additionaly we report the history to the user, although this may not |
| 515 |
@y |
| 516 |
Additionally we report the history to the user, although this may not |
| 517 |
@z |
| 518 |
|
| 519 |
@x l.1261 -- rewrite error reporting |
| 520 |
@<Print the job |history|@>= |
| 521 |
{string msg; |
| 522 |
switch (history) { |
| 523 |
case spotless: msg="No errors were found"; break; |
| 524 |
case troublesome: msg="Pardon me, but I think I spotted something wrong."; |
| 525 |
break; |
| 526 |
case fatal: msg="That was a fatal error, my friend"; break; |
| 527 |
} /* there are no other cases */ |
| 528 |
print2_nl("(%s.)",msg); term_new_line; |
| 529 |
exit ( history == spotless ? 0 : 1 ); |
| 530 |
} |
| 531 |
@y |
| 532 |
@<Print the job |history|@>= |
| 533 |
{ |
| 534 |
switch (history) { |
| 535 |
case spotless: print2_nl("(%s.)", "No errors were found"); |
| 536 |
term_new_line; break; |
| 537 |
case troublesome: new_line(stderr); fprintf(stderr, |
| 538 |
"(Pardon me, but I think I spotted something wrong.)"); |
| 539 |
new_line(stderr); break; |
| 540 |
case fatal: |
| 541 |
default: /* Anything except spotless, troublesome, or fatal is a bug. */ |
| 542 |
new_line(stderr); |
| 543 |
fprintf(stderr, "(That was a fatal error, my friend.)"); |
| 544 |
new_line(stderr); break; |
| 545 |
} |
| 546 |
exit ( history == spotless ? EXIT_SUCCESS : EXIT_FAILURE ); |
| 547 |
} |
| 548 |
@z |