Tweaks
This commit is contained in:
parent
332a0e2847
commit
f0fa98d70c
82
src/lexer.c
82
src/lexer.c
@ -29,15 +29,16 @@ char *process_line(char *line)
|
|||||||
static char filebuf[MAX_READFILE_LEN+1];
|
static char filebuf[MAX_READFILE_LEN+1];
|
||||||
static char retbuf[MAX_STRING_BUFSIZE];
|
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 countbuf[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);
|
bzero(retbuf, MAX_STRING_LEN);
|
||||||
bzero(compbuf, MAX_STRING_LEN);
|
|
||||||
|
|
||||||
tok_srch = strtok(line, "=\" |");
|
tok_srch = strtok(line, "=\" ;");
|
||||||
|
|
||||||
/* reuse function */
|
/* reuse function */
|
||||||
/*else if(strncmp("temp",tok_srch,4) == 0)
|
/*else if(strncmp("temp",tok_srch,4) == 0)
|
||||||
@ -56,8 +57,59 @@ char *process_line(char *line)
|
|||||||
|
|
||||||
// Lets add if and loop statements, make this
|
// Lets add if and loop statements, make this
|
||||||
// Somewhat usable as a language in other instances
|
// Somewhat usable as a language in other instances
|
||||||
|
|
||||||
|
// Loop
|
||||||
|
else if(strncmp("loop:", tok_srch, 4) == 0)
|
||||||
|
{
|
||||||
|
int loop_count, ii;
|
||||||
|
char *proc_return;
|
||||||
|
|
||||||
|
if(loopbuf != NULL || countbuf != NULL)
|
||||||
|
{
|
||||||
|
bzero(loopbuf, MAX_STRING_LEN);
|
||||||
|
bzero(countbuf, MAX_STRING_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
*loopbuf = '\0';
|
||||||
|
// We have an if statement
|
||||||
|
tok_srch = strtok(NULL, ";");
|
||||||
|
|
||||||
|
if(tok_srch == NULL)
|
||||||
|
{
|
||||||
|
syn_warn("ss:warn:loop statement requires arguments");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcat(countbuf, parse_vars(tok_srch));
|
||||||
|
loop_count = atoi(countbuf);
|
||||||
|
|
||||||
|
tok_srch = strtok(NULL, ";");
|
||||||
|
if(tok_srch == NULL)
|
||||||
|
{
|
||||||
|
syn_warn("ss:warn:loop syntax error, missing last argument?");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcat(loopbuf, parse_vars(tok_srch));
|
||||||
|
|
||||||
|
for(ii = 0; ii < loop_count; ii++)
|
||||||
|
{
|
||||||
|
proc_return = process_line(parse_vars(loopbuf));
|
||||||
|
printf("%s\n", proc_return);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// IF statement
|
||||||
else if(strncmp("if:", tok_srch, 3) == 0)
|
else if(strncmp("if:", tok_srch, 3) == 0)
|
||||||
{
|
{
|
||||||
|
if(compbuf != NULL)
|
||||||
|
{
|
||||||
|
bzero(compbuf, MAX_STRING_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
// We have an if statement
|
// We have an if statement
|
||||||
tok_srch = strtok(NULL, "\"");
|
tok_srch = strtok(NULL, "\"");
|
||||||
if(tok_srch == NULL)
|
if(tok_srch == NULL)
|
||||||
@ -76,13 +128,13 @@ char *process_line(char *line)
|
|||||||
// Make sure the end quote exists
|
// Make sure the end quote exists
|
||||||
if(strtok(NULL, "\"") == NULL)
|
if(strtok(NULL, "\"") == NULL)
|
||||||
{
|
{
|
||||||
syn_warn("ss:warn:if syntax error, missing quote?");
|
syn_warn("ss:warn:if syntax error, missing quote?");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen(tok_srch) < MAX_STRING_LEN)
|
if(strlen(tok_srch) < MAX_STRING_LEN)
|
||||||
{
|
{
|
||||||
strcpy(compbuf, tok_srch);
|
strcpy(compbuf, parse_vars(tok_srch));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -111,7 +163,7 @@ char *process_line(char *line)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(atoi(compbuf) == atoi(tok_srch))
|
if(atoi(compbuf) == atoi(parse_vars(tok_srch)))
|
||||||
{
|
{
|
||||||
return "true";
|
return "true";
|
||||||
}
|
}
|
||||||
@ -285,7 +337,7 @@ char *process_line(char *line)
|
|||||||
else if(strncmp("decompress",tok_srch,10) == 0)
|
else if(strncmp("decompress",tok_srch,10) == 0)
|
||||||
{
|
{
|
||||||
char *filename;
|
char *filename;
|
||||||
struct tar_t *archive = NULL;
|
struct tar_t *archive = (void *)0;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
tok_srch = strtok(NULL, "\"");
|
tok_srch = strtok(NULL, "\"");
|
||||||
@ -344,7 +396,13 @@ char *process_line(char *line)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tar_free(archive);
|
usleep(50);
|
||||||
|
|
||||||
|
if(archive != (void *)0)
|
||||||
|
{
|
||||||
|
tar_free(archive);
|
||||||
|
archive = (void *)0;
|
||||||
|
}
|
||||||
|
|
||||||
close(fd); // don't bother checking for fd < 0
|
close(fd); // don't bother checking for fd < 0
|
||||||
|
|
||||||
@ -359,7 +417,7 @@ char *process_line(char *line)
|
|||||||
{
|
{
|
||||||
char filename[MAX_FILENAME_LEN+1]; // Files to be added into the archive
|
char filename[MAX_FILENAME_LEN+1]; // Files to be added into the archive
|
||||||
char comp_size[128];
|
char comp_size[128];
|
||||||
struct tar_t *archive = NULL;
|
struct tar_t *archive = (void *)0;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
tok_srch = strtok(NULL, "\"");
|
tok_srch = strtok(NULL, "\"");
|
||||||
@ -436,7 +494,11 @@ char *process_line(char *line)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tar_free(archive);
|
if(archive != (void *)0)
|
||||||
|
{
|
||||||
|
tar_free(archive);
|
||||||
|
archive = (void *)0;
|
||||||
|
}
|
||||||
close(fd); // don't bother checking for fd < 0
|
close(fd); // don't bother checking for fd < 0
|
||||||
|
|
||||||
FILE *in;
|
FILE *in;
|
||||||
|
27
src/tar.c
27
src/tar.c
@ -46,7 +46,7 @@ int tar_read(const int fd, struct tar_t ** archive, const char verbosity){
|
|||||||
if (update && (read_size(fd, (*tar) -> block, 512) != 512)){
|
if (update && (read_size(fd, (*tar) -> block, 512) != 512)){
|
||||||
V_PRINT(stderr, "Error: Bad read. Stopping");
|
V_PRINT(stderr, "Error: Bad read. Stopping");
|
||||||
tar_free(*tar);
|
tar_free(*tar);
|
||||||
*tar = NULL;
|
*tar = (void *)0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,20 +56,25 @@ int tar_read(const int fd, struct tar_t ** archive, const char verbosity){
|
|||||||
if (read_size(fd, (*tar) -> block, 512) != 512){
|
if (read_size(fd, (*tar) -> block, 512) != 512){
|
||||||
V_PRINT(stderr, "Error: Bad read. Stopping");
|
V_PRINT(stderr, "Error: Bad read. Stopping");
|
||||||
tar_free(*tar);
|
tar_free(*tar);
|
||||||
*tar = NULL;
|
*tar = (void *)0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if next block is all zeros as well
|
// check if next block is all zeros as well
|
||||||
if (iszeroed((*tar) -> block, 512)){
|
if (iszeroed((*tar) -> block, 512)){
|
||||||
tar_free(*tar);
|
|
||||||
*tar = NULL;
|
|
||||||
|
|
||||||
// skip to end of record
|
// skip to end of record
|
||||||
if (lseek(fd, RECORDSIZE - (offset % RECORDSIZE), SEEK_CUR) == (off_t) (-1)){
|
if (lseek(fd, RECORDSIZE - (offset % RECORDSIZE), SEEK_CUR) == (off_t) (-1)){
|
||||||
RC_ERROR("Unable to seek file: %s", strerror(rc));
|
RC_ERROR("Unable to seek file: %s", strerror(rc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(*tar != (void *)0)
|
||||||
|
{
|
||||||
|
tar_free(*tar);
|
||||||
|
*tar = (void *)0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +140,7 @@ int tar_write(const int fd, struct tar_t **archive, const size_t filecount, cons
|
|||||||
// write entries first
|
// write entries first
|
||||||
if (write_entries(fd, tar, archive, filecount, files, &offset, verbosity) < 0){
|
if (write_entries(fd, tar, archive, filecount, files, &offset, verbosity) < 0){
|
||||||
tar_free(*archive);
|
tar_free(*archive);
|
||||||
|
*tar = (void *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write ending data
|
// write ending data
|
||||||
@ -158,9 +164,9 @@ void tar_free (struct tar_t *archive)
|
|||||||
if(archive != (void *) 0)
|
if(archive != (void *) 0)
|
||||||
{
|
{
|
||||||
free(archive);
|
free(archive);
|
||||||
archive = NULL;
|
archive = (void *) 0;
|
||||||
|
archive = next;
|
||||||
}
|
}
|
||||||
archive = next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -847,6 +853,7 @@ int write_entries(const int fd, struct tar_t ** archive, struct tar_t ** head, c
|
|||||||
// stat file
|
// stat file
|
||||||
if (format_tar_data(*tar, files[i], verbosity) < 0){
|
if (format_tar_data(*tar, files[i], verbosity) < 0){
|
||||||
tar_free(*tar);
|
tar_free(*tar);
|
||||||
|
*tar = (void *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*tar) -> begin = *offset;
|
(*tar) -> begin = *offset;
|
||||||
@ -870,12 +877,14 @@ int write_entries(const int fd, struct tar_t ** archive, struct tar_t ** head, c
|
|||||||
// write metadata to (*tar) file
|
// write metadata to (*tar) file
|
||||||
if (write_size(fd, (*tar) -> block, 512) != 512){
|
if (write_size(fd, (*tar) -> block, 512) != 512){
|
||||||
tar_free(*tar);
|
tar_free(*tar);
|
||||||
|
*tar = (void *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// go through directory
|
// go through directory
|
||||||
DIR * d = opendir(parent);
|
DIR * d = opendir(parent);
|
||||||
if (!d){
|
if (!d){
|
||||||
tar_free(*tar);
|
tar_free(*tar);
|
||||||
|
*tar = (void *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dirent * dir;
|
struct dirent * dir;
|
||||||
@ -889,6 +898,7 @@ int write_entries(const int fd, struct tar_t ** archive, struct tar_t ** head, c
|
|||||||
// recursively write each subdirectory
|
// recursively write each subdirectory
|
||||||
if (write_entries(fd, &((*tar) -> next), head, 1, (const char **) &path, offset, verbosity) < 0){
|
if (write_entries(fd, &((*tar) -> next), head, 1, (const char **) &path, offset, verbosity) < 0){
|
||||||
tar_free(*tar);
|
tar_free(*tar);
|
||||||
|
*tar = (void *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// go to end of new data
|
// go to end of new data
|
||||||
@ -932,6 +942,7 @@ int write_entries(const int fd, struct tar_t ** archive, struct tar_t ** head, c
|
|||||||
// write metadata to (*tar) file
|
// write metadata to (*tar) file
|
||||||
if (write_size(fd, (*tar) -> block, 512) != 512){
|
if (write_size(fd, (*tar) -> block, 512) != 512){
|
||||||
tar_free(*tar);
|
tar_free(*tar);
|
||||||
|
*tar = (void *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((*tar) -> type == REGULAR) || ((*tar) -> type == NORMAL) || ((*tar) -> type == CONTIGUOUS)){
|
if (((*tar) -> type == REGULAR) || ((*tar) -> type == NORMAL) || ((*tar) -> type == CONTIGUOUS)){
|
||||||
@ -940,6 +951,7 @@ int write_entries(const int fd, struct tar_t ** archive, struct tar_t ** head, c
|
|||||||
int f = open((*tar) -> name, O_RDONLY);
|
int f = open((*tar) -> name, O_RDONLY);
|
||||||
if (f < 0){
|
if (f < 0){
|
||||||
tar_free(*tar);
|
tar_free(*tar);
|
||||||
|
*tar = (void *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
@ -961,6 +973,7 @@ int write_entries(const int fd, struct tar_t ** archive, struct tar_t ** head, c
|
|||||||
for(unsigned int j = 0; j < pad; j++){
|
for(unsigned int j = 0; j < pad; j++){
|
||||||
if (write_size(fd, "\0", 1) != 1){
|
if (write_size(fd, "\0", 1) != 1){
|
||||||
tar_free(*tar);
|
tar_free(*tar);
|
||||||
|
*tar = (void *)0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*offset += pad;
|
*offset += pad;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user