mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-18 04:10:57 +01:00
migrate to codeberg (#21)
This commit is contained in:
@@ -19,26 +19,25 @@
|
||||
You can contact me by mail: <tlinden AT cpan DOT org>.
|
||||
*/
|
||||
|
||||
|
||||
#include "z85util.h"
|
||||
|
||||
int pcpz85_encode(char *infile, char *outfile) {
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
|
||||
if(infile == NULL)
|
||||
if (infile == NULL)
|
||||
in = stdin;
|
||||
else {
|
||||
if((in = fopen(infile, "rb")) == NULL) {
|
||||
if ((in = fopen(infile, "rb")) == NULL) {
|
||||
fatal(ptx, "Could not open input file %s\n", infile);
|
||||
goto errz1;
|
||||
}
|
||||
}
|
||||
|
||||
if(outfile == NULL)
|
||||
if (outfile == NULL)
|
||||
out = stdout;
|
||||
else {
|
||||
if((out = fopen(outfile, "wb+")) == NULL) {
|
||||
if ((out = fopen(outfile, "wb+")) == NULL) {
|
||||
fatal(ptx, "Could not open output file %s\n", outfile);
|
||||
goto errz1;
|
||||
}
|
||||
@@ -47,18 +46,18 @@ int pcpz85_encode(char *infile, char *outfile) {
|
||||
byte *input = NULL;
|
||||
size_t inputBufSize = 0;
|
||||
byte onebyte[1];
|
||||
|
||||
while(!feof(in)) {
|
||||
if(!fread(&onebyte, 1, 1, in))
|
||||
|
||||
while (!feof(in)) {
|
||||
if (!fread(&onebyte, 1, 1, in))
|
||||
break;
|
||||
byte *tmp = realloc(input, inputBufSize + 1);
|
||||
input = tmp;
|
||||
memmove(&input[inputBufSize], onebyte, 1);
|
||||
inputBufSize ++;
|
||||
inputBufSize++;
|
||||
}
|
||||
fclose(in);
|
||||
|
||||
if(inputBufSize == 0) {
|
||||
if (inputBufSize == 0) {
|
||||
fatal(ptx, "Input file is empty!\n");
|
||||
goto errz2;
|
||||
}
|
||||
@@ -66,9 +65,9 @@ int pcpz85_encode(char *infile, char *outfile) {
|
||||
size_t zlen;
|
||||
char *encoded = pcp_z85_encode(input, inputBufSize, &zlen, 1);
|
||||
|
||||
if(encoded != NULL) {
|
||||
if (encoded != NULL) {
|
||||
fprintf(out, "%s\n%s\n%s\n", PCP_ZFILE_HEADER, encoded, PCP_ZFILE_FOOTER);
|
||||
if(ferror(out) != 0) {
|
||||
if (ferror(out) != 0) {
|
||||
fatal(ptx, "Failed to write z85 output!\n");
|
||||
}
|
||||
free(encoded);
|
||||
@@ -77,33 +76,30 @@ int pcpz85_encode(char *infile, char *outfile) {
|
||||
|
||||
return 0;
|
||||
|
||||
errz2:
|
||||
errz2:
|
||||
free(input);
|
||||
|
||||
errz1:
|
||||
errz1:
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int pcpz85_decode(char *infile, char *outfile) {
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
|
||||
if(infile == NULL)
|
||||
if (infile == NULL)
|
||||
in = stdin;
|
||||
else {
|
||||
if((in = fopen(infile, "rb")) == NULL) {
|
||||
if ((in = fopen(infile, "rb")) == NULL) {
|
||||
fatal(ptx, "Could not open input file %s\n", infile);
|
||||
goto errdz1;
|
||||
}
|
||||
}
|
||||
|
||||
if(outfile == NULL)
|
||||
if (outfile == NULL)
|
||||
out = stdout;
|
||||
else {
|
||||
if((out = fopen(outfile, "wb+")) == NULL) {
|
||||
if ((out = fopen(outfile, "wb+")) == NULL) {
|
||||
fatal(ptx, "Could not open output file %s\n", outfile);
|
||||
goto errdz1;
|
||||
}
|
||||
@@ -111,20 +107,17 @@ int pcpz85_decode(char *infile, char *outfile) {
|
||||
|
||||
char *encoded = pcp_readz85file(ptx, in);
|
||||
|
||||
if(encoded == NULL)
|
||||
if (encoded == NULL)
|
||||
goto errdz1;
|
||||
|
||||
size_t clen;
|
||||
byte *decoded = pcp_z85_decode(ptx, encoded, &clen);
|
||||
|
||||
|
||||
|
||||
if(decoded == NULL)
|
||||
if (decoded == NULL)
|
||||
goto errdz2;
|
||||
|
||||
|
||||
fwrite(decoded, clen, 1, out);
|
||||
fclose(out);
|
||||
if(ferror(out) != 0) {
|
||||
if (fclose(out) != 0) {
|
||||
fatal(ptx, "Failed to write decoded output!\n");
|
||||
goto errdz3;
|
||||
}
|
||||
@@ -133,12 +126,12 @@ int pcpz85_decode(char *infile, char *outfile) {
|
||||
free(decoded);
|
||||
return 0;
|
||||
|
||||
errdz3:
|
||||
errdz3:
|
||||
free(decoded);
|
||||
|
||||
errdz2:
|
||||
errdz2:
|
||||
free(encoded);
|
||||
|
||||
errdz1:
|
||||
errdz1:
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user