|
| 1 | +// This file is part of SmallBASIC |
| 2 | +// |
| 3 | +// This program is distributed under the terms of the GPL v2.0 or later |
| 4 | +// Download the GNU Public License (GPL) from www.gnu.org |
| 5 | +// |
| 6 | +// Copyright(C) 2020 Chris Warren-Smith |
| 7 | + |
| 8 | +#include "config.h" |
| 9 | + |
| 10 | +#include <sys/stat.h> |
| 11 | +#include <cstring> |
| 12 | +#include <cstdlib> |
| 13 | + |
| 14 | +#include "include/var.h" |
| 15 | +#include "include/module.h" |
| 16 | +#include "include/param.h" |
| 17 | + |
| 18 | +char *programSource = nullptr; |
| 19 | +uint32_t modifiedTime; |
| 20 | + |
| 21 | +uint32_t get_modified_time() { |
| 22 | + uint32_t result = 0; |
| 23 | + if (programSource != nullptr) { |
| 24 | + struct stat st_file; |
| 25 | + if (!stat(programSource, &st_file)) { |
| 26 | + result = st_file.st_mtime; |
| 27 | + } |
| 28 | + } |
| 29 | + return result; |
| 30 | +} |
| 31 | + |
| 32 | +int cmd_issourcemodified(int argc, slib_par_t *params, var_t *retval) { |
| 33 | + v_setint(retval, modifiedTime < get_modified_time()); |
| 34 | + return 1; |
| 35 | +} |
| 36 | + |
| 37 | +FUNC_SIG lib_func[] = { |
| 38 | + {0, 0, "ISSOURCEMODIFIED", cmd_issourcemodified}, |
| 39 | +}; |
| 40 | + |
| 41 | +int sblib_func_count() { |
| 42 | + return (sizeof(lib_func) / sizeof(lib_func[0])); |
| 43 | +} |
| 44 | + |
| 45 | +int sblib_func_getname(int index, char *proc_name) { |
| 46 | + int result; |
| 47 | + if (index < sblib_func_count()) { |
| 48 | + strcpy(proc_name, lib_func[index]._name); |
| 49 | + result = 1; |
| 50 | + } else { |
| 51 | + result = 0; |
| 52 | + } |
| 53 | + return result; |
| 54 | +} |
| 55 | + |
| 56 | +int sblib_func_exec(int index, int argc, slib_par_t *params, var_t *retval) { |
| 57 | + int result; |
| 58 | + if (index < sblib_func_count()) { |
| 59 | + result = lib_func[index]._command(argc, params, retval); |
| 60 | + } else { |
| 61 | + result = 0; |
| 62 | + } |
| 63 | + return result; |
| 64 | +} |
| 65 | + |
| 66 | +int sblib_init(const char *sourceFile) { |
| 67 | + programSource = strdup(sourceFile); |
| 68 | + modifiedTime = get_modified_time(); |
| 69 | + return 1; |
| 70 | +} |
| 71 | + |
| 72 | +void sblib_close(void) { |
| 73 | + free(programSource); |
| 74 | +} |
0 commit comments