00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SUB_H
00021 #define SUB_H
00022
00023 #include <common/ac/stdarg.h>
00024 #include <common/ac/time.h>
00025 #include <common/str.h>
00026 #include <libaegis/change.h>
00027 #include <libaegis/sub/diversion/stack.h>
00028 #include <libaegis/sub/functor/list.h>
00029
00030 struct project_ty;
00031 struct sub_context_ty;
00032 class nstring;
00033 class wstring;
00034 class wstring_list;
00035
00040 class sub_context_ty
00041 {
00042 public:
00046 ~sub_context_ty();
00047
00051 sub_context_ty(const char *file = 0, int line = 0);
00052
00058 void clear();
00059
00075 void var_set_format(const char *name, const char *fmt, ...)
00076 ATTR_PRINTF(3, 4);
00089 void var_set_vformat(const char *name, const char *fmt, va_list args)
00090 ATTR_VPRINTF(3);
00099 void var_set_string(const char *name, string_ty *value);
00100
00109 void var_set_string(const char *name, const nstring &value);
00110
00119 void var_set_charstar(const char *name, const char *value);
00120
00129 void var_set_long(const char *name, long value);
00130
00139 void var_set_time(const char *name, time_t value);
00140
00148 void var_optional(const char *name);
00149
00158 void var_append_if_unused(const char *name);
00159
00169 void var_override(const char *name);
00170
00182 void var_resubstitute(const char *name);
00183
00196 void errno_setx(int value);
00197
00210 string_ty *substitute(change::pointer cp, string_ty *the_command);
00211
00221 string_ty *substitute_p(project_ty *pp, string_ty *the_command);
00222
00230 string_ty *subst_intl(const char *substme);
00231
00239 void subst_intl_project(struct project_ty *pp);
00240
00248 void subst_intl_change(change::pointer cp);
00249
00258 void error_intl(const char *message);
00259
00270 void fatal_intl(const char *message) NORETURN;
00271
00281 void verbose_intl(const char *message);
00282
00295 void error_set(const char *message);
00296
00308 project_ty *project_get();
00309
00321 change::pointer change_get();
00322
00327 int errno_sequester_get() const;
00328
00337 wstring subst(const wstring &msg);
00338
00349 wstring subst_intl_wide(const char *msg);
00350
00351 private:
00352 sub_diversion_stack diversion_stack;
00353 sub_functor_list var_list;
00354 change::pointer cp;
00355 project_ty *pp;
00356
00357 const char *suberr;
00358 int errno_sequester;
00359 const char *file_name;
00360 int line_number;
00361
00366 void diversion_close();
00367
00368 enum getc_type
00369 {
00370 getc_type_control,
00371 getc_type_data
00372 };
00373
00382 wchar_t getc_meta(getc_type &c);
00383
00393 void getc_meta_undo(wchar_t c);
00394
00401 wchar_t getch(getc_type &tr);
00402
00413 wchar_t dollar();
00414
00420 void execute(const wstring_list &arg);
00421
00425 sub_context_ty(const sub_context_ty &);
00426
00430 sub_context_ty &operator=(const sub_context_ty &);
00431 };
00432
00433 inline sub_context_ty *
00434 sub_context_New(const char *file, int line)
00435 {
00436 return new sub_context_ty(file, line);
00437 }
00438
00439 inline sub_context_ty *
00440 sub_context_new()
00441 {
00442 return new sub_context_ty();
00443 }
00444
00445 inline void
00446 sub_context_delete(sub_context_ty *scp)
00447 {
00448 delete scp;
00449 }
00450
00451 inline void
00452 sub_var_clear(sub_context_ty *scp)
00453 {
00454 scp->clear();
00455 }
00456
00457 inline void ATTR_PRINTF(3, 4)
00458 sub_var_set_format(sub_context_ty *scp, const char *name, const char *fmt, ...)
00459 {
00460 va_list ap;
00461 va_start(ap, fmt);
00462 scp->var_set_vformat(name, fmt, ap);
00463 va_end(ap);
00464 }
00465
00477 inline void
00478 sub_var_set_string(sub_context_ty *scp, const char *name, string_ty *value)
00479 {
00480 scp->var_set_string(name, value);
00481 }
00482
00494 inline void
00495 sub_var_set_string(sub_context_ty *scp, const char *name, const nstring &value)
00496 {
00497 scp->var_set_string(name, value);
00498 }
00499
00500 inline void
00501 sub_var_set_charstar(sub_context_ty *scp, const char *name, const char *value)
00502 {
00503 scp->var_set_charstar(name, value);
00504 }
00505
00506 inline void
00507 sub_var_set_long(sub_context_ty *scp, const char *name, long value)
00508 {
00509 scp->var_set_long(name, value);
00510 }
00511
00512 inline void
00513 sub_var_set_time(sub_context_ty *scp, const char *name, time_t value)
00514 {
00515 scp->var_set_time(name, value);
00516 }
00517
00518 inline void
00519 sub_var_optional(sub_context_ty *scp, const char *name)
00520 {
00521 scp->var_optional(name);
00522 }
00523
00524 inline void
00525 sub_var_append_if_unused(sub_context_ty *scp, const char *name)
00526 {
00527 scp->var_append_if_unused(name);
00528 }
00529
00530 inline void
00531 sub_var_override(sub_context_ty *scp, const char *name)
00532 {
00533 scp->var_override(name);
00534 }
00535
00536 inline void
00537 sub_var_resubstitute(sub_context_ty *scp, const char *name)
00538 {
00539 scp->var_resubstitute(name);
00540 }
00541
00553 inline void
00554 sub_errno_setx(sub_context_ty *scp, int value)
00555 {
00556 scp->errno_setx(value);
00557 }
00558
00559 inline string_ty *
00560 substitute(sub_context_ty *scp, change::pointer cp, string_ty *the_command)
00561 {
00562 if (!scp)
00563 {
00564 sub_context_ty inner;
00565 return inner.substitute(cp, the_command);
00566 }
00567 return scp->substitute(cp, the_command);
00568 }
00569
00570 inline string_ty *
00571 substitute_p(sub_context_ty *scp, struct project_ty *pp, string_ty *the_command)
00572 {
00573 if (!scp)
00574 {
00575 sub_context_ty inner;
00576 return inner.substitute_p(pp, the_command);
00577 }
00578 return scp->substitute_p(pp, the_command);
00579 }
00580
00581 inline string_ty *
00582 subst_intl(sub_context_ty *scp, const char *substme)
00583 {
00584 if (!scp)
00585 {
00586 sub_context_ty inner;
00587 return inner.subst_intl(substme);
00588 }
00589 return scp->subst_intl(substme);
00590 }
00591
00592 inline void
00593 subst_intl_project(sub_context_ty *scp, struct project_ty *pp)
00594 {
00595 if (!scp)
00596 {
00597 sub_context_ty inner;
00598 inner.subst_intl_project(pp);
00599 }
00600 else
00601 scp->subst_intl_project(pp);
00602 }
00603
00604 inline void
00605 subst_intl_change(sub_context_ty *scp, change::pointer cp)
00606 {
00607 if (!scp)
00608 {
00609 sub_context_ty inner;
00610 inner.subst_intl_change(cp);
00611 }
00612 else
00613 scp->subst_intl_change(cp);
00614 }
00615
00616 inline void
00617 error_intl(sub_context_ty *scp, const char *message)
00618 {
00619 if (!scp)
00620 {
00621 sub_context_ty inner;
00622 inner.error_intl(message);
00623 }
00624 else
00625 scp->error_intl(message);
00626 }
00627
00628 inline void
00629 fatal_intl(sub_context_ty *, const char *) NORETURN;
00630
00631 inline void
00632 fatal_intl(sub_context_ty *scp, const char *message)
00633 {
00634 if (!scp)
00635 {
00636 sub_context_ty inner;
00637 inner.fatal_intl(message);
00638 }
00639 else
00640 scp->fatal_intl(message);
00641 }
00642
00643 inline void
00644 verbose_intl(sub_context_ty *scp, const char *message)
00645 {
00646 if (!scp)
00647 {
00648 sub_context_ty temp;
00649 temp.verbose_intl(message);
00650 }
00651 else
00652 scp->verbose_intl(message);
00653 }
00654
00655
00656
00657
00658
00659
00660 inline const char *
00661 i18n(const char *x)
00662 {
00663 return x;
00664 }
00665
00666 inline DEPRECATED void
00667 sub_context_error_set(sub_context_ty *scp, const char *message)
00668 {
00669 scp->error_set(message);
00670 }
00671
00672 inline project_ty *
00673 sub_context_project_get(sub_context_ty *scp)
00674 {
00675 return scp->project_get();
00676 }
00677
00678 inline change::pointer
00679 sub_context_change_get(sub_context_ty *scp)
00680 {
00681 return scp->change_get();
00682 }
00683
00684 #endif // SUB_H