summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/args.c8
-rw-r--r--src/demo.c8
-rw-r--r--src/main.c133
3 files changed, 13 insertions, 136 deletions
diff --git a/src/args.c b/src/args.c
index f995903..8261c81 100644
--- a/src/args.c
+++ b/src/args.c
@@ -212,13 +212,13 @@ void printhelp()
inctype[type]++;
if (pa->flag)
- maxflag[type] = (maxflag[type] > strlen(pa->flag) ? maxflag[type] : strlen(pa->flag));
+ maxflag[type] = ((size_t)maxflag[type] > strlen(pa->flag) ? maxflag[type] : (int)strlen(pa->flag));
if (pa->full)
- maxfull[type] = (maxfull[type] > strlen(pa->full) ? maxfull[type] : strlen(pa->full));
+ maxfull[type] = ((size_t)maxfull[type] > strlen(pa->full) ? maxfull[type] : (int)strlen(pa->full));
if (pa->desc[0])
- maxdesc0[type] = (maxdesc0[type] > strlen(pa->desc[0]) ? maxdesc0[type] : strlen(pa->desc[0]));
+ maxdesc0[type] = ((size_t)maxdesc0[type] > strlen(pa->desc[0]) ? maxdesc0[type] : (int)strlen(pa->desc[0]));
if (pa->desc[1])
- maxdesc1[type] = (maxdesc1[type] > strlen(pa->desc[1]) ? maxdesc1[type] : strlen(pa->desc[1]));
+ maxdesc1[type] = ((size_t)maxdesc1[type] > strlen(pa->desc[1]) ? maxdesc1[type] : (int)strlen(pa->desc[1]));
}
if (inf)
printf("%s\n\n", inf);
diff --git a/src/demo.c b/src/demo.c
index 5de110a..250cd5f 100644
--- a/src/demo.c
+++ b/src/demo.c
@@ -115,7 +115,7 @@ int readdemomap(FILE *fp, demomap *dm, int mapsize, unsigned char ver)
}
dm->data = (char *)malloc(mapsize);
- if (fread(dm->data, 1, mapsize, fp) != mapsize)
+ if (fread(dm->data, 1, mapsize, fp) != (size_t)mapsize)
return -3;
return 1;
@@ -206,7 +206,7 @@ int readdemosnap(FILE *fp, demosnap *snap, int size)
int readdemomessage(FILE *fp, demomessage *message, int size)
{
unsigned char data[size];
- if (fread(data, 1, size, fp) != size)
+ if (fread(data, 1, size, fp) != (size_t)size)
return -1;
message->data = (char *)malloc(size);
@@ -219,7 +219,7 @@ int readdemomessage(FILE *fp, demomessage *message, int size)
int readdemodelta(FILE *fp, demodelta *delta, int size)
{
unsigned char data[size];
- if (fread(data, 1, size, fp) != size)
+ if (fread(data, 1, size, fp) != (size_t)size)
return -1;
delta->data = (char *)malloc(size);
@@ -394,7 +394,7 @@ int writedemomap(FILE *fp, demomap *dm, int mapsize, unsigned char ver)
return -1;
}
- if (fwrite(dm->data, 1, mapsize, fp) != mapsize)
+ if (fwrite(dm->data, 1, mapsize, fp) != (size_t)mapsize)
return -2;
return 1;
diff --git a/src/main.c b/src/main.c
index 0fd0868..a688cb6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,109 +6,6 @@
#include <stdio.h>
#include <stdlib.h>
-int testcompress(char *line)
-{
- char inputbuff[4096];
- char outputbuff[4096];
- char resultbuff[4096];
-
- int inputlen = 0;
- int resultlen = 0;
- char *splitpos = line;
-
- while (*splitpos != '#')
- splitpos++;
-
- while (sscanf(line, "%2hhx", inputbuff + inputlen) == 1 && line < splitpos)
- {
- inputlen++;
- line += 3;
- }
-
- splitpos++;
- while (sscanf(splitpos, "%2hhx", resultbuff + resultlen) == 1)
- {
- resultlen++;
- splitpos += 3;
- }
- int i;
-
- int outputlen = compresshuff(inputbuff, inputlen, outputbuff, 4096);
- if (outputlen < 0)
- {
- printf("[FAILED TEST] Failed compress test! outputbuff too small\n");
- return -1;
- }
-
- if (outputlen != resultlen)
- {
- printf("[FAILED TEST] Failed compress test! different result output length\n");
- return -1;
- }
-
- for (i = 0; i < outputlen; i++)
- {
- if (resultbuff[i] != outputbuff[i])
- {
- printf("[FAILED TEST] Failed compress test!\n");
- return -1;
- }
- }
- return 1;
-}
-
-int testdecompress(char *line)
-{
- char inputbuff[4096];
- char outputbuff[4096];
- char resultbuff[4096];
-
- int inputlen = 0;
- int resultlen = 0;
- char *splitpos = line;
-
- while (*splitpos != '#')
- splitpos++;
-
- while (sscanf(line, "%2hhx", inputbuff + inputlen) == 1 && line < splitpos)
- {
- inputlen++;
- line += 3;
- }
-
- splitpos++;
- while (sscanf(splitpos, "%2hhx", resultbuff + resultlen) == 1)
- {
- resultlen++;
- splitpos += 3;
- }
- int i;
-
- int outputlen = decompresshuff(resultbuff, inputlen, outputbuff, 4096);
- if (outputlen < 0)
- {
- printf("[FAILED TEST] Failed decompress test! Error when decompressing\n");
- return -1;
- }
-
- if (outputlen != inputlen)
- {
- printf("[FAILED TEST] Failed decompress test! different result output length\n");
- printf("[ PROGNOSIS ] inputlen: %d outputlen: %d\n", inputlen, outputlen);
- return -1;
- }
-
- for (i = 0; i < outputlen; i++)
- {
- if (inputbuff[i] != outputbuff[i])
- {
- printf("[FAILED TEST] Failed decompress test! non matching buffers\n");
- return -1;
- }
- }
- return 1;
-}
-
int mapname(char *mappath, char *out)
{
int start = 0;
@@ -159,6 +56,7 @@ void setdemo(arg *argument)
fprintf(stderr, "Error: failed to parse demo\n");
exit(EXIT_FAILURE);
}
+ fclose(demofile);
}
void setmap(arg *argument)
@@ -181,6 +79,7 @@ void setmap(arg *argument)
fprintf(stderr, "Error: map name is too long (> 32)\n");
exit(EXIT_FAILURE);
}
+ fclose(mapfile);
}
void runrename(arg *renamearg)
@@ -225,6 +124,7 @@ void runoutput(arg *outarg)
fprintf(stderr, "Error: failed to write demo file to outputfile\n");
exit(EXIT_FAILURE);
}
+ fclose(outfile);
}
int main(int argc, char *argv[])
@@ -236,8 +136,8 @@ int main(int argc, char *argv[])
addarg("<demo>", "Sets input demo", setdemo);
- addopt("-r", "--rename", 2, "<id> <name>", "Renames player with id to name", NULL);
- addopt("-s", "--skin", 2, "<id> <name>", "Set skin of player with id to skin", NULL);
+ addopt("-r", "--rename", 2, "<id/name> <name>", "Renames player with id/name to name", NULL);
+ addopt("-s", "--skin", 2, "<id/name> <name>", "Set skin of player with id/name to skin", NULL);
addopt("-m", "--map", 1, "<map>", "Changes the map of demo to map", setmap);
addopt("-e", "--extract-map", 1, "<file>", "Saves the map of demo to file", NULL);
addopt("-o", "--output", 1, "<file>", "Saves the output demo to file", NULL);
@@ -311,27 +211,4 @@ int main(int argc, char *argv[])
runoutput(outarg);
exit(EXIT_SUCCESS);
-
- // Testing
- /*
- inithuff(NULL);
-
- FILE *fp = fopen("data/huff_test_cases", "r");
- char *line = NULL;
- size_t len = 0;
- ssize_t nread;
-
- while ((nread = getline(&line, &len, fp)) != -1)
- {
- if (testcompress(line) < 0)
- exit(EXIT_FAILURE);
- if (testdecompress(line) < 0)
- exit(EXIT_FAILURE);
- }
-
- fclose(fp);
- free(line);
-
- exit(EXIT_SUCCESS);
- */
}