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 "RpUtilsTclInterface.h" |
---|
18 | #include "stdlib.h" |
---|
19 | #include "string.h" |
---|
20 | |
---|
21 | #ifdef __cplusplus |
---|
22 | extern "C" { |
---|
23 | #endif |
---|
24 | |
---|
25 | // EXTERN int RapptureUnits_Init _ANSI_ARGS_((Tcl_Interp * interp)); |
---|
26 | |
---|
27 | static int RpTclUtilsProgress _ANSI_ARGS_(( ClientData cdata, |
---|
28 | Tcl_Interp *interp, |
---|
29 | int argc, |
---|
30 | const char *argv[] )); |
---|
31 | |
---|
32 | #ifdef __cplusplus |
---|
33 | } |
---|
34 | #endif |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | /**********************************************************************/ |
---|
43 | // FUNCTION: RapptureUtils_Init() |
---|
44 | /// Initializes the Rappture Utils module and commands defined below |
---|
45 | /** |
---|
46 | * Called in RapptureGUI_Init() to initialize the Rappture Utils module. |
---|
47 | * Initialized commands include: |
---|
48 | * ::Rappture::progress |
---|
49 | */ |
---|
50 | |
---|
51 | int |
---|
52 | RapptureUtils_Init(Tcl_Interp *interp) |
---|
53 | { |
---|
54 | |
---|
55 | Tcl_CreateCommand(interp, "::Rappture::progress", |
---|
56 | RpTclUtilsProgress, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); |
---|
57 | |
---|
58 | return TCL_OK; |
---|
59 | } |
---|
60 | |
---|
61 | /**********************************************************************/ |
---|
62 | // FUNCTION: RpTclUtilsProgress() |
---|
63 | /// Rappture::progress function in Tcl, used to print progress statements in gui. |
---|
64 | /** |
---|
65 | * Full function call: |
---|
66 | * ::Rappture::progress <value> ?-mesg mesg? |
---|
67 | * |
---|
68 | */ |
---|
69 | |
---|
70 | int |
---|
71 | RpTclUtilsProgress ( ClientData cdata, |
---|
72 | Tcl_Interp *interp, |
---|
73 | int argc, |
---|
74 | const char *argv[] ) |
---|
75 | { |
---|
76 | int err = 0; // err code for validate() |
---|
77 | int nextarg = 1; |
---|
78 | long int val = 0; // value |
---|
79 | const char* mesg = NULL; // error mesg text |
---|
80 | |
---|
81 | Tcl_ResetResult(interp); |
---|
82 | |
---|
83 | // parse through command line options |
---|
84 | if ( (argc != 2) && (argc != 4) ) { |
---|
85 | Tcl_AppendResult(interp, |
---|
86 | "wrong # args: should be \"",argv[0]," <value> ?-mesg message?\"", |
---|
87 | (char*)NULL); |
---|
88 | return TCL_ERROR; |
---|
89 | } |
---|
90 | |
---|
91 | val = (int) strtol(argv[nextarg++],NULL,10); |
---|
92 | |
---|
93 | if (argc == 4) { |
---|
94 | if (*(argv[nextarg]) == '-') { |
---|
95 | if (strncmp("-mesg",argv[nextarg],5) == 0) { |
---|
96 | nextarg++; |
---|
97 | mesg = argv[nextarg]; |
---|
98 | } |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | err = Rappture::progress((int)val,mesg); |
---|
103 | |
---|
104 | if (err != 0) { |
---|
105 | Tcl_AppendResult(interp, |
---|
106 | "error while printing progress to stdout", |
---|
107 | (char*)NULL); |
---|
108 | return TCL_ERROR; |
---|
109 | } |
---|
110 | |
---|
111 | return TCL_OK; |
---|
112 | } |
---|