github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/cmd/dist/main.c (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #include "a.h" 6 7 int vflag; 8 char *argv0; 9 10 // cmdtab records the available commands. 11 static struct { 12 char *name; 13 void (*f)(int, char**); 14 } cmdtab[] = { 15 {"banner", cmdbanner}, 16 {"bootstrap", cmdbootstrap}, 17 {"clean", cmdclean}, 18 {"env", cmdenv}, 19 {"install", cmdinstall}, 20 {"version", cmdversion}, 21 }; 22 23 // The OS-specific main calls into the portable code here. 24 void 25 xmain(int argc, char **argv) 26 { 27 int i; 28 29 if(argc <= 1) 30 usage(); 31 32 for(i=0; i<nelem(cmdtab); i++) { 33 if(streq(cmdtab[i].name, argv[1])) { 34 cmdtab[i].f(argc-1, argv+1); 35 return; 36 } 37 } 38 39 xprintf("unknown command %s\n", argv[1]); 40 usage(); 41 }