| 1 |
/* X11::GUITest ($Id: script_file.c 253 2026-08-19 22:37:51Z ctrondlp $) |
| 2 |
* |
| 3 |
* Copyright (c) 2003-2026 Dennis K. Paulsen, All Rights Reserved. |
| 4 |
* Email: [email protected] |
| 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 <sys/time.h> |
| 25 |
#include "Common.h" |
| 26 |
#include "script_file.h" |
| 27 |
|
| 28 |
|
| 29 |
static FILE *sfp = NULL; // script output |
| 30 |
|
| 31 |
BOOL OpenScript(char *scriptFile) |
| 32 |
{ |
| 33 |
sfp = fopen(scriptFile, "wt"); |
| 34 |
if (sfp == NULL) { |
| 35 |
fprintf(stderr, _("Unable to open script file '%s'!\n"), scriptFile); |
| 36 |
return FALSE; |
| 37 |
} |
| 38 |
return TRUE; |
| 39 |
} |
| 40 |
|
| 41 |
void WriteScript(char *format, ...) |
| 42 |
{ |
| 43 |
if (sfp == NULL) { |
| 44 |
fprintf(stderr, _("Unable to write to script file!\n")); |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
char buffer[MAX_SCRIPT_BUFFER] = "\0"; |
| 49 |
va_list args; |
| 50 |
va_start(args, format); |
| 51 |
vsnprintf(buffer, sizeof(buffer), format, args); |
| 52 |
fwrite(buffer, sizeof(char), strlen(buffer), sfp); |
| 53 |
va_end(args); |
| 54 |
} |
| 55 |
|
| 56 |
void CloseScript(void) |
| 57 |
{ |
| 58 |
if (sfp != NULL) { |
| 59 |
fflush(sfp); |
| 60 |
fclose(sfp); |
| 61 |
} |
| 62 |
} |
| 63 |
|