home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / TRUNAME.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  81 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. ** tname.c -- wrapper for the undocumented DOS function TRUENAME
  5. **
  6. ** TRUENAME: interrupt 0x21 function 0x60
  7. **
  8. **   Call with: ah    =  60h
  9. **              es:di -> destination buffer
  10. **              ds:si -> source buffer
  11. **
  12. **   Returns:   carry bit set if there were problems
  13. **
  14. ** This code hereby contributed to the public domain.
  15. */
  16.  
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <ctype.h>
  20. #include <dos.h>
  21. #include "dosfiles.h"
  22. #include "snip_str.h"         /* For trim()     */
  23.  
  24. /*
  25. ** Truename itself. Note that I'm using intdosx() rather than
  26. ** playing with some inline assembler -- I've discovered some
  27. ** people that actually don't have an assembler, poor bastards :-)
  28. */
  29.  
  30. char *Truename(char *dst, char *src)
  31. {
  32.       union REGS rg;
  33.       struct SREGS rs;
  34.  
  35.       if (!src || !*src || !dst)
  36.             return NULL;
  37.  
  38.       src = trim(src);
  39.  
  40.       rg.h.ah = 0x60;
  41.       rg.x.si = FP_OFF(src);
  42.       rg.x.di = FP_OFF(dst);
  43.       rs.ds   = FP_SEG(src);
  44.       rs.es   = FP_SEG(dst);
  45.  
  46.       intdosx(&rg, &rg, &rs);
  47.  
  48.       return (rg.x.cflag) ? NULL : dst;
  49. }
  50.  
  51. #ifdef TEST
  52.  
  53. /*
  54. ** ... and a little test function.
  55. */
  56.  
  57. int main(int argc, char *argv[])
  58. {
  59.       char buf[128]="                             ", *s;
  60.       int i;
  61.  
  62.       if (3 > _osmajor)
  63.       {
  64.             puts("Only works with DOS 3+");
  65.             return -1;
  66.       }
  67.       if(argc > 1)
  68.       {
  69.             for(i = 1; i < argc; i++)
  70.             {
  71.                   s = Truename((char *)buf,(char *)argv[i]);
  72.                   printf("%s=%s\n",argv[i], s ? buf : "(null)");
  73.             }
  74.       }
  75.       else  printf("Usage: TRUENAME [filename [filename...]]\n");
  76.  
  77.       return 0;
  78. }
  79.  
  80. #endif /* TEST */
  81.