multi.c 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include "multiproto.h"
  12. struct {
  13. char *name;
  14. void (*fn)(int, char**);
  15. } mains[] =
  16. {
  17. #include "multi.h"
  18. };
  19. void
  20. main(int argc, char **argv)
  21. {
  22. int i;
  23. char *cmd, *p;
  24. if(argc == 1){
  25. fprint(2, "usage: multi cmd args...\n");
  26. exits("usage");
  27. }
  28. cmd = argv[1];
  29. if(p = strrchr(cmd, '/'))
  30. cmd = p+1;
  31. argv++;
  32. argc--;
  33. for(i=0; i<nelem(mains); i++){
  34. if(strcmp(cmd, mains[i].name) == 0){
  35. mains[i].fn(argc, argv);
  36. return;
  37. }
  38. }
  39. fprint(2, "multi: no such cmd %s\n", cmd);
  40. exits("no cmd");
  41. }