Call this v0.4.0

This commit is contained in:
Pentium44 2021-04-08 02:19:12 -07:00
parent 81e2495aba
commit 8608bf2392
13 changed files with 270 additions and 63 deletions

View File

@ -2,7 +2,7 @@
# (C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2)
# Some changes and tweaks from Menchers
VERSION = \"0.3.3\"
VERSION = \"0.4.0\"
VERSION_EXTRA = \"$(EXTRA)\"
PREFIX ?= /usr
@ -13,7 +13,7 @@ CPPFLAGS += -DVERSION=$(VERSION) -D_FORTIFY_SOURCE=2
LDFLAGS += -Wl,-O1,--sort-common,--hash-style=gnu,-z,relro
BIN ?= slidescript
OBJECTS = src/main.o src/functions.o src/util.o src/vars.o src/enc.o src/md5.o src/pipe.o src/network.o
OBJECTS = src/main.o src/functions.o src/util.o src/vars.o src/enc.o src/md5.o src/pipe.o src/network.o src/math.o
all: main

View File

@ -10,6 +10,7 @@ Using SlideScript
* 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***
Documentation
@ -24,6 +25,10 @@ at this moment!
* `write "file.txt" "This will be written to file.txt"`
* `read "file.txt"`
* Basic math expressions
* `calc "45 / 5"` or `calc "255.3 * 442.77"`
* Of course addition and subtraction as well!
* Delete example:
* `delete "file.txt"`
@ -48,8 +53,8 @@ at this moment!
* MD5 file checking
* `md5 "file.txt"` -> outputs filename and md5 hash
* 2 Layer piping
* `md5 "file.txt" | write "file.txt.md5" "%PIPE%"` -> writes output of md5 to file.txt.md5
* Layered piping
* `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
@ -57,19 +62,24 @@ at this moment!
* `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).
This will change rapidly as of currently, slidescript is in beavy development!
Todo list
-----
* Add in-script functions
* New static functions
* Loops, and if statements
Done
-----
* Simple syntax checking and error reporting
* 2 layer function piping
* 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
@ -78,19 +88,27 @@ Done
* Shebang handling
* Variable support
Changelog
-----
* 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

View File

@ -1,6 +1,6 @@
#!/usr/bin/slidescript
port=2001
port=2020
search=hi
respond=bye

View File

@ -1,13 +1,13 @@
#!/usr/bin/slidescript
address=127.0.0.1
port=2001
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%"
nettoss "%address%" "%port%" "%data3%"
encode "%data3%" | nettoss "%address%" "%port%" "%PIPE%"
nettoss "%address%" "%port%" "hi"

View File

@ -9,9 +9,13 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <regex.h>
#include <limits.h>
#include <stddef.h>
#include "config.h"
#include "sbyteswap.h"
#include <sys/types.h>
@ -26,7 +30,9 @@
#define MAX_STRING_LEN 4096
#define MAX_STRING_BUFSIZE (MAX_STRING_LEN + 1)
#define MAX_VAR_DATA_LEN 65536
#define MAX_DATA_BUFSIZE (MAX_VAR_DATA_LEN + 1)
#define MAXVARS 1488
#define MAX_PIPE_CMDS 32
#define MAX_CONCAT_BUF 131072
#define MAX_READFILE_LEN 2097152
// for networking functions
@ -36,6 +42,9 @@
#define MAX_NETSRCH_BUF (MAX_NETSRCH_LEN + 1)
#define MAX_NETRESP_LEN 65536
#define MAX_NETRESP_BUF (MAX_NETRESP_BUF + 1)
// For Expr
#define MAX_EXPR_ARGS 128
#define MAX_EXPR_LEN 512
// END
#define TOKEN '%'
#define TOKEN_STR "%"

View File

@ -10,6 +10,7 @@
#include "util.h"
#include "vars.h"
#include "enc.h"
#include "math.h"
#include "md5.h"
#include "network.h"
@ -37,6 +38,15 @@ char *process_line(char *line)
if(strncmp("exit", tok_srch, 4) == 0)
syn_error("ss:exit called");
/* time function */
/* print function */
else if(strncmp("time",tok_srch,4) == 0)
{
char *parsed;
parsed = ss_time();
return strip_nl(parsed);
}
/* print function */
else if(strncmp("print",tok_srch,5) == 0)
{
@ -78,6 +88,25 @@ char *process_line(char *line)
return NULL;
}
// Calc function, some math involved! //
else if(strncmp("calc",tok_srch,5) == 0)
{
char *expr_return;
tok_srch = strtok(NULL, "\"");
if(tok_srch == NULL)
syn_error("ss:error:calc syntax error, missing quotes around equation?");
if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0)
syn_error("ss:error:calc syntax error, missing quotes around equation?");
if(strtok(NULL, "\"") == NULL)
syn_error("ss:error:calc missing end quote");
expr_return = ss_expr(tok_srch);
return expr_return;
}
/* Networking, listen */
else if(strncmp("netlisten",tok_srch,9) == 0)
{

View File

@ -41,34 +41,36 @@ int main(int argc, char **argv)
/* parse each line from the script in order. */
while(fgets(script_line, sizeof(script_line), script) != NULL)
{
char *return_dat, *pipechk, *return_pipe_dat;
pipechk = ss_piping(script_line);
char *return_dat;
int pipechk;
ss_piping(script_line);
return_dat = process_line(script_line);
pipechk = get_cmd_count();
return_dat = process_line(spipe[0].command);
// Blank line, getting up outta here.
if(return_dat == NULL) continue;
if(pipechk != NULL)
{
int varc;
int varc, ii;
varc = get_var_count();
if(pipechk > 1)
{
for(ii = 1; ii < pipechk; ii++)
{
set_var(varc, "PIPE", return_dat);
// Process functions based on previous pipe return
return_pipe_dat = process_line(pipechk);
return_dat = process_line(spipe[ii].command);
// 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_pipe_dat == NULL) continue;
if(return_dat == NULL) break;
}
}
// Print the pipe line
printf("%s\n", return_pipe_dat);
}
else
{
// If return is not null, and no pipe; provide the return
if(return_dat != NULL)
printf("%s\n", return_dat);
}
} /* end of while */
} /* file null */

90
src/math.c Normal file
View File

@ -0,0 +1,90 @@
// expr.c, from suckless sbase.
#include "deps.h"
#include "math.h"
#include "util.h"
static char expr_out[(MAX_EXPR_LEN*2)+1];
int get_expr_count()
{
int yy;
for(yy = 0; yy < MAX_EXPR_ARGS; yy++)
{
if(strlen(sexpr[yy].arg) > 0)
{
continue;
}
else
{
return yy;
}
}
return 0;
}
void set_expr_arg(int index, char *arg)
{
strcpy(sexpr[index].arg, arg);
}
// Main expr function
char *ss_expr(char *string)
{
char *expr_tok, *f_end, *s_end, *calc_operator;
int expr_argc, n;
float first, second, finalf;
expr_tok = strtok(string, " ");
if(expr_tok == NULL)
syn_error("ss:error:calc missing equation");
// Clear arguments from previous calculations.
for(int ff = 0; ff < MAX_EXPR_ARGS; ff++) bzero(sexpr[ff].arg, MAX_EXPR_LEN);
// Set initial argument
set_expr_arg(0, expr_tok);
// Write new arguments
n = 1;
while((expr_tok = strtok(NULL, " ")) != NULL)
{
if(n > 3) syn_error("ss:error:calc recieved too many arguments");;
int argc = get_expr_count();
set_expr_arg(argc, expr_tok);
n++;
}
// Check routine to make sure we're doing simple math xD
expr_argc = get_expr_count();
if(expr_argc > 3)
syn_error("ss:error:calc only supports dual values (3 * 14)");
first = strtof(sexpr[0].arg, &f_end);
calc_operator = sexpr[1].arg;
second = strtof(sexpr[2].arg, &s_end);
switch (calc_operator[0]) {
case '+':
finalf = first + second;
break;
case '-':
finalf = first - second;
break;
case '*':
finalf = first * second;
break;
case '/':
finalf = first / second;
break;
// operator doesn't match any case constant
default:
finalf = 0;
syn_error("ss:error:calc operator not supported");
}
if(gcvt(finalf, 12, expr_out)==NULL)
syn_error("ss:error:calc illegal instruction");
return expr_out;
}

11
src/math.h Normal file
View File

@ -0,0 +1,11 @@
// For SS
struct s_expr
{
char arg[MAX_EXPR_LEN+1];
};
typedef struct s_expr EXPR;
EXPR sexpr [MAX_EXPR_ARGS];
void set_expr_arg(int index, char *arg);
char *ss_expr(char *string);

View File

@ -7,10 +7,33 @@
#include "deps.h"
#include "vars.h"
#include "pipe.h"
#include "util.h"
char *ss_piping(char *string)
void set_cmd(int index, char *cmd)
{
strcpy(spipe[index].command, cmd);
}
int get_cmd_count()
{
int yy;
for(yy = 0; yy < MAX_PIPE_CMDS; yy++)
{
if(strlen(spipe[yy].command) > 0)
{
continue;
}
else
{
return yy;
}
}
return 0;
}
void ss_piping(char *string)
{
char *pipe_tok;
@ -22,15 +45,20 @@ char *ss_piping(char *string)
sprintf(stringmem, "%s", string);
pipe_tok = strtok(stringmem, "|");
if(pipe_tok != NULL && strcmp(pipe_tok, string) !=0)
if(pipe_tok == NULL)
{
char *second_func;
pipe_tok = strtok(NULL, "|");
second_func = pipe_tok + 1;
return second_func;
set_cmd(0, string);
}
else
{
set_cmd(0, pipe_tok);
}
while((pipe_tok = strtok(NULL, "|")) != NULL)
{
int cmdc = get_cmd_count();
set_cmd(cmdc, pipe_tok);
}
free(stringmem);
return NULL;
}

View File

@ -6,4 +6,15 @@
*/
char *ss_piping(char *string);
struct s_cmds
{
char command [MAX_STRING_BUFSIZE];
};
typedef struct s_cmds CMDS;
MY_GLOBAL CMDS spipe [MAX_PIPE_CMDS];
void set_cmd(int index, char *cmd);
int get_cmd_count();
void ss_piping(char *string);

View File

@ -78,3 +78,9 @@ void parse_args(int argc, char** argv)
}
char *ss_time()
{
time(&current_time);
return ctime(&current_time);
}

View File

@ -5,9 +5,12 @@
View README file supplied with this software for more details
*/
time_t current_time;
void syn_error(char *message);
char *strip_nl(char *string);
int file_exists(char *path);
int is_dir(char *path);
char *ss_concat(char *str1, char *str2);
void parse_args(int argc, char** argv);
char *ss_time();