Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /********************************* executes the command from TCL **************************/ |
| 2 | /* |
||
| 3 | * $Id: vertcl_main_user.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $ |
||
| 4 | * |
||
| 5 | * $Log: vertcl_main_user.c,v $ |
||
| 6 | * Revision 1.1.1.1 2003/11/04 23:34:56 mjames |
||
| 7 | * Imported into local repositrory |
||
| 8 | * |
||
| 9 | * Revision 1.6 2001/10/31 22:20:19 mjames |
||
| 10 | * Tidying up problematical comments caused by CVS |
||
| 11 | * 'intelligent' comment guessing |
||
| 12 | * |
||
| 13 | */ |
||
| 14 | /* this takes the arglist passed in by TCL and converts it to a |
||
| 15 | VERTICAL command structure */ |
||
| 16 | #include "cmdexec.h" |
||
| 17 | #include "cmdlog.h" |
||
| 18 | #include "cmdparse.h" |
||
| 19 | #include "cmdutil.h" |
||
| 20 | #include "expression.h" |
||
| 21 | #include "generic.h" |
||
| 22 | #include "vertcl_main.h" |
||
| 23 | |||
| 24 | #include <ctype.h> |
||
| 25 | #include <stdlib.h> |
||
| 26 | #include <string.h> |
||
| 27 | /* used for dynamic string allocation/deallocation code |
||
| 28 | * used here for command keywords May 2 2000 */ |
||
| 29 | #include "lx_support.h" |
||
| 30 | |||
| 31 | #define DEB_MENU |
||
| 32 | |||
| 33 | #if defined DEB_MENU |
||
| 34 | FILE *f; |
||
| 35 | #endif |
||
| 36 | |||
| 37 | /* fills in a single menu item */ |
||
| 38 | void create_tcl_menu ( |
||
| 39 | ET_TCLARGS, |
||
| 40 | char *menuname, /* vertical.m.xxxx */ |
||
| 41 | char *vertcmd, /* vertical xxxx */ |
||
| 42 | struct command *menu) |
||
| 43 | { |
||
| 44 | char *thismenu, *verticalcmd; |
||
| 45 | int i; |
||
| 46 | |||
| 47 | /* create a menu */ |
||
| 48 | Et_EvalF (interp, "menu %q", menuname); |
||
| 49 | #if defined DEB_MENU |
||
| 50 | if (f) |
||
| 51 | fprintf (f, "menu %s\n", menuname); |
||
| 52 | #endif |
||
| 53 | for (i = 0; menu[i].name; i++) |
||
| 54 | { |
||
| 55 | if (menu[i].Menu) |
||
| 56 | { |
||
| 57 | thismenu = Tcl_Alloc (strlen (menuname) + strlen (menu[i].name) + 10); |
||
| 58 | verticalcmd = |
||
| 59 | Tcl_Alloc (strlen (vertcmd) + strlen (menu[i].name) + 10); |
||
| 60 | sprintf (thismenu, "%s.%s", menuname, menu[i].name); |
||
| 61 | sprintf (verticalcmd, "%s %s", vertcmd, menu[i].name); |
||
| 62 | |||
| 63 | Et_EvalF ( |
||
| 64 | interp, |
||
| 65 | "%q add cascade -label \"%q\" -menu \"%q\"", |
||
| 66 | menuname, |
||
| 67 | menu[i].name, |
||
| 68 | thismenu); |
||
| 69 | #if defined DEB_MENU |
||
| 70 | if (f) |
||
| 71 | fprintf ( |
||
| 72 | f, |
||
| 73 | "%s add cascade -label \"%s\" -menu \"%s\"\n", |
||
| 74 | menuname, |
||
| 75 | menu[i].name, |
||
| 76 | thismenu); |
||
| 77 | #endif |
||
| 78 | |||
| 79 | create_tcl_menu ( |
||
| 80 | clientData, |
||
| 81 | interp, |
||
| 82 | argc, |
||
| 83 | argv, |
||
| 84 | thismenu, |
||
| 85 | verticalcmd, |
||
| 86 | menu[i].Menu); |
||
| 87 | } |
||
| 88 | else |
||
| 89 | { |
||
| 90 | verticalcmd = |
||
| 91 | Tcl_Alloc (strlen (vertcmd) + strlen (menu[i].name) + 10); |
||
| 92 | sprintf (verticalcmd, "%s %s", vertcmd, menu[i].name); |
||
| 93 | |||
| 94 | Et_EvalF ( |
||
| 95 | interp, |
||
| 96 | "%q add command -label \"%q\" -command \"%q\" ", |
||
| 97 | menuname, |
||
| 98 | menu[i].name, |
||
| 99 | verticalcmd); |
||
| 100 | #if defined DEB_MENU |
||
| 101 | if (f) |
||
| 102 | fprintf ( |
||
| 103 | f, |
||
| 104 | "%s add command -label \"%s\" -command \"%s\"\n", |
||
| 105 | menuname, |
||
| 106 | menu[i].name, |
||
| 107 | verticalcmd); |
||
| 108 | #endif |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | #define MENUNAME ".mb.vertical" |
||
| 113 | #define MENU_TOP MENUNAME ".m" |
||
| 114 | |||
| 115 | /* creates the top level menu */ |
||
| 116 | int ET_COMMAND_wossat (ET_TCLARGS) |
||
| 117 | { |
||
| 118 | Tcl_interp = interp; |
||
| 119 | |||
| 120 | Et_EvalF (interp, "menubutton " MENUNAME " -text Vertical -menu " MENU_TOP); |
||
| 121 | #if defined DEB_MENU |
||
| 122 | f = fopen ("aamenu.txt", "w"); |
||
| 123 | if (f) |
||
| 124 | fprintf (f, "menubutton " MENUNAME " -text Vertical -menu " MENU_TOP "\n"); |
||
| 125 | #endif |
||
| 126 | create_tcl_menu (clientData, interp, argc, argv, MENU_TOP, "vertical", TopMenu); |
||
| 127 | Et_EvalF (interp, "pack " MENUNAME " -side left -padx 5"); |
||
| 128 | #if defined DEB_MENU |
||
| 129 | if (f) |
||
| 130 | { |
||
| 131 | fprintf (f, "pack " MENUNAME " -side left -padx 5\n"); |
||
| 132 | fclose (f); |
||
| 133 | } |
||
| 134 | #endif |
||
| 135 | |||
| 136 | return TCL_OK; |
||
| 137 | } |
||
| 138 | |||
| 139 | /********************************* executes the command from TCL **************************/ |
||
| 140 | /* this takes the arglist passed in by TCL and converts it to a |
||
| 141 | VERTICAL command structure */ |
||
| 142 | |||
| 143 | int ET_COMMAND_vertical (ET_TCLARGS) |
||
| 144 | { |
||
| 145 | FILE *f; |
||
| 146 | int i, l, Status; |
||
| 147 | char *p; |
||
| 148 | char *cmdbuff; |
||
| 149 | |||
| 150 | Tcl_interp = interp; |
||
| 151 | if (argc) |
||
| 152 | { |
||
| 153 | argc--; |
||
| 154 | argv++; |
||
| 155 | } |
||
| 156 | l = 0; |
||
| 157 | for (i = 0; i < argc - 1; i++) |
||
| 158 | { |
||
| 159 | l += strlen (argv[i + 1]) + 1; |
||
| 160 | } |
||
| 161 | |||
| 162 | cmdbuff = Tcl_Alloc (l + strlen (argv[0]) + 2); |
||
| 163 | cmdbuff[0] = 0; |
||
| 164 | for (i = 0; i < argc; i++) |
||
| 165 | { |
||
| 166 | strcat (cmdbuff, argv[i]); |
||
| 167 | strcat (cmdbuff, " "); |
||
| 168 | } |
||
| 169 | /* whatever command is given, put it in the console scroll |
||
| 170 | buffer , but not yet in the history */ |
||
| 171 | Log_Command ("# %s\n", cmdbuff); |
||
| 172 | |||
| 173 | Status = Execute (argc, argv, TopMenu); |
||
| 174 | |||
| 175 | switch (Status) |
||
| 176 | { |
||
| 177 | case TCL_ERROR: |
||
| 178 | Log (LOG_ERROR, "# Unknown command:"); |
||
| 179 | break; |
||
| 180 | default: |
||
| 181 | Status = TCL_OK; |
||
| 182 | }; |
||
| 183 | if (Status != TCL_OK) |
||
| 184 | { |
||
| 185 | Et_ResultF (interp, "Problem with 'vertical %s'\n", cmdbuff); |
||
| 186 | }; |
||
| 187 | |||
| 188 | Tcl_Free (cmdbuff); |
||
| 189 | |||
| 190 | return (Status); |
||
| 191 | } |
||
| 192 | |||
| 193 | /* |
||
| 194 | ** Main routine for UNIX programs. If the user has supplied |
||
| 195 | ** their own main() routine in a C module, then the ET_HAVE_MAIN |
||
| 196 | ** macro will be set to 1 and this code will be skipped. |
||
| 197 | */ |
||
| 198 | int main (int argc, char **argv) |
||
| 199 | { |
||
| 200 | /* VERTICAL SPECIFIC INITIALISATION */ |
||
| 201 | |||
| 202 | /* enter GUI mode for application |
||
| 203 | * Later this will be based on a command line switch */ |
||
| 204 | Tcl_Mode = Tcl_GUI; |
||
| 205 | |||
| 206 | atexit (EndErrorLog); |
||
| 207 | |||
| 208 | InitErrorLog (); |
||
| 209 | InitialiseData (); |
||
| 210 | /* called inside vertical */ |
||
| 211 | // ExecuteString("echo running \\$(VERTICAL_INIT) file name = $(VERTICAL_INIT) ", |
||
| 212 | // argc, argv); ExecuteString("do $(VERTICAL_INIT) ", argc, argv); |
||
| 213 | |||
| 214 | #if ET_AUTO_FORK |
||
| 215 | int rc = fork (); |
||
| 216 | if (rc < 0) |
||
| 217 | { |
||
| 218 | perror ("can't fork"); |
||
| 219 | exit (1); |
||
| 220 | } |
||
| 221 | if (rc > 0) |
||
| 222 | return 0; |
||
| 223 | close (0); |
||
| 224 | open ("/dev/null", O_RDONLY); |
||
| 225 | close (1); |
||
| 226 | open ("/dev/null", O_WRONLY); |
||
| 227 | #endif |
||
| 228 | return Et_Init (argc, argv) != TCL_OK; |
||
| 229 | } |