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