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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [unix/] [tk4.2/] [tkUnixSam42.c] - Blame information for rev 1774

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

Line No. Rev Author Line
1 578 markom
/*
2
 * tkUnixSam42.c --
3
 *
4
 *      Initializes the Tk stand-alone module Tk version 4.2.
5
 *
6
 * Copyright (c) 1996, Expert Interface Technologies
7
 *
8
 * See the file "license.terms" for information on usage and redistribution
9
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
 *
11
 */
12
 
13
#include <tkPort.h>
14
#include <tkInt.h>
15
 
16
#if defined(__WIN32__) || defined(_WIN32)
17
#   define SAMTK_WINDOWS
18
#else
19
#   if defined(MAC_TCL)
20
#       define SAMTK_MAC
21
#   else
22
#       define SAMTK_UNIX
23
#       include <tkUnixInt.h>
24
#   endif
25
#endif
26
 
27
int                     SamTk_Init _ANSI_ARGS_((Tcl_Interp *interp));
28
 
29
#include "tkSamLib.c"
30
 
31
static int
32
SamTkPlatformInit(interp)
33
    Tcl_Interp * interp;
34
{
35
#ifdef SAMTK_UNIX
36
    TkCreateXEventSource();
37
#endif
38
    Tcl_Eval(interp, "set tk_library {}");
39
    return LoadScripts(interp);
40
}
41
 
42
/*
43
 * The variables and table below are used to parse arguments from
44
 * the "argv" variable in Tk_Init.
45
 */
46
 
47
static int synchronize;
48
static char *name;
49
static char *display;
50
static char *geometry;
51
static char *colormap;
52
static char *visual;
53
static int rest = 0;
54
 
55
static Tk_ArgvInfo argTable[] = {
56
    {"-colormap", TK_ARGV_STRING, (char *) NULL, (char *) &colormap,
57
        "Colormap for main window"},
58
    {"-display", TK_ARGV_STRING, (char *) NULL, (char *) &display,
59
        "Display to use"},
60
    {"-geometry", TK_ARGV_STRING, (char *) NULL, (char *) &geometry,
61
        "Initial geometry for window"},
62
    {"-name", TK_ARGV_STRING, (char *) NULL, (char *) &name,
63
        "Name to use for application"},
64
    {"-sync", TK_ARGV_CONSTANT, (char *) 1, (char *) &synchronize,
65
        "Use synchronous mode for display server"},
66
    {"-visual", TK_ARGV_STRING, (char *) NULL, (char *) &visual,
67
        "Visual for main window"},
68
    {"--", TK_ARGV_REST, (char *) 1, (char *) &rest,
69
        "Pass all remaining arguments through to script"},
70
    {(char *) NULL, TK_ARGV_END, (char *) NULL, (char *) NULL,
71
        (char *) NULL}
72
};
73
 
74
int
75
Tksam_Init(interp)
76
    Tcl_Interp *interp;         /* Interpreter to initialize. */
77
{
78
    char *p;
79
    int argc, code;
80
    char **argv, *args[20];
81
    Tcl_DString class;
82
    char buffer[30];
83
 
84
    /*
85
     * If there is an "argv" variable, get its value, extract out
86
     * relevant arguments from it, and rewrite the variable without
87
     * the arguments that we used.
88
     */
89
 
90
    synchronize = 0;
91
    name = display = geometry = colormap = visual = NULL;
92
    p = Tcl_GetVar2(interp, "argv", (char *) NULL, TCL_GLOBAL_ONLY);
93
    argv = NULL;
94
    if (p != NULL) {
95
        if (Tcl_SplitList(interp, p, &argc, &argv) != TCL_OK) {
96
            argError:
97
            Tcl_AddErrorInfo(interp,
98
                    "\n    (processing arguments in argv variable)");
99
            return TCL_ERROR;
100
        }
101
        if (Tk_ParseArgv(interp, (Tk_Window) NULL, &argc, argv,
102
                argTable, TK_ARGV_DONT_SKIP_FIRST_ARG|TK_ARGV_NO_DEFAULTS)
103
                != TCL_OK) {
104
            ckfree((char *) argv);
105
            goto argError;
106
        }
107
        p = Tcl_Merge(argc, argv);
108
        Tcl_SetVar2(interp, "argv", (char *) NULL, p, TCL_GLOBAL_ONLY);
109
        sprintf(buffer, "%d", argc);
110
        Tcl_SetVar2(interp, "argc", (char *) NULL, buffer, TCL_GLOBAL_ONLY);
111
        ckfree(p);
112
    }
113
 
114
    /*
115
     * Figure out the application's name and class.
116
     */
117
 
118
    if (name == NULL) {
119
        name = Tcl_GetVar(interp, "argv0", TCL_GLOBAL_ONLY);
120
        if ((name == NULL) || (*name == 0)) {
121
            name = "tk";
122
        } else {
123
            p = strrchr(name, '/');
124
            if (p != NULL) {
125
                name = p+1;
126
            }
127
        }
128
    }
129
    Tcl_DStringInit(&class);
130
    Tcl_DStringAppend(&class, name, -1);
131
    p = Tcl_DStringValue(&class);
132
    if (islower(*p)) {
133
        *p = toupper((unsigned char) *p);
134
    }
135
 
136
    /*
137
     * Create an argument list for creating the top-level window,
138
     * using the information parsed from argv, if any.
139
     */
140
 
141
    args[0] = "toplevel";
142
    args[1] = ".";
143
    args[2] = "-class";
144
    args[3] = Tcl_DStringValue(&class);
145
    argc = 4;
146
    if (display != NULL) {
147
        args[argc] = "-screen";
148
        args[argc+1] = display;
149
        argc += 2;
150
 
151
        /*
152
         * If this is the first application for this process, save
153
         * the display name in the DISPLAY environment variable so
154
         * that it will be available to subprocesses created by us.
155
         */
156
 
157
        if (Tk_GetNumMainWindows() == 0) {
158
            Tcl_SetVar2(interp, "env", "DISPLAY", display, TCL_GLOBAL_ONLY);
159
        }
160
    }
161
    if (colormap != NULL) {
162
        args[argc] = "-colormap";
163
        args[argc+1] = colormap;
164
        argc += 2;
165
    }
166
    if (visual != NULL) {
167
        args[argc] = "-visual";
168
        args[argc+1] = visual;
169
        argc += 2;
170
    }
171
    args[argc] = NULL;
172
    code = TkCreateFrame((ClientData) NULL, interp, argc, args, 1, name);
173
    Tcl_DStringFree(&class);
174
    if (code != TCL_OK) {
175
        goto done;
176
    }
177
    Tcl_ResetResult(interp);
178
    if (synchronize) {
179
        XSynchronize(Tk_Display(Tk_MainWindow(interp)), True);
180
    }
181
 
182
    /*
183
     * Set the geometry of the main window, if requested.  Put the
184
     * requested geometry into the "geometry" variable.
185
     */
186
 
187
    if (geometry != NULL) {
188
        Tcl_SetVar(interp, "geometry", geometry, TCL_GLOBAL_ONLY);
189
        code = Tcl_VarEval(interp, "wm geometry . ", geometry, (char *) NULL);
190
        if (code != TCL_OK) {
191
            goto done;
192
        }
193
    }
194
    if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 1) == NULL) {
195
        code = TCL_ERROR;
196
        goto done;
197
    }
198
    code = Tcl_PkgProvide(interp, "Tk", TK_VERSION);
199
    if (code != TCL_OK) {
200
        goto done;
201
    }
202
 
203
    /*
204
     * Invoke platform-specific initialization.
205
     */
206
 
207
    code = SamTkPlatformInit(interp);
208
 
209
    done:
210
    if (argv != NULL) {
211
        ckfree((char *) argv);
212
    }
213
    return code;
214
}
215
 

powered by: WebSVN 2.1.0

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