diff --git a/GNUmakefile b/GNUmakefile index f11edf9..29f131e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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: diff --git a/test/zzipself.c b/test/zzipself.c index 2cd115e..f0d843f 100644 --- a/test/zzipself.c +++ b/test/zzipself.c @@ -3,85 +3,76 @@ * Use freely under the restrictions of the ZLIB License */ +#include #include #include -#include #ifndef O_BINARY #define O_BINARY 0 #endif -static const char usage[] = -{ - " zzipself ... \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 ... \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; +} diff --git a/test/zzipsetstub.c b/test/zzipsetstub.c index 5d5ad0c..d84a6d3 100644 --- a/test/zzipsetstub.c +++ b/test/zzipsetstub.c @@ -1,61 +1,66 @@ #include #include -static const char usage[] = -{ - "zzipsetstub ... \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 ... \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; +}