More tweaks via RJK
parent
6fe98d7d09
commit
17e53351a4
|
@ -10,16 +10,14 @@
|
||||||
# syntax handling!
|
# syntax handling!
|
||||||
# Example:
|
# Example:
|
||||||
# print "content"
|
# print "content"
|
||||||
# print "content";
|
|
||||||
# print("content")
|
# print("content")
|
||||||
# print("content");
|
|
||||||
###
|
###
|
||||||
### These will operate properly, as well as:
|
### These will operate properly, as well as:
|
||||||
# Example:
|
# Example:
|
||||||
# write "filename.txt" "data"
|
# write "filename.txt" "data"
|
||||||
# write "filename.txt" "data";
|
# write "filename.txt", "data"
|
||||||
# write("filename.txt" "data");
|
# write("filename.txt" "data")
|
||||||
# write("filename.txt", "data");
|
# write("filename.txt", "data")
|
||||||
#
|
#
|
||||||
# IT ALL WORKS!
|
# IT ALL WORKS!
|
||||||
# SlideScript really syntaxes based on quotes and key function words,
|
# SlideScript really syntaxes based on quotes and key function words,
|
||||||
|
|
|
@ -47,8 +47,8 @@ char *parse_bq(char *string)
|
||||||
char *output_pointer;
|
char *output_pointer;
|
||||||
char *variable_pointer;
|
char *variable_pointer;
|
||||||
|
|
||||||
varbuffer = qmalloc(QM_BQ, strlen(string));
|
varbuffer = qmalloc(QM_BQ, strlen(string) + 1);
|
||||||
finished = qmalloc(QM_BQ, (strlen(string) + 2));
|
finished = qmalloc(QM_BQ, (strlen(string) + 1));
|
||||||
|
|
||||||
*finished = NULLBYTE;
|
*finished = NULLBYTE;
|
||||||
|
|
||||||
|
@ -85,7 +85,9 @@ char *parse_bq(char *string)
|
||||||
|
|
||||||
var_len = strlen(variable_pointer);
|
var_len = strlen(variable_pointer);
|
||||||
|
|
||||||
qrealloc(finished, (var_len));
|
int moo = output_pointer - finished;
|
||||||
|
finished = qrealloc(finished, (strlen(finished) + var_len + 1));
|
||||||
|
output_pointer = moo + finished;
|
||||||
|
|
||||||
strcat (finished, variable_pointer);
|
strcat (finished, variable_pointer);
|
||||||
output_pointer += var_len;
|
output_pointer += var_len;
|
||||||
|
|
152
src/vars.c
152
src/vars.c
|
@ -1,45 +1,72 @@
|
||||||
/*
|
/*
|
||||||
SlideScript - minimalistic top-down scripting language.
|
SlideScript - minimalistic top-down scripting language.
|
||||||
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (GPLv2)
|
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (GPLv2)
|
||||||
|
|
||||||
View README file supplied with this software for more details
|
View README file supplied with this software for more details
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
// Header files.
|
||||||
|
|
||||||
#include "inc/deps.h"
|
#include "inc/deps.h"
|
||||||
#include "inc/vars.h"
|
#include "inc/vars.h"
|
||||||
#include "inc/util.h"
|
#include "inc/util.h"
|
||||||
|
|
||||||
void set_var(int index, char *varname, char *vardata)
|
//--------------------------------------------------------------------
|
||||||
|
// Module-private variables and/or data.
|
||||||
|
|
||||||
|
static QLIST QM_VAR [ONE];
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
// Functions.
|
||||||
|
|
||||||
|
void release_vars (void)
|
||||||
{
|
{
|
||||||
strcpy(svars[index].var_name, varname);
|
qflush (QM_VAR);
|
||||||
/* Set pointer in struct to a block of memory
|
|
||||||
THEN write to the memory buffer. */
|
|
||||||
svars[index].var_data = qmalloc(QM_VARIABLES, (strlen(vardata) + 1));
|
|
||||||
strcpy(svars[index].var_data, vardata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_var_data(char *varname)
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
void set_var (int index, char *varname, char *vardata)
|
||||||
|
{
|
||||||
|
strcpy (svars [index].var_name, varname);
|
||||||
|
|
||||||
|
/* Set pointer in struct to a block of memory
|
||||||
|
THEN write to the memory buffer. */
|
||||||
|
|
||||||
|
svars [index].var_data = qmalloc (QM_VAR,
|
||||||
|
strlen (vardata) + ONE);
|
||||||
|
strcpy (svars [index].var_data, vardata);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
char *get_var_data (char *varname)
|
||||||
{
|
{
|
||||||
int xx;
|
int xx;
|
||||||
for(xx = 0; xx < MAXVARS; xx++)
|
|
||||||
|
for(xx = ZERO; xx < MAXVARS; xx++)
|
||||||
{
|
{
|
||||||
char *varp = svars[xx].var_name;
|
char *varp = svars [xx].var_name;
|
||||||
if(*varp == '\0') continue;
|
if (*varp == '\0') continue;
|
||||||
if(strcmp(varp, varname) == 0)
|
|
||||||
|
if(strcmp (varp, varname) == ZERO)
|
||||||
{
|
{
|
||||||
return svars[xx].var_data;
|
return svars [xx].var_data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
int get_var_count()
|
int get_var_count()
|
||||||
{
|
{
|
||||||
int yy;
|
int yy;
|
||||||
for(yy = 0; yy < MAXVARS; yy++)
|
|
||||||
|
for(yy = ZERO; yy < MAXVARS; yy++)
|
||||||
{
|
{
|
||||||
if(strlen(svars[yy].var_name) > 0)
|
if (strlen (svars [yy].var_name) > ZERO)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -48,69 +75,90 @@ int get_var_count()
|
||||||
return yy;
|
return yy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
return ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *parse_vars(char *string)
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
char *parse_vars (char *var_string)
|
||||||
{
|
{
|
||||||
int str_char, var_len;
|
int str_char ;
|
||||||
char *varbuffer, *finished;
|
int sbufsize ;
|
||||||
|
char *ptr_input ; // Pointer into input text
|
||||||
|
|
||||||
varbuffer = qmalloc(QM_VARIABLES, (strlen(string) + 1));
|
char *buf_output ; // Output buffer
|
||||||
|
char *ptr_output ; // Pointer into that buffer
|
||||||
|
|
||||||
/* String pointers */
|
char *buf_varname ; // Variable-name buffer
|
||||||
char *input_pointer;
|
char *ptr_varname ; // Pointer into that buffer
|
||||||
char *output_pointer;
|
|
||||||
char *variable_pointer;
|
|
||||||
|
|
||||||
finished = qmalloc(QM_VARIABLES, (strlen(string) + 1));
|
char *var_data ; // Variable data
|
||||||
//finished = qmalloc(QM_VARIABLES, 16280);
|
int len_data ; // Length of data excluding EOS
|
||||||
|
|
||||||
*finished = NULLBYTE;
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
for (input_pointer = string, output_pointer = finished;
|
sbufsize = strlen (var_string) + ONE;
|
||||||
(str_char = *input_pointer) != NULLBYTE;
|
buf_varname = qmalloc (QM_VAR, sbufsize);
|
||||||
input_pointer++)
|
buf_output = qmalloc (QM_VAR, sbufsize);
|
||||||
|
|
||||||
|
*buf_output = NULLBYTE;
|
||||||
|
*buf_varname = NULLBYTE;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
for (ptr_input = var_string, ptr_output = buf_output;
|
||||||
|
(str_char = *ptr_input) != NULLBYTE;
|
||||||
|
ptr_input++)
|
||||||
{
|
{
|
||||||
if (str_char != TOKEN)
|
if (str_char != TOKEN)
|
||||||
{ *output_pointer++ = str_char; *output_pointer = NULLBYTE; continue; }
|
{
|
||||||
|
*ptr_output++ = str_char ;
|
||||||
|
*ptr_output = NULLBYTE ;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
variable_pointer = varbuffer;
|
ptr_varname = buf_varname;
|
||||||
do { *variable_pointer++ = (str_char = *++input_pointer); }
|
do { *ptr_varname++ = (str_char = *++ptr_input); }
|
||||||
while ((str_char != NULLBYTE) && (str_char != TOKEN));
|
while ((str_char != NULLBYTE) && (str_char != TOKEN));
|
||||||
|
|
||||||
str_char = *input_pointer;
|
str_char = *ptr_input;
|
||||||
if ((str_char != NULLBYTE) && (str_char != TOKEN))
|
if ((str_char != NULLBYTE) && (str_char != TOKEN))
|
||||||
x_error("ss:error:buffer out of sync");
|
x_error ("ss:error:buffer out of sync");
|
||||||
str_char = variable_pointer [-1];
|
str_char = ptr_varname [-1];
|
||||||
if ((str_char != NULLBYTE) && (str_char != TOKEN))
|
if ((str_char != NULLBYTE) && (str_char != TOKEN))
|
||||||
x_error("ss:error:buffer out of sync");
|
x_error ("ss:error:buffer out of sync");
|
||||||
|
|
||||||
variable_pointer[-1] = NULLBYTE;
|
ptr_varname [-1] = NULLBYTE;
|
||||||
|
|
||||||
if(*varbuffer == NULLBYTE)
|
if (*buf_varname == NULLBYTE)
|
||||||
{
|
{
|
||||||
x_warn("ss:warning:variable syntax error!");
|
x_warn ("ss:warning:variable syntax error!");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
variable_pointer = get_var_data(varbuffer);
|
var_data = get_var_data (buf_varname);
|
||||||
if(variable_pointer == NULL)
|
|
||||||
|
if (var_data == NULL)
|
||||||
{
|
{
|
||||||
x_error("ss:error:variable data not found, abort!");
|
x_error ("ss:error:variable data not found, abort!");
|
||||||
}
|
}
|
||||||
|
|
||||||
var_len = strlen(variable_pointer);
|
if (*ptr_input == NULLBYTE) break;
|
||||||
int moo = output_pointer - finished;
|
|
||||||
finished = qrealloc(finished, (strlen(finished) + var_len + 1));
|
|
||||||
output_pointer = moo + finished;
|
|
||||||
strcat (finished, variable_pointer);
|
|
||||||
|
|
||||||
output_pointer += var_len;
|
len_data = strlen (var_data);
|
||||||
|
int moo = ptr_output - buf_output;
|
||||||
|
buf_output = qrealloc (buf_output,
|
||||||
|
strlen (buf_output) + len_data + ONE);
|
||||||
|
ptr_output = buf_output + moo;
|
||||||
|
|
||||||
if(*input_pointer == NULLBYTE) break;
|
strcat (buf_output, var_data);
|
||||||
|
ptr_output += len_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
*output_pointer = NULLBYTE;
|
*ptr_output = NULLBYTE;
|
||||||
return finished;
|
return buf_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
// End of file.
|
||||||
|
|
Loading…
Reference in New Issue