1 #define banner "This is TIE, CWEB Version 2.4."
3 "Copyright (c) 1989,1992 by THD/ITI. All rights reserved." \
16 #define first_text_char 0
17 #define last_text_char 255 \
19 #define map_xchr(c)(text_char)(c) \
21 #define map_xord(c)(ASCII_Code)(c) \
26 #define form_feed 12 \
29 #define term_out stdout
30 #define print(a)fprintf(term_out,a)
31 #define print2(a,b)fprintf(term_out,a,b)
32 #define print3(a,b,c)fprintf(term_out,a,b,c)
33 #define print_c(v)fputc(v,term_out);
34 #define new_line(v)fputc('\n',v)
35 #define term_new_line new_line(term_out) \
37 #define print_ln(v){fprintf(term_out,v);term_new_line;} \
39 #define print2_ln(a,b){print2(a,b);term_new_line;}
40 #define print3_ln(a,b,c){print3(a,b,c);term_new_line;} \
42 #define print_nl(v){term_new_line;print(v);} \
44 #define print2_nl(a,b){term_new_line;print2(a,b);} \
47 #define update_terminal fflush(term_out) \
53 #define error_loc(m)err_loc(m);history= troublesome;}
54 #define err_print(m){print_nl(m);error_loc \
56 #define fatal_error(m){ \
57 print(m);print_c('.');history= fatal; \
58 term_new_line;jump_out(); \
62 #define jump_out()exit(1) \
68 #define none (max_file_index+1) \
95 #define max_file_index 9
113 #define max_ASCII (126+1)
114 typedef unsigned char ASCII_Code
;
121 typedef unsigned char text_char
;
122 typedef FILE*text_file
;
132 typedef int in_file_modes
;
136 typedef int file_types
;
145 typedef int out_md_type
;
151 typedef int buffer_index
;
152 typedef int file_index
;
158 typedef struct _idsc
{
160 ASCII_Code buffer
[buf_size
];
163 file_types type_of_file
;
175 static int history
= spotless
;
182 static ASCII_Code xord
[last_text_char
+1];
184 static text_char xchr
[max_ASCII
+1];
191 static file_index actual_input
,test_input
,no_ch
;
192 static file_types prod_chf
= unknown
;
193 static out_md_type out_mode
;
199 static input_description
*input_organization
[max_file_index
+1];
208 static boolean input_has_ended
= false;
214 static text_file out_file
;
215 static string out_name
;
227 print3_ln(" (file %s, l.%ld).",
228 input_organization
[i
]->name_of_file
,
229 input_organization
[i
]->line
);
241 {register input_description
*inp_desc
= input_organization
[i
];
242 if(inp_desc
->mode
==ignore
)return;
243 if(feof(inp_desc
->the_file
))
248 inp_desc
->mode
= ignore
;
250 if(inp_desc
->type_of_file
==master
)input_has_ended
= true;
266 incr(inp_desc
->line
);
267 if(inp_desc
->type_of_file
==master
&&inp_desc
->line
%100==0){
268 if(inp_desc
->line
%500==0)print2("%ld",inp_desc
->line
);
277 inp_desc
->limit
= final_limit
= 0;
278 while(inp_desc
->limit
<buf_size
){
279 c
= fgetc(inp_desc
->the_file
);
284 if(inp_desc
->limit
<=0){
285 inp_desc
->mode
= ignore
;
287 if(inp_desc
->type_of_file
==master
)input_has_ended
= true;
299 inp_desc
->buffer
[inp_desc
->limit
++]= c
= map_xord(c
);
301 if(c
!=32&&c
!=tab_mark
)
302 final_limit
= inp_desc
->limit
;
308 err_print("! Input line too long")(i
);
310 while((c
= fgetc(inp_desc
->the_file
))!=EOF
&&map_xord(c
)!=nl_mark
)
321 inp_desc
->limit
= final_limit
;
334 boolean
lines_dont_match(i
,j
)
338 if(input_organization
[i
]->limit
!=input_organization
[j
]->limit
)
340 lmt
= input_organization
[i
]->limit
;
342 if(input_organization
[i
]->buffer
[k
]!=input_organization
[j
]->buffer
[k
])
351 void init_change_file(i
,b
)
352 file_index i
;boolean b
;
353 {register input_description
*inp_desc
= input_organization
[i
];
359 if(inp_desc
->mode
==ignore
)return;
360 if(inp_desc
->limit
<2)continue;
361 if(inp_desc
->buffer
[0]!=64)continue;
362 c
= inp_desc
->buffer
[1];
368 err_print("! Where is the matching @x?")(i
);
381 if(inp_desc
->mode
==ignore
){
382 err_print("! Change file ended after @x")(i
);
386 }while(inp_desc
->limit
<=0);
403 lmt
= input_organization
[j
]->limit
;
404 p
= input_organization
[j
]->buffer
;
405 for(i
= 0;i
<lmt
;i
++)fputc(map_xchr(*p
++),out_file
);
413 boolean
e_of_ch_module(i
)
415 {register input_description
*inp_desc
= input_organization
[i
];
416 if(inp_desc
->limit
<0){
417 print_nl("! At the end of change file missing @z ");
419 print2("%s",input_organization
[i
]->name_of_file
);
422 }else if(inp_desc
->limit
>=2)if(inp_desc
->buffer
[0]==64&&
423 (inp_desc
->buffer
[1]==90||inp_desc
->buffer
[1]==122))
432 boolean
e_of_ch_preamble(i
)
434 {register input_description
*inp_desc
= input_organization
[i
];
435 if(inp_desc
->limit
>=2&&inp_desc
->buffer
[0]==64)
436 if(inp_desc
->buffer
[1]==89||inp_desc
->buffer
[1]==121)return(true);
447 print("Usage: tie -[mc] outfile master changefile(s)");
460 int argc
;string
*argv
;
568 xchr
[0]= ' ';xchr
[0x7F]= ' ';
574 for(i
= 1;i
<32;xchr
[i
++]= ' ');
575 xchr
[tab_mark
]= '\t';
576 xchr
[form_feed
]= '\f';
583 for(i
= first_text_char
;i
<=last_text_char
;xord
[i
++]= 32)do_nothing
;
584 for(i
= 1;i
<=126;i
++)xord
[xchr
[i
]]= i
;
602 if(argc
<5||argc
>max_file_index
+4-1)usage();
604 for(act_arg
= 1;act_arg
<argc
;act_arg
++){
605 if(argv
[act_arg
][0]=='-')/*57:*/
608 if(prod_chf
!=unknown
)usage();
610 switch(argv
[act_arg
][1]){
612 case'C':prod_chf
= chf
;break;
614 case'M':prod_chf
= master
;break;
626 out_name
= argv
[act_arg
];
627 }else{register input_description
*inp_desc
;
628 inp_desc
= (input_description
*)
629 malloc(sizeof(input_description
));
631 fatal_error("! No memory for descriptor");
633 inp_desc
->mode
= search
;
635 inp_desc
->type_of_file
= chf
;
637 inp_desc
->name_of_file
= argv
[act_arg
];
638 input_organization
[no_ch
]= inp_desc
;
648 if(no_ch
<=0||prod_chf
==unknown
)usage();
659 out_file
= fopen(out_name
,"w");
661 fatal_error("! Could not open/create output file");
673 {input_organization
[0]->the_file
=
674 fopen(input_organization
[0]->name_of_file
,"r");
675 if(input_organization
[0]->the_file
==NULL
)
676 fatal_error("! Could not open master file");
678 print2("(%s)",input_organization
[0]->name_of_file
);
680 input_organization
[0]->type_of_file
= master
;
693 input_organization
[i
]->the_file
=
694 fopen(input_organization
[i
]->name_of_file
,"r");
695 if(input_organization
[i
]->the_file
==NULL
)
696 fatal_error("!Could not open change file");
698 print2("(%s)",input_organization
[i
]->name_of_file
);
700 init_change_file(i
,true);
716 input_has_ended
= false;
717 while(input_has_ended
==false||actual_input
!=0)
721 {file_index test_file
;
725 {register input_description
*inp_desc
;
726 while(actual_input
>0&&e_of_ch_module(actual_input
)){
727 inp_desc
= input_organization
[actual_input
];
728 if(inp_desc
->type_of_file
==master
){
730 fatal_error("! This can't happen: change file is master file");
733 inp_desc
->mode
= search
;
734 init_change_file(actual_input
,true);
735 while((input_organization
[actual_input
]->mode
!=reading
736 &&actual_input
>0))decr(actual_input
);
744 if(input_has_ended
&&actual_input
==0)break;
749 test_file
= actual_input
;
750 while(test_input
==none
&&test_file
<no_ch
-1){
752 switch(input_organization
[test_file
]->mode
){
753 case search
:if(lines_dont_match(actual_input
,test_file
)==false){
754 input_organization
[test_file
]->mode
= test
;
755 test_input
= test_file
;
758 case test
:if(lines_dont_match(actual_input
,test_file
)==true){
760 input_organization
[test_file
]->mode
= search
;
761 err_print("! Sections do not match")(actual_input
);
764 init_change_file(test_file
,false);
765 }else test_input
= test_file
;
767 case reading
:do_nothing
;
769 case ignore
:do_nothing
;
786 if(out_mode
==normal
){
787 if(test_input
!=none
){
788 fputc(map_xchr(64),out_file
);fputc(map_xchr(120),out_file
);
803 if(test_input
==none
){
804 fputc(map_xchr(64),out_file
);fputc(map_xchr(121),out_file
);
808 if(input_organization
[actual_input
]->type_of_file
==master
)
809 put_line(actual_input
);
822 if(input_organization
[actual_input
]->type_of_file
==chf
){
823 if(test_input
==none
)put_line(actual_input
);
826 fputc(map_xchr(64),out_file
);fputc(map_xchr(122),out_file
);
839 if(test_input
==none
)put_line(actual_input
);
848 get_line(actual_input
);
849 if(test_input
!=none
){
850 get_line(test_input
);
851 if(e_of_ch_preamble(test_input
)==true){
852 get_line(test_input
);
853 input_organization
[test_input
]->mode
= reading
;
854 actual_input
= test_input
;
870 fputc(map_xchr(64),out_file
);fputc(map_xchr(122),out_file
);
882 for(i
= 1;i
<no_ch
;i
++){
883 if(input_organization
[i
]->mode
!=ignore
)
884 err_print("! Change file entry did not match")(i
);
898 case spotless
:msg
= "No errors were found";break;
899 case troublesome
:msg
= "Pardon me, but I think I spotted something wrong.";
901 case fatal
:msg
= "That was a fatal error, my friend";break;
903 print2_nl("(%s.)",msg
);term_new_line
;
904 exit(history
==spotless
?0:1);