home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / bm332c.zip / PC.C < prev    next >
C/C++ Source or Header  |  1993-02-24  |  3KB  |  120 lines

  1. /* This file contains IBM PC specific functions
  2.    for the Turbo C 2.0 compiler.
  3.  
  4.    Last changed: 1993 Jan 11 by Costas Krallis SV1XV:
  5.         removed all non-DOS non TCC stuff.
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. /* directory search utility for DOS */
  11.  
  12. #include <sys/stat.h>
  13. #include <dos.h>
  14. #include <conio.h>
  15. #define ST_RDONLY    0x01    /* read only file */
  16. #define ST_HIDDEN    0x02    /* hidden file */
  17. #define ST_SYSTEM    0x04    /* system file */
  18. #define ST_VLABEL    0x08    /* volume label */
  19. #define ST_DIRECT    0x10    /* file is a sub-directory */
  20. #define ST_ARCHIV    0x20    /* set when file has been written and closed */
  21.  
  22. #define REGFILE    (ST_HIDDEN|ST_SYSTEM|ST_DIRECT)
  23. #define    SET_DTA        0x1a
  24. #define    FIND_FIRST    0x4e
  25. #define    FIND_NEXT    0x4f
  26.  
  27. struct dirent {
  28.     char rsvd[21];
  29.     char attr;
  30.     short ftime;
  31.     short fdate;
  32.     long fsize;
  33.     char fname[13];
  34. };
  35.  
  36. /* wildcard filename lookup */
  37. int filedir(char *name, int times, char *ret_str)
  38. {
  39.     register char *cp,*cp1;
  40.     static struct dirent sbuf;
  41.     union REGS regs;
  42.  
  43.     bdos(SET_DTA,(unsigned)&sbuf,0);    /* Set disk transfer address */
  44.  
  45.     regs.h.ah = (times == 0) ? FIND_FIRST : FIND_NEXT;
  46.     regs.x.dx = (unsigned int) name;
  47.     regs.x.cx = (unsigned int) REGFILE;
  48.     intdos(®s,®s);
  49.     if (regs.x.cflag) 
  50.         sbuf.fname[0] = '\0';
  51.  
  52.     /* Copy result to output, forcing to lower case */
  53.     for(cp = ret_str,cp1 = sbuf.fname; cp1 < &sbuf.fname[13] && *cp1 != '\0';)
  54.         *cp++ = tolower(*cp1++);
  55.     *cp = '\0';
  56. }
  57.  
  58. /* This function should put the TTY in a mode such that signgle characters
  59. * can be read without waiting for a complete line. Echo should be on.
  60. */
  61. int setrawmode(void)
  62. {}
  63.  
  64. /* This function should restore the TTY modes back to cooked mode */
  65. int setcookedmode(void)
  66. {}
  67.  
  68. /* This function return one charater form the keyboard. It will wait
  69. * for a character to be input. This function will echo the character.
  70. * This funtion will return after each character is typed if rawmode is set
  71. */
  72. int getrch(void)
  73. {
  74.     return(bdos(1,0,0) & 0xff);
  75. }
  76.  
  77.  
  78. /* dummy do nothing */
  79. int catchit(void)
  80. {}
  81.  
  82. int setsignals(void)
  83. {
  84.     ctrlbrk(catchit);
  85. }
  86.  
  87.  
  88. int setvideo(char *s)
  89. {
  90.     if (strncmp("bios",s,4) == 0)
  91.         directvideo = 0;
  92.     else
  93.         directvideo = 1;
  94. }
  95.  
  96. /* I use my own gets to get around the DESQview raw mode bug
  97.    which causes gets not to work right.
  98.    It reads straight from console, not via "stdin".
  99. */
  100. char *gets(char *s)
  101. {
  102.     register char *p;
  103.     register int c;
  104.     p = s;
  105.     while ((c = getrch()) != EOF){
  106.         if ( c == '\b' && p > s) {
  107.             p--;
  108.             putch(' ');
  109.             putch('\b');
  110.         }
  111.         else if ( c == '\n' || c == '\r') {
  112.             break;
  113.         } else
  114.             *p++ = c;
  115.     }
  116.     *p = '\0';
  117.     putch('\n');
  118.     return(s);
  119. }
  120.