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

📄 ctangle.c

📁 著名算法大师高爷爷设计的语言。此语言结合了Tex和C
💻 C
📖 第 1 页 / 共 2 页
字号:
/*1:*/#line 64 "./ctangle.w"/*6:*/#line 35 "./common.h"#include <stdio.h> /*:6*//*62:*/#line 888 "./ctangle.w"#include <ctype.h>  #include <stdlib.h>  /*:62*/#line 65 "./ctangle.w"#define banner "This is CTANGLE (Version 3.64)\n" \#define max_bytes 90000 \#define max_toks 270000#define max_names 4000 \#define max_texts 2500#define hash_size 353#define longest_name 10000#define stack_size 50#define buf_size 100 \#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 xisalpha(c) (isalpha(c) &&((eight_bits) c<0200) ) #define xisdigit(c) (isdigit(c) &&((eight_bits) c<0200) ) #define xisspace(c) (isspace(c) &&((eight_bits) c<0200) ) #define xislower(c) (islower(c) &&((eight_bits) c<0200) ) #define xisupper(c) (isupper(c) &&((eight_bits) c<0200) ) #define xisxdigit(c) (isxdigit(c) &&((eight_bits) c<0200) )  \#define length(c) (c+1) ->byte_start-(c) ->byte_start#define print_id(c) term_write((c) ->byte_start,length((c) ) ) #define llink link#define rlink dummy.Rlink#define root name_dir->rlink \#define chunk_marker 0 \#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 max_file_name_length 60#define cur_file file[include_depth]#define cur_file_name file_name[include_depth]#define web_file_name file_name[0]#define cur_line line[include_depth] \#define show_banner flags['b']#define show_progress flags['p']#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)  \#define equiv equiv_or_xref \#define section_flag max_texts \#define string 02#define join 0177#define output_defs_flag (2*024000-1)  \#define cur_end cur_state.end_field#define cur_byte cur_state.byte_field#define cur_name cur_state.name_field#define cur_repl cur_state.repl_field#define cur_section cur_state.section_field \#define section_number 0201#define identifier 0202 \#define normal 0#define num_or_id 1#define post_slash 2#define unbreakable 3#define verbatim 4 \#define max_files 256#define translit_length 10 \#define ignore 0#define ord 0302#define control_text 0303#define translit_code 0304#define output_defs_code 0305#define format_code 0306#define definition 0307#define begin_C 0310#define section_name 0311#define new_section 0312 \#define constant 03 \#define isxalpha(c) ((c) =='_'||(c) =='$')  \#define ishigh(c) ((unsigned char) (c) > 0177)  \ \#define compress(c) if(loc++<=limit) return(c)  \#define macro 0#define app_repl(c) {if(tok_ptr==tok_mem_end) overflow("token") ;*tok_ptr++= c;} \#line 66 "./ctangle.w"/*5:*/#line 29 "./common.h"typedef short boolean;typedef char unsigned eight_bits;extern boolean program;extern int phase;/*:5*//*7:*/#line 57 "./common.h"char section_text[longest_name+1];char*section_text_end= section_text+longest_name;char*id_first;char*id_loc;/*:7*//*8:*/#line 72 "./common.h"extern char buffer[];extern char*buffer_end;extern char*loc;extern char*limit;/*:8*//*9:*/#line 87 "./common.h"typedef struct name_info{char*byte_start;struct name_info*link;union{struct name_info*Rlink;char Ilk;}dummy;char*equiv_or_xref;}name_info;typedef name_info*name_pointer;typedef name_pointer*hash_pointer;extern char byte_mem[];extern char*byte_mem_end;extern name_info name_dir[];extern name_pointer name_dir_end;extern name_pointer name_ptr;extern char*byte_ptr;extern name_pointer hash[];extern hash_pointer hash_end;extern hash_pointer h;extern name_pointer id_lookup();extern name_pointer section_lookup();extern void print_section_name(),sprint_section_name();/*:9*//*10:*/#line 122 "./common.h"extern history;extern err_print();extern wrap_up();extern void fatal();extern void overflow();/*:10*//*11:*/#line 137 "./common.h"extern include_depth;extern FILE*file[];extern FILE*change_file;extern char C_file_name[];extern char tex_file_name[];extern char idx_file_name[];extern char scn_file_name[];extern char file_name[][max_file_name_length];extern char change_file_name[];extern line[];extern change_line;extern boolean input_has_ended;extern boolean changing;extern boolean web_file_open;extern reset_input();extern get_line();extern check_complete();/*:11*//*12:*/#line 158 "./common.h"typedef unsigned short sixteen_bits;extern sixteen_bits section_count;extern boolean changed_section[];extern boolean change_pending;extern boolean print_where;/*:12*//*13:*/#line 170 "./common.h"extern int argc;extern char**argv;extern boolean flags[];/*:13*//*14:*/#line 182 "./common.h"extern FILE*C_file;extern FILE*tex_file;extern FILE*idx_file;extern FILE*scn_file;extern FILE*active_file;/*:14*//*15:*/#line 191 "./common.h"extern void common_init();#line 128 "./ctangle.w"/*:15*/#line 67 "./ctangle.w"/*16:*/#line 152 "./ctangle.w"typedef struct{eight_bits*tok_start;sixteen_bits text_link;}text;typedef text*text_pointer;/*:16*//*27:*/#line 296 "./ctangle.w"typedef struct{eight_bits*end_field;eight_bits*byte_field;name_pointer name_field;text_pointer repl_field;sixteen_bits section_field;}output_state;typedef output_state*stack_pointer;/*:27*/#line 68 "./ctangle.w"/*17:*/#line 159 "./ctangle.w"text text_info[max_texts];text_pointer text_info_end= text_info+max_texts-1;text_pointer text_ptr;eight_bits tok_mem[max_toks];eight_bits*tok_mem_end= tok_mem+max_toks-1;eight_bits*tok_ptr;/*:17*//*23:*/#line 227 "./ctangle.w"text_pointer last_unnamed;/*:23*//*28:*/#line 312 "./ctangle.w"output_state cur_state;output_state stack[stack_size+1];stack_pointer stack_ptr;stack_pointer stack_end= stack+stack_size;/*:28*//*32:*/#line 384 "./ctangle.w"int cur_val;/*:32*//*36:*/#line 473 "./ctangle.w"eight_bits out_state;boolean protect;/*:36*//*38:*/#line 502 "./ctangle.w"name_pointer output_files[max_files];name_pointer*cur_out_file,*end_output_files,*an_output_file;char cur_section_name_char;char output_file_name[longest_name];/*:38*//*45:*/#line 599 "./ctangle.w"boolean output_defs_seen= 0;/*:45*//*51:*/#line 710 "./ctangle.w"char translit[128][translit_length];/*:51*//*56:*/#line 789 "./ctangle.w"eight_bits ccode[256];/*:56*//*59:*/#line 845 "./ctangle.w"boolean comment_continues= 0;/*:59*//*61:*/#line 884 "./ctangle.w"name_pointer cur_section_name;int no_where;/*:61*//*75:*/#line 1195 "./ctangle.w"text_pointer cur_text;eight_bits next_control;/*:75*//*82:*/#line 1350 "./ctangle.w"extern sixteen_bits section_count;/*:82*/#line 69 "./ctangle.w"/*2:*/#line 77 "./ctangle.w"extern int strlen();extern int strcmp();extern char*strcpy();extern int strncmp();extern char*strncpy();/*:2*//*41:*/#line 533 "./ctangle.w"void phase_two();/*:41*//*46:*/#line 602 "./ctangle.w"void output_defs();/*:46*//*48:*/#line 648 "./ctangle.w"static void out_char();/*:48*//*90:*/#line 1457 "./ctangle.w"void phase_one();/*:90*//*92:*/#line 1475 "./ctangle.w"void skip_limbo();/*:92*/#line 70 "./ctangle.w"/*:1*//*3:*/#line 91 "./ctangle.w"int main(ac,av)int ac;char**av;{argc= ac;argv= av;program= ctangle;/*18:*/#line 167 "./ctangle.w"text_info->tok_start= tok_ptr= tok_mem;text_ptr= text_info+1;text_ptr->tok_start= tok_mem;/*:18*//*20:*/#line 177 "./ctangle.w"name_dir->equiv= (char*)text_info;/*:20*//*24:*/#line 230 "./ctangle.w"last_unnamed= text_info;text_info->text_link= 0;/*:24*//*39:*/#line 512 "./ctangle.w"cur_out_file= end_output_files= output_files+max_files;/*:39*//*52:*/#line 713 "./ctangle.w"{int i;for(i= 0;i<128;i++)sprintf(translit[i],"X%02X",(unsigned)(128+i));}/*:52*//*57:*/#line 792 "./ctangle.w"{int c;for(c= 0;c<256;c++)ccode[c]= ignore;ccode[' ']= ccode['\t']= ccode['\n']= ccode['\v']= ccode['\r']= ccode['\f']= ccode['*']= new_section;ccode['@']= '@';ccode['=']= string;ccode['d']= ccode['D']= definition;ccode['f']= ccode['F']= ccode['s']= ccode['S']= format_code;ccode['c']= ccode['C']= ccode['p']= ccode['P']= begin_C;ccode['^']= ccode[':']= ccode['.']= ccode['t']= ccode['T']= ccode['q']= ccode['Q']= control_text;ccode['h']= ccode['H']= output_defs_code;ccode['l']= ccode['L']= translit_code;ccode['&']= join;ccode['<']= ccode['(']= section_name;ccode['\'']= ord;}/*:57*//*71:*/#line 1116 "./ctangle.w"section_text[0]= ' ';/*:71*/#line 98 "./ctangle.w";common_init();if(show_banner)printf(banner);phase_one();phase_two();return wrap_up();}/*:3*//*21:*/#line 183 "./ctangle.w"int names_match(p,first,l)name_pointer p;char*first;int l;{if(length(p)!=l)return 0;return!strncmp(first,p->byte_start,l);}/*:21*//*22:*/#line 198 "./ctangle.w"voidinit_node(node)name_pointer node;{node->equiv= (char*)text_info;}voidinit_p(){}/*:22*//*26:*/#line 260 "./ctangle.w"voidstore_two_bytes(x)sixteen_bits x;{if(tok_ptr+2> tok_mem_end)overflow("token");*tok_ptr++= x>>8;*tok_ptr++= x&0377;}/*:26*//*30:*/#line 336 "./ctangle.w"voidpush_level(p)name_pointer p;{if(stack_ptr==stack_end)overflow("stack");*stack_ptr= cur_state;stack_ptr++;if(p!=NULL){cur_name= p;cur_repl= (text_pointer)p->equiv;cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;cur_section= 0;}}/*:30*//*31:*/#line 355 "./ctangle.w"voidpop_level(flag)int flag;{if(flag&&cur_repl->text_link<section_flag){cur_repl= cur_repl->text_link+text_info;cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;return;}stack_ptr--;if(stack_ptr> stack)cur_state= *stack_ptr;}/*:31*//*33:*/#line 391 "./ctangle.w"voidget_output(){sixteen_bits a;restart:if(stack_ptr==stack)return;if(cur_byte==cur_end){cur_val= -((int)cur_section);pop_level(1);if(cur_val==0)goto restart;out_char(section_number);return;}a= *cur_byte++;if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')C_putc(a);else if(a<0200)out_char(a);else{a= (a-0200)*0400+*cur_byte++;switch(a/024000){case 0:cur_val= a;out_char(identifier);break;case 1:if(a==output_defs_flag)output_defs();else/*34:*/#line 423 "./ctangle.w"{a-= 024000;if((a+name_dir)->equiv!=(char*)text_info)push_level(a+name_dir);else if(a!=0){printf("\n! Not present: <");print_section_name(a+name_dir);err_print(">");}goto restart;}/*:34*/#line 412 "./ctangle.w";break;default:cur_val= a-050000;if(cur_val> 0)cur_section= cur_val;out_char(section_number);}}}/*:33*//*37:*/#line 481 "./ctangle.w"voidflush_buffer(){C_putc('\n');if(cur_line%100==0&&show_progress){printf(".");if(cur_line%500==0)printf("%d",cur_line);update_terminal;}cur_line++;}/*:37*//*42:*/#line 536 "./ctangle.w"voidphase_two(){web_file_open= 0;cur_line= 1;/*29:*/#line 325 "./ctangle.w"stack_ptr= stack+1;cur_name= name_dir;cur_repl= text_info->text_link+text_info;cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;cur_section= 0;/*:29*/#line 541 "./ctangle.w";/*44:*/#line 595 "./ctangle.w"if(!output_defs_seen)output_defs();/*:44*/#line 542 "./ctangle.w";if(text_info->text_link==0&&cur_out_file==end_output_files){printf("\n! No program text was specified.");mark_harmless;}else{if(cur_out_file==end_output_files){if(show_progress)printf("\nWriting the output file (%s):",C_file_name);}else{if(show_progress){printf("\nWriting the output files:");printf(" (%s)",C_file_name);update_terminal;}if(text_info->text_link==0)goto writeloop;}while(stack_ptr> stack)get_output();flush_buffer();writeloop:/*43:*/#line 572 "./ctangle.w"for(an_output_file= end_output_files;an_output_file> cur_out_file;){an_output_file--;sprint_section_name(output_file_name,*an_output_file);fclose(C_file);C_file= fopen(output_file_name,"w");if(C_file==0)fatal("! Cannot open output file:",output_file_name);printf("\n(%s)",output_file_name);update_terminal;cur_line= 1;stack_ptr= stack+1;cur_name= (*an_output_file);cur_repl= (text_pointer)cur_name->equiv;cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;while(stack_ptr> stack)get_output();flush_buffer();}/*:43*/#line 563 "./ctangle.w";if(show_happiness)printf("\nDone.");}}/*:42*//*47:*/#line 605 "./ctangle.w"voidoutput_defs(){sixteen_bits a;push_level(NULL);for(cur_text= text_info+1;cur_text<text_ptr;cur_text++)if(cur_text->text_link==0){cur_byte= cur_text->tok_start;cur_end= (cur_text+1)->tok_start;C_printf("%s","#define ");out_state= normal;protect= 1;while(cur_byte<cur_end){a= *cur_byte++;if(cur_byte==cur_end&&a=='\n')break;if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')C_putc(a);else if(a<0200)out_char(a);else{a= (a-0200)*0400+*cur_byte++;if(a<024000){cur_val= a;out_char(identifier);}else if(a<050000){confusion("macro defs have strange char");}else{cur_val= a-050000;cur_section= cur_val;out_char(section_number);}}}protect= 0;flush_buffer();}pop_level(0);}/*:47*//*49:*/#line 651 "./ctangle.w"static voidout_char(cur_char)eight_bits cur_char;{char*j,*k;restart:switch(cur_char){case'\n':if(protect&&out_state!=verbatim)C_putc(' ');if(protect||out_state==verbatim)C_putc('\\');flush_buffer();if(out_state!=verbatim)out_state= normal;break;/*53:*/#line 719 "./ctangle.w"case identifier:if(out_state==num_or_id)C_putc(' ');j= (cur_val+name_dir)->byte_start;k= (cur_val+name_dir+1)->byte_start;while(j<k){if((unsigned char)(*j)<0200)C_putc(*j);else C_printf("%s",translit[(unsigned char)(*j)-0200]);j++;}out_state= num_or_id;break;/*:53*/#line 662 "./ctangle.w";/*54:*/#line 732 "./ctangle.w"case section_number:if(cur_val> 0)C_printf("/*%d:*/",cur_val);else if(cur_val<0)C_printf("/*:%d*/",-cur_val);else if(protect){cur_byte+= 4;cur_char= '\n';goto restart;}else{sixteen_bits a;a= 0400**cur_byte++;a+= *cur_byte++;C_printf("\n#line %d \"",a);cur_val= *cur_byte++;cur_val= 0400*(cur_val-0200)+*cur_byte++;for(j= (cur_val+name_dir)->byte_start,k= (cur_val+name_dir+1)->byte_start;j<k;j++){if(*j=='\\'||*j=='"')C_putc('\\');C_putc(*j);}C_printf("%s","\"\n");}break;/*:54*/#line 663 "./ctangle.w";/*50:*/#line 681 "./ctangle.w"case plus_plus:C_putc('+');C_putc('+');out_state= normal;break;

⌨️ 快捷键说明

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