From 10d663ecd9a84f330c617185696f350bf12bad58 Mon Sep 17 00:00:00 2001 From: Pentium44 Date: Sun, 9 May 2021 17:48:26 -0700 Subject: [PATCH] God dammit --- docs/README.txt | 231 ------------------------------------ docs/examples/functions.ss | 97 --------------- docs/examples/net-listen.ss | 7 -- docs/examples/net-toss.ss | 13 -- docs/examples/webserver.ss | 25 ---- src/inc/deps.h | 6 +- src/inc/inset.h | 3 - src/inset.c | 4 +- src/lexer.c | 4 +- src/main.c | 4 +- src/vars.c | 12 +- 11 files changed, 18 insertions(+), 388 deletions(-) delete mode 100755 docs/README.txt delete mode 100755 docs/examples/functions.ss delete mode 100755 docs/examples/net-listen.ss delete mode 100755 docs/examples/net-toss.ss delete mode 100755 docs/examples/webserver.ss diff --git a/docs/README.txt b/docs/README.txt deleted file mode 100755 index ea33076..0000000 --- a/docs/README.txt +++ /dev/null @@ -1,231 +0,0 @@ -====== -=== SlideScript -====== -A simple, user friendly scripting language for the average person. SS is meant to -be simple, and work as its documented as. SlideScript is a bin tool to say the -least and is a helpful *nix userland tool in the CLI - ------ -Compiling ------ -* Compile SS using the make command. -* Install SS using make install. -* Modify test.ss to learn the basics of SS. -* Run ./test.ss to execute the script. - -***NOTE: if compiling on OSX/BSD, please uncomment #define BSD in src/config.h*** - ------ -Directory bins/ ------ - -Since slidescript is so small, I made a collection of current builds of slidescript -in bins/* -These are built on Debian 10 using GCC 9.2.0, and current TCC. - ------ -Documentation ------ -Here is a list of functions and features that SlideScript comes with -at this moment! - -* Commenting! Examples: - * # Comment is real in this one - -* Comp and loop functions: - * comp: "1" "1" -> compares integer 1 and 1 -> returns true - * comp: "true" "false" -> compares string true and false -> returns false - * loop: 3; print "Hello world!" -> Will loop print "Hello world!" 3 times. - -* Read, write, and cat(enate) functions. Examples: - * write "file.txt" "This will be written to file.txt" - * read "file.txt" - * cat "file.txt" "Data to write to end of file.txt" - -* Basic math expressions - * calc "45 / 5"` or `calc "255.3 * 442.77" - * Of course addition and subtraction as well - -* Time example: - * time - -* Isdir and isfile function, example: - * isdir "examples/" -> returns 0 for not, 1 for is - * isfile "examples/functions.ss" -> returns 1, its there - -* File manipulation functions - * move "file1" "file2" -> Renames/moves file1 to file2 (mv) - * chdir "/home/user" -> Changes directory to /home/user (cd) - * backdir -> Moves you back one directory (..) - * 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' - -* Execute example: - * exec "ls -al" (alias to ~"ls -al") - -* Slidescript compression functions, example: - * compress "archivename" "file1 file2 dir1 dir2" -> file1, 2, dir1, 2 archived, compressed, - and saved in in 'archivename.tar.ss' - * decompress "archivename.tar.ss" -> decompresses 'archivename.tar.ss' - -* Print example: - * print "Hi everyone!" - -* Sleep (Zzz) example (sleeps for 2 seconds): - * sleep 2 - -* Search functions, example: - * search "README.txt" "SlideScript" -> returns each line that 'SlideScript' is found on - -* Variable setting and passing - * filename=file.txt -> filename - * filedata=File '%filename%' is being moved to moo -> %filename% is populated as file.txt - * write "%filename%" "%filedata%" -> writes filedata contents to file.txt as expected. - -* Decoding and encoding strings - * encode "Regular string" -> Converts to encrypted string 'Uhjvqds#xuulqj' - * decode "Uhjvqds#xuulqj" -> Converts back to 'Regular string' - -* MD5 file checking - * md5 "file.txt" -> outputs filename and md5 hash - -* Layered piping - * md5 "file.txt" | encrypt "%PIPE" | write "file.txt.md5.enc" "%PIPE%" -> writes output of md5 to file.txt.md5 - -* Networking functions - * netlisten "" "" "" -> listens on and replies on found from outside - * nettoss "
" "" "" -> binds to outside server at
: and pushes thus, disconnecting - * nethttp "" "" -> throws up a web server on in the current working directory, - forkval (0 or 1, 0 don't fork into background / 1 do). - -* Backquoted function parsing within variables - * curtime=`time` -> Will set curtime value to return of time at the time of parse. - print "%curtime%" -> Prints the variable value of curtime, same operation as function time, but good for timing scripts - - -This will change rapidly as of currently, slidescript is in beavy development! To get the feel of the scripting, -the best bet is to take a look at some of the slidescript examples in 'examples/' - -functions.ss -> displays most basic functions -net-http.ss -> displays built in http web server -net-listen.ss -> displays slidescript's raw listen socket -net-toss.ss -> displays the 'client side' networking function. - - ------ -Todo list ------ - -This section will obviously expand and adapt to the direction of the language. This is going to change rapidly. - -* Add in-script functions -* Add script including -* Loops, and if statements -* More networking function flexibility -* File pull / file push functionality - ------ -Done ------ - -List of finished features, in a rough summary. - -* Added help, and version functions -* Simple syntax checking and error reporting, its a lazy language, syntax can sway. -* Most syntax errors will produce warnings instead of terminating process -* Up to 32 layer function piping -* Support for linux system calls -* Network listen socket, toss function -* Builtin HTTP server for disposeable use, can be ran in the foreground or forked into the background -* Read and write from file -* Some simple functions -* Shebang handling -* Variable support - ------ -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.4 - * Added memory management framework for dynamic memory handling - * tar.c cleanup - * fflush additions for telnet usage of SS. - -* V0.5.3 - * Added version, and help command - -* V0.5.2 - * Bugfixes and tweaks - * Added loop and comp(are) statements - -* 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) - * Added compress / decompress functions (WIP, slow LZ77 algorithm) - * Multiple bug fixes - * Shell like interactive behavior - -* V0.4.5 - * Multiple bug fixes in not setting null byte to dynamic mem before strcat is used - * Function isfile, as well as mkfile and mkdir are added - * Added grep like function, search! - * Cleanup code - -* V0.4.4 - * Softened the kill program errors, added warn functions behind the scenes - * Added backquote function processing in variables - * Fixed bug in read not displaying multi-line files - * Fixed bug in write not finding first quote syntax - * Added function isdir, and cat(enate) function. NOT cat as in linux env. - * Code clean-up - -* V0.4.0 - * Added calc function for floating math equations - * Cleaned up some more syntax handling, as well as bugs - * Added structured and savable multi-layer piping up to 32 functions deep - -* V0.3.3 - * Added first networking functions: netlisten, nettoss, nethttp. - * Embedded web server functionality - * Cleaned up code - * Improved syntax handling on functions - -* V0.3.0 - * Added simple 2 layer function piping for more useful tasks - * Fixed a couple core dump bugs - * Now reads files into memory, and then forces text files through SS, allows for in file variables - * Added "md5" functionality - * Multi-formal working syntax - -* V0.2.1 - * Added "decrypt" decode function - * Added "encrypt" encode function - * Added system "exec" function - * Added basic syntax handling, for a more uniform language - -* V0.2.0 - * Added "delete" function - * Added embedded variable handling to SS functions (variables can be used like everywhere!) - * Added linux system calls via exec - * Some cleaning up. - -* V0.1.1 - * Added variable handling with a buffer size of 2KB per variable, and cap of 2048 variables. - * Now operates under the shebang! - ------ -Contributions ------ -Robert (OldCoder) Kiraly -> shebang support and string manipulations -(C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2) diff --git a/docs/examples/functions.ss b/docs/examples/functions.ss deleted file mode 100755 index a1f63b7..0000000 --- a/docs/examples/functions.ss +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/slidescript -############################################################# -#### Welcome to the world of SlideScript! #### -#### This script is here for the learning purposes of SS #### -#### Any line starting with a hashtag will treated as a #### -#### comment! #### -############################################################# - -# Slide Script, also refered to as SS, is extremely forgiving in -# syntax handling! -# Example: -# print "content" -# print "content"; -# print("content") -# print("content"); -### -### These will operate properly, as well as: -# Example: -# write "filename.txt" "data" -# write "filename.txt" "data"; -# write("filename.txt" "data"); -# write("filename.txt", "data"); -# -# IT ALL WORKS! -# SlideScript really syntaxes based on quotes and key function words, -# as well as pipes. It really doesn't mind whats around it otherwise -# And every variable is called by %varname%, defining variables, as normal - -# Variables in SS -ss_filename=file.txt -ss_stringdata=Data to encrypt and decrypt -ss_exec_command=uname -a - -# Printing function in SS -print "Welcome to SlideScript!" -# Sleep function in SS -print "Some content to print, working with '%ss_filename%' today!" -# Below demonstrates SS encrypting a string, passing the output -# over a pipe, and using the write function and %PIPE% variable -# holding the first functions output, writes to %ss_filename%; file.txt -### %PIPE% is the output from the first line function, enc -### %PIPE% is always applied when a pipe is used! -encode "%ss_stringdata%" | write "%ss_filename%" "%PIPE%" -# You're left with file.txt, lets move on - -# Lets read the file we just created and show how SS handles its -# own decryption algorithm -read "%ss_filename%" | decrypt "%PIPE%" -# Will display the original variable string! - -# SS MD5 function -# Lets get the md5sum of file.txt with our md5 function -md5 "%ss_filename%" | write "%ss_filename%.md5" "%PIPE%" -# Use a pipe, and push the md5 into a text file of file.txt - -# You can also stack pipes for whatever tasks you may need -# Here's the encrypt function in action, can also be used as encode -md5 "%ss_filename%" | encode "%PIPE%" | write "%ss_filename%.md5.enc" "%PIPE%" - -# Read md5 file -print "%ss_filename%.md5:" -read "%ss_filename%.md5" - -# Read encrypted md5 file and decrypt using decode alias -print "%ss_filename%.md5.enc:" -read "%ss_filename%.md5.enc" | decode "%PIPE%" - -# Delete function, SS can delete files and directories with one function -# NOTE: it is extremely powerful and can wreck your system if used in the -# wrong way! Proceed with caution, delete "/" WILL send your files to the -# grave. -### -# Lets delete the files we've been messing with, no system calls needed -delete "%ss_filename%" -delete "%ss_filename%.md5" -delete "%ss_filename%.md5.enc" -# Gone! - -print "Playing with some calc..." -# calc function, lets do some basic math -calc "32 * 1024" -# You can pipe calc to do multi layer equations -calc "32 * 1024" | calc "%PIPE% * 2" - -# Lets play with some big numbers here! -# SlideScript parses its calc functions using floating points, so you can -# handle decimal as well -calc "1024 * 1024" | calc "%PIPE% * %PIPE%" - -# Decimal -print "Here comes the decimal:" -calc "46 / 3.4" - -# Execute function, SS can call unix system calls! -# Executes the ss_exec_command variable data, 'ls' -print "Testing exec function on system" -exec "%ss_exec_command%" diff --git a/docs/examples/net-listen.ss b/docs/examples/net-listen.ss deleted file mode 100755 index e9adbbd..0000000 --- a/docs/examples/net-listen.ss +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/slidescript - -port=2020 -search=hi -respond=bye - -netlisten "%port%" "%search%" "%respond%" diff --git a/docs/examples/net-toss.ss b/docs/examples/net-toss.ss deleted file mode 100755 index 59b9ba5..0000000 --- a/docs/examples/net-toss.ss +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/slidescript - -address=127.0.0.1 -port=2020 -data1=This data is gonna be pushed to the server side host! -data2=Here's the second set of data getting tossed to the server -data3=Of course, do a little more considering the transfer is instant! - -nettoss "%address%" "%port%" "%data1%" -nettoss "%address%" "%port%" "%data2%" -encode "%data3%" | nettoss "%address%" "%port%" "%PIPE%" - -nettoss "%address%" "%port%" "hi" diff --git a/docs/examples/webserver.ss b/docs/examples/webserver.ss deleted file mode 100755 index 2bbfc23..0000000 --- a/docs/examples/webserver.ss +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/slidescript -# Generate an index.html example for the built-in HTTP daemon example -# This will be used as a disposible web server! - -# First, lets populate some data for the web server itself, this script -# will generate the index.html for the web server before launch. - -# Variables of the contents for index.html -header=SlideScript ~ Web server -head=

SlideScript - disposible web server index page

-content=

There's not much to see here yet, more to come!

-footer=
powered by ss:http
- -# Webserver port -port=8080 - -# Filename in a variable -filename=index.html - -# Writing the variable data to the file -write "%filename%" "%header%%head%%content%%footer%" - -# Starting web server in the foreground, change 0 to 1 to fork to background -print "Ctrl-C to kill me!" -nethttp "%port%" "0" diff --git a/src/inc/deps.h b/src/inc/deps.h index 5d9d8f4..3c5b00c 100644 --- a/src/inc/deps.h +++ b/src/inc/deps.h @@ -66,15 +66,17 @@ #define MAX_FILENAME_LEN 1024 #define MAX_FILENAME_BUFSIZE (MAX_FILENAME_LEN + 1) #define MAX_FILES 1024 +// Inset backquote buffers +#define MAX_BQ_FUNCTIONS 128 // END #define TOKEN '%' #define TOKEN_STR "%" #define TOKEN_BQ '`' #define NULLBYTE '\0' #define NEWLINE '\n' -#define ENCOFFSET 3 +#define ENCOFFSET 80 #define ENCSTEPODD 2 -#define ENCSTEPEVEN 2 +#define ENCSTEPEVEN 3 // HELP PRINTOUT diff --git a/src/inc/inset.h b/src/inc/inset.h index 91ee218..9c5d9b9 100644 --- a/src/inc/inset.h +++ b/src/inc/inset.h @@ -7,9 +7,6 @@ #include "x3mem.h" -// Inset backquote buffers -#define MAX_BQ_FUNCTIONS 128 - struct s_bq { char *function; diff --git a/src/inset.c b/src/inset.c index b59163e..9f3fbf5 100644 --- a/src/inset.c +++ b/src/inset.c @@ -23,7 +23,7 @@ void s_inset(int index, char *function) int get_bq_count() { int yy; - for(yy = 0; yy < MAXVARS; yy++) + for(yy = 0; yy < MAX_BQ_FUNCTIONS; yy++) { if(s_bqf[yy].function != NULL) { @@ -79,7 +79,7 @@ char *parse_bq(char *string) strcat (varbuffer, "\n"); variable_pointer = process_line(varbuffer); - tar_free_pool(); + //tar_free_pool(); if(variable_pointer == NULL) syn_error("ss:error:backquoted function must return string!"); diff --git a/src/lexer.c b/src/lexer.c index 3a854c7..b9634a0 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1487,10 +1487,10 @@ char *process_line(char *line) tok_srch = strtok(NULL, "="); // Check for back quotes, return string with backquotes processed - bq_check = strip_nl(parse_bq(parse_vars(tok_srch))); + bq_check = strip_nl(parse_vars(parse_bq(tok_srch))); // Don't check if variable is blank, if so let it fly! set_var(varc, varname_tmp, bq_check); - /* printf("ss: var '%s' -> %s", varname_tmp, get_var_data(varname_tmp)); */ + printf("ss: var '%s' -> %s\n", varname_tmp, get_var_data(varname_tmp)); } } diff --git a/src/main.c b/src/main.c index 0c1b46d..03a417a 100644 --- a/src/main.c +++ b/src/main.c @@ -82,12 +82,12 @@ int main(int argc, char **argv) return_dat = process_line(spipe[ii].command); tar_free_pool(); - // set PIPE var back to NULL after use, keep the struct clean set_var(varc, "\0", "\0"); + // Check to see if there's anything to even display if(return_dat == NULL) { - break; + continue; } } } diff --git a/src/vars.c b/src/vars.c index 790aea2..8fc9aca 100644 --- a/src/vars.c +++ b/src/vars.c @@ -63,7 +63,8 @@ char *parse_vars(char *string) char *output_pointer; char *variable_pointer; - finished = qmalloc(QM_VARIABLES, (strlen(string) + 1)); + //finished = qmalloc(QM_VARIABLES, (strlen(string) + 1)); + finished = qmalloc(QM_VARIABLES, 16280); *finished = NULLBYTE; @@ -94,19 +95,22 @@ char *parse_vars(char *string) } variable_pointer = get_var_data(varbuffer); - printf("%s\n", variable_pointer); + printf("Variable: %s, data: %s, full string: %s\n", varbuffer, variable_pointer, string); if(variable_pointer == NULL) { x_error("ss:error:variable data not found, abort!"); } + if(*input_pointer == NULLBYTE) break; + var_len = strlen(variable_pointer); - qrealloc(finished, (var_len + 1)); + chk_qm0(finished); + + //qrealloc(finished, (strlen(finished) + var_len + 1)); strcat (finished, variable_pointer); output_pointer += var_len; - if(*input_pointer == NULLBYTE) break; } *output_pointer = NULLBYTE;