Subversion Repositories Vertical

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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 <string.h>
  17. #include <stdlib.h>
  18. #include <ctype.h>
  19.  
  20. #include "vertcl_main.h"
  21. #include "cmdparse.h"
  22. #include "cmdlog.h"
  23. #include "cmdutil.h"
  24. #include "cmdexec.h"
  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 */
  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(ET_TCLARGS,
  39.                      char * menuname, /* vertical.m.xxxx */
  40.                      char * vertcmd,  /* vertical xxxx */
  41.                      struct command * menu) {
  42.   char * thismenu, * verticalcmd;
  43.   int i;
  44.  
  45.   /* create a menu */
  46.   Et_EvalF(interp,"menu %q",menuname);
  47. #if defined DEB_MENU
  48.   if(f)
  49.     fprintf(f,"menu %s\n",menuname);
  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
  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.  
  83.       }
  84.     }
  85.  
  86.   }
  87. #define MENUNAME ".mb.vertical"
  88. #define MENU_TOP MENUNAME".m"
  89.  
  90. /* creates the top level menu */
  91. int ET_COMMAND_wossat(ET_TCLARGS) {
  92.  
  93.   Tcl_interp = interp;
  94.  
  95.   Et_EvalF(interp,"menubutton "MENUNAME" -text Vertical -menu "MENU_TOP);
  96. #if defined DEB_MENU
  97.   f=fopen("aamenu.txt","w");
  98.   if(f)
  99.     fprintf(f,"menubutton "MENUNAME" -text Vertical -menu "MENU_TOP"\n");
  100. #endif
  101.   create_tcl_menu(clientData,interp,argc,argv,MENU_TOP,"vertical",TopMenu);
  102.   Et_EvalF(interp,"pack "MENUNAME" -side left -padx 5");
  103. #if defined DEB_MENU
  104.   if(f){  
  105.     fprintf(f,"pack "MENUNAME" -side left -padx 5\n");
  106.     fclose(f);
  107.     }
  108. #endif
  109.  
  110.   return TCL_OK;
  111.   }
  112.  
  113.  
  114. /********************************* executes the command from TCL  **************************/
  115. /* this takes the arglist passed in by TCL and converts it to a
  116.    VERTICAL command structure */
  117.  
  118. int ET_COMMAND_vertical (ET_TCLARGS)
  119.    {
  120.    FILE * f;
  121.    int  i,l, Status;
  122.    char * p;
  123.    char * cmdbuff;
  124.  
  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.      }
  134.  
  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);
  144.  
  145.    Status = Execute (argc,argv,TopMenu);
  146.  
  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) {
  155.  
  156.  
  157.      Et_ResultF(interp,"Problem with 'vertical %s'\n",cmdbuff);
  158.      };
  159.  
  160.    Tcl_Free(cmdbuff);
  161.  
  162.    return(Status);
  163.    }
  164.  
  165.  
  166.  
  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. */
  172. int main(int argc, char **argv){
  173. /* VERTICAL SPECIFIC INITIALISATION */
  174.  
  175. /* enter GUI mode for application
  176.  * Later this will be based on a command line switch */
  177.   Tcl_Mode = Tcl_GUI;
  178.  
  179.   atexit(EndErrorLog);
  180.  
  181.  
  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.  
  189. #if ET_AUTO_FORK
  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);
  200. #endif
  201.   return Et_Init(argc,argv)!=TCL_OK;
  202. }
  203.  
  204.