diff options
author | Matthew Wozniak <me@woz.blue> | 2024-11-04 11:56:25 -0500 |
---|---|---|
committer | Matthew Wozniak <me@woz.blue> | 2024-11-04 13:26:49 -0500 |
commit | 09c6eab77771198f63860aa0c612b324d5ea09d5 (patch) | |
tree | 2eaef4291353ce03f171cb27024f0df3271c651a /main.c | |
parent | 3c19c509af38424cd04df53e1af7ef1b20a191ef (diff) | |
download | rt-09c6eab77771198f63860aa0c612b324d5ea09d5.tar.gz rt-09c6eab77771198f63860aa0c612b324d5ea09d5.zip |
switch from using getopt to mike's opt.h
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 106 |
1 files changed, 57 insertions, 49 deletions
@@ -19,8 +19,7 @@ #include "log.h" #include "render.h" #include "os.h" - -#include "ms/getopt.h" +#include "opt.h" #include <stddef.h> #define WIN32_LEAN_AND_MEAN @@ -29,13 +28,13 @@ struct { int width; int height; - char *game; + const char *game; int fps; int quality; int bitrate; int qvs; - char *out; - char **demo; + const char *out; + const char **demo; bool combine; } args = {0}; @@ -81,45 +80,57 @@ void WINAPI *hook_LoadLibraryExA(const char *filename, void *hfile, int flags) { typedef int (*LauncherMain_t)(void *instance, void *prev_inst, char *cmdline, int cmd_show); -int main(int argc, char **argv) { +void usage() { + const char *usage = + "usage:\n" + " rt [-w <width>] [-h <height>] [-g <game>] [-r <fps>] [-s <qvs>]" + "[-1] [-q <quality>] OR [-b <bitrate>]\n" + " path/to/video.mp4 path/to/demo1.dem..."; + puts(usage); +} + +int main(int argc, const char **argv) { SetDllDirectoryA("bin/"); - int c; + char *strend; - while ((c = getopt(argc, argv, "w:h:g:r:q:b:s:")) != -1) { - switch (c) { - case 'w': - args.width = strtol(optarg, &strend, 10); - if (strend == optarg) die("width must be a number"); - break; - case 'h': - args.height = strtol(optarg, &strend, 10); - if (strend == optarg) die("height must be a number"); - break; - case 'r': - args.fps = strtol(optarg, &strend, 10); - if (strend == optarg) die("fps must be a number"); - break; - case 'q': - args.quality = strtol(optarg, &strend, 10); - if (strend == optarg || args.quality < 1 || args.quality > 100) - die("quality must be a number 1-100"); - break; - case 's': - args.qvs = strtol(optarg, &strend, 10); - if (strend == optarg || args.qvs < 1 || args.qvs > 100) - die("qvs must be a number 1-100"); - break; - case 'b': - args.bitrate = strtol(optarg, &strend, 10); - if (strend == optarg) die("bitrate must be a number"); - break; - case 'g': - args.game = optarg; - case '1': - args.combine = true; - case '?': - break; - } + const char *arg; + FOR_OPTS(argc, argv) { + case 'w': + arg = OPTARG(argc, argv); + args.width = strtol(arg, &strend, 10); + if (strend == arg) die("width must be a number"); + break; + case 'h': + arg = OPTARG(argc, argv); + args.height = strtol(arg, &strend, 10); + if (strend == arg) die("height must be a number"); + break; + case 'r': + arg = OPTARG(argc, argv); + args.fps = strtol(arg, &strend, 10); + if (strend == arg) die("fps must be a number"); + break; + case 'q': + arg = OPTARG(argc, argv); + args.quality = strtol(arg, &strend, 10); + if (strend == arg || args.quality < 1 || args.quality > 100) + die("quality must be a number 1-100"); + break; + case 's': + arg = OPTARG(argc, argv); + args.qvs = strtol(arg, &strend, 10); + if (strend == arg || args.qvs < 1 || args.qvs > 100) + die("qvs must be a number 1-100"); + break; + case 'b': + arg = OPTARG(argc, argv); + args.bitrate = strtol(arg, &strend, 10); + if (strend == arg) die("bitrate must be a number"); + break; + case 'g': + args.game = OPTARG(argc, argv); + case '1': + args.combine = true; } if (!args.width) args.width = 1280; @@ -129,15 +140,12 @@ int main(int argc, char **argv) { if (!args.quality) args.quality = 75; if (!args.qvs) args.qvs = 100; - if (argc - optind < 2) { - printf( - "usage:\n" - " rt [-w <width>] [-h <height>] [-g <game>] [-r <fps>] [-s <qvs>] [-1] [-q <quality>] OR [-b <bitrate>]\n" - " path/to/video.mp4 path/to/demo1.dem...\n"); + if (argc < 2) { + usage(); exit(1); } - args.out = argv[optind++]; - args.demo = argv + optind; + args.out = argv[0]; + args.demo = argv + 1; sprintf(cmdline, "hl2.exe -game %s -w %d -h %d -window -console", args.game, args.width, args.height); |