home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Tele / Hermes / Hermes Toolbox 1.0.1 ƒ / HermesToolboxIntf.p < prev    next >
Encoding:
Text File  |  1993-10-28  |  47.0 KB  |  721 lines  |  [TEXT/PJMM]

  1. {-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
  2. {This unit is the interface file for the Hermes Toolbox library by Chris Owen}
  3. {The Hermes Toolbox extends the number of procedures and functions that}
  4. {are available when writing externals.  This library is constantly being }
  5. {updated and the most recent version can always be found on Mulligan's Valley}
  6. {at 203-772-4485 or by contacting the author at owen-christopher@yale.edu}
  7. {-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
  8.  
  9. {Last modified for Hermes II version 1.0 on 9/27/93}
  10. {Version 1.0}
  11.  
  12. unit HermesToolboxIntf;
  13.  
  14. interface
  15.  
  16.     uses
  17.         HermHeaders, MiscIntf;
  18.  
  19.     type
  20.  
  21. {For GetQDGlobals, CenterDialog and DoRegistrationDialog}
  22.         QDGlobalRecPtr = ^QDGlobalRec;
  23.         QDGlobalRec = record
  24.                 randSeed: Longint;
  25.                 screenBits: BitMap;
  26.                 arrow: Cursor;
  27.                 dkGray: Pattern;
  28.                 ltGray: Pattern;
  29.                 gray: Pattern;
  30.                 black: Pattern;
  31.                 white: Pattern;
  32.                 thePort: GrafPtr;
  33.             end;
  34.  
  35.  
  36. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  37. {----------------------------- Hermes Display Functions ------------------------------}
  38. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  39.  
  40.  
  41.     procedure DoCR (numLines: integer; HermSetup: UserXIPtr);
  42. {-----------------------------------------------------------------------------------}
  43. {This procedure will move the cursor down the number of line specified in numLines.  This is}
  44. {just like bCR but you don't have to repeat it so many times and clog up your code.}
  45. {-----------------------------------------------------------------------------------}
  46.  
  47.     procedure Write (theString: str255; HermSetup: UserXIPtr);
  48. {-----------------------------------------------------------------------------------}
  49. {This procedure will simply output theString to the screen.  It uses the built in command in}
  50. {Hermes but I think this is an easier format to call it from.  It uses the current text color.}
  51. {Write will not begin on a new line but start where the last write left off.}
  52. {-----------------------------------------------------------------------------------}
  53.  
  54.     procedure Writeln (theString: str255; HermSetup: UserXIPtr);
  55. {-----------------------------------------------------------------------------------}
  56. {This procedure will simply output theString to the screen.  It uses the built in command in}
  57. {Hermes but I think this is an easier format to call it from.  It uses the current text color.}
  58. {Writeln will  begin on a new line.}
  59. {-----------------------------------------------------------------------------------}
  60.  
  61.     procedure WriteANSI (theString: str255; where: point; color: integer; HermSetup: UserXIPtr);
  62. {-----------------------------------------------------------------------------------}
  63. {WriteANSI will output theString begining at where and in the color specified by color.}
  64. {-----------------------------------------------------------------------------------}
  65.  
  66.     function ListTextRsrc (textID: integer; HermSetup: UserXIPtr): boolean;
  67. {-----------------------------------------------------------------------------------}
  68. {This function willl output to the screen a TEXT resource of number textID.  If the resouce}
  69. {can not be found this returns false.  You must exit the current stage immeadiately after}
  70. {this procedure in order for it to display the text.}
  71. {-----------------------------------------------------------------------------------}
  72.  
  73.     function ListTextFile (filePath: str255; insertPath: boolean; HermSetup: UserXIPtr): boolean;
  74. {-----------------------------------------------------------------------------------}
  75. {This function is mostly to make life a little easier.  Given the path to a file filepath it will}
  76. {output the contents to the screen.  If insertPath is true Hermes will add the path you pass}
  77. {to the path to the Hermes Files folder (ie. you can just pass 'Externals:A textfile'),}
  78. {otherwise it will use filePath as is. If the file isn't found this function will return false. You}
  79. {must exit the current stage immeadiately after this procedure in order for it to display the}
  80. {text.}
  81. {-----------------------------------------------------------------------------------}
  82.  
  83.     procedure Pause (HermSetup: UserXIPtr);
  84. {-----------------------------------------------------------------------------------}
  85. {This procedure will pause the screen until the user hits a key.  It using the built in pause}
  86. {string in Hermes, so whatever the sysop has customized that to will be used.  This}
  87. {procedure must be just before exiting a stage of your external.  Set the stage to where}
  88. {you want to go after the pause, call this and exit the current stage}
  89. {-----------------------------------------------------------------------------------}
  90.  
  91.     procedure ClearScreen (HermSetup: UserXIPtr);
  92. {-----------------------------------------------------------------------------------}
  93. {This procedure will clear the users screen.}
  94. {-----------------------------------------------------------------------------------}
  95.  
  96.     procedure Beep (HermSetup: UserXIPtr);
  97. {-----------------------------------------------------------------------------------}
  98. {This procedure will cause the remote users computer to beep (or flash the menu bar if they}
  99. {have the sound set to 0)}
  100. {-----------------------------------------------------------------------------------}
  101.  
  102. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  103. {----------------------------- File Manipulation Functions -----------------------------}
  104. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  105.  
  106.  
  107.     function FileExists (filePath: str255; var OSResult: OSErr): boolean;
  108. {-----------------------------------------------------------------------------------}
  109. {Given filePath this function will return whether the specified file actually exists.  It also}
  110. {returns the reason for any error in OSResult}
  111. {-----------------------------------------------------------------------------------}
  112.  
  113.     function CreateFile (pathName: string; var theVRefNum: Integer; var theDirID: Integer): OSErr;
  114. {-----------------------------------------------------------------------------------}
  115. {This is a cool one. This function will create a new file with the path pathName.  The cool part}
  116. {is that it will create all the folders along the way. If the path name ends with a : then only}
  117. {the folders will be created.  If you need to start part way down the path you can pass a}
  118. {VRefNum to theVRefNum and a file name or partial path name to thePath.  The function will}
  119. {return the VRefNum and dirID of the file which is created.  If you are using a full path name}
  120. {you MUST pass 0 (zero) for theVRefNum and theDirID.  This is the perfect way to create}
  121. {preference files.  If they don't exist already you can create the whole subdirectory}
  122. {necessary to create them.}
  123. {-----------------------------------------------------------------------------------}
  124.  
  125.     procedure WriteFile (theString: str255; fileRefNum: integer; var OSResult: OSErr);
  126. {-----------------------------------------------------------------------------------}
  127. {WriteFile with write theString to the current location in the file specified by fileRefNum.}
  128. {It will return any error in OSResult.  WriteFile does not add a return to the end of the string}
  129. {-----------------------------------------------------------------------------------}
  130.  
  131.     procedure WritelnFile (theString: str255; fileRefNum: integer; var OSResult: OSErr);
  132. {-----------------------------------------------------------------------------------}
  133. {WritelnFile with write theString to the current location in the file specified by fileRefNum.}
  134. {It will return any error in OSResult.  WriteFile will add a return at the end of the string so}
  135. {that the next string will begin on a new line.}
  136. {-----------------------------------------------------------------------------------}
  137.  
  138.     function TouchFolder (folderPath: str255): OSErr;
  139. {-----------------------------------------------------------------------------------}
  140. {This procedure will chage the last modified date of a folder to the current time and date.}
  141. {This is often useful because it forces the Finder to update all the files in that folder.  Pass}
  142. {it the path to the folder you want to change and it will return any error.}
  143. {-----------------------------------------------------------------------------------}
  144.  
  145.     procedure FlushAllVolumes;
  146. {-----------------------------------------------------------------------------------}
  147. {This procdure will cause all mounted volumes to be immeadiately flushed.  All changes that}
  148. {have been made to files will be written to disk.  This is important because the mac doesn't}
  149. {write to disk until the buffer is full.  If you want to do something especially dangerous or}
  150. {something like shutdown the machine it might be a good idea to call this first.  This will}
  151. {cause a momentary pause in the action if there is lots to be written but no worse than the}
  152. {many pauses that take place when writting something to disk.}
  153. {-----------------------------------------------------------------------------------}
  154.  
  155.     function Readln (refNum: integer; endOfLine: char): str255;
  156. {-----------------------------------------------------------------------------------}
  157. {This function will let you read from a text file.  It is intended to return a single line so it is}
  158. {limited to a returning a string.  refNum is the refNum of the already opened file you want to}
  159. {read from.  endOfLine is the character which ends a line (normally a return). It will return}
  160. {the line as a string and will return a empty string if there is an error. This might be useful}
  161. {if you want to read the BBS list file that Hermes creates.}
  162. {-----------------------------------------------------------------------------------}
  163.  
  164.     procedure ReadText (refNum: integer; data: Handle; endOfLine: char);
  165. {-----------------------------------------------------------------------------------}
  166. {This function is useful if you need to read something larger than a string.  Like Readln you}
  167. {need to pass it a refNum for the open file and the endOfLine character which marks the end}
  168. {of the data you want to read.  With this procedure you must also pass a valid handle to hold}
  169. {the data which is read.  The handle you pass will be resized to the size of the data and will}
  170. {be nil if there is an error.}
  171. {-----------------------------------------------------------------------------------}
  172.  
  173.     function DiskSpaceAvail (volToTest: str255): longInt;
  174. {-----------------------------------------------------------------------------------}
  175. {Given a volume name volToTest this function will return the total amount of free disk space}
  176. {on that volume.}
  177. {-----------------------------------------------------------------------------------}
  178.  
  179.     function CopyFile (source, destination: str255; deleteOriginal: boolean): OSErr;
  180. {-----------------------------------------------------------------------------------}
  181. {CopyFile will copy both the data and resource fork of a file on the path source to the file}
  182. {specified by the path destination.  If true, deleteOriginal will cause the source file to be}
  183. {erased only if the copy was successful.  Any error will be returned in OSErr.}
  184. {-----------------------------------------------------------------------------------}
  185.  
  186.     function GetVolRefNum (thePath: str255): integer;
  187. {-----------------------------------------------------------------------------------}
  188. {Given thePath this function will return the volume reference number of the directory pointed}
  189. {to by that path.  Since pathnames are used so frequently in Hermes you will need this for}
  190. {many of the mac toolbox calls}
  191. {-----------------------------------------------------------------------------------}
  192.  
  193.     function GetPathName (volRefNum: longInt): Str255;
  194. {-----------------------------------------------------------------------------------}
  195. {Given a volume reference number this function will return a path name for that directory.}
  196. {This is useful for converting the result of many of the mac toolbox calls to strings for }
  197. {Hermes}
  198. {-----------------------------------------------------------------------------------}
  199.  
  200.     function GetSystemPath: str255;
  201. {-----------------------------------------------------------------------------------}
  202. {This function returns a pathname to the current system folder.  Good for finding the }
  203. {preference folder or things like Stuffit Engine.}
  204. {-----------------------------------------------------------------------------------}
  205.  
  206.     function DirectoryList (pathtoDir: str255; numtypes: integer; typelist: SFTypelist; var numFiles: integer; HermSetup: UserXIPtr): OSErr;
  207. {-----------------------------------------------------------------------------------}
  208. {This function will write out a list of files in the directory pointed to by pathToDir.  If}
  209. {numTypes is between 1 and 4 it will only list those files which are listed in typeList.  If}
  210. {numTypes is between -1 and -4 it will only list those files in typeList but will also list all}
  211. {folders. Folders are signified by a colon (:) after their name.  If numTypes is greater than}
  212. {4 it will list all files without listing folders.  If it is less than -4 it will list all files and}
  213. {folders in the directory. *Remember that SFTypeList arrays are 0-3 not 1-4* }
  214. {-----------------------------------------------------------------------------------}
  215.  
  216. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  217. {--------------------------- Resource Manipulation Functions --------------------------}
  218. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  219.  
  220.  
  221.     function GetHRMS: eInfoRec;
  222. {-----------------------------------------------------------------------------------}
  223. {This function will get the current externals restriction information that Hermes uses to}
  224. {limit access to the external.  This is useful if you use a main menu command and want to}
  225. {limit that commands use to users who would have access to the external from the }
  226. {external menu.}
  227. {-----------------------------------------------------------------------------------}
  228.  
  229.     procedure SetHRMS (HRMSInfo: eInfoRec);
  230. {-----------------------------------------------------------------------------------}
  231. {This procedure will save the restriction information that Hermes uses to limit access to an}
  232. {external.  No errors are reported but this should be a generally safe procedure.}
  233. {-----------------------------------------------------------------------------------}
  234.  
  235.     function GetRegistration (var bbsName: str255; var registrationNum: longInt; resourceName: resType): boolean;
  236. {-----------------------------------------------------------------------------------}
  237. {This function will let you get saved registration information.  It will retrieve the registration}
  238. {information in bbsName and registration number.  You must pass the resourceName that you}
  239. {previously used to save the information.  See SetRegistration for details.  It will return true}
  240. {if it found the resource and false if it did not.  If it did not find the resource you can create a}
  241. {new one by calling SetRegistration. }
  242. {-----------------------------------------------------------------------------------}
  243.  
  244.     procedure SetRegistration (bbsName: str255; registrationNum: longInt; resourceName: resType);
  245. {-----------------------------------------------------------------------------------}
  246. {This procedure will let you save registration information in your external's resource fork.}
  247. {Pass it the bbsName and registrationNum you want to save.  You also need to pass a}
  248. {resource type name.  This is simply 4 letters (ie HRMS).  Each external you write should have}
  249. {its own type though to avoid possible conflicts.  Use the same type you use here as in}
  250. {GetRegistration.  You should define a constant in your headers that is something like }
  251. {regResource = 'REGI' and use that each time.}
  252. {-----------------------------------------------------------------------------------}
  253.  
  254.     function CheckRegistration (bbsName: str255; registrationNum: longInt; regNum1, regNum2: longint): boolean;
  255. {-----------------------------------------------------------------------------------}
  256. {This procedure will check a registration number for a given BBS name.  It returns true if the}
  257. {registration number is valid and false if it is invalid.  This relies on regNum1 and regNum2 }
  258. {regNum1 should be a 6 digit number and regNum2 should be a 3 digit number.  These numbers}
  259. {should be changed for each external.  You must use the same numbers that you used when you}
  260. {created the number with CreateRegistration though.}
  261. {-----------------------------------------------------------------------------------}
  262.  
  263.     function CreateRegistration (bbsName: str255; regNum1, regNum2: longint): longint;
  264. {-----------------------------------------------------------------------------------}
  265. {This procedure will return a registration number for the bbsName you pass it.  It also relies}
  266. {on regNum1 and regNum2 (see above).  You can use this is a small application or external}
  267. {that creates registration numbers.  You should define these two numbers as constants and}
  268. {use the same ones to create and then check registration numbers.}
  269. {-----------------------------------------------------------------------------------}
  270.  
  271. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  272. {------------------------------ Sysop External Functions -----------------------------}
  273. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  274.  
  275.  
  276.     function GetCheck (theDialog: dialogPtr; itemNum: integer): boolean;
  277. {-----------------------------------------------------------------------------------}
  278. {Given a dialog pointer theDialog and an item in that dialog, this function will return the }
  279. {current state of the item.  This is for reading check boxes and radio buttons in sysop}
  280. {externals.  Writing this as a function makes it generally easier to use. True is on and }
  281. {false is off.}
  282. {-----------------------------------------------------------------------------------}
  283.  
  284.     procedure SetCheck (theDialog: dialogPtr; itemNum: integer; on: boolean);
  285. {-----------------------------------------------------------------------------------}
  286. {Given a dialog pointer theDialog and an item in that dialog, this function will set the }
  287. {current state of the item to the value of on (true is on and false is off).  This is for setting}
  288. {check boxes and radio buttons in sysop externals.  Writing this as a function makes it }
  289. {generally easier to use. True is on and false is off.}
  290. {-----------------------------------------------------------------------------------}
  291.  
  292.     function GetEditText (theDialog: DialogPtr; itemNum: integer): str255;
  293. {-----------------------------------------------------------------------------------}
  294. {Given a dialog pointer theDialog and an item in that dialog, this function will return the }
  295. {current value an edit text item.  This is for reading edit text fields in sysop externals.}
  296. {Writing this as a function makes it generally easier to use}
  297. {-----------------------------------------------------------------------------------}
  298.  
  299.     procedure SetEditText (theDialog: DialogPtr; itemNum: integer; ETString: str255);
  300. {-----------------------------------------------------------------------------------}
  301. {Given a dialog pointer theDialog and an item in that dialog, this function will set the }
  302. {current value of the edit text item to ETString.  This is for setting edit text fields in }
  303. {sysop externals.  Writing this as a function makes it generally easier to use. }
  304. {-----------------------------------------------------------------------------------}
  305.  
  306.     procedure CenterDialog (theDialog: DialogPtr);
  307. {-----------------------------------------------------------------------------------}
  308. {This procedure takes a dialog (or window) pointer (which you would get from GetNewDialog)}
  309. {and centers it on the screen.  You should make your dialog 'initially invisable' and call this}
  310. {procedure BEFORE calling ShowWindow.  Otherwise the user will see the dialog move across}
  311. {the screen.}
  312. {-----------------------------------------------------------------------------------}
  313.  
  314.     function DoRegistrationDialog (var bbsName: str255; var registrationNum: longInt): boolean;
  315. {-----------------------------------------------------------------------------------}
  316. {This function will put up a small dialog that will allow the sysop to enter basic registration}
  317. {information.  The dialog has two items, one for a BBS name and one for a registration}
  318. {number.  The function stores these two values in bbsName and registrationNum.  The dialog}
  319. {also has two buttons, one for OK and one for cancel.  The function will return true if the OK}
  320. {buttun is hit and false if cancel is hit.  Note that this dialog is modal so it will stop other}
  321. {action on the BBS, but this isn't really a problem since the sysop will  use it rarely. If you}
  322. {use this function you MUST include all the resources included in the file with the same name}
  323. {as this function.  Use ResEdit to copy them to your external's resource file.}
  324. {-----------------------------------------------------------------------------------}
  325.  
  326.     procedure DoTimeDialog (var hour, minute: integer);
  327. {-----------------------------------------------------------------------------------}
  328. {This procedure puts up a dialog similar to that which Hermes uses to enter the time for node}
  329. {start and end time.  It gives the sysop the opportunity to enter time in a manner similar to}
  330. {that used by the Alarm Clock DA and General control panel.  It returns the hour and minute}
  331. {that the sysop entered.  The hour is in 24 hour format so 0 is midnight and 23 is 11 pm.}
  332. {Note that this dialog is modal so it will stop other action on the BBS, but this isn't really a}
  333. {problem since the sysop will  use it rarely. If you use this function you MUST include all}
  334. {the resources included in the file with the same name as this function.  Use ResEdit to copy}
  335. {them to your external's resource file.  There is a text item in this dialog which can be used}
  336. {to prompt the user.  You can either change it with ResEdit or call ParamText and set string}
  337. {number 0 to what you want displayed in that item.}
  338. {-----------------------------------------------------------------------------------}
  339.  
  340.  
  341. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  342. {----------------------------- Process Manager Functions ----------------------------}
  343. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  344.  
  345.  
  346.     function HermesToFront (var oldProcess: ProcessSerialNumber): OSErr;
  347. {-----------------------------------------------------------------------------------}
  348. {This function will make Hermes the front most application.  It returns the process serial}
  349. {number of the application which had been in from in oldProcess.  This is a really rude and}
  350. {not very mac-like thing to do but there are times when it is handy.}
  351. {THIS REQUIRES SYSTEM 7.0 OR LATER - Use System7OrLater below to check.}
  352. {-----------------------------------------------------------------------------------}
  353.  
  354.     function HermesToBack (theProcess: ProcessSerialNumber): OSErr;
  355. {-----------------------------------------------------------------------------------}
  356. {This function will return Hermes to the background after a call to HermesToFront.  You}
  357. {should store the value of oldProcess returned by that function in order to return the old}
  358. {process to the front.}
  359. {THIS REQUIRES SYSTEM 7.0 OR LATER - Use System7OrLater below to check.}
  360. {-----------------------------------------------------------------------------------}
  361.  
  362.     procedure ShutDownMac;
  363. {-----------------------------------------------------------------------------------}
  364. {This procedure will shut the macintosh down and turn off the power on most newer macs.}
  365. {It gives no warning and does not save open documents so it should be used sparingly.}
  366. {-----------------------------------------------------------------------------------}
  367.  
  368.     procedure RestartMac;
  369. {-----------------------------------------------------------------------------------}
  370. {This procedure will restart the macintosh.  It gives no warning and does not save open }
  371. {documents so it should be used sparingly.}
  372. {-----------------------------------------------------------------------------------}
  373.  
  374. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  375. {----------------------------------- User Functions ----------------------------------}
  376. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  377.  
  378.     function FindUserOnline (userNum: integer; var node: integer; HermSetup: UserXIPtr): boolean;
  379. {-----------------------------------------------------------------------------------}
  380. {This function will return true if the user specified  by userNum  is online.  If true then the}
  381. {node that user is on will be returned in node.}
  382. {-----------------------------------------------------------------------------------}
  383.  
  384.     function NewUserAccount (var newUser: UserRec; HermSetup: UserXIPtr): OSErr;
  385. {-----------------------------------------------------------------------------------}
  386. {This function will create a new user on the BBS.  You can pass a full user record or use}
  387. {WriteUser to flesh it out later.  The new user's user number will be passed back in}
  388. {newUser.userNum.}
  389. {-----------------------------------------------------------------------------------}
  390.  
  391.     function DeleteUser (userNum: integer; sysopNote: str255; HermSetup: UserXIPtr): OSErr;
  392. {-----------------------------------------------------------------------------------}
  393. {This function will delete the user specified by userNum from the Hermes user list.  Deleted}
  394. {users will have a '•' added to the end of their name.  Optionally you can add a string of up}
  395. {to 40 characters in sysopNote and this function will change the current sysopNote to that}
  396. {string.  This might be usefull to keep track of why the user was deleted.}
  397. {-----------------------------------------------------------------------------------}
  398.  
  399.     function WriteUser (user: UserRec; HermSetup: UserXIPtr): OSErr;
  400. {-----------------------------------------------------------------------------------}
  401. {This function will save the user info contained in UserRec.  It will return any error in writing}
  402. {the info to the HermShared file.  The user info will be written to the account number}
  403. {contained in user.UserNum so if you want to swap user info you need to reset that number.}
  404. {You can change anything in a users record by using the Hermes function 'FindUser' to get}
  405. {a user record, make the necessary changes and then call this function.}
  406. {-----------------------------------------------------------------------------------}
  407.  
  408.     function CheckSub (forumNum, subNum: integer; user: UserRec; HermSetup: UserXIPtr): boolean;
  409. {-----------------------------------------------------------------------------------}
  410. {This function will check whether user has access to the the message base specified by}
  411. {forumNum and subNum.  It returns true if the user does have access.  This funciton will}
  412. {take into consideration if the user has access the forum and if they have the proper security}
  413. {level, restriction and age.}
  414. {-----------------------------------------------------------------------------------}
  415.  
  416. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  417. {---------------------------------- Stuffit Functions ---------------------------------}
  418. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  419.  
  420.     function StuffitExists: boolean;
  421. {-----------------------------------------------------------------------------------}
  422. {This function will check for the existence of the Stuffit Engine.  The Stuffit Engine is}
  423. {supposed to be kept in the Extensions folder inside the System Folder.  It returns true if the}
  424. {Engine is found and false if not.  Most of the other Stuffit Functions call this one but you}
  425. {should still check before using any of them so you can report back to the user.}
  426. {-----------------------------------------------------------------------------------}
  427.  
  428.     function StuffFile (source, destination: str255; deleteOriginal: boolean): OSErr;
  429. {-----------------------------------------------------------------------------------}
  430. {This function will compress a single file using the Stuffit Engine which is part of the Stuffit}
  431. {Deluxe package.  You should pass the path to the file to be compressed in source and where}
  432. {you want the archive to be placed in destination.  If deleteOriginal is true then the file will}
  433. {be deleted after it has been compressed.   This function does not add .sit to the end of the}
  434. {file name so if you are putting the new archive in the same directory you will need to add}
  435. {it yourself in the destination name.  The fuction returns any OSErr that might take place}
  436. {and returns -1 if the user cancels the operation by hitting the stop button in the Stuffit}
  437. {Engine dialog.  Although this function calls StuffitExists you should before calling it in order}
  438. {to report any errors to the user.}
  439. {-----------------------------------------------------------------------------------}
  440.  
  441. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  442. {--------------------------------- Debugging Functions -------------------------------}
  443. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  444.  
  445.     function ParseError (theErr: OSErr; HermSetup: UserXIPtr): str255;
  446. {-----------------------------------------------------------------------------------}
  447. {This function will allow you to translate theErr into a string. It assumes that you have}
  448. {already checked to make sure there actually is an error so you should not call it with error}
  449. {0.}
  450. {-----------------------------------------------------------------------------------}
  451.  
  452.     procedure ReportError (theErr: OSErr; user, log: boolean; HermSetup: UserXIPtr);
  453. {-----------------------------------------------------------------------------------}
  454. {This procedure will translate theErr into a string which can be reported to the user or sysop.}
  455. {If user is true it will print the error string out to the current node.  If log is true it will}
  456. {write the error string to the daily log.  This procedure DOES check the error so you can}
  457. {call it each time you do something that might cause an error and it will not do anything}
  458. {unless the error is other than 0.}
  459. {-----------------------------------------------------------------------------------}
  460.  
  461.     procedure LogIt (outStr: str255; HermSetup: UserXIPtr);
  462. {-----------------------------------------------------------------------------------}
  463. {This is identical to the LogThis function in Hermes but works even if a user isn't online.  With}
  464. {the built-in function if a users isn't on the current node when you log something to the daily}
  465. {log, it isn't actually written until a user logs on (and then off) that node.  In the meantime}
  466. {lots of people may have logged on to other nodes and your entry will be way out of order.}
  467. {This writes directly to the 'Today Log' file.  You should still use the other procedure if a}
  468. {user is online when you are writing to the log, but use this one when writing to the log}
  469. {from the idle loop.}
  470. {-----------------------------------------------------------------------------------}
  471.  
  472.     function OpenDebugFile (HermSetup: UserXIPtr): integer;
  473. {-----------------------------------------------------------------------------------}
  474. {This function is just intended to make setting up a debugging file a little easier.  Calling it}
  475. {will open (or create) a file calle "Debug File" inside your Hermes Files folder.  It also stamps}
  476. {the time and date when it was opened to the file.  It returns a integer which is the file}
  477. {reference number or 0 if it wasn't able to open the file.  Save this number in your privates}
  478. {so you can write to the file and later to close it.}
  479. {-----------------------------------------------------------------------------------}
  480.  
  481.     procedure WriteDebugFile (theString: str255; debugRefNum: integer);
  482. {-----------------------------------------------------------------------------------}
  483. {Once again this is to simplify the logging of errors.  Pass it the refNum created by your}
  484. {call to "Open DebugFile" along with the string you want recorded and it will write it to the}
  485. {Debug file.  A return is automatically added to the end of the string.  There is no error}
  486. {checking here but for just testing that is probably preferable.}
  487. {-----------------------------------------------------------------------------------}
  488.  
  489.     procedure CloseDebugFile (debugRefNum: integer);
  490. {-----------------------------------------------------------------------------------}
  491. {This procedure will close the file created by "OpenDebugFile".  Pass it the refNum created}
  492. {by that procedure.}
  493. {-----------------------------------------------------------------------------------}
  494.  
  495.     procedure DebugString (theStr: str255; waitForReply: boolean);
  496. {-----------------------------------------------------------------------------------}
  497. {This procedure is great for debugging.  It requires that you have an freeware application}
  498. {called "Debug Window".  Pass a debugging string in theStr and this will send an AppleEvent}
  499. {to Debug Window that will log that string to the text window of "Debug Window".  This does}
  500. {not add a return to the end of the string but Debug Window has an option to automatically add}
  501. {them to each string that is sent.  The waitForReply variable determines whether it should}
  502. {wait for Debug Window to reply.  If true it will wait (up to 5 seconds) for a reply.  The}
  503. {advantage of waiting for a reply is that strings appear in the Debug Window one at a time}
  504. {as they are sent out.  That way you can watch both the Hermes window and Debug Window}
  505. {and see your debugging strings at the same time that event is taking place in Hermes.  If you}
  506. {don't wait for a reply the stings will tend to bunch up and it won't always be apparent at}
  507. {what stage they generated in Hermes.  The disadvantage to waiting for a reply is that it}
  508. {slows Hermes down some.  Since you will only use this for debugging this is probably}
  509. {acceptable but you have the option to no wait.  This procedure requires System 7 of course.}
  510. {***Note*** As with all debugging procedures, don't forget to take these out before you}
  511. {ship your external.  You can't tell its there but you don't want it there in your finished}
  512. {external.}
  513. {-----------------------------------------------------------------------------------}
  514.  
  515.     procedure DebugTimestamp (waitForReply: boolean);
  516. {-----------------------------------------------------------------------------------}
  517. {This procedure will cause Debug Window to stamp the time and date in the Debug Window.}
  518. {See DebugString for details.}
  519. {-----------------------------------------------------------------------------------}
  520.  
  521.     procedure DebugClearWindow (waitForReply: boolean);
  522. {-----------------------------------------------------------------------------------}
  523. {This procedure will clear the window in Debug Window.  See DebugString for details.}
  524. {-----------------------------------------------------------------------------------}
  525.  
  526.  
  527. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  528. {--------------------------------- String Functions ----------------------------------}
  529. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  530.  
  531.     function GetAString (stringGroup, stringNum: integer; addSpaceAtEnd: boolean): str255;
  532. {-----------------------------------------------------------------------------------}
  533. {Get a string from str# resource.  stringGroup is str# resource number and stringNum is}
  534. {number of individual string in that resource.  addSpaceAtEnd will add a single space at end}
  535. {of string if true.  This is useful when getting strings for prompts.}
  536. {-----------------------------------------------------------------------------------}
  537.  
  538.     function SetAString (stringGroup, stringNum: integer; newStr: Str255): OSErr;
  539. {-----------------------------------------------------------------------------------}
  540. {Write a string to a str# resource.  stringGroup is str# resource number and stringNum is}
  541. {number of individual string in that resource. newStr is the string to be saved. Function}
  542. {returns OSErr}
  543. {-----------------------------------------------------------------------------------}
  544.  
  545.     function SetSizeRight (theString: str255; size: integer): str255;
  546. {-----------------------------------------------------------------------------------}
  547. {Make a string a standard width.  theString is either truncated or spaces are added from}
  548. {the left to make the returned string length of size.}
  549. {-----------------------------------------------------------------------------------}
  550.  
  551.     function SetSizeLeft (theString: str255; size: integer): str255;
  552. {-----------------------------------------------------------------------------------}
  553. {Make a string a standard width.  theString is either truncated or spaces are added from}
  554. {the right to make the returned string length of size.}
  555. {-----------------------------------------------------------------------------------}
  556.  
  557.     function Uppercase (theString: str255): str255;
  558. {-----------------------------------------------------------------------------------}
  559. {Make string uppercase.  All characters in theString are raised to uppercase including}
  560. {diacriticals.}
  561. {-----------------------------------------------------------------------------------}
  562.  
  563.     function Lowercase (theString: str255): str255;
  564. {-----------------------------------------------------------------------------------}
  565. {Make string lowercase.  All characters in theString are lowered to lowercase including}
  566. {diacriticals.}
  567. {-----------------------------------------------------------------------------------}
  568.  
  569.     function CapitalizeWords (theString: str255): str255;
  570. {-----------------------------------------------------------------------------------}
  571. {The first character of each word in theString is made uppercase.}
  572. {-----------------------------------------------------------------------------------}
  573.  
  574.     function NumberToString (num: LONGINT): Str255;
  575. {-----------------------------------------------------------------------------------}
  576. {The number num is converted to a string.  This will accept either longInts or integers}
  577. {-----------------------------------------------------------------------------------}
  578.  
  579.     function RealToString (realNum: real; decimals: integer): str255;
  580. {-----------------------------------------------------------------------------------}
  581. {This function converts realNum to a string.  The number will be rounded to the number of}
  582. {decimals specified by decimals.}
  583. {-----------------------------------------------------------------------------------}
  584.  
  585.     function StringToNumber (theString: str255): longInt;
  586. {-----------------------------------------------------------------------------------}
  587. {theString is converted to a number.  Does not check for characters other than numbers}
  588. {in theString}
  589. {-----------------------------------------------------------------------------------}
  590.  
  591.     function TimeToDateString (time: longInt; style: integer): Str255;
  592. {-----------------------------------------------------------------------------------}
  593. {TimeToString will convert time (obtained by using GetTimeDate or TimeNow) to a string}
  594. {using the International Utilities Toolbox.  There are three choices of style.  Using 1 will}
  595. {return a string in the format 11/24/68. Using 2 will return a string in the format}
  596. {Sunday, November 24, 1968. Using 3 will return Sun, Nov 24, 1968.  There are no}
  597. {leading zeros for these formats.  If you need equal length strings use TimeToStr instead}
  598. {-----------------------------------------------------------------------------------}
  599.  
  600.     function TimeToStr (time: longInt; includeTime: boolean; timeOnly: boolean): Str255;
  601. {-----------------------------------------------------------------------------------}
  602. {time (obtained by using GetTimeDate or TimeNow) is converted to a string with the format}
  603. { (MM/DD/YY HH:MM:SS) or (MM/DD/YY) or (HH:MM:SS) depending on the value of includeTime}
  604. {and timeOnly.  The advantage of this function is that it adds leading zeros so the string returned}
  605. {is always the same length.}
  606. {-----------------------------------------------------------------------------------}
  607.  
  608.     function FindAndReplace (theString: Str255; oldString, newString: Str255): str255;
  609. {-----------------------------------------------------------------------------------}
  610. {This function takes theString and replaces the first occurance of oldString with newString}
  611. {and returns the resulting string.}
  612. {-----------------------------------------------------------------------------------}
  613.  
  614.     function FindAndReplaceAll (theString: Str255; oldString, newString: Str255): str255;
  615. {-----------------------------------------------------------------------------------}
  616. {This function takes theString and replaces the all occurances of oldString with newString}
  617. {and returns the resulting string.}
  618. {-----------------------------------------------------------------------------------}
  619.  
  620.  
  621. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  622. {----------------------------------- Misc Functions ----------------------------------}
  623. {•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
  624.  
  625.     function GetQDGlobals: QDGlobalRec;
  626. {-----------------------------------------------------------------------------------}
  627. {This function will return a QDGlobalRec which is defined above.  This record is identical to}
  628. {the QuickDraw globals which are normally available in an application but not normally}
  629. {available in an external.  Really good stuff can be found here like screenBits.bounds which}
  630. {has the screen size.  This also allows you to use the random call below}
  631. {-----------------------------------------------------------------------------------}
  632.  
  633.     function GetRandom (range: integer): integer;
  634. {-----------------------------------------------------------------------------------}
  635. {This function will return a random number between 1 and range.  When you first call this}
  636. {function it may be a good idea to call it a few times before using its value.  A good way to}
  637. {make it more random might be take the current seconds value and call this function that}
  638. {many times to initialize it.  Without true access to the QDGlobals this function does not}
  639. {properly seed the random call.  After the first time however this call be fine.}
  640. {-----------------------------------------------------------------------------------}
  641.  
  642.     function RandomNumber (range: integer): integer;
  643. {-----------------------------------------------------------------------------------}
  644. {This function will also return a random number but does not rely on the Mac toolbox call. Its}
  645. {your choice.  This may not be as true a random but doesn't suffer from the lack of QD globals}
  646. {that GetRandom does.  If you need to be sure that the first few times you call random are}
  647. {truely random I would use this function rather than the other one.}
  648. {-----------------------------------------------------------------------------------}
  649.  
  650.     function TimeNow: longInt;
  651. {-----------------------------------------------------------------------------------}
  652. {This function returns the current time in seconds since 1/1/1904.  This is just written as}
  653. {a function to make it easier to use.  You can use this with the TimeToDateString to get the}
  654. {current date or time.}
  655. {-----------------------------------------------------------------------------------}
  656.  
  657.     function Sys7OrLater: boolean;
  658. {-----------------------------------------------------------------------------------}
  659. {This function returns whether the current system is 7.0 or later.}
  660. {-----------------------------------------------------------------------------------}
  661.  
  662.     function TrapAvailable (trapNum: integer; tType: TrapType): boolean;
  663. {-----------------------------------------------------------------------------------}
  664. {This function will return whether a trap is available just in case knowing that system 7 is}
  665. {available isn't enough.}
  666. {-----------------------------------------------------------------------------------}
  667.  
  668.     function PlaySound (sndNum: integer; sndName: str255; asynch: boolean; channel: SndChannelPtr): OSErr;
  669. {-----------------------------------------------------------------------------------}
  670. {This function will play a sound on the local machine.  sndNum is the resource number of a }
  671. {'snd ' resource contained in your external.  If you pass a number of 0 the procedure will}
  672. {use the sndName instead.  This may be a better way of making sure that you don't play}
  673. {someone elses sound ;-] If asynch is false the sound will play before control is returned,}
  674. {if true the sound will play asychronously.  If you want to play the sound asynchronously}
  675. {you MUST keep track of a SndChannelPtr in your privates and pass it to this function. This}
  676. {pointer should be intitialized as nil before passing it to PlaySound.  If you set asynch to}
  677. {false you can just pass nil for channel.  I would recommend just passing false and nil unless}
  678. {your sound is really long (which would lock up the BBS until finished).}
  679. {-----------------------------------------------------------------------------------}
  680.  
  681.     function MovedFrom (thePoint: Point; changeAllowed: integer): boolean;
  682. {-----------------------------------------------------------------------------------}
  683. {This function returns whether the mouse has moved more than changeAllowed pixels from}
  684. {thePoint.  Use GetMouse(thePoint) and then LocalToGlobal(thePoint) to get the mouse}
  685. {postion and then this function to decided if it has moved.}
  686. {-----------------------------------------------------------------------------------}
  687.  
  688.     function CheckCard (cardNum: str255; visa, master, amex, discover: boolean): boolean;
  689. {-----------------------------------------------------------------------------------}
  690. {Yea, yea this is getting strange but I needed it so why not make it avaliable.  This function}
  691. {will take a string representing a credit card number and will determine if the number is in}
  692. {the valid format.  Pass true in the remaining varialbes for each type of credit card that is}
  693. {acceptable.  In other words if you pass false for a varialbe that card type will  not be }
  694. {considered valid.  The cardNum string can have spaces although they are not necessary.}
  695. {All spaces will be ignored when evaluating the number.  This function does three things.}
  696. {First, it checks the first number of the card for the credit card type and sees if that type}
  697. {is accepted.  Second, it makes sure that the number is of the proper number of digits for}
  698. {each type.  Third , it does a checksum on the number to see if it is a possible credit card}
  699. {number. This checksum is fairly involved and is not something you would want to do in}
  700. {your head but it is a good way to check cards.  A number which passes these checks is}
  701. {not necessarily valid (ie it may not be assigned to anyone, stolen etc) but this is a good way}
  702. {to screen out fake numbers and mistakes.}
  703. {-----------------------------------------------------------------------------------}
  704.  
  705.     function CheckExpiration (expirationDate: str255): boolean;
  706. {-----------------------------------------------------------------------------------}
  707. {This function will take an expiration date (in the form MM/YY) and return whether this date}
  708. {has passed yet.  With this and CheckCard, assuming the information is given truthfully, you}
  709. {can confirm the validity of a credit card immeadiately.}
  710. {-----------------------------------------------------------------------------------}
  711.  
  712.     procedure SetMouse (newPoint: Point);
  713. {-----------------------------------------------------------------------------------}
  714. {This procedure will set the cursor to newPoint.  Why you would want to do this is beyond me}
  715. {but I had a reason to do so (the user doesn't ever notice).  This is a really rude thing to do}
  716. {and is a good way to have an program which flops (people hate the mouse moving on them)}
  717. {-----------------------------------------------------------------------------------}
  718.  
  719. implementation
  720.  
  721. end.