home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 2
/
FFMCD02.bin
/
new
/
dev
/
misc
/
cweb
/
common.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-21
|
30KB
|
1,525 lines
/*1:*/
#line 57 "common.w"
#line 140 "common-p.ch"
/*5:*/
#line 101 "common.w"
#include <ctype.h>
/*:5*//*8:*/
#line 161 "common.w"
#include <stdio.h>
/*:8*//*22:*/
#line 466 "common.w"
#include <stdlib.h>
/*:22*//*81:*/
#line 808 "common-p.ch"
#line 809 "common-p.ch"
#include <string.h>
/*:81*//*86:*/
#line 874 "common-p.ch"
#ifdef __TURBOC__
#include <alloc.h>
#include <io.h>
#endif
/*:86*//*90:*/
#line 925 "common-p.ch"
#include <stdlib.h>
/*:90*/
#line 140 "common-p.ch"
/*87:*/
#line 881 "common-p.ch"
#ifdef __TURBOC__
#define HUGE huge
#else
#define HUGE
#endif
/*:87*/
#line 141 "common-p.ch"
#line 59 "common.w"
#define ctangle 0
#define cweave 1 \
#define and_and 04
#define lt_lt 020
#define gt_gt 021
#define plus_plus 013
#define minus_minus 01
#define minus_gt 031
#define not_eq 032
#define lt_eq 034
#define gt_eq 035
#define eq_eq 036
#define or_or 037
#define dot_dot_dot 016
#define colon_colon 06
#define period_ast 026
#define minus_gt_ast 027 \
#define buf_size 100
#define long_buf_size 500 \
#define max_include_depth 10 \
\
#define max_file_name_length 256 \
#define cur_file file[include_depth]
#define cur_file_name file_name[include_depth]
#define cur_line line[include_depth]
#define web_file file[0]
#define web_file_name file_name[0] \
#define lines_dont_match (change_limit-change_buffer!=limit-buffer|| \
strncmp(buffer,change_buffer,limit-buffer) ) \
#define if_section_start_make_pending(b) {*limit= '!'; \
for(loc= buffer;isspace(*loc) ;loc++) ; \
*limit= ' '; \
if(*loc=='@'&&(isspace(*(loc+1) ) ||*(loc+1) =='*') ) change_pending= b; \
} \
#define max_sections 2000 \
\
#define PATH_SEPARATOR ','
#define DIR_SEPARATOR '/'
#define DEVICE_SEPARATOR ':' \
#define too_long() {include_depth--; \
err_print("! Include file name too long") ;goto restart;} \
#define max_bytes 90000 \
#define max_names 4000 \
\
#define length(c) (c+1) ->byte_start-(c) ->byte_start
#define print_id(c) term_write((c) ->byte_start,length((c) ) ) \
#define hash_size 353 \
#define llink link
#define rlink dummy.Rlink
#define root name_dir->rlink \
\
#define first_chunk(p) ((p) ->byte_start+2)
#define prefix_length(p) (int) ((unsigned char) *((p) ->byte_start) *256+ \
(unsigned char) *((p) ->byte_start+1) )
#define set_prefix_length(p,m) (*((p) ->byte_start) = (m) /256, \
*((p) ->byte_start+1) = (m) %256) \
#define less 0
#define equal 1
#define greater 2
#define prefix 3
#define extension 4 \
#define bad_extension 5 \
\
#define spotless 0
#define harmless_message 1
#define error_message 2
#define fatal_message 3
#define mark_harmless {if(history==spotless) history= harmless_message;}
#define mark_error history= error_message \
#define RETURN_OK 0
#define RETURN_WARN 5
#define RETURN_ERROR 10
#define RETURN_FAIL 20 \
#define confusion(s) fatal("! This can't happen: ",s) \
\
#define show_banner flags['b']
#define show_progress flags['p']
#define show_stats flags['s']
#define show_happiness flags['h']
#define use_amiga_keywords flags['a']
#define use_german_macros flags['g']
#define indent_param_decl flags['i'] \
#define update_terminal fflush(stdout) \
#define new_line putchar('\n')
#define putxchar putchar
#define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout)
#define C_printf(c,a) fprintf(C_file,c,a)
#define C_putc(c) putc(c,C_file) \
#define MAXPATHLENGTH 4095
#define CWEBINPUTS ",CWeb:,CWeb:include,CWeb:inputs" \
#line 59 "common.w"
/*2:*/
#line 72 "common.w"
typedef short boolean;
boolean program;
/*:2*//*7:*/
#line 155 "common.w"
char buffer[long_buf_size];
char*buffer_end= buffer+buf_size-2;
char*limit= buffer;
char*loc= buffer;
/*:7*//*10:*/
#line 210 "common.w"
int include_depth;
FILE*file[max_include_depth];
FILE*change_file;
char file_name[max_include_depth][max_file_name_length];
char change_file_name[max_file_name_length];
char alt_web_file_name[max_file_name_length];
int line[max_include_depth];
int change_line;
int change_depth;
boolean input_has_ended;
boolean changing;
boolean web_file_open= 0;
#line 177 "common-p.ch"
/*:10*//*20:*/
#line 414 "common.w"
typedef unsigned short sixteen_bits;
sixteen_bits section_count;
boolean changed_section[max_sections];
boolean change_pending;
boolean print_where= 0;
/*:20*//*27:*/
#line 584 "common.w"
typedef struct name_info{
#line 298 "common-p.ch"
char HUGE*byte_start;
#line 587 "common.w"
/*31:*/
#line 621 "common.w"
#line 343 "common-p.ch"
struct name_info HUGE*link;
#line 623 "common.w"
/*:31*//*40:*/
#line 720 "common.w"
union{
#line 381 "common-p.ch"
struct name_info HUGE*Rlink;
#line 724 "common.w"
char Ilk;
}dummy;
/*:40*//*55:*/
#line 1052 "common.w"
#line 550 "common-p.ch"
char HUGE*equiv_or_xref;
#line 1054 "common.w"
/*:55*/
#line 587 "common.w"
}name_info;
#line 308 "common-p.ch"
typedef name_info HUGE*name_pointer;
#ifdef __TURBOC__
char HUGE*byte_mem;
char HUGE*byte_mem_end;
name_info HUGE*name_dir;
name_pointer name_dir_end;
#else
char byte_mem[max_bytes];
char*byte_mem_end= byte_mem+max_bytes-1;
name_info name_dir[max_names];
name_pointer name_dir_end= name_dir+max_names-1;
#endif
#line 594 "common.w"
/*:27*//*29:*/
#line 607 "common.w"
name_pointer name_ptr;
#line 325 "common-p.ch"
char HUGE*byte_ptr;
#line 610 "common.w"
/*:29*//*32:*/
#line 634 "common.w"
typedef name_pointer*hash_pointer;
name_pointer hash[hash_size];
hash_pointer hash_end= hash+hash_size-1;
hash_pointer h;
#line 350 "common-p.ch"
/*:32*//*56:*/
#line 1072 "common.w"
int history= spotless;
/*:56*//*67:*/
#line 1210 "common.w"
int argc;
char**argv;
char C_file_name[max_file_name_length];
char tex_file_name[max_file_name_length];
char idx_file_name[max_file_name_length];
char scn_file_name[max_file_name_length];
#line 678 "common-p.ch"
boolean flags[256];
#line 1218 "common.w"
/*:67*//*77:*/
#line 1361 "common.w"
FILE*C_file;
FILE*tex_file;
FILE*idx_file;
FILE*scn_file;
FILE*active_file;
/*:77*/
#line 60 "common.w"
/*3:*/
#line 82 "common.w"
int phase;
/*:3*//*11:*/
#line 236 "common.w"
char change_buffer[buf_size];
char*change_limit;
/*:11*//*83:*/
#line 840 "common-p.ch"
char include_path[MAXPATHLENGTH+1]= CWEBINPUTS;
char*p,*path_prefix,*next_path_prefix;
/*:83*//*88:*/
#line 893 "common-p.ch"
#ifdef _AMIGA
typedef unsigned char eight_bits;
#else
typedef char unsigned eight_bits;
#endif
void common_init(void);
void reset_input(void);
int get_line(void);
void check_complete(void);
name_pointer id_lookup(char*first,char*last,char t);
void print_section_name(name_pointer);
void sprint_section_name(char*,name_pointer);
void print_prefix_name(name_pointer);
name_pointer add_section_name(name_pointer par,int c,
char*first,char*last,int ispref);
void extend_section_name(name_pointer p,char*first,char*last,int ispref);
name_pointer section_lookup(char*first,char*last,int ispref);
/*:88*//*89:*/
#line 914 "common-p.ch"
static int input_ln(FILE*fp);
static void prime_the_change_buffer(void);
static void check_change(void);
static int web_strcmp(char HUGE*j,int j_len,char HUGE*k,int k_len);
static boolean set_path(char*ptr,char*override);
/*:89*/
#line 61 "common.w"
/*33:*/
#line 350 "common-p.ch"
extern int names_match(name_pointer,char*,int,eight_bits);
#line 642 "common.w"
/*:33*//*38:*/
#line 374 "common-p.ch"
#line 375 "common-p.ch"
extern void init_p(name_pointer,eight_bits);
#line 695 "common.w"
/*:38*//*46:*/
#line 451 "common-p.ch"
#line 452 "common-p.ch"
extern void init_node(name_pointer);
#line 844 "common.w"
/*:46*//*53:*/
#line 524 "common-p.ch"
static int section_name_cmp(char**,int,name_pointer);
#line 1009 "common.w"
/*:53*//*57:*/
#line 564 "common-p.ch"
#line 565 "common-p.ch"
extern void err_print(char*);
#line 1084 "common.w"
/*:57*//*60:*/
#line 581 "common-p.ch"
#line 582 "common-p.ch"
int wrap_up(void);
extern void print_stats(void);
#line 1133 "common.w"
#line 606 "common-p.ch"
/*:60*//*63:*/
#line 638 "common-p.ch"
#line 639 "common-p.ch"
extern void fatal(char*,char*);
extern void overflow(char*);
#line 1165 "common.w"
/*:63*//*69:*/
#line 706 "common-p.ch"
#line 707 "common-p.ch"
static void scan_args(void);
#line 1243 "common.w"
/*:69*//*84:*/
#line 858