home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / conflict.0 / conflict / conflict-6.0 / msdos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-13  |  2.5 KB  |  131 lines

  1. /******************************************************************************
  2.  * Copyright 1995 by Thomas E. Dickey.  All Rights Reserved.                  *
  3.  *                                                                            *
  4.  * You may freely copy or redistribute this software, so long as there is no  *
  5.  * profit made from its use, sale trade or reproduction. You may not change   *
  6.  * this copyright notice, and it must be included in any copy made.           *
  7.  ******************************************************************************/
  8. #ifndef NO_IDENT
  9. static char *Id = "$Id: msdos.c,v 6.0 1995/03/13 00:23:48 dickey Rel $";
  10. #endif
  11.  
  12. /*
  13.  * MSDOS (and some OS/2) support functions.
  14.  */
  15.  
  16. #include "conflict.h"
  17. #include <ctype.h>
  18.  
  19. char *
  20. fleaf (char *name)
  21. {
  22.     char    *s;
  23.  
  24.     while ((s = strpbrk(name, ":/\\")) != 0) {
  25.         name = s+1;
  26.     }
  27.     return name;
  28. }
  29.  
  30. char *
  31. ftype (char *name)
  32. {
  33.     char    *leaf = fleaf(name);
  34.     char    *type = strrchr(leaf, '.');
  35.     if (type == 0)
  36.         type = leaf + strlen(leaf);
  37.     return type;
  38. }
  39.  
  40. void    blip(int c)
  41. {
  42.     putc(c, stderr);
  43. }
  44.  
  45. int
  46. have_drive (char *name)
  47. {
  48.     return (isalpha(name[0]) && name[1] == ':');
  49. }
  50.  
  51. int
  52. same_drive (char *a, char *b)
  53. {
  54.     return have_drive(a) && have_drive(b) && (*a == *b);
  55. }
  56.  
  57. int
  58. set_directory (char *name)
  59. {
  60.     return set_drive(name) && (chdir(name) >= 0);
  61. }
  62.  
  63. #if SYS_MSDOS
  64. #include <dos.h>        /* ...for _getdrive/_setdrive */
  65.  
  66. int
  67. set_drive (char *name)
  68. {
  69.     if (have_drive(name)) {
  70.         unsigned want = name[0] - 'A';
  71.         unsigned have;
  72.         bdos(0x0e, want, 0);             /* set drive */
  73.         have = (bdos(0x19, 0, 0) & 0xff);    /* get drive */
  74.         if (want != have)
  75.             return FALSE;
  76.     }
  77.     return TRUE;
  78. }
  79. #endif    /* SYS_MSDOS */
  80.  
  81. #ifndef HAVE_GETOPT
  82. int    optind;
  83. char    *optarg;
  84.  
  85.     /*
  86.      * This version of 'getopt()' uses either '/' or '-' for the switch
  87.      * character to look more like a native dos or os/2 application.
  88.      */
  89. int    getopt(int argc, char **argv, char *opts)
  90. {
  91.     int    code = EOF;
  92.     char    *s, *t;
  93.  
  94.     if (optind == 0) {
  95.         optind = 1;
  96.         optarg = "";
  97.     }
  98.     if (optind < argc) {
  99.         s = argv[optind];
  100.         if (*s == '/' || *s == '-') {
  101.             optind++;
  102.             code = '?';
  103.             if (*++s != EOS) {
  104.                 t = strchr(opts, *s++);
  105.                 if (t != 0 && *t != ':') {
  106.                     code = *t++;
  107.                     if (*t == ':') {
  108.                         if (*s != EOS)
  109.                             optarg = s;
  110.                         else if (optind < argc)
  111.                             optarg = argv[optind++];
  112.                     } else if (*s != EOS) {
  113.                         optind--;
  114.                         while ((s[-1] = s[0]) != EOS)
  115.                             s++;
  116.                     }
  117.                 }
  118.             }
  119.         }
  120.     }
  121.     return code;
  122. }
  123. #endif
  124.  
  125. #if    !HAVE_REALPATH
  126. char    *my_realpath(char *given, char *actual)
  127. {
  128.     return (_fullpath(actual, given, MAXPATHLEN));
  129. }
  130. #endif
  131.