Commit c395c22f authored by Stefan Pasteiner's avatar Stefan Pasteiner

compiles without warning now

parent e1211297
build: ./src/xsptt.c ./src/libXsptt.c ./src/libXsptt.h
mkdir -p build
gcc `xml2-config --cflags --libs` ./src/xsptt.c -o ./build/xsptt
gcc `xml2-config --cflags --libs` ./src/xsptt.c ./src/libXsptt.c -o ./build/xsptt
clean:
rm -rf ./build
......
#include "libXsptt.h"
#define STR_BUFFER_LEN 1024
bool strcpy_n(char *dest, char *source, unsigned int lenght)
{
unsigned int i=0;
bool toReturn = false;
while(i<lenght)
{
dest[i] = source[i];
if (dest[i] == '\n')
{
break;
}
i++;
}
if (i==lenght)
{
toReturn = true;
}
return toReturn;
}
bool strcat_n(char *dest, char *source, unsigned int lenght)
{
unsigned int i=0;
unsigned int j=0;
bool toReturn = false;
while(i<lenght)
{
if ((j != 0) | (dest[i] == '\0'))
{
dest[i] = source[j];
j++;
}
if (dest[i] == '\0')
{
break;
}else
{
i++;
}
}
if (i==lenght)
{
toReturn = true;
}
return toReturn;
}
int act_on_location(xmlChar * location_str, Action_t action)
{
char str_buffer
char str_buffer[XSPTT_STR_BUFFSIZE];
int toReturn = 0;
if(action.type == PRINT_NAME | action.options.verbose)
{
printf("%s",location_str);
}
if(action.type == COPY_FILE)
if(action.type == COPY_FILES)
{
//TODO: Do path analysis and use tools fit for type of path
strlcp(str_buffer, "cp \"" , STR_BUFFER_LEN);
strlcat(str_buffer, location_str, STR_BUFFER_LEN);
strlcat(str_buffer, "\" \"", STR_BUFFER_LEN);
strlcat(str_buffer, action.dest, STR_BUFFER_LEN);
strlcat(str_buffer, "\"", STR_BUFFER_LEN);
system(str_buffer);
strcpy_n(str_buffer, "cp \"" , XSPTT_STR_BUFFSIZE);
strcat_n(str_buffer, location_str, XSPTT_STR_BUFFSIZE);
strcat_n(str_buffer, "\" \"", XSPTT_STR_BUFFSIZE);
strcat_n(str_buffer, action.dest, XSPTT_STR_BUFFSIZE);
if (strcat_n(str_buffer, "\"", XSPTT_STR_BUFFSIZE) )
{
fprintf(stderr, "ERROR: buffer too short for defined location refuse to transfer file\n");
}else
{
system(str_buffer);
}
}else if(action.type != PRINT_NAME)
{
printf("Warning: unknown action.type in ");
printf("Warning: unknown action.type in \n");
//TODO: complet above.
toReturn ++;
}
......@@ -51,7 +103,7 @@ int act_on_track(xmlNode * track, Action_t action)
{
act_on_location(curNode_p->children->content, action);
//TODO: check return value and act accordingly.
if(action.transfer_all)
if(action.options.transfer_all)
{
curNode_p = curNode_p->next;
}else
......@@ -60,8 +112,8 @@ int act_on_track(xmlNode * track, Action_t action)
}
}else
{
printf("Warning: Broken xspf file");
if(action.strict)
printf("Warning: Broken xspf file \n");
if(action.options.strict)
{
printf(", strict mode activ\n");
printf("If you want to skip run programm in non strict mode \n");
......@@ -70,12 +122,12 @@ int act_on_track(xmlNode * track, Action_t action)
exit(1);
}else
{
printf(", skip element\n")
printf(", skip element\n");
curNode_p = curNode_p->next;
toReturn ++;
if(toReturn < 0)
{
printf("Warning: Bad file, missing many locations \n")
printf("Warning: Bad file, missing many locations \n");
toReturn =1;
}
}
......
#ifndef LIBXSPTT
#define LIBXSPTT
#define __STDC_LIB_EXT1__
#include <stdbool.h>
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlstring.h>
#include <stdlib.h>
#include <string.h>
#define XSPTT_STR_BUFFSIZE 1024
bool strcpy_n(char *dest, char *source, unsigned int lenght);
bool strcat_n(char *dest, char *source, unsigned int lenght);
enum ActionType
{
......@@ -21,14 +27,14 @@ typedef struct Option_s
bool convert_location;
bool transfer_all;
bool strict;
char *mediaRoot;
char mediaRoot[XSPTT_STR_BUFFSIZE];
}Option_t;
typedef struct Action_s
{
enum ActionType type;
Option_t options;
char *dest;
char dest[XSPTT_STR_BUFFSIZE];
}Action_t;
/**
......
......@@ -7,32 +7,19 @@
void do_action_file_names(xmlNode * a_node, Action_t action)
{
xmlNode * cur_node = NULL;
char str_buffer[1024];
//TODO: Find more suficient way for above
char str_buffer[XSPTT_STR_BUFFSIZE];
cur_node = a_node;
while (cur_node)
{
if (cur_node->type == XML_ELEMENT_NODE & xmlStrEqual(cur_node->name, xmlCharStrdup("location")))
if (cur_node->type == XML_ELEMENT_NODE & xmlStrEqual(cur_node->name, xmlCharStrdup("track")))
{
//check if currect type
if(cur_node->children->type == XML_TEXT_NODE)
{
if(DEBUG | action.type == PRINT_NAME)
printf("%s \n", cur_node->children->content);
if(action.type == COPY_FILES)
{
strcpy(str_buffer,"cp \"");
strcat(str_buffer, cur_node->children->content);
strcat(str_buffer, "\" \"");
strcat(str_buffer, action.dest);
strcat(str_buffer, "\"");
system(str_buffer);
}
}
//TODO: check for failure
act_on_track(cur_node, action);
}
//Find next Element
if(cur_node->children)
//TODO: Check xspf standard if first condition is save
if((! xmlStrEqual(cur_node->name, xmlCharStrdup("track"))) & (cur_node->children != NULL ))
{
cur_node = cur_node->children;
}else if(cur_node == a_node)
......@@ -61,20 +48,22 @@ int main(int argc, char **argv)
{
xmlDoc *doc = NULL;
xmlNode *root_element = NULL;
char source[XSPTT_STR_BUFFSIZE];
int i;
Action_t action = {
PRINT_FILES,
PRINT_NAME,
{
false,
false,
false,
false,
true,
NULL
""
},
NULL
""
};
char str_buffer[1024];
char str_buffer[XSPTT_STR_BUFFSIZE];
/*
* this initialize the library and check potential ABI mismatches
......@@ -92,26 +81,88 @@ int main(int argc, char **argv)
action.type = COPY_FILES;
}else
{
printf("ERROR: unknown action");
printf("ERROR: unknown action\n");
exit(1);
}
for (i = 2; i < argc;;)
for (i = 2; i < argc;)
{
if //TODO: Continue
if (argv[i][0] == '-')
{
if(i >= argc -2 | argv[i][1] == '\0')
{
//TODO: write option for error massages and warnings
printf("ERROR: invalic argument list\n");
exit(1);
}else
{
if(argv[i][1] == '-')
{
//check for long options
//TODO: actoally implement
if(false)
{}else
{
printf("ERROR: unknown argument\n");
exit(1);
}
}else
{
//check for short options
//TODO: actually implement
if(false)
{}else
{
printf("ERROR: unknown argument\n");
exit(1);
}
}
}
}else if((i == argc -1 & action.type == PRINT_NAME) |
(i == argc -2 & action.type != PRINT_NAME) )
{
//TODO: Implement sanity check for source and dest
if(strcpy_n(source, argv[i], XSPTT_STR_BUFFSIZE))
{
fprintf(stderr, "source path too long for intern Buffer\n");
exit(1);
}
i++;
}else if((i == argc -1 & action.type != PRINT_NAME))
{
if(strcpy_n(action.dest, argv[i], XSPTT_STR_BUFFSIZE))
{
fprintf(stderr, "ERROR: Destination path too lang \n");
exit(1);
}
i++;
}else
{
//TODO:make something else
printf("ERROR: Something went wrong in file %s bevore line %s \n",
__FILE__, __LINE__);
printf("If Possible please, report that bug to the Autor \n");
exit(1);
}
}
/*parse the file and get the DOM */
doc = xmlReadFile(argv[2], NULL, 0);
doc = xmlReadFile(source, NULL, 0);
if (doc == NULL) {
printf("ERROR: could not parse file %s\n", argv[2]);
printf("ERROR: could not parse file %s\n", source);
return(1);
}
//TODO: make depedef System and ifdef's
strcpy(str_buffer, "mkdir \"");
strcat(str_buffer, argv[3]);
strcat(str_buffer, "\"");
//TODO: check strings if terminated bevore calling system
strcpy_n(str_buffer, "mkdir -p \"", XSPTT_STR_BUFFSIZE);
strcat_n(str_buffer, action.dest, XSPTT_STR_BUFFSIZE);
if (strcat_n(str_buffer, "\"", XSPTT_STR_BUFFSIZE) )
{
fprintf(stderr, "ERROR: Too long destination path. \n");
exit(1);
}
system(str_buffer);
/*Get the root element node */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment