First part of adding in backquoting for embedded functions within variables and other functions

This commit is contained in:
Pentium44 2021-04-08 14:52:56 -07:00
parent 3bfaaec1c2
commit d4e3886071
7 changed files with 142 additions and 6 deletions

View File

@ -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 src/math.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 src/inset.o
all: main all: main

View File

@ -28,7 +28,7 @@
#define MAX_VAR_NAME_LEN 512 #define MAX_VAR_NAME_LEN 512
#define MAX_VAR_NAME_BUFSIZE (MAX_VAR_NAME_LEN + 1) #define MAX_VAR_NAME_BUFSIZE (MAX_VAR_NAME_LEN + 1)
#define MAX_STRING_LEN 4096 #define MAX_STRING_LEN 8128
#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 MAX_DATA_BUFSIZE (MAX_VAR_DATA_LEN + 1)
@ -49,6 +49,7 @@
// END // END
#define TOKEN '%' #define TOKEN '%'
#define TOKEN_STR "%" #define TOKEN_STR "%"
#define TOKEN_BQ '`'
#define NULLBYTE '\0' #define NULLBYTE '\0'
#define ENCOFFSET 3 #define ENCOFFSET 3
#define ENCSTEPODD 2 #define ENCSTEPODD 2

View File

@ -13,11 +13,14 @@
#include "math.h" #include "math.h"
#include "md5.h" #include "md5.h"
#include "network.h" #include "network.h"
#include "inset.h"
char *process_line(char *line) char *process_line(char *line)
{ {
char *tok_srch; char *tok_srch;
//printf("%s", &line[strlen(line)-2]);
static char concatbuf[MAX_CONCAT_BUF+1]; static char concatbuf[MAX_CONCAT_BUF+1];
static char filebuf[MAX_READFILE_LEN+1]; static char filebuf[MAX_READFILE_LEN+1];
@ -96,7 +99,7 @@ char *process_line(char *line)
if(tok_srch == NULL) if(tok_srch == NULL)
syn_error("ss:error:calc syntax error, missing quotes around equation?"); syn_error("ss:error:calc syntax error, missing quotes around equation?");
if(strcmp(tok_srch, "\n") == 0 || strcmp(tok_srch, " \n") == 0) if(strcmp(tok_srch, "\n") == 0 || (strcmp(tok_srch, " \n") == 0))
syn_error("ss:error:calc syntax error, missing quotes around equation?"); syn_error("ss:error:calc syntax error, missing quotes around equation?");
if(strtok(NULL, "\"") == NULL) if(strtok(NULL, "\"") == NULL)
@ -495,9 +498,12 @@ char *process_line(char *line)
{ {
int varc = get_var_count(); int varc = get_var_count();
char *varname_tmp = tok_srch; char *varname_tmp = tok_srch;
char *bq_check;
tok_srch = strtok(NULL, "="); tok_srch = strtok(NULL, "=");
// Check for back quotes, return string with backquotes processed
bq_check = strip_nl(parse_bq(tok_srch));
// Don't check if variable is blank, if so let it fly! // Don't check if variable is blank, if so let it fly!
set_var(varc, varname_tmp, parse_vars(strip_nl(tok_srch))); set_var(varc, varname_tmp, bq_check);
/* printf("ss: var '%s' -> %s", varname_tmp, get_var_data(varname_tmp)); */ /* printf("ss: var '%s' -> %s", varname_tmp, get_var_data(varname_tmp)); */
} }
} }

93
src/inset.c Normal file
View File

@ -0,0 +1,93 @@
/*
SlideScript - minimalistic top-down scripting language.
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (GPLv2)
View README file supplied with this software for more details
*/
#include "deps.h"
#include "inset.h"
#include "functions.h"
#include "vars.h"
#include "util.h"
void s_inset(int index, char *function)
{
strcpy(s_bqf[index].function, function);
}
int get_bq_count()
{
int yy;
for(yy = 0; yy < MAXVARS; yy++)
{
if(strlen(s_bqf[yy].function) > 0)
{
continue;
}
else
{
return yy;
}
}
return 0;
}
char *parse_bq(char *string)
{
int str_char, buf_len, var_len;
static char finished [MAX_STRING_BUFSIZE];
char varbuffer [MAX_BQ_BUFSIZE];
/* String pointers */
char *input_pointer;
char *output_pointer;
char *variable_pointer;
*finished = NULLBYTE;
for (input_pointer = string, output_pointer = finished;
(str_char = *input_pointer) != NULLBYTE;
input_pointer++)
{
if (str_char != TOKEN_BQ)
{ *output_pointer++ = str_char; *output_pointer = NULLBYTE; continue; }
variable_pointer = varbuffer;
do { *variable_pointer++ = (str_char = *++input_pointer); }
while ((str_char != NULLBYTE) && (str_char != TOKEN_BQ));
str_char = *input_pointer;
if ((str_char != NULLBYTE) && (str_char != TOKEN_BQ))
syn_error("ss:error:backquote buffer out of sync");
str_char = variable_pointer [-1];
if ((str_char != NULLBYTE) && (str_char != TOKEN_BQ))
syn_error("ss:error:backquote out of sync");
variable_pointer[-1] = NULLBYTE;
if(*varbuffer == NULLBYTE)
syn_error("ss:error:backquote syntax error!");
// Add newline so other function processing doesn't miss end quotes
strcat (varbuffer, "\n");
variable_pointer = process_line(varbuffer);
if(variable_pointer == NULL)
syn_error("ss:error:backquoted function must return string!");
var_len = strlen(variable_pointer);
buf_len = strlen(finished) + var_len;
if(buf_len > MAX_STRING_LEN)
syn_error("ss:error:string buffer overflow!");
strcat (finished, variable_pointer);
output_pointer += var_len;
if(*input_pointer == NULLBYTE) break;
}
*output_pointer = NULLBYTE;
return finished;
}

24
src/inset.h Normal file
View File

@ -0,0 +1,24 @@
/*
SlideScript - minimalistic top-down scripting language.
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (GPLv2)
View README file supplied with this software for more details
*/
// Inset backquote buffers
#define MAX_BACKQUOTE_LEN 6144
#define MAX_BQ_BUFSIZE (MAX_BACKQUOTE_LEN + 1)
#define MAX_BQ_FUNCTIONS 16
struct s_bq
{
char function [MAX_BQ_BUFSIZE];
};
typedef struct s_bq BQ;
BQ s_bqf [MAX_BQ_FUNCTIONS];
void s_set_bq(int index, char *function);
int get_bq_count();
char *parse_bq(char *string);

View File

@ -1,4 +1,10 @@
// expr.c, from suckless sbase. /*
SlideScript - minimalistic top-down scripting language.
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (GPLv2)
View README file supplied with this software for more details
*/
#include "deps.h" #include "deps.h"
#include "math.h" #include "math.h"
#include "util.h" #include "util.h"

View File

@ -1,4 +1,10 @@
// For SS /*
SlideScript - minimalistic top-down scripting language.
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (GPLv2)
View README file supplied with this software for more details
*/
struct s_expr struct s_expr
{ {
char arg[MAX_EXPR_LEN+1]; char arg[MAX_EXPR_LEN+1];