Back to index

tetex-bin  3.0
Classes | Defines | Typedefs | Functions | Variables
tie.c File Reference
#include <stdio.h>
#include <malloc.h>

Go to the source code of this file.

Classes

struct  _idsc

Defines

#define banner   "This is TIE, CWEB Version 2.4."
#define copyright
#define incr(v)   v+= 1
#define decr(v)   v-= 1
#define loop   while(1)
#define do_nothing
#define false   0
#define true   1
#define spotless   0
#define troublesome   1
#define fatal   2 \
#define first_text_char   0
#define last_text_char   255 \
#define map_xchr(c)   (text_char)(c) \
#define map_xord(c)
#define tab_mark   9
#define nl_mark   10
#define form_feed
#define term_out   stdout
#define print(a)   fprintf(term_out,a)
#define print2(a, b)   fprintf(term_out,a,b)
#define print3(a, b, c)   fprintf(term_out,a,b,c)
#define print_c(v)   fputc(v,term_out);
#define new_line(v)   fputc('\n',v)
#define term_new_line   new_line(term_out) \
#define print_ln(v)   {fprintf(term_out,v);term_new_line;} \
#define print2_ln(a, b)   {print2(a,b);term_new_line;}
#define print3_ln(a, b, c)   {print3(a,b,c);term_new_line;} \
#define print_nl(v)   {term_new_line;print(v);} \
#define print2_nl(a, b)
#define update_terminal
#define error_loc(m)   err_loc(m);history= troublesome;}
#define err_print(m)   {print_nl(m);error_loc \
#define fatal_error(m)
#define jump_out()
#define none   (max_file_index+1) \
#define buf_size   512
#define max_file_index   9
#define max_ASCII   (126+1)
#define search   0
#define test   1
#define reading   2
#define ignore   3
#define unknown   0
#define master   1
#define chf   2
#define normal   0
#define pre   1
#define post   2

Typedefs

typedef int boolean
typedef char * string
typedef unsigned char ASCII_Code
typedef unsigned char text_char
typedef FILEtext_file
typedef int in_file_modes
typedef int file_types
typedef int out_md_type
typedef int buffer_index
typedef int file_index
typedef struct _idsc input_description

Functions

void err_loc (int i)
void get_line (file_index i)
boolean lines_dont_match (file_index i, file_index j)
void init_change_file (file_index i, boolean b)
void put_line (file_index j)
boolean e_of_ch_module (file_index i)
boolean e_of_ch_preamble (file_index i)
void usage ()
 main (int argc, string *argv)

Variables

static int history = spotless
static ASCII_Code xord [last_text_char+1]
static text_char xchr [max_ASCII+1]
static file_index actual_input
static file_index test_input
static file_index no_ch
static file_types prod_chf = unknown
static out_md_type out_mode
static input_descriptioninput_organization [max_file_index+1]
static boolean input_has_ended = false
static text_file out_file
static string out_name

Class Documentation

struct _idsc

Definition at line 104 of file ctie-k.c.

Collaboration diagram for _idsc:
Class Members
char buffer
ASCII_Code buffer
char * buffer_end
include_description * current_include
int dont_match
string file_name
char * limit
buffer_index limit
long line
char * loc
in_file_modes mode
string name_of_file
FILE * the_file
text_file the_file
file_types type_of_file

Define Documentation

#define banner   "This is TIE, CWEB Version 2.4."

Definition at line 1 of file tie.c.

#define buf_size   512

Definition at line 94 of file tie.c.

#define chf   2

Definition at line 135 of file tie.c.

#define copyright
Value:
"Copyright (c) 1989,1992 by THD/ITI. All rights reserved." \
 \

Definition at line 2 of file tie.c.

#define decr (   v)    v-= 1

Definition at line 7 of file tie.c.

#define do_nothing

Definition at line 9 of file tie.c.

#define err_print (   m)    {print_nl(m);error_loc \

Definition at line 54 of file tie.c.

#define error_loc (   m)    err_loc(m);history= troublesome;}

Definition at line 53 of file tie.c.

#define false   0

Definition at line 10 of file tie.c.

#define fatal   2 \

Definition at line 14 of file tie.c.

#define fatal_error (   m)
Value:
{ \
print(m);print_c('.');history= fatal; \
term_new_line;jump_out(); \
} \
 \

Definition at line 56 of file tie.c.

#define first_text_char   0

Definition at line 16 of file tie.c.

#define form_feed
Value:
12 \
 \

Definition at line 26 of file tie.c.

#define ignore   3

Definition at line 131 of file tie.c.

#define incr (   v)    v+= 1

Definition at line 6 of file tie.c.

#define jump_out ( )
Value:
exit(1) \
 \
 \
 \
 \

Definition at line 62 of file tie.c.

#define last_text_char   255 \

Definition at line 17 of file tie.c.

#define loop   while(1)

Definition at line 8 of file tie.c.

#define map_xchr (   c)    (text_char)(c) \

Definition at line 19 of file tie.c.

#define map_xord (   c)
Value:
(ASCII_Code)(c) \
 \

Definition at line 21 of file tie.c.

#define master   1

Definition at line 134 of file tie.c.

#define max_ASCII   (126+1)

Definition at line 113 of file tie.c.

#define max_file_index   9

Definition at line 95 of file tie.c.

#define new_line (   v)    fputc('\n',v)

Definition at line 34 of file tie.c.

#define nl_mark   10

Definition at line 25 of file tie.c.

#define none   (max_file_index+1) \

Definition at line 68 of file tie.c.

#define normal   0

Definition at line 142 of file tie.c.

#define post   2

Definition at line 144 of file tie.c.

#define pre   1

Definition at line 143 of file tie.c.

#define print (   a)    fprintf(term_out,a)

Definition at line 30 of file tie.c.

#define print2 (   a,
  b 
)    fprintf(term_out,a,b)

Definition at line 31 of file tie.c.

#define print2_ln (   a,
  b 
)    {print2(a,b);term_new_line;}

Definition at line 39 of file tie.c.

#define print2_nl (   a,
  b 
)
Value:

Definition at line 44 of file tie.c.

#define print3 (   a,
  b,
  c 
)    fprintf(term_out,a,b,c)

Definition at line 32 of file tie.c.

#define print3_ln (   a,
  b,
  c 
)    {print3(a,b,c);term_new_line;} \

Definition at line 40 of file tie.c.

#define print_c (   v)    fputc(v,term_out);

Definition at line 33 of file tie.c.

#define print_ln (   v)    {fprintf(term_out,v);term_new_line;} \

Definition at line 37 of file tie.c.

#define print_nl (   v)    {term_new_line;print(v);} \

Definition at line 42 of file tie.c.

#define reading   2

Definition at line 130 of file tie.c.

#define search   0

Definition at line 128 of file tie.c.

#define spotless   0

Definition at line 12 of file tie.c.

#define tab_mark   9

Definition at line 24 of file tie.c.

#define term_new_line   new_line(term_out) \

Definition at line 35 of file tie.c.

#define term_out   stdout

Definition at line 29 of file tie.c.

#define test   1

Definition at line 129 of file tie.c.

#define troublesome   1

Definition at line 13 of file tie.c.

#define true   1

Definition at line 11 of file tie.c.

#define unknown   0

Definition at line 133 of file tie.c.

#define update_terminal
Value:
fflush(term_out) \
 \
 \
 \
 \

Definition at line 47 of file tie.c.


Typedef Documentation

typedef unsigned char ASCII_Code

Definition at line 114 of file tie.c.

typedef int boolean

Definition at line 106 of file tie.c.

typedef int buffer_index

Definition at line 151 of file tie.c.

typedef int file_index

Definition at line 152 of file tie.c.

typedef int file_types

Definition at line 136 of file tie.c.

typedef int in_file_modes

Definition at line 132 of file tie.c.

typedef struct _idsc input_description
typedef int out_md_type

Definition at line 145 of file tie.c.

typedef char* string

Definition at line 107 of file tie.c.

typedef unsigned char text_char

Definition at line 121 of file tie.c.

typedef FILE* text_file

Definition at line 122 of file tie.c.


Function Documentation

Definition at line 413 of file tie.c.

{register input_description*inp_desc= input_organization[i];
if(inp_desc->limit<0){
print_nl("! At the end of change file missing @z ");

print2("%s",input_organization[i]->name_of_file);
term_new_line;
return(true);
}else if(inp_desc->limit>=2)if(inp_desc->buffer[0]==64&&
(inp_desc->buffer[1]==90||inp_desc->buffer[1]==122))
return(true);
return(false);
}

Definition at line 432 of file tie.c.

{register input_description*inp_desc= input_organization[i];
if(inp_desc->limit>=2&&inp_desc->buffer[0]==64)
if(inp_desc->buffer[1]==89||inp_desc->buffer[1]==121)return(true);
return(false);
}
void err_loc ( int  i)

Definition at line 224 of file tie.c.

{
print3_ln(" (file %s, l.%ld).",
input_organization[i]->name_of_file,
input_organization[i]->line);
}

Here is the caller graph for this function:

Definition at line 239 of file tie.c.

{register input_description*inp_desc= input_organization[i];
if(inp_desc->mode==ignore)return;
if(feof(inp_desc->the_file))
/*25:*/
#line 630 "tie.w"

{
inp_desc->mode= ignore;
inp_desc->limit= -1;
if(inp_desc->type_of_file==master)input_has_ended= true;
return;
}


/*:25*/
#line 622 "tie.w"

/*27:*/
#line 655 "tie.w"

{int final_limit;
int c;
/*28:*/
#line 679 "tie.w"

incr(inp_desc->line);
if(inp_desc->type_of_file==master&&inp_desc->line%100==0){
if(inp_desc->line%500==0)print2("%ld",inp_desc->line);
else print_c('.');
update_terminal;
}


/*:28*/
#line 659 "tie.w"

inp_desc->limit= final_limit= 0;
while(inp_desc->limit<buf_size){
c= fgetc(inp_desc->the_file);
/*29:*/
#line 696 "tie.w"

if(c==EOF){
if(inp_desc->limit<=0){
inp_desc->mode= ignore;
inp_desc->limit= -1;
if(inp_desc->type_of_file==master)input_has_ended= true;
return;
}else{
c= nl_mark;
break;
}
}


/*:29*/
#line 664 "tie.w"

inp_desc->buffer[inp_desc->limit++]= c= map_xord(c);
if(c==nl_mark)break;
if(c!=32&&c!=tab_mark)
final_limit= inp_desc->limit;
}
/*30:*/
#line 712 "tie.w"

if(c!=nl_mark){
err_print("! Input line too long")(i);

while((c= fgetc(inp_desc->the_file))!=EOF&&map_xord(c)!=nl_mark)
do_nothing;
}





/*:30*/
#line 670 "tie.w"

inp_desc->limit= final_limit;
}


/*:27*/
#line 623 "tie.w"

}

Definition at line 351 of file tie.c.

{register input_description*inp_desc= input_organization[i];
/*40:*/
#line 885 "tie.w"

loop{ASCII_Code c;
get_line(i);
if(inp_desc->mode==ignore)return;
if(inp_desc->limit<2)continue;
if(inp_desc->buffer[0]!=64)continue;
c= inp_desc->buffer[1];
if(c>=88&&c<=90)
c+= 122-90;
if(c==120)break;
if(c==121||c==122)
if(b)
err_print("! Where is the matching @x?")(i);

}


/*:40*/
#line 875 "tie.w"

/*41:*/
#line 904 "tie.w"

do{
get_line(i);
if(inp_desc->mode==ignore){
err_print("! Change file ended after @x")(i);

return;
}
}while(inp_desc->limit<=0);


/*:41*/
#line 876 "tie.w"

}

Here is the call graph for this function:

Definition at line 334 of file tie.c.

{
buffer_index k,lmt;
if(input_organization[i]->limit!=input_organization[j]->limit)
return(true);
lmt= input_organization[i]->limit;
for(k= 0;k<lmt;k++)
if(input_organization[i]->buffer[k]!=input_organization[j]->buffer[k])
return(true);
return(false);
}
main ( int  argc,
string argv 
)

Definition at line 459 of file tie.c.

{{/*12:*/
#line 408 "tie.w"

int i;


/*:12*/
#line 1238 "tie.w"

/*10:*/
#line 296 "tie.w"

xchr[32]= ' ';
xchr[33]= '!';
xchr[34]= '\"';
xchr[35]= '#';
xchr[36]= '$';
xchr[37]= '%';
xchr[38]= '&';
xchr[39]= '\'';
xchr[40]= '(';
xchr[41]= ')';
xchr[42]= '*';
xchr[43]= '+';
xchr[44]= ',';
xchr[45]= '-';
xchr[46]= '.';
xchr[47]= '/';
xchr[48]= '0';
xchr[49]= '1';
xchr[50]= '2';
xchr[51]= '3';
xchr[52]= '4';
xchr[53]= '5';
xchr[54]= '6';
xchr[55]= '7';
xchr[56]= '8';
xchr[57]= '9';
xchr[58]= ':';
xchr[59]= ';';
xchr[60]= '<';
xchr[61]= '=';
xchr[62]= '>';
xchr[63]= '?';
xchr[64]= '@';
xchr[65]= 'A';
xchr[66]= 'B';
xchr[67]= 'C';
xchr[68]= 'D';
xchr[69]= 'E';
xchr[70]= 'F';
xchr[71]= 'G';
xchr[72]= 'H';
xchr[73]= 'I';
xchr[74]= 'J';
xchr[75]= 'K';
xchr[76]= 'L';
xchr[77]= 'M';
xchr[78]= 'N';
xchr[79]= 'O';
xchr[80]= 'P';
xchr[81]= 'Q';
xchr[82]= 'R';
xchr[83]= 'S';
xchr[84]= 'T';
xchr[85]= 'U';
xchr[86]= 'V';
xchr[87]= 'W';
xchr[88]= 'X';
xchr[89]= 'Y';
xchr[90]= 'Z';
xchr[91]= '[';
xchr[92]= '\\';
xchr[93]= ']';
xchr[94]= '^';
xchr[95]= '_';
xchr[96]= '`';
xchr[97]= 'a';
xchr[98]= 'b';
xchr[99]= 'c';
xchr[100]= 'd';
xchr[101]= 'e';
xchr[102]= 'f';
xchr[103]= 'g';
xchr[104]= 'h';
xchr[105]= 'i';
xchr[106]= 'j';
xchr[107]= 'k';
xchr[108]= 'l';
xchr[109]= 'm';
xchr[110]= 'n';
xchr[111]= 'o';
xchr[112]= 'p';
xchr[113]= 'q';
xchr[114]= 'r';
xchr[115]= 's';
xchr[116]= 't';
xchr[117]= 'u';
xchr[118]= 'v';
xchr[119]= 'w';
xchr[120]= 'x';
xchr[121]= 'y';
xchr[122]= 'z';
xchr[123]= '{';
xchr[124]= '|';
xchr[125]= '}';
xchr[126]= '~';
xchr[0]= ' ';xchr[0x7F]= ' ';


/*:10*//*13:*/
#line 429 "tie.w"

for(i= 1;i<32;xchr[i++]= ' ');
xchr[tab_mark]= '\t';
xchr[form_feed]= '\f';
xchr[nl_mark]= '\n';


/*:13*//*14:*/
#line 440 "tie.w"

for(i= first_text_char;i<=last_text_char;xord[i++]= 32)do_nothing;
for(i= 1;i<=126;i++)xord[xchr[i]]= i;





/*:14*/
#line 1239 "tie.w"

}
print_ln(banner);
print_ln(copyright);
actual_input= 0;
out_mode= normal;
/*56:*/
#line 1177 "tie.w"

{int act_arg;
if(argc<5||argc>max_file_index+4-1)usage();
no_ch= -1;
for(act_arg= 1;act_arg<argc;act_arg++){
if(argv[act_arg][0]=='-')/*57:*/
#line 1195 "tie.w"

if(prod_chf!=unknown)usage();
else
switch(argv[act_arg][1]){
case'c':
case'C':prod_chf= chf;break;
case'm':
case'M':prod_chf= master;break;
default:usage();
}


/*:57*/
#line 1182 "tie.w"

else/*58:*/
#line 1211 "tie.w"

{if(no_ch==(-1)){
out_name= argv[act_arg];
}else{register input_description*inp_desc;
inp_desc= (input_description*)
malloc(sizeof(input_description));
if(inp_desc==NULL)
fatal_error("! No memory for descriptor");

inp_desc->mode= search;
inp_desc->line= 0;
inp_desc->type_of_file= chf;
inp_desc->limit= 0;
inp_desc->name_of_file= argv[act_arg];
input_organization[no_ch]= inp_desc;
}
incr(no_ch);
}


/*:58*/
#line 1183 "tie.w"

}
if(no_ch<=0||prod_chf==unknown)usage();
}


/*:56*/
#line 1245 "tie.w"

/*34:*/
#line 788 "tie.w"

{
out_file= fopen(out_name,"w");
if(out_file==NULL){
fatal_error("! Could not open/create output file");

}
}


/*:34*/
#line 1246 "tie.w"

/*36:*/
#line 809 "tie.w"

{input_organization[0]->the_file= 
fopen(input_organization[0]->name_of_file,"r");
if(input_organization[0]->the_file==NULL)
fatal_error("! Could not open master file");

print2("(%s)",input_organization[0]->name_of_file);
term_new_line;
input_organization[0]->type_of_file= master;
get_line(0);
}

/*:36*/
#line 1247 "tie.w"

/*37:*/
#line 825 "tie.w"

{file_index i;
i= 1;
while(i<no_ch){
input_organization[i]->the_file= 
fopen(input_organization[i]->name_of_file,"r");
if(input_organization[i]->the_file==NULL)
fatal_error("!Could not open change file");

print2("(%s)",input_organization[i]->name_of_file);
term_new_line;
init_change_file(i,true);
incr(i);
}
}





/*:37*/
#line 1248 "tie.w"

/*53:*/
#line 1128 "tie.w"

actual_input= 0;
input_has_ended= false;
while(input_has_ended==false||actual_input!=0)
/*45:*/
#line 970 "tie.w"

{file_index test_file;
/*46:*/
#line 985 "tie.w"

{register input_description*inp_desc;
while(actual_input>0&&e_of_ch_module(actual_input)){
inp_desc= input_organization[actual_input];
if(inp_desc->type_of_file==master){

fatal_error("! This can't happen: change file is master file");

}
inp_desc->mode= search;
init_change_file(actual_input,true);
while((input_organization[actual_input]->mode!=reading
&&actual_input>0))decr(actual_input);
}
}


/*:46*/
#line 972 "tie.w"

if(input_has_ended&&actual_input==0)break;
/*47:*/
#line 1009 "tie.w"

test_input= none;
test_file= actual_input;
while(test_input==none&&test_file<no_ch-1){
incr(test_file);
switch(input_organization[test_file]->mode){
case search:if(lines_dont_match(actual_input,test_file)==false){
input_organization[test_file]->mode= test;
test_input= test_file;
}
break;
case test:if(lines_dont_match(actual_input,test_file)==true){

input_organization[test_file]->mode= search;
err_print("! Sections do not match")(actual_input);

err_loc(test_file);
init_change_file(test_file,false);
}else test_input= test_file;
break;
case reading:do_nothing;
break;
case ignore:do_nothing;
break;
}
}


/*:47*/
#line 974 "tie.w"

/*48:*/
#line 1043 "tie.w"

if(prod_chf==chf){
loop{
/*49:*/
#line 1057 "tie.w"

if(out_mode==normal){
if(test_input!=none){
fputc(map_xchr(64),out_file);fputc(map_xchr(120),out_file);
new_line(out_file);
out_mode= pre;
}else break;
}


/*:49*/
#line 1046 "tie.w"

/*50:*/
#line 1071 "tie.w"


if(out_mode==pre){
if(test_input==none){
fputc(map_xchr(64),out_file);fputc(map_xchr(121),out_file);
new_line(out_file);
out_mode= post;
}else{
if(input_organization[actual_input]->type_of_file==master)
put_line(actual_input);
break;
}
}


/*:50*/
#line 1047 "tie.w"

/*51:*/
#line 1092 "tie.w"

if(out_mode==post){
if(input_organization[actual_input]->type_of_file==chf){
if(test_input==none)put_line(actual_input);
break;
}else{
fputc(map_xchr(64),out_file);fputc(map_xchr(122),out_file);
new_line(out_file);
new_line(out_file);
out_mode= normal;
}
}


/*:51*/
#line 1048 "tie.w"

}
}else
if(test_input==none)put_line(actual_input);


/*:48*/
#line 975 "tie.w"

/*52:*/
#line 1109 "tie.w"

get_line(actual_input);
if(test_input!=none){
get_line(test_input);
if(e_of_ch_preamble(test_input)==true){
get_line(test_input);
input_organization[test_input]->mode= reading;
actual_input= test_input;
test_input= none;
}
}


/*:52*/
#line 976 "tie.w"

}


/*:45*/
#line 1132 "tie.w"

if(out_mode==post){
fputc(map_xchr(64),out_file);fputc(map_xchr(122),out_file);
new_line(out_file);
}


/*:53*/
#line 1249 "tie.w"

/*54:*/
#line 1143 "tie.w"

{file_index i;
for(i= 1;i<no_ch;i++){
if(input_organization[i]->mode!=ignore)
err_print("! Change file entry did not match")(i);

}
}


/*:54*/
#line 1250 "tie.w"

/*60:*/
#line 1261 "tie.w"

{string msg;
switch(history){
case spotless:msg= "No errors were found";break;
case troublesome:msg= "Pardon me, but I think I spotted something wrong.";
break;
case fatal:msg= "That was a fatal error, my friend";break;
}
print2_nl("(%s.)",msg);term_new_line;
exit(history==spotless?0:1);
}





/*:60*/
#line 1251 "tie.w"

}

Here is the call graph for this function:

Definition at line 398 of file tie.c.

void usage ( void  )

Definition at line 445 of file tie.c.

{
print("Usage: tie -[mc] outfile master changefile(s)");
term_new_line;
jump_out();
}

Variable Documentation

Definition at line 191 of file tie.c.

int history = spotless [static]

Definition at line 175 of file tie.c.

Definition at line 208 of file tie.c.

Definition at line 199 of file tie.c.

file_index no_ch [static]

Definition at line 191 of file tie.c.

text_file out_file [static]

Definition at line 214 of file tie.c.

Definition at line 193 of file tie.c.

string out_name [static]

Definition at line 215 of file tie.c.

Definition at line 192 of file tie.c.

Definition at line 191 of file tie.c.

text_char xchr[max_ASCII+1] [static]

Definition at line 184 of file tie.c.

Definition at line 182 of file tie.c.