aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c106
1 files changed, 57 insertions, 49 deletions
diff --git a/main.c b/main.c
index 3d89c08..4775b48 100644
--- a/main.c
+++ b/main.c
@@ -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);