summaryrefslogtreecommitdiff
path: root/src/cmd/dist/main.c
blob: fad01802a5952b6c2456d8d3b848dea4757b1fd5 (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
// Copyright 2012 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "a.h"

int vflag;
int sflag;
char *argv0;

// cmdtab records the available commands.
static struct {
	char *name;
	void (*f)(int, char**);
} cmdtab[] = {
	{"banner", cmdbanner},
	{"bootstrap", cmdbootstrap},
	{"clean", cmdclean},
	{"env", cmdenv},
	{"install", cmdinstall},
	{"version", cmdversion},
};

// The OS-specific main calls into the portable code here.
void
xmain(int argc, char **argv)
{
	int i;

	if(argc <= 1)
		usage();
	
	for(i=0; i<nelem(cmdtab); i++) {
		if(streq(cmdtab[i].name, argv[1])) {
			cmdtab[i].f(argc-1, argv+1);
			return;
		}
	}

	xprintf("unknown command %s\n", argv[1]);
	usage();
}