Call this v0.4.4
This commit is contained in:
parent
2ba8a35f5f
commit
3f25d81908
2
Makefile
2
Makefile
@ -2,7 +2,7 @@
|
||||
# (C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2)
|
||||
# Some changes and tweaks from Menchers
|
||||
|
||||
VERSION = \"0.4.0\"
|
||||
VERSION = \"0.4.4\"
|
||||
VERSION_EXTRA = \"$(EXTRA)\"
|
||||
|
||||
PREFIX ?= /usr
|
||||
|
63
README.txt
63
README.txt
@ -22,49 +22,61 @@ Here is a list of functions and features that SlideScript comes with
|
||||
at this moment!
|
||||
|
||||
* Commenting! Examples:
|
||||
* `# Comment is real in this one`
|
||||
* # Comment is real in this one
|
||||
|
||||
* Read and writing to flat files. Examples:
|
||||
* `write "file.txt" "This will be written to file.txt"`
|
||||
* `read "file.txt"`
|
||||
* 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!
|
||||
* calc "45 / 5"` or `calc "255.3 * 442.77"
|
||||
* Of course addition and subtraction as well
|
||||
|
||||
* Time example:
|
||||
* time
|
||||
|
||||
* Isdir function, example:
|
||||
* isdir "examples/" -> returns 0 for not, 1 for is
|
||||
|
||||
* Delete example:
|
||||
* `delete "file.txt"`
|
||||
* delete "file.txt"
|
||||
|
||||
* Execute example:
|
||||
* `exec "ls -al"`
|
||||
* exec "ls -al"
|
||||
|
||||
* Print example:
|
||||
* `print "Hi everyone!"`
|
||||
* print "Hi everyone!"
|
||||
|
||||
* Sleep (Zzz) example (sleeps for 2 seconds):
|
||||
* `sleep 2`
|
||||
* sleep 2
|
||||
|
||||
* 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.
|
||||
* 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
|
||||
* `encrypt "Regular string"` -> Converts to encrypted string 'Uhjvqds#xuulqj'
|
||||
* `decrypt "Uhjvqds#xuulqj"` -> Converts back to 'Regular string'
|
||||
* 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
|
||||
* 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
|
||||
* md5 "file.txt" | encrypt "%PIPE" | write "file.txt.md5.enc" "%PIPE%" -> writes output of md5 to file.txt.md5
|
||||
|
||||
* Networking functions
|
||||
* `netlisten "<port>" "<search>" "<respond>"` -> listens on <port> and replies <respond> on <search> found from outside
|
||||
* `nettoss "<address>" "<port>" "<data>"` -> binds to outside server at <address>:<port> and pushes <data> thus, disconnecting
|
||||
* `nethttp "<port>" "<forkval>"` -> throws up a web server on <port> in the current working directory,
|
||||
* netlisten "<port>" "<search>" "<respond>" -> listens on <port> and replies <respond> on <search> found from outside
|
||||
* nettoss "<address>" "<port>" "<data>" -> binds to outside server at <address>:<port> and pushes <data> thus, disconnecting
|
||||
* nethttp "<port>" "<forkval>" -> throws up a web server on <port> 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/'
|
||||
|
||||
@ -92,7 +104,8 @@ Done
|
||||
|
||||
List of finished features, in a rough summary.
|
||||
|
||||
* Simple syntax checking and error reporting
|
||||
* 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
|
||||
@ -109,6 +122,14 @@ 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.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
|
||||
|
1
examples/file.txt
Normal file
1
examples/file.txt
Normal file
@ -0,0 +1 @@
|
||||
hi1
|
@ -1,6 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
<h2>SlideScript</h2>
|
||||
<p>This is an index page hosted by the built in SS HTTP server</p>
|
||||
</body>
|
||||
</html>
|
@ -1,20 +0,0 @@
|
||||
#!/usr/bin/slidescript
|
||||
# SlideScript example, start a disposable http server
|
||||
#
|
||||
# Function nethttp "<portvalue>" "<forkvalue>"
|
||||
# fork values:
|
||||
# * 0 = do not fork to background
|
||||
# * 1 = fork to background
|
||||
|
||||
# Daemonize port
|
||||
port1=8081
|
||||
# Forground port
|
||||
port2=8080
|
||||
|
||||
# Daemonize, run in background
|
||||
#nethttp "%port1%" "1"
|
||||
|
||||
# Run in foreground, Ctrl-C to exit ;)
|
||||
nethttp "%port1%" "0"
|
||||
|
||||
print "Server on %port1% still running in the background"
|
25
examples/webserver.ss
Executable file
25
examples/webserver.ss
Executable file
@ -0,0 +1,25 @@
|
||||
#!/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=<!DOCTYPE html><html><head><title>SlideScript ~ Web server</title></head>
|
||||
head=<body><h3>SlideScript - disposible web server index page</h3>
|
||||
content=<p>There's not much to see here yet, more to come!</p>
|
||||
footer=<br /><center>powered by ss:http</center></body></html>
|
||||
|
||||
# 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"
|
141
src/functions.c
141
src/functions.c
@ -50,6 +50,34 @@ char *process_line(char *line)
|
||||
return strip_nl(parsed);
|
||||
}
|
||||
|
||||
/* print function */
|
||||
else if(strncmp("isdir",tok_srch,5) == 0)
|
||||
{
|
||||
int parsed;
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
if(tok_srch == NULL)
|
||||
{
|
||||
syn_warn("ss:warn:isdir syntax error, missing quote?");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(strtok(NULL, "\"")==NULL)
|
||||
{
|
||||
syn_warn("ss:warn:isdir syntax error, missing end quote?");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
parsed = is_dir(parse_vars(tok_srch));
|
||||
if(parsed == 1)
|
||||
{
|
||||
return "1";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
/* print function */
|
||||
else if(strncmp("print",tok_srch,5) == 0)
|
||||
{
|
||||
@ -500,6 +528,7 @@ char *process_line(char *line)
|
||||
/* strtok to filename of function */
|
||||
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
if(tok_srch == NULL)
|
||||
{
|
||||
syn_warn("ss:warn:write syntax error, missing quote?");
|
||||
return NULL;
|
||||
@ -518,7 +547,7 @@ char *process_line(char *line)
|
||||
/* Check if file exists and can be opened */
|
||||
if(write_file == NULL)
|
||||
{
|
||||
syn_warn("ss:warn:write syntax error, missing quote?");
|
||||
syn_warn("ss:warn:write, failed to open file");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -546,7 +575,7 @@ char *process_line(char *line)
|
||||
|
||||
if(strtok(NULL, "\"") == NULL)
|
||||
{
|
||||
syn_warn("ss:warn:write syntax error, missing quote?");
|
||||
syn_warn("ss:warn:write syntax error, missing end quote?");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -613,25 +642,123 @@ char *process_line(char *line)
|
||||
|
||||
if(read_size <= MAX_READFILE_LEN)
|
||||
{
|
||||
// Copy string to end of file, rewrite file
|
||||
sprintf(filebuf, "%s", dynfile);
|
||||
free(dynfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(read_file);
|
||||
free(dynfile);
|
||||
fclose(read_file);
|
||||
syn_warn("ss:warn:write, file too large (2MB max)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
fclose(read_file);
|
||||
|
||||
// For now print to test //
|
||||
free(dynfile);
|
||||
|
||||
return strip_nl(filebuf);
|
||||
} /* read function */
|
||||
|
||||
/* Cat function, writes to end of file specified */
|
||||
else if(strncmp("cat",tok_srch,3) == 0)
|
||||
{
|
||||
unsigned long read_size;
|
||||
char read_line[1024];
|
||||
char filename[2048+1], *dynfile;
|
||||
FILE *read_file = NULL;
|
||||
|
||||
/* strtok to filename of function */
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
if(tok_srch == NULL)
|
||||
{
|
||||
syn_warn("ss:warn:cat syntax error, missing quote?");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0)
|
||||
{
|
||||
syn_warn("ss:warn:cat syntax error, missing filename?");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(strlen(parse_vars(tok_srch)) < 2048)
|
||||
{
|
||||
strcpy(filename, parse_vars(tok_srch));
|
||||
}
|
||||
else
|
||||
{
|
||||
syn_warn("ss:warn:cat, filename too long");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// WERE LOADING FILES INTO MEMORY NOW!
|
||||
/* open file */
|
||||
read_file = fopen(filename, "r");
|
||||
|
||||
/* strtok to the content that will be written to file */
|
||||
if(read_file == NULL)
|
||||
{
|
||||
syn_warn("ss:warn:cat, failed to open file");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
if(tok_srch == NULL)
|
||||
{
|
||||
syn_warn("ss:warn:cat syntax error, missing quote?");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
if(tok_srch == NULL)
|
||||
{
|
||||
syn_warn("ss:warn:cat syntax error, missing quote?");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0)
|
||||
{
|
||||
syn_warn("ss:warn:cat syntax error, missing write data?");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(strtok(NULL, "\"") == NULL)
|
||||
{
|
||||
syn_warn("ss:warn:cat syntax error, missing end quote?");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fseek(read_file, 0L, SEEK_END);
|
||||
read_size = ftell(read_file);
|
||||
rewind(read_file);
|
||||
|
||||
dynfile = (char *)malloc(read_size + 1);
|
||||
|
||||
while(fgets(read_line, sizeof(read_line), read_file) != NULL)
|
||||
{
|
||||
strcat(dynfile, read_line);
|
||||
}
|
||||
|
||||
fclose(read_file);
|
||||
|
||||
if((read_size + strlen(parse_vars(tok_srch))) <= MAX_READFILE_LEN)
|
||||
{
|
||||
read_file = fopen(filename, "w");
|
||||
sprintf(filebuf, "%s%s", dynfile, parse_vars(tok_srch));
|
||||
fprintf(read_file, "%s", filebuf);
|
||||
free(dynfile);
|
||||
fclose(read_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(dynfile);
|
||||
syn_warn("ss:warn:cat, file too large (2MB max)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
} /* cat function */
|
||||
|
||||
else if(strncmp("delete", tok_srch, 6) == 0) {
|
||||
char *del_filename;
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
|
14
src/vars.c
14
src/vars.c
@ -82,17 +82,25 @@ char *parse_vars(char *string)
|
||||
variable_pointer[-1] = NULLBYTE;
|
||||
|
||||
if(*varbuffer == NULLBYTE)
|
||||
syn_error("ss:error:variable syntax error!");
|
||||
{
|
||||
syn_warn("ss:warning:variable syntax error!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
variable_pointer = get_var_data(varbuffer);
|
||||
if(variable_pointer == NULL)
|
||||
syn_error("ss:error:variable syntax error!");
|
||||
{
|
||||
syn_error("ss:error:variable data not found, abort!");
|
||||
}
|
||||
|
||||
var_len = strlen(variable_pointer);
|
||||
buf_len = strlen(finished) + var_len;
|
||||
|
||||
if(buf_len > MAX_STRING_LEN)
|
||||
syn_error("ss:error:string buffer overflow!");
|
||||
{
|
||||
syn_warn("ss:error:variable data too long, abort!");
|
||||
}
|
||||
|
||||
|
||||
strcat (finished, variable_pointer);
|
||||
output_pointer += var_len;
|
||||
|
Loading…
x
Reference in New Issue
Block a user