⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.c

📁 著名算法大师高爷爷设计的语言。此语言结合了Tex和C
💻 C
📖 第 1 页 / 共 2 页
字号:
/*1:*/#line 58 "common.w"/*5:*/#line 102 "common.w"#include <ctype.h> /*:5*//*8:*/#line 165 "common.w"#include <stdio.h> /*:8*//*22:*/#line 471 "common.w"#include <stdlib.h>  /*:22*/#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 longest_name 1000#define long_buf_size (buf_size+longest_name) #define xisspace(c) (isspace(c) &&((unsigned char) c<0200) ) #define xisupper(c) (isupper(c) &&((unsigned char) c<0200) )  \#define max_include_depth 10 \#define max_file_name_length 60#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;xisspace(*loc) ;loc++) ; \*limit= ' '; \if(*loc=='@'&&(xisspace(*(loc+1) ) ||*(loc+1) =='*') ) change_pending= b; \} \#define max_sections 2000 \ \#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 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 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)  \#line 60 "common.w"/*2:*/#line 73 "common.w"typedef short boolean;boolean program;/*:2*//*7:*/#line 159 "common.w"char buffer[long_buf_size];char*buffer_end= buffer+buf_size-2;char*limit= buffer;char*loc= buffer;/*:7*//*10:*/#line 214 "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;/*:10*//*20:*/#line 418 "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 594 "common.w"typedef struct name_info{char*byte_start;/*31:*/#line 631 "common.w"struct name_info*link;/*:31*//*40:*/#line 730 "common.w"union{struct name_info*Rlink;char Ilk;}dummy;/*:40*//*55:*/#line 1062 "common.w"char*equiv_or_xref;/*:55*/#line 597 "common.w"}name_info;typedef name_info*name_pointer;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;/*:27*//*29:*/#line 617 "common.w"name_pointer name_ptr;char*byte_ptr;/*:29*//*32:*/#line 644 "common.w"typedef name_pointer*hash_pointer;name_pointer hash[hash_size];hash_pointer hash_end= hash+hash_size-1;hash_pointer h;/*:32*//*56:*/#line 1082 "common.w"int history= spotless;/*:56*//*67:*/#line 1220 "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];boolean flags[128];/*:67*//*77:*/#line 1370 "common.w"FILE*C_file;FILE*tex_file;FILE*idx_file;FILE*scn_file;FILE*active_file;/*:77*/#line 61 "common.w"/*3:*/#line 83 "common.w"int phase;/*:3*//*11:*/#line 240 "common.w"char change_buffer[buf_size];char*change_limit;/*:11*/#line 62 "common.w"/*33:*/#line 650 "common.w"extern int names_match();/*:33*//*38:*/#line 703 "common.w"void init_p();/*:38*//*46:*/#line 852 "common.w"extern void init_node();/*:46*//*53:*/#line 1017 "common.w"int section_name_cmp();/*:53*//*57:*/#line 1092 "common.w"void err_print();/*:57*//*60:*/#line 1140 "common.w"int wrap_up();extern void print_stats();/*:60*//*63:*/#line 1173 "common.w"void fatal(),overflow();/*:63*//*69:*/#line 1251 "common.w"void scan_args();/*:69*//*81:*/#line 1411 "common.w"extern int strlen();extern int strcmp();extern char*strcpy();extern int strncmp();extern char*strncpy();/*:81*/#line 63 "common.w"/*:1*//*4:*/#line 89 "common.w"voidcommon_init(){/*30:*/#line 621 "common.w"name_dir->byte_start= byte_ptr= byte_mem;name_ptr= name_dir+1;name_ptr->byte_start= byte_mem;/*:30*//*34:*/#line 655 "common.w"for(h= hash;h<=hash_end;*h++= NULL);/*:34*//*41:*/#line 737 "common.w"root= NULL;/*:41*/#line 93 "common.w";/*68:*/#line 1233 "common.w"show_banner= show_happiness= show_progress= 1;/*:68*/#line 94 "common.w";/*78:*/#line 1377 "common.w"scan_args();if(program==ctangle){if((C_file= fopen(C_file_name,"w"))==NULL)fatal("! Cannot open output file ",C_file_name);}else{if((tex_file= fopen(tex_file_name,"w"))==NULL)fatal("! Cannot open output file ",tex_file_name);}/*:78*/#line 95 "common.w";}/*:4*//*9:*/#line 172 "common.w"int input_ln(fp)FILE*fp;{register int c= EOF;register char*k;if(feof(fp))return(0);limit= k= buffer;while(k<=buffer_end&&(c= getc(fp))!=EOF&&c!='\n')if((*(k++)= c)!=' ')limit= k;if(k> buffer_end)if((c= getc(fp))!=EOF&&c!='\n'){ungetc(c,fp);loc= buffer;err_print("! Input line too long");}if(c==EOF&&limit==buffer)return(0);return(1);}/*:9*//*12:*/#line 251 "common.w"voidprime_the_change_buffer(){change_limit= change_buffer;/*13:*/#line 265 "common.w"while(1){change_line++;if(!input_ln(change_file))return;if(limit<buffer+2)continue;if(buffer[0]!='@')continue;if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);if(buffer[1]=='x')break;if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){loc= buffer+2;err_print("! Missing @x in change file");}}/*:13*/#line 256 "common.w";/*14:*/#line 282 "common.w"do{change_line++;if(!input_ln(change_file)){err_print("! Change file ended after @x");return;}}while(limit==buffer);/*:14*/#line 257 "common.w";/*15:*/#line 292 "common.w"{change_limit= change_buffer+(limit-buffer);strncpy(change_buffer,buffer,limit-buffer+1);}/*:15*/#line 258 "common.w";}/*:12*//*16:*/#line 320 "common.w"voidcheck_change(){int n= 0;if(lines_dont_match)return;change_pending= 0;if(!changed_section[section_count]){if_section_start_make_pending(1);if(!change_pending)changed_section[section_count]= 1;}while(1){changing= 1;print_where= 1;change_line++;if(!input_ln(change_file)){err_print("! Change file ended before @y");change_limit= change_buffer;changing= 0;return;}if(limit> buffer+1&&buffer[0]=='@'){char xyz_code= xisupper(buffer[1])?tolower(buffer[1]):buffer[1];/*17:*/#line 358 "common.w"if(xyz_code=='x'||xyz_code=='z'){loc= buffer+2;err_print("! Where is the matching @y?");}else if(xyz_code=='y'){if(n> 0){loc= buffer+2;printf("\n! Hmm... %d ",n);err_print("of the preceding lines failed to match");}change_depth= include_depth;return;}/*:17*/#line 342 "common.w";}/*15:*/#line 292 "common.w"{change_limit= change_buffer+(limit-buffer);strncpy(change_buffer,buffer,limit-buffer+1);}/*:15*/#line 344 "common.w";changing= 0;cur_line++;while(!input_ln(cur_file)){if(include_depth==0){err_print("! CWEB file ended during a change");input_has_ended= 1;return;}include_depth--;cur_line++;}if(lines_dont_match)n++;}}/*:16*//*18:*/#line 378 "common.w"voidreset_input(){limit= buffer;loc= buffer+1;buffer[0]= ' ';/*19:*/#line 393 "common.w"if((web_file= fopen(web_file_name,"r"))==NULL){strcpy(web_file_name,alt_web_file_name);if((web_file= fopen(web_file_name,"r"))==NULL)fatal("! Cannot open input file ",web_file_name);}web_file_open= 1;if((change_file= fopen(change_file_name,"r"))==NULL)fatal("! Cannot open change file ",change_file_name);/*:19*/#line 383 "common.w";include_depth= 0;cur_line= 0;change_line= 0;change_depth= include_depth;changing= 1;prime_the_change_buffer();changing= !changing;limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= 0;}/*:18*//*21:*/#line 426 "common.w"int get_line(){restart:if(changing&&include_depth==change_depth)/*25:*/#line 537 "common.w"{change_line++;if(!input_ln(change_file)){err_print("! Change file ended without @z");buffer[0]= '@';buffer[1]= 'z';limit= buffer+2;}if(limit> buffer){if(change_pending){if_section_start_make_pending(0);if(change_pending){changed_section[section_count]= 1;change_pending= 0;}}*limit= ' ';if(buffer[0]=='@'){if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);if(buffer[1]=='x'||buffer[1]=='y'){loc= buffer+2;err_print("! Where is the matching @z?");}else if(buffer[1]=='z'){prime_the_change_buffer();changing= !changing;print_where= 1;}}}}/*:25*/#line 431 "common.w";if(!changing||include_depth> change_depth){/*24:*/#line 520 "common.w"{cur_line++;while(!input_ln(cur_file)){print_where= 1;if(include_depth==0){input_has_ended= 1;break;}else{fclose(cur_file);include_depth--;if(changing&&include_depth==change_depth)break;cur_line++;}}if(!changing&&!input_has_ended)if(limit-buffer==change_limit-change_buffer)if(buffer[0]==change_buffer[0])if(change_limit> change_buffer)check_change();}/*:24*/#line 433 "common.w";if(changing&&include_depth==change_depth)goto restart;}if(input_has_ended)return 0;loc= buffer;*limit= ' ';if(buffer[0]=='@'&&(buffer[1]=='i'||buffer[1]=='I')){loc= buffer+2;*limit= '"';while(*loc==' '||*loc=='\t')loc++;if(loc>=limit){err_print("! Include file name not given");goto restart;}if(include_depth>=max_include_depth-1){err_print("! Too many nested includes");goto restart;}include_depth++;/*23:*/#line 474 "common.w"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -