ARB
WETC_main.cxx
Go to the documentation of this file.
1 // ================================================================ //
2 // //
3 // File : WETC_main.cxx //
4 // Purpose : provide minor windowed tasks for CLI //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ================================================================ //
10 
11 #include <arbdb.h>
12 #include <awt.hxx>
13 #include <aw_window.hxx>
14 #include <aw_root.hxx>
15 #include <aw_question.hxx>
16 
18 
19 
20 int ARB_main(int argc, char *argv[]) {
21  GB_shell shell;
22  AW_root *aw_root = AWT_create_root("ntree.arb", "ARB_WETC", new NullTracker); // no macro recording here
23 
25 
26  if (argc < 3) {
27  error = "Missing arguments";
28  }
29  else {
30  const char *cmd = argv[1];
31  const char *param = argv[2];
32  const char *option = NULp;
33  const char *optparam = NULp;
34 
35  enum { UNKNOWN, FILEEDIT, NOTIFY } mode = UNKNOWN;
36 
37  if (strcmp(cmd, "-fileedit") == 0) mode = FILEEDIT;
38  else if (strcmp(cmd, "-notify") == 0) {
39  mode = NOTIFY;
40  if (argc != 3) {
41  if (argc == 5) {
42  option = argv[3];
43  optparam = argv[4];
44 
45  if (strcmp(option, "-button") != 0) {
46  error = GBS_global_string("unknown option '%s'", option);
47  }
48  }
49  else {
50  error = "invalid number of arguments";
51  }
52  }
53  }
54 
55  if (!error) {
56  if (mode == UNKNOWN) {
57  error = GBS_global_string("Unexpected parameter '%s'", cmd);
58  }
59  else {
60  switch (mode) {
61  case FILEEDIT:
62  AWT_show_file(aw_root, param);
63  break;
64 
65  case NOTIFY: {
66  aw_question(NULp, param, option ? optparam : "Ok", true, NULp);
67  break;
68  }
69 
70  case UNKNOWN:
71  arb_assert(0); // should not be reached!
72  break;
73  }
74 
75  aw_root->window_hide(NULp);
77  aw_root->main_loop();
78  }
79  }
80  }
81 
82  if (error) {
83  fprintf(stderr,
84  "arb_wetc -- ARB Window Environment To CLI -- start GUI tasks from CLI\n"
85  "\n"
86  "Syntax: arb_wetc -fileedit filename\n"
87  " edit a file before sending it to printer.\n"
88  "\n"
89  "Syntax: arb_wetc -notify message [-button buttontext]\n"
90  " display a message. Allow user to press OK button.\n"
91  "\n"
92  "Error: %s\n",
93  error);
94  return EXIT_FAILURE;
95  }
96 
97  return EXIT_SUCCESS;
98 }
99 
#define arb_assert(cond)
Definition: arb_assert.h:245
const char * GB_ERROR
Definition: arb_core.h:25
Definition: fun.h:25
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
#define EXIT_SUCCESS
Definition: arb_a2ps.c:154
static void error(const char *msg)
Definition: mkptypes.cxx:96
#define EXIT_FAILURE
Definition: arb_a2ps.c:157
#define AW_HEADER_MAIN
Definition: aw_window.hxx:36
void main_loop()
Definition: AW_root.cxx:625
AW_root * AWT_create_root(const char *properties, const char *program, UserActionTracker *user_tracker)
int aw_question(const char *unique_id, const char *question, const char *buttons, bool sameSizeButtons, const char *helpfile)
Definition: AW_question.cxx:26
#define NULp
Definition: cxxforward.h:116
void AWT_install_cb_guards()
AW_HEADER_MAIN int ARB_main(int argc, char *argv[])
Definition: WETC_main.cxx:20
void window_hide(AW_window *aww)
Definition: AW_root.cxx:477
void AWT_show_file(AW_root *awr, const char *filename)