Call this v0.4.0
This commit is contained in:
parent
81e2495aba
commit
8608bf2392
4
Makefile
4
Makefile
@ -2,7 +2,7 @@
|
|||||||
# (C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2)
|
# (C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2)
|
||||||
# Some changes and tweaks from Menchers
|
# Some changes and tweaks from Menchers
|
||||||
|
|
||||||
VERSION = \"0.3.3\"
|
VERSION = \"0.4.0\"
|
||||||
VERSION_EXTRA = \"$(EXTRA)\"
|
VERSION_EXTRA = \"$(EXTRA)\"
|
||||||
|
|
||||||
PREFIX ?= /usr
|
PREFIX ?= /usr
|
||||||
@ -13,7 +13,7 @@ CPPFLAGS += -DVERSION=$(VERSION) -D_FORTIFY_SOURCE=2
|
|||||||
LDFLAGS += -Wl,-O1,--sort-common,--hash-style=gnu,-z,relro
|
LDFLAGS += -Wl,-O1,--sort-common,--hash-style=gnu,-z,relro
|
||||||
BIN ?= slidescript
|
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
|
all: main
|
||||||
|
|
||||||
|
76
README.md
76
README.md
@ -10,6 +10,7 @@ Using SlideScript
|
|||||||
* Modify test.ss to learn the basics of SS.
|
* Modify test.ss to learn the basics of SS.
|
||||||
* Run ./test.ss to execute the script.
|
* Run ./test.ss to execute the script.
|
||||||
|
|
||||||
|
|
||||||
***NOTE: if compiling on OSX/BSD, please uncomment #define BSD in src/config.h***
|
***NOTE: if compiling on OSX/BSD, please uncomment #define BSD in src/config.h***
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
@ -17,93 +18,110 @@ Documentation
|
|||||||
Here is a list of functions and features that SlideScript comes with
|
Here is a list of functions and features that SlideScript comes with
|
||||||
at this moment!
|
at this moment!
|
||||||
|
|
||||||
* Commenting! Examples:
|
* Commenting! Examples:
|
||||||
* `# Comment is real in this one`
|
* `# Comment is real in this one`
|
||||||
|
|
||||||
* Read and writing to flat files. Examples:
|
* Read and writing to flat files. Examples:
|
||||||
* `write "file.txt" "This will be written to file.txt"`
|
* `write "file.txt" "This will be written to file.txt"`
|
||||||
* `read "file.txt"`
|
* `read "file.txt"`
|
||||||
|
|
||||||
* Delete example:
|
* Basic math expressions
|
||||||
|
* `calc "45 / 5"` or `calc "255.3 * 442.77"`
|
||||||
|
* Of course addition and subtraction as well!
|
||||||
|
|
||||||
|
* Delete example:
|
||||||
* `delete "file.txt"`
|
* `delete "file.txt"`
|
||||||
|
|
||||||
* Execute example:
|
* Execute example:
|
||||||
* `exec "ls -al"`
|
* `exec "ls -al"`
|
||||||
|
|
||||||
* Print example:
|
* Print example:
|
||||||
* `print "Hi everyone!"`
|
* `print "Hi everyone!"`
|
||||||
|
|
||||||
* Sleep (Zzz) example (sleeps for 2 seconds):
|
* Sleep (Zzz) example (sleeps for 2 seconds):
|
||||||
* `sleep 2`
|
* `sleep 2`
|
||||||
|
|
||||||
* Variable setting and passing
|
* Variable setting and passing
|
||||||
* `filename=file.txt` -> filename
|
* `filename=file.txt` -> filename
|
||||||
* `filedata=File '%filename%' is being moved to moo` -> %filename% is populated as file.txt
|
* `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.
|
* `write "%filename%" "%filedata%"` -> writes filedata contents to file.txt as expected.
|
||||||
|
|
||||||
* Decoding and encoding strings
|
* Decoding and encoding strings
|
||||||
* `encrypt "Regular string"` -> Converts to encrypted string 'Uhjvqds#xuulqj'
|
* `encrypt "Regular string"` -> Converts to encrypted string 'Uhjvqds#xuulqj'
|
||||||
* `decrypt "Uhjvqds#xuulqj"` -> Converts back to 'Regular string'
|
* `decrypt "Uhjvqds#xuulqj"` -> Converts back to 'Regular string'
|
||||||
|
|
||||||
* MD5 file checking
|
* MD5 file checking
|
||||||
* `md5 "file.txt"` -> outputs filename and md5 hash
|
* `md5 "file.txt"` -> outputs filename and md5 hash
|
||||||
|
|
||||||
* 2 Layer piping
|
* Layered piping
|
||||||
* `md5 "file.txt" | write "file.txt.md5" "%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
|
* Networking functions
|
||||||
* `netlisten "<port>" "<search>" "<respond>"` -> listens on <port> and replies <respond> on <search> found from outside
|
* `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
|
* `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,
|
* `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).
|
forkval (0 or 1, 0 don't fork into background / 1 do).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
This will change rapidly as of currently, slidescript is in beavy development!
|
This will change rapidly as of currently, slidescript is in beavy development!
|
||||||
|
|
||||||
|
|
||||||
Todo list
|
Todo list
|
||||||
-----
|
-----
|
||||||
* Add in-script functions
|
|
||||||
* New static functions
|
* Add in-script functions
|
||||||
* Loops, and if statements
|
* New static functions
|
||||||
|
* Loops, and if statements
|
||||||
|
|
||||||
|
|
||||||
Done
|
Done
|
||||||
-----
|
-----
|
||||||
* Simple syntax checking and error reporting
|
|
||||||
* 2 layer function piping
|
* Simple syntax checking and error reporting
|
||||||
* Support for linux system calls
|
* Up to 32 layer function piping
|
||||||
* Network listen socket, toss function
|
* Support for linux system calls
|
||||||
* Builtin HTTP server for disposeable use, can be ran in the foreground or forked into the background
|
* Network listen socket, toss function
|
||||||
* Read and write from file
|
* Builtin HTTP server for disposeable use, can be ran in the foreground or forked into the background
|
||||||
* Some simple functions
|
* Read and write from file
|
||||||
* Shebang handling
|
* Some simple functions
|
||||||
* Variable support
|
* Shebang handling
|
||||||
|
* Variable support
|
||||||
|
|
||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
-----
|
-----
|
||||||
* V0.3.3
|
* 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.
|
* Added first networking functions: netlisten, nettoss, nethttp.
|
||||||
* Embedded web server functionality
|
* Embedded web server functionality
|
||||||
* Cleaned up code
|
* Cleaned up code
|
||||||
* Improved syntax handling on functions
|
* Improved syntax handling on functions
|
||||||
* V0.3.0
|
|
||||||
|
* V0.3.0
|
||||||
* Added simple 2 layer function piping for more useful tasks
|
* Added simple 2 layer function piping for more useful tasks
|
||||||
* Fixed a couple core dump bugs
|
* Fixed a couple core dump bugs
|
||||||
* Now reads files into memory, and then forces text files through SS, allows for in file variables
|
* Now reads files into memory, and then forces text files through SS, allows for in file variables
|
||||||
* Added "md5" functionality
|
* Added "md5" functionality
|
||||||
* Multi-formal working syntax
|
* Multi-formal working syntax
|
||||||
* V0.2.1
|
|
||||||
|
* V0.2.1
|
||||||
* Added "decrypt" decode function
|
* Added "decrypt" decode function
|
||||||
* Added "encrypt" encode function
|
* Added "encrypt" encode function
|
||||||
* Added system "exec" function
|
* Added system "exec" function
|
||||||
* Added basic syntax handling, for a more uniform language
|
* Added basic syntax handling, for a more uniform language
|
||||||
|
|
||||||
* V0.2.0
|
* V0.2.0
|
||||||
* Added "delete" function
|
* Added "delete" function
|
||||||
* Added embedded variable handling to SS functions (variables can be used like everywhere!)
|
* Added embedded variable handling to SS functions (variables can be used like everywhere!)
|
||||||
* Added linux system calls via exec
|
* Added linux system calls via exec
|
||||||
* Some cleaning up.
|
* Some cleaning up.
|
||||||
|
|
||||||
* V0.1.1
|
* V0.1.1
|
||||||
* Added variable handling with a buffer size of 2KB per variable, and cap of 2048 variables.
|
* Added variable handling with a buffer size of 2KB per variable, and cap of 2048 variables.
|
||||||
* Now operates under the shebang!
|
* Now operates under the shebang!
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/slidescript
|
#!/usr/bin/slidescript
|
||||||
|
|
||||||
port=2001
|
port=2020
|
||||||
search=hi
|
search=hi
|
||||||
respond=bye
|
respond=bye
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#!/usr/bin/slidescript
|
#!/usr/bin/slidescript
|
||||||
|
|
||||||
address=127.0.0.1
|
address=127.0.0.1
|
||||||
port=2001
|
port=2020
|
||||||
data1=This data is gonna be pushed to the server side host!
|
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
|
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!
|
data3=Of course, do a little more considering the transfer is instant!
|
||||||
|
|
||||||
nettoss "%address%" "%port%" "%data1%"
|
nettoss "%address%" "%port%" "%data1%"
|
||||||
nettoss "%address%" "%port%" "%data2%"
|
nettoss "%address%" "%port%" "%data2%"
|
||||||
nettoss "%address%" "%port%" "%data3%"
|
encode "%data3%" | nettoss "%address%" "%port%" "%PIPE%"
|
||||||
|
|
||||||
nettoss "%address%" "%port%" "hi"
|
nettoss "%address%" "%port%" "hi"
|
@ -9,9 +9,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <regex.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "sbyteswap.h"
|
#include "sbyteswap.h"
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -26,7 +30,9 @@
|
|||||||
#define MAX_STRING_LEN 4096
|
#define MAX_STRING_LEN 4096
|
||||||
#define MAX_STRING_BUFSIZE (MAX_STRING_LEN + 1)
|
#define MAX_STRING_BUFSIZE (MAX_STRING_LEN + 1)
|
||||||
#define MAX_VAR_DATA_LEN 65536
|
#define MAX_VAR_DATA_LEN 65536
|
||||||
|
#define MAX_DATA_BUFSIZE (MAX_VAR_DATA_LEN + 1)
|
||||||
#define MAXVARS 1488
|
#define MAXVARS 1488
|
||||||
|
#define MAX_PIPE_CMDS 32
|
||||||
#define MAX_CONCAT_BUF 131072
|
#define MAX_CONCAT_BUF 131072
|
||||||
#define MAX_READFILE_LEN 2097152
|
#define MAX_READFILE_LEN 2097152
|
||||||
// for networking functions
|
// for networking functions
|
||||||
@ -36,6 +42,9 @@
|
|||||||
#define MAX_NETSRCH_BUF (MAX_NETSRCH_LEN + 1)
|
#define MAX_NETSRCH_BUF (MAX_NETSRCH_LEN + 1)
|
||||||
#define MAX_NETRESP_LEN 65536
|
#define MAX_NETRESP_LEN 65536
|
||||||
#define MAX_NETRESP_BUF (MAX_NETRESP_BUF + 1)
|
#define MAX_NETRESP_BUF (MAX_NETRESP_BUF + 1)
|
||||||
|
// For Expr
|
||||||
|
#define MAX_EXPR_ARGS 128
|
||||||
|
#define MAX_EXPR_LEN 512
|
||||||
// END
|
// END
|
||||||
#define TOKEN '%'
|
#define TOKEN '%'
|
||||||
#define TOKEN_STR "%"
|
#define TOKEN_STR "%"
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "vars.h"
|
#include "vars.h"
|
||||||
#include "enc.h"
|
#include "enc.h"
|
||||||
|
#include "math.h"
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
@ -37,6 +38,15 @@ char *process_line(char *line)
|
|||||||
if(strncmp("exit", tok_srch, 4) == 0)
|
if(strncmp("exit", tok_srch, 4) == 0)
|
||||||
syn_error("ss:exit called");
|
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 */
|
/* print function */
|
||||||
else if(strncmp("print",tok_srch,5) == 0)
|
else if(strncmp("print",tok_srch,5) == 0)
|
||||||
{
|
{
|
||||||
@ -78,6 +88,25 @@ char *process_line(char *line)
|
|||||||
return NULL;
|
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 */
|
/* Networking, listen */
|
||||||
else if(strncmp("netlisten",tok_srch,9) == 0)
|
else if(strncmp("netlisten",tok_srch,9) == 0)
|
||||||
{
|
{
|
||||||
|
42
src/main.c
42
src/main.c
@ -41,34 +41,36 @@ int main(int argc, char **argv)
|
|||||||
/* parse each line from the script in order. */
|
/* parse each line from the script in order. */
|
||||||
while(fgets(script_line, sizeof(script_line), script) != NULL)
|
while(fgets(script_line, sizeof(script_line), script) != NULL)
|
||||||
{
|
{
|
||||||
char *return_dat, *pipechk, *return_pipe_dat;
|
char *return_dat;
|
||||||
pipechk = ss_piping(script_line);
|
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.
|
// Blank line, getting up outta here.
|
||||||
if(return_dat == NULL) continue;
|
if(return_dat == NULL) continue;
|
||||||
|
|
||||||
if(pipechk != NULL)
|
int varc, ii;
|
||||||
|
varc = get_var_count();
|
||||||
|
if(pipechk > 1)
|
||||||
{
|
{
|
||||||
int varc;
|
for(ii = 1; ii < pipechk; ii++)
|
||||||
varc = get_var_count();
|
{
|
||||||
set_var(varc, "PIPE", return_dat);
|
set_var(varc, "PIPE", return_dat);
|
||||||
// Process functions based on previous pipe return
|
// 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 PIPE var back to NULL after use, keep the struct clean
|
||||||
set_var(varc, "\0", "\0");
|
set_var(varc, "\0", "\0");
|
||||||
// Check to see if there's anything to even display
|
// 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
|
// Print the pipe line
|
||||||
printf("%s\n", return_pipe_dat);
|
if(return_dat != NULL)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If return is not null, and no pipe; provide the return
|
|
||||||
printf("%s\n", return_dat);
|
printf("%s\n", return_dat);
|
||||||
}
|
|
||||||
} /* end of while */
|
} /* end of while */
|
||||||
} /* file null */
|
} /* file null */
|
||||||
|
|
||||||
|
90
src/math.c
Normal file
90
src/math.c
Normal 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
11
src/math.h
Normal 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);
|
44
src/pipe.c
44
src/pipe.c
@ -7,10 +7,33 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "deps.h"
|
#include "deps.h"
|
||||||
|
#include "vars.h"
|
||||||
#include "pipe.h"
|
#include "pipe.h"
|
||||||
#include "util.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;
|
char *pipe_tok;
|
||||||
|
|
||||||
@ -22,15 +45,20 @@ char *ss_piping(char *string)
|
|||||||
sprintf(stringmem, "%s", string);
|
sprintf(stringmem, "%s", string);
|
||||||
|
|
||||||
pipe_tok = strtok(stringmem, "|");
|
pipe_tok = strtok(stringmem, "|");
|
||||||
if(pipe_tok != NULL && strcmp(pipe_tok, string) !=0)
|
if(pipe_tok == NULL)
|
||||||
{
|
{
|
||||||
char *second_func;
|
set_cmd(0, string);
|
||||||
pipe_tok = strtok(NULL, "|");
|
}
|
||||||
second_func = pipe_tok + 1;
|
else
|
||||||
return second_func;
|
{
|
||||||
|
set_cmd(0, pipe_tok);
|
||||||
|
}
|
||||||
|
|
||||||
|
while((pipe_tok = strtok(NULL, "|")) != NULL)
|
||||||
|
{
|
||||||
|
int cmdc = get_cmd_count();
|
||||||
|
set_cmd(cmdc, pipe_tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(stringmem);
|
free(stringmem);
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
13
src/pipe.h
13
src/pipe.h
@ -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);
|
||||||
|
@ -78,3 +78,9 @@ void parse_args(int argc, char** argv)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *ss_time()
|
||||||
|
{
|
||||||
|
time(¤t_time);
|
||||||
|
|
||||||
|
return ctime(¤t_time);
|
||||||
|
}
|
||||||
|
@ -5,9 +5,12 @@
|
|||||||
View README file supplied with this software for more details
|
View README file supplied with this software for more details
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
time_t current_time;
|
||||||
|
|
||||||
void syn_error(char *message);
|
void syn_error(char *message);
|
||||||
char *strip_nl(char *string);
|
char *strip_nl(char *string);
|
||||||
int file_exists(char *path);
|
int file_exists(char *path);
|
||||||
int is_dir(char *path);
|
int is_dir(char *path);
|
||||||
char *ss_concat(char *str1, char *str2);
|
char *ss_concat(char *str1, char *str2);
|
||||||
void parse_args(int argc, char** argv);
|
void parse_args(int argc, char** argv);
|
||||||
|
char *ss_time();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user