/* --- END LICENSE --- */
#include <dataworks.h>
+#include <dw_util.h>
#include <stdbool.h>
#include <stdio.h>
HANDLE winstdout;
#endif
+void padleft(int leftpad, const char* str) {
+ int i;
+ char* spaces = malloc(leftpad - strlen(str) + 1);
+ memset(spaces, ' ', leftpad - strlen(str));
+ spaces[leftpad - strlen(str)] = 0;
+ printf("%s%s", str, spaces);
+ free(spaces);
+}
+
int main(int argc, char** argv) {
int i;
bool noclear = false;
while(1) {
if(fread(&ch, 1, 1, stdin) <= 0) break;
if(ch == '\n') {
+ if(buf[0] == '.') {
+ if(__dw_strcaseequ(buf, ".bye") || __dw_strcaseequ(buf, ".quit")) {
+ printf("Bye.\n");
+ break;
+ } else if(__dw_strcaseequ(buf, ".version")) {
+ printf("DataWorks version %s %s %s\n", dataworks_get_version(), dataworks_get_compile_date(), dataworks_get_platform());
+ } else if(__dw_strcaseequ(buf, ".help")) {
+ padleft(16, ".help");
+ printf("Shows this help.\n");
+ padleft(16, ".bye .quit");
+ printf("Quits from the CLI.\n");
+ padleft(16, ".version");
+ printf("Shows the version of DataWorks.\n");
+ } else {
+ printf("Unknown dot-command.\n");
+ }
+ }
printf("%c ", prompt);
fflush(stdout);
free(buf);
.PHONY: all clean
.SUFFIXES: .c .o
-OBJS = parser.o dataworks.o
+OBJS = parser.o util.o dataworks.o
all: $(LIB_PREFIX)dataworks$(LIB_SUFFIX)
--- /dev/null
+/* $Id$ */
+/* --- START LICENSE --- */
+/* -------------------------------------------------------------------------- */
+/* Copyright (c) 2024 Nishi. */
+/* Redistribution and use in source and binary forms, with or without modific */
+/* ation, are permitted provided that the following conditions are met: */
+/* 1. Redistributions of source code must retain the above copyright noti */
+/* ce, this list of conditions and the following disclaimer. */
+/* 2. Redistributions in binary form must reproduce the above copyright n */
+/* otice, this list of conditions and the following disclaimer in the documen */
+/* tation and/or other materials provided with the distribution. */
+/* 3. Neither the name of the copyright holder nor the names of its contr */
+/* ibutors may be used to endorse or promote products derived from this softw */
+/* are without specific prior written permission. */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */
+/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */
+/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */
+/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */
+/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */
+/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */
+/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */
+/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */
+/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */
+/* OF SUCH DAMAGE. */
+/* -------------------------------------------------------------------------- */
+/* --- END LICENSE --- */
+
+#ifndef __DATAWORKS_DW_UTIL_H__
+#define __DATAWORKS_DW_UTIL_H__
+
+/**
+ * @file dw_util.h
+ * @~english
+ * @brief DataWorks utils
+ *
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdbool.h>
+
+bool __dw_strcaseequ(const char* a, const char* b);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+/* $Id$ */
+/* --- START LICENSE --- */
+/* -------------------------------------------------------------------------- */
+/* Copyright (c) 2024 Nishi. */
+/* Redistribution and use in source and binary forms, with or without modific */
+/* ation, are permitted provided that the following conditions are met: */
+/* 1. Redistributions of source code must retain the above copyright noti */
+/* ce, this list of conditions and the following disclaimer. */
+/* 2. Redistributions in binary form must reproduce the above copyright n */
+/* otice, this list of conditions and the following disclaimer in the documen */
+/* tation and/or other materials provided with the distribution. */
+/* 3. Neither the name of the copyright holder nor the names of its contr */
+/* ibutors may be used to endorse or promote products derived from this softw */
+/* are without specific prior written permission. */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */
+/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */
+/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */
+/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */
+/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */
+/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */
+/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */
+/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */
+/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */
+/* OF SUCH DAMAGE. */
+/* -------------------------------------------------------------------------- */
+/* --- END LICENSE --- */
+
+#include "dw_util.h"
+
+#include <ctype.h>
+#include <stdbool.h>
+#include <string.h>
+
+bool __dw_strcaseequ(const char* a, const char* b) {
+ if(strlen(a) != strlen(b)) return false;
+ int i;
+ for(i = 0; a[i] != 0; i++) {
+ if(tolower(a[i]) != tolower(b[i])) return false;
+ }
+ return true;
+}