Print this page
make: use the more modern wchar routines, not widec.h
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/include/mksh/defs.h
+++ new/usr/src/cmd/make/include/mksh/defs.h
1 1 #ifndef _MKSH_DEFS_H
2 2 #define _MKSH_DEFS_H
3 3 /*
4 4 * CDDL HEADER START
5 5 *
6 6 * The contents of this file are subject to the terms of the
7 7 * Common Development and Distribution License (the "License").
8 8 * You may not use this file except in compliance with the License.
9 9 *
10 10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 11 * or http://www.opensolaris.org/os/licensing.
12 12 * See the License for the specific language governing permissions
13 13 * and limitations under the License.
14 14 *
15 15 * When distributing Covered Code, include this CDDL HEADER in each
16 16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 17 * If applicable, add the following below this CDDL HEADER, with the
18 18 * fields enclosed by brackets "[]" replaced with your own identifying
19 19 * information: Portions Copyright [yyyy] [name of copyright owner]
20 20 *
21 21 * CDDL HEADER END
22 22 */
23 23 /*
24 24 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 25 * Use is subject to license terms.
26 26 */
27 27
28 28 #include <limits.h> /* MB_LEN_MAX */
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
29 29 #include <stdio.h>
30 30 #include <stdlib.h> /* wchar_t */
31 31 #include <string.h> /* strcmp() */
32 32 #include <sys/param.h> /* MAXPATHLEN */
33 33 #include <sys/types.h> /* time_t, caddr_t */
34 34 #include <vroot/vroot.h> /* pathpt */
35 35 #include <sys/time.h> /* timestruc_t */
36 36 #include <errno.h> /* errno */
37 37
38 38 #include <wctype.h>
39 -#include <widec.h>
40 -
41 39
42 40 /*
43 41 * A type and some utilities for boolean values
44 42 */
45 43
46 44 #define false BOOLEAN_false
47 45 #define true BOOLEAN_true
48 46
49 47 typedef enum {
50 48 false = 0,
51 49 true = 1,
52 50 failed = 0,
53 51 succeeded = 1
54 52 } Boolean;
55 53 #define BOOLEAN(expr) ((expr) ? true : false)
56 54
57 55 /*
58 56 * Some random constants (in an enum so dbx knows their values)
59 57 */
60 58 enum {
61 59 update_delay = 30, /* time between rstat checks */
62 60 ar_member_name_len = 1024,
63 61 hashsize = 2048 /* size of hash table */
64 62 };
65 63
66 64
67 65 /*
68 66 * Symbols that defines all the different char constants make uses
69 67 */
70 68 enum {
71 69 ampersand_char = '&',
72 70 asterisk_char = '*',
73 71 at_char = '@',
74 72 backquote_char = '`',
75 73 backslash_char = '\\',
76 74 bar_char = '|',
77 75 braceleft_char = '{',
78 76 braceright_char = '}',
79 77 bracketleft_char = '[',
80 78 bracketright_char = ']',
81 79 colon_char = ':',
82 80 comma_char = ',',
83 81 dollar_char = '$',
84 82 doublequote_char = '"',
85 83 equal_char = '=',
86 84 exclam_char = '!',
87 85 greater_char = '>',
88 86 hat_char = '^',
89 87 hyphen_char = '-',
90 88 less_char = '<',
91 89 newline_char = '\n',
92 90 nul_char = '\0',
93 91 numbersign_char = '#',
94 92 parenleft_char = '(',
95 93 parenright_char = ')',
96 94 percent_char = '%',
97 95 period_char = '.',
98 96 plus_char = '+',
99 97 question_char = '?',
100 98 quote_char = '\'',
101 99 semicolon_char = ';',
102 100 slash_char = '/',
103 101 space_char = ' ',
104 102 tab_char = '\t',
105 103 tilde_char = '~'
106 104 };
107 105
108 106 /*
109 107 * For make i18n. Codeset independent.
110 108 * Setup character semantics by identifying all the special characters
111 109 * of make, and assigning each an entry in the char_semantics[] vector.
112 110 */
113 111 enum {
114 112 ampersand_char_entry = 0, /* 0 */
115 113 asterisk_char_entry, /* 1 */
116 114 at_char_entry, /* 2 */
117 115 backquote_char_entry, /* 3 */
118 116 backslash_char_entry, /* 4 */
119 117 bar_char_entry, /* 5 */
120 118 bracketleft_char_entry, /* 6 */
121 119 bracketright_char_entry, /* 7 */
122 120 colon_char_entry, /* 8 */
123 121 dollar_char_entry, /* 9 */
124 122 doublequote_char_entry, /* 10 */
125 123 equal_char_entry, /* 11 */
126 124 exclam_char_entry, /* 12 */
127 125 greater_char_entry, /* 13 */
128 126 hat_char_entry, /* 14 */
129 127 hyphen_char_entry, /* 15 */
130 128 less_char_entry, /* 16 */
131 129 newline_char_entry, /* 17 */
132 130 numbersign_char_entry, /* 18 */
133 131 parenleft_char_entry, /* 19 */
134 132 parenright_char_entry, /* 20 */
135 133 percent_char_entry, /* 21 */
136 134 plus_char_entry, /* 22 */
137 135 question_char_entry, /* 23 */
138 136 quote_char_entry, /* 24 */
139 137 semicolon_char_entry, /* 25 */
140 138 no_semantics_entry /* 26 */
141 139 };
142 140
143 141 /*
144 142 * CHAR_SEMANTICS_ENTRIES should be the number of entries above.
145 143 * The last entry in char_semantics[] should be blank.
146 144 */
147 145 #define CHAR_SEMANTICS_ENTRIES 27
148 146 /*
149 147 #define CHAR_SEMANTICS_STRING "&*@`\\|[]:$=!>-\n#()%+?;^<'\""
150 148 */
↓ open down ↓ |
100 lines elided |
↑ open up ↑ |
151 149
152 150 /*
153 151 * Some utility macros
154 152 */
155 153 #define ALLOC(x) ((struct _##x *)getmem(sizeof (struct _##x)))
156 154 #define ALLOC_WC(x) ((wchar_t *)getmem((x) * SIZEOFWCHAR_T))
157 155 #define FIND_LENGTH -1
158 156 #define GETNAME(a,b) getname_fn((a), (b), false)
159 157 #define IS_EQUAL(a,b) (!strcmp((a), (b)))
160 158 #define IS_EQUALN(a,b,n) (!strncmp((a), (b), (n)))
161 -#define IS_WEQUAL(a,b) (!wscmp((a), (b)))
162 -#define IS_WEQUALN(a,b,n) (!wsncmp((a), (b), (n)))
159 +#define IS_WEQUAL(a,b) (!wcscmp((a), (b)))
160 +#define IS_WEQUALN(a,b,n) (!wcsncmp((a), (b), (n)))
163 161 #define MBLEN(a) mblen((a), MB_LEN_MAX)
164 162 #define MBSTOWCS(a,b) (void) mbstowcs_with_check((a), (b), MAXPATHLEN)
165 163 #define MBTOWC(a,b) mbtowc((a), (b), MB_LEN_MAX)
166 164 #define SIZEOFWCHAR_T (sizeof (wchar_t))
167 165 #define VSIZEOF(v) (sizeof (v) / sizeof ((v)[0]))
168 166 #define WCSTOMBS(a,b) (void) wcstombs((a), (b), (MAXPATHLEN * MB_LEN_MAX))
169 167 #define WCTOMB(a,b) (void) wctomb((a), (b))
170 168 #define HASH(v, c) (v = (v)*31 + (unsigned int)(c))
171 169
172 170 extern void mbstowcs_with_check(wchar_t *pwcs, const char *s, size_t n);
173 171
174 172 /*
175 173 * Bits stored in funny vector to classify chars
176 174 */
177 175 enum {
178 176 dollar_sem = 0001,
179 177 meta_sem = 0002,
180 178 percent_sem = 0004,
181 179 wildcard_sem = 0010,
182 180 command_prefix_sem = 0020,
183 181 special_macro_sem = 0040,
184 182 colon_sem = 0100,
185 183 parenleft_sem = 0200
186 184 };
187 185
188 186 /*
189 187 * Type returned from doname class functions
190 188 */
191 189 typedef enum {
192 190 build_dont_know = 0,
193 191 build_failed,
194 192 build_ok,
195 193 build_in_progress,
196 194 build_running, /* PARALLEL & DISTRIBUTED */
197 195 build_pending, /* PARALLEL & DISTRIBUTED */
198 196 build_serial, /* PARALLEL & DISTRIBUTED */
199 197 build_subtree /* PARALLEL & DISTRIBUTED */
200 198 } Doname;
201 199
202 200 /*
203 201 * The String struct defines a string with the following layout
204 202 * "xxxxxxxxxxxxxxxCxxxxxxxxxxxxxxx________"
205 203 * ^ ^ ^ ^
206 204 * | | | |
207 205 * buffer.start text.p text.end buffer.end
208 206 * text.p points to the next char to read/write.
209 207 */
210 208 struct _String {
211 209 struct Text {
212 210 wchar_t *p; /* Read/Write pointer */
213 211 wchar_t *end; /* Read limit pointer */
214 212 } text;
215 213 struct Physical_buffer {
216 214 wchar_t *start; /* Points to start of buffer */
217 215 wchar_t *end; /* End of physical buffer */
218 216 } buffer;
219 217 Boolean free_after_use:1;
220 218 };
221 219
222 220 #define STRING_BUFFER_LENGTH 1024
223 221 #define INIT_STRING_FROM_STACK(str, buf) { \
224 222 str.buffer.start = (buf); \
225 223 str.text.p = (buf); \
226 224 str.text.end = NULL; \
227 225 str.buffer.end = (buf) \
228 226 + (sizeof (buf)/SIZEOFWCHAR_T); \
229 227 str.free_after_use = false; \
230 228 }
231 229
232 230 #define APPEND_NAME(np, dest, len) append_string((np)->string_mb, (dest), (len));
233 231
234 232 class Wstring {
235 233 public:
236 234 struct _String string;
↓ open down ↓ |
64 lines elided |
↑ open up ↑ |
237 235 wchar_t string_buf[STRING_BUFFER_LENGTH];
238 236
239 237 public:
240 238 Wstring();
241 239 Wstring(struct _Name * name);
242 240 ~Wstring();
243 241
244 242 void init(struct _Name * name);
245 243 void init(wchar_t * name, unsigned length);
246 244 unsigned length() {
247 - return wslen(string.buffer.start);
245 + return wcslen(string.buffer.start);
248 246 };
249 247 void append_to_str(struct _String * str, unsigned off, unsigned length);
250 248
251 249 wchar_t * get_string() {
252 250 return string.buffer.start;
253 251 };
254 252
255 253 wchar_t * get_string(unsigned off) {
256 254 return string.buffer.start + off;
257 255 };
258 256
259 257 Boolean equaln(wchar_t * str, unsigned length);
260 258 Boolean equal(wchar_t * str);
261 259 Boolean equal(wchar_t * str, unsigned off);
262 260 Boolean equal(wchar_t * str, unsigned off, unsigned length);
263 261
264 262 Boolean equaln(Wstring * str, unsigned length);
265 263 Boolean equal(Wstring * str);
266 264 Boolean equal(Wstring * str, unsigned off);
267 265 Boolean equal(Wstring * str, unsigned off, unsigned length);
268 266 };
269 267
270 268
271 269 /*
272 270 * Used for storing the $? list and also for the "target + target:"
273 271 * construct.
274 272 */
275 273 struct _Chain {
276 274 struct _Chain *next;
277 275 struct _Name *name;
278 276 struct _Percent *percent_member;
279 277 };
280 278
281 279 /*
282 280 * Stores one command line for a rule
283 281 */
284 282 struct _Cmd_line {
285 283 struct _Cmd_line *next;
286 284 struct _Name *command_line;
287 285 Boolean make_refd:1; /* $(MAKE) referenced? */
288 286 /*
289 287 * Remember any command line prefixes given
290 288 */
291 289 Boolean ignore_command_dependency:1; /* `?' */
292 290 Boolean assign:1; /* `=' */
293 291 Boolean ignore_error:1; /* `-' */
294 292 Boolean silent:1; /* `@' */
295 293 Boolean always_exec:1; /* `+' */
296 294 };
297 295
298 296 /*
299 297 * Linked list of targets/files
300 298 */
301 299 struct _Dependency {
302 300 struct _Dependency *next;
303 301 struct _Name *name;
304 302 Boolean automatic:1;
305 303 Boolean stale:1;
306 304 Boolean built:1;
307 305 };
308 306
309 307 /*
310 308 * The specials are markers for targets that the reader should special case
311 309 */
312 310 typedef enum {
313 311 no_special,
314 312 built_last_make_run_special,
315 313 default_special,
316 314 get_posix_special,
317 315 get_special,
318 316 ignore_special,
319 317 keep_state_file_special,
320 318 keep_state_special,
321 319 make_version_special,
322 320 no_parallel_special,
323 321 parallel_special,
324 322 posix_special,
325 323 precious_special,
326 324 sccs_get_posix_special,
327 325 sccs_get_special,
328 326 silent_special,
329 327 suffixes_special,
330 328 svr4_special,
331 329 localhost_special
332 330 } Special;
333 331
334 332 typedef enum {
335 333 no_colon,
336 334 one_colon,
337 335 two_colon,
338 336 equal_seen,
339 337 conditional_seen,
340 338 none_seen
341 339 } Separator;
342 340
343 341 /*
344 342 * Magic values for the timestamp stored with each name object
345 343 */
346 344
347 345
348 346 extern const timestruc_t file_no_time;
349 347 extern const timestruc_t file_doesnt_exist;
350 348 extern const timestruc_t file_is_dir;
351 349 extern const timestruc_t file_min_time;
352 350 extern const timestruc_t file_max_time;
353 351
354 352 /*
355 353 * Each Name has a list of properties
356 354 * The properties are used to store information that only
357 355 * a subset of the Names need
358 356 */
359 357 typedef enum {
360 358 no_prop,
361 359 conditional_prop,
362 360 line_prop,
363 361 macro_prop,
364 362 makefile_prop,
365 363 member_prop,
366 364 recursive_prop,
367 365 sccs_prop,
368 366 suffix_prop,
369 367 target_prop,
370 368 time_prop,
371 369 vpath_alias_prop,
372 370 long_member_name_prop,
373 371 macro_append_prop,
374 372 env_mem_prop
375 373 } Property_id;
376 374
377 375 typedef enum {
378 376 no_daemon = 0,
379 377 chain_daemon
380 378 } Daemon;
381 379
382 380 struct _Env_mem {
383 381 char *value;
384 382 };
385 383
386 384 struct _Macro_appendix {
387 385 struct _Name *value;
388 386 struct _Name *value_to_append;
389 387 };
390 388
391 389 struct _Macro {
392 390 /*
393 391 * For "ABC = xyz" constructs
394 392 * Name "ABC" get one macro prop
395 393 */
396 394 struct _Name *value;
397 395 Boolean exported:1;
398 396 Boolean read_only:1;
399 397 /*
400 398 * This macro is defined conditionally
401 399 */
402 400 Boolean is_conditional:1;
403 401 /*
404 402 * The list for $? is stored as a structured list that
405 403 * is translated into a string iff it is referenced.
406 404 * This is why some macro values need a daemon.
407 405 */
408 406 Daemon daemon:2;
409 407 };
410 408
411 409 struct _Macro_list {
412 410 struct _Macro_list *next;
413 411 char *macro_name;
414 412 char *value;
415 413 };
416 414
417 415 enum sccs_stat {
418 416 DONT_KNOW_SCCS = 0,
419 417 NO_SCCS,
420 418 HAS_SCCS
421 419 };
422 420
423 421 struct _Name {
424 422 struct _Property *prop; /* List of properties */
425 423 char *string_mb; /* Multi-byte name string */
426 424 struct {
427 425 unsigned int length;
428 426 } hash;
429 427 struct {
430 428 timestruc_t time; /* Modification */
431 429 int stat_errno; /* error from "stat" */
432 430 off_t size; /* Of file */
433 431 mode_t mode; /* Of file */
434 432 Boolean is_file:1;
435 433 Boolean is_dir:1;
436 434 Boolean is_sym_link:1;
437 435 Boolean is_precious:1;
438 436 enum sccs_stat has_sccs:2;
439 437 } stat;
440 438 /*
441 439 * Count instances of :: definitions for this target
442 440 */
443 441 short colon_splits;
444 442 /*
445 443 * We only clear the automatic depes once per target per report
446 444 */
447 445 short temp_file_number;
448 446 /*
449 447 * Count how many conditional macros this target has defined
450 448 */
451 449 short conditional_cnt;
452 450 /*
453 451 * A conditional macro was used when building this target
454 452 */
455 453 Boolean depends_on_conditional:1;
456 454 /*
457 455 * Pointer to list of conditional macros which were used to build
458 456 * this target
459 457 */
460 458 struct _Macro_list *conditional_macro_list;
461 459 Boolean has_member_depe:1;
462 460 Boolean is_member:1;
463 461 /*
464 462 * This target is a directory that has been read
465 463 */
466 464 Boolean has_read_dir:1;
467 465 /*
468 466 * This name is a macro that is now being expanded
469 467 */
470 468 Boolean being_expanded:1;
471 469 /*
472 470 * This name is a magic name that the reader must know about
473 471 */
474 472 Special special_reader:5;
475 473 Doname state:3;
476 474 Separator colons:3;
477 475 Boolean has_depe_list_expanded:1;
478 476 Boolean suffix_scan_done:1;
479 477 Boolean has_complained:1; /* For sccs */
480 478 /*
481 479 * This target has been built during this make run
482 480 */
483 481 Boolean ran_command:1;
484 482 Boolean with_squiggle:1; /* for .SUFFIXES */
485 483 Boolean without_squiggle:1; /* for .SUFFIXES */
486 484 Boolean has_read_suffixes:1; /* Suffix list cached*/
487 485 Boolean has_suffixes:1;
488 486 Boolean has_target_prop:1;
489 487 Boolean has_vpath_alias_prop:1;
490 488 Boolean dependency_printed:1; /* For dump_make_state() */
491 489 Boolean dollar:1; /* In namestring */
492 490 Boolean meta:1; /* In namestring */
493 491 Boolean percent:1; /* In namestring */
494 492 Boolean wildcard:1; /* In namestring */
495 493 Boolean has_parent:1;
496 494 Boolean is_target:1;
497 495 Boolean has_built:1;
498 496 Boolean colon:1; /* In namestring */
499 497 Boolean parenleft:1; /* In namestring */
500 498 Boolean has_recursive_dependency:1;
501 499 Boolean has_regular_dependency:1;
502 500 Boolean is_double_colon:1;
503 501 Boolean is_double_colon_parent:1;
504 502 Boolean has_long_member_name:1;
505 503 /*
506 504 * allowed to run in parallel
507 505 */
508 506 Boolean parallel:1;
509 507 /*
510 508 * not allowed to run in parallel
511 509 */
512 510 Boolean no_parallel:1;
513 511 /*
514 512 * used in dependency_conflict
515 513 */
516 514 Boolean checking_subtree:1;
517 515 Boolean added_pattern_conditionals:1;
518 516 /*
519 517 * rechecking target for possible rebuild
520 518 */
521 519 Boolean rechecking_target:1;
522 520 /*
523 521 * build this target in silent mode
524 522 */
525 523 Boolean silent_mode:1;
526 524 /*
527 525 * build this target in ignore error mode
528 526 */
529 527 Boolean ignore_error_mode:1;
530 528 Boolean dont_activate_cond_values:1;
531 529 /*
532 530 * allowed to run serially on local host
533 531 */
534 532 Boolean localhost:1;
535 533 };
536 534
537 535 /*
538 536 * Stores the % matched default rules
539 537 */
540 538 struct _Percent {
541 539 struct _Percent *next;
542 540 struct _Name **patterns;
543 541 struct _Name *name;
544 542 struct _Percent *dependencies;
545 543 struct _Cmd_line *command_template;
546 544 struct _Chain *target_group;
547 545 int patterns_total;
548 546 Boolean being_expanded;
549 547 };
550 548
551 549 struct Conditional {
552 550 /*
553 551 * For "foo := ABC [+]= xyz" constructs
554 552 * Name "foo" gets one conditional prop
555 553 */
556 554 struct _Name *target;
557 555 struct _Name *name;
558 556 struct _Name *value;
559 557 int sequence;
560 558 Boolean append:1;
561 559 };
562 560
563 561 struct Line {
564 562 /*
565 563 * For "target : dependencies" constructs
566 564 * Name "target" gets one line prop
567 565 */
568 566 struct _Cmd_line *command_template;
569 567 struct _Cmd_line *command_used;
570 568 struct _Dependency *dependencies;
571 569 timestruc_t dependency_time;
572 570 struct _Chain *target_group;
573 571 Boolean is_out_of_date:1;
574 572 Boolean sccs_command:1;
575 573 Boolean command_template_redefined:1;
576 574 Boolean dont_rebuild_command_used:1;
577 575 /*
578 576 * Values for the dynamic macros
579 577 */
580 578 struct _Name *target;
581 579 struct _Name *star;
582 580 struct _Name *less;
583 581 struct _Name *percent;
584 582 struct _Chain *query;
585 583 };
586 584
587 585 struct Makefile {
588 586 /*
589 587 * Names that reference makefiles gets one prop
590 588 */
591 589 wchar_t *contents;
592 590 off_t size;
593 591 };
594 592
595 593 struct Member {
596 594 /*
597 595 * For "lib(member)" and "lib((entry))" constructs
598 596 * Name "lib(member)" gets one member prop
599 597 * Name "lib((entry))" gets one member prop
600 598 * The member field is filled in when the prop is refd
601 599 */
602 600 struct _Name *library;
603 601 struct _Name *entry;
604 602 struct _Name *member;
605 603 };
606 604
607 605 struct Recursive {
608 606 /*
609 607 * For "target: .RECURSIVE dir makefiles" constructs
610 608 * Used to keep track of recursive calls to make
611 609 * Name "target" gets one recursive prop
612 610 */
613 611 struct _Name *directory;
614 612 struct _Name *target;
615 613 struct _Dependency *makefiles;
616 614 Boolean has_built;
617 615 Boolean in_depinfo;
618 616 };
619 617
620 618 struct Sccs {
621 619 /*
622 620 * Each file that has a SCCS s. file gets one prop
623 621 */
624 622 struct _Name *file;
625 623 };
626 624
627 625 struct Suffix {
628 626 /*
629 627 * Cached list of suffixes that can build this target
630 628 * suffix is built from .SUFFIXES
631 629 */
632 630 struct _Name *suffix;
633 631 struct _Cmd_line *command_template;
634 632 };
635 633
636 634 struct Target {
637 635 /*
638 636 * For "target:: dependencies" constructs
639 637 * The "::" construct is handled by converting it to
640 638 * "foo: 1@foo" + "1@foo: dependecies"
641 639 * "1@foo" gets one target prop
642 640 * This target prop cause $@ to be bound to "foo"
643 641 * not "1@foo" when the rule is evaluated
644 642 */
645 643 struct _Name *target;
646 644 };
647 645
648 646 struct STime {
649 647 /*
650 648 * Save the original time for :: targets
651 649 */
652 650 timestruc_t time;
653 651 };
654 652
655 653 struct Vpath_alias {
656 654 /*
657 655 * If a file was found using the VPATH it gets
658 656 * a vpath_alias prop
659 657 */
660 658 struct _Name *alias;
661 659 };
662 660
663 661 struct Long_member_name {
664 662 /*
665 663 * Targets with a truncated member name carries
666 664 * the full lib(member) name for the state file
667 665 */
668 666 struct _Name *member_name;
669 667 };
670 668
671 669 union Body {
672 670 struct _Macro macro;
673 671 struct Conditional conditional;
674 672 struct Line line;
675 673 struct Makefile makefile;
676 674 struct Member member;
677 675 struct Recursive recursive;
678 676 struct Sccs sccs;
679 677 struct Suffix suffix;
680 678 struct Target target;
681 679 struct STime time;
682 680 struct Vpath_alias vpath_alias;
683 681 struct Long_member_name long_member_name;
684 682 struct _Macro_appendix macro_appendix;
685 683 struct _Env_mem env_mem;
686 684 };
687 685
688 686 #define PROPERTY_HEAD_SIZE (sizeof (struct _Property)-sizeof (union Body))
689 687 struct _Property {
690 688 struct _Property *next;
691 689 Property_id type:4;
692 690 union Body body;
693 691 };
694 692
695 693 /* Structure for dynamic "ascii" arrays */
696 694 struct ASCII_Dyn_Array {
697 695 char *start;
698 696 size_t size;
699 697 };
700 698
701 699 struct _Envvar {
702 700 struct _Name *name;
703 701 struct _Name *value;
704 702 struct _Envvar *next;
705 703 char *env_string;
706 704 Boolean already_put:1;
707 705 };
708 706
709 707 /*
710 708 * Macros for the reader
711 709 */
712 710 #define GOTO_STATE(new_state) { \
713 711 SET_STATE(new_state); \
714 712 goto enter_state; \
715 713 }
716 714 #define SET_STATE(new_state) state = (new_state)
717 715
718 716 #define UNCACHE_SOURCE() if (source != NULL) { \
719 717 source->string.text.p = source_p; \
720 718 }
721 719 #define CACHE_SOURCE(comp) if (source != NULL) { \
722 720 source_p = source->string.text.p - \
723 721 (comp); \
724 722 source_end = source->string.text.end; \
725 723 }
726 724 #define GET_NEXT_BLOCK_NOCHK(source) { UNCACHE_SOURCE(); \
727 725 source = get_next_block_fn(source); \
728 726 CACHE_SOURCE(0) \
729 727 }
730 728 #define GET_NEXT_BLOCK(source) { GET_NEXT_BLOCK_NOCHK(source); \
731 729 if (source != NULL && source->error_converting) { \
732 730 GOTO_STATE(illegal_bytes_state); \
733 731 } \
734 732 }
735 733 #define GET_CHAR() ((source == NULL) || \
736 734 (source_p >= source_end) ? 0 : *source_p)
737 735
738 736 struct _Source {
739 737 struct _String string;
740 738 struct _Source *previous;
741 739 off_t bytes_left_in_file;
742 740 short fd;
743 741 Boolean already_expanded:1;
744 742 Boolean error_converting:1;
745 743 char *inp_buf;
746 744 char *inp_buf_end;
747 745 char *inp_buf_ptr;
748 746 };
749 747
750 748 typedef enum {
751 749 reading_nothing,
752 750 reading_makefile,
753 751 reading_statefile,
754 752 rereading_statefile,
755 753 reading_cpp_file
756 754 } Makefile_type;
757 755
758 756 /*
759 757 * Typedefs for all structs
760 758 */
761 759 typedef struct _Chain *Chain, Chain_rec;
762 760 typedef struct _Envvar *Envvar, Envvar_rec;
763 761 typedef struct _Macro_list *Macro_list, Macro_list_rec;
764 762 typedef struct _Name *Name, Name_rec;
765 763 typedef struct _Property *Property, Property_rec;
766 764 typedef struct _Source *Source, Source_rec;
767 765 typedef struct _String *String, String_rec;
768 766
769 767 /*
770 768 * name records hash table.
771 769 */
772 770 struct Name_set {
773 771 private:
774 772 // single node in a tree
775 773 struct entry {
776 774 entry(Name name_, entry *parent_) :
777 775 name(name_),
778 776 parent(parent_),
779 777 left(0),
780 778 right(0),
781 779 depth(1)
782 780 {}
783 781
784 782 Name name;
785 783
786 784 entry *parent;
787 785 entry *left;
788 786 entry *right;
789 787 unsigned depth;
790 788
791 789 void setup_depth() {
792 790 unsigned rdepth = (right != 0) ? right->depth : 0;
793 791 unsigned ldepth = (left != 0) ? left->depth : 0;
794 792 depth = 1 + ((ldepth > rdepth) ? ldepth : rdepth);
795 793 }
796 794 };
797 795
798 796 public:
799 797 // make iterator a friend of Name_set to have access to struct entry
800 798 struct iterator;
801 799 friend struct Name_set::iterator;
802 800
803 801 // iterator over tree nodes
804 802 struct iterator {
805 803 public:
806 804 // constructors
807 805 iterator() : node(0) {}
808 806 iterator(entry *node_) : node(node_) {}
809 807
810 808 // dereference operator
811 809 Name operator->() const { return node->name; }
812 810
813 811 // conversion operator
814 812 operator Name() { return node->name; }
815 813
816 814 // assignment operator
817 815 iterator& operator=(const iterator &o) { node = o.node; return *this; }
818 816
819 817 // equality/inequality operators
820 818 int operator==(const iterator &o) const { return (node == o.node); }
821 819 int operator!=(const iterator &o) const { return (node != o.node); }
822 820
823 821 // pre/post increment operators
824 822 iterator& operator++();
825 823 iterator operator++(int) { iterator it = *this; ++*this; return it; }
826 824
827 825 private:
828 826 // the node iterator points to
829 827 entry *node;
830 828 };
831 829
832 830 public:
833 831 // constructor
834 832 Name_set() : root(0) {}
835 833
836 834 // lookup, insert and remove operations
837 835 Name lookup(const char *key);
838 836 Name insert(const char *key, Boolean &found);
839 837 void insert(Name name);
840 838
841 839 // begin/end iterators
842 840 iterator begin() const;
843 841 iterator end() const { return iterator(); }
844 842
845 843 private:
846 844 // rebalance given node
847 845 void rebalance(entry *node);
848 846
849 847 private:
850 848 // tree root
851 849 entry *root;
852 850 };
853 851
854 852 /*
855 853 * extern declarations for all global variables.
856 854 * The actual declarations are in globals.cc
857 855 */
858 856 extern char char_semantics[];
859 857 extern wchar_t char_semantics_char[];
860 858 extern Macro_list cond_macro_list;
861 859 extern Boolean conditional_macro_used;
862 860 extern Boolean do_not_exec_rule; /* `-n' */
863 861 extern Boolean dollarget_seen;
864 862 extern Boolean dollarless_flag;
865 863 extern Name dollarless_value;
866 864 extern char **environ;
867 865 extern Envvar envvar;
868 866 extern int exit_status;
869 867 extern wchar_t *file_being_read;
870 868 /* Variable gnu_style=true if env. var. SUN_MAKE_COMPAT_MODE=GNU (RFE 4866328) */
871 869 extern Boolean gnu_style;
872 870 extern Name_set hashtab;
873 871 extern Name host_arch;
874 872 extern Name host_mach;
875 873 extern int line_number;
876 874 extern char *make_state_lockfile;
877 875 extern Boolean make_word_mentioned;
878 876 extern Makefile_type makefile_type;
879 877 extern char mbs_buffer[];
880 878 extern Name path_name;
881 879 extern Boolean posix;
882 880 extern Name query;
883 881 extern Boolean query_mentioned;
884 882 extern Name hat;
885 883 extern Boolean reading_environment;
886 884 extern Name shell_name;
887 885 extern Boolean svr4;
888 886 extern Name target_arch;
889 887 extern Name target_mach;
890 888 extern Boolean tilde_rule;
891 889 extern wchar_t wcs_buffer[];
892 890 extern Boolean working_on_targets;
893 891 extern Name virtual_root;
894 892 extern Boolean vpath_defined;
895 893 extern Name vpath_name;
896 894 extern Boolean make_state_locked;
897 895 extern Boolean out_err_same;
898 896 extern pid_t childPid;
899 897
900 898 /*
901 899 * RFE 1257407: make does not use fine granularity time info available from stat.
902 900 * High resolution time comparison.
903 901 */
904 902
905 903 inline int
906 904 operator==(const timestruc_t &t1, const timestruc_t &t2) {
907 905 return ((t1.tv_sec == t2.tv_sec) && (t1.tv_nsec == t2.tv_nsec));
908 906 }
909 907
910 908 inline int
911 909 operator!=(const timestruc_t &t1, const timestruc_t &t2) {
912 910 return ((t1.tv_sec != t2.tv_sec) || (t1.tv_nsec != t2.tv_nsec));
913 911 }
914 912
915 913 inline int
916 914 operator>(const timestruc_t &t1, const timestruc_t &t2) {
917 915 if (t1.tv_sec == t2.tv_sec) {
918 916 return (t1.tv_nsec > t2.tv_nsec);
919 917 }
920 918 return (t1.tv_sec > t2.tv_sec);
921 919 }
922 920
923 921 inline int
924 922 operator>=(const timestruc_t &t1, const timestruc_t &t2) {
925 923 if (t1.tv_sec == t2.tv_sec) {
926 924 return (t1.tv_nsec >= t2.tv_nsec);
927 925 }
928 926 return (t1.tv_sec > t2.tv_sec);
929 927 }
930 928
931 929 inline int
932 930 operator<(const timestruc_t &t1, const timestruc_t &t2) {
933 931 if (t1.tv_sec == t2.tv_sec) {
934 932 return (t1.tv_nsec < t2.tv_nsec);
935 933 }
936 934 return (t1.tv_sec < t2.tv_sec);
937 935 }
938 936
939 937 inline int
940 938 operator<=(const timestruc_t &t1, const timestruc_t &t2) {
941 939 if (t1.tv_sec == t2.tv_sec) {
942 940 return (t1.tv_nsec <= t2.tv_nsec);
943 941 }
944 942 return (t1.tv_sec < t2.tv_sec);
945 943 }
946 944
947 945 #endif
↓ open down ↓ |
690 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX