home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / rap101.zip / COMMON.RAP < prev    next >
Encoding:
Text File  |  1989-05-10  |  19.1 KB  |  818 lines

  1. ; common.rap  v1.01  compacted version - copyright 1988 SIL - 10 May 1989
  2. #verbose=1
  3. if ($screentype == "Sharp LCD")
  4. $skip=$null
  5. else
  6. $skip=$newline*chr(13)
  7. endif
  8. $valdr=*getdr__()
  9. #help__= -1
  10. $helpfile__=
  11. $dospath__=$path
  12. proc error($message,$topic)
  13. declare $tag,$indent
  14. declare $left,$match,$right
  15. if (not ($message contains "[.!?]$"))
  16. $message=$message.
  17. endif
  18. if ($message contains "^[ \\t][ \\t]*")
  19. $indent=$match
  20. endif
  21. t:$skip*chr(7)$message\
  22. if ($topic == "")
  23. $tag=Try again.
  24. else
  25. $tag=Try again.  (Type ? for help.)
  26. endif
  27. if ((*strlen($message) + *strlen($tag)) > 72)
  28. t:
  29. t:$indent\
  30. else
  31. t:  \
  32. endif
  33. t:$tag
  34. endproc
  35. proc warning($message)
  36. if (not $message has "\\.?!$")
  37. $message=$message.
  38. endif
  39. t:$skip*chr(7)$message.
  40. kbflush()
  41. foot
  42. endproc
  43. proc mount_volume($drive,$id,$name,$topic)
  44. declare $volname,#fd,#case,#opentest,#reopen_help
  45. loop
  46. $volname=*volume($drive)
  47. exit if ($volname == $id)
  48. if (not #opentest)
  49. #opentest = 1
  50. #fd = *open("nul")
  51. close #fd
  52. if (#fd > 1 or (#fd > 0 and #help__ == -1))
  53. t:*chr(7)
  54. t:The program needs to change disks so that the $name
  55. t:disk is accessible, but it is not safe to do so because the program has
  56. t:one or more files open.
  57. t:
  58. if ($topic <> "")
  59. explain($topic)
  60. else
  61. t:   The program must terminate immediately.  Please report this
  62. t:   message to the program's author.
  63. endif
  64. foot
  65. bye
  66. endif
  67. endif
  68. if (#help__ >= 0)
  69. close #help__
  70. #help__ = -1
  71. #reopen_help = 1
  72. endif
  73. t:$skip\Put the $name disk in drive $drive.
  74. kbflush()
  75. foot:Press RETURN after you have done this.
  76. endloop
  77. if (#reopen_help)
  78. reopen_help__()
  79. endif
  80. endproc
  81. proc panic__($location,$msg)
  82. declare #paged
  83. t:*chr(7)$skip\Internal error in \*$location:
  84. t:
  85. t:    $msg
  86. t:
  87. t:The program will continue to run, but the results may not be valid.
  88. t:Copy this message exactly, so you can report it to the program's author,
  89. t:and exit as soon as possible.  You may exit immediately by typing
  90. t:Ctrl-C.
  91. kbflush()
  92. foot
  93. endproc
  94. proc kbflush()
  95. declare $junk
  96. loop while (*keypress())
  97. as $junk
  98. endloop
  99. endproc
  100. strfunc getdr__()
  101. declare $drvlist,$tmp,#case,#tmp
  102. declare $left,$match,$right
  103. if ($cmdline contains "[-/]drive=[ \\t]*")
  104. $drvlist=$right
  105. if ($drvlist contains "[ \\t]")
  106. $drvlist=$left
  107. endif
  108. return $drvlist
  109. endif
  110. if ($screentype == "Sharp LCD")
  111. if (*freesp("P") == -1)
  112. return "ABCDG"
  113. else
  114. return "ABCDGP"
  115. endif
  116. else
  117. $drvlist=AB
  118. $tmp=C
  119. loop while (*freesp($tmp) > 0)
  120. $drvlist=$drvlist$tmp
  121. #tmp = *ascii($tmp) + 1
  122. $tmp=*chr(#tmp)
  123. endloop
  124. return $drvlist
  125. endif
  126. endfunc
  127. proc explain($topic)
  128. declare #case,$line
  129. declare $left,$match,$right
  130. if (not #verbose)
  131. return
  132. else if (#help__ < 0)
  133. t:There is no help-file available to this program.
  134. foot
  135. return
  136. endif
  137. seek #help__,2
  138. loop while ($line <> "End of file.")
  139. read #help__,$line
  140. exit if (not ($line contains ":"))
  141. exit if ($left == $topic)
  142. endloop
  143. if ($line == "End of file." or $left <> $topic)
  144. t:Sorry, there is no information on <$topic> in the help file.
  145. foot
  146. return
  147. endif
  148. seek #help__,*value($right),bytes
  149. loop
  150. read #help__,$line
  151. exit if ($line == "End of file.")
  152. if (not ($line has "^\\\\"))
  153. t:$line
  154. else if ($line=="\\cls")
  155. cls
  156. else if ($line=="\\foot")
  157. foot
  158. else if ($line has "^\\\\topic[ \\t]")
  159. exit
  160. else
  161. t:$line
  162. endif
  163. endloop
  164. endproc
  165. strfunc get_filespec($query,$defpath,$defname,$defext,$topic)
  166. declare $answer,$left,$match,$right,#case,$default,$defdrive
  167. $drive=
  168. $subdir=
  169. $name=
  170. $ext=
  171. $defext=*ensure_dot($defext)
  172. if ($defpath <> "")
  173. if (not ($defpath has "[:\\\\]$"))
  174. $defpath=$defpath\\        
  175. endif
  176. endif
  177. $default=$defname$defext
  178. if ($default <> "")
  179. $query=$query [$default]
  180. endif
  181. loop
  182. $answer=*get_ans("$query (type DIR for directory):","",$topic,not +
  183. *strlen($default))
  184. if (($answer == "") and ($default == $defext))
  185. error("  Your answer must always include a filename part.",$topic)
  186. repeat
  187. else if ($answer == "")
  188. $answer=$defpath$defname$defext
  189. else if ($answer contains "^[ \\t]*dir\[ \\t]*")
  190. show_dir__($right,$defpath,$defext)
  191. repeat
  192. endif
  193. if (not ($answer has "[\\\\:]"))
  194. $answer=$defpath$answer
  195. endif
  196. if (*parse_filespec($answer,1,$topic))
  197. if ($ext == "")
  198. $ext=$defext
  199. endif
  200. return "$drive$subdir$name$ext"
  201. endif
  202. endloop
  203. endfunc
  204. strfunc get_input_file($query,$defpath,$defname,$defext,$topic)
  205. declare #case,#verbose,$filespec
  206. declare $oldname
  207. #verbose=1
  208. loop
  209. $filespec=*get_filespec($query,$defpath,$defname,$defext,$topic)
  210. #filesize=*filesize($filespec)
  211. if (#filesize < 0)
  212. error("  $filespec does not exist.",$topic)
  213. else
  214. #filesize=(#filesize+1023)/1024
  215. if (($ext == ".TMP") or ($ext == ".BAK"))
  216. t:*chr(7)An input file may not have a TMP or BAK extension.
  217. repeat if (*no("Do you want to rename the file to a different+
  218. extension","",""))
  219. $oldname=$filespec
  220. loop
  221. $ext=*get_str("New extension for $oldname","","",1,4,1)
  222. $ext=*ensure_dot($ext)
  223. $filespec=$drive$subdir$name$ext
  224. if (not *val_ext($ext,$topic))
  225. repeat
  226. else if (($ext == ".TMP") or ($ext == ".BAK"))
  227. error("  You must rename the extension to something besides TMP or BAK.",$topic)
  228. else if (not *existf($filespec))
  229. exit
  230. endif
  231. t:*chr(7)$filespec already exists.  Try a different extension.
  232. endloop
  233. xs ren $oldname $name$ext
  234. endif
  235. return $filespec
  236. endif
  237. endloop
  238. endfunc
  239. strfunc get_output_file($query,$defpath,$defname,$defext,$topic,#size)
  240. declare $filespec,#case
  241. loop
  242. $filespec=*get_filespec($query,$defpath,$defname,$defext,$topic)
  243. if (*delq($filespec) <> 4)
  244. ensure_space($drive,$subdir,#size)
  245. return $filespec
  246. endif
  247. endloop
  248. endfunc
  249. proc ensure_space($dr,$subdir,#size)
  250. declare #need
  251. declare $spare
  252. declare $delname
  253. declare $path
  254. declare $name,$ext
  255. declare $drive
  256. declare #attr
  257. if (#size < 1)
  258. return
  259. else if ($dr == "")
  260. $dr=*currdriv():
  261. else
  262. $dr=*to_upper("*mid($dr,1,1)"):
  263. endif
  264. loop
  265. #need=#size-(*freesp($dr)/1024)
  266. exit if (#need < -10)
  267. if (#need > 0)
  268. t:*chr(7)\
  269. t:
  270. t:There is not enough space for the output file on drive $dr.
  271. t:You need to reclaim at least #need\K of space before proceeding.
  272. else
  273. if (#need == 0)
  274. $spare=absolutely no space
  275. else
  276. #need = (0 - #need)
  277. $spare=only #need\K
  278. endif
  279. t:*chr(7)\
  280. t:
  281. t:Your output file will probably fit on drive $dr, but there is
  282. t:$spare to spare.  If there is a possibility that the output file
  283. t:will grow, it would be wise to make some extra space for the +
  284. output file.
  285. exit if (*no("Do you want to pause to delete some files","y",""))
  286. endif
  287. xs dir $dr$subdir /w /p
  288. get_filespec("File to delete","$dr$subdir","","","")
  289. if (*to_upper($dr) <> *to_upper($drive))
  290. error("  You must delete files on drive *to_upper($dr).","")
  291. else
  292. $delname=$dr$subdir$name$ext
  293. #attr = *deletef($delname)
  294. if (#attr == 0)
  295. t:File $delname not found.
  296. else if (#attr == 4)
  297. t:File $delname is read-only and can't be deleted.
  298. endif
  299. endif
  300. endloop
  301. endproc
  302. strfunc make_tmp_output($file,#size)
  303. declare $left,$right,$match,#case,$path
  304. declare $drive
  305. if ($file contains "\\.[^\\.\\\\]*$")
  306. $file=$left.TMP
  307. else
  308. $file=$file.TMP
  309. endif
  310. if ($file contains ":")
  311. $drive=$left
  312. else
  313. $drive=
  314. endif
  315. if (*deletef($file) == 4)
  316. panic__("make_tmp_output","Need to delete $file but it's read-only")
  317. endif
  318. ensure_space($drive,"",#size)
  319. return $file
  320. endfunc
  321. proc make_bak_file($oldname,$tmpname)
  322. declare $left,$match,$right,#case
  323. declare $bak
  324. if ($oldname contains "\\.[^\\.\\\\]*$")
  325. $bak=$left.BAK
  326. else
  327. $bak=$oldname.BAK
  328. endif
  329. if (*deletef($bak) == 4)
  330. panic__("make_bak_file","need to delete $bak but it's read-only")
  331. else
  332. xs ren $oldname *.BAK
  333. if ($oldname contains "[^:\\\\]*$")
  334. xs ren $tmpname $match
  335. else
  336. warning("Couldn't rename $tmpname to $oldname")
  337. endif
  338. endif
  339. endproc
  340. proc make_bak_to_bat($oldname,$tmpname,#bat)
  341. declare $left,$match,$right,#case
  342. declare $bak
  343. if ($oldname contains "\\.[^\\.\\\\]*$")
  344. $bak=$left.BAK
  345. else
  346. $bak=$oldname.BAK
  347. endif
  348. wr #bat,if exist $bak del $bak
  349. wr #bat,if exist $oldname ren $oldname *.bak
  350. if ($oldname contains "[^:\\\\]*$")
  351. wr #bat,if exist $tmpname ren $tmpname $match
  352. else
  353. warning("Couldn't rename $tmpname to $oldname")
  354. endif
  355. endproc
  356. strfunc ensure_dot($ext)
  357. if ($ext <> "")
  358. if (*mid($ext,1,1) <> ".")
  359. $ext=.$ext
  360. endif
  361. endif
  362. return $ext
  363. endfunc
  364. numfunc val_ext($ext,$topic)
  365. declare $left,$match,$right
  366. if ($ext == "")
  367. return (1)
  368. else if ($ext has "^\\.[a-z0-9_A-Z!@#$%^&()'`{}~\-]*$")
  369. if (*strlen($match) > 4)
  370. error("  No more than 3 characters in extension.",$topic)
  371. else
  372. return (1)
  373. endif
  374. else
  375. error("  Extension contains invalid characters",$topic)
  376. return (0)
  377. endif
  378. endfunc
  379. numfunc val_dir($subdir,$topic)
  380. declare $left,$match,$right
  381. if ($subdir == "" or ($subdir contains "^[\\\\\\.a-z0-9_A-Z!@#$%^&()'`{}~\-][\\\\\\.a-z0-9_A-Z!@#$%^&()'`{}~\-]*$"))
  382. return (1)
  383. else if (*index($subdir,"/"))
  384. error("  Path names use \\, not /.",$topic)
  385. else if ($subdir has "[^\\\\\\.]\\." or $subdir has "\\.[^\\\\\\.]" or $subdir has "\\.\\.\\.")
  386. error("  Dots in subdirectories cannot be mixed with other +
  387. characters.",$topic)
  388. else 
  389. error("  Subdirectory name(s) include invalid characters",$topic)
  390. endif
  391. return (0)
  392. endfunc
  393. numfunc val_drive($drive,$topic)
  394. declare #case
  395. if ($drive has "^[$valdr]:$")
  396. return 1
  397. else if ($drive has "^.:$")
  398. error("  Drive *to_upper($drive) does not exist.",$topic)
  399. else if (*index($drive,":"))
  400. error("  Cannot use *to_upper($drive) - must be a disk drive",$topic)
  401. else
  402. error("  Invalid drive designator: $drive",$topic)
  403. endif
  404. return (0)
  405. endfunc
  406. numfunc delq($filespec)
  407. declare $path,#attrib
  408. #attrib = *existf($filespec)
  409. if (#attrib == 0)
  410. return (0)
  411. else if (#attrib == 4)
  412. t:*chr(7)$filespec already exists and can't be deleted.
  413. return (4)
  414. else
  415. t:*chr(7)$filespec already exists.  \
  416. kbflush()
  417. if (*yes("Do you want to overwrite it","",""))
  418. killf $filespec
  419. return (2)
  420. else
  421. return (4)
  422. endif
  423. endif
  424. endfunc
  425. numfunc deletef($file)
  426. declare $path,#attr
  427. #attr = *existf($file)
  428. if (#attr == 4)
  429. return (4)
  430. else if (#attr == 2 or #attr == 1)
  431. killf $file
  432. return (2)
  433. else
  434. return (0)
  435. endif
  436. endfunc
  437. strfunc get_ans($query,$default,$topic,#oblig)
  438. declare $answer, $prompt, #verbose
  439. #verbose = 1
  440. if (not ($query has "[?:]$"))
  441. $query=$query?
  442. endif
  443. if ($default <> "")
  444. $query=$query [$default]
  445. endif
  446. loop
  447. t:$skip$query \
  448. a:$answer
  449. if ($answer == "")
  450. if (#oblig and $default == "")
  451. error("  This question requires an answer.",$topic)
  452. else
  453. return $default
  454. endif
  455. else if ($answer == "?")
  456. if ($topic <> "")
  457. explain($topic)
  458. else
  459. error("  There is no help for this question.","")
  460. endif
  461. else
  462. return $answer
  463. endif
  464. endloop
  465. endfunc
  466. numfunc yes($query,$default,$topic)
  467. declare $answer,#case
  468. loop
  469. $answer=*get_ans($query,$default,$topic,not *strlen($default))
  470. $answer=*trim($answer)
  471. if (($answer == "y") or ($answer == "yes"))
  472. return(1)
  473. else if (($answer == "n") or ($answer == "no"))
  474. return(0)
  475. else
  476. error("  Please type yes or no.",$topic)
  477. endif
  478. endloop
  479. endfunc
  480. numfunc no($query,$default,$topic)
  481. return (not *yes($query,$default,$topic))
  482. endfunc
  483. strfunc get_str($query,$default,$topic,#minlen,#maxlen,#oblig)
  484. declare $answer,#len
  485. if (#minlen > #maxlen)
  486. panic__("get_str","minimum length is greater than maximum length")
  487. #minlen = 0
  488. endif
  489. if (#maxlen < 1)
  490. panic__("get_str","maximum length of zero")
  491. #maxlen = 78
  492. endif
  493. loop
  494. $answer=*get_ans($query,$default,$topic,#oblig)
  495. #len = *strlen($answer)
  496. if (#len < #minlen)
  497. error("  Answer too short - must be at least #minlen characters.",$topic)
  498. else if (#len > #maxlen)
  499. error("  Answer too long - must be #maxlen characters or less.",$topic)
  500. else
  501. return $answer
  502. endif
  503. endloop
  504. endfunc
  505. strfunc get_code($query,$default,$topic,#minlen,#maxlen)
  506. declare $answer,$left,$right,$match,#case
  507. if (#maxlen > 78)
  508. #maxlen = 78
  509. endif
  510. if ($default <> "")
  511. if ($default contains "^\\\\\\\\*")
  512. $default=\\$right
  513. else
  514. $default=\\$default
  515. endif
  516. endif
  517. loop
  518. $answer=*get_str("$query",$default,$topic,#minlen,#maxlen+1,#minlen)
  519. $answer=*trim($answer)
  520. if ($answer contains "^\\\\*")
  521. $answer=$right
  522. endif
  523. if (not ($answer has "^[a-z0-9_]*$"))
  524. error("  Slash code may contain only letters, digits, and _.",$topic)
  525. else if (*strlen($answer) < #minlen)
  526. error("  Code is too short - must be at least #minlen characters (not including \\).",$topic)
  527. else if (*strlen($answer) > #maxlen)
  528. error("  Code is too long - must be no more than #maxlen characters.",$topic)
  529. else
  530. return $answer
  531. endif
  532. endloop
  533. endfunc
  534. numfunc get_num($query,$default,$topic,#min,#max)
  535. declare $string,#number
  536. if ($default <> "")
  537. if (not *isnumber($default))
  538. panic__("getnum","default value is not a number")
  539. $default=
  540. endif
  541. endif
  542. if (#min > #max)
  543. panic__("getnum","minimum is greater than maximum")
  544. #min = (-2147483639)
  545. #max = 2147483639
  546. endif
  547. loop
  548. $string=*get_ans($query,$default,$topic,not *strlen($default))
  549. if (*isnumber($string))
  550. #number = *value($string)
  551. if ((#number >= #min) and (#number <= #max))
  552. return (#number)
  553. endif
  554. endif
  555. error("  Please enter a number between #min and #max.",$topic)
  556. endloop
  557. endfunc
  558. strfunc to_lower($source)
  559. declare $left,$match,$right
  560. declare #case
  561. #case=1
  562. loop while ($source contains "[A-Z]")
  563. $source=$left*chr(*ascii($match)+32)$right
  564. endloop
  565. return $source
  566. endfunc
  567. strfunc to_upper($source)
  568. declare $left,$match,$right
  569. declare #case
  570. #case=1
  571. loop while ($source contains "[a-z]")
  572. $source=$left*chr(*ascii($match)-32)$right
  573. endloop
  574. return $source
  575. endfunc
  576. strfunc trim($source)
  577. declare $left,$match,$right
  578. if ($source contains "^[ \\t][ \\t]*")
  579. $source=$right
  580. endif
  581. if ($source contains "[ \\t][ \\t]*$")
  582. $source=$left
  583. endif
  584. return $source
  585. endfunc
  586. proc show_dir__($spec,$defpath,$defext)
  587. if ($spec <> "")
  588. xs dir $spec
  589. else
  590. if ($defext <> "")
  591. $defext=*ensure_dot($defext)
  592. $defext=*$defext
  593. endif
  594. if ($defpath <> "")
  595. if (not ($defpath has "[:\\\\]$"))
  596. $defpath=$defpath\\
  597. endif
  598. endif
  599. xs dir $defpath$defext /w
  600. endif
  601. foot
  602. endproc
  603. numfunc parse_filespec($filespec,#report,$topic)
  604. $drive=
  605. $subdir=
  606. $name=
  607. $ext=
  608. if ($filespec contains ":")
  609. $drive=$left:
  610. $filespec=$right
  611. if (#report)
  612. if (not *val_drive($drive,$topic))
  613. return (0)
  614. endif
  615. else if (not ($drive has "^[$valdr]:$))
  616. return (0)
  617. endif
  618. endif
  619. if ($filespec contains "\\.[^\\.\\\\]*$")
  620. if (*strlen($match) > 4)
  621. if (#report)
  622. error("  Extension is too long",$topic)
  623. endif
  624. return (0)
  625. else if ($match has "[^\\.a-z0-9_A-Z!@#$%^&()'`{}~\-]")
  626. if (#report)
  627. error("  Invalid character(s) in extension.",$topic)
  628. endif
  629. return (0)
  630. endif
  631. $ext=$match
  632. $filespec=$left
  633. endif
  634. if ($filespec has "[^\\\\\\.]\\." or $filespec has "\\.[^\\\\\\.]" or $filespec has "\\.\\.\\.")
  635. if (#report)
  636. error("  Invalid dots in pathname (only . and .. are valid).",$topic)
  637. endif
  638. return (0)
  639. endif
  640. if ($filespec has "[^a-z0-9_A-Z!@#$%^&()'`{}~\-\\.\\\\]")
  641. if (#report)
  642. error("  Invalid character(s) in subdirectory or filename.",$topic)
  643. endif
  644. return (0)
  645. endif
  646. if ($filespec contains "[^\\\\\\.][^\\\\\\.]*$")
  647. $name=$match
  648. $filespec=$left
  649. $subdir=$left
  650. else
  651. if (#report)
  652. error("  Filename is missing.",$topic)
  653. endif
  654. return (0)
  655. endif
  656. return (1)
  657. endfunc    
  658. proc open_help($helpfile)
  659. loop while (not *existf($helpfile))
  660. t:*chr(7)The program's help file ($helpfile) cannot be found.  At this point you may:
  661. t:
  662. menu
  663. option enter the correct location (drive and directory) for the help file.
  664. $helpfile=*get_str("Help-file location","","",0,64,0)
  665. option continue without on-line help available
  666. return
  667. option quit the program now
  668. if (*yes("Are you sure you want to quit","",""))
  669. bye
  670. endif
  671. endmenu
  672. endloop
  673. #help__ = *open($helpfile)
  674. $helpfile__=*findpath($helpfile)
  675. return
  676. endproc    
  677. strfunc get_append_file($query,$defpath,$defname,$defext,$topic)
  678. declare #case,#verbose,$filespec,$path
  679. declare $oldname
  680. declare #attrib,#file
  681. #verbose=1
  682. loop
  683. $filespec=*get_filespec($query,$defpath,$defname,$defext,$topic)
  684. #attrib = *existf($filespec)
  685. if (#attrib == 4)
  686. error("  $name$ext is read-only.  You must use a different file.",$topic)
  687. repeat
  688. else if (#attrib == 0)
  689. #file = *open($filespec,"w")
  690. close #file
  691. endif
  692. #filesize=(*filesize($filespec)+1023)/1024
  693. if (($ext <> ".TMP") and ($ext <> ".BAK"))
  694. exit
  695. else
  696. t:*chr(7)An "append" file may not have a TMP or BAK extension.
  697. repeat if (*no("Do you want to rename the file to a different extension","",""))
  698. $oldname=$filespec
  699. loop
  700. $ext=*get_str("New extension for $oldname","","",1,4,1)
  701. $ext=*ensure_dot($ext)
  702. $filespec=$drive$subdir$name$ext
  703. if (not *val_ext($ext,$topic))
  704. repeat
  705. else if (($ext == ".TMP") or ($ext == ".BAK"))
  706. error("  You must rename the extension to something besides TMP or BAK.",$topic)
  707. else if (not *existf($filespec))
  708. exit
  709. endif
  710. t:*chr(7)$filespec already exists.  Try a different extension.
  711. endloop
  712. xs ren $oldname $name$ext
  713. $filespec=$drive$subdir$name$ext
  714. exit
  715. endif
  716. endloop
  717. return $filespec
  718. endfunc
  719. strfunc get_fixed_output($filespec,#size,#allow_sub,$query,$topic)
  720. declare $path
  721. if (*deletef($filespec) == 4)
  722. if (not #allow_sub)
  723. t:*chr(7)
  724. t:This program needs to create an output file named $filespec,
  725. t:but there is an existing file with that name that is read-only.
  726. t:
  727. if ($topic <> "")
  728. explain($topic)
  729. else
  730. t:You must rename or delete the existing copy of
  731. t:$filespec and then rerun this program.
  732. endif
  733. foot
  734. bye
  735. else if (not *parse_filespec($filespec,0,""))
  736. panic__("get_fixed_output","invalid filespec ($filespec)")
  737. endif
  738. $filespec=*get_output_file($query,"$drive$subdir","",$ext,$topic,#size)
  739. endif
  740. return $filespec
  741. endfunc
  742. proc mount_program($filespec,$topic)
  743. mount_file__($filespec,1,$topic)
  744. endproc
  745. proc mount_file__($filespec,#is_prog,$topic)
  746. declare $path,#nullfile,#reopen_help,$program
  747. if (#is_prog)
  748. $path=$dospath__
  749. $program=program$blank
  750. endif
  751. #nullfile = -2
  752. loop while (not *existf($filespec))
  753. t:
  754. if (#nullfile < -1)
  755. t:*chr(7)\
  756. #nullfile = *open("nul")
  757. close #nullfile
  758. if (#nullfile > 1 or (#nullfile > 0 and #help__ == -1))
  759. t:   This program needs to change disks so that the $filespec
  760. t:   $program\file is accessible, but it is not safe to do so because
  761. t:   one or more files are open.
  762. t:
  763. if ($topic <> "")
  764. explain($topic)
  765. else
  766. t:   The program must terminate immediately.  Please report this
  767. t:   message to the program's author.
  768. endif
  769. foot
  770. bye
  771. endif
  772. endif
  773. t:   This program needs access to the $program\file $filespec.
  774. t:   If you can change disks without removing any of your data files, please
  775. t:   do so now.  Otherwise, exit by typing Ctrl-C and rearrange your disks
  776. t:   so $filespec is available when this program is run.
  777. t:
  778. if (#help__ >= 0)
  779. close #help__
  780. #help__ = -1
  781. #reopen_help = 1
  782. endif
  783. kbflush()
  784. foot Press ENTER when you have changed disks.
  785. endloop
  786. if (#reopen_help)
  787. reopen_help__()
  788. endif
  789. endproc
  790. proc mount_file($filespec,$topic)
  791. mount_file__($filespec,0,$topic)
  792. endproc
  793. proc reopen_help__()
  794. if (*existf($helpfile__))
  795. #help__ = *open($helpfile__)
  796. else
  797. t:*chr(7)
  798. t:The help-file for this program was on the disk you removed.  You have
  799. t:successfully changed disks, and the program should operate properly.
  800. t:However, help information will no longer be available when you type '?'.
  801. t:
  802. $helpfile__=
  803. kbflush()
  804. foot
  805. endif
  806. endproc
  807. .define .BELL t:*chr(7)\
  808. .define .YES 1
  809. .define .NO 0
  810. .define .NOTFOUND 0
  811. .define .READWRITE 2
  812. .define .READONLY 4
  813. .define .MININT (-2147483639)
  814. .define .MAXINT   2147483639
  815. .define .MAXCODE 78
  816. .define .FILECHARS a-z0-9_A-Z!@#$%^&()'`{}~\-
  817. .define .LOCALMATCH declare $left,$match,$right
  818.