diff --git a/Makefile b/Makefile index 5c7abdd..5fa4c99 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # (C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2) # Some changes and tweaks from Menchers -VERSION = \"0.5.0\" +VERSION = \"0.5.1\" VERSION_EXTRA = \"$(EXTRA)\" PREFIX ?= /usr diff --git a/Makefile.musl b/Makefile.musl index c3fc585..a2fd7b3 100644 --- a/Makefile.musl +++ b/Makefile.musl @@ -2,7 +2,7 @@ # (C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2) # Some changes and tweaks from Menchers -VERSION = \"0.5.0\" +VERSION = \"0.5.1\" VERSION_EXTRA = \"$(EXTRA)\" PREFIX ?= /usr diff --git a/README.txt b/README.txt index 57ac656..5bdb809 100644 --- a/README.txt +++ b/README.txt @@ -48,20 +48,18 @@ at this moment! * isdir "examples/" -> returns 0 for not, 1 for is * isfile "examples/functions.ss" -> returns 1, its there -* showdir (alias ls) function, example: - * showdir -> Lists current directory (ls does the same) - * showdir "/" -> lists '/' (ls "/" does the same) - -* mkdir and mkfile functions, example: - * mkfile "file.txt" -> creates empty 'file.txt' +* File manipulation functions + * move "file1" "file2" -> Renames/moves file1 to file2 (mv) + * chdir "/home/user" -> Changes directory to /home/user (cd) + * showpath -> Returns current working directory (pwd alias) + * showdir -> Lists current directory (ls alias) + * showdir "/" -> lists '/' + * mkfile "file.txt" -> creates empty 'file.txt' (touch alias) * mkdir "testing/" -> creates directory 'testing' * mkfile "testing/file.txt" -> creates directory 'testing', and creates 'file.txt' -* Delete example: - * delete "file.txt" - * Execute example: - * exec "ls -al" + * exec "ls -al" (alias to ~"ls -al") * Slidescript compression functions, example: * compress "archivename" "file1 file2 dir1 dir2" -> file1, 2, dir1, 2 archived, compressed, @@ -148,6 +146,11 @@ Changelog Changes between version bumps in SlideScript. Hoping to have a lightweight top-down scripting language by V1.0.0 release! From there it will be molding and preserving the art. +* V0.5.1 + * Compression and decompression bugfixes + * System working functions (move, chdir, and showpath) + * General clean, removed bins/ until language stabilizes + * V0.5.0 * Interactive mode gives users prompt on call to slidescript (Thanks OldCoder!) * Added showdir (alias ls) diff --git a/bins/slidescript.gcc-glibc-x86_64 b/bins/slidescript.gcc-glibc-x86_64 deleted file mode 100755 index ea624b7..0000000 Binary files a/bins/slidescript.gcc-glibc-x86_64 and /dev/null differ diff --git a/bins/slidescript.gcc-musl-x86_64 b/bins/slidescript.gcc-musl-x86_64 deleted file mode 100755 index 35e1443..0000000 Binary files a/bins/slidescript.gcc-musl-x86_64 and /dev/null differ diff --git a/bins/slidescript.llvm-glibc-aarch64 b/bins/slidescript.llvm-glibc-aarch64 deleted file mode 100755 index 8303f44..0000000 Binary files a/bins/slidescript.llvm-glibc-aarch64 and /dev/null differ diff --git a/bins/slidescript.tcc-glibc-x86_64 b/bins/slidescript.tcc-glibc-x86_64 deleted file mode 100755 index 49468f1..0000000 Binary files a/bins/slidescript.tcc-glibc-x86_64 and /dev/null differ diff --git a/bins/slidescript.tcc-musl-x86_64 b/bins/slidescript.tcc-musl-x86_64 deleted file mode 100755 index e0d8345..0000000 Binary files a/bins/slidescript.tcc-musl-x86_64 and /dev/null differ diff --git a/src/functions.c b/src/functions.c index 978f2ea..1cfcd0b 100644 --- a/src/functions.c +++ b/src/functions.c @@ -52,8 +52,108 @@ char *process_line(char *line) else if(strncmp("exit", tok_srch, 4) == 0) syn_error("ss:exit called"); + // Move files using rename() + else if(strncmp("move",tok_srch,4) == 0 || strncmp("mv", tok_srch, 2) == 0) + { + char orig_fn[MAX_STRING_BUFSIZE]; // Should never be more than 6 characters + tok_srch = strtok(NULL, "\""); + if(tok_srch == NULL) + { + syn_warn("ss:warn:move syntax error, missing quote?"); + return NULL; + } - else if(strncmp("showdir",tok_srch,7) == 0 || strncmp("ls", tok_srch,2) == 0) + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + { + syn_warn("ss:warn:move syntax error, missing filename?"); + return NULL; + } + + if(strlen(parse_vars(tok_srch)) < MAX_STRING_LEN) + { + strcpy(orig_fn, parse_vars(tok_srch)); + } + else + { + syn_warn("ss:warn:move syntax error, missing quote?"); + return NULL; + } + + /* strtok to the content that will be written to file */ + tok_srch = strtok(NULL, "\""); + if(tok_srch == NULL) + { + syn_warn("ss:warn:move syntax error, missing quote?"); + return NULL; + } + + + tok_srch = strtok(NULL, "\""); + if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) + { + syn_warn("ss:warn:move syntax error, missing quote?"); + return NULL; + } + + if(strtok(NULL, "\"") == NULL) + { + syn_warn("ss:warn:move syntax error, missing quote?"); + return NULL; + } + + int rename_return = rename(orig_fn, parse_vars(tok_srch)); + if(rename_return < 0) + { + syn_warn("ss:warn:move, failed to move file"); + } + + return NULL; + } + + + // Show current directory. + else if(strncmp("showpath", tok_srch, 8) == 0 || strncmp("pwd", tok_srch, 3) == 0) + { + // Get current directory, if it errors, return NULL + if (getcwd(retbuf, sizeof(retbuf)) == NULL) { + return NULL; + } + // All good, return path + return retbuf; + } + + // Change directory + else if(strncmp("chdir", tok_srch, 5) == 0 || strncmp("cd", tok_srch, 2) == 0) + { + char *dirname; + int chdir_return; + + tok_srch = strtok(NULL, "\""); + if(tok_srch == NULL) + { + syn_warn("ss:warn:chdir syntax error, missing quote?"); + return NULL; + } + + if(strtok(NULL, "\"") == NULL) + { + syn_warn("ss:warn:chdir syntax error, missing end quote?"); + return NULL; + } + + dirname = parse_vars(tok_srch); + + chdir_return = chdir(dirname); + + if(chdir_return < 0) + { + syn_warn("ss:warn:chdir, error changing directory"); + } + return NULL; + } + + + else if(strncmp("showdir", tok_srch, 7) == 0 || strncmp("ls", tok_srch, 2) == 0) { char *dirname;