home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Boston 2
/
boston-2.iso
/
DOS
/
HILFEN
/
SYSTEM
/
MSH
/
STDDEFS.MSH
< prev
next >
Wrap
Text File
|
1993-12-01
|
15KB
|
511 lines
| file: STDDEF.MSH Standard definitions for Mi-Shell
|───────────────────────────────────────────────────────────
|
| ┌─────────────────────────────────────────────┐
| │ utilities to get various parts of a pathname│
| └─────────────────────────────────────────────┘
|
("."cutlast drop)basename!
("."cutlast swap drop)extension!
|
| the following definition tests if top is a substring of top+1
|
(swap dup 3 roll cutfirst drop = not )belong!
|
| Cut a pathname into its unit and the rest.
|
(dup ":"cutfirst dup
(3 roll drop swap":"&swap)
(drop 2 pick =
(false swap)
(false)
ifelse
)
ifelse
)unit_and_name!
|
| Get the directory of a pathname. It is hard because of DOS's dumb syntax.
| examples: "a:x\y" -> "a:x", "a:x\" -> "a:x\.", "a:" -> "a:.", etc...
|
(unit_and_name
dup"\\"cutlast
(dup(swap drop)
(drop drop "\\")
ifelse
)
(drop &".")
ifelse
&
)directory!
|
| A simpler variant which gives the directory part of a pathname, so
| that dirpart&filepart=initial pathname.
| examples: "a:x\y" -> "a:x\", "a:x\" -> "a:x\", "a:" -> "a:", etc...
|
(dup "\\"endsby("."&)if
unit_and_name"\\"cutlast
("\\"&)
(drop"")
ifelse
&
)dirpart!
|
| Get the filename part of a pathname.
|
(unit_and_name swap drop
"\\"cutlast dup
(swap drop)
(drop)
ifelse
)filepart!
|
| makename puts together a directory and a filename. The difficulty is
| to add a '\' when necessary.
|
(2 pick swap cutlast (drop drop false)(match not)ifelse)endsby!
|
(swap
dup "\\" endsby
(dup ":" endsby
("\\"&)ifnot
)
ifnot
swap &
)makename!
|
| ┌─────────────────────────────────┐
| │ various kind of loops on a panel│
| └─────────────────────────────────┘
|
| loop_panel: general loop operator. Assumes top is a piece of code and
| executes it for each entry in the panel
|
( action! current.pos oldpos! 0 current.pos!
(action current.pos 1+ dup current.pos! panel.nbfiles = not)()while
oldpos current.pos!
)loop_panel!
|
| deselect: deselect all selected files.
|
((current.selected(false current.selected!)if)loop_panel)deselect!
|
| foreachselected: supposes <Top> is a piece of code taking 1 argument,
| and execute for each selected file that code with the selected
| file as argument (uses current if no file was selected)
|
( action! current.pos oldpos! 0 current.pos! false found!
(current.selected(true found! false current.selected! current.name action)if
current.pos 1+ dup current.pos! panel.nbfiles = not)()
while
oldpos current.pos!
found (current.name action)ifnot
)foreachselected!
|
| foreachbase: same as foreachselected but use the basename as argument.
|
( action! current.pos oldpos! 0 current.pos! false found!
(current.selected(true found! false current.selected! current.name basename
action)if current.pos 1+ dup current.pos! panel.nbfiles = not)()
while
oldpos current.pos!
found (current.name action)ifnot
)foreachbase!
|
| selected_list: <Push> the list of selected files, catenated with blanks
| as separators. If nothing was selected, <Push> current.
|
( false (current.selected(current.name&" "&)if)loop_panel
dup (drop current.name)ifnot
)selected_list!
|
| next: circular version of down to be used in circular searches
|
(current.pos 1+ dup current.pos! panel.nbfiles=(0 current.pos!)if)next!
|
| search: positions to the first file matching <Top>
|
( current.name
(2 pick current.name match
(false)
(next dup current.name = not)
ifelse
)
()
while
drop
)search!
|
| ┌──────────────────────┐
| │ updates of the panels│
| └──────────────────────┘
|
| refresh refills the panel with the contents of the current directory
|
(cwd panel.pattern filepart makename panel.pattern!)refresh!
|
| reread updates the current panel by rereading from disk (but doesn't
| change its directory to the current one: use refresh for that)
|
(panel.pattern panel.pattern!)reread!
|
| variants which deal with the next panel
|
("panel.on_activate"@oa! ()panel.on_activate! next_panel
#prev_panel oa "panel.on_activate!")in_next_panel!
((reread) in_next_panel)reread_next!
((panel.pattern directory)in_next_panel)next_dir!
|
|
| ┌──────────────────────┐
| │ variants of 'execute'│
| └──────────────────────┘
|
| execshow: show the command in a message window before executing it
|
(dup 600 swap"Executing..." swap flash execute)execshow!
|
| exec: usual variant: just reread after 'execute'
|
(execute reread)exec!
|
| with_magic: do something with `magic' swap enabled
| with_nomagic: do something with magic off
| with_magicnoxms: do something with swap to disk enabled but swap to xms disabled
|
(magic oldmagic!"*"magic! # oldmagic magic!)with_nomagic!
(magic oldmagic!tmp_dir magic! # oldmagic magic!)with_magic!
(magic oldmagic!"*"tmp_dir& magic! # oldmagic magic!)with_magicnoxms!
|
| confirm: ask confirmation before executing command
|
(act! dup ok(act)(drop)ifelse)confirm!
|
((true)(false)3 roll nl&" %yes% %no%"&
(false)"-1" 5 e_att e_att current_selected_att true false menu.install)
my_ok!
|
| execsave: variant executed by Enter which saves the command on the circular
| list of saved commands before execution
|
( cmd dup cmdlist nl&swap&cmdlist! dup
" "cutfirst drop"."cutfirst drop"*"nl&swap&nl&"*"& dup magic_list match
( drop(execute)with_magic)
( nl"set"&match
("="cutfirst dup(swap " " cutlast swap drop "$"swap& !)
(drop execute)ifelse)
(execute)ifelse
)ifelse
cmd.clear refresh
)execsave!
|
| below is part of the code for Enter.
|
( current.isdir
( current.name cwd! refresh)
( "extension_" current.name extension)
ifelse
)cur_action!
|
("cur_action"panel.type)act_on_cur!
|
(current.isdir
(current.name cwd! refresh)
("extension2_" current.name extension)
ifelse
)act2_on_cur!
|
| ┌───────────────────────────────┐
| │ now, the actions on the panels│
| └───────────────────────────────┘
|
| wide_narrow: flip between complete/name only listing of entries
|
(panel.size(false panel.size! false panel.attrs!
false panel.date! false panel.time!)
(true panel.size! true panel.attrs!
true panel.date! true panel.time!)
ifelse
)wide_narrow!
|
(panel.rc drop linescols drop 2/ 1- <
(side_by_side)
(linescols drop 4/ nb_pn_lines! menu_line 1+ 0 panel.startrc!nb_pn_lines 79 panel.rc!
(nb_pn_lines menu_line 1++ 0 panel.startrc!nb_pn_lines 79 panel.rc!)in_next_panel
)
ifelse
)top_bottom!
|
(linescols drop 2/ 1- nb_pn_lines! 0 startcol!
(nb_pn_lines 40 panel.rc! menu_line 1+ startcol panel.startrc! true panel.on!
normal_att current_att selected_att current_selected_att panel.att!
startcol 40+startcol!
)
loop_panels
)side_by_side!
|
| the next code execute the action <top> for each panel
|
("panel.on_activate"@oa! ()panel.on_activate!
0 cnt!
(cnt nb_panels <)
(cnt 1+ cnt! dup # next_panel)
while
drop
oa "panel.on_activate!"
)loop_panels!
|
| switches panels on/off
| adapt the following code if you get rid of some of the panels or menus
|
(panel.on
((false panel.on!)loop_panels main_menu_no window.uninstall
drive_menu_no window.uninstall)
((true panel.on!)loop_panels show_menu drive_menu)
ifelse
)hide_all!
|
| swap the panels
|
(panel.startrc (panel.startrc 4 roll 4 roll panel.startrc!)in_next_panel
panel.startrc!)swap_panels!
|
|
| Up/Down: move up/down; note that they do prevcmd/nextcmd if panels are off
|
(panel.on(current.pos 0=(beep)(current.pos 1 - current.pos!)ifelse)
(prevcmd)
ifelse
)Up_panel!
|
(panel.on(current.pos panel.nbfiles 1- =(beep)(current.pos 1 + current.pos!)
ifelse)
(nextcmd)
ifelse
)Down_panel!
|
| go up/down one panel-windowfull
|
(current.pos panel.rc drop 2 - - current.pos!)PageUp_panel!
(panel.rc drop 2 - current.pos + current.pos!)PageDown_panel!
|
| goto next/previous panel
|
(panel_directory cwd!)panel.on_activate!
(cur_pn 1 + dup nb_panels>(nb_panels -)if dup cur_pn! window.activate)
next_panel!
(cur_pn 1 - dup 0 le(nb_panels +)if dup cur_pn! window.activate)
prev_panel!
|
( panel.type
(panel.pattern panel.type cutfirst drop panel.type&)
(panel.pattern)
ifelse
directory
)panel_directory!
|
| Expand/Trim current panel
|
(panel.rc swap 3+ swap panel.rc!)expand_panel!
(panel.rc swap 2- swap panel.rc!)trim_panel!
|
| search first file whose beginning matches contents of command line
|
(cmd cmd.clear file_to_search! find_again)find_file!
(file_to_search "*.*"&dup next drop search current.name match(beep)ifnot)find_again!
|
| Replace selection pattern of current.name panel from command line contents
|
(cmd () ("*.*" cmd!) ifelse
panel.pattern dirpart cmd&cmd.clear panel.pattern!)filter_files!
|
| select all files matching command line contents; if the command
| line is empty, select all.
|
(cmd cmd.clear dup(drop "*.*")ifnot
(dup current.name match(true current.selected!)if)loop_panel
drop
)sel_match!
|
| deselect all selected files matching pattern
|
(cmd cmd.clear dup(drop "*.*")ifnot
(dup current.name match(false current.selected!)if)loop_panel
drop
)desel_match!
|
| select/deselect current entry
|
(current.selected not current.selected!)select_on_off!
|
| go up one level in directory hierarchy
|
(".."cwd! refresh)go_up!
|
("go_up"panel.type)up_one_level!
|
| go home
|
(0 current.pos!)go_home!
|
| go to end of list of entries
|
(panel.nbfiles current.pos!)go_end!
|
|
| ┌─────────────────────────────┐
| │ actions on the command line │
| └─────────────────────────────┘
|
| prevcmd/nextcmd: replace command line with previous/next item in circular
| list of saved commands.
|
| first, the variable nl is set to a newline.
"
"nl!
|
(cmdlist nl cutfirst swap drop nl cutfirst nl swap & swap dup the_cmd!
swap nl&swap&cmdlist! cmd.clear the_cmd cmd!)nextcmd!
|
(cmdlist nl cutlast dup the_cmd! nl swap&swap&cmdlist!cmd.clear the_cmd cmd!)
prevcmd!
|
| show the command stack.
|
(tmp!"tmp"@)quote!
(
cmdlist temp!""cmd2!temp nl cutfirst swap drop temp!
(temp nl cutfirst swap dup)
(dup "%"swap&"%"&nl&cmd2 swap&cmd2!
quote"("swap&"cmd!)"swap
temp!
)while
drop drop
" Command Stack
" cmd2&
() "-1" "-1" temp_bordered_menu)view_cmdlist!
|
| write 'current' to the command line
|
(current.name " "&cmd!)write_current!
|
| write the selected list to the command line
|
(selected_list deselect cmd!)write_all_selected!
|
| write complete pathname of 'current' of next panel to the command line
|
((panel.pattern dirpart current.name&" "&cmd!)in_next_panel)write_other_current!
|
| add in turn to the command line the basename of each selected file
| and execute the resulting command
|
(cmd CMD!(CMD " "& swap &execshow)foreachbase)run_on_selected!
|
| execute as an MSH script instruction the contents of the command line
|
(cmd cmd.clear#)exec_msh!
|
| display on the command line, ready to be edited, the definition of
| the identifier whose name was on the command line
|
(cmd @cmd&"!"&cmd.clear cmd!)definition!
|
| toggle insert mode
|
(cmd.imode(false cmd.imode!)(true cmd.imode!)ifelse)insert_toggle!
|
|
| ┌───────────────┐
| │ Miscellaneous │
| └───────────────┘
|
|
| the next instruction defines the name of the config file
|
(prog_dir"config.msh"&)cfg_filename!
|
(0 0 linescols page_att page_status_att page_empty_att page_tab_att page)pager!
|
|
( "stats"
0 (current.size +)loop_panel
panel.nbfiles " files"&nl&
"total size "&" bytes "&swap &
message
)panel_stats!
|
(3000 i!(0 i=not)(i 1-i!)while)test!
|
(dup 32 / dup 32 * 3 roll swap - " "&swap
dup 64 / dup 64 * 3 roll swap - dup 10 < ("0"swap&)if":"& 3 roll&swap
dup 32 / dup 32 * 3 roll swap - dup 10 < (" "swap&)if":"& 3 roll&swap
dup 32 / dup 32 * 3 roll swap - dup 10 < (" "swap&)if"/"&swap
dup 16 / dup 16 * 3 roll swap - dup 10 < ("0"swap&)if"/"&swap 80 +&&&
)time_convert!
|
| The next code rereads the config file; this allows you to see the effect
| of any changes you make in it|
|
("config.msh" loaddefs)reconfig!
|
("ascii table" prog_dir"ascii" makename read message)ascii!
|
("do you want the captured screen to keep video attributes
as ANSI escapes (or a plain text file)" ok
"Please input the filename where the captured screen will be appended
(default is file 'screen' in MSH program directory)" 60 input dup
(drop prog_dir"screen" makename)ifnot
swap capture_screen swap write refresh)capt_screen!
|
("stats" current.name": "¤t.size&" bytes -- last modified "¤t.time
time_convert & message)file_stats!
|
(editor selected_list deselect &exec)edit_selected!
|
|
| flip on/off Debug switch
|
(debug not debug!)debug_toggle!
|
((stack_size 0 > ) (drop) while)clean_stack!
|
( "time_menu_no"isdefined(time_menu_no window.uninstall)if
time time_convert ":" cutlast drop () menu_line 0=(73)(75)ifelse menu_line
permanent_menu time_menu_no!)show_clock!
( show_clock 1000 (clock)timer)clock!
|
| the following extend conveniently the dos commands
|
("copy"panel.type&"to"&(panel.type)in_next_panel)copy_files!
("move"panel.type&"to"&(panel.type)in_next_panel)move_files!
("delete"panel.type)delete_files!
("browse"panel.type)browse_current!
|
(current.name pager)browse!
|
berk_cpmvrm(
("delete "selected_list& ok
((dup current.isdir
("rd "swap&(execshow)with_nomagic)
(dup 100 swap"Deleting..." swap flash unlink)
ifelse
)foreachselected reread
)
if)delete!
|
("copy "selected_list&" to "&next_dir& ok
(("copy "swap&" "&next_dir&(execshow)with_nomagic)foreachselected reread_next)
if)copyto!
|
(panel.pattern directory next_dir=
("warning" "cannot move files: next panel is the same directory" message)
("move "selected_list&" to "&next_dir& ok
((dup "copy "swap&" "&next_dir&(execshow)with_nomagic
dup 600 swap"Deleting..." swap flash unlink)
foreachselected reread reread_next
)if
)ifelse
)moveto!
)ifnot
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||