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