1 /*
2    Copyright (c) 2003 Perry Rapp
3    "The MIT license"
4    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 */
8 /*=============================================================
9  * rptui.c -- Wrappers for UI functions used by report interpreter
10  * These take care of switching to UI locale, and keeping GUI wait time
11  *  accounted separately from report run time.
12  *==============================================================*/
13 
14 
15 #include <time.h>
16 #include "llstdlib.h"
17 #include "liflines.h"
18 #include "rptui.h"
19 
20 /*********************************************
21  * local function prototypes
22  *********************************************/
23 
24 /* alphabetical */
25 static void begin_rptui(void);
26 static void end_rptui(void);
27 
28 /*********************************************
29  * local variables
30  *********************************************/
31 
32 static time_t uitime=0;
33 static time_t begint=0;
34 
35 /*=================================================
36  * begin_rptui -- begin a UI call from report interpreter
37  *===============================================*/
38 static void
begin_rptui(void)39 begin_rptui (void)
40 {
41 	uilocale();
42 	begint = time(NULL);
43 }
44 /*=================================================
45  * end_rptui -- finish a UI call & return to report interpreter
46  *===============================================*/
47 static void
end_rptui(void)48 end_rptui (void)
49 {
50 	rptlocale();
51 	uitime += time(NULL) - begint;
52 	begint = 0;
53 }
54 /*=================================================
55  * rptui_init -- begin UI timing for report
56  *===============================================*/
57 void
rptui_init(void)58 rptui_init (void)
59 {
60 	uitime = 0;
61 }
62 /*=================================================
63  * rptui_elapsed -- report elapsed UI time for report
64  *===============================================*/
65 int
rptui_elapsed(void)66 rptui_elapsed (void)
67 {
68 	return (int)uitime;
69 }
70 /*==========================================================
71  * Wrappers for ui functions
72  *========================================================*/
73 RECORD
rptui_ask_for_fam(STRING s1,STRING s2)74 rptui_ask_for_fam (STRING s1, STRING s2)
75 {
76 	RECORD rec;
77 	begin_rptui();
78 	rec = ask_for_fam(s1, s2);
79 	end_rptui();
80 	return rec;
81 }
82 INDISEQ
rptui_ask_for_indi_list(STRING ttl,BOOLEAN reask)83 rptui_ask_for_indi_list (STRING ttl, BOOLEAN reask)
84 {
85 	INDISEQ seq;
86 	begin_rptui();
87 	seq = ask_for_indi_list(ttl, reask);
88 	end_rptui();
89 	return seq;
90 }
91 STRING
rptui_ask_for_indi_key(STRING ttl,ASK1Q ask1)92 rptui_ask_for_indi_key (STRING ttl, ASK1Q ask1)
93 {
94 	STRING s;
95 	begin_rptui();
96 	s = ask_for_indi_key(ttl, ask1);
97 	end_rptui();
98 	return s;
99 }
100 BOOLEAN
rptui_ask_for_int(STRING ttl,INT * prtn)101 rptui_ask_for_int (STRING ttl, INT * prtn)
102 {
103 	BOOLEAN b;
104 	begin_rptui();
105 	b = ask_for_int(ttl, prtn);
106 	end_rptui();
107 	return b;
108 }
109 FILE *
rptui_ask_for_output_file(STRING mode,STRING ttl,STRING * pfname,STRING * pfullpath,STRING path,STRING ext)110 rptui_ask_for_output_file (STRING mode, STRING ttl, STRING *pfname
111 	, STRING *pfullpath, STRING path, STRING ext)
112 {
113 	FILE * fp;
114 	begin_rptui();
115 	fp = ask_for_output_file(mode, ttl, pfname, pfullpath, path, ext);
116 	end_rptui();
117 	return fp;
118 }
119 BOOLEAN
rptui_ask_for_program(STRING mode,STRING ttl,STRING * pfname,STRING * pfullpath,STRING path,STRING ext,BOOLEAN picklist)120 rptui_ask_for_program (STRING mode, STRING ttl, STRING *pfname
121 	, STRING *pfullpath, STRING path, STRING ext, BOOLEAN picklist)
122 {
123 	BOOLEAN b;
124 	begin_rptui();
125 	b = ask_for_program(mode, ttl, pfname, pfullpath, path, ext, picklist);
126 	end_rptui();
127 	return b;
128 }
129 INT
rptui_choose_from_array(STRING ttl,INT no,STRING * pstrngs)130 rptui_choose_from_array (STRING ttl, INT no, STRING *pstrngs)
131 {
132 	INT i;
133 	begin_rptui();
134 	i = choose_from_array(ttl, no, pstrngs);
135 	end_rptui();
136 	return i;
137 }
138 INT
rptui_prompt_stdout(STRING prompt)139 rptui_prompt_stdout (STRING prompt)
140 {
141 	INT i;
142 	begin_rptui();
143 	i = prompt_stdout(prompt);
144 	end_rptui();
145 	return i;
146 }
147 void
rptui_view_array(STRING ttl,INT no,STRING * pstrngs)148 rptui_view_array (STRING ttl, INT no, STRING *pstrngs)
149 {
150 	begin_rptui();
151 	view_array(ttl, no, pstrngs);
152 	end_rptui();
153 }
154