1 /* X11::GUITest ($Id: script_file.c 231 2014-01-11 14:26:57Z ctrondlp $)
2 *
3 * Copyright (c) 2003-2014 Dennis K. Paulsen, All Rights Reserved.
4 * Email: ctrondlp@cpan.org
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses>.
18 *
19 */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stdarg.h>
23 #include <string.h>
24 #include <libintl.h>
25 #include <sys/time.h>
26 #include "Common.h"
27 #include "script_file.h"
28
29
30 static FILE *sfp = NULL; // script output
31
OpenScript(char * scriptFile)32 BOOL OpenScript(char *scriptFile)
33 {
34 sfp = fopen(scriptFile, "wt");
35 if (sfp == NULL) {
36 fprintf(stderr, _("Unable to open script file '%s'!\n"), scriptFile);
37 return FALSE;
38 }
39 return TRUE;
40 }
41
WriteScript(char * format,...)42 void WriteScript(char *format, ...)
43 {
44 if (sfp == NULL) {
45 fprintf(stderr, _("Unable to write to script file!\n"));
46 return;
47 }
48
49 char buffer[MAX_SCRIPT_BUFFER] = "\0";
50 va_list args;
51 va_start(args, format);
52 vsprintf(buffer, format, args);
53 fwrite(buffer, sizeof(char), strlen(buffer), sfp);
54 va_end(args);
55 }
56
CloseScript(void)57 void CloseScript(void)
58 {
59 if (sfp != NULL) {
60 fflush(sfp);
61 fclose(sfp);
62 }
63 }
64
65