ref: 0ce117fceb04b089bad16df2b7b8615dd0157fe7
parent: a5a88b06fa49cfec4d244db55196dbafd35e3f5f
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Feb 17 08:43:09 EST 2020
plan9: add command-line options
--- a/plan9.c
+++ b/plan9.c
@@ -802,7 +802,7 @@
static void
usage(void)
{
- print("usage: %s [-b]\n", argv0);
+ print("usage: %s [-i] [-p] [-b bpm] [-s WxH] [-r random_seed] [FILE]\n", argv0);
threadexitsall("usage");
}
@@ -815,6 +815,7 @@
Mouse m;
char tmp[256];
int oldw, oldh, w, h, n;
+ long seed;
bool inverse;
int movex, movey;
bool shiftdown, complete, ctldown;
@@ -828,15 +829,56 @@
};
inverse = false;
+ srand(time(0));
+ w = h = 0;
+
ARGBEGIN{
- case 'b':
+ case 'i':
inverse = true;
break;
+ case 'p':
+ pause = true;
+ break;
+ case 'b':
+ bpm = atoi(EARGF(usage()));
+ if (bpm < 1) {
+ fprint(2, "invalid bpm %d\n", bpm);
+ threadexitsall("args");
+ }
+ break;
+ case 's':
+ if (sscanf(EARGF(usage()), "%dx%d", &w, &h) != 2)
+ usage();
+ if (w <= 0 || h <= 0 || w > ORCA_X_MAX || h > ORCA_Y_MAX) {
+ fprint(2, "invalid dimensions %dx%d\n", w, h);
+ threadexitsall("args");
+ }
+ break;
+ case 'r':
+ if ((seed = atol(EARGF(usage()))) < 0) {
+ fprint(2, "invalid seed %ld\n", seed);
+ threadexitsall("args");
+ }
+ srand(seed);
+ break;
default:
usage();
}ARGEND
- srand(time(0));
+ if (argc > 1)
+ usage();
+
+ if (argc == 1) {
+ field_init(&field);
+ snprint(filename, sizeof(filename), "%s", argv[0]);
+ if (fieldload(filename) != 0) {
+ fprint(2, "%s: %r\n", filename);
+ threadexitsall("file");
+ }
+ w = field.width;
+ h = field.height;
+ }
+
threadsetname("orca/draw");
if(initdraw(nil, nil, "orca") < 0)
@@ -862,8 +904,12 @@
glyphsz.x = stringwidth(font, "X");
glyphsz.y = font->height;
- screensize(&w, &h);
- field_init_fill(&field, h, w, '.');
+ if (filename[0] == 0) {
+ if (w == 0 || h == 0)
+ screensize(&w, &h);
+ field_init_fill(&field, h, w, '.');
+ }
+
field_init_fill(©field, h, w, '.');
field_init(&selfield);