home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / tpw / doc / windos.int < prev    next >
Text File  |  1991-05-20  |  13KB  |  358 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Turbo Pascal Runtime Library                    }
  4. {       Windows DOS Interface Unit                      }
  5. {                                                       }
  6. {       Copyright (c) 1991 Borland International        }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit WinDos;
  11.  
  12. {$D-,S-,W-}
  13.  
  14. interface
  15.  
  16. { Flags bit masks }
  17.  
  18. const
  19.   fCarry     = $0001;
  20.   fParity    = $0004;
  21.   fAuxiliary = $0010;
  22.   fZero      = $0040;
  23.   fSign      = $0080;
  24.   fOverflow  = $0800;
  25.  
  26. { File mode magic numbers }
  27.  
  28. const
  29.   fmClosed = $D7B0;
  30.   fmInput  = $D7B1;
  31.   fmOutput = $D7B2;
  32.   fmInOut  = $D7B3;
  33.  
  34. { File attribute constants }
  35.  
  36. const
  37.   faReadOnly  = $01;
  38.   faHidden    = $02;
  39.   faSysFile   = $04;
  40.   faVolumeID  = $08;
  41.   faDirectory = $10;
  42.   faArchive   = $20;
  43.   faAnyFile   = $3F;
  44.  
  45. { Maximum file name component string lengths }
  46.  
  47. const
  48.   fsPathName  = 79;
  49.   fsDirectory = 67;
  50.   fsFileName  = 8;
  51.   fsExtension = 4;
  52.  
  53. { FileSplit return flags }
  54.  
  55. const
  56.   fcExtension = $0001;
  57.   fcFileName  = $0002;
  58.   fcDirectory = $0004;
  59.   fcWildcards = $0008;
  60.  
  61. { Registers record used by Intr and MsDos }
  62.  
  63. type
  64.   TRegisters = record
  65.     case Integer of
  66.       0: (AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags: Word);
  67.       1: (AL, AH, BL, BH, CL, CH, DL, DH: Byte);
  68.   end;
  69.  
  70. { Typed-file and untyped-file record }
  71.  
  72. type
  73.   TFileRec = record
  74.     Handle: Word;
  75.     Mode: Word;
  76.     RecSize: Word;
  77.     Private: array[1..26] of Byte;
  78.     UserData: array[1..16] of Byte;
  79.     Name: array[0..79] of Char;
  80.   end;
  81.  
  82. { Textfile record }
  83.  
  84. type
  85.   PTextBuf = ^TTextBuf;
  86.   TTextBuf = array[0..127] of Char;
  87.   TTextRec = record
  88.     Handle: Word;
  89.     Mode: Word;
  90.     BufSize: Word;
  91.     Private: Word;
  92.     BufPos: Word;
  93.     BufEnd: Word;
  94.     BufPtr: PTextBuf;
  95.     OpenFunc: Pointer;
  96.     InOutFunc: Pointer;
  97.     FlushFunc: Pointer;
  98.     CloseFunc: Pointer;
  99.     UserData: array[1..16] of Byte;
  100.     Name: array[0..79] of Char;
  101.     Buffer: TTextBuf;
  102.   end;
  103.  
  104. { Search record used by FindFirst and FindNext }
  105.  
  106. type
  107.   TSearchRec = record
  108.     Fill: array[1..21] of Byte;
  109.     Attr: Byte;
  110.     Time: Longint;
  111.     Size: Longint;
  112.     Name: array[0..12] of Char;
  113.   end;
  114.  
  115. { Date and time record used by PackTime and UnpackTime }
  116.  
  117. type
  118.   TDateTime = record
  119.     Year, Month, Day, Hour, Min, Sec: Word;
  120.   end;
  121.  
  122. { Error status variable }
  123.  
  124. var
  125.   DosError: Integer;
  126.  
  127. { DosVersion returns the DOS version number. The low byte of    }
  128. { the result is the major version number, and the high byte is  }
  129. { the minor version number. For example, DOS 3.20 returns 3 in  }
  130. { the low byte, and 20 in the high byte.                        }
  131.  
  132. function DosVersion: Word;
  133.  
  134. { Intr executes a specified software interrupt with a specified }
  135. { TRegisters package. NOTE: To avoid general protection faults  }
  136. { when running in protected mode, always make sure to           }
  137. { initialize the DS and ES fields of the TRegisters record with }
  138. { valid selector values, or set the fields to zero.             }
  139.  
  140. procedure Intr(IntNo: Byte; var Regs: TRegisters);
  141.  
  142. { MsDos invokes the DOS function call handler with a specified  }
  143. { TRegisters package.                                           }
  144.  
  145. procedure MsDos(var Regs: TRegisters);
  146.  
  147. { GetDate returns the current date set in the operating system. }
  148. { Ranges of the values returned are: Year 1980-2099, Month      }
  149. { 1-12, Day 1-31 and DayOfWeek 0-6 (0 corresponds to Sunday).   }
  150.  
  151. procedure GetDate(var Year, Month, Day, DayOfWeek: Word);
  152.  
  153. { SetDate sets the current date in the operating system. Valid  }
  154. { parameter ranges are: Year 1980-2099, Month 1-12 and Day      }
  155. { 1-31. If the date is not valid, the function call is ignored. }
  156.  
  157. procedure SetDate(Year, Month, Day: Word);
  158.  
  159. { GetTime returns the current time set in the operating system. }
  160. { Ranges of the values returned are: Hour 0-23, Minute 0-59,    }
  161. { Second 0-59 and Sec100 (hundredths of seconds) 0-99.          }
  162.  
  163. procedure GetTime(var Hour, Minute, Second, Sec100: Word);
  164.  
  165. { SetTime sets the time in the operating system. Valid          }
  166. { parameter ranges are: Hour 0-23, Minute 0-59, Second 0-59 and }
  167. { Sec100 (hundredths of seconds) 0-99. If the time is not       }
  168. { valid, the function call is ignored.                          }
  169.  
  170. procedure SetTime(Hour, Minute, Second, Sec100: Word);
  171.  
  172. { GetCBreak returns the state of Ctrl-Break checking in DOS.    }
  173. { When off (False), DOS only checks for Ctrl-Break during I/O   }
  174. { to console, printer, or communication devices. When on        }
  175. { (True), checks are made at every system call.                 }
  176.  
  177. procedure GetCBreak(var Break: Boolean);
  178.  
  179. { SetCBreak sets the state of Ctrl-Break checking in DOS.       }
  180.  
  181. procedure SetCBreak(Break: Boolean);
  182.  
  183. { GetVerify returns the state of the verify flag in DOS. When   }
  184. { off (False), disk writes are not verified. When on (True),    }
  185. { all disk writes are verified to insure proper writing.        }
  186.  
  187. procedure GetVerify(var Verify: Boolean);
  188.  
  189. { SetVerify sets the state of the verify flag in DOS.           }
  190.  
  191. procedure SetVerify(Verify: Boolean);
  192.  
  193. { DiskFree returns the number of free bytes on the specified    }
  194. { drive number (0=Default,1=A,2=B,..). DiskFree returns -1 if   }
  195. { the drive number is invalid.                                  }
  196.  
  197. function DiskFree(Drive: Byte): Longint;
  198.  
  199. { DiskSize returns the size in bytes of the specified drive     }
  200. { number (0=Default,1=A,2=B,..). DiskSize returns -1 if the     }
  201. { drive number is invalid.                                      }
  202.  
  203. function DiskSize(Drive: Byte): Longint;
  204.  
  205. { GetFAttr returns the attributes of a file. F must be a file   }
  206. { variable (typed, untyped or textfile) which has been assigned }
  207. { a name. The attributes are examined by ANDing with the        }
  208. { attribute masks defined as constants above. Errors are        }
  209. { reported in DosError.                                         }
  210.  
  211. procedure GetFAttr(var F; var Attr: Word);
  212.  
  213. { SetFAttr sets the attributes of a file. F must be a file      }
  214. { variable (typed, untyped or textfile) which has been assigned }
  215. { a name. The attribute value is formed by adding (or ORing)    }
  216. { the appropriate attribute masks defined as constants above.   }
  217. { Errors are reported in DosError.                              }
  218.  
  219. procedure SetFAttr(var F; Attr: Word);
  220.  
  221. { GetFTime returns the date and time a file was last written.   }
  222. { F must be a file variable (typed, untyped or textfile) which  }
  223. { has been assigned and opened. The Time parameter may be       }
  224. { unpacked throgh a call to UnpackTime. Errors are reported in  }
  225. { DosError.                                                     }
  226.  
  227. procedure GetFTime(var F; var Time: Longint);
  228.  
  229. { SetFTime sets the date and time a file was last written.      }
  230. { F must be a file variable (typed, untyped or textfile) which  }
  231. { has been assigned and opened. The Time parameter may be       }
  232. { created through a call to PackTime. Errors are reported in    }
  233. { DosError.                                                     }
  234.  
  235. procedure SetFTime(var F; Time: Longint);
  236.  
  237. { FindFirst searches the specified (or current) directory for   }
  238. { the first entry that matches the specified filename and       }
  239. { attributes. The result is returned in the specified search    }
  240. { record. Errors (and no files found) are reported in DosError. }
  241.  
  242. procedure FindFirst(Path: PChar; Attr: Word; var F: TSearchRec);
  243.  
  244. { FindNext returs the next entry that matches the name and      }
  245. { attributes specified in a previous call to FindFirst. The     }
  246. { search record must be one passed to FindFirst. Errors (and no }
  247. { more files) are reported in DosError.                         }
  248.  
  249. procedure FindNext(var F: TSearchRec);
  250.  
  251. { UnpackTime converts a 4-byte packed date/time returned by     }
  252. { FindFirst, FindNext or GetFTime into a TDateTime record.      }
  253.  
  254. procedure UnpackTime(P: Longint; var T: TDateTime);
  255.  
  256. { PackTime converts a TDateTime record into a 4-byte packed     }
  257. { date/time used by SetFTime.                                   }
  258.  
  259. procedure PackTime(var T: TDateTime; var P: Longint);
  260.  
  261. { GetIntVec returns the address stored in the specified         }
  262. { interrupt vector.                                             }
  263.  
  264. procedure GetIntVec(IntNo: Byte; var Vector: Pointer);
  265.  
  266. { SetIntVec sets the address in the interrupt vector table for  }
  267. { the specified interrupt.                                      }
  268.  
  269. procedure SetIntVec(IntNo: Byte; Vector: Pointer);
  270.  
  271. { FileSearch searches for the file given by Name in the list of }
  272. { directories given by List. The directory paths in List must   }
  273. { be separated by semicolons. The search always starts with the }
  274. { current directory of the current drive. If the file is found, }
  275. { FileSearch stores a concatenation of the directory path and   }
  276. { the file name in Dest. Otherwise FileSearch stores an empty   }
  277. { string in Dest. The maximum length of the result is defined   }
  278. { by the fsPathName constant. The returned value is Dest.       }
  279.  
  280. function FileSearch(Dest, Name, List: PChar): PChar;
  281.  
  282. { FileExpand fully expands the file name in Name, and stores    }
  283. { the result in Dest. The maximum length of the result is       }
  284. { defined by the fsPathName constant. The result is an all      }
  285. { upper case string consisting of a drive letter, a colon, a    }
  286. { root relative directory path, and a file name. Embedded '.'   }
  287. { and '..' directory references are removed, and all name and   }
  288. { extension components are truncated to 8 and 3 characters. The }
  289. { returned value is Dest.                                       }
  290.  
  291. function FileExpand(Dest, Name: PChar): PChar;
  292.  
  293. { FileSplit splits the file name specified by Path into its     }
  294. { three components. Dir is set to the drive and directory path  }
  295. { with any leading and trailing backslashes, Name is set to the }
  296. { file name, and Ext is set to the extension with a preceding   }
  297. { period. If a component string parameter is NIL, the           }
  298. { corresponding part of the path is not stored. If the path     }
  299. { does not contain a given component, the returned component    }
  300. { string is empty. The maximum lengths of the strings returned  }
  301. { in Dir, Name, and Ext are defined by the fsDirectory,         }
  302. { fsFileName, and fsExtension constants. The returned value is  }
  303. { a combination of the fcDirectory, fcFileName, and fcExtension }
  304. { bit masks, indicating which components were present in the    }
  305. { path. If the name or extension contains any wildcard          }
  306. { characters (* or ?), the fcWildcards flag is set in the       }
  307. { returned value.                                               }
  308.  
  309. function FileSplit(Path, Dir, Name, Ext: PChar): Word;
  310.  
  311. { GetCurDir returns the current directory of a specified drive. }
  312. { Drive = 0 indicates the current drive, 1 indicates drive A, 2 }
  313. { indicates drive B, and so on. The string returned in Dir      }
  314. { always starts with a drive letter, a colon, and a backslash.  }
  315. { The maximum length of the resulting string is defined by the  }
  316. { fsDirectory constant. The returned value is Dir. Errors are   }
  317. { reported in DosError.                                         }
  318.  
  319. function GetCurDir(Dir: PChar; Drive: Byte): PChar;
  320.  
  321. { SetCurDir changes the current directory to the path specified }
  322. { by Dir. If Dir specifies a drive letter, the current drive is }
  323. { also changed. Errors are reported in DosError.                }
  324.  
  325. procedure SetCurDir(Dir: PChar);
  326.  
  327. { CreateDir creates a new subdirectory with the path specified  }
  328. { by Dir. Errors are reported in DosError.                      }
  329.  
  330. procedure CreateDir(Dir: PChar);
  331.  
  332. { RemoveDir removes the subdirectory with the path specified by }
  333. { Dir. Errors are reported in DosError.                         }
  334.  
  335. procedure RemoveDir(Dir: PChar);
  336.  
  337. { GetArgCount returns the number of parameters passed to the    }
  338. { program on the command line.                                  }
  339.  
  340. function GetArgCount: Integer;
  341.  
  342. { GetArgStr returns the Index'th parameter from the command     }
  343. { line, or an empty string if Index is less than zero or        }
  344. { greater than GetArgCount. If Index is zero, GetArgStr returns }
  345. { the filename of the current module. The maximum length of the }
  346. { string returned in Dest is given by the MaxLen parameter. The }
  347. { returned value is Dest.                                       }
  348.  
  349. function GetArgStr(Dest: PChar; Index: Integer; MaxLen: Word): PChar;
  350.  
  351. { GetEnvVar returns a pointer to the value of a specified       }
  352. { environment variable, i.e. a pointer to the first character   }
  353. { after the equals sign (=) in the environment entry given by   }
  354. { VarName. VarName is case insensitive. GetEnvVar returns NIL   }
  355. { if the specified environment variable does not exist.         }
  356.  
  357. function GetEnvVar(VarName: PChar): PChar;
  358.