~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to visualization/nviz/src/script_support.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * script_support.c --
3
 
 *
4
 
 * This file provides a few commands for supporting scripting.
5
 
 * Basically, we just track any X events and flush them to
6
 
 * a file.
7
 
 */
8
 
 
9
 
#include <stdio.h>
10
 
#include <stdlib.h>
11
 
#include <tk.h>
12
 
 
13
 
int Nv_script_state = 0;
14
 
FILE *Nv_script_file = NULL;
15
 
 
16
 
/*
17
 
 * ScriptAddString_Cmd --
18
 
 *
19
 
 * syntax: Nv_script_add_string string
20
 
 * Output a string to the current script file if one exists
21
 
 *
22
 
 */
23
 
int ScriptAddString_Cmd(ClientData clientData,  /* Main window associated with
24
 
                                                 * interpreter. */
25
 
                        Tcl_Interp * interp,    /* Current interpreter. */
26
 
                        int argc,       /* Number of arguments. */
27
 
                        char **argv     /* Argument strings. */
28
 
    )
29
 
{
30
 
    if (argc != 2) {
31
 
        Tcl_SetResult(interp, "Usage: Nv_script_add_string string",
32
 
                      TCL_VOLATILE);
33
 
        return (TCL_ERROR);
34
 
    }
35
 
 
36
 
    if (Nv_script_file != NULL) {
37
 
        fprintf(Nv_script_file, "%s\n", argv[1]);
38
 
    }
39
 
 
40
 
    return (TCL_OK);
41
 
}
42
 
 
43
 
/*
44
 
 * CloseScripting_Cmd --
45
 
 *
46
 
 * Closes the current scriptfile if one exists.
47
 
 */
48
 
int CloseScripting_Cmd(ClientData clientData,   /* Main window associated with
49
 
                                                 * interpreter. */
50
 
                       Tcl_Interp * interp,     /* Current interpreter. */
51
 
                       int argc,        /* Number of arguments. */
52
 
                       char **argv      /* Argument strings. */
53
 
    )
54
 
{
55
 
    if (argc != 1) {
56
 
        Tcl_SetResult(interp, "Usage: Nv_close_scripting", TCL_VOLATILE);
57
 
        return (TCL_ERROR);
58
 
    }
59
 
 
60
 
    if (Nv_script_file != NULL) {
61
 
        fprintf(Nv_script_file, "puts \"script complete\"\n");
62
 
        fclose(Nv_script_file);
63
 
    }
64
 
 
65
 
    return (TCL_OK);
66
 
}
67
 
 
68
 
/*
69
 
 * ScriptState_Cmd --
70
 
 *
71
 
 * Takes one argument to turn scripting on and off. 1=on 0=off
72
 
 */
73
 
int SetState_Cmd(ClientData clientData, /* Main window associated with
74
 
                                         * interpreter. */
75
 
                 Tcl_Interp * interp,   /* Current interpreter. */
76
 
                 int argc,      /* Number of arguments. */
77
 
                 char **argv    /* Argument strings. */
78
 
    )
79
 
{
80
 
    int val;
81
 
 
82
 
    if (argc != 2) {
83
 
        Tcl_SetResult(interp, "Usage: Nv_set_script_state [0 | 1]",
84
 
                      TCL_VOLATILE);
85
 
        return (TCL_ERROR);
86
 
    }
87
 
 
88
 
    if (Nv_script_file == NULL) {
89
 
        Tcl_SetResult(interp, "no script file specified", TCL_VOLATILE);
90
 
        return (TCL_ERROR);
91
 
    }
92
 
 
93
 
    Tcl_GetInt(interp, argv[1], &val);
94
 
 
95
 
    if (val)
96
 
        Nv_script_state = 1;
97
 
    else
98
 
        Nv_script_state = 0;
99
 
 
100
 
    return (TCL_OK);
101
 
}
102
 
 
103
 
 
104
 
/*
105
 
 * SetScriptFile_Cmd --
106
 
 *
107
 
 * Possibly open a new script file with the given name.
108
 
 */
109
 
int SetScriptFile_Cmd(ClientData clientData,    /* Main window associated with
110
 
                                                 * interpreter. */
111
 
                      Tcl_Interp * interp,      /* Current interpreter. */
112
 
                      int argc, /* Number of arguments. */
113
 
                      char **argv       /* Argument strings. */
114
 
    )
115
 
{
116
 
    if (argc != 2) {
117
 
        Tcl_SetResult(interp, "Usage: Nv_set_script_file file_name",
118
 
                      TCL_VOLATILE);
119
 
        return (TCL_ERROR);
120
 
    }
121
 
 
122
 
    if (Nv_script_file != NULL) {
123
 
        fclose(Nv_script_file);
124
 
    }
125
 
 
126
 
    Nv_script_file = fopen(argv[1], "a");
127
 
 
128
 
    /* Do a little initialization for file looping */
129
 
    fprintf(Nv_script_file, "global Nv_mapLoopMode Nv_mapLoopFile\n");
130
 
    fprintf(Nv_script_file, "set Nv_mapLoopMode 0\n");
131
 
    fprintf(Nv_script_file, "set Nv_mapLoopFile \"\"\n");
132
 
 
133
 
    return (TCL_OK);
134
 
}