aboutsummaryrefslogtreecommitdiff
path: root/hcalc.c
blob: beae271148b941aa84fe8a448469c79befb8cd7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Copyright 1998 DJ Delorie <dj@delorie.com>
   Distributed under the terms of the GNU GPL
   http://www.delorie.com/store/hcalc/
   Revisions copyright 2007,  
   Theodore Kilgore <kilgota@auburn.edu>
	More revisions copyright 2023, B. Watson <urchlay@slackware.uk>
*/
#include <stdlib.h>
#include <string.h>
#include "hcalc.h"

char *self;

void version(void) {
	printf("%s %s\n", SELF, VERSION);
	exit(0);
}

void usage(const char *self, const char *msg) {
	if(msg)
		fprintf(stderr, "%s: %s\n", self, msg);
	printf
		("%s %s\nUsage: %s [-default] [-small|-medium|-large] [-dec|-hex|-oct|-bin] [-quiet] [--version] [--help]\n",
		 SELF, VERSION, self);
	exit(msg != NULL);
}

int main(int argc, char **argv) {
	self = argv[0];

	setbuf(stdout, 0);

	if(argc >= 2 && strcmp(argv[1], "-default") == 0) {
		/* don't load the config file */
	} else {
		load_config();
	}
	atexit(save_config);

	while(argv++, --argc) {
		if(strcmp(*argv, "-small") == 0)
			winsize = 0;
		else if(strcmp(*argv, "-medium") == 0)
			winsize = 1;
		else if(strcmp(*argv, "-large") == 0)
			winsize = 2;
		else if(strcmp(*argv, "-dec") == 0)
			base = 10;
		else if(strcmp(*argv, "-hex") == 0)
			base = 16;
		else if(strcmp(*argv, "-oct") == 0)
			base = 8;
		else if(strcmp(*argv, "-bin") == 0)
			base = 2;
		else if(strcmp(*argv, "-quiet") == 0)
			quiet = 1;
		else if(strcmp(*argv, "--help") == 0)
			usage(self, NULL);
		else if(strcmp(*argv, "--version") == 0)
			version();
		else if(strcmp(*argv, "-default") == 0) {	/* do nothing */
		} else
			usage(self, "Invalid command-line option %s");
	}

	setup_x();
	load_pixmaps();
	process_input();
}