Cleaning up some static buffers, and adding in dynamic allocation. No more limits!
This commit is contained in:
parent
9c1c11b56d
commit
7f88238255
@ -177,7 +177,7 @@ V_FUNC x_warn(s,a,b,c,d,e,f,g,h,i,j)
|
|||||||
char *s; /* format string */
|
char *s; /* format string */
|
||||||
unsigned long a,b,c,d,e,f,g,h,i,j; /* dummy arguments */
|
unsigned long a,b,c,d,e,f,g,h,i,j; /* dummy arguments */
|
||||||
{
|
{
|
||||||
z_msg (FALSE, "Warning: ", s,a,b,c,d,e,f,g,h,i,j);
|
z_msg (FALSE, ":", s,a,b,c,d,e,f,g,h,i,j);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
@ -199,7 +199,7 @@ V_FUNC x_error(s,a,b,c,d,e,f,g,h,i,j)
|
|||||||
char *s; /* format string */
|
char *s; /* format string */
|
||||||
long a,b,c,d,e,f,g,h,i,j; /* dummy arguments */
|
long a,b,c,d,e,f,g,h,i,j; /* dummy arguments */
|
||||||
{
|
{
|
||||||
z_msg (TRUE, "Error: ", s,a,b,c,d,e,f,g,h,i,j);
|
z_msg (TRUE, ":", s,a,b,c,d,e,f,g,h,i,j);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
@ -224,7 +224,7 @@ V_FUNC x_panic (s,a,b,c,d,e,f,g,h,i,j)
|
|||||||
char *s; /* format string */
|
char *s; /* format string */
|
||||||
unsigned long a,b,c,d,e,f,g,h,i,j; /* dummy arguments */
|
unsigned long a,b,c,d,e,f,g,h,i,j; /* dummy arguments */
|
||||||
{
|
{
|
||||||
z_msg (TRUE, "Internal error: ",
|
z_msg (TRUE, "INTERNAL ERROR! :",
|
||||||
s,a,b,c,d,e,f,g,h,i,j);
|
s,a,b,c,d,e,f,g,h,i,j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,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 65535
|
#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 65535
|
#define MAX_VAR_DATA_LEN 65535
|
||||||
#define MAX_DATA_BUFSIZE (MAX_VAR_DATA_LEN + 1)
|
#define MAX_DATA_BUFSIZE (MAX_VAR_DATA_LEN + 1)
|
||||||
|
@ -5,4 +5,9 @@
|
|||||||
View README file supplied with this software for more details
|
View README file supplied with this software for more details
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "x3mem.h"
|
||||||
|
|
||||||
|
UX3_EXT QLIST QM_RETURN [ONE]; // Dynamic-memory QLIST
|
||||||
|
|
||||||
|
|
||||||
char *process_line(char *line);
|
char *process_line(char *line);
|
||||||
|
@ -30,6 +30,7 @@ THE SOFTWARE
|
|||||||
|
|
||||||
UX3_EXT QLIST QM_TAR [ONE]; // Dynamic-memory QLIST
|
UX3_EXT QLIST QM_TAR [ONE]; // Dynamic-memory QLIST
|
||||||
|
|
||||||
|
|
||||||
extern void tar_free_pool (void);
|
extern void tar_free_pool (void);
|
||||||
|
|
||||||
#ifndef _DEFAULT_SOURCE
|
#ifndef _DEFAULT_SOURCE
|
||||||
|
92
src/lexer.c
92
src/lexer.c
@ -21,22 +21,21 @@
|
|||||||
|
|
||||||
char *process_line(char *line)
|
char *process_line(char *line)
|
||||||
{
|
{
|
||||||
char *tok_srch;
|
char *tok_srch, *retbuf;
|
||||||
|
|
||||||
//printf("%s", &line[strlen(line)-2]);
|
//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];
|
||||||
static char retbuf[MAX_STRING_BUFSIZE];
|
|
||||||
static char compbuf[MAX_STRING_BUFSIZE];
|
static char compbuf[MAX_STRING_BUFSIZE];
|
||||||
static char loopbuf[MAX_STRING_BUFSIZE];
|
static char loopbuf[MAX_STRING_BUFSIZE];
|
||||||
static char countbuf[MAX_STRING_BUFSIZE];
|
static char countbuf[MAX_STRING_BUFSIZE];
|
||||||
|
static char dirpathbuf[MAX_STRING_BUFSIZE];
|
||||||
|
|
||||||
// Make sure static buffers are empty before initialize
|
// Make sure static buffers are empty before initialize
|
||||||
// Write with zeros
|
// Write with zeros
|
||||||
bzero(filebuf, MAX_READFILE_LEN);
|
bzero(filebuf, MAX_READFILE_LEN);
|
||||||
bzero(concatbuf, MAX_CONCAT_BUF);
|
bzero(concatbuf, MAX_CONCAT_BUF);
|
||||||
bzero(retbuf, MAX_STRING_LEN);
|
|
||||||
|
|
||||||
tok_srch = strtok(line, "=\" ;");
|
tok_srch = strtok(line, "=\" ;");
|
||||||
|
|
||||||
@ -58,14 +57,14 @@ char *process_line(char *line)
|
|||||||
|
|
||||||
else if(strncmp("version", tok_srch, 7) == 0)
|
else if(strncmp("version", tok_srch, 7) == 0)
|
||||||
{
|
{
|
||||||
sprintf(retbuf, "ss:version: %s, type 'help' for function list\n", VERSION);
|
x_warn(":ss:version: %s, type 'help' for function list\n", VERSION);
|
||||||
return retbuf;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(strncmp("help", tok_srch, 4) == 0)
|
else if(strncmp("help", tok_srch, 4) == 0)
|
||||||
{
|
{
|
||||||
sprintf(retbuf, "ss:help:\n%s", FUNCTION_HELP);
|
x_warn(":ss:help:\n%s", FUNCTION_HELP);
|
||||||
return retbuf;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lets add if and loop statements, make this
|
// Lets add if and loop statements, make this
|
||||||
@ -260,11 +259,11 @@ char *process_line(char *line)
|
|||||||
else if(strncmp("showpath", tok_srch, 8) == 0 || strncmp("pwd", tok_srch, 3) == 0)
|
else if(strncmp("showpath", tok_srch, 8) == 0 || strncmp("pwd", tok_srch, 3) == 0)
|
||||||
{
|
{
|
||||||
// Get current directory, if it errors, return NULL
|
// Get current directory, if it errors, return NULL
|
||||||
if (getcwd(retbuf, sizeof(retbuf)) == NULL) {
|
if (getcwd(retbuf, sizeof(dirpathbuf)) == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// All good, return path
|
// All good, return path
|
||||||
return retbuf;
|
return dirpathbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change directory
|
// Change directory
|
||||||
@ -317,10 +316,8 @@ char *process_line(char *line)
|
|||||||
if(dirname == NULL)
|
if(dirname == NULL)
|
||||||
dirname = parse_vars(tok_srch);
|
dirname = parse_vars(tok_srch);
|
||||||
|
|
||||||
sprintf(retbuf, "%s\n", "ss:showdir:");
|
|
||||||
|
|
||||||
struct dirent **files;
|
struct dirent **files;
|
||||||
int nn;
|
int nn, dirstr_size;
|
||||||
|
|
||||||
nn = scandir (dirname, &files, NULL, alphasort);
|
nn = scandir (dirname, &files, NULL, alphasort);
|
||||||
|
|
||||||
@ -330,18 +327,27 @@ char *process_line(char *line)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dirstr_size = 14;
|
||||||
|
|
||||||
|
for (int jj = 0; jj < nn; jj++)
|
||||||
|
{
|
||||||
|
struct dirent *ent = files [jj];
|
||||||
|
dirstr_size += (strlen(ent->d_name)+3);
|
||||||
|
}
|
||||||
|
|
||||||
|
retbuf = qmalloc(QM_RETURN, dirstr_size);
|
||||||
|
|
||||||
|
sprintf(retbuf, "%s\n", "ss:showdir:");
|
||||||
|
|
||||||
for (int ii = 0; ii < nn; ii++)
|
for (int ii = 0; ii < nn; ii++)
|
||||||
{
|
{
|
||||||
struct dirent *ent = files [ii];
|
struct dirent *ent = files [ii];
|
||||||
if((strlen(retbuf) + strlen(ent->d_name) + 1) < MAX_STRING_LEN)
|
strcat(retbuf, ent->d_name);
|
||||||
{
|
strcat(retbuf, "\n");
|
||||||
strcat(retbuf, ent->d_name);
|
}
|
||||||
strcat(retbuf, "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int ii = 0; ii < nn; ii++) { free (files [ii]); }
|
for (int ii = 0; ii < nn; ii++) { free (files [ii]); }
|
||||||
free (files);
|
free (files);
|
||||||
|
|
||||||
return retbuf;
|
return retbuf;
|
||||||
}
|
}
|
||||||
@ -386,7 +392,7 @@ char *process_line(char *line)
|
|||||||
sprintf(origsize, "%ld", fsize(in));
|
sprintf(origsize, "%ld", fsize(in));
|
||||||
|
|
||||||
uint32_t deco_return = ss_decompress(filename, filedecout);
|
uint32_t deco_return = ss_decompress(filename, filedecout);
|
||||||
|
retbuf = qmalloc(QM_RETURN, (sizeof(deco_return) + strlen(filename) + strlen(origsize) + 40));
|
||||||
sprintf(retbuf, "ss: %s: decompressed: %s -> %u", filename, origsize, deco_return);
|
sprintf(retbuf, "ss: %s: decompressed: %s -> %u", filename, origsize, deco_return);
|
||||||
|
|
||||||
fclose(in);
|
fclose(in);
|
||||||
@ -534,9 +540,12 @@ char *process_line(char *line)
|
|||||||
{
|
{
|
||||||
uint32_t comp_return = ss_compress(filename, file_comp, i);
|
uint32_t comp_return = ss_compress(filename, file_comp, i);
|
||||||
uint32_t deco_return = ss_decompress(file_comp, filedecout);
|
uint32_t deco_return = ss_decompress(file_comp, filedecout);
|
||||||
sprintf(retbuf, "ss: %s: compressed: %u -> %u", file_comp, deco_return, comp_return);
|
|
||||||
if(atoi(comp_size) < (int)comp_return && comp_return != 0 && deco_return != 0 && i != 1)
|
if(atoi(comp_size) < (int)comp_return && comp_return != 0 && deco_return != 0 && i != 1)
|
||||||
break;
|
{
|
||||||
|
retbuf = qmalloc(QM_RETURN, sizeof(deco_return) + sizeof(comp_return) + strlen(file_comp) + 40);
|
||||||
|
sprintf(retbuf, "ss: %s: compressed: %u -> %u", file_comp, deco_return, comp_return);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
sprintf(comp_size, "%u", comp_return);
|
sprintf(comp_size, "%u", comp_return);
|
||||||
printf("pass %u decompressed/compressed: %u/%u\n", i, deco_return, comp_return);
|
printf("pass %u decompressed/compressed: %u/%u\n", i, deco_return, comp_return);
|
||||||
@ -1084,9 +1093,10 @@ char *process_line(char *line)
|
|||||||
catfile = ss_concat(file_md5_val, file_line);
|
catfile = ss_concat(file_md5_val, file_line);
|
||||||
if(strlen(catfile) < MAX_CONCAT_BUF)
|
if(strlen(catfile) < MAX_CONCAT_BUF)
|
||||||
{
|
{
|
||||||
strcpy(concatbuf, catfile);
|
retbuf = qmalloc(QM_RETURN, strlen(catfile)+1);
|
||||||
|
strcpy(retbuf, catfile);
|
||||||
free(catfile);
|
free(catfile);
|
||||||
return concatbuf;
|
return retbuf;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1314,40 +1324,26 @@ char *process_line(char *line)
|
|||||||
read_size = ftell(read_file);
|
read_size = ftell(read_file);
|
||||||
rewind(read_file);
|
rewind(read_file);
|
||||||
|
|
||||||
dynfile = (char *)malloc(read_size + 1);
|
dynfile = qmalloc(QM_RETURN, read_size);
|
||||||
|
|
||||||
*dynfile = '\0';
|
|
||||||
|
|
||||||
/* Check if file was opened successfully */
|
/* Check if file was opened successfully */
|
||||||
if(read_file == NULL)
|
if(read_file == NULL)
|
||||||
{
|
{
|
||||||
free(dynfile);
|
|
||||||
x_warn("ss:warn:write, failed open");
|
x_warn("ss:warn:write, failed open");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *nullbyte = "\0";
|
||||||
|
strcpy(dynfile, nullbyte);
|
||||||
|
|
||||||
while(fgets(read_line, sizeof(read_line), read_file) != NULL)
|
while(fgets(read_line, sizeof(read_line), read_file) != NULL)
|
||||||
{
|
{
|
||||||
strcat(dynfile, read_line);
|
strcat(dynfile, read_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(read_size <= MAX_READFILE_LEN)
|
|
||||||
{
|
|
||||||
// Copy string to end of file, rewrite file
|
|
||||||
sprintf(filebuf, "%s", dynfile);
|
|
||||||
free(dynfile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
free(dynfile);
|
|
||||||
fclose(read_file);
|
|
||||||
x_warn("ss:warn:write, file too large (2MB max)");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(read_file);
|
fclose(read_file);
|
||||||
|
|
||||||
return strip_nl(filebuf);
|
return strip_nl(dynfile);
|
||||||
} /* read function */
|
} /* read function */
|
||||||
|
|
||||||
/* Cat function, writes to end of file specified */
|
/* Cat function, writes to end of file specified */
|
||||||
@ -1427,9 +1423,9 @@ char *process_line(char *line)
|
|||||||
read_size = ftell(read_file);
|
read_size = ftell(read_file);
|
||||||
rewind(read_file);
|
rewind(read_file);
|
||||||
|
|
||||||
dynfile = (char *)malloc(read_size + 1);
|
dynfile = qmalloc(QM_RETURN, read_size);
|
||||||
|
|
||||||
*dynfile = '\0';
|
strcpy(dynfile, "\0");
|
||||||
|
|
||||||
while(fgets(read_line, sizeof(read_line), read_file) != NULL)
|
while(fgets(read_line, sizeof(read_line), read_file) != NULL)
|
||||||
{
|
{
|
||||||
@ -1440,15 +1436,15 @@ char *process_line(char *line)
|
|||||||
|
|
||||||
if((read_size + strlen(parse_vars(tok_srch))) <= MAX_READFILE_LEN)
|
if((read_size + strlen(parse_vars(tok_srch))) <= MAX_READFILE_LEN)
|
||||||
{
|
{
|
||||||
|
char *filebuf = qmalloc(QM_RETURN, (read_size + strlen(parse_vars(tok_srch))));
|
||||||
read_file = fopen(filename, "w");
|
read_file = fopen(filename, "w");
|
||||||
sprintf(filebuf, "%s%s", dynfile, parse_vars(tok_srch));
|
sprintf(filebuf, "%s%s", dynfile, parse_vars(tok_srch));
|
||||||
fprintf(read_file, "%s", filebuf);
|
fprintf(read_file, "%s", filebuf);
|
||||||
free(dynfile);
|
|
||||||
fclose(read_file);
|
fclose(read_file);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
free(dynfile);
|
|
||||||
fclose(read_file);
|
fclose(read_file);
|
||||||
x_warn("ss:warn:cat, file too large (2MB max)");
|
x_warn("ss:warn:cat, file too large (2MB max)");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
10
src/main.c
10
src/main.c
@ -53,7 +53,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (is_interactive)
|
if (is_interactive)
|
||||||
{
|
{
|
||||||
printf ("%s", "ss:prompt: ");
|
printf ("%s", ":ss:prompt: ");
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,10 @@ int main(int argc, char **argv)
|
|||||||
// 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_dat == NULL) break;
|
if(return_dat == NULL)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +98,9 @@ int main(int argc, char **argv)
|
|||||||
printf("%s\n", return_dat);
|
printf("%s\n", return_dat);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Free used mallocs within QM_RETURN
|
||||||
|
qflush(QM_RETURN);
|
||||||
} /* end of while */
|
} /* end of while */
|
||||||
} /* file null */
|
} /* file null */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user