Skip to content

Commit

Permalink
auto format for test/*.c
Browse files Browse the repository at this point in the history
  • Loading branch information
gdraheim committed May 26, 2024
1 parent 966a5a2 commit c54828e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 109 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ checkversion versions:

# format ..............................
CLANG_FORMAT=clang-format
format ff: ; $(CLANG_FORMAT) -i zzip/*.h zzip/*.c bins/*.h bins/*.c
format ff: ; $(CLANG_FORMAT) -i zzip/*.h zzip/*.c bins/*.h bins/*.c test/*.c

FORMATDIR=../zziplib-format
formatdir:
Expand Down
105 changes: 48 additions & 57 deletions test/zzipself.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,76 @@
* Use freely under the restrictions of the ZLIB License
*/

#include <zzip/zzip.h>
#include <stdio.h>
#include <stdlib.h>
#include <zzip/zzip.h>

#ifndef O_BINARY
#define O_BINARY 0
#endif

static const char usage[] =
{
" zzipself <file>... \n"
" - prints the file to stdout, so you may want to redirect the output; \n"
" the file can be a normal file or an inflated part of a zip-archive, \n"
" however in this case the zip-archive happens to be the executed\n"
" binary itself, as if this program is a self-extract header of a zip. \n"
" zzipself README # same as # zzcat zzipself/README \n"
};
static const char usage[] = /* .. */
{" zzipself <file>... \n"
" - prints the file to stdout, so you may want to redirect the output; \n"
" the file can be a normal file or an inflated part of a zip-archive, \n"
" however in this case the zip-archive happens to be the executed\n"
" binary itself, as if this program is a self-extract header of a zip. \n"
" zzipself README # same as # zzcat zzipself/README \n"};

int
main (int argc, char ** argv)
int
main(int argc, char** argv)
{
int status = 0;
int status = 0;
int argn;
if (argc <= 1)
{
printf (usage);
exit (0);
if (argc <= 1) {
printf(usage);
exit(0);
}

for (argn=1; argn < argc; argn++)
{
/* ZZIP_FILE* fp = zzip_fopen (argv[0]+"/"+argv[argn], "rbi"); */
/* .... = zzip_open (argv[0]+"/"+argv[argn], O_RDONLY|O_BINARY,
* ZZIP_CASELESS|ZZIP_ONLYZIP, ext, 0); */

static const char* ext[] = { "", ".exe", ".EXE", 0 };
ZZIP_FILE* fp;
ZZIP_DIR* zip = zzip_opendir_ext_io (argv[0],
ZZIP_CASELESS|ZZIP_ONLYZIP, ext, 0);
for (argn = 1; argn < argc; argn++) {
/* ZZIP_FILE* fp = zzip_fopen (argv[0]+"/"+argv[argn], "rbi"); */
/* .... = zzip_open (argv[0]+"/"+argv[argn], O_RDONLY|O_BINARY,
* ZZIP_CASELESS|ZZIP_ONLYZIP, ext, 0); */

if (! zip) { perror(argv[0]); break; }
static const char* ext[] = {"", ".exe", ".EXE", 0};
ZZIP_FILE* fp;
ZZIP_DIR* zip = zzip_opendir_ext_io(argv[0], /* .. */
ZZIP_CASELESS | ZZIP_ONLYZIP, ext, 0);

fp = zzip_file_open (zip, argv[argn], ZZIP_CASELESS);
if (! zip) {
perror(argv[0]);
break;
}

fp = zzip_file_open(zip, argv[argn], ZZIP_CASELESS);

if (! fp)
{
perror (argv[argn]);
if (! fp) {
perror(argv[argn]);
continue;
}else{
}
else {
char buf[17];
int n;
int n;

/* read chunks of 16 bytes into buf and print them to stdout */
while (0 < (n = zzip_read(fp, buf, 16)))
{
/* read chunks of 16 bytes into buf and print them to stdout */
while (0 < (n = zzip_read(fp, buf, 16))) {
buf[n] = '\0';
# ifdef STDOUT_FILENO
write (STDOUT_FILENO, buf, n);
# else
fwrite (buf, 1, n, stdout);
# endif
#ifdef STDOUT_FILENO
write(STDOUT_FILENO, buf, n);
#else
fwrite(buf, 1, n, stdout);
#endif
}

if (n == -1)
{
perror (argv[argn]);
status ++;
}
if (n == -1) {
perror(argv[argn]);
status++;
}
}

zzip_file_close (fp);
zzip_closedir (zip);
zzip_file_close(fp);
zzip_closedir(zip);
}

return status;
}

/*
* Local variables:
* c-file-style: "stroustrup"
* End:
*/
return status;
}
107 changes: 56 additions & 51 deletions test/zzipsetstub.c
Original file line number Diff line number Diff line change
@@ -1,61 +1,66 @@
#include <stdio.h>
#include <stdlib.h>

static const char usage[] =
{
"zzipsetstub <zipfile> <zipsfxstub>... \n"
" overwrite the header of the zipfile with the sfxstub code.\n"
" this is usually the last step in creating a selfextract archive\n"
" or an application with all its data appended as a zip.\n"
};

int
main (int argc, char ** argv)
static const char usage[] = /* .. */
{"zzipsetstub <zipfile> <zipsfxstub>... \n"
" overwrite the header of the zipfile with the sfxstub code.\n"
" this is usually the last step in creating a selfextract archive\n"
" or an application with all its data appended as a zip.\n"};

int
main(int argc, char** argv)
{
int argn;
if (argc <= 2)
{
printf (usage);
exit (0);
if (argc <= 2) {
printf(usage);
exit(0);
}

{
char buf[17]; int n;
char* zipfile = 0; FILE* zipFILE = 0;
char* sfxfile = 0; FILE* sfxFILE = 0;

for (argn=1; argn < argc; argn++)
{
if (argv[argn][0] == '-') continue;
if (! zipfile) { zipfile = argv[argn]; continue; }
if (! sfxfile) { sfxfile = argv[argn]; continue; }
/* superflous argument */
}

zipFILE = fopen (zipfile, "r+b");
if (! zipFILE) { perror (zipfile); return 1; }

sfxFILE = fopen (sfxfile, "rb");
if (! sfxFILE) { perror (sfxfile); return 1; }

while (0 < (n = fread(buf, 1, 16, sfxFILE)))
{
buf[n] = '\0';
fwrite (buf, 1, n, zipFILE);
}

if (n == -1)
perror (argv[argn]);

fclose (sfxFILE);
fclose (zipFILE);
char buf[17];
int n;
char* zipfile = 0;
FILE* zipFILE = 0;
char* sfxfile = 0;
FILE* sfxFILE = 0;

for (argn = 1; argn < argc; argn++) {
if (argv[argn][0] == '-')
continue;
if (! zipfile) {
zipfile = argv[argn];
continue;
}
if (! sfxfile) {
sfxfile = argv[argn];
continue;
}
/* superflous argument */
}

zipFILE = fopen(zipfile, "r+b");
if (! zipFILE) {
perror(zipfile);
return 1;
}

sfxFILE = fopen(sfxfile, "rb");
if (! sfxFILE) {
perror(sfxfile);
return 1;
}

while (0 < (n = fread(buf, 1, 16, sfxFILE))) {
buf[n] = '\0';
fwrite(buf, 1, n, zipFILE);
}

if (n == -1)
perror(argv[argn]);

fclose(sfxFILE);
fclose(zipFILE);
}

return 0;
}

/*
* Local variables:
* c-file-style: "stroustrup"
* End:
*/
return 0;
}

0 comments on commit c54828e

Please sign in to comment.