home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / m / msh_ut11.zip / MYDEFS.ZIP / STDDEFS.MSH < prev    next >
Text File  |  1992-05-09  |  16KB  |  562 lines

  1. |    file: STDDEF.MSH      Standard definitions for Mi-Shell
  2. |───────────────────────────────────────────────────────────
  3. |
  4. |              ┌─────────────────────────────────────────────┐
  5. |              │ utilities to get various parts of a pathname│
  6. |              └─────────────────────────────────────────────┘
  7. |
  8. ("."cutlast drop)basename!
  9. ("."cutlast swap drop)extension!
  10. |
  11. | the following definition tests if top is a substring of top+1
  12. |
  13. (swap dup 3 roll cutfirst drop = not )belong!
  14. |
  15. | Cut a pathname into its unit and the rest.
  16. |
  17. (dup ":"cutfirst dup
  18.  (3 roll drop swap":"&swap)
  19.  (drop 2 pick =
  20.   (false swap)
  21.   (false)
  22.   ifelse
  23.  )
  24.  ifelse
  25. )unit_and_name!
  26. |
  27. | Get the directory of a pathname. It is hard because of DOS's dumb syntax.
  28. | examples:  "a:x\y" -> "a:x", "a:x\" -> "a:x\.",   "a:" -> "a:.", etc...
  29. |
  30. (unit_and_name
  31.  dup"\\"cutlast
  32.  (dup(swap drop)
  33.      (drop drop "\\")
  34.      ifelse
  35.  )
  36.  (drop &".")
  37.  ifelse
  38.  &
  39. )directory!
  40. |
  41. | A simpler variant which gives the directory part of a pathname, so
  42. | that dirpart&filepart=initial pathname.
  43. | examples:  "a:x\y" -> "a:x\", "a:x\" -> "a:x\",   "a:" -> "a:", etc...
  44. |
  45. (dup "\\"endsby("."&)if
  46.  unit_and_name"\\"cutlast
  47.  ("\\"&)
  48.  (drop"")
  49.  ifelse
  50.  &
  51. )dirpart!
  52. |
  53. | Get the filename part of a pathname.
  54. |
  55. (unit_and_name swap drop
  56.  "\\"cutlast dup
  57.  (swap drop)
  58.  (drop)
  59.  ifelse
  60. )filepart!
  61. |
  62. | makename puts together a directory and a filename. The difficulty is
  63. | to add a '\' when necessary.
  64. |
  65. (2 pick swap cutlast (drop drop false)(match not)ifelse)endsby!
  66. |
  67. (swap
  68.  dup "\\" endsby
  69.  (dup ":" endsby
  70.   ("\\"&)ifnot
  71.  )
  72.  ifnot
  73.  swap &
  74. )makename!
  75. |
  76. |              ┌─────────────────────────────────┐
  77. |              │ various kind of loops on a panel│
  78. |              └─────────────────────────────────┘
  79. |
  80. | loop_panel: general loop operator. Assumes top is a piece of code and
  81. | executes it for each entry in the panel
  82. |
  83. ( action!
  84.   panel.nbfiles 0 =
  85.   (
  86.   current.pos oldpos! 0 current.pos!
  87.   (action current.pos 1+ dup current.pos! panel.nbfiles = not)()while
  88.   oldpos current.pos!
  89.   )
  90.   ifnot
  91. )loop_panel!
  92. |
  93. | deselect: deselect all selected files.
  94. |
  95. ((current.selected(false current.selected!)if)loop_panel
  96. )deselect!
  97. |
  98. | foreachselected: supposes <Top> is a piece of code taking 1 argument,
  99. | and execute for each selected file that code with the selected
  100. | file as argument (uses current if no file was selected)
  101. |
  102. ( action! current.pos oldpos! 0 current.pos! false found!
  103.   (current.selected(true found! false current.selected! current.name action)if
  104.    current.pos 1+ dup current.pos! panel.nbfiles = not)()
  105.   while
  106.   oldpos current.pos!
  107.   found (current.name action)ifnot
  108. )foreachselected!
  109. |
  110. | foreachbase: same as foreachselected but use the basename as argument.
  111. |
  112. ( action! current.pos oldpos! 0 current.pos! false found!
  113.   (current.selected(true found! false current.selected! current.name basename
  114.    action)if current.pos 1+ dup current.pos! panel.nbfiles = not)()
  115.   while
  116.   oldpos current.pos!
  117.   found (current.name action)ifnot
  118. )foreachbase!
  119. |
  120. | selected_list: <Push> the list of selected files, catenated with blanks
  121. | as separators. If nothing was selected, <Push> current.
  122. |
  123. ( false (current.selected(current.name&" "&)if)loop_panel
  124.   dup (drop current.name)ifnot
  125. )selected_list!
  126. |
  127. | next: circular version of down to be used in circular searches
  128. |
  129. (current.pos 1+ dup current.pos! panel.nbfiles=(0 current.pos!)if)next!
  130. |
  131. | search: positions to the first file matching <Top>
  132. |
  133. ( current.name
  134.   (2 pick current.name match
  135.    (false)
  136.    (next dup current.name = not)
  137.    ifelse
  138.   )
  139.   ()
  140.   while
  141.   drop
  142. )search!
  143. |
  144. |              ┌──────────────────────┐
  145. |              │ updates of the panels│
  146. |              └──────────────────────┘
  147. |
  148. |  refresh refills the panel with the contents of the current directory
  149. |
  150. (cwd panel.pattern filepart makename panel.pattern!)refresh!
  151. |
  152. |  reread updates the current panel by rereading from disk (but doesn't
  153. |  change its directory to the current one: use refresh for that)
  154. |
  155. (panel.pattern panel.pattern!)reread!
  156. |
  157. | variants which deal with the next panel
  158. |
  159. ("panel.on_activate"@oa! ()panel.on_activate! next_panel
  160.  #prev_panel oa "panel.on_activate!"&#)in_next_panel!
  161. ((reread) in_next_panel)reread_next!
  162. ((panel.pattern directory)in_next_panel)next_dir!
  163. |
  164. |
  165. |              ┌──────────────────────┐
  166. |              │ variants of 'execute'│
  167. |              └──────────────────────┘
  168. |
  169. | execshow: show the command in a message window before executing it
  170. |
  171. (dup 600 swap"Executing..." swap flash execute)execshow!
  172. |
  173. | exec: usual variant: just reread after 'execute'
  174. |
  175. (execute reread)exec!
  176. |
  177. | with_magic: do something with `magic' swap enabled
  178. | with_nomagic: do something with magic off
  179. | with_magicnoxms: do something with swap to disk enabled but swap to xms disabled
  180. |
  181. (magic oldmagic!"*"magic! # oldmagic magic!)with_nomagic!
  182. (magic oldmagic!tmp_dir magic! # oldmagic magic!)with_magic!
  183. (magic oldmagic!"*"tmp_dir& magic! # oldmagic magic!)with_magicnoxms!
  184. |
  185. | confirm: ask confirmation before executing command
  186. |
  187. (act! dup ok(act)(drop)ifelse)confirm!
  188. |
  189. ((true)(false)3 roll nl&" %yes% %no%"&
  190. (false)"-1" 5 e_att e_att current_selected_att true false menu.install)
  191. my_ok!
  192. |
  193. | execsave: variant executed by Enter which saves the command on the circular
  194. | list of saved commands before execution
  195. |
  196. ( cmd dup cmdlist nl&swap&cmdlist! dup
  197.   " "cutfirst drop"."cutfirst drop"*"nl&swap&nl&"*"& dup magic_list match
  198.   ( drop(execute)with_magic)
  199.   ( nl"set"&match
  200.     ("="cutfirst dup(swap " " cutlast swap drop "$"swap& !)
  201.                     (drop execute)ifelse)
  202.     (execute)ifelse
  203.   )ifelse 
  204.   cmd.clear refresh
  205. )execsave!
  206. |
  207. | below is part of the code for Enter.
  208. |
  209. ( current.isdir
  210.   ( current.name cwd! refresh)
  211.   ( "extension_" current.name extension&#)
  212.   ifelse
  213. )cur_action!
  214. |
  215. ("cur_action"panel.type&#)act_on_cur!
  216. |
  217. (current.isdir
  218.  (current.name cwd! refresh)
  219.  ("extension2_" current.name extension&#)
  220.  ifelse
  221. )act2_on_cur!
  222. |
  223. |              ┌───────────────────────────────┐
  224. |              │ now, the actions on the panels│
  225. |              └───────────────────────────────┘
  226. |
  227. | wide_narrow: flip between complete/name only listing of entries
  228. |
  229. (panel.size(false panel.size! false panel.attrs!
  230.             false panel.date! false panel.time!)
  231.        (true  panel.size! true  panel.attrs!
  232.         true  panel.date! true  panel.time!)
  233.        ifelse
  234. )wide_narrow!
  235. |
  236. (panel.rc drop linescols drop 2/ 1- <
  237.  (side_by_side)
  238.  (linescols drop 4/ nb_pn_lines! menu_line 1+ 0 panel.startrc!nb_pn_lines 79  panel.rc!
  239.   (nb_pn_lines menu_line 1++ 0 panel.startrc!nb_pn_lines 79  panel.rc!)in_next_panel
  240.  )
  241.  ifelse
  242. )top_bottom!
  243. |
  244. (linescols drop 2/ 1- nb_pn_lines! 0 startcol!
  245.  (nb_pn_lines 40  panel.rc! menu_line 1+ startcol panel.startrc! true panel.on!
  246.   normal_att current_att selected_att current_selected_att panel.att!
  247.   startcol 40+startcol!
  248.  )
  249.  loop_panels
  250. )side_by_side!
  251. |
  252. | the next code execute the action <top> for each panel
  253. |
  254. ("panel.on_activate"@oa! ()panel.on_activate! 
  255.   0 cnt! 
  256.   (cnt nb_panels <)
  257.   (cnt 1+ cnt! dup # next_panel)
  258.   while 
  259.   drop
  260.   oa "panel.on_activate!"&#
  261. )loop_panels!
  262. |
  263. |    switches panels on/off
  264. |    adapt the following code if you get rid of some of the panels or menus
  265. |
  266. (panel.on
  267.  ((false panel.on!)loop_panels main_menu_no window.uninstall
  268. |  drive_menu_no window.uninstall
  269.  )
  270.  ((true  panel.on!)loop_panels show_menu | drive_menu
  271.  )
  272.  ifelse
  273. )hide_all!
  274. |
  275. | swap the panels
  276. |
  277. (panel.startrc (panel.startrc 4 roll 4 roll panel.startrc!)in_next_panel
  278.  panel.startrc!)swap_panels!
  279. |
  280. |
  281. | Up/Down: move up/down; note that they do prevcmd/nextcmd if panels are off
  282. |
  283. (panel.on(current.pos 0=(beep)(current.pos 1 - current.pos!)ifelse)
  284.          (prevcmd)
  285.      ifelse
  286. )Up_panel!
  287. |
  288. (panel.on(current.pos panel.nbfiles 1- =(beep)(current.pos 1 + current.pos!)
  289.           ifelse)
  290.          (nextcmd)
  291.      ifelse
  292. )Down_panel!
  293. |
  294. |  go up/down one panel-windowfull
  295. |
  296. (current.pos panel.rc drop 2 - - current.pos!)PageUp_panel!
  297. (panel.rc drop 2 - current.pos + current.pos!)PageDown_panel!
  298. |
  299. | goto next/previous panel
  300. |
  301. (panel_directory cwd!)panel.on_activate!
  302. (cur_pn 1 + dup nb_panels>(nb_panels -)if dup cur_pn! window.activate)
  303. next_panel!
  304. (cur_pn 1 - dup 0 le(nb_panels +)if dup cur_pn! window.activate)
  305. prev_panel!
  306. |
  307. ( panel.type
  308.   (panel.pattern panel.type cutfirst drop panel.type&)
  309.   (panel.pattern)
  310.   ifelse
  311.   directory
  312. )panel_directory!
  313. |
  314. | Expand/Trim current panel
  315. |
  316. (panel.rc swap 3+ swap panel.rc!)expand_panel!
  317. (panel.rc swap 2- swap panel.rc!)trim_panel!
  318. |
  319. | search first file whose beginning matches contents of command line
  320. |
  321. (cmd cmd.clear file_to_search! find_again)find_file!
  322. (file_to_search "*.*"&dup next drop search current.name match(beep)ifnot)find_again!
  323. |
  324. | Replace selection pattern of current.name panel from command line contents
  325. |
  326. (cmd () ("*.*" cmd!) ifelse
  327. panel.pattern dirpart cmd&cmd.clear panel.pattern!)filter_files!
  328. |
  329. |  select all files matching command line contents; if the command
  330. | line is empty, select all.
  331. |
  332. (cmd cmd.clear dup(drop "*.*")ifnot
  333.  (dup current.name match
  334.    (current.isdir (true current.selected!)ifnot)if)loop_panel
  335.  drop
  336. )sel_match!
  337. |
  338. |  deselect all selected files matching pattern
  339. |
  340. (cmd cmd.clear dup(drop "*.*")ifnot
  341.  (dup current.name match(false current.selected!)if)loop_panel
  342.  drop
  343. )desel_match!
  344. |
  345. |  select/deselect current entry
  346. |
  347. (current.selected not current.selected!)select_on_off!
  348. | Here no update_info for performance reasons!
  349. |
  350. |  go up one level in directory hierarchy
  351. |
  352. (".."cwd! refresh)go_up!
  353. |
  354. ("go_up"panel.type&#)up_one_level!
  355. |
  356. |  go home
  357. |
  358. (0 current.pos!)go_home!
  359. |
  360. |  go to end of list of entries
  361. |
  362. (panel.nbfiles current.pos!)go_end!
  363. |
  364. |
  365. |              ┌─────────────────────────────┐
  366. |              │ actions on the command line │
  367. |              └─────────────────────────────┘
  368. |
  369. | prevcmd/nextcmd: replace command line with previous/next item in circular
  370. | list of saved commands.
  371. |
  372. | first, the variable nl is set to a newline.
  373. "
  374. "nl!
  375. |
  376. (cmdlist nl cutfirst swap drop nl cutfirst nl swap & swap dup the_cmd!
  377.  swap nl&swap&cmdlist! cmd.clear the_cmd cmd!)nextcmd!
  378. |
  379. (cmdlist nl cutlast dup the_cmd! nl swap&swap&cmdlist!cmd.clear the_cmd cmd!)
  380. prevcmd!
  381. |
  382. |  show the command stack.
  383. |
  384. (tmp!"tmp"@)quote!
  385. (
  386. cmdlist temp!""cmd2!
  387. (temp nl cutlast dup)
  388. (dup "%"swap&"%"&nl&cmd2 swap&cmd2!
  389.  quote"("swap&"cmd!)"&#swap
  390.  temp!
  391. )while
  392. drop drop
  393. " Command Stack
  394. " cmd2&
  395. () "-1" "-1" temp_bordered_menu)view_cmdlist!
  396. |
  397. |  write 'current' to the command line
  398. |
  399. (current.name " "&cmd!)write_current!
  400. |
  401. | write the selected list to the command line
  402. |
  403. (selected_list deselect cmd!)write_all_selected!
  404. |
  405. |  write complete pathname of 'current' of next panel to the command line
  406. |
  407. ((panel.pattern dirpart current.name&" "&cmd!)in_next_panel)write_other_current!
  408. |
  409. |  add in turn to the command line the basename of each selected file
  410. |       and execute the resulting command
  411. |
  412. (cmd CMD!(CMD " "& swap &execshow)foreachbase)run_on_selected!
  413. |
  414. |  execute as an MSH script instruction the contents of the command line
  415. |
  416. |(cmd cmd.clear#)exec_msh!
  417. ( cmd dup mshlist nl & swap & mshlist! cmd.clear#)exec_msh!
  418. |
  419. (mshlist nl cutfirst swap drop nl cutfirst nl swap & swap dup the_cmd!
  420.  swap nl&swap&mshlist! cmd.clear the_cmd cmd!)nextmsh!
  421. |
  422. (mshlist nl cutlast dup the_cmd! nl swap&swap&mshlist!cmd.clear the_cmd cmd!)
  423. prevmsh!
  424. |
  425. |  display on the command line, ready to be edited, the definition of
  426. | the identifier whose name was on the command line
  427. |
  428. (cmd @cmd&"!"&cmd.clear cmd!)definition!
  429. |
  430. | toggle insert mode
  431. |
  432. (cmd.imode(false cmd.imode!)(true cmd.imode!)ifelse)insert_toggle!
  433. |
  434. |
  435. |              ┌───────────────┐
  436. |              │ Miscellaneous │
  437. |              └───────────────┘
  438. |
  439. |
  440. | the next instruction defines the name of the config file
  441. |
  442. (prog_dir"config.msh"&)cfg_filename!
  443. |
  444. (0 0 linescols page_att page_status_att page_empty_att page_tab_att page)pager!
  445. |
  446. |
  447. (dup length 3 - str_pos!
  448. (str_pos 1 ge)(|  create two substrings and insert a "."
  449. dup | handle first copy
  450. 1 str_pos substring swap dup length str_pos 1 + swap substring
  451. | "," swap & &   | ',' American, english way
  452. "." swap & &     | '.' German Way
  453. str_pos 3 - str_pos!)while
  454. )formatted_nr!
  455. ( "stats"                               | code enhanced by J.Pirnay
  456.   panel.nbfiles " files"&nl&
  457.   "total size "&
  458.   0 (current.size +)loop_panel formatted_nr &
  459.   " bytes " &
  460.   0 (current.selected(1 +)if)loop_panel | get nr of selected files
  461.   dup 0 >                               | any selected ?
  462.   (
  463.   0 (current.selected(current.size +)if)loop_panel formatted_nr
  464.   " bytes in " & swap &
  465.   " selected files" &
  466.   nl swap &&
  467.   )
  468.   (drop)                                | don't need nr anymore
  469.   ifelse
  470. || Now I want to know, what's still available at the drive:
  471.   nl &
  472.   prog_dir "dskfree " &  panel.pattern unit_and_name drop & " " &
  473.   prog_dir "df.txt" & & (execute)with_nomagic
  474.   prog_dir "df.txt" & read &
  475.   message
  476. )panel_stats!
  477. |
  478. (3000 i!(0 i=not)(i 1-i!)while)test!
  479. |
  480. (dup 32 / dup 32 * 3 roll swap - " "&swap
  481.  dup 64 / dup 64 * 3 roll swap - dup 10 < ("0"swap&)if":"& 3 roll&swap
  482.  dup 32 / dup 32 * 3 roll swap - dup 10 < (" "swap&)if":"& 3 roll&swap
  483.  dup 32 / dup 32 * 3 roll swap - dup 10 < (" "swap&)if"/"&swap
  484.  dup 16 / dup 16 * 3 roll swap - dup 10 < ("0"swap&)if"/"&swap 80 +&&&
  485. )time_convert!
  486. |
  487. | The next code rereads the config file; this allows you to see the effect
  488. | of any changes you make in it
  489. |
  490. ("config.msh" loaddefs)reconfig!
  491. |
  492. ("ascii table" prog_dir"ascii" makename read message)ascii!
  493. |
  494. ("do you want the captured screen to keep video attributes
  495.   as ANSI escapes (or a plain text file)" ok
  496.   "Please input the filename where the captured screen will be appended
  497.   (default is file 'screen' in MSH program directory)" 60 input dup 
  498.   (drop prog_dir"screen" makename)ifnot
  499.  swap capture_screen swap write refresh)capt_screen!
  500. |
  501. ("stats" current.name": "¤t.size&" bytes -- last modified "¤t.time
  502.  time_convert & message)file_stats!
  503. |
  504. (editor selected_list deselect &exec)edit_selected!
  505. |
  506. |
  507. | flip on/off Debug switch
  508. |
  509. (debug not debug!)debug_toggle!
  510. |
  511. ((stack_size 0 > ) (drop) while)clean_stack!
  512. |
  513. ( "time_menu_no"isdefined(time_menu_no window.uninstall)if
  514.   time time_convert ":" cutlast drop () menu_line 0=(73)(75)ifelse menu_line
  515.   permanent_menu time_menu_no!)show_clock!
  516. ( show_clock 100 (clock)timer)clock!
  517. | this would update the clock every 100 / 17 = 59 seconds
  518. ||( "stat_menu_no"isdefined(stat_menu_no window.uninstall)if
  519. ||  0 (current.selected(current.size +)if)loop_panel formatted_nr
  520. ||  " bytes" &
  521. ||  () menu_line 0=(63)(65)ifelse menu_line
  522. ||  permanent_menu stat_menu_no!)show_stats!
  523. ||( show_stats 17 (clock)timer)clock!
  524. |
  525. | the following extend conveniently the dos commands
  526. |
  527. ("copy"panel.type&"to"&(panel.type)in_next_panel&#)copy_files!
  528. ("move"panel.type&"to"&(panel.type)in_next_panel&#)move_files!
  529. ("delete"panel.type&#)delete_files!
  530. ("browse"panel.type&#)browse_current!
  531. ("edit"panel.type&#)edit_current!
  532. |
  533. |(current.name pager)browse!
  534. (browser current.name&(execute)with_nomagic)browse!
  535. (editor current.name & exec)edit!
  536. |
  537. berk_cpmvrm(
  538. ("delete "selected_list& ok
  539.  ((dup current.isdir 
  540.        ("rd "swap&(execshow)with_nomagic)
  541.        (dup 100 swap"Deleting..." swap flash unlink)
  542.        ifelse
  543.   )foreachselected reread
  544.  )
  545.  if)delete!
  546. |
  547. ("copy "selected_list&" to "&next_dir& ok
  548.  (("copy "swap&" "&next_dir&(execshow)with_nomagic)foreachselected reread_next)
  549. if)copyto!
  550. |
  551. (panel.pattern directory next_dir=
  552.  ("warning" "cannot move files: next panel is the same directory" message)
  553.  ("move "selected_list&" to "&next_dir& ok
  554.   ((dup "copy "swap&" "&next_dir&(execshow)with_nomagic
  555.     dup 600 swap"Deleting..." swap flash unlink)
  556.    foreachselected reread reread_next
  557.   )if
  558.  )ifelse
  559. )moveto!
  560. )ifnot
  561. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  562.