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.

113 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. beep.c
  5. Abstract:
  6. User mode beep program. This program simply calls the beep function
  7. Author:
  8. Steve Wood (stevewo) 8-23-94
  9. Revision History:
  10. --*/
  11. #include <windows.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. //
  15. // Local definitions
  16. //
  17. VOID
  18. DisplayUsage( VOID );
  19. DWORD
  20. AsciiToInteger(
  21. char *Number
  22. );
  23. int
  24. __cdecl main(
  25. int argc,
  26. char *argv[]
  27. )
  28. {
  29. char *s;
  30. DWORD dwFreq = 0;
  31. DWORD dwDuration = 0;
  32. while (--argc) {
  33. s = *++argv;
  34. if (*s == '/' || *s == '-') {
  35. DisplayUsage();
  36. exit( 1 );
  37. }
  38. else
  39. if (dwFreq == 0) {
  40. dwFreq = AsciiToInteger( s );
  41. if (dwFreq == 0xFFFFFFFF) {
  42. DisplayUsage();
  43. exit( 1 );
  44. }
  45. }
  46. else
  47. if (dwDuration == 0) {
  48. dwDuration = AsciiToInteger( s );
  49. if (dwDuration == 0xFFFFFFFF) {
  50. DisplayUsage();
  51. exit( 1 );
  52. }
  53. }
  54. }
  55. //
  56. // No bounds checking here. Live with it.
  57. //
  58. if (dwFreq == 0) {
  59. dwFreq = 800;
  60. }
  61. if (dwDuration == 0) {
  62. dwDuration = 200;
  63. }
  64. Beep( dwFreq, dwDuration );
  65. return 0;
  66. }
  67. VOID
  68. DisplayUsage( VOID )
  69. {
  70. printf( "Usage: BEEP frequency(in Hertz) duration(in milliseconds)\n" );
  71. }
  72. DWORD
  73. AsciiToInteger(
  74. char *Number
  75. )
  76. {
  77. int total = 0;
  78. while ( *Number != '\0' ) {
  79. if ( *Number >= '0' && *Number <= '9' ) {
  80. total = total * 10 + *Number - '0';
  81. Number++;
  82. } else {
  83. total = -1;
  84. break;
  85. }
  86. }
  87. return total;
  88. }