| 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 | |
|---|
| 17 | AW_HEADER_MAIN |
|---|
| 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 | |
|---|
| 24 | GB_ERROR error = NULp; |
|---|
| 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); |
|---|
| 76 | AWT_install_cb_guards(); |
|---|
| 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 | |
|---|