Aegis  4.25.D505
/home/archives/aegis/branch.4/branch.25/delta28933.505/libaegis/sub.h
Go to the documentation of this file.
00001 //
00002 // aegis - project change supervisor
00003 // Copyright (C) 1991-1995, 1997, 1999, 2002-2008, 2011, 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #ifndef SUB_H
00020 #define SUB_H
00021 
00022 #include <common/ac/stdarg.h>
00023 #include <common/ac/time.h>
00024 #include <common/str.h>
00025 #include <libaegis/change.h>
00026 #include <libaegis/sub/diversion/stack.h>
00027 #include <libaegis/sub/functor/list.h>
00028 
00029 struct project; // forward
00030 struct sub_context_ty; // forward
00031 class nstring; // forward
00032 class wstring; // forward
00033 class wstring_list; // forward
00034 
00039 class sub_context_ty
00040 {
00041 public:
00045     ~sub_context_ty();
00046 
00050     sub_context_ty(const char *file = 0, int line = 0);
00051 
00057     void clear();
00058 
00074     void var_set_format(const char *name, const char *fmt, ...)
00075                                                               ATTR_PRINTF(3, 4);
00088     void var_set_vformat(const char *name, const char *fmt, va_list args)
00089                                                                 ATTR_VPRINTF(3);
00098     void var_set_string(const char *name, string_ty *value);
00099 
00108     void var_set_string(const char *name, const nstring &value);
00109 
00118     void var_set_charstar(const char *name, const char *value);
00119 
00128     void var_set_long(const char *name, long value);
00129 
00138     void var_set_time(const char *name, time_t value);
00139 
00147     void var_optional(const char *name);
00148 
00157     void var_append_if_unused(const char *name);
00158 
00168     void var_override(const char *name);
00169 
00181     void var_resubstitute(const char *name);
00182 
00195     void errno_setx(int value);
00196 
00209     string_ty *substitute(change::pointer cp, string_ty *the_command);
00210 
00220     string_ty *substitute_p(project *pp, string_ty *the_command);
00221 
00229     string_ty *subst_intl(const char *substme);
00230 
00238     void subst_intl_project(struct project *pp);
00239 
00247     void subst_intl_change(change::pointer cp);
00248 
00257     void error_intl(const char *message);
00258 
00269     void fatal_intl(const char *message) NORETURN;
00270 
00280     void verbose_intl(const char *message);
00281 
00294     void error_set(const char *message);
00295 
00307     project *project_get();
00308 
00320     change::pointer change_get();
00321 
00326     int errno_sequester_get() const;
00327 
00336     wstring subst(const wstring &msg);
00337 
00348     wstring subst_intl_wide(const char *msg);
00349 
00350 private:
00351     sub_diversion_stack diversion_stack;
00352     sub_functor_list var_list;
00353     change::pointer cp;
00354     project *pp;
00355 
00356     const char *suberr;
00357     int errno_sequester;
00358     const char *file_name;
00359     int line_number;
00360 
00365     void diversion_close();
00366 
00367     enum getc_type
00368     {
00369         getc_type_control,
00370         getc_type_data
00371     };
00372 
00381     wchar_t getc_meta(getc_type &c);
00382 
00392     void getc_meta_undo(wchar_t c);
00393 
00400     wchar_t getch(getc_type &tr);
00401 
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 *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 *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 // The inline i18n function does nothing by itself, but it serves as a
00657 // keyword for the xgettext program, when extracting internationalized
00658 // msgid keys.
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 *
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
00685 // vim: set ts=8 sw=4 et :