fix naming

This commit is contained in:
2025-03-23 20:01:00 +03:00
parent 6d653ae183
commit f88718422e

View File

@@ -7,23 +7,15 @@
#include <getopt.h> #include <getopt.h>
#include <sys/stat.h> #include <sys/stat.h>
/*
TODO
Usage:
kpack [--nologo / -n] [--kernel / -k] [--unpack / -u] <infile> [<outfile>]
*/
static const char* str_usage = "Usage: %s [--nologo / -n] [--kernel / -k] [--unpack / -u] <infile> [<outfile>]\n"; static const char* str_usage = "Usage: %s [--nologo / -n] [--kernel / -k] [--unpack / -u] <infile> [<outfile>]\n";
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
bool nologo = false; bool flag_nologo = false;
bool kernel = false; bool flag_kernel = false;
bool unpack = false; bool flag_unpack = false;
char *infile = NULL; char *infile_name = NULL;
char *outfile = NULL; char *outfile_name = NULL;
int opt; int opt;
static struct option long_options[] = { static struct option long_options[] = {
{"nologo", no_argument, NULL, 'n'}, {"nologo", no_argument, NULL, 'n'},
@@ -34,13 +26,13 @@ int main(int argc, char *argv[])
while ((opt = getopt_long(argc, argv, "nku", long_options, NULL)) != -1) { while ((opt = getopt_long(argc, argv, "nku", long_options, NULL)) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
nologo = true; flag_nologo = true;
break; break;
case 'k': case 'k':
kernel = true; flag_kernel = true;
break; break;
case 'u': case 'u':
unpack = true; flag_unpack = true;
break; break;
default: // '?' default: // '?'
fprintf(stderr, str_usage, argv[0]); fprintf(stderr, str_usage, argv[0]);
@@ -53,11 +45,11 @@ int main(int argc, char *argv[])
printf(str_usage, argv[0]); printf(str_usage, argv[0]);
return 1; return 1;
} }
infile = argv[optind]; infile_name = argv[optind];
// Optional outfile // Optional outfile
if (optind + 1 < argc) { if (optind + 1 < argc) {
outfile = argv[optind + 1]; outfile_name = argv[optind + 1];
optind++; optind++;
} }
@@ -69,19 +61,19 @@ int main(int argc, char *argv[])
} }
// for debug: print parsed options and args // for debug: print parsed options and args
printf("nologo: %s\n", nologo ? "true" : "false"); printf("nologo: %s\n", flag_nologo ? "true" : "false");
printf("kernel: %s\n", kernel ? "true" : "false"); printf("kernel: %s\n", flag_kernel ? "true" : "false");
printf("unpack: %s\n", unpack ? "true" : "false"); printf("unpack: %s\n", flag_unpack ? "true" : "false");
printf("infile: %s\n", infile); printf("infile: %s\n", infile_name);
printf("outfile: %s\n", outfile ? outfile : "Not specified"); printf("outfile: %s\n", outfile_name ? outfile_name : "Not specified");
printf("\n"); printf("\n");
if (!nologo) { if (!flag_nologo) {
printf("KPackC - Kolibri Packer in C\nUses LZMA v4.32 compression library\n\n"); printf("KPackC - Kolibri Packer in C\nUses LZMA v4.32 compression library\n\n");
} }
struct stat64 statbuf; struct stat64 statbuf;
int res_stat = stat64(infile, &statbuf); int res_stat = stat64(infile_name, &statbuf);
if (res_stat == -1) { if (res_stat == -1) {
printf("Error: cannot load input file\n"); printf("Error: cannot load input file\n");
return 1; return 1;
@@ -95,7 +87,7 @@ int main(int argc, char *argv[])
unsigned infile_size = (unsigned int)statbuf.st_size; unsigned infile_size = (unsigned int)statbuf.st_size;
printf("infile_size = %u\n", infile_size); printf("infile_size = %u\n", infile_size);
FILE *infile_handle = fopen(infile, "rb"); FILE *infile_handle = fopen(infile_name, "rb");
if (!infile_handle) { if (!infile_handle) {
printf("Error: cannot load input file\n"); printf("Error: cannot load input file\n");
return 1; return 1;