home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Workbench / Archivers / UnAce.lha / Src / Uac_sys.c < prev    next >
C/C++ Source or Header  |  1997-12-10  |  3KB  |  104 lines

  1. /* ------------------------------------------------------------------------ */
  2. /*                                                                          */
  3. /*      Some basic things.                                                  */
  4. /*                                                                          */
  5. /* ------------------------------------------------------------------------ */
  6.  
  7. #include "os.h"
  8.  
  9. #include <signal.h>  // signal()
  10. #include <stdio.h>   // fprintf() fflush() getch() putc()
  11.  
  12. #if defined(DOS) || defined(WIN32) || defined(WIN16)
  13.  #include <conio.h>  // getch()
  14. #endif
  15. #if defined(DOS)
  16.  #include <dos.h>    // delay() sound()
  17. #endif
  18.  
  19. #include "globals.h"
  20. #include "uac_sys.h"
  21.  
  22.  
  23. void memset16(USHORT * dest, SHORT val, INT len)  // fills short-array with
  24. {                                                 // value
  25.    while (len--)
  26.       *(dest++) = val;
  27. }
  28.  
  29. INT  cancel(void)               // checks whether to interrupt the program
  30. {
  31. #ifdef DOS
  32.    while (kbhit())
  33.    {
  34.       if (getch() == 27)
  35.          f_err = ERR_USER;
  36.    }
  37. #endif
  38.    return (f_err);
  39. }
  40.  
  41. INT  wrask(CHAR * s)            // prompt-routine
  42. {
  43.    INT  ch;
  44.  
  45.    fprintf(stderr, "\n %s (Yes,Always,No,Cancel) ", s);
  46.    fflush(stderr);
  47.    do
  48.    {
  49.       ch = getch();
  50.       ch = upcase(ch);
  51.    }
  52.    while (ch != 'Y' && ch != 'A' && ch != 'N' && ch != 'C' && ch != 27);
  53.    fprintf(stderr, "%s", ch == 'Y' ? "Yes" : (ch == 'A' ? "Always" : (ch == 'N' ? "No" : "Cancel")));
  54.    fflush(stderr);
  55.    return (ch == 'Y' ? 0 : (ch == 'A' ? 1 : (ch == 'N' ? 2 : 3)));
  56. }
  57.  
  58. void beep(void)                        // makes some noise
  59. {
  60. #ifdef DOS
  61.    sound(800);
  62.    delay(250);
  63.    nosound();
  64. #endif
  65. #ifdef AMIGA
  66.    putc(0x07, stderr);
  67. #endif
  68. }
  69.  
  70. void my_signalhandler(INT sig_number)  // sets f_err if ctrl+c or ctrl+brk
  71. {
  72.    f_err = ERR_USER;
  73.    printf("\nUser break\n");
  74. }
  75.  
  76. #ifdef DOS                             // handles hardware errors
  77. #ifdef __BORLANDC__
  78. INT harderrhandler(UINT deverr, UINT errc, UINT * devhdr)
  79. #else
  80. INT __far harderrhandler(UINT deverr, UINT errc, UINT * devhdr)
  81. #endif
  82. {
  83.    f_criterr = 'A' + deverr & 0xff;
  84.    f_err = ERR_OTHER;
  85.    return (0x3);
  86. }
  87. #endif
  88.  
  89. void set_handler(void)                 // initializes handlers
  90. {
  91. #if defined(DOS) && !defined(__BORLANDC__)
  92.    signal(SIGBREAK, my_signalhandler); // set ctrl-break/-c handlers
  93. #endif
  94.    signal(SIGINT, my_signalhandler);
  95. #ifdef DOS                             // set hardware error handler
  96. #ifdef __BORLANDC__
  97.    harderr(harderrhandler);
  98. #else
  99.    _harderr(harderrhandler);
  100. #endif
  101. #endif
  102. }
  103.  
  104.