From: nishi Date: Thu, 16 May 2024 15:56:44 +0000 (+0000) Subject: add .help X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=0118bfffab8e5e9c244530e3ef03aa5057555950;p=dataworks.git add .help git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@7 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Client/main.c b/Client/main.c index 316d38b..213184e 100644 --- a/Client/main.c +++ b/Client/main.c @@ -27,6 +27,7 @@ /* --- END LICENSE --- */ #include +#include #include #include @@ -38,6 +39,15 @@ 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; @@ -83,6 +93,23 @@ int main(int argc, char** argv) { 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); diff --git a/Library/Makefile b/Library/Makefile index 64338c4..390ab50 100644 --- a/Library/Makefile +++ b/Library/Makefile @@ -3,7 +3,7 @@ .PHONY: all clean .SUFFIXES: .c .o -OBJS = parser.o dataworks.o +OBJS = parser.o util.o dataworks.o all: $(LIB_PREFIX)dataworks$(LIB_SUFFIX) diff --git a/Library/dw_util.h b/Library/dw_util.h new file mode 100644 index 0000000..0b5d689 --- /dev/null +++ b/Library/dw_util.h @@ -0,0 +1,51 @@ +/* $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 + +bool __dw_strcaseequ(const char* a, const char* b); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Library/util.c b/Library/util.c new file mode 100644 index 0000000..dddb91c --- /dev/null +++ b/Library/util.c @@ -0,0 +1,42 @@ +/* $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 +#include +#include + +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; +}