Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.5 KiB

  1. #include <stdio.h>
  2. #include <windef.h>
  3. #include <winbase.h>
  4. #include <nls.h>
  5. #include "nlstxt.h"
  6. char * optarg;
  7. int optind = 1;
  8. int optinx = 1;
  9. int opterr;
  10. int
  11. getopt(
  12. int ac,
  13. char * av[],
  14. char * opts_allowed)
  15. {
  16. char option;
  17. static char NoOpt[] = "";
  18. optarg = NoOpt;
  19. if (optind >= ac)
  20. return(-1);
  21. if (*av[optind] != '-')
  22. return(-1);
  23. option = av[optind][optinx];
  24. while ((*opts_allowed ) && (*opts_allowed != option))
  25. opts_allowed ++;
  26. if (!*opts_allowed)
  27. {
  28. NlsPutMsg(STDOUT, LIBUEMUL_OPTION_INVALID, option);
  29. return((int) '?');
  30. }
  31. if ( *(opts_allowed + 1) == ':') // there's an argument
  32. {
  33. if (av[optind][optinx+1] == '\0') // the argument is in the next av[]
  34. {
  35. optind++;
  36. optinx = 1;
  37. optarg = av[optind];
  38. }
  39. else
  40. {
  41. optarg = &av[optind][optinx+1];
  42. }
  43. if (optarg == NULL)
  44. {
  45. NlsPutMsg(STDOUT, LIBUEMUL_OPTION_MORE_ARGS, option);
  46. optarg = NoOpt;
  47. return((int) '?');
  48. }
  49. optind++;
  50. optinx = 1;
  51. }
  52. else
  53. {
  54. if (av[optind][optinx+1] == '\0') // no more args for this -
  55. {
  56. optind++;
  57. optinx = 1;
  58. }
  59. else // more args for this -
  60. {
  61. optinx++;
  62. }
  63. }
  64. return((int) option);
  65. }