1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * Rappture::units |
---|
4 | * |
---|
5 | * This is an interface to the rappture units module. |
---|
6 | * It allows you to convert between units and format values. |
---|
7 | * ====================================================================== |
---|
8 | * AUTHOR: Derrick Kearney, Purdue University |
---|
9 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
10 | * |
---|
11 | * See the file "license.terms" for information on usage and |
---|
12 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | * ====================================================================== |
---|
14 | */ |
---|
15 | #include <tcl.h> |
---|
16 | #include "RpUtils.h" |
---|
17 | #include "stdlib.h" |
---|
18 | #include "string.h" |
---|
19 | |
---|
20 | extern "C" Tcl_AppInitProc RpUtils_Init; |
---|
21 | static Tcl_CmdProc RpTclUtilsProgress; |
---|
22 | |
---|
23 | /**********************************************************************/ |
---|
24 | // FUNCTION: RpUtils_Init() |
---|
25 | /// Initializes the Rappture Utils module and commands defined below |
---|
26 | /** |
---|
27 | * Called in RapptureGUI_Init() to initialize the Rappture Utils module. |
---|
28 | * Initialized commands include: |
---|
29 | * ::Rappture::progress |
---|
30 | */ |
---|
31 | |
---|
32 | int |
---|
33 | RpUtils_Init(Tcl_Interp *interp) |
---|
34 | { |
---|
35 | |
---|
36 | Tcl_CreateCommand(interp, "::Rappture::Utils::progress", |
---|
37 | RpTclUtilsProgress, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
---|
38 | |
---|
39 | return TCL_OK; |
---|
40 | } |
---|
41 | |
---|
42 | /**********************************************************************/ |
---|
43 | // FUNCTION: RpTclUtilsProgress() |
---|
44 | /// Rappture::progress function in Tcl, used to print progress statements in gui. |
---|
45 | /** |
---|
46 | * Full function call: |
---|
47 | * ::Rappture::progress <value> ?-mesg mesg? |
---|
48 | * |
---|
49 | */ |
---|
50 | |
---|
51 | int |
---|
52 | RpTclUtilsProgress ( ClientData cdata, |
---|
53 | Tcl_Interp *interp, |
---|
54 | int argc, |
---|
55 | const char *argv[] ) |
---|
56 | { |
---|
57 | int err = 0; // err code for validate() |
---|
58 | int nextarg = 1; |
---|
59 | long int val = 0; // value |
---|
60 | const char* mesg = NULL; // error mesg text |
---|
61 | |
---|
62 | Tcl_ResetResult(interp); |
---|
63 | |
---|
64 | // parse through command line options |
---|
65 | if ( (argc != 2) && (argc != 4) ) { |
---|
66 | Tcl_AppendResult(interp, |
---|
67 | "wrong # args: should be \"",argv[0]," <value> ?-mesg message?\"", |
---|
68 | (char*)NULL); |
---|
69 | return TCL_ERROR; |
---|
70 | } |
---|
71 | |
---|
72 | val = (int) strtol(argv[nextarg++],NULL,10); |
---|
73 | |
---|
74 | if (argc == 4) { |
---|
75 | if (*(argv[nextarg]) == '-') { |
---|
76 | if (strncmp("-mesg",argv[nextarg],5) == 0) { |
---|
77 | nextarg++; |
---|
78 | mesg = argv[nextarg]; |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | err = Rappture::Utils::progress((int)val,mesg); |
---|
84 | |
---|
85 | if (err != 0) { |
---|
86 | Tcl_AppendResult(interp, |
---|
87 | "error while printing progress to stdout", |
---|
88 | (char*)NULL); |
---|
89 | return TCL_ERROR; |
---|
90 | } |
---|
91 | |
---|
92 | return TCL_OK; |
---|
93 | } |
---|