OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [libgui/] [src/] [tclmain.c] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* tclmain.c - a simple main() for IDE programs that use Tk.
2
   Copyright (C) 1997, 1998 Cygnus Solutions.
3
   Written by Tom Tromey <tromey@cygnus.com>.  */
4
 
5
#include <config.h>
6
 
7
#include <tcl.h>
8
#include <tk.h>
9
 
10
#include <stdio.h>
11
 
12
#ifdef HAVE_STDLIB_H
13
#include <stdlib.h>
14
#endif
15
 
16
#ifdef _WIN32
17
#include <windows.h>
18
#include <winuser.h>
19
#endif
20
 
21
#include "guitcl.h"
22
 
23
#ifndef EXIT_SUCCESS
24
#define EXIT_SUCCESS 0
25
#endif
26
 
27
#ifndef EXIT_FAILURE
28
#define EXIT_FAILURE 1
29
#endif
30
 
31
/* This is like Tk_Main, except that the resulting program doesn't try
32
   to act like a script interpreter.  It never reads commands from
33
   stdin.  */
34
void
35
ide_main (int argc, char *argv[], Tcl_AppInitProc *appInitProc)
36
{
37
  Tcl_Interp *interp;
38
  char *args;
39
  char buf[20];
40
 
41
  Tcl_FindExecutable (argv[0]);
42
  interp = Tcl_CreateInterp ();
43
 
44
#ifdef TCL_MEM_DEBUG
45
  Tcl_InitMemory (interp);
46
#endif
47
 
48
  args = Tcl_Merge (argc - 1, argv + 1);
49
  Tcl_SetVar (interp, "argv", args, TCL_GLOBAL_ONLY);
50
  Tcl_Free (args);
51
 
52
  sprintf (buf, "%d", argc-1);
53
  Tcl_SetVar (interp, "argc", buf, TCL_GLOBAL_ONLY);
54
  Tcl_SetVar (interp, "argv0", argv[0], TCL_GLOBAL_ONLY);
55
 
56
  /* We set this to "1" so that the console window will work.  */
57
  Tcl_SetVar (interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
58
 
59
#if IDE_ENABLED
60
    Tcl_SetVar (interp, "IDE_ENABLED", "1", TCL_GLOBAL_ONLY);
61
#else
62
    Tcl_SetVar (interp, "IDE_ENABLED", "0", TCL_GLOBAL_ONLY);
63
#endif
64
 
65
  if ((*appInitProc) (interp) != TCL_OK)
66
    {
67
      Tcl_Channel err_channel;
68
      char *msg;
69
 
70
      /* Guarantee that errorInfo is set properly.  */
71
      Tcl_AddErrorInfo (interp, "");
72
      msg = Tcl_GetVar (interp, "errorInfo", TCL_GLOBAL_ONLY);
73
 
74
      /* On Windows, we are probably running as a windows app, and
75
         stderr is the bit bucket, so we call a win32 function to
76
         display the error.  */
77
 
78
#ifdef _WIN32
79
      MessageBox (NULL, msg, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL);
80
#else
81
      err_channel = Tcl_GetStdChannel (TCL_STDERR);
82
      if (err_channel)
83
        {
84
 
85
          Tcl_Write (err_channel, msg, -1);
86
          Tcl_Write (err_channel, "\n", 1);
87
        }
88
#endif
89
 
90
      Tcl_DeleteInterp (interp);
91
      Tcl_Exit (EXIT_FAILURE);
92
    }
93
 
94
  Tcl_ResetResult (interp);
95
 
96
  /* Now just go until the user decides to shut down.  */
97
  Tk_MainLoop ();
98
  Tcl_DeleteInterp (interp);
99
  Tcl_Exit (EXIT_SUCCESS);
100
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.