More tweaks via RJK
parent
6fe98d7d09
commit
17e53351a4
|
@ -10,16 +10,14 @@
|
|||
# syntax handling!
|
||||
# Example:
|
||||
# print "content"
|
||||
# print "content";
|
||||
# print("content")
|
||||
# print("content");
|
||||
###
|
||||
### These will operate properly, as well as:
|
||||
# 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")
|
||||
#
|
||||
# IT ALL WORKS!
|
||||
# SlideScript really syntaxes based on quotes and key function words,
|
||||
|
|
|
@ -47,8 +47,8 @@ char *parse_bq(char *string)
|
|||
char *output_pointer;
|
||||
char *variable_pointer;
|
||||
|
||||
varbuffer = qmalloc(QM_BQ, strlen(string));
|
||||
finished = qmalloc(QM_BQ, (strlen(string) + 2));
|
||||
varbuffer = qmalloc(QM_BQ, strlen(string) + 1);
|
||||
finished = qmalloc(QM_BQ, (strlen(string) + 1));
|
||||
|
||||
*finished = NULLBYTE;
|
||||
|
||||
|
@ -85,7 +85,9 @@ char *parse_bq(char *string)
|
|||
|
||||
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);
|
||||
output_pointer += var_len;
|
||||
|
|
152
src/vars.c
152
src/vars.c
|
@ -1,45 +1,72 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Header files.
|
||||
|
||||
#include "inc/deps.h"
|
||||
#include "inc/vars.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);
|
||||
/* 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);
|
||||
qflush (QM_VAR);
|
||||
}
|
||||
|
||||
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;
|
||||
for(xx = 0; xx < MAXVARS; xx++)
|
||||
|
||||
for(xx = ZERO; xx < MAXVARS; xx++)
|
||||
{
|
||||
char *varp = svars[xx].var_name;
|
||||
if(*varp == '\0') continue;
|
||||
if(strcmp(varp, varname) == 0)
|
||||
char *varp = svars [xx].var_name;
|
||||
if (*varp == '\0') continue;
|
||||
|
||||
if(strcmp (varp, varname) == ZERO)
|
||||
{
|
||||
return svars[xx].var_data;
|
||||
return svars [xx].var_data;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
int get_var_count()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -48,69 +75,90 @@ int get_var_count()
|
|||
return yy;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
return ZERO;
|
||||
}
|
||||
|
||||
char *parse_vars(char *string)
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
char *parse_vars (char *var_string)
|
||||
{
|
||||
int str_char, var_len;
|
||||
char *varbuffer, *finished;
|
||||
int str_char ;
|
||||
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 *input_pointer;
|
||||
char *output_pointer;
|
||||
char *variable_pointer;
|
||||
char *buf_varname ; // Variable-name buffer
|
||||
char *ptr_varname ; // Pointer into that buffer
|
||||
|
||||
finished = qmalloc(QM_VARIABLES, (strlen(string) + 1));
|
||||
//finished = qmalloc(QM_VARIABLES, 16280);
|
||||
char *var_data ; // Variable data
|
||||
int len_data ; // Length of data excluding EOS
|
||||
|
||||
*finished = NULLBYTE;
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
for (input_pointer = string, output_pointer = finished;
|
||||
(str_char = *input_pointer) != NULLBYTE;
|
||||
input_pointer++)
|
||||
sbufsize = strlen (var_string) + ONE;
|
||||
buf_varname = qmalloc (QM_VAR, sbufsize);
|
||||
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)
|
||||
{ *output_pointer++ = str_char; *output_pointer = NULLBYTE; continue; }
|
||||
{
|
||||
*ptr_output++ = str_char ;
|
||||
*ptr_output = NULLBYTE ;
|
||||
continue;
|
||||
}
|
||||
|
||||
variable_pointer = varbuffer;
|
||||
do { *variable_pointer++ = (str_char = *++input_pointer); }
|
||||
ptr_varname = buf_varname;
|
||||
do { *ptr_varname++ = (str_char = *++ptr_input); }
|
||||
while ((str_char != NULLBYTE) && (str_char != TOKEN));
|
||||
|
||||
str_char = *input_pointer;
|
||||
str_char = *ptr_input;
|
||||
if ((str_char != NULLBYTE) && (str_char != TOKEN))
|
||||
x_error("ss:error:buffer out of sync");
|
||||
str_char = variable_pointer [-1];
|
||||
x_error ("ss:error:buffer out of sync");
|
||||
str_char = ptr_varname [-1];
|
||||
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;
|
||||
}
|
||||
|
||||
variable_pointer = get_var_data(varbuffer);
|
||||
if(variable_pointer == NULL)
|
||||
var_data = get_var_data (buf_varname);
|
||||
|
||||
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);
|
||||
int moo = output_pointer - finished;
|
||||
finished = qrealloc(finished, (strlen(finished) + var_len + 1));
|
||||
output_pointer = moo + finished;
|
||||
strcat (finished, variable_pointer);
|
||||
if (*ptr_input == NULLBYTE) break;
|
||||
|
||||
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;
|
||||
return finished;
|
||||
*ptr_output = NULLBYTE;
|
||||
return buf_output;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// End of file.
|
||||
|
|
Loading…
Reference in New Issue