Leaked source code of windows server 2003
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.

105 lines
2.3 KiB

  1. #include "string.h"
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <process.h>
  5. #include <windows.h>
  6. #include <tools.h>
  7. /* YNC is a Yes No Cancel program
  8. * ===============================================================================
  9. * Usage: ync [/c choices] text ...
  10. *
  11. * "choices" is a string of characters, default "ync".
  12. * YNC echos its text parameters and the text " [choices]" and waits for the
  13. * user to type one of the choices. When one of the choices is typed, the
  14. * index of the choice is returned.
  15. *
  16. * Rtns -1 if no parameters specified or /c but no choices or CONTROL-C input.
  17. *
  18. * Beeps on all other input.
  19. *
  20. * Good for use in make batch files.cd \lib
  21. *
  22. * ync your query?
  23. * if errorlevel 2 goto cancel
  24. * if errorlevel 1 goto no
  25. * :yes
  26. * ...
  27. * goto continue
  28. * :no
  29. * ...
  30. * goto continue
  31. * :cancel
  32. * ...
  33. * :continue
  34. *
  35. * or
  36. * ync /c acr abort cancel, retry
  37. * ync /c acr "abort cancel, retry"
  38. */
  39. #define BEL 0x07
  40. #define LF 0x0a
  41. #define CR 0x0d
  42. #define CTRLC 0x03
  43. char *strYNC = "ync";
  44. // Forward Function Declarations...
  45. void chkusage( int );
  46. void chkusage(argc)
  47. int argc;
  48. {
  49. if (!argc) {
  50. printf("Usage: ync [/c choices] text ...\n");
  51. exit (-1);
  52. }
  53. }
  54. __cdecl main(argc, argv)
  55. int argc;
  56. char *argv[];
  57. {
  58. char ch;
  59. char *s;
  60. char *pChoices = strYNC;
  61. ConvertAppToOem( argc, argv );
  62. SHIFT(argc, argv)
  63. chkusage(argc);
  64. while (argc) {
  65. s = argv[0];
  66. if (fSwitChr(*s++)) {
  67. if (*s == 'c' || *s == 'C') {
  68. SHIFT(argc, argv);
  69. chkusage(argc);
  70. pChoices = argv[0];
  71. }
  72. else
  73. printf("ync: invalid switch - %s\n", argv[0]);
  74. }
  75. else {
  76. _cputs(*argv);
  77. _putch(' ');
  78. }
  79. SHIFT(argc, argv);
  80. }
  81. _putch('[');
  82. _cputs(pChoices);
  83. _putch(']');
  84. while (!(s = strchr(pChoices, ch = (char)_getch()))) {
  85. if (ch == CTRLC) {
  86. exit(-1);
  87. } else {
  88. _putch(BEL);
  89. }
  90. }
  91. _putch(ch);
  92. _putch(LF);
  93. _putch(CR);
  94. return( (int)(s - pChoices) );
  95. }