home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ZOO21E.EXE / MSC.C < prev    next >
C/C++ Source or Header  |  1991-07-14  |  2KB  |  88 lines

  1. /* @(#) msc.c 1.2 91/07/14 16:08:54 */
  2.  
  3. #include <stdio.h>        /* to get fileno() */
  4. #include <stdlib.h>
  5. #include <signal.h>
  6.  
  7. #ifdef OS2
  8. #define INCL_BASE
  9. #include <os2.h>
  10. #else
  11. #include <dos.h>
  12. #endif
  13.  
  14. void dosname PARMS((char *, char *));
  15.  
  16. /****************
  17. function zootrunc() truncates a file at the current seek position.
  18. */
  19.  
  20. int zootrunc (f)
  21. FILE *f;
  22. {
  23.     int handle = fileno(f);
  24.     extern long tell();
  25.     extern int chsize();
  26.     return chsize(handle, tell(handle));
  27. }
  28.  
  29. /****************
  30. Function fixfname() converts the supplied filename to a syntax
  31. legal for the host system.  It is used during extraction.
  32. */
  33.  
  34. char *fixfname(fname)
  35. char *fname;
  36. {
  37.     char tmpname[PATHSIZE];
  38. #ifdef OS2
  39.         if ( IsFileNameValid(fname) )
  40.       return(fname);
  41. #endif
  42.     dosname (nameptr(fname), tmpname);
  43.     strcpy(fname,tmpname);
  44.     return(fname);
  45. }
  46.  
  47. static int set_break (int flag)
  48. {
  49. #ifdef OS2
  50.     KBDINFO info;
  51.     int ret;
  52.  
  53.     info.cb = sizeof(info);
  54.     KbdGetStatus(&info, 0);
  55.     ret = info.fsMask & 0x0f;
  56.     info.fsMask = flag ? KEYBOARD_ECHO_OFF | KEYBOARD_BINARY_MODE
  57.                            : KEYBOARD_ECHO_ON  | KEYBOARD_ASCII_MODE;
  58.     KbdSetStatus(&info, 0); /* keyboard in new mode */
  59.     return ret;
  60. #else
  61.     int retval;
  62.     union REGS regs;
  63.  
  64.     regs.x.ax = 0x3300;                /* get ctrl-break flag */
  65.     intdos (®s, ®s);
  66.     retval = regs.h.dl;                /* retval is old value of setting */
  67.     regs.x.ax = 0x3301;                /* set ctrl-break flag */
  68.     regs.h.dl = flag;                /* status to set to */
  69.     intdos (®s, ®s);
  70.     return (retval);
  71. #endif
  72. }
  73.  
  74. static int break_flag;
  75.  
  76. void zooexit (int status)
  77. {
  78.     set_break (break_flag);            /* restore control_break setting */
  79.     exit (status);
  80. }
  81.  
  82. void spec_init(void)
  83. {
  84.     break_flag = set_break (0);
  85.     signal (SIGINT, zooexit);        /* install our own Control-C handler */
  86.     signal (SIGBREAK, zooexit);        /* install our own Control-Break handler */
  87. }
  88.