Commit d575253e authored by Stefan Pasteiner's avatar Stefan Pasteiner

fixed wrong assumption about strcmp

parent c395c22f
......@@ -7,7 +7,7 @@ bool strcpy_n(char *dest, char *source, unsigned int lenght)
while(i<lenght)
{
dest[i] = source[i];
if (dest[i] == '\n')
if (dest[i] == '\0')
{
break;
}
......
......@@ -73,26 +73,27 @@ int main(int argc, char **argv)
LIBXML_TEST_VERSION
//parse command line input
if (strcmp( argv[1], "print" ))
if (strcmp( argv[1], "print" ) == 0)
{
action.type = PRINT_NAME;
}else if (strcmp( argv[1], "copy" ))
}else if (strcmp( argv[1], "copy" ) == 0)
{
action.type = COPY_FILES;
}else
{
printf("ERROR: unknown action\n");
fprintf(stderr, "ERROR: unknown action\n");
exit(1);
}
for (i = 2; i < argc;)
i = 2;
while ( i < argc)
{
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");
fprintf(stderr, "ERROR: invalic argument list\n");
exit(1);
}else
{
......@@ -103,7 +104,7 @@ int main(int argc, char **argv)
if(false)
{}else
{
printf("ERROR: unknown argument\n");
fprintf(stderr, "ERROR: unknown argument\n");
exit(1);
}
}else
......@@ -113,13 +114,13 @@ int main(int argc, char **argv)
if(false)
{}else
{
printf("ERROR: unknown argument\n");
fprintf(stderr, "ERROR: unknown argument\n");
exit(1);
}
}
}
}else if((i == argc -1 & action.type == PRINT_NAME) |
(i == argc -2 & action.type != PRINT_NAME) )
}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))
......@@ -128,7 +129,7 @@ int main(int argc, char **argv)
exit(1);
}
i++;
}else if((i == argc -1 & action.type != PRINT_NAME))
}else if(((i == argc -1) && (action.type != PRINT_NAME)))
{
if(strcpy_n(action.dest, argv[i], XSPTT_STR_BUFFSIZE))
{
......
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