DOS 3.30 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
5.8 KiB

5 years ago
  1. /*** MSDOS JOIN Utility Vers 4.0
  2. *
  3. * This utility allows the splicing of a physical drive to a pathname
  4. * on another physical drive such that operations performed using the
  5. * pathname as an arguement take place on the physical drive.
  6. *
  7. * MODIFICATION HISTORY
  8. *
  9. * Converted to CMERGE 03/26/85 by Greg Tibbetts
  10. *
  11. * M000 May 23/85 Barrys
  12. * Disallow splicing similar drives.
  13. *
  14. * M001 May 24/85 Barrys
  15. * The original IBM version of JOIN allowed the delete splice switch
  16. * "/D" immediately after the drive specification. The argument parsing
  17. * code has been modified to allow this combination.
  18. *
  19. * M002 June 5/85 Barrys
  20. * Changed low version check for specific 320.
  21. *
  22. * M003 July 15/85 Barrys
  23. * Checked for any possible switch characters in the other operands.
  24. *
  25. * M004 July 15/85 Barrys
  26. * Moved check for physical drive before check for NET and SHARED tests.
  27. *
  28. * 33D0016 July 16/86 Rosemarie Gazzia
  29. * Put SHARED test on an equal basis with physical drive check.
  30. * Last fix (M004) erroneously allowed joining physical or local shared
  31. * drives. This is because it only performed the SHARED test if the drive
  32. * failed the physical test.
  33. */
  34. #include "types.h"
  35. #include "versionc.h"
  36. #include "sysvar.h"
  37. #include "cds.h"
  38. #include <dos.h>
  39. #include <ctype.h>
  40. extern char NoMem[], ParmNum[], BadParm[], DirNEmp[], NetErr[], BadVer[] ;
  41. extern char *strchr(); /* M003 */
  42. struct sysVarsType SysVars ;
  43. /*** main - program entry point
  44. *
  45. * Purpose:
  46. * To test arguements for validity and perform the splice
  47. *
  48. * int main(int c, char *v[])
  49. *
  50. * Args:
  51. * c - the number of command line arguements
  52. * v - pointer to pointers to the command line arguements
  53. *
  54. * Links:
  55. * ERRTST.C - Drive and path validity testing functions
  56. * SYSVAR.C - Functions to get/set DOS System Variable structures
  57. * CDS.C - Functions to get/set DOS CDS structures
  58. *
  59. * Returns:
  60. * Appropriate return code with error message to stdout if
  61. * necessary.
  62. *
  63. */
  64. main(c, v)
  65. int c ;
  66. char *v[] ;
  67. {
  68. char *strbscan() ;
  69. union REGS ir;
  70. register union REGS *iregs = &ir ; /* Used for DOS calls */
  71. struct findType findbuf ;
  72. char path [MAXPATHLEN],*p ;
  73. struct CDSType CDS ;
  74. int i ;
  75. int dstdrv; /* dest. drive number M000 */
  76. int delflag = FALSE; /* delete splice flag M001 */
  77. int arglen; /* length of argument M001 */
  78. /* check os version */
  79. iregs->h.ah = GETVERS ; /* Function 0x30 */
  80. intdos(iregs, iregs) ;
  81. if ( (iregs->h.al != expected_version_major) || (iregs->h.ah != expected_version_minor) )
  82. Fatal(BadVer);
  83. /* i = (iregs->h.al * 100) + iregs->h.ah; */
  84. /* if (i < LowVersion || i > HighVersion) */
  85. /* Fatal(BadVer) ; */
  86. SHIFT(c,v) ;
  87. for (i=0 ; i < c ; i++) /* Convert to upper case */
  88. strupr(v[i]) ;
  89. GetVars(&SysVars) ; /* Access to DOS data structures */
  90. if (c > 2) /* M001 */
  91. Fatal(ParmNum); /* M001 */
  92. if (c == 0)
  93. DoList() ; /* list splices */
  94. else {
  95. /* Process drive letter */
  96. i = **v - 'A' ;
  97. if ((*v)[1] != ':') {
  98. if (c == 1) {
  99. Fatal(ParmNum);
  100. }
  101. else {
  102. Fatal(BadParm) ;
  103. }
  104. }
  105. if (!fGetCDS(i, &CDS)) {
  106. Fatal(BadParm) ;
  107. }
  108. /* Accept arguments separate or mixed with drive spec M001 */
  109. arglen = strlen(*v);
  110. if (arglen != 2) {
  111. if ((*v)[2] != SwitChr) {
  112. Fatal(ParmNum);
  113. }
  114. if (arglen != 4) {
  115. if (c == 1) {
  116. Fatal(BadParm);
  117. }
  118. else {
  119. Fatal(ParmNum);
  120. }
  121. }
  122. /* Advance arg pointer to possible switches */
  123. (*v)++; (*v)++;
  124. }
  125. else {
  126. SHIFT(c,v) ;
  127. }
  128. /* Check for splice deletion switch */
  129. if (**v == SwitChr) {
  130. if ((*v)[1] == 'D')
  131. delflag = TRUE;
  132. else {
  133. Fatal(BadParm);
  134. }
  135. }
  136. if (delflag == TRUE) { /* Deassigning perhaps? */
  137. if (!TESTFLAG(CDS.flags, CDSSPLICE)) {
  138. Fatal(BadParm) ; /* If NOT spliced */
  139. }
  140. if (fPathErr(CDS.text)) {
  141. Fatal(BadParm) ; /* If prefix of curdir */
  142. }
  143. CDS.text[0] = i + 'A' ;
  144. CDS.text[1] = ':' ;
  145. CDS.text[2] = '\\' ;
  146. CDS.text[3] = 0 ;
  147. CDS.cbEnd = 2 ;
  148. if (i >= SysVars.cDrv)
  149. CDS.flags = FALSE ;
  150. else
  151. CDS.flags = CDSINUSE ;
  152. GetVars(&SysVars) ;
  153. SysVars.fSplice-- ;
  154. PutVars(&SysVars) ;
  155. fPutCDS(i, &CDS) ;
  156. }
  157. else {
  158. /* Test if there are any other possible switches
  159. * in the operand M003
  160. */
  161. if (strchr(v[0], SwitChr)) {
  162. Fatal(ParmNum);
  163. }
  164. if (TESTFLAG(CDS.flags,CDSSPLICE)) {
  165. Fatal(BadParm) ; /* If now spliced */
  166. }
  167. rootpath(*v, path) ; /* Get root path */
  168. strupr(path) ; /* Upper case */
  169. /* M004 Start */
  170. if (i == getdrv() || /* Can't mov curdrv */
  171. fPathErr(path) || /* or curdir prefix */
  172. *strbscan(path+3, "/\\") != 0 ||
  173. !fPhysical(i) ||
  174. fShared(i)) { /* 33D0016 RG */
  175. /* Determine if it was a NET error */
  176. if (fNet(i) || fShared(i)) {
  177. Fatal(NetErr) ;
  178. }
  179. Fatal(BadParm) ;
  180. }
  181. if (fNet(path[0] - 'A') || fNet(path[0] - 'A')) {
  182. Fatal(NetErr) ; /* Same for dest */
  183. }
  184. /* M004 End */
  185. /* Check src and dst drives are not same */
  186. dstdrv = *path - 'A'; /* M000 */
  187. if (i == dstdrv) /* M000 */
  188. Fatal (BadParm); /* M000 */
  189. if (mkdir(path) == -1) { /* If can't mkdir */
  190. /* or if no dir or */
  191. /* if node is file */
  192. if (ffirst(path, A_D, &findbuf) == -1 ||
  193. !TESTFLAG(findbuf.attr,A_D))
  194. Fatal(BadParm) ;
  195. p = path + strlen(path) ;
  196. strcat(p, "\\*.*") ;
  197. if (ffirst(path, 0, &findbuf) != -1)
  198. Fatal(DirNEmp) ; /* if dir */
  199. /* not empty */
  200. *p = 0 ;
  201. } ;
  202. strcpy(CDS.text, path) ;
  203. CDS.flags = CDSINUSE | CDSSPLICE ;
  204. fPutCDS(i, &CDS) ;
  205. GetVars(&SysVars) ;
  206. SysVars.fSplice++ ;
  207. PutVars(&SysVars) ;
  208. } ;
  209. }
  210. exit(0) ;
  211. }
  212. DoList()
  213. {
  214. int i ;
  215. struct CDSType CDS ;
  216. for (i=0 ; fGetCDS(i, &CDS) ; i++) {
  217. if (TESTFLAG(CDS.flags,CDSSPLICE))
  218. printf("%c: => %s\n", i+'A', CDS.text) ;
  219. } ;
  220. }
  221.