| 1 |
/*1:*/ |
| 2 |
#line 66 "ctangle.w" |
| 3 |
|
| 4 |
/*5:*/ |
| 5 |
#line 47 "common.h" |
| 6 |
|
| 7 |
#include <ctype.h> |
| 8 |
#include <stdbool.h> |
| 9 |
#include <stddef.h> |
| 10 |
#include <stdint.h> |
| 11 |
#include <stdio.h> |
| 12 |
#include <stdlib.h> |
| 13 |
#include <string.h> |
| 14 |
|
| 15 |
/*:5*/ |
| 16 |
#line 67 "ctangle.w" |
| 17 |
|
| 18 |
#define banner "This is CTANGLE (Version 4.12.2)" |
| 19 |
#define ctangle false |
| 20 |
#define cweave true |
| 21 |
#define and_and 04 |
| 22 |
#define lt_lt 020 |
| 23 |
#define gt_gt 021 |
| 24 |
#define plus_plus 013 |
| 25 |
#define minus_minus 01 |
| 26 |
#define minus_gt 031 |
| 27 |
#define non_eq 032 |
| 28 |
#define lt_eq 034 |
| 29 |
#define gt_eq 035 |
| 30 |
#define eq_eq 036 |
| 31 |
#define or_or 037 |
| 32 |
#define dot_dot_dot 016 |
| 33 |
#define colon_colon 06 |
| 34 |
#define period_ast 026 |
| 35 |
#define minus_gt_ast 027 |
| 36 |
#define compress(c) if(loc++<=limit)return c |
| 37 |
#define xisalpha(c) (isalpha((int)(c))&&!ishigh(c)) |
| 38 |
#define xisdigit(c) (isdigit((int)(c))&&!ishigh(c)) |
| 39 |
#define xisspace(c) (isspace((int)(c))&&!ishigh(c)) |
| 40 |
#define xislower(c) (islower((int)(c))&&!ishigh(c)) |
| 41 |
#define xisupper(c) (isupper((int)(c))&&!ishigh(c)) |
| 42 |
#define xisxdigit(c) (isxdigit((int)(c))&&!ishigh(c)) |
| 43 |
#define isxalpha(c) ((c)=='_'||(c)=='$') |
| 44 |
#define ishigh(c) ((eight_bits)(c)> 0177) |
| 45 |
#define max_include_depth 10 |
| 46 |
#define max_file_name_length 60 |
| 47 |
#define cur_file file[include_depth] |
| 48 |
#define cur_file_name file_name[include_depth] |
| 49 |
#define cur_line line[include_depth] |
| 50 |
#define web_file file[0] |
| 51 |
#define web_file_name file_name[0] |
| 52 |
#define length(c) (size_t)((c+1)->byte_start-(c)->byte_start) |
| 53 |
#define print_id(c) term_write((c)->byte_start,length(c)) |
| 54 |
#define llink link |
| 55 |
#define rlink dummy.Rlink |
| 56 |
#define root name_dir->rlink |
| 57 |
#define ilk dummy.Ilk |
| 58 |
#define spotless 0 |
| 59 |
#define harmless_message 1 |
| 60 |
#define error_message 2 |
| 61 |
#define fatal_message 3 |
| 62 |
#define mark_harmless() if(history==spotless)history= harmless_message |
| 63 |
#define mark_error() history= error_message |
| 64 |
#define confusion(s) fatal("! This can't happen: ",s) |
| 65 |
#define show_banner flags['b'] |
| 66 |
#define show_progress flags['p'] |
| 67 |
#define show_happiness flags['h'] |
| 68 |
#define show_stats flags['s'] |
| 69 |
#define make_xrefs flags['x'] |
| 70 |
#define update_terminal() fflush(stdout) |
| 71 |
#define new_line() putchar('\n') |
| 72 |
#define term_write(a,b) fflush(stdout),fwrite(a,sizeof(char),b,stdout) |
| 73 |
#define buf_size 200 |
| 74 |
#define longest_name 10000 |
| 75 |
#define long_buf_size (buf_size+longest_name) |
| 76 |
#define max_bytes 100000 |
| 77 |
#define max_names 5000 |
| 78 |
#define max_sections 2000 |
| 79 |
#define max_texts 4000 |
| 80 |
#define max_toks 270000 |
| 81 |
#define equiv equiv_or_xref |
| 82 |
#define macro 0 |
| 83 |
#define section_flag max_texts |
| 84 |
#define string 02 |
| 85 |
#define constant 03 |
| 86 |
#define join 0177 |
| 87 |
#define output_defs_flag (2*024000-1) |
| 88 |
#define stack_size 50 |
| 89 |
#define cur_state stack[stack_size+1] |
| 90 |
#define cur_byte cur_state.byte_field |
| 91 |
#define cur_name cur_state.name_field |
| 92 |
#define cur_repl cur_state.repl_field |
| 93 |
#define cur_section cur_state.section_field |
| 94 |
#define cur_end (cur_repl+1) ->tok_start |
| 95 |
#define section_number 0201 |
| 96 |
#define identifier 0202 |
| 97 |
#define normal 0 |
| 98 |
#define num_or_id 1 |
| 99 |
#define post_slash 2 |
| 100 |
#define unbreakable 3 |
| 101 |
#define verbatim 4 |
| 102 |
#define max_files 256 |
| 103 |
#define C_printf(c,a) fprintf(C_file,c,a) |
| 104 |
#define C_putc(c) fputc((int)(c),C_file) |
| 105 |
#define translit_length 10 |
| 106 |
#define ignore 00 |
| 107 |
#define ord 0302 |
| 108 |
#define control_text 0303 |
| 109 |
#define translit_code 0304 |
| 110 |
#define output_defs_code 0305 |
| 111 |
#define format_code 0306 |
| 112 |
#define definition 0307 |
| 113 |
#define begin_C 0310 |
| 114 |
#define section_name 0311 |
| 115 |
#define new_section 0312 |
| 116 |
#define app_repl(c) { \ |
| 117 |
if(tok_ptr==tok_mem_end)overflow("token"); \ |
| 118 |
else*(tok_ptr++)= (eight_bits)c; \ |
| 119 |
} |
| 120 |
#define store_id(a) a= id_lookup(id_first,id_loc,'\0')-name_dir; \ |
| 121 |
app_repl((a/0400)+0200); \ |
| 122 |
app_repl(a%0400) |
| 123 |
#define keep_digit_separators flags['k'] |
| 124 |
|
| 125 |
#line 68 "ctangle.w" |
| 126 |
|
| 127 |
/*3:*/ |
| 128 |
#line 35 "common.h" |
| 129 |
|
| 130 |
typedef uint8_t eight_bits; |
| 131 |
typedef uint16_t sixteen_bits; |
| 132 |
extern bool program; |
| 133 |
extern int phase; |
| 134 |
|
| 135 |
/*:3*//*6:*/ |
| 136 |
#line 92 "common.h" |
| 137 |
|
| 138 |
extern char section_text[]; |
| 139 |
extern char*section_text_end; |
| 140 |
extern char*id_first; |
| 141 |
extern char*id_loc; |
| 142 |
|
| 143 |
/*:6*//*7:*/ |
| 144 |
#line 110 "common.h" |
| 145 |
|
| 146 |
extern char buffer[]; |
| 147 |
extern char*buffer_end; |
| 148 |
extern char*loc; |
| 149 |
extern char*limit; |
| 150 |
|
| 151 |
/*:7*//*8:*/ |
| 152 |
#line 127 "common.h" |
| 153 |
|
| 154 |
extern int include_depth; |
| 155 |
extern FILE*file[]; |
| 156 |
extern FILE*change_file; |
| 157 |
extern char file_name[][max_file_name_length]; |
| 158 |
|
| 159 |
extern char change_file_name[]; |
| 160 |
extern int line[]; |
| 161 |
extern int change_line; |
| 162 |
extern int change_depth; |
| 163 |
extern bool input_has_ended; |
| 164 |
extern bool changing; |
| 165 |
extern bool web_file_open; |
| 166 |
|
| 167 |
/*:8*//*10:*/ |
| 168 |
#line 147 "common.h" |
| 169 |
|
| 170 |
extern sixteen_bits section_count; |
| 171 |
extern bool changed_section[]; |
| 172 |
extern bool change_pending; |
| 173 |
extern bool print_where; |
| 174 |
|
| 175 |
/*:10*//*11:*/ |
| 176 |
#line 162 "common.h" |
| 177 |
|
| 178 |
typedef struct name_info{ |
| 179 |
char*byte_start; |
| 180 |
struct name_info*link; |
| 181 |
union{ |
| 182 |
struct name_info*Rlink; |
| 183 |
|
| 184 |
eight_bits Ilk; |
| 185 |
}dummy; |
| 186 |
void*equiv_or_xref; |
| 187 |
}name_info; |
| 188 |
typedef name_info*name_pointer; |
| 189 |
typedef name_pointer*hash_pointer; |
| 190 |
extern char byte_mem[]; |
| 191 |
extern char*byte_mem_end; |
| 192 |
extern char*byte_ptr; |
| 193 |
extern name_info name_dir[]; |
| 194 |
extern name_pointer name_dir_end; |
| 195 |
extern name_pointer name_ptr; |
| 196 |
extern name_pointer hash[]; |
| 197 |
extern hash_pointer hash_end; |
| 198 |
extern hash_pointer hash_ptr; |
| 199 |
|
| 200 |
/*:11*//*13:*/ |
| 201 |
#line 207 "common.h" |
| 202 |
|
| 203 |
extern int history; |
| 204 |
|
| 205 |
/*:13*//*15:*/ |
| 206 |
#line 225 "common.h" |
| 207 |
|
| 208 |
extern int argc; |
| 209 |
extern char**argv; |
| 210 |
extern char C_file_name[]; |
| 211 |
extern char tex_file_name[]; |
| 212 |
extern char idx_file_name[]; |
| 213 |
extern char scn_file_name[]; |
| 214 |
extern bool flags[]; |
| 215 |
|
| 216 |
/*:15*//*16:*/ |
| 217 |
#line 239 "common.h" |
| 218 |
|
| 219 |
extern FILE*C_file; |
| 220 |
extern FILE*tex_file; |
| 221 |
extern FILE*idx_file; |
| 222 |
extern FILE*scn_file; |
| 223 |
extern FILE*active_file; |
| 224 |
|
| 225 |
/*:16*/ |
| 226 |
#line 69 "ctangle.w" |
| 227 |
|
| 228 |
/*19:*/ |
| 229 |
#line 122 "ctangle.w" |
| 230 |
|
| 231 |
typedef struct{ |
| 232 |
eight_bits*tok_start; |
| 233 |
sixteen_bits text_link; |
| 234 |
}text; |
| 235 |
typedef text*text_pointer; |
| 236 |
|
| 237 |
/*:19*//*31:*/ |
| 238 |
#line 267 "ctangle.w" |
| 239 |
|
| 240 |
typedef struct{ |
| 241 |
eight_bits*byte_field; |
| 242 |
name_pointer name_field; |
| 243 |
text_pointer repl_field; |
| 244 |
sixteen_bits section_field; |
| 245 |
}output_state; |
| 246 |
typedef output_state*stack_pointer; |
| 247 |
|
| 248 |
/*:31*/ |
| 249 |
#line 70 "ctangle.w" |
| 250 |
|
| 251 |
/*20:*/ |
| 252 |
#line 131 "ctangle.w" |
| 253 |
|
| 254 |
static text text_info[max_texts]; |
| 255 |
static text_pointer text_info_end= text_info+max_texts-1; |
| 256 |
static text_pointer text_ptr; |
| 257 |
static eight_bits tok_mem[max_toks]; |
| 258 |
static eight_bits*tok_mem_end= tok_mem+max_toks-1; |
| 259 |
static eight_bits*tok_ptr; |
| 260 |
|
| 261 |
/*:20*//*26:*/ |
| 262 |
#line 196 "ctangle.w" |
| 263 |
|
| 264 |
static text_pointer last_unnamed; |
| 265 |
|
| 266 |
/*:26*//*32:*/ |
| 267 |
#line 285 "ctangle.w" |
| 268 |
|
| 269 |
static output_state stack[stack_size+2]; |
| 270 |
static stack_pointer stack_end= stack+stack_size; |
| 271 |
static stack_pointer stack_ptr; |
| 272 |
|
| 273 |
/*:32*//*38:*/ |
| 274 |
#line 367 "ctangle.w" |
| 275 |
|
| 276 |
static int cur_val; |
| 277 |
|
| 278 |
/*:38*//*42:*/ |
| 279 |
#line 457 "ctangle.w" |
| 280 |
|
| 281 |
static eight_bits out_state; |
| 282 |
static bool protect; |
| 283 |
|
| 284 |
/*:42*//*45:*/ |
| 285 |
#line 488 "ctangle.w" |
| 286 |
|
| 287 |
static name_pointer output_files[max_files]; |
| 288 |
static name_pointer*cur_out_file,*end_output_files,*an_output_file; |
| 289 |
static char cur_section_name_char; |
| 290 |
static char output_file_name[longest_name+1]; |
| 291 |
|
| 292 |
/*:45*//*53:*/ |
| 293 |
#line 584 "ctangle.w" |
| 294 |
|
| 295 |
static bool output_defs_seen= false; |
| 296 |
|
| 297 |
/*:53*//*57:*/ |
| 298 |
#line 694 "ctangle.w" |
| 299 |
|
| 300 |
static char translit[0200][translit_length]; |
| 301 |
|
| 302 |
/*:57*//*62:*/ |
| 303 |
#line 770 "ctangle.w" |
| 304 |
|
| 305 |
static eight_bits ccode[256]= {ignore}; |
| 306 |
|
| 307 |
/*:62*//*66:*/ |
| 308 |
#line 827 "ctangle.w" |
| 309 |
|
| 310 |
static bool comment_continues= false; |
| 311 |
|
| 312 |
/*:66*//*68:*/ |
| 313 |
#line 864 "ctangle.w" |
| 314 |
|
| 315 |
static name_pointer cur_section_name; |
| 316 |
static bool no_where; |
| 317 |
|
| 318 |
/*:68*//*82:*/ |
| 319 |
#line 1182 "ctangle.w" |
| 320 |
|
| 321 |
static text_pointer cur_text; |
| 322 |
static eight_bits next_control; |
| 323 |
|
| 324 |
/*:82*/ |
| 325 |
#line 71 "ctangle.w" |
| 326 |
|
| 327 |
/*4:*/ |
| 328 |
#line 42 "common.h" |
| 329 |
|
| 330 |
extern void common_init(void); |
| 331 |
|
| 332 |
/*:4*//*9:*/ |
| 333 |
#line 141 "common.h" |
| 334 |
|
| 335 |
extern bool get_line(void); |
| 336 |
extern void check_complete(void); |
| 337 |
extern void reset_input(void); |
| 338 |
|
| 339 |
/*:9*//*12:*/ |
| 340 |
#line 185 "common.h" |
| 341 |
|
| 342 |
extern name_pointer id_lookup(const char*,const char*,eight_bits); |
| 343 |
|
| 344 |
extern name_pointer section_lookup(char*,char*,bool); |
| 345 |
extern void print_prefix_name(name_pointer); |
| 346 |
extern void print_section_name(name_pointer); |
| 347 |
extern void sprint_section_name(char*,name_pointer); |
| 348 |
|
| 349 |
extern bool names_match(name_pointer,const char*,size_t,eight_bits); |
| 350 |
|
| 351 |
extern void init_node(name_pointer); |
| 352 |
|
| 353 |
/*:12*//*14:*/ |
| 354 |
#line 210 "common.h" |
| 355 |
|
| 356 |
extern int wrap_up(void); |
| 357 |
extern void err_print(const char*); |
| 358 |
extern void fatal(const char*,const char*); |
| 359 |
extern void overflow(const char*); |
| 360 |
|
| 361 |
extern void print_stats(void); |
| 362 |
|
| 363 |
/*:14*//*30:*/ |
| 364 |
#line 242 "ctangle.w" |
| 365 |
static void store_two_bytes(sixteen_bits); |
| 366 |
|
| 367 |
/*:30*//*37:*/ |
| 368 |
#line 347 "ctangle.w" |
| 369 |
|
| 370 |
static void push_level(name_pointer); |
| 371 |
static void pop_level(bool); |
| 372 |
static void get_output(void); |
| 373 |
|
| 374 |
/*:37*//*44:*/ |
| 375 |
#line 478 "ctangle.w" |
| 376 |
static void flush_buffer(void); |
| 377 |
|
| 378 |
/*:44*//*49:*/ |
| 379 |
#line 547 "ctangle.w" |
| 380 |
|
| 381 |
static void phase_two(void); |
| 382 |
static void output_defs(void); |
| 383 |
static void out_char(eight_bits); |
| 384 |
|
| 385 |
/*:49*//*65:*/ |
| 386 |
#line 807 "ctangle.w" |
| 387 |
|
| 388 |
static eight_bits skip_ahead(void); |
| 389 |
static bool skip_comment(bool); |
| 390 |
|
| 391 |
/*:65*//*70:*/ |
| 392 |
#line 915 "ctangle.w" |
| 393 |
static eight_bits get_next(void); |
| 394 |
|
| 395 |
/*:70*//*84:*/ |
| 396 |
#line 1208 "ctangle.w" |
| 397 |
static void scan_repl(eight_bits); |
| 398 |
|
| 399 |
/*:84*//*91:*/ |
| 400 |
#line 1399 "ctangle.w" |
| 401 |
static void scan_section(void); |
| 402 |
|
| 403 |
/*:91*//*99:*/ |
| 404 |
#line 1476 "ctangle.w" |
| 405 |
static void phase_one(void); |
| 406 |
|
| 407 |
/*:99*//*101:*/ |
| 408 |
#line 1509 "ctangle.w" |
| 409 |
static void skip_limbo(void); |
| 410 |
|
| 411 |
/*:101*/ |
| 412 |
#line 72 "ctangle.w" |
| 413 |
|
| 414 |
|
| 415 |
/*:1*//*2:*/ |
| 416 |
#line 81 "ctangle.w" |
| 417 |
|
| 418 |
int main( |
| 419 |
int ac, |
| 420 |
char**av) |
| 421 |
{ |
| 422 |
argc= ac;argv= av; |
| 423 |
program= ctangle; |
| 424 |
/*21:*/ |
| 425 |
#line 139 "ctangle.w" |
| 426 |
|
| 427 |
text_info->tok_start= tok_ptr= tok_mem; |
| 428 |
text_ptr= text_info+1;text_ptr->tok_start= tok_mem; |
| 429 |
|
| 430 |
|
| 431 |
/*:21*//*23:*/ |
| 432 |
#line 149 "ctangle.w" |
| 433 |
|
| 434 |
init_node(name_dir); |
| 435 |
|
| 436 |
/*:23*//*27:*/ |
| 437 |
#line 199 "ctangle.w" |
| 438 |
last_unnamed= text_info;text_info->text_link= macro; |
| 439 |
|
| 440 |
/*:27*//*46:*/ |
| 441 |
#line 498 "ctangle.w" |
| 442 |
|
| 443 |
cur_out_file= end_output_files= output_files+max_files; |
| 444 |
|
| 445 |
/*:46*//*58:*/ |
| 446 |
#line 697 "ctangle.w" |
| 447 |
|
| 448 |
{int i; |
| 449 |
for(i= 0;i<0200;i++) |
| 450 |
snprintf(translit[i],translit_length,"X%02X",(unsigned int)(0200+i)); |
| 451 |
} |
| 452 |
|
| 453 |
/*:58*//*63:*/ |
| 454 |
#line 773 "ctangle.w" |
| 455 |
|
| 456 |
ccode[' ']= ccode['\t']= ccode['\n']= ccode['\v']= ccode['\r']= ccode['\f'] |
| 457 |
= ccode['*']= new_section; |
| 458 |
ccode['@']= (eight_bits)'@';ccode['=']= string; |
| 459 |
ccode['d']= ccode['D']= definition; |
| 460 |
ccode['f']= ccode['F']= ccode['s']= ccode['S']= format_code; |
| 461 |
ccode['c']= ccode['C']= ccode['p']= ccode['P']= begin_C; |
| 462 |
ccode['^']= ccode[':']= ccode['.']= ccode['t']= ccode['T']= |
| 463 |
ccode['q']= ccode['Q']= control_text; |
| 464 |
ccode['h']= ccode['H']= output_defs_code; |
| 465 |
ccode['l']= ccode['L']= translit_code; |
| 466 |
ccode['&']= join; |
| 467 |
ccode['<']= ccode['(']= section_name; |
| 468 |
ccode['\'']= ord; |
| 469 |
|
| 470 |
/*:63*//*78:*/ |
| 471 |
#line 1103 "ctangle.w" |
| 472 |
section_text[0]= ' '; |
| 473 |
|
| 474 |
/*:78*/ |
| 475 |
#line 88 "ctangle.w" |
| 476 |
|
| 477 |
common_init(); |
| 478 |
if(show_banner)puts(banner); |
| 479 |
phase_one(); |
| 480 |
phase_two(); |
| 481 |
return wrap_up(); |
| 482 |
} |
| 483 |
|
| 484 |
/*:2*//*24:*/ |
| 485 |
#line 155 "ctangle.w" |
| 486 |
|
| 487 |
bool names_match( |
| 488 |
name_pointer p, |
| 489 |
const char*first, |
| 490 |
size_t l, |
| 491 |
eight_bits t) |
| 492 |
{(void)t; |
| 493 |
return length(p)==l&&strncmp(first,p->byte_start,l)==0; |
| 494 |
} |
| 495 |
|
| 496 |
/*:24*//*25:*/ |
| 497 |
#line 168 "ctangle.w" |
| 498 |
|
| 499 |
void |
| 500 |
init_node( |
| 501 |
name_pointer node) |
| 502 |
{ |
| 503 |
node->equiv= (void*)text_info; |
| 504 |
} |
| 505 |
|
| 506 |
/*:25*//*29:*/ |
| 507 |
#line 232 "ctangle.w" |
| 508 |
|
| 509 |
static void |
| 510 |
store_two_bytes( |
| 511 |
sixteen_bits x) |
| 512 |
{ |
| 513 |
if(tok_ptr+2> tok_mem_end)overflow("token"); |
| 514 |
*tok_ptr++= x>>8; |
| 515 |
*tok_ptr++= x&0377; |
| 516 |
} |
| 517 |
|
| 518 |
/*:29*//*35:*/ |
| 519 |
#line 315 "ctangle.w" |
| 520 |
|
| 521 |
static void |
| 522 |
push_level( |
| 523 |
name_pointer p) |
| 524 |
{ |
| 525 |
if(stack_ptr==stack_end)overflow("stack"); |
| 526 |
*stack_ptr= cur_state; |
| 527 |
stack_ptr++; |
| 528 |
if(p!=NULL){ |
| 529 |
cur_name= p;cur_repl= (text_pointer)p->equiv; |
| 530 |
cur_byte= cur_repl->tok_start;cur_section= 0; |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
/*:35*//*36:*/ |
| 536 |
#line 334 "ctangle.w" |
| 537 |
|
| 538 |
static void |
| 539 |
pop_level( |
| 540 |
bool flag) |
| 541 |
{ |
| 542 |
if(flag&&cur_repl->text_link<section_flag){ |
| 543 |
cur_repl= cur_repl->text_link+text_info; |
| 544 |
cur_byte= cur_repl->tok_start;return; |
| 545 |
} |
| 546 |
stack_ptr--; |
| 547 |
if(stack_ptr> stack)cur_state= *stack_ptr; |
| 548 |
} |
| 549 |
|
| 550 |
/*:36*//*39:*/ |
| 551 |
#line 374 "ctangle.w" |
| 552 |
|
| 553 |
static void |
| 554 |
get_output(void) |
| 555 |
{ |
| 556 |
sixteen_bits a; |
| 557 |
restart:if(stack_ptr==stack)return; |
| 558 |
if(cur_byte==cur_end){ |
| 559 |
cur_val= -((int)cur_section); |
| 560 |
pop_level(true); |
| 561 |
if(cur_val==0)goto restart; |
| 562 |
out_char(section_number);return; |
| 563 |
} |
| 564 |
a= *cur_byte++; |
| 565 |
if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n') |
| 566 |
C_putc(a); |
| 567 |
else if(a<0200)out_char(a); |
| 568 |
else{ |
| 569 |
a= (a-0200)*0400+*cur_byte++; |
| 570 |
switch(a/024000){ |
| 571 |
case 0:cur_val= (int)a;out_char(identifier);break; |
| 572 |
case 1:if(a==output_defs_flag)output_defs(); |
| 573 |
else/*40:*/ |
| 574 |
#line 407 "ctangle.w" |
| 575 |
|
| 576 |
{ |
| 577 |
a-= 024000; |
| 578 |
if((a+name_dir)->equiv!=(void*)text_info)push_level(a+name_dir); |
| 579 |
else if(a!=0){ |
| 580 |
printf("%s","\n! Not present: <"); |
| 581 |
print_section_name(a+name_dir);err_print(">"); |
| 582 |
|
| 583 |
} |
| 584 |
goto restart; |
| 585 |
} |
| 586 |
|
| 587 |
/*:40*/ |
| 588 |
#line 395 "ctangle.w" |
| 589 |
|
| 590 |
break; |
| 591 |
default:cur_val= (int)a-050000; |
| 592 |
if(cur_val> 0)cur_section= (sixteen_bits)cur_val; |
| 593 |
out_char(section_number); |
| 594 |
} |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
/*:39*//*43:*/ |
| 599 |
#line 465 "ctangle.w" |
| 600 |
|
| 601 |
static void |
| 602 |
flush_buffer(void) |
| 603 |
{ |
| 604 |
C_putc('\n'); |
| 605 |
if(cur_line%100==0&&show_progress){ |
| 606 |
putchar('.'); |
| 607 |
if(cur_line%500==0)printf("%d",cur_line); |
| 608 |
update_terminal(); |
| 609 |
} |
| 610 |
cur_line++; |
| 611 |
} |
| 612 |
|
| 613 |
/*:43*//*48:*/ |
| 614 |
#line 517 "ctangle.w" |
| 615 |
|
| 616 |
static void |
| 617 |
phase_two(void){ |
| 618 |
phase= 2; |
| 619 |
web_file_open= false; |
| 620 |
cur_line= 1; |
| 621 |
/*33:*/ |
| 622 |
#line 296 "ctangle.w" |
| 623 |
|
| 624 |
stack_ptr= stack+1;cur_name= name_dir; |
| 625 |
cur_repl= text_info->text_link+text_info; |
| 626 |
cur_byte= cur_repl->tok_start;cur_section= 0; |
| 627 |
|
| 628 |
/*:33*/ |
| 629 |
#line 523 "ctangle.w" |
| 630 |
|
| 631 |
/*52:*/ |
| 632 |
#line 580 "ctangle.w" |
| 633 |
|
| 634 |
if(!output_defs_seen) |
| 635 |
output_defs(); |
| 636 |
|
| 637 |
/*:52*/ |
| 638 |
#line 524 "ctangle.w" |
| 639 |
|
| 640 |
if(text_info->text_link==macro&&cur_out_file==end_output_files){ |
| 641 |
printf("%s","\n! No program text was specified.");mark_harmless(); |
| 642 |
|
| 643 |
} |
| 644 |
else{ |
| 645 |
if(show_progress){ |
| 646 |
printf(cur_out_file==end_output_files? |
| 647 |
"\nWriting the output file (%s):": |
| 648 |
"\nWriting the output files: (%s)",C_file_name); |
| 649 |
|
| 650 |
update_terminal(); |
| 651 |
} |
| 652 |
if(text_info->text_link!=macro) |
| 653 |
/*51:*/ |
| 654 |
#line 570 "ctangle.w" |
| 655 |
|
| 656 |
{ |
| 657 |
while(stack_ptr> stack)get_output(); |
| 658 |
flush_buffer(); |
| 659 |
} |
| 660 |
|
| 661 |
/*:51*/ |
| 662 |
#line 538 "ctangle.w" |
| 663 |
|
| 664 |
/*50:*/ |
| 665 |
#line 556 "ctangle.w" |
| 666 |
|
| 667 |
for(an_output_file= end_output_files;an_output_file> cur_out_file;){ |
| 668 |
an_output_file--; |
| 669 |
sprint_section_name(output_file_name,*an_output_file); |
| 670 |
fclose(C_file); |
| 671 |
if((C_file= fopen(output_file_name,"wb"))==NULL) |
| 672 |
fatal("! Cannot open output file ",output_file_name); |
| 673 |
|
| 674 |
if(show_progress){printf("\n(%s)",output_file_name);update_terminal();} |
| 675 |
cur_line= 1; |
| 676 |
/*34:*/ |
| 677 |
#line 303 "ctangle.w" |
| 678 |
|
| 679 |
stack_ptr= stack+1;cur_name= *an_output_file; |
| 680 |
cur_repl= (text_pointer)cur_name->equiv; |
| 681 |
cur_byte= cur_repl->tok_start; |
| 682 |
|
| 683 |
/*:34*/ |
| 684 |
#line 566 "ctangle.w" |
| 685 |
|
| 686 |
/*51:*/ |
| 687 |
#line 570 "ctangle.w" |
| 688 |
|
| 689 |
{ |
| 690 |
while(stack_ptr> stack)get_output(); |
| 691 |
flush_buffer(); |
| 692 |
} |
| 693 |
|
| 694 |
/*:51*/ |
| 695 |
#line 567 "ctangle.w" |
| 696 |
|
| 697 |
} |
| 698 |
|
| 699 |
/*:50*/ |
| 700 |
#line 539 "ctangle.w" |
| 701 |
|
| 702 |
if(show_happiness){ |
| 703 |
if(show_progress)new_line(); |
| 704 |
printf("%s","Done."); |
| 705 |
} |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
/*:48*//*54:*/ |
| 710 |
#line 590 "ctangle.w" |
| 711 |
|
| 712 |
static void |
| 713 |
output_defs(void) |
| 714 |
{ |
| 715 |
sixteen_bits a;eight_bits*macro_end; |
| 716 |
push_level(NULL); |
| 717 |
for(cur_text= text_info+1;cur_text<text_ptr;cur_text++) |
| 718 |
if(cur_text->text_link==macro){ |
| 719 |
cur_byte= cur_text->tok_start; |
| 720 |
macro_end= (cur_text+1)->tok_start; |
| 721 |
C_printf("%s","#define "); |
| 722 |
out_state= normal; |
| 723 |
protect= true; |
| 724 |
do macro_end--;while(isspace(*macro_end)&&plus_plus!=*macro_end); |
| 725 |
|
| 726 |
while(cur_byte<=macro_end){ |
| 727 |
a= *cur_byte++; |
| 728 |
if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n') |
| 729 |
C_putc(a); |
| 730 |
|
| 731 |
else if(a<0200)out_char(a); |
| 732 |
else{ |
| 733 |
a= (a-0200)*0400+*cur_byte++; |
| 734 |
if(a<024000){ |
| 735 |
cur_val= (int)a;out_char(identifier); |
| 736 |
} |
| 737 |
else if(a<050000)confusion("macro defs have strange char"); |
| 738 |
else{ |
| 739 |
cur_val= (int)a-050000;cur_section= (sixteen_bits)cur_val; |
| 740 |
out_char(section_number); |
| 741 |
} |
| 742 |
|
| 743 |
} |
| 744 |
} |
| 745 |
protect= false; |
| 746 |
flush_buffer(); |
| 747 |
} |
| 748 |
pop_level(false); |
| 749 |
} |
| 750 |
|
| 751 |
/*:54*//*55:*/ |
| 752 |
#line 635 "ctangle.w" |
| 753 |
|
| 754 |
static void |
| 755 |
out_char( |
| 756 |
eight_bits cur_char) |
| 757 |
{ |
| 758 |
char*j; |
| 759 |
restart: |
| 760 |
switch(cur_char){ |
| 761 |
case'\n':if(protect&&out_state!=verbatim)C_putc(' '); |
| 762 |
if(protect||out_state==verbatim)C_putc('\\'); |
| 763 |
flush_buffer();if(out_state!=verbatim)out_state= normal;break; |
| 764 |
/*59:*/ |
| 765 |
#line 703 "ctangle.w" |
| 766 |
|
| 767 |
case identifier: |
| 768 |
if(out_state==num_or_id)C_putc(' '); |
| 769 |
for(j= (cur_val+name_dir)->byte_start; |
| 770 |
j<(cur_val+name_dir+1)->byte_start;j++) |
| 771 |
if(ishigh(*j))C_printf("%s",translit[(eight_bits)(*j)-0200]); |
| 772 |
|
| 773 |
else C_putc(*j); |
| 774 |
out_state= num_or_id;break; |
| 775 |
|
| 776 |
/*:59*/ |
| 777 |
#line 646 "ctangle.w" |
| 778 |
|
| 779 |
/*60:*/ |
| 780 |
#line 713 "ctangle.w" |
| 781 |
|
| 782 |
case section_number: |
| 783 |
if(cur_val> 0)C_printf("/*%d:*/",cur_val); |
| 784 |
else if(cur_val<0)C_printf("/*:%d*/",-cur_val); |
| 785 |
else if(protect){ |
| 786 |
cur_byte+= 4; |
| 787 |
cur_char= (eight_bits)'\n'; |
| 788 |
goto restart; |
| 789 |
}else{ |
| 790 |
sixteen_bits a; |
| 791 |
a= *cur_byte++*0400; |
| 792 |
a+= *cur_byte++; |
| 793 |
C_printf("\n#line %d \"",(int)a); |
| 794 |
|
| 795 |
cur_val= (int)(*cur_byte++-0200)*0400; |
| 796 |
cur_val+= *cur_byte++; |
| 797 |
for(j= (cur_val+name_dir)->byte_start; |
| 798 |
j<(cur_val+name_dir+1)->byte_start;j++){ |
| 799 |
if(*j=='\\'||*j=='"')C_putc('\\'); |
| 800 |
C_putc(*j); |
| 801 |
} |
| 802 |
C_putc('"');C_putc('\n'); |
| 803 |
} |
| 804 |
break; |
| 805 |
|
| 806 |
/*:60*/ |
| 807 |
#line 647 "ctangle.w" |
| 808 |
|
| 809 |
/*56:*/ |
| 810 |
#line 665 "ctangle.w" |
| 811 |
|
| 812 |
case plus_plus:C_putc('+');C_putc('+');out_state= normal;break; |
| 813 |
case minus_minus:C_putc('-');C_putc('-');out_state= normal;break; |
| 814 |
case minus_gt:C_putc('-');C_putc('>');out_state= normal;break; |
| 815 |
case gt_gt:C_putc('>');C_putc('>');out_state= normal;break; |
| 816 |
case eq_eq:C_putc('=');C_putc('=');out_state= normal;break; |
| 817 |
case lt_lt:C_putc('<');C_putc('<');out_state= normal;break; |
| 818 |
case gt_eq:C_putc('>');C_putc('=');out_state= normal;break; |
| 819 |
case lt_eq:C_putc('<');C_putc('=');out_state= normal;break; |
| 820 |
case non_eq:C_putc('!');C_putc('=');out_state= normal;break; |
| 821 |
case and_and:C_putc('&');C_putc('&');out_state= normal;break; |
| 822 |
case or_or:C_putc('|');C_putc('|');out_state= normal;break; |
| 823 |
case dot_dot_dot:C_putc('.');C_putc('.');C_putc('.');out_state= normal; |
| 824 |
break; |
| 825 |
case colon_colon:C_putc(':');C_putc(':');out_state= normal;break; |
| 826 |
case period_ast:C_putc('.');C_putc('*');out_state= normal;break; |
| 827 |
case minus_gt_ast:C_putc('-');C_putc('>');C_putc('*');out_state= normal; |
| 828 |
break; |
| 829 |
|
| 830 |
/*:56*/ |
| 831 |
#line 648 "ctangle.w" |
| 832 |
|
| 833 |
case'=':case'>':C_putc(cur_char);C_putc(' '); |
| 834 |
out_state= normal;break; |
| 835 |
case join:out_state= unbreakable;break; |
| 836 |
case constant:if(out_state==verbatim){ |
| 837 |
out_state= num_or_id;break; |
| 838 |
} |
| 839 |
if(out_state==num_or_id)C_putc(' ');out_state= verbatim;break; |
| 840 |
case string:if(out_state==verbatim)out_state= normal; |
| 841 |
else out_state= verbatim;break; |
| 842 |
case'/':C_putc('/');out_state= post_slash;break; |
| 843 |
case'*':if(out_state==post_slash)C_putc(' '); |
| 844 |
/* fall through */ |
| 845 |
default:C_putc(cur_char);out_state= normal;break; |
| 846 |
} |
| 847 |
} |
| 848 |
|
| 849 |
/*:55*//*64:*/ |
| 850 |
#line 791 "ctangle.w" |
| 851 |
|
| 852 |
static eight_bits |
| 853 |
skip_ahead(void) |
| 854 |
{ |
| 855 |
eight_bits c; |
| 856 |
while(true){ |
| 857 |
if(loc> limit&&(get_line()==false))return new_section; |
| 858 |
*(limit+1)= '@'; |
| 859 |
while(*loc!='@')loc++; |
| 860 |
if(loc<=limit){ |
| 861 |
loc++;c= ccode[(eight_bits)*loc];loc++; |
| 862 |
if(c!=ignore||*(loc-1)=='>')return c; |
| 863 |
} |
| 864 |
} |
| 865 |
} |
| 866 |
|
| 867 |
/*:64*//*67:*/ |
| 868 |
#line 830 "ctangle.w" |
| 869 |
|
| 870 |
static bool skip_comment( |
| 871 |
bool is_long_comment) |
| 872 |
{ |
| 873 |
char c; |
| 874 |
while(true){ |
| 875 |
if(loc> limit){ |
| 876 |
if(is_long_comment){ |
| 877 |
if(get_line())return comment_continues= true; |
| 878 |
else{ |
| 879 |
err_print("! Input ended in mid-comment"); |
| 880 |
|
| 881 |
return comment_continues= false; |
| 882 |
} |
| 883 |
} |
| 884 |
else return comment_continues= false; |
| 885 |
} |
| 886 |
c= *(loc++); |
| 887 |
if(is_long_comment&&c=='*'&&*loc=='/'){ |
| 888 |
loc++;return comment_continues= false; |
| 889 |
} |
| 890 |
if(c=='@'){ |
| 891 |
if(ccode[(eight_bits)*loc]==new_section){ |
| 892 |
err_print("! Section name ended in mid-comment");loc--; |
| 893 |
|
| 894 |
return comment_continues= false; |
| 895 |
} |
| 896 |
else loc++; |
| 897 |
} |
| 898 |
} |
| 899 |
} |
| 900 |
|
| 901 |
/*:67*//*69:*/ |
| 902 |
#line 871 "ctangle.w" |
| 903 |
|
| 904 |
static eight_bits |
| 905 |
get_next(void) |
| 906 |
{ |
| 907 |
static bool preprocessing= false; |
| 908 |
eight_bits c; |
| 909 |
while(true){ |
| 910 |
if(loc> limit){ |
| 911 |
if(preprocessing&&*(limit-1)!='\\')preprocessing= false; |
| 912 |
if(get_line()==false)return new_section; |
| 913 |
else if(print_where&&!no_where){ |
| 914 |
sixteen_bits a; |
| 915 |
print_where= false; |
| 916 |
/*85:*/ |
| 917 |
#line 1218 "ctangle.w" |
| 918 |
|
| 919 |
{ |
| 920 |
store_two_bytes(0150000); |
| 921 |
if(changing&&include_depth==change_depth){ |
| 922 |
id_first= change_file_name; |
| 923 |
store_two_bytes((sixteen_bits)change_line); |
| 924 |
}else{ |
| 925 |
id_first= cur_file_name; |
| 926 |
store_two_bytes((sixteen_bits)cur_line); |
| 927 |
} |
| 928 |
id_loc= id_first+strlen(id_first); |
| 929 |
store_id(a); |
| 930 |
} |
| 931 |
|
| 932 |
/*:85*/ |
| 933 |
#line 884 "ctangle.w" |
| 934 |
|
| 935 |
} |
| 936 |
else return(eight_bits)'\n'; |
| 937 |
} |
| 938 |
c= (eight_bits)*loc; |
| 939 |
if(comment_continues||(c=='/'&&(*(loc+1)=='*'||*(loc+1)=='/'))){ |
| 940 |
if(skip_comment(comment_continues||*(loc+1)=='*'))return'\n'; |
| 941 |
|
| 942 |
else continue; |
| 943 |
} |
| 944 |
loc++; |
| 945 |
if(xisdigit(c)||c=='.')/*73:*/ |
| 946 |
#line 956 "ctangle.w" |
| 947 |
{ |
| 948 |
bool hex_flag= false; |
| 949 |
id_first= loc-1; |
| 950 |
if(*id_first=='.'&&!xisdigit(*loc))goto mistake; |
| 951 |
if(*id_first=='0'){ |
| 952 |
if(*loc=='x'||*loc=='X'){ |
| 953 |
hex_flag= true; |
| 954 |
loc++;while(xisxdigit(*loc)||*loc=='\'')loc++; |
| 955 |
} |
| 956 |
else if(*loc=='b'||*loc=='B'){ |
| 957 |
loc++;while(*loc=='0'||*loc=='1'||*loc=='\'')loc++;goto found; |
| 958 |
} |
| 959 |
} |
| 960 |
while(xisdigit(*loc)||*loc=='\'')loc++; |
| 961 |
if(*loc=='.'){ |
| 962 |
loc++; |
| 963 |
while((hex_flag&&xisxdigit(*loc))||xisdigit(*loc)||*loc=='\'')loc++; |
| 964 |
} |
| 965 |
if(*loc=='e'||*loc=='E'){ |
| 966 |
if(*++loc=='+'||*loc=='-')loc++; |
| 967 |
while(xisdigit(*loc)||*loc=='\'')loc++; |
| 968 |
} |
| 969 |
else if(hex_flag&&(*loc=='p'||*loc=='P')){ |
| 970 |
if(*++loc=='+'||*loc=='-')loc++; |
| 971 |
while(xisxdigit(*loc)||*loc=='\'')loc++; |
| 972 |
} |
| 973 |
found:while(*loc=='u'||*loc=='U'||*loc=='l'||*loc=='L' |
| 974 |
||*loc=='f'||*loc=='F')loc++; |
| 975 |
id_loc= loc; |
| 976 |
return constant; |
| 977 |
} |
| 978 |
|
| 979 |
/*:73*/ |
| 980 |
#line 895 "ctangle.w" |
| 981 |
|
| 982 |
else if(c=='\''||c=='"' |
| 983 |
||((c=='L'||c=='u'||c=='U')&&(*loc=='\''||*loc=='"')) |
| 984 |
||((c=='u'&&*loc=='8')&&(*(loc+1)=='\''||*(loc+1)=='"'))) |
| 985 |
/*74:*/ |
| 986 |
#line 993 "ctangle.w" |
| 987 |
{ |
| 988 |
char delim= (char)c; |
| 989 |
id_first= section_text+1; |
| 990 |
id_loc= section_text;*++id_loc= delim; |
| 991 |
if(delim=='L'||delim=='u'||delim=='U'){ |
| 992 |
if(delim=='u'&&*loc=='8')*++id_loc= *loc++; |
| 993 |
delim= *loc++;*++id_loc= delim; |
| 994 |
} |
| 995 |
while(true){ |
| 996 |
if(loc>=limit){ |
| 997 |
if(*(limit-1)!='\\'){ |
| 998 |
err_print("! String didn't end");loc= limit;break; |
| 999 |
|
| 1000 |
} |
| 1001 |
if(get_line()==false){ |
| 1002 |
err_print("! Input ended in middle of string");loc= buffer;break; |
| 1003 |
|
| 1004 |
} |
| 1005 |
else if(++id_loc<=section_text_end)*id_loc= '\n'; |
| 1006 |
|
| 1007 |
} |
| 1008 |
if((c= (eight_bits)*loc++)==delim){ |
| 1009 |
if(++id_loc<=section_text_end)*id_loc= (char)c; |
| 1010 |
break; |
| 1011 |
} |
| 1012 |
if(c=='\\'){ |
| 1013 |
if(loc>=limit)continue; |
| 1014 |
if(++id_loc<=section_text_end)*id_loc= '\\'; |
| 1015 |
c= (eight_bits)*loc++; |
| 1016 |
} |
| 1017 |
if(++id_loc<=section_text_end)*id_loc= (char)c; |
| 1018 |
} |
| 1019 |
if(id_loc>=section_text_end){ |
| 1020 |
printf("%s","\n! String too long: "); |
| 1021 |
|
| 1022 |
term_write(section_text+1,25); |
| 1023 |
err_print("..."); |
| 1024 |
} |
| 1025 |
id_loc++; |
| 1026 |
return string; |
| 1027 |
} |
| 1028 |
|
| 1029 |
/*:74*/ |
| 1030 |
#line 899 "ctangle.w" |
| 1031 |
|
| 1032 |
else if(isalpha((int)c)||isxalpha(c)||ishigh(c)) |
| 1033 |
/*72:*/ |
| 1034 |
#line 947 "ctangle.w" |
| 1035 |
{ |
| 1036 |
id_first= --loc; |
| 1037 |
do |
| 1038 |
++loc; |
| 1039 |
while(isalpha((int)*loc)||isdigit((int)*loc) |
| 1040 |
||isxalpha(*loc)||ishigh(*loc)); |
| 1041 |
id_loc= loc;return identifier; |
| 1042 |
} |
| 1043 |
|
| 1044 |
/*:72*/ |
| 1045 |
#line 901 "ctangle.w" |
| 1046 |
|
| 1047 |
else if(c=='@')/*75:*/ |
| 1048 |
#line 1038 "ctangle.w" |
| 1049 |
|
| 1050 |
switch(c= ccode[(eight_bits)*loc++]){ |
| 1051 |
case ignore:continue; |
| 1052 |
case translit_code:err_print("! Use @l in limbo only");continue; |
| 1053 |
|
| 1054 |
case control_text:while((c= skip_ahead())=='@'); |
| 1055 |
|
| 1056 |
if(*(loc-1)!='>') |
| 1057 |
err_print("! Double @ should be used in control text"); |
| 1058 |
|
| 1059 |
continue; |
| 1060 |
case section_name: |
| 1061 |
cur_section_name_char= *(loc-1); |
| 1062 |
/*77:*/ |
| 1063 |
#line 1083 "ctangle.w" |
| 1064 |
{ |
| 1065 |
char*k= section_text; |
| 1066 |
/*79:*/ |
| 1067 |
#line 1105 "ctangle.w" |
| 1068 |
|
| 1069 |
while(true){ |
| 1070 |
if(loc> limit&&get_line()==false){ |
| 1071 |
err_print("! Input ended in section name"); |
| 1072 |
|
| 1073 |
loc= buffer+1;break; |
| 1074 |
} |
| 1075 |
c= (eight_bits)*loc; |
| 1076 |
/*80:*/ |
| 1077 |
#line 1128 "ctangle.w" |
| 1078 |
|
| 1079 |
if(c=='@'){ |
| 1080 |
c= (eight_bits)*(loc+1); |
| 1081 |
if(c=='>'){ |
| 1082 |
loc+= 2;break; |
| 1083 |
} |
| 1084 |
if(ccode[(eight_bits)c]==new_section){ |
| 1085 |
err_print("! Section name didn't end");break; |
| 1086 |
|
| 1087 |
} |
| 1088 |
if(ccode[(eight_bits)c]==section_name){ |
| 1089 |
err_print("! Nesting of section names not allowed");break; |
| 1090 |
|
| 1091 |
} |
| 1092 |
*(++k)= '@';loc++; |
| 1093 |
} |
| 1094 |
|
| 1095 |
/*:80*/ |
| 1096 |
#line 1113 "ctangle.w" |
| 1097 |
|
| 1098 |
loc++;if(k<section_text_end)k++; |
| 1099 |
if(xisspace(c)){ |
| 1100 |
c= (eight_bits)' ';if(*(k-1)==' ')k--; |
| 1101 |
} |
| 1102 |
*k= (char)c; |
| 1103 |
} |
| 1104 |
if(k>=section_text_end){ |
| 1105 |
printf("%s","\n! Section name too long: "); |
| 1106 |
|
| 1107 |
term_write(section_text+1,25); |
| 1108 |
printf("...");mark_harmless(); |
| 1109 |
} |
| 1110 |
if(*k==' '&&k> section_text)k--; |
| 1111 |
|
| 1112 |
/*:79*/ |
| 1113 |
#line 1085 "ctangle.w" |
| 1114 |
|
| 1115 |
if(k-section_text> 3&&strncmp(k-2,"...",3)==0) |
| 1116 |
cur_section_name= section_lookup(section_text+1,k-3,true); |
| 1117 |
|
| 1118 |
else cur_section_name= section_lookup(section_text+1,k,false); |
| 1119 |
|
| 1120 |
if(cur_section_name_char=='(') |
| 1121 |
/*47:*/ |
| 1122 |
#line 502 "ctangle.w" |
| 1123 |
|
| 1124 |
{ |
| 1125 |
for(an_output_file= cur_out_file; |
| 1126 |
an_output_file<end_output_files;an_output_file++) |
| 1127 |
if(*an_output_file==cur_section_name)break; |
| 1128 |
if(an_output_file==end_output_files){ |
| 1129 |
if(cur_out_file> output_files) |
| 1130 |
*--cur_out_file= cur_section_name; |
| 1131 |
else overflow("output files"); |
| 1132 |
} |
| 1133 |
} |
| 1134 |
|
| 1135 |
/*:47*/ |
| 1136 |
#line 1093 "ctangle.w" |
| 1137 |
|
| 1138 |
return section_name; |
| 1139 |
} |
| 1140 |
|
| 1141 |
/*:77*/ |
| 1142 |
#line 1051 "ctangle.w" |
| 1143 |
|
| 1144 |
case string:/*81:*/ |
| 1145 |
#line 1150 "ctangle.w" |
| 1146 |
|
| 1147 |
id_first= loc++;*(limit+1)= '@';*(limit+2)= '>'; |
| 1148 |
while(*loc!='@'||*(loc+1)!='>')loc++; |
| 1149 |
if(loc>=limit)err_print("! Verbatim string didn't end"); |
| 1150 |
|
| 1151 |
id_loc= loc;loc+= 2; |
| 1152 |
return string; |
| 1153 |
|
| 1154 |
/*:81*/ |
| 1155 |
#line 1052 "ctangle.w" |
| 1156 |
|
| 1157 |
case ord:/*76:*/ |
| 1158 |
#line 1063 "ctangle.w" |
| 1159 |
|
| 1160 |
id_first= loc; |
| 1161 |
if(*loc=='\\') |
| 1162 |
if(*++loc=='\'')loc++; |
| 1163 |
while(*loc!='\''){ |
| 1164 |
if(*loc=='@'){ |
| 1165 |
if(*(loc+1)!='@') |
| 1166 |
err_print("! Double @ should be used in ASCII constant"); |
| 1167 |
|
| 1168 |
else loc++; |
| 1169 |
} |
| 1170 |
loc++; |
| 1171 |
if(loc> limit){ |
| 1172 |
err_print("! String didn't end");loc= limit-1;break; |
| 1173 |
|
| 1174 |
} |
| 1175 |
} |
| 1176 |
loc++; |
| 1177 |
return ord; |
| 1178 |
|
| 1179 |
/*:76*/ |
| 1180 |
#line 1053 "ctangle.w" |
| 1181 |
|
| 1182 |
default:return c; |
| 1183 |
} |
| 1184 |
|
| 1185 |
/*:75*/ |
| 1186 |
#line 902 "ctangle.w" |
| 1187 |
|
| 1188 |
else if(xisspace(c)){ |
| 1189 |
if(!preprocessing||loc> limit)continue; |
| 1190 |
|
| 1191 |
else return(eight_bits)' '; |
| 1192 |
|
| 1193 |
} |
| 1194 |
else if(c=='#'&&loc==buffer+1)preprocessing= true; |
| 1195 |
mistake:/*71:*/ |
| 1196 |
#line 924 "ctangle.w" |
| 1197 |
|
| 1198 |
switch(c){ |
| 1199 |
case'+':if(*loc=='+')compress(plus_plus);break; |
| 1200 |
case'-':if(*loc=='-'){compress(minus_minus);} |
| 1201 |
else if(*loc=='>'){ |
| 1202 |
if(*(loc+1)=='*'){loc++;compress(minus_gt_ast);} |
| 1203 |
else compress(minus_gt); |
| 1204 |
}break; |
| 1205 |
case'.':if(*loc=='*'){compress(period_ast);} |
| 1206 |
else if(*loc=='.'&&*(loc+1)=='.'){ |
| 1207 |
loc++;compress(dot_dot_dot); |
| 1208 |
}break; |
| 1209 |
case':':if(*loc==':')compress(colon_colon);break; |
| 1210 |
case'=':if(*loc=='=')compress(eq_eq);break; |
| 1211 |
case'>':if(*loc=='='){compress(gt_eq);} |
| 1212 |
else if(*loc=='>')compress(gt_gt);break; |
| 1213 |
case'<':if(*loc=='='){compress(lt_eq);} |
| 1214 |
else if(*loc=='<')compress(lt_lt);break; |
| 1215 |
case'&':if(*loc=='&')compress(and_and);break; |
| 1216 |
case'|':if(*loc=='|')compress(or_or);break; |
| 1217 |
case'!':if(*loc=='=')compress(non_eq);break; |
| 1218 |
} |
| 1219 |
|
| 1220 |
/*:71*/ |
| 1221 |
#line 910 "ctangle.w" |
| 1222 |
|
| 1223 |
return c; |
| 1224 |
} |
| 1225 |
} |
| 1226 |
|
| 1227 |
/*:69*//*83:*/ |
| 1228 |
#line 1186 "ctangle.w" |
| 1229 |
|
| 1230 |
static void |
| 1231 |
scan_repl( |
| 1232 |
eight_bits t) |
| 1233 |
{bool first_bracket= true; |
| 1234 |
sixteen_bits a; |
| 1235 |
if(t==section_name)/*85:*/ |
| 1236 |
#line 1218 "ctangle.w" |
| 1237 |
|
| 1238 |
{ |
| 1239 |
store_two_bytes(0150000); |
| 1240 |
if(changing&&include_depth==change_depth){ |
| 1241 |
id_first= change_file_name; |
| 1242 |
store_two_bytes((sixteen_bits)change_line); |
| 1243 |
}else{ |
| 1244 |
id_first= cur_file_name; |
| 1245 |
store_two_bytes((sixteen_bits)cur_line); |
| 1246 |
} |
| 1247 |
id_loc= id_first+strlen(id_first); |
| 1248 |
store_id(a); |
| 1249 |
} |
| 1250 |
|
| 1251 |
/*:85*/ |
| 1252 |
#line 1192 "ctangle.w" |
| 1253 |
|
| 1254 |
while(true)switch(a= get_next()){ |
| 1255 |
/*86:*/ |
| 1256 |
#line 1232 "ctangle.w" |
| 1257 |
|
| 1258 |
case identifier:store_id(a); |
| 1259 |
if(*buffer=='#'&&( |
| 1260 |
(id_loc-id_first==5&&strncmp("endif",id_first,5)==0)|| |
| 1261 |
(id_loc-id_first==4&&strncmp("else",id_first,4)==0)|| |
| 1262 |
(id_loc-id_first==4&&strncmp("elif",id_first,4)==0))) |
| 1263 |
|
| 1264 |
print_where= true; |
| 1265 |
break; |
| 1266 |
case section_name:if(t!=section_name)goto done; |
| 1267 |
else{ |
| 1268 |
/*87:*/ |
| 1269 |
#line 1273 "ctangle.w" |
| 1270 |
{ |
| 1271 |
char*try_loc= loc; |
| 1272 |
while(*try_loc==' '&&try_loc<limit)try_loc++; |
| 1273 |
if(*try_loc=='+'&&try_loc<limit)try_loc++; |
| 1274 |
while(*try_loc==' '&&try_loc<limit)try_loc++; |
| 1275 |
if(*try_loc=='=')err_print("! Missing `@ ' before a named section"); |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
} |
| 1280 |
|
| 1281 |
/*:87*/ |
| 1282 |
#line 1243 "ctangle.w" |
| 1283 |
|
| 1284 |
a= cur_section_name-name_dir; |
| 1285 |
app_repl((a/0400)+0250); |
| 1286 |
app_repl(a%0400); |
| 1287 |
/*85:*/ |
| 1288 |
#line 1218 "ctangle.w" |
| 1289 |
|
| 1290 |
{ |
| 1291 |
store_two_bytes(0150000); |
| 1292 |
if(changing&&include_depth==change_depth){ |
| 1293 |
id_first= change_file_name; |
| 1294 |
store_two_bytes((sixteen_bits)change_line); |
| 1295 |
}else{ |
| 1296 |
id_first= cur_file_name; |
| 1297 |
store_two_bytes((sixteen_bits)cur_line); |
| 1298 |
} |
| 1299 |
id_loc= id_first+strlen(id_first); |
| 1300 |
store_id(a); |
| 1301 |
} |
| 1302 |
|
| 1303 |
/*:85*/ |
| 1304 |
#line 1247 "ctangle.w" |
| 1305 |
|
| 1306 |
} |
| 1307 |
break; |
| 1308 |
case output_defs_code:if(t!=section_name)err_print("! Misplaced @h"); |
| 1309 |
|
| 1310 |
else{ |
| 1311 |
output_defs_seen= true; |
| 1312 |
a= output_defs_flag; |
| 1313 |
app_repl((a/0400)+0200); |
| 1314 |
app_repl(a%0400); |
| 1315 |
/*85:*/ |
| 1316 |
#line 1218 "ctangle.w" |
| 1317 |
|
| 1318 |
{ |
| 1319 |
store_two_bytes(0150000); |
| 1320 |
if(changing&&include_depth==change_depth){ |
| 1321 |
id_first= change_file_name; |
| 1322 |
store_two_bytes((sixteen_bits)change_line); |
| 1323 |
}else{ |
| 1324 |
id_first= cur_file_name; |
| 1325 |
store_two_bytes((sixteen_bits)cur_line); |
| 1326 |
} |
| 1327 |
id_loc= id_first+strlen(id_first); |
| 1328 |
store_id(a); |
| 1329 |
} |
| 1330 |
|
| 1331 |
/*:85*/ |
| 1332 |
#line 1257 "ctangle.w" |
| 1333 |
|
| 1334 |
} |
| 1335 |
break; |
| 1336 |
case constant:case string: |
| 1337 |
/*88:*/ |
| 1338 |
#line 1290 "ctangle.w" |
| 1339 |
|
| 1340 |
app_repl(a); |
| 1341 |
while(id_first<id_loc){ |
| 1342 |
if(*id_first=='@'){ |
| 1343 |
if(*(id_first+1)=='@')id_first++; |
| 1344 |
else err_print("! Double @ should be used in string"); |
| 1345 |
|
| 1346 |
} |
| 1347 |
else if(a==constant&&*id_first=='\''&&!keep_digit_separators) |
| 1348 |
id_first++; |
| 1349 |
app_repl(*id_first++); |
| 1350 |
} |
| 1351 |
app_repl(a); |
| 1352 |
|
| 1353 |
/*:88*/ |
| 1354 |
#line 1261 "ctangle.w" |
| 1355 |
|
| 1356 |
break; |
| 1357 |
case ord: |
| 1358 |
/*89:*/ |
| 1359 |
#line 1308 "ctangle.w" |
| 1360 |
{ |
| 1361 |
int c= (int)((eight_bits)*id_first); |
| 1362 |
if(c=='\\'){ |
| 1363 |
c= (int)((eight_bits)*++id_first); |
| 1364 |
if(c>='0'&&c<='7'){ |
| 1365 |
c-= '0'; |
| 1366 |
if(*(id_first+1)>='0'&&*(id_first+1)<='7'){ |
| 1367 |
c= 8*c+*(++id_first)-'0'; |
| 1368 |
if(*(id_first+1)>='0'&&*(id_first+1)<='7'&&c<32) |
| 1369 |
c= 8*c+*(++id_first)-'0'; |
| 1370 |
} |
| 1371 |
} |
| 1372 |
else switch(c){ |
| 1373 |
case't':c= '\t';break; |
| 1374 |
case'n':c= '\n';break; |
| 1375 |
case'b':c= '\b';break; |
| 1376 |
case'f':c= '\f';break; |
| 1377 |
case'v':c= '\v';break; |
| 1378 |
case'r':c= '\r';break; |
| 1379 |
case'a':c= '\7';break; |
| 1380 |
case'?':c= '?';break; |
| 1381 |
case'x': |
| 1382 |
if(xisdigit(*(id_first+1)))c= (int)(*(++id_first)-'0'); |
| 1383 |
else if(xisxdigit(*(id_first+1))){ |
| 1384 |
++id_first; |
| 1385 |
c= toupper((int)*id_first)-'A'+10; |
| 1386 |
} |
| 1387 |
if(xisdigit(*(id_first+1)))c= 16*c+(int)(*(++id_first)-'0'); |
| 1388 |
else if(xisxdigit(*(id_first+1))){ |
| 1389 |
++id_first; |
| 1390 |
c= 16*c+toupper((int)*id_first)-(int)'A'+10; |
| 1391 |
} |
| 1392 |
break; |
| 1393 |
case'\\':c= '\\';break; |
| 1394 |
case'\'':c= '\'';break; |
| 1395 |
case'\"':c= '\"';break; |
| 1396 |
default:err_print("! Unrecognized escape sequence"); |
| 1397 |
|
| 1398 |
} |
| 1399 |
} |
| 1400 |
|
| 1401 |
app_repl(constant); |
| 1402 |
if(c>=100)app_repl((int)'0'+c/100); |
| 1403 |
if(c>=10)app_repl((int)'0'+(c/10)%10); |
| 1404 |
app_repl((int)'0'+c%10); |
| 1405 |
app_repl(constant); |
| 1406 |
} |
| 1407 |
|
| 1408 |
/*:89*/ |
| 1409 |
#line 1264 "ctangle.w" |
| 1410 |
|
| 1411 |
break; |
| 1412 |
case definition:case format_code:case begin_C:if(t!=section_name)goto done; |
| 1413 |
else{ |
| 1414 |
err_print("! @d, @f and @c are ignored in C text");continue; |
| 1415 |
|
| 1416 |
} |
| 1417 |
case new_section:goto done; |
| 1418 |
|
| 1419 |
/*:86*/ |
| 1420 |
#line 1197 "ctangle.w" |
| 1421 |
|
| 1422 |
case')':app_repl(a); |
| 1423 |
if(t==macro&&first_bracket){app_repl(' ');first_bracket= false;} |
| 1424 |
break; |
| 1425 |
default:app_repl(a); |
| 1426 |
} |
| 1427 |
done:next_control= (eight_bits)a; |
| 1428 |
if(text_ptr> text_info_end)overflow("text"); |
| 1429 |
cur_text= text_ptr;(++text_ptr)->tok_start= tok_ptr; |
| 1430 |
} |
| 1431 |
|
| 1432 |
/*:83*//*90:*/ |
| 1433 |
#line 1366 "ctangle.w" |
| 1434 |
|
| 1435 |
static void |
| 1436 |
scan_section(void) |
| 1437 |
{ |
| 1438 |
name_pointer p; |
| 1439 |
text_pointer q; |
| 1440 |
sixteen_bits a; |
| 1441 |
section_count++;no_where= true; |
| 1442 |
if(*(loc-1)=='*'&&show_progress){ |
| 1443 |
printf("*%d",(int)section_count);update_terminal(); |
| 1444 |
} |
| 1445 |
next_control= ignore; |
| 1446 |
while(true){ |
| 1447 |
/*92:*/ |
| 1448 |
#line 1407 "ctangle.w" |
| 1449 |
|
| 1450 |
while(next_control<definition) |
| 1451 |
|
| 1452 |
if((next_control= skip_ahead())==section_name){ |
| 1453 |
loc-= 2;next_control= get_next(); |
| 1454 |
} |
| 1455 |
|
| 1456 |
/*:92*/ |
| 1457 |
#line 1380 "ctangle.w" |
| 1458 |
|
| 1459 |
if(next_control==definition){ |
| 1460 |
/*93:*/ |
| 1461 |
#line 1414 "ctangle.w" |
| 1462 |
|
| 1463 |
while((next_control= get_next())=='\n'); |
| 1464 |
if(next_control!=identifier){ |
| 1465 |
err_print("! Definition flushed, must start with identifier"); |
| 1466 |
|
| 1467 |
continue; |
| 1468 |
} |
| 1469 |
store_id(a); |
| 1470 |
if(*loc!='('){ |
| 1471 |
app_repl(string);app_repl(' ');app_repl(string); |
| 1472 |
} |
| 1473 |
scan_repl(macro); |
| 1474 |
cur_text->text_link= macro; |
| 1475 |
|
| 1476 |
/*:93*/ |
| 1477 |
#line 1382 "ctangle.w" |
| 1478 |
|
| 1479 |
continue; |
| 1480 |
} |
| 1481 |
if(next_control==begin_C){ |
| 1482 |
p= name_dir;break; |
| 1483 |
} |
| 1484 |
if(next_control==section_name){ |
| 1485 |
p= cur_section_name; |
| 1486 |
/*94:*/ |
| 1487 |
#line 1436 "ctangle.w" |
| 1488 |
|
| 1489 |
while((next_control= get_next())=='+'); |
| 1490 |
if(next_control!='='&&next_control!=eq_eq) |
| 1491 |
continue; |
| 1492 |
|
| 1493 |
/*:94*/ |
| 1494 |
#line 1390 "ctangle.w" |
| 1495 |
|
| 1496 |
break; |
| 1497 |
} |
| 1498 |
return; |
| 1499 |
} |
| 1500 |
no_where= print_where= false; |
| 1501 |
/*95:*/ |
| 1502 |
#line 1441 "ctangle.w" |
| 1503 |
|
| 1504 |
/*96:*/ |
| 1505 |
#line 1446 "ctangle.w" |
| 1506 |
|
| 1507 |
store_two_bytes((sixteen_bits)(0150000+section_count)); |
| 1508 |
|
| 1509 |
|
| 1510 |
/*:96*/ |
| 1511 |
#line 1442 "ctangle.w" |
| 1512 |
|
| 1513 |
scan_repl(section_name); |
| 1514 |
/*97:*/ |
| 1515 |
#line 1450 "ctangle.w" |
| 1516 |
|
| 1517 |
if(p==name_dir||p==NULL){ |
| 1518 |
last_unnamed->text_link= cur_text-text_info;last_unnamed= cur_text; |
| 1519 |
} |
| 1520 |
else if(p->equiv==(void*)text_info)p->equiv= (void*)cur_text; |
| 1521 |
|
| 1522 |
else{ |
| 1523 |
q= (text_pointer)p->equiv; |
| 1524 |
while(q->text_link<section_flag) |
| 1525 |
q= q->text_link+text_info; |
| 1526 |
q->text_link= cur_text-text_info; |
| 1527 |
} |
| 1528 |
cur_text->text_link= section_flag; |
| 1529 |
|
| 1530 |
|
| 1531 |
/*:97*/ |
| 1532 |
#line 1444 "ctangle.w" |
| 1533 |
|
| 1534 |
|
| 1535 |
/*:95*/ |
| 1536 |
#line 1396 "ctangle.w" |
| 1537 |
|
| 1538 |
} |
| 1539 |
|
| 1540 |
/*:90*//*98:*/ |
| 1541 |
#line 1465 "ctangle.w" |
| 1542 |
|
| 1543 |
static void |
| 1544 |
phase_one(void){ |
| 1545 |
phase= 1; |
| 1546 |
section_count= 0; |
| 1547 |
reset_input(); |
| 1548 |
skip_limbo(); |
| 1549 |
while(!input_has_ended)scan_section(); |
| 1550 |
check_complete(); |
| 1551 |
} |
| 1552 |
|
| 1553 |
/*:98*//*100:*/ |
| 1554 |
#line 1481 "ctangle.w" |
| 1555 |
|
| 1556 |
static void |
| 1557 |
skip_limbo(void) |
| 1558 |
{ |
| 1559 |
while(true){ |
| 1560 |
if(loc> limit&&get_line()==false)return; |
| 1561 |
*(limit+1)= '@'; |
| 1562 |
while(*loc!='@')loc++; |
| 1563 |
if(loc++<=limit){ |
| 1564 |
char c= *loc++; |
| 1565 |
switch(ccode[(eight_bits)c]){ |
| 1566 |
case new_section:return; |
| 1567 |
case translit_code:/*102:*/ |
| 1568 |
#line 1511 "ctangle.w" |
| 1569 |
|
| 1570 |
while(xisspace(*loc)&&loc<limit)loc++; |
| 1571 |
loc+= 3; |
| 1572 |
if(loc> limit||!xisxdigit(*(loc-3))||!xisxdigit(*(loc-2)) |
| 1573 |
||(*(loc-3)>='0'&&*(loc-3)<='7')||!xisspace(*(loc-1))) |
| 1574 |
err_print("! Improper hex number following @l"); |
| 1575 |
|
| 1576 |
else{ |
| 1577 |
unsigned int i; |
| 1578 |
char*beg; |
| 1579 |
sscanf(loc-3,"%x",&i); |
| 1580 |
while(xisspace(*loc)&&loc<limit)loc++; |
| 1581 |
beg= loc; |
| 1582 |
while(loc<limit&&(xisalpha(*loc)||xisdigit(*loc)||isxalpha(*loc)))loc++; |
| 1583 |
if(loc-beg>=translit_length) |
| 1584 |
err_print("! Replacement string in @l too long"); |
| 1585 |
|
| 1586 |
else{ |
| 1587 |
strncpy(translit[i-0200],beg,(size_t)(loc-beg)); |
| 1588 |
translit[i-0200][loc-beg]= '\0'; |
| 1589 |
} |
| 1590 |
} |
| 1591 |
|
| 1592 |
/*:102*/ |
| 1593 |
#line 1493 "ctangle.w" |
| 1594 |
break; |
| 1595 |
case format_code:case'@':break; |
| 1596 |
case control_text:if(c=='q'||c=='Q'){ |
| 1597 |
while((c= (char)skip_ahead())=='@'); |
| 1598 |
if(*(loc-1)!='>') |
| 1599 |
err_print("! Double @ should be used in control text"); |
| 1600 |
|
| 1601 |
break; |
| 1602 |
}/* otherwise fall through */ |
| 1603 |
default:err_print("! Double @ should be used in limbo"); |
| 1604 |
|
| 1605 |
} |
| 1606 |
} |
| 1607 |
} |
| 1608 |
} |
| 1609 |
|
| 1610 |
/*:100*//*103:*/ |
| 1611 |
#line 1537 "ctangle.w" |
| 1612 |
|
| 1613 |
void |
| 1614 |
print_stats(void){ |
| 1615 |
puts("\nMemory usage statistics:"); |
| 1616 |
printf("%td names (out of %ld)\n", |
| 1617 |
(ptrdiff_t)(name_ptr-name_dir),(long)max_names); |
| 1618 |
printf("%td replacement texts (out of %ld)\n", |
| 1619 |
(ptrdiff_t)(text_ptr-text_info),(long)max_texts); |
| 1620 |
printf("%td bytes (out of %ld)\n", |
| 1621 |
(ptrdiff_t)(byte_ptr-byte_mem),(long)max_bytes); |
| 1622 |
printf("%td tokens (out of %ld)\n", |
| 1623 |
(ptrdiff_t)(tok_ptr-tok_mem),(long)max_toks); |
| 1624 |
} |
| 1625 |
|
| 1626 |
/*:103*/ |