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