diff --git a/bin/gsh/Makefile b/bin/gsh/Makefile index c05ab4f..0f08b07 100644 --- a/bin/gsh/Makefile +++ b/bin/gsh/Makefile @@ -1,7 +1,7 @@ # # makefile for building gsh. This is for use with dmake. # -# $Id: Makefile,v 1.4 1998/06/09 16:22:50 tribby Exp $ +# $Id: Makefile,v 1.5 1998/06/30 17:25:01 tribby Exp $ # # Devin Reade, February 1998. # @@ -41,8 +41,9 @@ SRCS = $(MAINSRC) \ # ltermcap library from GNO v2.0.4. # # LDADD = -ltermcap -###LDLIBS += -l/trenco3/lib.206/ltermcap -LDLIBS += -l/h1/orca/libraries/ltermcap +LDLIBS += -l/trenco3/lib.206/ltermcap +###LDLIBS += -l/h1/orca/libraries/ltermcap +###LDLIBS += -l/usr/lib/libtermcap # Make sure our macro files get built before trying to assemble source files. # LOCAL_SETUP = macros @@ -59,14 +60,14 @@ LOCAL_MACRO_SRC = gsh.mac MACRO_SRC = \ $(LOCAL_MACRO_SRC) -# Everything should be in gsh.mac. If usefule, the following could be added +# Everything should be in gsh.mac. If useful, the following could be added # /usr/ainclude/m16.gno \ # $(ORCA_DIST)/libraries/orcainclude/m16.orca \ # $(ORCA_DIST)/libraries/orcainclude/m16.gs.os \ # $(ORCA_DIST)/libraries/orcainclude/m16.tools \ # $(ORCA_DIST)/libraries/orcainclude/m16.shell \ # $(ORCA_DIST)/libraries/ainclude/m16.pascal \ - $(ORCA_DIST)/libraries/ainclude/m16.debug +# $(ORCA_DIST)/libraries/ainclude/m16.debug MACROS = \ $(OBJ_DIR)main.mac \ diff --git a/bin/gsh/To.Do b/bin/gsh/To.Do index 386a6e1..820d3a6 100644 --- a/bin/gsh/To.Do +++ b/bin/gsh/To.Do @@ -1,30 +1,26 @@ +Last updated: June 19, 1998 By: Dave Tribby + For more bug reports, see also http://www.gno.org/~gno/bugs.html -Gsh is not currently running for GNO v2.0.6 (when it is rebuilt; the v2.0.4 -gsh works fine -- other than outstanding bug reports -- with the v2.0.6 -kernel). This obviously has to be sorted out. +Completed items are reported in file UpdateLog. + + +Initialize internal shell variables to match environment variables +(echo, nodirexec, nonewline, noglob, nobeep, pushdsilent, term, and ignoreeof) +when shell first starts. Gsh requires the v2.0.4 ltermcap to link. Termcap has changed in v2.0.6, and gsh should be updated to reflect this. -There is a lot of duplication in the macro files. They should be generated -with macgen from a common source file. (The constructs to do this are -already in the makefile, but commented out.) - -Need to modify Tim's mutex code to be: - -t lda #1 - tsb mutex - beq go - cop $7F - bra t -go ; execute code here ------------------------------------- - -coolish handling of setdebug by editor. - When building the EXE hash table, duplicate entries oughta should be ignored. +Make PATH's use consistent with forward parsing. + +Identify limits built into gsh and how they can be changed; for example, +size of $PATH <= 256; max programs in hash table = 256. + +Allow redirection of built-in commands' I/O even if they aren't forked. + When a background process finishes and there's text in the input buffer, the next keypress correctly reprints the edit line but the key itself does not get put in the buffer. @@ -33,27 +29,22 @@ running a process in the background from inside a script (not 'source', but executing the script as a command) causes the shell to wait for that background process to end - not exactly what we want. -recursive aliases. - -multiple files for 'edit'. - -'df' lists a bunch appleshare shit. [gdr: There is now a stand-alone df -implementation. The builtin should either use code from the other -implementation, or be declared obsolecent. - -change updatevars to do a read_variable for better performance (and -for correctness!) - --a in ps (and any other redeemable switches) +usage for alias and hash job control monitor for defunct processes when waiting. -usage for alias and hash - job control needs to save tty information. -echo should use octal and hex \12 is dec, \012 is octal, \x12 is hex. +Allow ~user construct (call routines to get user's home directory) + +recursive aliases. + +[ -- below this line...probably not -- ] write new memory management. +coolish handling of setdebug by editor. + +echo should use octal and hex \12 is dec, \012 is octal, \x12 is hex. + write history expansion. diff --git a/bin/gsh/UpdateLog b/bin/gsh/UpdateLog index 31f3707..0d27348 100644 --- a/bin/gsh/UpdateLog +++ b/bin/gsh/UpdateLog @@ -1,6 +1,105 @@ GSH 2.0 UPDATES ^^^^^^^^^^^^^^^ +Jun 28 98 [dmt] Added InitVar routine to shellvar.asm to read values + of all environment variables tracked in vardata. + +Jun 25 98 [dmt] Added 2.0 versions of shell calls to gsh.mac (e.g. + ErrorGS, ReadVariableGS). Replaced old calls with new ones + for the following: ERROR to ErrorGS in builtin.asm, cmd.asm + dir.asm, shellvar.asm; Push[Pop]Variables to Push[Pop]VariabesGS + in invoke.asm, shellvar.asm, shell.asm; ReadVariable to + ReadVariableGS in builtin.asm and dir.asm. + +Jun 23 98 [dmt] Made clear built-in a non-forked command. + +Jun 21 98 [dmt] Added loop to execute(), in cmd.asm, to extract a single + command from the input line before sending it to command(). It + removes leading blanks and tabs and terminates the string at + the first ";" or "#". After command() has finished, execute() + loops again if the previous command was terminated with a ";". + This change fixed both problems in bug report #12: + a) All commands separated by ";" were evaluated before any + were executed, so the following wouldn't work: + set t_num=1 ; echo "Test number $t_num" + b) Odd things randomly happened when tab was the first + character of multiple consecutive lines. + +Jun 20 98 [dmt] Changed pointer arithmetic from dec or inc to acd or sbc + to allow for boundary condition in shell.asm. + In ShellExec (cmd.asm), save status from call to execute and + pass back to caller in Accumulator. + Modify table of builtins so that source is unforked; this + fixes bug reports #7 and #8: prefix does not work from a + sourced file. + +Jun 18 98 [dmt] In cmd.asm, modified system() to check for null pointer, + since that is documented in the ORCA/C manual as legal. + +Jun 15 98 [dmt] Fixed bug report #3: when wildcards were expanded, if + nothing was found gsh printed "No match." and terminated, even + if there were more arguments to parse. Now gsh prints a message + "No match: ignored" to stderr for each that + does not match any filename. These changes were in expand.asm. + Changed mutual exclusion in cmd.asm and shellvar.asm to use + lock/unlock/key macros. That should be all of 'em. + +Jun 14 98 [dmt] Fixed bug report #47: when ~ is parsed and next character + is a delimiter ("/" or ":") and first character of $HOME does + not match that delimiter, replace the delimiters in $HOME to + match the user's value. Changed three "ora addr" to "ora addr+2" + (alias.asm: ora ptr; edit.asm and history.asm: ora cdcap). + Changed mutual exclusion in expand.asm to use lock/unlock macros. + +Jun 13 98 [dmt] Wrote script to test built-in commands; found many that + returned status=227. Updated exit, setdebug, ps, hash, commands, + history, dirs, pushd, popd, jobs, fg, bg, and stop to return + status of 0 (modified "return" to add "2:#0"). + +Jun 12 98 [dmt] Squeezed about 80 bytes out of orca.o (edit built-in), + mainly by removing "invalid path name" error msg, since I + couldn't force ExpandPath to report the error and the editor + handles it fine. Also tightened "whileloop" by using Y-reg + to index off of two pointers. Added lots of comments. + +Jun 10 98 [dmt] The boolean shell environment variables (echo, pushdsilent, + etc.) would not work if they were set using UPPER CASE names. + Added routine cmpdcstr in shellutil.asm to downshift characters + while comparing two c strings, then called it from updatevars + in shellvar.asm to compare env variable names. + +Jun 9 98 [dmt] Modified echo command (in builtin.asm) so it doesn't append + a blank to the end of everything it prints. Added comments to code. + +Jun 8 98 [dmt] Added breakpoint option to setdebug (in builtin.asm) to + allow turning on conditional brk instructions for debugging. + Made "check4debug" a global word that reflects the current debug + state, and added "breakpoint" macro (in gsh.mac) to generate code. + Changed "2.0.4" to "2.0.6" within gnostr (in shell.asm). + +Jun 6 98 [dmt] All the macros were extracted, compared, and collated in + alphabetical order into the file gsh.mac. Six macros used by + other macros had to be moved to the end of the file. + + Added direct-page/stack data segment (size 2K) to main.asm. + It is initialized to be filled with "?" characters, so that + it can be examined to see how much space is being used. + +Jun 5 98 [dmt] Determined that the current sources have only two + differences from the gsh distributed with GNO/2.0.4: + In main.asm between (argloop and cmd3) the code + ph4 #1024 + jsl ~NEW + formerly was + pea 1024 + jsl ~NEW + + In jobs.asm (after dokill) the error check after + kill (pid,signum) + was not present. + +Jun 1 98 [dmt] Changed to execvp to _execve in invoke.asm. gsh works! + 24 Apr 98 [gdr] Fitted gsh sources into into GNO builds. While gsh assembles and links (abeit using the v2.0.4 termcap library), it does not currently run -- it just crashes. The changes diff --git a/bin/gsh/alias.asm b/bin/gsh/alias.asm index 974ae94..51d55a3 100644 --- a/bin/gsh/alias.asm +++ b/bin/gsh/alias.asm @@ -6,16 +6,44 @@ * Jawaid Bazyar * Tim Meekins * +* $Id: alias.asm,v 1.3 1998/06/30 17:25:07 tribby Exp $ +* ************************************************************************** * * ALIAS.ASM * By Tim Meekins * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ +************************************************************************** +* +* Interfaces defined in this file: +* +* alias +* +* unalias +* +* initalias +* +* expandalias +* +* addalias +* +* removealias +* +* findalias +* +* startalias +* +* nextalias +* +* ************************************************************************** mcopy /obj/gno/bin/gsh/alias.mac -dummy start ; ends up in root +dummyalias start ; ends up in root end setcom 60 @@ -255,9 +283,11 @@ initalias START using AliasData +; Set all entries in AliasTable to 0 + lda #0 ldy #VTABSIZE - tax #0 + tax yahaha sta AliasTable,x inx2 sta AliasTable,x @@ -446,7 +476,7 @@ space equ hashval+4 sta ptr+2 search lda ptr - ora ptr + ora ptr+2 beq notfound ldy #4 lda [ptr],y diff --git a/bin/gsh/bufpool.asm b/bin/gsh/bufpool.asm index a7fc404..d67f8bb 100644 --- a/bin/gsh/bufpool.asm +++ b/bin/gsh/bufpool.asm @@ -6,7 +6,7 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: bufpool.asm,v 1.2 1998/04/24 15:38:05 gdr-ftp Exp $ +* $Id: bufpool.asm,v 1.3 1998/06/30 17:25:09 tribby Exp $ * ************************************************************************** * @@ -15,11 +15,30 @@ * * This is the buffer pool * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ +************************************************************************** +* +* Interfaces defined in this file: +* The alloc routines are a jsl without any stack params. +* Pointer to requested buffer is returned in X/A registers. +* alloc256 +* free256 +* alloc1024 +* free1024 +* +* bufpool data: +* pool256 dc i4'0' +* pool256mutex key +* pool1024 dc i4'0' +* pool1024mutex key +* ************************************************************************** mcopy /obj/gno/bin/gsh/bufpool.mac -dummy start ; ends up in .root +dummybufpool start ; ends up in .root end ************************************************************************** @@ -32,31 +51,35 @@ alloc256 START using bufpool - lock pool256mutex + lock pool256mutex Mutual exclusion lock. - lda pool256 - ora pool256+2 - beq allocbuf + lda pool256 Get address of + ora pool256+2 256-byte pool. + beq allocbuf If NULL, go allocate the buffer. - phd - ph4 pool256 - tsc - tcd - lda [1] - sta pool256 - ldy #2 + phd Hold on to Direct Page register. + ph4 pool256 Put current contents of pool256 on stack. + tsc Copy stack pointer to + tcd Direct Page register. + lda [1] Store 4 bytes of data + sta pool256 that pool256 pointed to + ldy #2 in pool256. lda [1],y sta pool256+2 - unlock pool256mutex - pla - plx - pld - rtl -allocbuf unlock pool256mutex - ph4 #256 - jsl ~NEW - rtl + unlock pool256mutex Mutual exclusion unlock. + + pla A = old pool256 + plx X = old pool256+2 + pld Restore Direct Page register. + + rtl Return to caller. + + +allocbuf unlock pool256mutex Mutual exclusion unlock. + ph4 #256 Request 256 bytes + jsl ~NEW from system. + rtl Return to caller. END @@ -70,12 +93,14 @@ free256 START using bufpool - phd - phx - pha - tsc - tcd - lock pool256mutex + phd Save data bank register. + phx Put address to free + pha on stack. + tsc Copy stack pointer into + tcd direct page register. + + lock pool256mutex Mutual exclusion lock. + lda pool256 sta [1] ldy #2 @@ -85,11 +110,14 @@ free256 START sta pool256 lda 3 sta pool256+2 - unlock pool256mutex - pla - plx - pld - rtl + + unlock pool256mutex Mutual exclusion unlock. + + pla Restore Accumulator, + plx X-register, and + pld Direct Page register, + + rtl Return to caller. END diff --git a/bin/gsh/builtin.asm b/bin/gsh/builtin.asm index 9b2f927..b99ecf2 100644 --- a/bin/gsh/builtin.asm +++ b/bin/gsh/builtin.asm @@ -6,18 +6,53 @@ * Jawaid Bazyar * Tim Meekins * +* $Id: builtin.asm,v 1.3 1998/06/30 17:25:12 tribby Exp $ +* ************************************************************************** * * BUILTIN.ASM * By Tim Meekins +* Modified by Dave Tribby for GNO 2.0.6 * * Builtin command searching and execution. * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** +* +* Interfaces defined in this file: +* +* builtin subroutine (2:argc,4:argv) +* Returns completion status in Accumulator +* +* IsBuiltin subroutine (4:name) +* return 2:tbl +* +* Remainder are interfaces to builtin commands with interface +* subroutine (4:argv,2:argc) +* returns status in accumulator +* cd (chdir is entry as an alternate name) +* clear +* echo +* pwd +* which +* prefix +* rehash (unhash is entry as an alternate name) +* df +* exit +* setdebug +* psbi (command name is "ps") +* hashbi (command name is "hash") +* source +* cmdbi (command name is "commands") +* +************************************************************************** + mcopy /obj/gno/bin/gsh/builtin.mac -dummy start ; ends up in .root +dummybuiltin start ; ends up in .root end setcom 60 @@ -34,7 +69,7 @@ p_space gequ p_command+4 ;space for structure ************************************************************************** * -* Find a builtin command +* Find and execute a builtin command * ************************************************************************** @@ -103,7 +138,7 @@ ourproc jsl >$FFFFFF ;might want to mutex this!!!!!! pei (argv) jsl argfree -done ldy val +done anop lda space sta end-3 lda space+1 @@ -114,6 +149,8 @@ done ldy val adc #end-4 tcs tya + + lda val rtl END @@ -122,6 +159,9 @@ done ldy val * * Is it a built-in? * +* Return value is: -1 if not a built-in, 0 if forked built-in, +* 1 if non-forked built-in. +* ************************************************************************** IsBuiltin START @@ -149,11 +189,11 @@ builtinloop ldy #2 bpl nofile add2 tbl,#10,tbl bra builtinloop -foundit ldy #8 - lda [tbl],y +foundit ldy #8 Get the fork/nofork flag + lda [tbl],y and use it as return value. bra foundbuiltin -nofile lda #-1 +nofile lda #-1 Set not-found return value. foundbuiltin sta tbl return 2:tbl @@ -169,14 +209,15 @@ foundbuiltin sta tbl BuiltinData DATA ; ; First address is a pointer to the name, the second is a pointer to the -; command. MUST BE SORTED. +; command. Third value is fork flag (0 to fork, 1 for no fork). +; TABLE MUST BE SORTED BY COMMAND NAME. ; builtintbl dc a4'aliasname,alias',i2'0' dc a4'bgname,bg',i2'1' dc a4'bindkeyname,bindkey',i2'0' dc a4'cdname,cd',i2'1' dc a4'chdirname,chdir',i2'1' - dc a4'clearname,clear',i2'0' + dc a4'clearname,clear',i2'1' Changed to unforked dc a4'cmdname,cmdbi',i2'0' dc a4'dfname,df',i2'0' dc a4'dirsname,dirs',i2'0' @@ -198,7 +239,7 @@ builtintbl dc a4'aliasname,alias',i2'0' dc a4'setname,set',i2'0' dc a4'setbugname,setdebug',i2'0' dc a4'setenvname,setenv',i2'0' - dc a4'sourcename,source',i2'0' + dc a4'sourcename,source',i2'1' Changed to unforked dc a4'stopname,stop',i2'1' dc a4'tsetname,tset',i2'1' dc a4'unaliasname,unalias',i2'1' @@ -256,8 +297,9 @@ whichname dc c'which',h'00' cd START chdir ENTRY -dir equ 1 -space equ dir+4 +dpg equ 1 Direct page pointer. +buf equ dpg+4 Buffer address to be freed. +space equ buf+4 argc equ space+3 argv equ argc+2 end equ argv+4 @@ -273,12 +315,18 @@ end equ argv+4 lock cdmutex - lda argc - dec a - beq cdhome - dec a - jeq normalcd + stz buf Clear the pointer to + stz buf+2 allocated buffer. + lda argc Number of parameters + dec a determines type of cd... + beq cdhome either to $HOME + dec a or to the directory + jeq paramcd on the command line. + +; +; Illegal parameters: print usage string +; showusage lda [argv] tax ldy #2 @@ -296,87 +344,100 @@ cdusage ldx #^Usage lda #Usage jsr errputs jmp exit + ; -; set prefix to home +; Set prefix to $home ; -cdhome jsl alloc256 - sta dir - stx dir+2 +cdhome ph4 #256 Allocate 256 bytes for result buf. + jsl ~NEW + sta buf + stx buf+2 sta ReadName stx ReadName+2 - ora ReadName+2 + ora ReadName+2 If both address bytes are 0, bne madeit lda #$201 - jmp ohshit -madeit Read_Variable ReadVar - lda [dir] - and #$FF - beq nohome - ph4 ReadName - jsr p2cstr - sta dir - stx dir+2 - ph4 @xa - lda ReadName - ldx ReadName+2 - jsl free256 - pl4 ReadName - bra setprefix + jmp ohshit we have a problem... + +madeit lda #256 Set length of GS/OS result buffer + sta [buf] + + ReadVariableGS ReadVar Read value of $home + + clc Calculate address + lda buf of GS/OS input string + adc #2 (2 bytes from start of + sta PRecPath result buffer). + sta GRecPath + lda buf+2 + adc #0 + sta PRecPath+2 + sta GRecPath+2 + + ldy #2 + lda [buf],y Get string length word. + beq done If 0, bail out. + + bra getinfo -nohome ldx dir+2 - lda dir - jsl free256 - jmp exit ; -; set prefix to specified path +; Set prefix to path specified on command line ; -normalcd stz ReadName - stz ReadName+2 +paramcd anop ldy #4 lda [argv],y - sta dir + sta dpg iny2 lda [argv],y - sta dir+2 + sta dpg+2 - lda [dir] + lda [dpg] and #$FF if2 @a,ne,#'-',setprefix jmp showusage -setprefix pei (dir+2) - pei (dir) +setprefix pei (dpg+2) + pei (dpg) jsr c2gsstr sta PRecPath sta GRecPath + sta buf stx PRecPath+2 stx GRecPath+2 + stx buf+2 - GetFileInfo GRec +; +; Get file information to determine whether target is a valid directory +; +getinfo GetFileInfo GRec bcc ok -ohshit sta Err - Error Err +ohshit sta ErrError + ErrorGS Err bra done ok if2 GRecFT,eq,#$F,ok2 - ldx dir+2 - lda dir + ldx dpg+2 + lda dpg jsr errputs ldx #^direrr lda #direrr jsr errputs bra done +; +; Everything looks OK. Set prefix 0 to the indicated value +; ok2 SetPrefix PRec bcs ohshit -done ph4 PRecPath + +; +; Deallocate buffer (if necessary), unlock mutex, cleanup stack, and leave +; +done ora2 buf,buf+2,@a + beq exit + ph4 buf jsl nullfree - ora2 ReadName,ReadName+2,@a - beq whoaboy - ph4 ReadName - jsl nullfree -whoaboy anop exit unlock cdmutex @@ -394,22 +455,31 @@ exit unlock cdmutex rtl -cdmutex key +cdmutex key Mutual exclusion key -PRec dc i'2' -PRecNum dc i'0' -PRecPath ds 4 +; Parameter block for GS/OS SetPrefix call +PRec dc i'2' pCount +PRecNum dc i'0' prefixNum (0 = current directory) +PRecPath ds 4 Pointer to input prefix path -GRec dc i'3' -GRecPath ds 4 -GRecAcc ds 2 -GRecFT ds 2 +; Parameter block for GS/OS GetFileInfo call +GRec dc i'3' pCount +GRecPath ds 4 Pointer to input pathname +GRecAcc ds 2 access (result) +GRecFT ds 2 fileType (result) -ReadVar dc a4'home' -ReadName ds 4 -home str 'home' +; Parameter block for shell ReadVariableGS call (p 423 in ORCA/M manual) +ReadVar anop + dc i2'3' pCount + dc a4'home' Pointer to name +ReadName ds 4 GS/OS Output buffer ptr: value + ds 2 export flag -Err ds 2 +home gsstr 'home' Env variable name + +; Parameter block for shell ErrorGS call (p 393 in ORCA/M manual) +Err dc i2'1' pCount +ErrError ds 2 Error number Usage dc c'Usage: cd [pathname]',h'0d00' Usage2 dc c'Usage: chdir [pathname]',h'0d00' @@ -483,7 +553,7 @@ Usage dc c'Usage: clear',h'0d00' echo START val equ 1 -nl equ val+2 +nl equ val+2 flag: was -n option set? ptr equ nl+2 space equ ptr+4 argc equ space+3 @@ -492,6 +562,8 @@ end equ argv+4 ; subroutine (4:argv,2:argc),space +* Add space on stack for local variables + tsc sec sbc #space-1 @@ -499,71 +571,78 @@ end equ argv+4 phd tcd - stz nl - if2 argc,lt,#2,loop - ldy #4 - lda [argv],y - sta ptr - iny2 - lda [argv],y - sta ptr+2 - ldy #1 - lda [ptr] - and #$FF - if2 @a,ne,#'-',loop - lda [ptr],y - and #$FF - if2 @a,ne,#'n',showusage - iny - lda [ptr],y - and #$FF - bne showusage - inc nl - add2 argv,#4,argv - dec argc - bra loop + stz nl Clear the -n flag. + dec argc Decrement argument counter. + jeq done Done if no more arguments. -showusage ldx #^Usage - lda #Usage + ldy #4 + lda [argv],y Set ptr to + sta ptr point to the + iny2 text of the + lda [argv],y first + sta ptr+2 argument. + ldy #1 + lda [ptr] Get first + and #$FF character. + if2 @a,ne,#'-',loop If != '-', handle as regular param. + + +; First argument begins with "-"; only legal value is -n + + lda [ptr],y Get second + and #$FF character. + if2 @a,eq,#'n',gotn If != 'n', it's a bad one. + +showusage ldx #^Usage Incorrect parameter usage: + lda #Usage display the usage string. jsr errputs jmp exit -loop add2 argv,#4,argv - dec argc - jeq done +gotn iny + lda [ptr],y Get third + and #$FF character. + bne showusage If != 0, it's a bad one. + inc nl Set the -n flag. + add2 argv,#4,argv Bump argument pointer. + dec argc Decrement argument counter. + jeq done Done if no more arguments. + +* Beginning of main processing loop of echo parameters. + +loop add2 argv,#4,argv Bump argument pointer. ldy #2 - lda [argv],y + lda [argv],y Set ptr to argv (next argument) sta ptr+2 lda [argv] sta ptr -putloop lda [ptr] - and #$FF - cmp #0 - jeq doneput - cmp #'\' - jne putit - inc ptr - lda [ptr] - and #$FF - jeq doneput - if2 @a,ne,#'b',esc02 +putloop lda [ptr] Get first + and #$FF character. + cmp #0 If 0, + jeq doneput done with this argument. + cmp #'\' If != "\" + jne putit go save in print buffer. + inc ptr Escape character found; point + lda [ptr] to the next + and #$FF character. + beq doneput If 0, done with this argument. + if2 @a,ne,#'b',esc02 Check for escape codes: "b" ldx #1 - jsr moveleft + jsr moveleft moveleft bra didit -esc02 if2 @a,ne,#'f',esc03 - jsr clearscrn +esc02 if2 @a,ne,#'f',esc03 "f" + jsr clearscrn clearscreen bra didit -esc03 if2 @a,ne,#'n',esc04 - lda #13 +esc03 if2 @a,ne,#'n',esc04 "n" + lda #13 print newline bra putit -esc04 if2 @a,ne,#'r',esc05 - lda #13 +esc04 if2 @a,ne,#'r',esc05 "r" + lda #13 print newline bra putit -esc05 if2 @a,ne,#'t',esc06 - lda #9 +esc05 if2 @a,ne,#'t',esc06 "t" + lda #9 print tab bra putit -esc06 if2 @a,ne,#'0',putit - stz val +esc06 if2 @a,ne,#'0',putit "0" + stz val decode numeric value ldy #1 escloop lda [ptr],y and #$FF @@ -581,19 +660,29 @@ escloop lda [ptr],y pla inc ptr bra escloop -putval lda val -putit jsr putchar -didit inc ptr - jmp putloop -doneput lda #' ' - jsr putchar - jmp loop -done lda nl +putval lda val Get numeric escape code. + +putit jsr putchar Save character in accumulator. +didit inc ptr Point to next char in arg + jmp putloop and go process it. + +doneput dec argc Decrement argument counter. + beq done Done if no more arguments. + bmi done (or if there were no arguments!) + lda #' ' Add a blank + jsr putchar between arguments. + jmp loop Get next argument. + +done lda nl If "-n" flag isn't set, bne exit - jsr newline + jsr newline add a newline. + +exit jsr flush Print the buffer. + + +* Clear parameters from stack and return from subroutine. -exit jsr flush lda space sta end-3 lda space+1 @@ -638,53 +727,54 @@ end equ argv+4 phd tcd - lda argc - dec a + dec argc If an argument was provided, beq wait - ldx #^Usage + ldx #^Usage print the usage string. lda #Usage jsr errputs bra exit wait lock pwdmutex - jsl alloc256 + jsl alloc256 Allocate buffer for GetPrefix. sta gpptr stx gpptr+2 sta ptr stx ptr+2 - lda #256 + lda #256 Set max return len. sta [ptr] - GetPrefix gpparm - bcc ok - -awshit sta err - Error err + GetPrefix gpparm Get value of prefix 0 via GetPrefix. + bcc ok If there was an error, +awshit sta errError Save the value + ErrorGS err and report it. bra done -ok ldy #2 +ok ldy #2 Get GS/OS string length word. lda [ptr],y - xba - sta [ptr],y + xba Swap the bytes and store back, + sta [ptr],y so it can be used as a p-string. - ldx ptr+2 + ldx ptr+2 Load X/A with addr 3 bytes beyond ptr. lda ptr clc adc #3 - jsr putp - jsr newline + bcc doputp + inx +doputp anop + jsr putp Print the p-string + jsr newline and add a newline. -done ldx ptr+2 +done ldx ptr+2 Free the buffer. lda ptr jsl free256 unlock pwdmutex -exit lda space - sta end-3 +exit lda space Deallocate stack space + sta end-3 and return to the caller. lda space+1 sta end-2 pld @@ -693,17 +783,20 @@ exit lda space adc #end-4 tcs - lda #0 + lda #0 Return status always 0. rtl pwdmutex key -gpparm dc i'2' - dc i'0' -gpptr ds 4 +; Parameter block for GS/OS call GetPrefix +gpparm dc i'2' Parameter count + dc i'0' Prefix number +gpptr ds 4 Pointer to result buffer -err ds 2 +; Parameter block for shell ErrorGS call (p 393 in ORCA/M manual) +err dc i2'1' pCount +errError ds 2 Error number Usage dc c'Usage: pwd',h'0d00' @@ -1481,7 +1574,7 @@ space equ 0 inc exitamundo - return + return 2:#0 END @@ -1554,7 +1647,7 @@ turnnext sta newdebug done setdebug newdebug mv2 newdebug,globaldebug -return return +return return 2:#0 findflag inc arg ldy #0 @@ -1598,17 +1691,21 @@ usage dc c'Usage: setdebug (value | [+|-]flag ... )',h'0d0d' dc c' pathtrace - Trace GS/OS pathnames',h'0d' dc c' sigtrace - Trace signals',h'0d' dc c' systrace - Trace system calls',h'0d' +* >> Next line is temporary + dc c' breakpoint - Coded brk instructions',h'0d' dc h'00' errstr dc c': Unknown flag',h'0d0d00' -nametbl dc a4'str01,str02,str03,str04,str05,str06,0' +nametbl dc a4'str01,str02,str03,str04,str05,str06,str07,0' str01 dc c'gsostrace',h'00' str02 dc c'pathtrace',h'00' str03 dc c'gsoserrors',h'00' str04 dc c'sigtrace',h'00' str05 dc c'systrace',h'00' str06 dc c'gsosblocks',h'00' +* >> Next line is temporary; Also: remove str07 in nametbl +str07 dc c'breakpoint',h'00' bittbl dc i2'%000001' dc i2'%000010' @@ -1616,6 +1713,11 @@ bittbl dc i2'%000001' dc i2'%001000' dc i2'%010000' dc i2'%100000' +* >> Next line is temporary + dc i2'%10000000' + +* >> Next line is temporary +check4debug ENTRY globaldebug dc i2'0' @@ -1847,7 +1949,7 @@ skip jmp loop done kvm_close ps -return return +return return 2:#0 usage dc c'Usage: ps',h'0d00' kvmerrstr dc c'ps: error in kvm_open()',h'0d00' @@ -1950,7 +2052,7 @@ doneprint pei (sv+2) pei (sv) jsl sv_dispose -exit return +exit return 2:#0 END @@ -1970,29 +2072,31 @@ space equ retval+2 subroutine (4:argv,2:argc),space - stz retval - - dec argc + dec argc If no filename was provided, bne ok - ldx #^usage + ldx #^usage Print usage string. lda #usage jsr errputs - lda #1 + lda #1 Return error status. sta retval bra exit -ok add2 argv,#4,argv +ok stz retval - ldy #2 + add2 argv,#4,argv + +* ShellExec subroutine (4:path,2:argc,4:argv,2:jobflag) + + ldy #2 path is filename argument lda [argv],y pha lda [argv] pha - pei (argc) - pei (argv+2) + pei (argc) reuse argc + pei (argv+2) reuse argv pei (argv) - pea 0 + pea 0 jobflag = 0 jsl ShellExec sta retval @@ -2005,7 +2109,7 @@ usage dc c'usage: source file [arguments...]',h'0d00' ************************************************************************** * * COMMANDS: builtin command -* syntax: hash +* syntax: commands * * display builtin commands * @@ -2060,6 +2164,6 @@ doneprint pei (sv+2) pei (sv) jsl sv_dispose -exit return +exit return 2:#0 END diff --git a/bin/gsh/cmd.asm b/bin/gsh/cmd.asm index 4a357ee..85d5f64 100644 --- a/bin/gsh/cmd.asm +++ b/bin/gsh/cmd.asm @@ -6,20 +6,46 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: cmd.asm,v 1.2 1998/04/24 15:38:09 gdr-ftp Exp $ +* $Id: cmd.asm,v 1.3 1998/06/30 17:25:17 tribby Exp $ * ************************************************************************** * * CMD.ASM * By Tim Meekins +* Modified by Dave Tribby for GNO 2.0.6 * * Command line parsing routines. * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ +************************************************************************** +* +* Interfaces defined in this file: +* +* gettoken subroutine (4:word,4:stream) +* Returns value of token in Accumulator +* +* command subroutine (4:waitpid,2:inpipe,2:jobflag,2:inpipe2, +* 4:pipesem,4:stream) +* Returns next token in Accumulator +* +* argfree subroutine (2:argc,4:argv) +* +* ShellExec subroutine (4:path,2:argc,4:argv,2:jobflag) +* Returns completion status in Accumulator +* +* execute subroutine (4:cmdline,2:jobflag) +* Returns completion status in Accumulator +* +* system Defined for libc; interface in +* int system (char *command) +* ************************************************************************** mcopy /obj/gno/bin/gsh/cmd.mac -dummy start ; ends up in .root +dummycmd start ; ends up in .root end setcom 60 @@ -83,7 +109,7 @@ INQUOTE equ 2 ;parsing a quoted string INWORD equ 3 ;parsing a word SINGQUOTE equ 4 ;single quote string ; -; start in the neutral state +; Start in the neutral state ; ld2 NEUTRAL,state lda [stream] @@ -92,27 +118,29 @@ SINGQUOTE equ 4 ;single quote string lda [stream],y sta buf+2 ; -; the main loop +; Main loop: get character and take action based upon state. ; loop lda [buf] inc buf - and2 @a,#$FF,ch + and2 @a,#$FF,ch ch = next character. bne switch +; End of string detected. Action depends upon current state. + if2 state,ne,#INWORD,loop2 - jmp endword + jmp endword state INWORD: end the word. loop2 if2 @a,ne,#GTGT,loop3 dec buf - lda #T_GT + lda #T_GT state GTGT: return single GT. jmp done -loop3 if2 @a,eq,#INQUOTE,error1 - if2 @a,eq,#SINGQUOTE,error2 - lda #T_EOF +loop3 if2 @a,eq,#INQUOTE,error1 INQUOTE: error. + if2 @a,eq,#SINGQUOTE,error2 SINGQUOTE: error. + lda #T_EOF must be NEUTRAL: return EOF. jmp done -error1 ldx #^errstr1 +error1 ldx #^errstr1 Report string errors. lda #errstr1 bra error0 error2 ldx #^errstr2 @@ -134,9 +162,18 @@ statetbl dc a2'case_neutral' dc a2'case_single' ; ; CASE NEUTRAL -; +; Check for special characters: +; ; & | < creturn EOF -- set token value and go to done +; space tab -- ignore and stay in loop +; > -- Change state to GTGT and stay in loop +; # -- Eat characters to creturn or lf, then stay in loop +; " -- Change state to INQUOTE and stay in loop +; ' -- Change state to SINGQUOTE and stay in loop +; \ -- Get next character, change state to INWORD, and stay in loop +; All other characters: change state to INWORD and stay in loop + case_neutral if2 ch,ne,#';',neut1 - lda #T_SEMI + lda #T_SEMI jmp done neut1 if2 @a,ne,#'&',neut2 lda #T_AMP @@ -147,6 +184,7 @@ neut2 if2 @a,ne,#'|',neut3 neut3 if2 @a,ne,#'<',neut4 lda #T_LT jmp done + neut5 cmp #' ' ;space jeq loop cmp #9 ;tab @@ -154,12 +192,14 @@ neut5 cmp #' ' ;space if2 @a,ne,#'>',neut6 lda #GTGT bra neut10 + neut4 if2 @a,ne,#13,neut4a ;return lda #T_NL jmp done -neut4a if2 @a,ne,#0,neut4b ;EOF +neut4a if2 @a,ne,#0,neut4b ;EOF [Is this possible?? DMT] lda #T_EOF jmp done + neut4b if2 @a,ne,#'#',neut5 ;comment neut4c lda [buf] and #$7F @@ -169,6 +209,7 @@ neut4c lda [buf] if2 @a,eq,#10,neut4d bra neut4c neut4d jmp loop + neut6 if2 @a,ne,#'"',neut7 startquote lda #INQUOTE bra neut10 @@ -185,6 +226,7 @@ neut9 sta [word] ;default lda #INWORD neut10 sta state neut10a jmp loop + ; ; CASE GTGT ; @@ -316,11 +358,11 @@ end equ waitpid+4 phd tcd - ph4 #1024 - jsl ~NEW + ph4 #1024 Allocate 1024 bytes + jsl ~NEW and pointer in cmdline. sta cmdline stx cmdline+2 - lda #0 + lda #0 Initialize to null C string. sta [cmdline] jsl alloc1024 @@ -366,6 +408,7 @@ toktbl dc a2'loop' dc a2'tok_nl' dc a2'tok_eof' dc a2'tok_error' + ; ; Parse a word token ; @@ -535,13 +578,14 @@ tok_semi anop tok_nl anop tok_eof anop - lda argc ;terminate the argv list + lda argc bne nonnull lda #0 sta [waitpid] lda #T_NULL jmp exit -nonnull asl2 a + +nonnull asl2 a ;terminate the argv list tay lda #0 sta [argv],y @@ -594,9 +638,9 @@ run2 phx cmp #-1 beq exit - if2 token,ne,#T_BAR,run3 + if2 token,ne,#T_BAR,run3 If next token is "|", - pei (waitpid+2) + pei (waitpid+2) recursively call command. pei (waitpid) pei (pipefds) pei (jobflag) @@ -738,7 +782,8 @@ RRec equ CRec+4 NRec equ RRec+4 ORec equ NRec+4 ptr equ ORec+4 -space equ ptr+4 +status equ ptr+4 +space equ status+2 jobflag equ space+3 argv equ jobflag+2 argc equ argv+4 @@ -754,11 +799,7 @@ end equ path+4 phd tcd -wait ldy mutex - beq wait0 - cop $7F - bra wait -wait0 inc mutex + lock mutex ; ; set the variables 0..argc ; @@ -809,7 +850,7 @@ setit ph4 setparm cmp argc jcc parmloop -skipvar dec mutex +skipvar unlock mutex ph4 #4 ;Close parms jsl ~NEW @@ -858,11 +899,12 @@ skipvar dec mutex ph2 #$2010 ;OPEN jsl $E100B0 bcc ok - sta Err - Error Err + sta ErrError + ErrorGS Err jmp done -awshit sta Err - Error Err + +awshit sta ErrError + ErrorGS Err jmp almostdone ok ldy #2 ;Copy file ref num @@ -926,12 +968,16 @@ ReadLoop anop noecho lda [data] and #$FF if2 @a,eq,#'#',ReadLoop + +* execute subroutine (4:cmdline,2:jobflag) pei (data+2) pei (data) * ph2 #0 * ph2 #1 pei (jobflag) jsl execute + sta status + lda exitamundo bne almostdone bra ReadLoop @@ -975,17 +1021,21 @@ exit1a anop clc adc #end-4 tcs + + lda status Pass back status value. rtl NLTable dc h'0d' -Err ds 2 +; Parameter block for shell ErrorGS call (p 393 in ORCA/M manual) +Err dc i2'1' pCount +ErrError ds 2 Error number setparm ds 4 ds 4 num dc c'000',h'00' -mutex dc i'0' +mutex key END @@ -1004,7 +1054,11 @@ waitstatus equ ptr2+4 ptr equ waitstatus+2 pid equ ptr+4 term equ pid+2 -space equ term+2 +cmdstrt equ term+2 +cmdend equ cmdstrt+4 +end_char equ cmdend+4 +inquote equ end_char+2 +space equ inquote+2 jobflag equ space+3 ;set if not a job cmdline equ jobflag+2 end equ cmdline+4 @@ -1018,26 +1072,165 @@ end equ cmdline+4 phd tcd +; --------------------------------------------------------------- + +; New code for gsh 2.0 (Dave Tribby): within execute, loop through +; the command line to separate each command and expand it separately, +; rather than passing multiple commands to the next level. This is +; done so that commands that depend upon each other will work, e.g. +; set testnum=2 ; echo "This is test $testnum" + +; +; Find beginning and end of next command in the command line +; + lda cmdline Initialize cmdstrt to + sta cmdstrt beginning of cmdline. + lda cmdline+2 + sta cmdstrt+2 + +; Remove leading whitespace + +chkws lda [cmdstrt] Get next character. + and #$FF + jeq goback If at end of line, nothing to do! + cmp #" " If it's a space + beq bump_strt + cmp #9 or a tab, + bne found_start +bump_strt inc cmdstrt bump the start pointer + bne chkws and look for more whitespace. + inc cmdstrt+2 + bra chkws + +; Initialize pointer to end of command + +found_start anop + +; Scan the command line for next semi-colon. Need to account for +; quoted strings, backslash-escaped characters, and comments. + +; Take advantage of 65816's BIT command for the "in quotes" flag. Use +; $8000 for single-quote bit and $4000 for double-quote bit. After +; bit inquote +; can do a bmi to check for $8000 set and bvs for $4000 set. Can +; check for either with lda inquote followed by beq or bne. + + stz inquote Clear the "in quotes" flag. + + ldy #$FFFF Clear index into cmdstrt + +find_end anop + iny + lda [cmdstrt],y Get next character. + and #$FF If at end of string, + beq found_end all done looking. +; Check for special characters + cmp #"'" + beq s_quote + cmp #'"' + beq d_quote + cmp #'\' + beq b_slash +; "#" and ";" are special only if we aren't in a quoted string + ldx inquote + bne find_end + cmp #"#" + beq found_end + cmp #";" + beq found_end +; Not a special character. Keep looking. + bra find_end + + +; "'" found +s_quote bit inquote Check the "in quotes" flag. + bvs find_end In double quotes...keep looking. + lda inquote Toggle the single_quote + eor #$8000 bit in the "in quotes" flag. + sta inquote + bra find_end Keep looking. + +; '"' found +d_quote bit inquote Check the "in quotes" flag. + bmi find_end In single quotes...keep looking. + lda inquote Toggle the double_quote + eor #$4000 bit in the "in quotes" flag. + sta inquote + bra find_end Keep looking. + +; "\" found: accept next character without examining it in detail +b_slash iny Bump index. + lda [cmdstrt],y Get next character. + and #$FF If not at end of string, + bne find_end keep looking. + +; +; Found a ";", "#", or null byte. +; +found_end anop + sta end_char Save the ending character. + + tya Get number of bytes in command. + jeq goback If none, just skip it. + + clc Add command length to + adc cmdstrt starting address to + sta cmdend get ending address. + lda #0 + adc cmdstrt+2 + sta cmdend+2 + + lda end_char Get the termination character. + beq expand If it's not a null byte, + lda #0 + short m + sta [cmdend] store null byte in string. + long m + +; Continue with command-line expansions for the single command + +expand anop + +; --------------------------------------------------------------- + stz pipesem stz waitstatus - pei (cmdline+2) - pei (cmdline) +; Expand $ (environment variables) and ~ in the raw command line + pei (cmdstrt+2) + pei (cmdstrt) jsl expandvars + +; Expand wildcard characters in the modified command line phx pha sta ptr stx ptr+2 jsl glob + +; Expand aliases in the modified command line phx pha sta ptr2 stx ptr2+2 jsl expandalias + phx pha sta exebuf stx exebuf+2 + +* >> Temporary debug code: echo expanded command if echo is set. + using vardata + lda varecho + beq noecho + ldx exebuf+2 + lda exebuf + jsr puts + jsr newline +noecho anop + + ldx ptr+2 lda ptr jsl free1024 @@ -1053,27 +1246,31 @@ end equ cmdline+4 pla stz term lda #0 - jmp ouch + jmp chk_cmd -loop pea 0 ;Bank 0 + +* command l_subroutine (4:waitpid,2:inpipe,2:jobflag,2:inpipe2, +* 4:pipesem,4:stream) +loop pea 0 ;Bank 0 waitpid (hi) tdc clc adc #pid - pha - pea 0 - pei (jobflag) - pea 0 - pea 0 ;Bank 0 + pha waitpid (low) + pea 0 inpipe + pei (jobflag) jobflag + pea 0 inpipe2 + pea 0 ;Bank 0 pipesem (hi) tdc clc adc #pipesem - pha - pea 0 ;Bank 0 + pha pipesem (low) + pea 0 ;Bank 0 stream (hi) tdc clc adc #exebuf - pha + pha stream (low) jsl command + sta term bmi noerrexit @@ -1118,23 +1315,48 @@ otherwait ldx #0 jobwait jsl pwait sta waitstatus +; If command detected EOF terminator, all done nowait if2 term,eq,#T_EOF,noerrexit - lda [exebuf] + lda [exebuf] If not at end of line, and #$FF - beq exit - jmp loop + beq exit + jmp loop process the next command. noerrexit stz waitstatus ;non-forked builtins cannot return an error + exit jsl nullfree lda term ;make sure we return -1 if error - bmi ouch + bmi chk_cmd lda waitstatus xba and #$FF -ouch tay - lda space+1 - sta end-2 + +; +; Is there another command waiting in the buffer? +; +chk_cmd ldx end_char Was the original ending character + cpx #";" a semi-colon? + bne goback NO -- all done. + +; Set cmdstrt to point to the character beyond cmdend + lda cmdend + ldx cmdend+2 + ina + bne set_strt + inx +set_strt sta cmdstrt + stx cmdstrt+2 + + jmp chkws Parse the next command. + +; +; All done. +; +goback tay Hold return status in Y-reg. + + lda space+1 Set up stack + sta end-2 for rtl. lda space sta end-3 pld @@ -1143,7 +1365,8 @@ ouch tay adc #end-4 tcs - tya + tya Restore return status from Y-reg. + rtl END @@ -1161,11 +1384,22 @@ space equ retval+2 subroutine (4:str),space ;need the phk/plb - pei (str+2) + lda str If user passes a + ora str+2 null pointer, + bne makecall + ina return 1 to caller. + +; +; Let execute(str) do the work +; +makecall pei (str+2) pei (str) ph2 #1 ;tells execute we're called by system jsl execute - sta retval +; +; Set status and go back to the caller +; +setrtn sta retval return 2:retval diff --git a/bin/gsh/dir.asm b/bin/gsh/dir.asm index 0aff679..03b9191 100644 --- a/bin/gsh/dir.asm +++ b/bin/gsh/dir.asm @@ -6,20 +6,38 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: dir.asm,v 1.2 1998/04/24 15:38:12 gdr-ftp Exp $ +* $Id: dir.asm,v 1.3 1998/06/30 17:25:20 tribby Exp $ * ************************************************************************** * * DIR.ASM * By Tim Meekins +* Modified by Dave Tribby for GNO 2.0.6 * * Directory stack management * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ +************************************************************************** +* +* Interfaces defined in this file: +* +* InitDStack +* +* dirs +* +* pushd +* +* popd +* +* path2tilde +* ************************************************************************** mcopy /obj/gno/bin/gsh/dir.mac -dummy start ; ends up in .root +dummydir start ; ends up in .root end setcom 60 @@ -97,7 +115,7 @@ showshort jsl dotods pea 1 jsl showdir -exit return +exit return 2:#0 usingstr dc c'usage: dirs [-l]',h'0d00' @@ -258,7 +276,7 @@ done lda varpushdsil pea 1 jsl showdir -exit return +exit return 2:#0 usagestr dc c'usage: pushd [+n | dir]',h'0d00' err1 dc c'pushd: No other directory',h'0d00' @@ -386,7 +404,7 @@ gototop lda tods pea 1 jsl showdir -exit return +exit return 2:#0 usingstr dc c'Usage: popd [+n]',h'0d00' err1 dc c'popd: Directory stack empty',h'0d00' @@ -421,8 +439,8 @@ space equ retval+2 GetFileInfo GRec bcc ok -ohshit sta Err - Error Err +ohshit sta ErrError + ErrorGS Err inc retval bra done @@ -448,16 +466,21 @@ done ph4 PRecPath mutex key -PRec dc i'2' -PRecNum dc i'0' -PRecPath ds 4 +; Parameter block for GS/OS SetPrefix call +PRec dc i'2' pCount +PRecNum dc i'0' prefixNum (0 = current directory) +PRecPath ds 4 Pointer to input prefix path -GRec dc i'3' -GRecPath ds 4 -GRecAcc ds 2 -GRecFT ds 2 +; Parameter block for GS/OS GetFileInfo call +GRec dc i'3' pCount +GRecPath ds 4 Pointer to input pathname +GRecAcc ds 2 access (result) +GRecFT ds 2 fileType (result) + +; Parameter block for shell ErrorGS call (p 393 in ORCA/M manual) +Err dc i2'1' pCount +ErrError ds 2 Error number -Err ds 2 dirErr dc c': Not a directory',h'0d00' END @@ -625,34 +648,40 @@ space equ home+4 sta ptr stx ptr+2 - jsl alloc256 + jsl alloc256 Allocate 256 byte GS/OS result buf. sta home stx home+2 - sta varparm+4 - stx varparm+6 - Read_Variable varparm + sta ReadName + stx ReadName+2 + lda #256 Set buffer length word. + sta [home] + ReadVariableGS ReadVar Read $home environment variable. - ldy #0 - lda [home] - and #$FF - beq copyrest - tax -checkhome lda [path],y - and #$FF - beq notfound2 - jsr tolower - jsr toslash - pha - iny + ldy #2 Get result length word. lda [home],y - and #$FF - jsr tolower - jsr toslash - cmp 1,s - bne notfound - pla - dex - bne checkhome + beq notfound2 If 0, just copy the rest. + tax Use X to count down HOME chars. + ldy #0 path index is based from 0. +checkhome lda [path],y + and #$FF Isolate character in parameter, + beq notfound2 checking for end of string, + jsr tolower converting to lower-case + jsr toslash and changing ":" to "/". + pha Hold that character on the stack. + iny4 $home has 4 bytes of length info + lda [home],y that need to be indexed over. + dey2 Take back 3 of the offset, + dey nudging Y ahead by 1. + and #$FF Isolate $home character, + jsr tolower converting to lower-case + jsr toslash and changing ":" to "/". + cmp 1,s If the parameter character !=, + bne notfound there is no match. + pla Pop the parameter character off stack. + dex Decrement $home length counter. + bne checkhome If more, stay in loop. + +; All the characters matched $home. cmp #'/' beq found lda [path],y @@ -696,9 +725,13 @@ skipshorten ldx home+2 return 4:newpath -varparm dc i4'homename' - ds 4 +; Parameter block for shell ReadVariableGS call (p 423 in ORCA/M manual) +ReadVar anop + dc i2'3' pCount + dc a4'homename' Pointer to name +ReadName ds 4 GS/OS Output buffer ptr: value + ds 2 export flag -homename str 'home' +homename gsstr 'home' Env variable name END diff --git a/bin/gsh/edit.asm b/bin/gsh/edit.asm index c89d259..c16f409 100644 --- a/bin/gsh/edit.asm +++ b/bin/gsh/edit.asm @@ -6,7 +6,7 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: edit.asm,v 1.2 1998/04/24 15:38:14 gdr-ftp Exp $ +* $Id: edit.asm,v 1.3 1998/06/30 17:25:23 tribby Exp $ * ************************************************************************** * @@ -15,11 +15,14 @@ * * The GNO/Shell command-line editor * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/edit.mac -dummy start ; ends up in .root +dummyedit start ; ends up in .root end setcom 60 @@ -347,7 +350,7 @@ cmdclrline ldx cmdloc ;------------------------------------------------------------------------- cmdclreol lda cdcap - ora cdcap + ora cdcap+2 beq ctl4a0 tputs (cdcap,#1,#outc) bra ctl4g @@ -729,10 +732,11 @@ newpos equ varpos+2 wordpos equ newpos+2 jsl alloc256 - sta varparms+4 - stx varparms+6 + sta ReadName + stx ReadName+2 phx pha + Read_Variable varparms jsr p2cstr sta var @@ -740,8 +744,8 @@ wordpos equ newpos+2 phx pha jsr lowercstr - lda varparms+4 - ldx varparms+6 + lda ReadName + ldx ReadName+2 jsl free256 lda [var] @@ -818,10 +822,13 @@ done pei (var+2) jsl nullfree rts -varparms dc a4'fignore' - ds 4 +; Parameter block for shell Read_Variable call +; [predecessor to ReadVariableGS call (p 423 in ORCA/M manual)] +varparms anop + dc a4'fignore' Pointer to name +ReadName ds 4 Pointer to result -fignore str 'fignore' +fignore str 'fignore' Env variable name END @@ -1070,10 +1077,9 @@ gotflag anop cmp #'$' jne filem - ld2 1,varParm+8 + ld2 1,varIndex varloop Read_Indexed varParm lda buffer - and #$FF jeq vardone dec a cmp wordlen ;if shorter than word skip @@ -1149,7 +1155,7 @@ gv01 lda buffer,y lda sepstyle sta [0],y -nextvar inc varParm+8 +nextvar inc varIndex jmp varloop vardone rts @@ -1441,10 +1447,13 @@ GFType dc i2'0' GFAux dc i4'0' -varParm dc i4'buffer' - dc i4'varval' - dc i2'0' - +; Parameter block for shell Read_Indexed call +; [predecessor to ReadIndexedGS call (p 421 in ORCA/M manual)] +varParm anop + dc i4'buffer' Name (pointer to 256-byte p-string) + dc i4'varval' Value (pointer to 256-byte p-string) +varIndex dc i2'0' Index number + ds 1 ;<- don't futz with me!! varval ds 256 diff --git a/bin/gsh/expand.asm b/bin/gsh/expand.asm index 8fea51c..58fb7f5 100644 --- a/bin/gsh/expand.asm +++ b/bin/gsh/expand.asm @@ -6,27 +6,31 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: expand.asm,v 1.2 1998/04/24 15:38:17 gdr-ftp Exp $ +* $Id: expand.asm,v 1.3 1998/06/30 17:25:27 tribby Exp $ * ************************************************************************** * * EXPAND.ASM * By Tim Meekins +* Modified by Dave Tribby for GNO 2.0.6 * -* Command line expansion routines. +* Command line expansion routines for wildcards and env vars * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/expand.mac -dummy start ; ends up in .root +dummyexpand start ; ends up in .root end setcom 60 ************************************************************************** * -* glob the command line +* glob the command line and expand filename wildcard characters * ************************************************************************** @@ -52,7 +56,9 @@ space equ buf+4 ; lda varnoglob beq doglob - jsl alloc1024 ;create a tmp output buffer buffer + +; Allocate a buffer, copy the command line into it, and return. + jsl alloc1024 sta buf stx buf+2 pei (cmd+2) @@ -64,7 +70,7 @@ space equ buf+4 ; ; noglob isn't set, so now we can actually start. ; -doglob jsl alloc1024 ;create an output buffer buffer +doglob jsl alloc1024 ;create an output buffer sta buf sta ptr stx buf+2 @@ -72,29 +78,38 @@ doglob jsl alloc1024 ;create an output buffer buffer jsl alloc1024 ;create a word buffer sta wordbuf stx wordbuf+2 + ; -; strip some white space +; Find the beginning of the next word ; -skipit jsr getbyte +findword jsr g_getbyte Get character from command line. jeq alldone - if2 @a,eq,#' ',whitestuff - if2 @a,eq,#009,whitestuff - if2 @a,eq,#013,whitestuff - if2 @a,eq,#010,whitestuff - if2 @a,eq,#';',whitestuff - if2 @a,eq,#'&',whitestuff - if2 @a,eq,#'|',whitestuff - if2 @a,eq,#'>',whitestuff - if2 @a,eq,#'<',whitestuff + if2 @a,eq,#' ',passthru + if2 @a,eq,#009,passthru + if2 @a,eq,#013,passthru + if2 @a,eq,#010,passthru + if2 @a,eq,#';',passthru + if2 @a,eq,#'&',passthru + if2 @a,eq,#'|',passthru + if2 @a,eq,#'>',passthru + if2 @a,eq,#'<',passthru + +; It's not a simple pass-through character. See what needs to happen. + stz shallweglob ldy #0 bra grabbingword -whitestuff jsr putbyte - bra skipit + +; For pass-through characters, just copy to output buffer. + +passthru jsr g_putbyte + bra findword + + ; ; single out the next word [y is initialized above] ; -grabword jsr getbyte +grabword jsr g_getbyte grabbingword if2 @a,eq,#"'",grabsingle if2 @a,eq,#'"',grabdouble if2 @a,eq,#'\',grabslash @@ -112,35 +127,48 @@ grabbingword if2 @a,eq,#"'",grabsingle if2 @a,eq,#']',grabglob if2 @a,eq,#'*',grabglob if2 @a,eq,#'?',grabglob -grabnext sta [wordbuf],y - iny - bra grabword -grabglob ldx #1 - stx shallweglob - bra grabnext -grabslash sta [wordbuf],y - iny - jsr getbyte - beq procword - bra grabnext -grabsingle sta [wordbuf],y - iny - jsr getbyte - beq procword - if2 @a,eq,#"'",grabnext - bra grabsingle -grabdouble sta [wordbuf],y - iny - jsr getbyte - beq procword - if2 @a,eq,#'"',grabnext - bra grabdouble + +; Default action (also completion of some of the other special cases) +grabnext sta [wordbuf],y Save character in word buffer + iny and bump its index. + bra grabword Get next character of word. + +; "[", "]", "*", "?" +grabglob ldx #1 Set "shallweglob" + stx shallweglob flag. + bra grabnext Store char in word buf & get next. + +; "\" +grabslash sta [wordbuf],y Save "\" in word buffer + iny and bump its index. + jsr g_getbyte Get next character in cmd line. + beq procword If null byte, word is terminated. + bra grabnext Store char in word buf & get next. + +; '"' +grabsingle sta [wordbuf],y Save char in word buffer + iny and bump its index. + jsr g_getbyte Get next character in cmd line. + beq procword If null byte, word is terminated. + if2 @a,eq,#"'",grabnext If "'", store and grab next char. + bra grabsingle Save new char and stay in this loop. + +; "'" +grabdouble sta [wordbuf],y Save char in word buffer + iny and bump its index. + jsr g_getbyte Get next character in cmd line. + beq procword If null byte, word is terminated. + if2 @a,eq,#'"',grabnext If '"', store and grab next char. + bra grabdouble Save new char and stay in this loop. + + ; -; we've grabbed the next word, now process the word +; The complete word is in the buffer. Time to process it. ; -procword dec cmd - lda #0 - sta [wordbuf],y +procword dec cmd Decrement cmd line pointer. + lda #0 Terminate word buffer with + sta [wordbuf],y a null byte. + ; ; Shall we glob? Shall we scream? What happened, to our postwar dream? ; @@ -150,16 +178,17 @@ procword dec cmd lda shallweglob bne globword ; -; we didn't glob this word, so flush the word buffer +; we didn't glob this word, so copy the word buffer to the output buffer ; skipdeglob ldy #0 flushloop lda [wordbuf],y and #$FF beq doneflush - jsr putbyte + jsr g_putbyte iny bra flushloop -doneflush jmp skipit +doneflush jmp findword + ; ; Hello, boys and goils, velcome to Tim's Magik Shoppe ; @@ -183,7 +212,7 @@ doneflush jmp skipit ; Expand out the quoted stuff, and keep an eye out for that ubiquitous last ; filename separator... then we can isolate him! ; -globword stz filesep +globword stz filesep jsl alloc1024 sta eptr stx eptr+2 @@ -255,13 +284,9 @@ copyback lda [wordbuf],y ; We now have enough to call _InitWildCard!!! ; [ let's mutex the rest so we don't have to fix _InitWC and _NextWC ;-) ] ; -wait2 lda mutex - beq wait2a - cop $7F - bra wait2 -wait2a inc mutex + lock glob_mutex ; -; start 'em up +; Call shell routine InitWildcard to initialize the filename pattern ; stz count mv4 exppath,initWCparm @@ -276,57 +301,52 @@ wait2a inc mutex sta nWCparm stx nWCparm+2 ; -; start the expansion dudes! +; Call shell routine NextWildcard to get the next name that matches. ; WCloop Next_Wildcard nWCparm lda [gname] and #$FF beq nomore - inc count ; -; get that owiginal path outta here! +; Keep count of how many paths are expanded +; + inc count + +; +; Copy the original path (up to file separator) to output buffer ; ldy #0 outtahere if2 @y,eq,filesep,globout lda [wordbuf],y - jsr putspecial + jsr g_putspecial iny bra outtahere ; -; now get that newly globbed file outta here +; Copy the expanded filename to output buffer ; globout lda [gname] and #$FF tax ldy #1 globoutta lda [gname],y - jsr putspecial + jsr g_putspecial iny dex bne globoutta ; -; well well well, one down, how many to go? +; Place blank as separator after name and see if more are expanded. ; lda #' ' - jsr putbyte + jsr g_putbyte bra WCloop + ; -; no more left, whatta we gonna do now! +; All of the names (if any) from this pattern have been expanded. ; nomore anop + ; -; no match -; - lda count - bne yesmore - ldx #^nomatch - lda #nomatch - jsr puts - lda #0 - sta [buf] -yesmore anop -; -; throw em away (we should probably alloc once, not each word... ) +; Deallocate path buffers (we should probably alloc once, not each word... ) ; pei (gname+2) pei (gname) @@ -334,31 +354,54 @@ yesmore anop ldx exppath+2 lda exppath jsl free1024 - dec mutex - lda count - beq alldone2 - jmp skipit + unlock glob_mutex + + lda count If somehing was expanded, + jne findword go find the next word. + +; Nothing was expanded from the wildcard. If we wanted to act like +; ksh, we could pass the original text by doing a "jmp skipdeglob". +; Since passing a bad filename can mess up some programs, we will +; print an error message for this name and continue processing others. + + ldx #^nomatch + lda #nomatch + jsr errputs + + ldx wordbuf+2 + lda wordbuf + jsr errputs + + ldx #^ignored + lda #ignored + jsr errputs + + jmp findword Go find the next word. + ; ; Goodbye, cruel world, I'm leaving you today, Goodbye, goodbye. ; -alldone jsr putbyte -alldone2 ldx wordbuf+2 +alldone jsr g_putbyte + ldx wordbuf+2 lda wordbuf jsl free1024 bye return 4:buf + + ; -; get a byte from the original command-line +; Subroutine of glob: get a byte from the original command-line ; -getbyte lda [cmd] +g_getbyte lda [cmd] inc cmd and #$FF rts + ; -; put special characters. Same as putbyte, but if it is a special -; shell character then quote it. +; Subroutine of glob: put special characters. Same as g_putbyte, but +; if it is a special shell character then quote it. ; -putspecial and #$7F +g_putspecial and #$7F if2 @a,eq,#' ',special if2 @a,eq,#'.',special if2 @a,eq,#013,special @@ -368,33 +411,38 @@ putspecial and #$7F if2 @a,eq,#'<',special if2 @a,eq,#'>',special if2 @a,eq,#'|',special - bra putbyte + bra g_putbyte special pha lda #'\' - jsr putbyte - pla + jsr g_putbyte + pla ; fall through to g_putbyte... ; -; store a byte into the new command-line +; Subroutine of glob: store a byte into the new command-line ; -putbyte short a +g_putbyte short a sta [ptr] long a inc ptr rts -mutex dc i'0' -InitWCParm ds 4 - dc i2'%00000001' -nWCparm ds 4 +glob_mutex key -nomatch dc c'No match.',h'0d00' +; Parameter block for InitWildcard shell call (ORCA/M pp 414-415) +InitWCParm ds 4 Path name, with wildcard + dc i2'%00000001' Flags (this bit not documented!!!) + +; Parameter block for NextWildcard shell call (ORCA/M pp 417-418) +nWCparm ds 4 Pointer to returned path name + +nomatch dc c'No match: ',h'00' +ignored dc c' ignored',h'0d00' END ************************************************************************** * -* Expand variables not in single quotes +* Expand $variables and tildes not in single quotes * * * Add error checking if out buf gets too big (> 1024) * * Get rid of fixed buffers @@ -404,9 +452,9 @@ nomatch dc c'No match.',h'0d00' expandvars START ptr equ 1 -;ptr equ 0 buf equ ptr+4 -space equ buf+4 +dflag equ buf+4 +space equ dflag+2 cmd equ space+3 end equ cmd+4 @@ -419,61 +467,55 @@ end equ cmd+4 phd tcd + stz dflag Delimiter flag = FALSE. + jsl alloc1024 sta buf sta ptr stx buf+2 stx ptr+2 -loop jsr getbyte +loop jsr e_getbyte jeq done if2 @a,eq,#"'",quote if2 @a,eq,#'$',expand if2 @a,eq,#'~',tilde if2 @a,eq,#'\',slasher - jsr putbyte + jsr e_putbyte bra loop -slasher jsr putbyte - jsr getbyte - jsr putbyte +slasher jsr e_putbyte + jsr e_getbyte + jsr e_putbyte bra loop -quote jsr putbyte - jsr getbyte +quote jsr e_putbyte + jsr e_getbyte jeq done if2 @a,ne,#"'",quote - jsr putbyte + jsr e_putbyte bra loop -tilde anop -wait2 lda mutex - beq wait2a - cop $7F - bra wait2 -wait2a inc mutex - - short a - lda #'h' - sta name - lda #'o' - sta name+1 - lda #'m' - sta name+2 - lda #'e' - sta name+3 - long a - ldx #4 - jmp getval ; -; expand the variable since a '$' was encountered. +; Tilde expansion: use the contents of $home, but make sure the +; path delimiter(s) match what the user wants (either "/" or ":") +; +tilde anop + lock exp_mutex + + lda #"oh" Strangely enough, + sta name this spells "home"! + lda #"em" + sta name+2 + sta dflag Delimiter flag = TRUE. + ldx #4 + jmp getval + +; +; Expand an environment variable since a '$' was encountered. ; expand anop -wait1 lda mutex - beq wait1a - cop $7F - bra wait1 -wait1a inc mutex + lock exp_mutex lda #0 sta name @@ -493,29 +535,32 @@ nameloop lda [cmd] if2 @a,cc,#'a',getval if2 @a,cc,#'z'+1,inname bra getval -inname jsr getbyte +inname jsr e_getbyte sta name,x inx bra nameloop + ; ; expand in braces {} ; -braceexpand jsr getbyte +braceexpand jsr e_getbyte ldx #0 braceloop lda [cmd] and #$FF beq getval - jsr getbyte + jsr e_getbyte if2 @a,eq,#'}',getval sta name,x inx bra braceloop + ; ; get text from standard input ; -stdinexpand jsr getbyte +stdinexpand jsr e_getbyte ReadLine (#value+1,#255,#13,#1),@a - bra storeval2 + bra chklen + ; ; get a value for this variable ; @@ -529,24 +574,77 @@ getval lda #0 stx parm+2 Read_Variable parm jsl nullfree + + lda value Get length +chklen and #$FF byte. + beq expanded If 0, nothing to do + tax Save length in X-reg. + lda dflag If delimiter flag isn't set, + beq storeval go store the variable value + +; Check to see if delimiters in the variable need to be switched + lda value Set up length + and #$FF byte in + tax X-reg and + lda [cmd] Get next command line + and #$FF character. + cmp #"/" If it's a slash, see if + beq chkvarslash variable needs to convert to slash. + cmp #":" If it's not a colon, + bne storeval no need to convert. + lda value+1 Get first character of value. + and #$FF + cmp #"/" If it's not a slash, + bne storeval no need to convert. + +; Convert variable from "/" to ":" delimiter + short m +chk_s lda value,x + cmp #"/" + bne bump_s + lda #":" + sta value,x +bump_s dex + bpl chk_s + long m + bra storeval + +chkvarslash anop + lda value+1 Get first character of value. + and #$FF + cmp #":" If it's not a colon, + bne storeval no need to convert. + +; Convert variable from ":" to "/" delimiter + short m +chk_c lda value,x + cmp #":" + bne bump_c + lda #"/" + sta value,x +bump_c dex + bpl chk_c + long m + ; ; store the variable value in the out buffer ; -storeval lda value -storeval2 and #$FF - beq expanded - tay - ldx #0 +storeval anop + lda value Get length + and #$FF byte. + tay Save length in Y-reg. + ldx #0 Use X-reg in index value. putval lda value+1,x - jsr putbyte + jsr e_putbyte inx dey bne putval -expanded dec mutex +expanded unlock exp_mutex + stz dflag Delimiter flag = FALSE. jmp loop -done jsr putbyte +done jsr e_putbyte ldx buf+2 ldy buf @@ -564,20 +662,21 @@ done jsr putbyte tya rtl -getbyte lda [cmd] +e_getbyte lda [cmd] inc cmd and #$FF rts -putbyte short a +e_putbyte short a sta [ptr] long a inc ptr rts -mutex dc i'0' +exp_mutex key -parm dc a4'name' +; Parameter block for ReadVariable shell call +parm dc a4'name' dc a4'value' name ds 256 diff --git a/bin/gsh/gsh.mac b/bin/gsh/gsh.mac index c876ec6..2403093 100644 --- a/bin/gsh/gsh.mac +++ b/bin/gsh/gsh.mac @@ -4,6 +4,20 @@ ; because of use by other macros: bgt, ble, p16, ph2, pl2, tool ; ---------------------------------------------------------------------- +; New, experimental macros + +******************** +* breakpoint +******************** + MACRO +&lab breakpoint &flag + lda check4debug + and #$80 + beq *+4 + brk &flag + MEND + + ******************** * add2 ******************** @@ -222,7 +236,7 @@ macro &l dosin &adr &l dc i"l:~&sysname&syscnt" -~&sysname&syscnt dc c"&adr" +~&sysname&syscnt dc c"&adr" mend ******************** @@ -289,6 +303,14 @@ &lab p16 $105,&a1 mend +******************** +* ErrorGS +******************** + macro +&l ErrorGS &p +&l ShellGS $0145,&p + mend + ******************** * ErrWriteCString ******************** @@ -323,6 +345,14 @@ &lab p16 $116,&a1 mend +******************** +* ExportGS +******************** + macro +&l EsportGS &p +&l ShellGS $0156,&p + mend + ******************** * FindHandle ******************** @@ -489,6 +519,14 @@ &lab p16 $109,&a1 mend +*********************** +* InitWildcardGS +*********************** + macro +&l InitWildcardGS &p +&l ShellGS $0149,&p + mend + ******************** * Int2Dec ******************** @@ -917,6 +955,14 @@ pastName&SYSCNT anop &lab p16 $10A,&a1 mend +*********************** +* NextWildcardGS +*********************** + macro +&l NextWildcardGS &p +&l ShellGS $014A,&p + mend + ******************** * Open ******************** @@ -1105,6 +1151,14 @@ pastName&SYSCNT anop &lab p16 $117,&a1 mend +*********************** +* PopVariablesGS +*********************** + macro +&l PopVariablesGS &p +&l ShellGS $0157,&p + mend + ******************** * PtrToHand ******************** @@ -1124,6 +1178,14 @@ pastName&SYSCNT anop &lab p16 $118,&a1 mend +************************ +* PushVariablesGS +************************ + macro +&l PushVariablesGS &p +&l ShellGS $0158,&p + mend + ******************** * Quit ******************** @@ -1147,6 +1209,15 @@ pastName&SYSCNT anop &lab READ_INDEXED &a1 &lab p16 $108,&a1 mend + +********************** +* ReadIndexedGS +********************** + macro +&l ReadIndexedGS &p +&l ShellGS $0148,&p + mend + ******************** * READ_VARIABLE ******************** @@ -1155,6 +1226,14 @@ pastName&SYSCNT anop &lab p16 $10B,&a1 mend +*********************** +* ReadVariableGS +*********************** + macro +&l ReadVariableGS &p +&l ShellGS $014B,&p + mend + ******************** * ReadLine ******************** @@ -1193,6 +1272,14 @@ pastName&SYSCNT anop &lab p16 $110,&a1 mend +******************** +* RedirectGS +******************** + macro +&l RedirectGS &p +&l ShellGS $0150,&p + mend + ******************** * return ******************** @@ -1273,11 +1360,11 @@ pastName&SYSCNT anop MEND ******************** -* SET_LINFOGS +* SetLInfoGS ******************** macro -&lab SET_LINFOGS &a1 -&lab p16 $142,&a1 +&l SetLInfoGS &p +&l ShellGS $0142,&p mend ******************** @@ -1288,6 +1375,14 @@ pastName&SYSCNT anop &lab p16 $106,&a1 mend +******************** +* SetGS +******************** + macro +&l SetGS &p +&l ShellGS $0146,&p + mend + ******************** * setdebug ******************** @@ -1671,6 +1766,14 @@ pastName&SYSCNT anop &lab p16 $115,&a1 mend +******************** +* UnsetVariableGS +******************** + macro +&l UnsetVariableGS &p +&l ShellGS $0155,&p + mend + ******************** * Volume ******************** @@ -1758,6 +1861,25 @@ pastName&SYSCNT anop dc i4'&a2' mend +*********************************************** +* ShellGS: Jump into OS for a shell call +*********************************************** + MACRO +&lab ShellGS &a1,&a2 +&lab jsl $E100A8 + dc i2'&a1' + dc i4'&a2' + mend + +******************** +* GSOS +******************** + MACRO +&lab GSOS &a1,&a2 +&lab jsl $E100A8 + dc i2'&a1' + dc i4'&a2' + mend ******************** * ph2 diff --git a/bin/gsh/gsh.rez b/bin/gsh/gsh.rez index fdfcade..1792a04 100644 --- a/bin/gsh/gsh.rez +++ b/bin/gsh/gsh.rez @@ -1,7 +1,7 @@ /* * Resources for version and comment * - * $Id: gsh.rez,v 1.1 1998/04/24 15:38:19 gdr-ftp Exp $ + * $Id: gsh.rez,v 1.2 1998/06/30 17:25:33 tribby Exp $ */ #define PROG "gsh" @@ -15,8 +15,8 @@ */ resource rVersion (1, purgeable3) { { 2, 0, 0, /* Version 2.0.0 */ - release, /* development|alpha|beta|final|release */ - 0 }, /* non-final release number */ + development, /* development|alpha|beta|final|release */ + 1 }, /* non-final release number */ verUS, /* Country */ PROG, /* Program name */ DESC diff --git a/bin/gsh/hash.asm b/bin/gsh/hash.asm index fdf141e..41e23c3 100644 --- a/bin/gsh/hash.asm +++ b/bin/gsh/hash.asm @@ -6,7 +6,7 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: hash.asm,v 1.2 1998/04/24 15:38:21 gdr-ftp Exp $ +* $Id: hash.asm,v 1.3 1998/06/30 17:25:34 tribby Exp $ * ************************************************************************** * @@ -15,11 +15,41 @@ * * Command hashing routines * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ +************************************************************************** +* +* Interfaces defined in this file: +* +* hash jsr with params: (2:num, 4:name) +* +* dohash subroutine (4:files) +* return 4:table +* +* search subroutine (4:file,4:table,4:paths) +* return 4:full_path +* +* dispose_table subroutine (4:table) +* return +* +* free_files subroutine (4:files) +* return +* +* dir_search subroutine (4:dir,2:dirNum,4:files) +* return +* +* hashpath jsl with no parameters +* no returned value +* +* dispose_hash jsr with no parameters +* no returned value +* ************************************************************************** mcopy /obj/gno/bin/gsh/hash.mac -dummy start ; ends up in .root +dummyhash start ; ends up in .root end setcom 60 @@ -532,6 +562,7 @@ goodopen jsl nullfree sta ptr stx DRecName+2 stx ptr+2 + lda #254 ;Output buffer size (GT never did this?) sta [ptr] GetDirEntry DRec @@ -606,25 +637,28 @@ done ldx DRecName+2 exit return -ORec dc i'3' -ORecRef ds 2 -ORecPath ds 4 -ORecAccess dc i'1' ;read -DRec dc i'13' -DRecRef ds 2 -DRecFlag ds 2 -DRecBase dc i'0' -DRecDisp dc i'0' -DRecName ds 4 -DRecEntry ds 2 -DRecFileType ds 2 -DRecEOF ds 4 -DRecBlockCnt ds 4 -DRecCreate ds 8 -DRecMod ds 8 -DRecAccess ds 2 -DRecAuxType ds 4 +; Parameter block for GS/OS Open and Close calls +ORec dc i'3' pCount (3 for Open, 1 for Close) +ORecRef ds 2 refNum +ORecPath ds 4 pathname (result buf) +ORecAccess dc i'1' requested access = read + +; Parameter block for GS/OS GetDirEntry call +DRec dc i'13' pCount +DRecRef ds 2 refNum +DRecFlag ds 2 flags: extended/not +DRecBase dc i'0' base: displacement is absolute entry # +DRecDisp dc i'0' displacement: get tot # active entries +DRecName ds 4 name: result buf +DRecEntry ds 2 entryNum: entry # whose info is rtrned +DRecFileType ds 2 fileType +DRecEOF ds 4 eof: # bytes in data fork +DRecBlockCnt ds 4 blockCount: # blocks in data fork +DRecCreate ds 8 createDateTime +DRecMod ds 8 modDateTime +DRecAccess ds 2 access attribute +DRecAuxType ds 4 auxType END @@ -646,6 +680,9 @@ pathptr equ files+4 space equ pathptr+4 end equ space+3 +; +; Allocate space on stack for direct page variables +; tsc sec sbc #space-1 @@ -686,8 +723,8 @@ end equ space+3 ; allocate memory for $path variable ; jsl alloc256 - sta pathparm+4 - stx pathparm+4+2 + sta pathvalue + stx pathvalue+2 phx pha phx @@ -700,8 +737,8 @@ end equ space+3 jsr p2cstr stx pathptr+2 sta pathptr - stx pathparm+6 ;for disposal only - sta pathparm+4 + stx pathvalue+2 ;for disposal only + sta pathvalue pla plx jsl free256 ;pushed earlier @@ -725,10 +762,16 @@ despace lda [pathptr],y if2 @a,eq,#'\',gotquote iny bra despace + +; Found "\" gotquote iny2 bra despace + +; Found null byte gotspace0 tyx bra gotspace3 + +; Found " ", tab, or creturn gotspace1 tyx short a lda #0 @@ -740,11 +783,15 @@ gotspace2 iny if2 @a,eq,#' ',gotspace2 if2 @a,eq,#009,gotspace2 if2 @a,eq,#013,gotspace2 + gotspace3 anop - clc - tya - adc pathptr + clc Bump pathptr by + tya the number of bytes + adc pathptr indicated in Y-reg. sta pathptr + lda pathptr+2 + adc #0 + sta pathptr+2 lda pathnum cmp #32*4 @@ -759,30 +806,35 @@ numok pei (ptr+2) jsr c2gsstr phx pha - sta EPParm+2 - stx EPParm+4 + sta EPinputPath + stx EPinputPath+2 ExpandPath EPParm bcc epok - ldx #^eperrstr - lda #eperrstr + ldx #^eperrstr Print error message: + lda #eperrstr "Invalid pathname syntax." jsr errputs jsl nullfree jmp next epok jsl nullfree - lda EPParm+6+2 - sta ptr+2 - lda EPParm+6 - inc2 a + clc Set ptr to GS/OS string + lda EPoutputPath portion of result buffer. + adc #2 sta ptr - lda [ptr] - sta len - inc2 a - tay + lda EPoutputPath+2 + adc #0 + sta ptr+2 + + lda [ptr] Get GS/OS string's length word + sta len and store in len. + + inc2 a Store 0 at end of text + tay in string. lda #0 sta [ptr],y + pea 0 phy jsl ~NEW @@ -824,7 +876,8 @@ go4it lda pathnum next jmp loop -done ph4 pathparm+4 + +done ph4 pathvalue jsl nullfree lda hash_print @@ -842,8 +895,8 @@ noprint ld2 1,hash_print sta hash_table stx hash_table+2 - lda EPParm+6 - ldx EPParm+6+2 + lda EPoutputPath + ldx EPoutputPath+2 jsl free256 pld @@ -854,16 +907,20 @@ noprint ld2 1,hash_print rtl -pathparm dc a4'pathvar' - ds 4 +; Parameter block for shell call Read_Variable +pathparm anop + dc a4'pathvar' Address of name +pathvalue ds 4 Address to store result + pathvar str 'path' hashmsg dc c'hashed ' hashnum dc c'000 files',h'0d00' -EPParm dc i'2' - ds 4 - ds 4 +; Parameter block for GS/OS call ExpandPath +EPParm dc i'2' pCount = 2 +EPinputPath ds 4 ptr to inputPath (GS/OS string) +EPoutputPath ds 4 ptr to outputPath (Result buffer) eperrstr dc c'rehash: Invalid pathname syntax.',h'0d00' toomanyerr dc c'rehash: Too many paths specified.',h'0d00' diff --git a/bin/gsh/history.asm b/bin/gsh/history.asm index e1867d7..3751182 100644 --- a/bin/gsh/history.asm +++ b/bin/gsh/history.asm @@ -6,7 +6,7 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: history.asm,v 1.2 1998/04/24 15:38:23 gdr-ftp Exp $ +* $Id: history.asm,v 1.3 1998/06/30 17:25:37 tribby Exp $ * ************************************************************************** * @@ -24,11 +24,32 @@ * [+0] NextHistory: pointer to historyRec * [+4] HistoryCmd: string of characters * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ +************************************************************************** +* +* Interfaces defined in this file: +* +* InsertHistory +* +* PrevHistory +* +* NextHistory +* +* SaveHistory +* +* ReadHistory +* +* InitHistory +* +* PrintHistory +* ************************************************************************** mcopy /obj/gno/bin/gsh/history.mac -dummy start ; ends up in .root +dummyhistory start ; ends up in .root end setcom 60 @@ -491,16 +512,16 @@ size ds 2 InitHistory START using HistoryData - ph4 #histName - jsl AppendHome - stx historyFN+2 - sta historyFN + ph4 #histName Create string + jsl AppendHome $HOME/history + stx historyFN+2 Store pointer to it + sta historyFN in historyFN rts END ;========================================================================= ; -; Print History +; Print History (this is the history command) ; ;========================================================================= @@ -552,7 +573,7 @@ ok jsr puts next dec num bra loop1 -done return +done return 2:#0 numbstr dc c'0000: ',h'00' num ds 2 diff --git a/bin/gsh/invoke.asm b/bin/gsh/invoke.asm index 582ee5a..136bfcf 100644 --- a/bin/gsh/invoke.asm +++ b/bin/gsh/invoke.asm @@ -1,26 +1,42 @@ -*********************************************************************** +************************************************************************* * * The GNO Shell Project * * Developed by: * Jawaid Bazyar * Tim Meekins -* Modified by Dave Tribby for GNO/ME 2.0.6 * -* $Id: invoke.asm,v 1.3 1998/05/11 19:18:43 tribby Exp $ +* $Id: invoke.asm,v 1.4 1998/06/30 17:25:40 tribby Exp $ * ************************************************************************** * * INVOKE.ASM * By Tim Meekins +* Modified by Dave Tribby for GNO 2.0.6 * * Command invocation routines. * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ +************************************************************************** +* +* Interfaces defined in this file: +* +* redirect subroutine (4:sfile,4:dfile,4:efile,2:app,2:eapp,2:pipein, +* 2:pipeout,2:pipein2,2:pipeout2) +* returns with carry set/clear to indicate failure/success +* +* invoke subroutine (2:argc,4:argv,4:sfile,4:dfile,4:efile,2:app, +* 2:eapp,2:bg,4:cmd,2:jobflag,2:pipein,2:pipeout, +* 2:pipein2,2:pipeout2,4:pipesem) +* return 2:val +* ************************************************************************** mcopy /obj/gno/bin/gsh/invoke.mac -dummy start ; ends up in .root +dummyinvoke start ; ends up in .root end setcom 60 @@ -87,8 +103,8 @@ end equ sfile+4 jsl nullfree plp bcc execa - ldx #^err1 - lda #err1 + ldx #^err1 Print error message: + lda #err1 'Error redirecting standard input.' jmp badbye ; ; standard output @@ -117,8 +133,8 @@ execa ora2 dfile,dfile+2,@a jsl nullfree plp bcc execb - ldx #^err2 - lda #err2 + ldx #^err2 Print error message: + lda #err2 'Error redirecting standard output.' jmp badbye ; ; standard error @@ -141,14 +157,17 @@ execb ora2 efile,efile+2,@a jsr c2pstr ld2 2,RedirectDev mv2 eapp,RedirectApp + +; Make shell call to recirect I/O Redirect RedirectParm + php ph4 RedirectFile jsl nullfree plp bcc execc - ldx #^err3 - lda #err3 + ldx #^err3 Print error message: + lda #err3 'Error redirecting standard error.' jmp badbye ; ; is input piped in? @@ -190,14 +209,17 @@ exit lda space adc #end-4 tcs - cpy #1 + cpy #1 Clear/set carry for success/failure. rtl +; Parameter block for shell call to redirect I/O (ORCA/M manual p.425) RedirectParm anop -RedirectDev ds 2 -RedirectApp ds 2 -RedirectFile ds 4 +RedirectDev ds 2 Dev num (0=stdin,1=stdout,2=errout) +RedirectApp ds 2 Append flag (0=delete) +RedirectFile ds 4 File name (GS/OS input string) + +; Parameter block for GS/OS call to close a file CloseParm dc i'1' CloseRef dc i'0' @@ -232,36 +254,37 @@ space equ dir+4 ld2 -1,val stz biflag ;not a built-in - lda argc - bne chknull + lda argc Get number of arguments. + bne chknull If != 0 continue with processing. - lda sfile - ora sfile+2 + lda sfile If any of the file pointers + ora sfile+2 are != NULL, ora dfile ora dfile+2 ora efile ora efile+2 beq nulldone - ldx #^hehstr - lda #hehstr + ldx #^hehstr print error message: + lda #hehstr ' specify a command before redirecting.' jsr errputs nulldone jmp done + ; ; Check for null command ; -chknull ldy #2 - lda [argv] - sta dir +chknull ldy #2 Move command line + lda [argv] pointer to + sta dir dir (4 bytes). lda [argv],y - sta dir+2 + sta dir+2 If pointer == NULL ora dir - beq gonull - lda [dir] + beq nulldone all done. + lda [dir] If first character == '\0', and #$FF - bne checkfile -gonull jmp done + beq nulldone all done. + ; ; check for file ; @@ -273,6 +296,8 @@ checkfile anop cmp #-1 jne trybuiltin +; Command is not listed in the built-in table + pei (dir+2) pei (dir) ph4 hash_table @@ -299,26 +324,36 @@ skip lock mutex2 unlock mutex2 jcs notfound +; File type $B5 is a GS/OS Shell application (EXE) if2 GRecFileType,eq,#$B5,doExec + +; File type $B3 is a GS/OS application (S16) if2 @a,eq,#$B3,doExec + ldx vardirexec bne ft02 cmp #$0F - jeq doDir + jeq doDir Target is a directory; change to it. + +; File type $B0 is a source code file (SRC) ft02 if2 @a,ne,#$B0,badfile +; Type $B0, Aux $00000006 is a shell command file (EXEC) if2 GRecAuxType,ne,#6,badfile if2 GRecAuxType+2,ne,#0,badfile jmp doShell + + badfile ldx dir+2 lda dir jsr errputs - ldx #^err1 - lda #err1 + ldx #^err1 Print error message: + lda #err1 'Not executable.' jsr errputs free pei (ptr+2) pei (ptr) jsl nullfree jmp done + ; ; launch an executable ; @@ -330,10 +365,11 @@ doExec pei (ptr+2) jsr postfork jmp done + invoke0 phk plb ; -; make a a copy of cmd +; make a copy of cmd ; pha pha @@ -367,7 +403,7 @@ invoke0 phk phx ;_cmd pha ; -; make a a copy of dir +; make a copy of dir ; pha pha @@ -403,9 +439,8 @@ invoke0 phk jsl infork bcs invoke1 -* Change for GNO 2.0.6: call _execve instead of execve case on - jsl _execve + jsl _execve For 2.0.6: call _execve, not execve case off rtl invoke1 pla @@ -413,8 +448,9 @@ invoke1 pla pla pla rtl + ; -; do path (it was a directory entry so change to that directory) +; Next command is a directory name, so change to that directory ; doDir lock cdmutex mv4 GRecPath,PRecPath @@ -422,8 +458,9 @@ doDir lock cdmutex unlock cdmutex stz val jmp free + ; -; fork a shell script +; Next command is a shell command file: fork a shell script ; doShell inc biflag ;don't free argv... jsr prefork @@ -455,12 +492,13 @@ exec0 ph2 _argc ;for argfree jsl infork bcs exec0c signal (#SIGCHLD,#0) - PushVariables 0 + PushVariablesGS NullPB pea 1 jsl ShellExec jsl argfree - PopVariables 0 + PopVariablesGS NullPB rtl + exec0c pla pla pla @@ -470,29 +508,49 @@ exec0c pla pla pla rtl -; -; file not found, so try a builtin. + +; Null parameter block used for shell calls PushVariables +; (ORCA/M manual p.420) and PopVariablesGS (p. 419) +NullPB dc i2'0' pCount + +* +* --------------------------------------------------------------- +* +* File name was found in the built-in table + +trybuiltin inc biflag It's a built-in. Which type? + cmp #1 Either fork or don't fork. + beq noforkbuiltin + +; +; It's a forked builtin ; -trybuiltin inc biflag ;it's a built-in - cmp #1 - beq noforkbuiltin jsr prefork fork #forkbuiltin jsr postfork jmp done +; +; Control transfers here for a forked built-in command +; +forkbuiltin cop $7F Give palloc a chance -forkbuiltin cop $7F ;give palloc a chance ph2 _argc ph4 _argv jsl infork bcs fork0c jsl builtin rtl + +; Error reported by infork; clean up stack and return to caller fork0c pla pla pla rtl + +; +; It's a non-forked builtin +; noforkbuiltin anop pei (argc) pei (argv+2) @@ -501,6 +559,11 @@ noforkbuiltin anop stz val bra done +* +* --------------------------------------------------------------- +* +* Command was not found as built-in or as a file + notfound pei (ptr+2) pei (ptr) jsl nullfree @@ -509,8 +572,8 @@ notfound pei (ptr+2) tax lda [argv] jsr errputs - ldx #^err2 - lda #err2 + ldx #^err2 Print error message: + lda #err2 'Command not found.' jsr errputs lda pipein beq notfound0 @@ -526,6 +589,7 @@ notfound pei (ptr+2) sigpause #0 notfound0 anop + done cop $7F lda biflag bne skipfrarg @@ -568,6 +632,7 @@ prefork lock mutex lda pipesem+1 sta putsem+2 rts + ; ; stuff to do right after forking ; @@ -583,11 +648,12 @@ postfork2 lda pipeout postfork3 lda val cmp #-1 bne postfork4 - ldx #^deadstr - lda #deadstr + ldx #^deadstr Print error message: + lda #deadstr 'Cannot fork (too many processes?)' jsr errputs unlock mutex jmp done + postfork4 ldx jobflag dex beq postfork5 @@ -605,6 +671,7 @@ postfork5 lda >mutex ;DANGER!!!!! Assumes knowledge of cop $7F bra postfork5 postfork6 rts + ; ; stuff to do in fork ; @@ -694,11 +761,14 @@ hehstr dc c'heh heh, next time you''ll need to specify a command ' dc c'before redirecting.',h'0d00' deadstr dc c'Cannot fork (too many processes?)',h'0d00' ;try a spoon -GRec dc i'4' -GRecPath ds 4 - ds 2 -GRecFileType ds 2 -GRecAuxType ds 4 + +; Parameter block for GS/OC call GetFileInfo +GRec dc i'4' pCount (# of parameters) +GRecPath ds 4 pathname (input; ptr to GS/OS string) + ds 2 access (access attributes) +GRecFileType ds 2 fileType (file type attribute) +GRecAuxType ds 4 auxType (auxiliary type attribute) + PRec dc i'2' PRecNum dc i'0' diff --git a/bin/gsh/jobs.asm b/bin/gsh/jobs.asm index 15aaa27..cead5c4 100644 --- a/bin/gsh/jobs.asm +++ b/bin/gsh/jobs.asm @@ -6,7 +6,7 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: jobs.asm,v 1.2 1998/04/24 15:38:27 gdr-ftp Exp $ +* $Id: jobs.asm,v 1.3 1998/06/30 17:25:43 tribby Exp $ * ************************************************************************** * @@ -15,11 +15,14 @@ * * Job control handling routines * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/jobs.mac -dummy start ; ends up in .root +dummyjobs start ; ends up in .root end setcom 60 @@ -909,7 +912,7 @@ next inc count beq loop bcc loop -done return +done return 2:#0 Usage dc c'Usage: jobs [-l]',h'0d00' @@ -1230,7 +1233,7 @@ nojob ldx #^err03 lda #err03 puterr jsr errputs -done return +done return 2:#0 usage dc c'Usage: fg [%job | pid]',h'0d00' err01 dc c'fg: No job to foreground.',h'0d00' @@ -1347,7 +1350,7 @@ nojob ldx #^err03 lda #err03 puterr jsr errputs -done return +done return 2:#0 usage dc c'Usage: bg [%job | pid]',h'0d00' err01 dc c'bg: No job to background.',h'0d00' @@ -1435,7 +1438,7 @@ nojob ldx #^err03 lda #err03 puterr jsr errputs -done return +done return 2:#0 usage dc c'Usage: stop [%job | pid]',h'0d00' err01 dc c'stop: No job to stop.',h'0d00' diff --git a/bin/gsh/main.asm b/bin/gsh/main.asm index 7560081..7e7eeef 100644 --- a/bin/gsh/main.asm +++ b/bin/gsh/main.asm @@ -6,11 +6,17 @@ * Jawaid Bazyar * Tim Meekins * +* $Id: main.asm,v 1.5 1998/07/20 16:23:08 tribby Exp $ +* ************************************************************************** * * MAIN.ASM * By Tim Meekins +* Modified by Dave Tribby for GNO 2.0.6 * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/main.mac @@ -24,23 +30,33 @@ stack data STACK ; ends up in main.root kind $12 -; Define direct-page/stack in 256-byte (1-page) chunks. -; Fill them with question marks so they can be examined for use. +; Define direct-page/stack and fill it with question marks it can be +; examined for how much is used. dc 128c'??' ; 256 bytes dc 128c'??' ; 512 bytes total dc 128c'????' ; 1024 bytes total - dc 128c'????' - dc 128c'????' ; 2048 bytes total + dc 128c'????????' ; 2048 bytes total end ************************************************************************** init START + +; Call the code to emulate C program startup: +; store Accumulator in ~USER_ID, X- and Y- registers as ~COMMANDLINE +; start up memory manager (~MM_INIT) +; parse commandline (via ~GNO_PARSEARG) and push argc and arvg on stack + jml ~GNO_COMMAND + +; Control continues with the entry point "MAIN". When MAIN returns to +; ~GNO_COMMAND via rtl, it frees argv and argc before doing its own rtl. + END + MAIN START using global @@ -61,23 +77,26 @@ ok stz FastFlag stz CmdFlag stz ExecFlag -argloop dec argc - jeq start +; Parse gsh's command-line arguments. + +argloop dec argc Decrement argument count. + beq go_start If none left, ready to start working. clc - lda argv - adc #4 + lda argv Point to next + adc #4 argument pointer. sta argv ldy #2 - lda [argv] - sta arg + lda [argv] Set arg to point to + sta arg the argument text. lda [argv],y sta arg+2 - lda [arg] - and #$FF - cmp #'-' - beq intoption + lda [arg] Get first character + and #$FF of argument. + cmp #'-' If it's a "-", + beq intoption handle as an option. -; parse remaining args as a command to run + +; Parse remaining args as a command to run (in ExecCmd) inc ExecFlag inc FastFlag @@ -89,7 +108,7 @@ argloop dec argc stx p+2 cmd3 ldy #0 -cmd0 lda [arg],y +cmd0 lda [arg],y and #$ff beq cmd1 sta [p],y @@ -115,7 +134,10 @@ cmd1 lda #' ' bra cmd3 cmd2 lda #0 sta [p] - bra start +go_start bra start + + +; Parse an argument as an option (first character is "-") intoption ldy #1 optloop lda [arg],y @@ -126,9 +148,12 @@ optloop lda [arg],y cmp #'c' beq parsec +; Option is not recognized. showusage ErrWriteCString #usage bra done + +; Option = "-f": Skip history, gshrc optf inc FastFlag nextopt iny @@ -138,6 +163,7 @@ nextarg cpy #1 beq showusage jmp argloop +; Option = "-c": execute shell commands found in file named by next argument parsec clc lda argv adc #4 @@ -149,6 +175,9 @@ parsec clc mv4 argv,CmdArgV mv2 argc,CmdArgC +; +; When preliminary setup is complete, control transfers to here! +; start case on jsl shell case off diff --git a/bin/gsh/orca.asm b/bin/gsh/orca.asm index 786a7be..ae4c8be 100644 --- a/bin/gsh/orca.asm +++ b/bin/gsh/orca.asm @@ -6,20 +6,24 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: orca.asm,v 1.2 1998/04/24 15:38:34 gdr-ftp Exp $ +* $Id: orca.asm,v 1.3 1998/06/30 17:25:48 tribby Exp $ * ************************************************************************** * * ORCA.ASM * By Tim Meekins +* Modified by Dave Tribby for GNO 2.0.6 * -* Builtin commands for Orca compiling/editing, etc. +* Builtin command for ORCA editor * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/orca.mac -dummy start ; ends up in .root +dummyorca start ; ends up in .root end setcom 60 @@ -29,7 +33,7 @@ dummy start ; ends up in .root * EDIT: builtin command * syntax: edit pathname... * -* Invokes an editor and edits a file or files. +* Invokes the ORCA editor and edits a file or files. * ************************************************************************** @@ -40,9 +44,9 @@ strPtr equ 0 inLoopPtr equ strPtr+4 argLoopPtr equ inLoopPtr+4 sLen equ argLoopPtr+4 -k equ sLen+2 -j equ k+2 -editcommand equ j+2 +pathLen equ sLen+2 +pnum equ pathLen+2 +editcommand equ pnum+2 retval equ editcommand+4 sFile equ retval+2 GSString255Ptr inPath equ sFile+4 @@ -51,22 +55,17 @@ space equ outPath+4 subroutine (4:argv,2:argc),space - stz retval - stz sLen - - lda #1 - sta j - - lda argc make sure there are two or - cmp #2 more parameters, otherwise we - bcs enoughparms - - ldx #^enofile - lda #enofile + lda argc Make sure there are two or + cmp #2 more parameters. + bcs enoughparms Otherwise, + ldx #^enofile report error: + lda #enofile no filename specified jsr errputs lda #1 - sta retval - jmp goaway + bra seterr + + +; Allocate memory for sFile, inPath, and outPath enoughparms anop jsl alloc1024 @@ -87,15 +86,23 @@ enoughparms anop ora outPath+2 bne noerr1 -memerr1 ldx #^enomem - lda #enomem +memerr1 ldx #^enomem Report error: + lda #enomem out of memory jsr errputs lda #-1 - sta retval +seterr sta retval jmp goaway +; Parameters were provided, and memory has been allocated. +; Ready to start processing the filename(s). noerr1 anop - lda sFile + stz retval Zero return status + stz sLen and length of source names. + + lda #1 Initialize parameter + sta pnum number to 1. + + lda sFile strPtr = sFile + 2 clc adc #2 sta strPtr @@ -103,89 +110,85 @@ noerr1 anop adc #0 sta strPtr+2 -doloop lda j - cmp #2 - bcc nodelimit - short m - lda #10 ; newline - sta [strPtr] + bra nodelimit Skip delimiter for 1st file. + +; Loop for getting name, converting it to a full path, and +; appending it to sFile + +doloop short m Between parameters: + lda #10 Store newline as delimiter + sta [strPtr] character in strPtr. long m - inc sLen - inc strPtr + inc sLen Bump string length + inc strPtr and pointer. bne nodelimit inc strPtr+2 nodelimit anop - lda j - asl a ; get the proper argv pointer - asl a - tay - lda [argv],y - sta argLoopPtr - iny2 + lda pnum Get parameter number + asl a and turn it into an + asl a index to the proper + tay argv pointer. + lda [argv],y Store address in + sta argLoopPtr direct page variable + iny2 argLoopPtr. lda [argv],y sta argLoopPtr+2 - lda inPath get text field of inPath - clc + lda inPath Get address of text field + clc in inPath. adc #2 sta inLoopPtr lda inPath+2 adc #0 sta inLoopPtr+2 - stz k +; Move argument into inPath, counting characters -whileloop lda [argLoopPtr] - and #$00FF - beq donewhile + ldy #0 - short m - sta [inLoopPtr] - long m - inc argLoopPtr - bne noinc2 - inc argLoopPtr+2 -noinc2 inc inLoopPtr - bne noinc3 - inc inLoopPtr+2 -noinc3 inc k - lda k - cmp #255 - bcc whileloop - ldx #^einval - lda #einval +whileloop lda [argLoopPtr],y Get next character of name. + and #$00FF If it's the terminating null, + beq donewhile done copying. + + sta [inLoopPtr],y Store character (and null byte) + iny + cpy #255 If < 255, + bcc whileloop stay in loop. + + ldx #^einval Print error: + lda #einval invalid argument (filename too long) jsr errputs lda #2 - sta retval - jmp goaway -donewhile lda k + bra seterr + +donewhile tya Set length of GS/OS string inPath. sta [inPath] - lda #1024 + lda #1024 Set max len of result buffer outPath. sta [outPath] + +; Set up GS/OS ExpandPath parameter buffer and make call. + mv4 inPath,ep_inputPath mv4 outPath,ep_outputPath + ExpandPath ep Expand the pathname. - ExpandPath ep - bcc noeperror - ldx #^err3 - lda #err3 - jsr errputs - lda #-1 - sta retval - jmp goaway +; Note: The GS/OS reference says ExpandPath can detect invalid pathname +; syntax error, but I can't get this to happen (even with names like +; "::/^" and " "). Ignore errors and let the editor report them. -noeperror anop - ldy #2 + ldy #2 Get length of result string lda [outPath],y - sta k + sta pathLen and store in pathLen. clc - adc sLen - cmp #MAXPARMBUF - bcs doloopend + adc sLen If accumulated length is + cmp #MAXPARMBUF beyond the maximum, + bcs doloopend don't add this name. - pei (k) - pei (outPath+2) + sta sLen Store accumulated length in sLen. + + pei (pathLen) Append outPath string + pei (outPath+2) to the end of sFile's text. lda outPath clc adc #4 @@ -194,51 +197,56 @@ noeperror anop pei (strPtr) jsl rmemcpy - lda sLen + lda strPtr Add pathLen to strPtr. clc - adc k - sta sLen - lda strPtr - clc - adc k + adc pathLen sta strPtr lda strPtr+2 adc #0 sta strPtr+2 -doloopend inc j - lda j + +doloopend inc pnum pnum++ + lda pnum if pnum < argc, cmp argc - jcc doloop + jcc doloop continue processing filenames. + +; All of the arguments have been processed. + + lda sLen Save length in + sta [sFile] GS/OS buffer. + +; Set up shell SetLInfo parameter buffer and make call. - lda sLen - sta [sFile] mv4 sFile,gl_sFile + SetLInfoGS gl Set the edit environment. - Set_LInfoGS gl ;now set up the environment - - ph4 #editorvar - jsl getenv + ph4 #editorvar Get value of environment + jsl getenv variable "editor". sta editcommand stx editcommand+2 ora editcommand+2 - bne goteditvar - - ph4 #defedit - jsr p2cstr - sta editcommand - stx editcommand+2 + bne goteditvar If $editor is not defined, + ph4 #defedit use default value. + bra execit goteditvar anop pei (editcommand+2) pei (editcommand) - ph2 #0 ;tells execute we're called by system +execit ph2 #0 ;tells execute we're called by system jsl execute sta retval - pei (editcommand+2) + lda editcommand If getenv allocated it, + ora editcommand+2 + beq goaway + + pei (editcommand+2) free the "editcommand" string. pei (editcommand) jsl nullfree + +; See which GS/OS buffers need to be deallocated + goaway lda sFile ora sFile+2 beq donedealloc @@ -260,33 +268,39 @@ goaway lda sFile lda outPath jsl free1024 + +; Return to caller with status set to value in retval + donedealloc return 2:retval -ep dc i2'2' -ep_inputPath dc i4'0' -ep_outputPath dc i4'0' +; Parameter block for GS/OS ExpandPath call (p. 140 in GS/OS Reference) +ep dc i2'2' pCount +ep_inputPath dc i4'0' input pointer (GS/OS string) +ep_outputPath dc i4'0' output pointer (GS/OS result buf) + +; Error messages enofile dc c'edit: no filename specified',h'0D00' enomem dc c'edit: out of memory',h'0D00' einval dc c'edit: invalid argument (filename too long)',h'0D00' -err3 dc c'edit: invalid path name',h'0d00' +; Parameter block for shell SetLInfo call (p. 433 in ORCA/M book) gl anop - dc i2'11' -gl_sfile dc i4'0' - dc i4'nullparm' - dc i4'nullparm' - dc i4'nullparm' - dc i1'8' - dc i1'0' - dc i1'0' - dc i1'0' - dc i4'0' - dc i4'$8000000' - dc i4'0' + dc i2'11' pCount +gl_sfile dc i4'0' source file name (GS/OS string) + dc i4'nullparm' output file name (compile/link) + dc i4'nullparm' names in NAMES parameter list (compile) + dc i4'nullparm' compiler commands (compiler) + dc i1'0' max err level allowed (compile/link) + dc i1'0' max err level found (compile/link) + dc i1'0' operations flags (compile/link) + dc i1'0' keep flag (compile) + dc i4'0' minus flags (see ASML) + dc i4'$08000000' plus flags [+E] (see ASML) + dc i4'0' origin (link) nullparm dc i2'0' -editorvar dc c'editor',h'00' -defedit str '4:editor' +editorvar dc c'editor',h'00' Name of editor environment variable +defedit dc c'4:editor',h'00' Default value for editor END diff --git a/bin/gsh/prompt.asm b/bin/gsh/prompt.asm index ab3abd8..c38d7d4 100644 --- a/bin/gsh/prompt.asm +++ b/bin/gsh/prompt.asm @@ -6,20 +6,24 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: prompt.asm,v 1.2 1998/04/24 15:38:35 gdr-ftp Exp $ +* $Id: prompt.asm,v 1.3 1998/06/30 17:25:50 tribby Exp $ * ************************************************************************** * * PROMPT.ASM * By Tim Meekins +* Modified by Dave Tribby for GNO 2.0.6 * * This displays the command-line prompt * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/prompt.mac -dummy start ; ends up in .root +dummyprompt start ; ends up in .root end setcom 60 diff --git a/bin/gsh/shell.asm b/bin/gsh/shell.asm index 7372f0e..0c9a04e 100644 --- a/bin/gsh/shell.asm +++ b/bin/gsh/shell.asm @@ -6,20 +6,40 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: shell.asm,v 1.2 1998/04/24 15:38:37 gdr-ftp Exp $ +* $Id: shell.asm,v 1.3 1998/06/30 17:25:52 tribby Exp $ * ************************************************************************** * * SHELL.ASM * By Tim Meekins +* Modified by Dave Tribby for GNO 2.0.6 * * This is the main routines for the shell. * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ +************************************************************************** +* +* Interfaces defined in this file: +* +* shell subroutine (0:dummy) +* NOTE: gnoloop is an entry defined in shell. +* +* AppendHome subroutine (4:str) +* return 4:outPtr +* +* DoLogin jsr with no parameters +* +* signal2 subroutine (4:fubar) +* +* signal18 subroutine (4:fubar) +* ************************************************************************** mcopy /obj/gno/bin/gsh/shell.mac -dummy start ; ends up in .root +dummyshell start ; ends up in .root end setcom 60 @@ -30,6 +50,11 @@ SIGCHLD gequ 20 cmdbuflen gequ 1024 +************************************************************************** +* +* shell: entry point for acting upon commands +* +************************************************************************** case on shell start case off @@ -44,19 +69,21 @@ space equ p+4 subroutine (0:dummy),space - tsc - sta cmdcontext - tdc - sta cmddp + tsc Save stack pointer + sta cmdcontext in cmdcontext + tdc and direct page reg + sta cmddp ind cmddp. * PushVariables 0 - Open ttyopen - bcc settty + Open ttyopen Open tty, + bcc settty checking for error. ErrWriteCString #ttyerr jmp quit + ttyerr dc c'gsh: Failed opening tty.',h'0d00' + settty mv2 ttyref,gshtty tcnewpgrp gshtty settpgrp gshtty @@ -65,8 +92,8 @@ settty mv2 ttyref,gshtty jsr InitTerm - lda FastFlag - bne fastskip1 + lda FastFlag If FastFlag is set, + bne fastskip1 skip copyright message. lda gshpid ; only print the copyright msg cmp #2 ; if not using login bne fastskip1 @@ -75,32 +102,44 @@ settty mv2 ttyref,gshtty jsr puts fastskip1 anop +; +; Set up signal handlers +; signal (#SIGINT,#signal2) signal (#SIGTSTP,#signal18) signal (#SIGCHLD,#pchild) +; +; Set entry point for users calling system +; setsystemvector #system + ; ; Initialize some stuff ; - lda FastFlag + jsr initalias Set all AliasTable entries to 0. + jsr InitDStack Zero out directory stack. + jsr InitVars Set value of all env var flags. + lda FastFlag If fast startup flag isn't set, bne fastskip2 - jsr InitHistory - jsr ReadHistory ;Read in history from disk -fastskip2 jsr initalias ;initialize alias - jsr InitDStack ;initialize directory stack - lda FastFlag - bne fastskip3 - jsr DoLogin ;Read gshrc + jsr InitHistory Init: historyFN->"$HOME/history", + jsr ReadHistory read in history from disk, + jsr DoLogin and read $HOME/gshrc. jsr newline -fastskip3 anop +fastskip2 anop lda didReadTerm bne didit jsr readterm didit jsl hashpath ;hash $path +; +; Check for command-line arguments -c and -e +; lda CmdFlag beq cmdskip +; +; The -c flag is set: execute remaining arguments as a command file and exit. +; mv4 CmdArgV,p ldy #2 lda [p],y @@ -117,6 +156,9 @@ didit jsl hashpath ;hash $path cmdskip lda ExecFlag beq execskip +; +; The -e flag is set: execute remaining arguments as a command and exit. +; ph4 ExecCmd ph2 #0 jsl Execute @@ -124,35 +166,47 @@ cmdskip lda ExecFlag execskip anop +**************************************************************** +* +* Main loop for reading and executing commands +* +**************************************************************** + stz lastabort gnoloop entry - phk - plb +; +; Set the fundamental registers. +; + phk Copy Program Bank register + plb into Data Bank register. + lda cmdcontext Set Stack Pointer and + tcs Direct Page register + lda cmddp to values saved when + tcd entering shell. - lda cmdcontext ;dare you to make a mistake - tcs - lda cmddp - tcd - - jsl WritePrompt - jsr GetCmdLine + jsl WritePrompt Print prompt. + jsr GetCmdLine Get response. bcs done jsr newline - lda cmdlen + + lda cmdlen Check for empty string. beq gnoloop - jsr cursoron + jsr cursoron jsr newlineX jsr flush + ph4 #cmdline ph2 #0 jsl execute + lda exitamundo bne done1 jsr newlineX stz lastabort bra gnoloop + ; ; shut down gsh ; @@ -164,22 +218,28 @@ done1 ora2 pjoblist,pjoblist+2,@a bne donekiller inc lastabort stz exitamundo - ldx #^stopstr - lda #stopstr + ldx #^stopstr Print message: + lda #stopstr "There are stopped jobs" jsr puts jsr newlineX - bra gnoloop + bra gnoloop Continue getting commands. + donekiller jsl jobkiller done2 lda FastFlag bne fastskip5 jsr SaveHistory fastskip5 jsr dispose_hash -quit PopVariables 0 +quit PopVariablesGS NullPB Quit QuitParm + QuitParm dc i'0' -gnostr dc h'0d',c'GNO/Shell 2.0.4',h'0d' +; Null parameter block used for shell calls PushVariables +; (ORCA/M manual p.420) and PopVariablesGS (p. 419) +NullPB dc i2'0' pCount + +gnostr dc h'0d',c'GNO/Shell 2.0.6',h'0d' dc c'Copyright 1991-1993, Procyon, Inc. & Tim Meekins. ' dc c'ALL RIGHTS RESERVED',h'0d' dc h'0d00' @@ -205,40 +265,69 @@ lastabort ds 2 ; ;========================================================================= +DoLogin START -* Appends a C string to the value of the $HOME variable. If $HOME is + ph4 #gshrcName + jsl AppendHome + phx Save pointer to GS/OS input + pha string for later. + + clc Adjust the pointer + adc #2 to skip the length word + bcc no_ovf so it's a C string. + inx +no_ovf phx + pha + +* ShellExec subroutine (4:path,2:argc,4:argv,2:jobflag) +; (ptr to $HOME/gshrc is on stack) + lda #0 + pha argc = 0 + pha argv = NULL + pha + pha jobflag = 0 + jsl ShellExec + +; Dispose $HOME/gshrc string + pla Get address of + plx GS/OS input string. + sec Subtract two bytes to get + sbc #2 addr of original output buffer. + bcs no_undf + dex +no_undf jsl free256 + rts + +gshrcName dc c'/gshrc',h'00' + + END + + +* Append a C string to the value of the $HOME variable. If $HOME is * not set, then it appends the C string to the string '@/'. Returns -* a pointer to a GC string. Call DisposeHome/AX to deallocate the -* string. - -DisposeHome START - dec a - dec a - jsl free256 - rtl - END +* a pointer to a GC string. AppendHome START outPtr equ 0 len equ 4 subroutine (4:str),6 - jsl alloc256 - stx outPtr1+2 - sta outPtr1 - stx outPtr+2 - sta outPtr + jsl alloc256 Allocate memory for + stx outPtr1+2 GS/OS output buffer + sta outPtr1 that will hold the + stx outPtr+2 value of $HOME and + sta outPtr the final result. - pei (str+2) + pei (str+2) pei (str) jsr cstrlen sta len - lda #256 - sta [outPtr] + lda #255 Max len is 255 (leave room + sta [outPtr] for C string terminator). - GSOS $014B,rvbl ;ReadVariable - bcs doAtSign + ReadVariableGS rvbl ReadVariable $HOME + bcs doAtSign If error, use @/ ldy #2 lda [outPtr],y @@ -252,6 +341,9 @@ len equ 4 long m bra doAppend +; +; $HOME is null string or not defined. Use @ +; doAtSign lda atSign ldy #4 sta [outPtr],y @@ -270,9 +362,10 @@ lp lda [outPtr],y beq foundSep iny bra lp -noSep lda #':' -foundSep sta [str] +noSep lda #':' No separator found; use ":". + +foundSep sta [str] Store separator at end of string. long m pei (str+2) @@ -286,50 +379,33 @@ foundSep sta [str] jsl strcat case off - inc outPtr - inc outPtr - lda [outPtr] + clc Add 2 bytes to address of + lda outPtr GS/OS output buffer to + adc #2 get address if GS/OS + bcc no_ovf input string. + inc outPtr+2 clc - adc len - sta [outPtr] ; adjust GS/OS string length +no_ovf sta outPtr + + lda [outPtr] Adjust string length + clc to include appended + adc len string (parameter). + sta [outPtr] + return 4:outPtr atSign dc c'@',i1'0' -rvbl dc i2'3' - dc a4'in' -outPtr1 dc a4'0' - dc i2'0' ; value of 'Export' flag + +; Parameter block for Shell call ReadVariable (p 423 in ORCA/M reference) +rvbl dc i2'3' pCount + dc a4'in' address of variable's name +outPtr1 dc a4'0' pointer to result buffer + dc i2'0' value of 'Export' flag (returned) in dosin 'HOME' END -DoLogin START - - ph4 #gshrcName - jsl AppendHome - phx ; saved pointer for later - pha - phx - inc a - inc a ; adjust to the C string - pha - - lda #0 - pha - pha - pha - pea 0 - jsl shellexec - - pla - plx - jsl DisposeHome - rts - -gshrcName dc c'/gshrc',h'00' - - END ;========================================================================= ; diff --git a/bin/gsh/shellutil.asm b/bin/gsh/shellutil.asm index 0030767..09b22f8 100644 --- a/bin/gsh/shellutil.asm +++ b/bin/gsh/shellutil.asm @@ -6,7 +6,7 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: shellutil.asm,v 1.2 1998/04/24 15:38:39 gdr-ftp Exp $ +* $Id: shellutil.asm,v 1.3 1998/06/30 17:25:55 tribby Exp $ * ************************************************************************** * @@ -15,11 +15,14 @@ * * Utility functions used by the shell. Mainly string functions. * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/shellutil.mac -dummy start ; ends up in .root +dummyshellutil start ; ends up in .root end setcom 60 @@ -397,6 +400,66 @@ done rep #$21 END +;========================================================================= +; +; Compare two downshifted c strings. Return 0 if ==, -1 if <, +1 > +; +;========================================================================= + +cmpdcstr START + +hold equ 1 +space equ hold+2 +q equ space+2 +p equ q+4 +end equ p+4 + + tsc + sec + sbc #space-1 + tcs + phd + tcd + + ldx #0 + + ldy #0 +strloop lda [q],y + and #$FF + jsr tolower + sta hold + lda [p],y + and #$FF + beq strchk + jsr tolower + cmp hold + bne notequal + iny + bra strloop + +strchk lda hold + beq done + +lessthan dex + bra done + +notequal bcc lessthan + inx + +done anop + lda space + sta end-2 + pld + tsc + clc + adc #end-3 + tcs + + txa + rts + + END + ;========================================================================= ; ; Convert a c string to a GS/OS string (don't forget to dispose when done) @@ -529,6 +592,12 @@ done ldx new+2 nullfree START + lda 6,s + and #$FF80 + beq notbad + brk $db +notbad anop + lda 4,s ora 6,s bne ok diff --git a/bin/gsh/shellvar.asm b/bin/gsh/shellvar.asm index cd80663..601da89 100644 --- a/bin/gsh/shellvar.asm +++ b/bin/gsh/shellvar.asm @@ -7,20 +7,24 @@ * Tim Meekins * Derek Taubert * -* $Id: shellvar.asm,v 1.2 1998/04/24 15:38:41 gdr-ftp Exp $ +* $Id: shellvar.asm,v 1.3 1998/06/30 17:25:57 tribby Exp $ * ************************************************************************** * * SHELLVAR.ASM * By Tim Meekins +* Modified by Dave Tribby for GNO 2.0.6 * * Routines for handling variables in the shell * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/shellvar.mac -dummy start ; ends up in .root +dummyshellvar start ; ends up in .root end setcom 60 @@ -94,29 +98,24 @@ showvars anop ldx varbuf+2 lda varbuf jsl free256 -svwhoops ld2 $201,Err - Error Err +svwhoops ld2 $201,ErrError + ErrorGS Err jmp exit startshow lda #254 sta [valbuf] - sta [varbuf] - lda setmutex - beq wait0 - cop $7F - bra startshow -wait0 inc setmutex - mv4 varbuf,idxParm+2 - mv4 valbuf,idxParm+6 - ld2 1,idxParm+10 -showloop GSOS $0148,idxParm ;ReadIndexed 2.0 + lock setmutex + mv4 varbuf,idxName + mv4 valbuf,idxValue + ld2 1,idxIndex +showloop ReadIndexedGS idxParm ldy #2 lda [varbuf],y and #$FF beq showdone xba sta [varbuf],y - ldy idxParm+12 + ldy idxExport beq noexp xba tax @@ -152,10 +151,10 @@ noexp ldx varbuf+2 adc #3 jsr putp jsr newline - inc idxParm+10 + inc idxIndex bra showloop -showdone dec setmutex +showdone unlock setmutex ldx varbuf+2 lda varbuf jsl free256 @@ -166,11 +165,7 @@ showdone dec setmutex ; ; set variables ; -setvar lda setmutex - beq wait1 - cop $7F - bra setvar -wait1 inc setmutex +setvar lock setmutex lda argc jeq doneset ldy #2 @@ -292,12 +287,12 @@ unix0 short a jsl updatevars jsl nullfree -nextvar dec setmutex +nextvar unlock setmutex skipvar add2 argv,#4,argv dec argc jmp setvar -doneset dec setmutex +doneset unlock setmutex exit lda space sta end-3 @@ -316,24 +311,29 @@ varParm ds 4 ds 4 ds 2 -idxParm dc i2'4' - ds 4 - ds 4 - ds 2 - ds 2 +; Parameter block for shell Read_Indexed call (p 421 in ORCA/M manual) +idxParm anop + dc i2'4' pCount +idxName ds 4 Name (pointer to GS/OS result buf) +idxValue ds 4 Value (pointer to GS/OS result buf) +idxIndex ds 2 Index number +idxExport ds 2 Export flag -setmutex dc i'0' + +setmutex key showeq dc c' = ',h'00' Usage dc c'Usage:',h'0d' - dc c' set - displays all variables',h'0d' - dc c' set ... [var] - displays the value of var',h'0d' - dc c' set [var value]... - sets var to value',h'0d' - dc c' set [var=value]... - sets var to value',h'0d' - dc h'00' + dc c' set - displays all variables',h'0d' + dc c' set ... [var] - displays the value of var',h'0d' + dc c' set [var value]... - sets var to value',h'0d' + dc c' set [var=value]... - sets var to value',h'0d' + dc h'00' error1 dc c'set: Variable not specified',h'0d00' error2 dc c'set: Variable not defined',h'0d00' -Err ds 2 +; Parameter block for shell ErrorGS call (p 393 in ORCA/M manual) +Err dc i2'1' pCount +ErrError ds 2 Error number END @@ -406,19 +406,15 @@ showvars anop ldx varbuf+2 lda varbuf jsl free256 -svwhoops ld2 $201,Err - Error Err +svwhoops ld2 $201,ErrError + ErrorGS Err jmp exit -startshow lda setmutex - beq wait0 - cop $7F - bra startshow -wait0 inc setmutex +startshow lock setmutex mv4 varbuf,varParm+0 mv4 valbuf,varParm+4 ld2 1,varParm+8 - PushVariables 0 + PushVariablesGS NullPB showloop Read_Indexed varParm lda [varbuf] and #$FF @@ -451,8 +447,8 @@ upperfoo iny inc varParm+8 bra showloop -showdone PopVariables 0 - dec setmutex +showdone PopVariablesGS NullPB + unlock setmutex ldx varbuf+2 lda varbuf jsl free256 @@ -463,11 +459,7 @@ showdone PopVariables 0 ; ; set variables ; -setvar lda setmutex - beq wait1 - cop $7F - bra setvar -wait1 inc setmutex +setvar lock setmutex lda argc jeq doneset ldy #2 @@ -532,9 +524,9 @@ showonevar jsl alloc256 pha sta varParm stx varParm+2 - PushVariables 0 + PushVariablesGS NullPB Read_Variable varParm - PopVariables 0 + PopVariablesGS NullPB lda [valbuf] and #$FF beq notthere @@ -580,7 +572,7 @@ unix0 short a pha sta varParm+4 stx varParm+4+2 - pei (arg+2) + pei (arg+2) pei (arg) pea 1 pei (arg+2) @@ -598,12 +590,12 @@ unix0 short a jsl updatevars jsl nullfree -nextvar dec setmutex +nextvar unlock setmutex skipvar add2 argv,#4,argv dec argc jmp setvar -doneset dec setmutex +doneset unlock setmutex exit lda space sta end-3 @@ -625,18 +617,24 @@ varParm ds 4 exportparm ds 4 dc i'1' -setmutex dc i'0' +setmutex key showeq dc c' = ',h'00' Usage dc c'Usage:',h'0d' - dc c' setenv - displays all variables',h'0d' - dc c' setenv ... [var] - displays the value of var',h'0d' - dc c' setenv [var value]... - sets var to value',h'0d' - dc c' setenv [var=value]... - sets var to value',h'0d' - dc h'00' + dc c' setenv - displays all variables',h'0d' + dc c' setenv ... [var] - displays the value of var',h'0d' + dc c' setenv [var value]... - sets var to value',h'0d' + dc c' setenv [var=value]... - sets var to value',h'0d' + dc h'00' error1 dc c'setenv: Variable not specified',h'0d00' error2 dc c'setenv: Variable not defined',h'0d00' -Err ds 2 +; Parameter block for shell ErrorGS call (p 393 in ORCA/M manual) +Err dc i2'1' pCount +ErrError ds 2 Error number + +; Null parameter block used for shell calls PushVariables +; (ORCA/M manual p.420) and PopVariablesGS (p. 419) +NullPB dc i2'0' pCount END @@ -674,11 +672,7 @@ loop add2 argv,#4,argv dec argc beq done -wait lda expmutex - beq wait0 - cop $7F - bra wait -wait0 inc expmutex +wait lock expmutex ldy #2 lda [argv],y @@ -693,7 +687,7 @@ wait0 inc expmutex Export exportparm jsl nullfree - dec expmutex + unlock expmutex bra loop @@ -711,7 +705,7 @@ done lda space rtl -expmutex dc i'0' +expmutex key exportparm ds 4 dc i'1' @@ -755,11 +749,7 @@ loop add2 argv,#4,argv dec argc beq done -wait lda unsmutex - beq wait0 - cop $7F - bra wait -wait0 inc unsmutex + lock unsmutex ldy #2 lda [argv],y @@ -779,7 +769,7 @@ wait0 inc unsmutex jsl nullfree jsl updatevars - dec unsmutex + unlock unsmutex bra loop @@ -797,7 +787,7 @@ done lda space rtl -unsmutex dc i'0' +unsmutex key unsetparm ds 4 @@ -809,8 +799,6 @@ Usage dc c'Usage: unset var ...',h'0d00' ; ; update shell variable flags ; -; CHANGE TO JUST DO A READVARIABLES ON THE PASSED VAR -; ;==================================================================== updatevars START @@ -824,7 +812,7 @@ space equ 0 pei (var+2) pei (var) ph4 #varechoname - jsr cmpcstr + jsr cmpdcstr bne up2 lda flag sta varecho @@ -833,7 +821,7 @@ space equ 0 up2 pei (var+2) pei (var) ph4 #direxecname - jsr cmpcstr + jsr cmpdcstr bne up3 lda flag sta vardirexec @@ -842,7 +830,7 @@ up2 pei (var+2) up3 pei (var+2) pei (var) ph4 #newlinename - jsr cmpcstr + jsr cmpdcstr bne up4 lda flag sta varnewline @@ -851,7 +839,7 @@ up3 pei (var+2) up4 pei (var+2) pei (var) ph4 #noglobname - jsr cmpcstr + jsr cmpdcstr bne up5 lda flag sta varnoglob @@ -860,7 +848,7 @@ up4 pei (var+2) up5 pei (var+2) pei (var) ph4 #nobeepname - jsr cmpcstr + jsr cmpdcstr bne up6 lda flag sta varnobeep @@ -869,7 +857,7 @@ up5 pei (var+2) up6 pei (var+2) pei (var) ph4 #pushdsilname - jsr cmpcstr + jsr cmpdcstr bne up7 lda flag sta varpushdsil @@ -878,7 +866,7 @@ up6 pei (var+2) up7 pei (var+2) pei (var) ph4 #termname - jsr cmpcstr + jsr cmpdcstr bne up8 jsr readterm jmp done @@ -886,7 +874,7 @@ up7 pei (var+2) up8 pei (var+2) pei (var) ph4 #ignorename - jsr cmpcstr + jsr cmpdcstr bne up9 lda flag sta varignore @@ -898,6 +886,83 @@ done return END +;==================================================================== +; +; Update all shell variable flags from environment +; +;==================================================================== + +InitVars START + + using vardata + + lock gvmutex Mutual exclusion lock. + + ldx #0 Use X-reg to index value table. +loop phx Hold onto value table index. + txa + asl a Double the value array index + tax to get addr table index. + lda evstrtbl,x Store address of variable name + sta RVname in ReadVariableGS parameter block. + lda evstrtbl+2,x + sta RVname+2 + stz RVexpflag Clear export flag. + + ReadVariableGS ReadVar Read the value of the named variable. + + plx Restore value table index. + lda RBlen If variable length != 0 + bne set it is set. + lda RVexpflag It could be exported with len = 0. +set sta evvaltbl,x Save flag in variable. + inx2 Bump index. + cpx evvaltblsz If not at end, + bcc loop stay in loop. + + unlock gvmutex Mutual exclusion unlock. + + rts + +gvmutex key Key for mutual exclusion. + +; Parameter block for shell ReadVariableGS call (p 423 in ORCA/M manual) +ReadVar anop + dc i2'3' pCount +RVname ds 4 Pointer to name +RVresult dc a4'ResultBuf' GS/OS Output buffer ptr +RVexpflag ds 2 export flag + +; GS/OS result buffer for testing whether a variable is defined. +; It doesn't have enough room for > 1 byte to be returned, but we +; only need to get the length of the value. +ResultBuf dc i2'5' Only five bytes total. +RBlen ds 2 Value's length returned here. + ds 1 Only 1 byte for value. + +; GS/OS strings +echostr gsstr 'echo' +nodirexecstr gsstr 'nodirexec' +nonewlinestr gsstr 'nonewline' +noglobstr gsstr 'noglob' +nobeepstr gsstr 'nobeep' +pushdsilentstr gsstr 'pushdsilent' +termstr gsstr 'term' +ignoreofstr gsstr 'ignoreeof' + +; Table of GS/OS string addresses +evstrtbl anop + dc a4'echostr' + dc a4'nodirexecstr' + dc a4'nonewlinestr' + dc a4'noglobstr' + dc a4'nobeepstr' + dc a4'pushdsilentstr' + dc a4'termstr' + dc a4'ignoreofstr' + + END + ;=================================================================== ; ; variable settings @@ -915,12 +980,16 @@ pushdsilname dc c'pushdsilent',h'00' termname dc c'term',h'00' ignorename dc c'ignoreeof',h'00' -varecho dc i'0' -vardirexec dc i'0' -varnewline dc i'0' -varnoglob dc i'0' -varnobeep dc i'0' -varpushdsil dc i'0' -varignore dc i'0' +; Table of flag values (must be in same order as string addresses) +evvaltbl anop +varecho dc i2'0' +vardirexec dc i2'0' +varnewline dc i2'0' +varnoglob dc i2'0' +varnobeep dc i2'0' +varpushdsil dc i2'0' +varignore dc i2'0' + +evvaltblsz dc i2'evvaltblsz-evvaltbl' # bytes in table END diff --git a/bin/gsh/stdio.asm b/bin/gsh/stdio.asm index fc60bd2..38b08fc 100644 --- a/bin/gsh/stdio.asm +++ b/bin/gsh/stdio.asm @@ -6,7 +6,7 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: stdio.asm,v 1.2 1998/04/24 15:38:43 gdr-ftp Exp $ +* $Id: stdio.asm,v 1.3 1998/06/30 17:26:00 tribby Exp $ * ************************************************************************** * @@ -19,11 +19,14 @@ * stderr buffer size: 256 bytes * stdin buffer size: 128 bytes * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/stdio.mac -dummy start ; ends up in .root +dummystdio start ; ends up in .root end setcom 60 @@ -39,23 +42,24 @@ putchar START using stdout - tay ;lock destroys Acc - lock mutex - tya - and #$FF - ldx index - sta stream,x ;we're still in long mode, note extra - inx ; length of stream by one :) - cmp #13 - beq _flush - cpx #512 - bcc done -_flush stx index - Write WriteParm - ldx #0 -done stx index - unlock mutex - rts + tay Note: lock destroys Acc + lock mutex Wait for others to leave, and lock. + tya + and #$FF Isolate the single character. + ldx index Get num of chars already in stream. + sta stream,x Store this char + null byte. + inx Bump length of stream by one. + cmp #13 If character was newline, + beq _flush go write the stream. + cpx #512 If length < 512, + bcc done all done. +_flush stx index Save current length. + Write WriteParm Write the stream. + ldx #0 Set new length to 0. + +done stx index Save stream length in global. + unlock mutex Allow others through. + rts Return to caller. END @@ -70,44 +74,46 @@ puts START using stdout - tay ;lock destroys Acc - lock mutex - sty getchar+1 + tay Note: lock destroys Acc + lock mutex Wait for others to leave, and lock. + sty getchar+1 Save low-order bytes of address. txa - short a - sta getchar+3 - ora getchar+2 - ora getchar+1 - beq exit + short a SWITCH TO SINGLE-BYTE MEMORY MODE. + sta getchar+3 Store high-order byte of address. + ora getchar+2 If string address + ora getchar+1 is 00/0000, + beq exit don't do the write. - ldy index - ldx #0 + ldy index Get current number of chars in stream. + ldx #0 Clear source string offset. -getchar lda >$FFFFFF,x - beq done - sta stream,y - iny - inx - cmp #13 - beq _flush - cpy #512 - bcc getchar +getchar lda >$FFFFFF,x Get next character from string. + beq done Done when we see a null byte. + sta stream,y Store in output stream. + iny Bump the stream and + inx string pointers. + cmp #13 If newline was encountered, + beq _flush go write & flush the stream. + cpy #512 If stream length < 512, + bcc getchar continue copying characters. -_flush sty index - phx - long a - Write WriteParm - Flush flushparm - short a - plx - ldy #0 - bra getchar +_flush sty index Save length of stream. + phx Hold source string offset on stack. + long a SWITCH TO FULL-WORD MEMORY MODE. + Write WriteParm Write the stream to stdout + Flush flushparm and flush it. + short a SWITCH TO SINGLE-BYTE MEMORY MODE. + plx Restore source string offset to X-reg. + ldy #0 Set stream length to 0. + bra getchar Continue copying characters. -done sty index -exit long a - unlock mutex - rts +; Arrive here when null character is encountered. +done sty index Save stream length in global. + +exit long a SWITCH TO FULL-WORD MEMORY MODE. + unlock mutex Allow others through. + rts Return to caller. END @@ -122,47 +128,52 @@ putp START using stdout - tay ;lock destroys Acc - lock mutex - sty getchar+1 + tay Note: lock destroys Acc + lock mutex Wait for others to leave, and lock. + sty getchar+1 Save low-order bytes of address. sty cmpchar+1 txa - short a - sta getchar+3 + short a SWITCH TO SINGLE-BYTE MEMORY MODE. + sta getchar+3 Store high-order byte of address. sta cmpchar+3 + ora getchar+2 If string address + ora getchar+1 is 00/0000, + beq exit don't do the write. - ldy index - ldx #1 - bra next + ldy index Get current number of chars in stream. + ldx #1 Skip len byte in source string offset. + bra chklen See if there are characters to copy. -getchar lda >$FFFFFF,x - sta stream,y - iny - inx - cmp #13 - beq _flush -next txa -cmpchar cmp >$FFFFFF +getchar lda >$FFFFFF,x Get next character from string. + sta stream,y Store in output stream. + iny Bump the stream and + inx string pointers. + cmp #13 If newline was encountered, + beq _flush go write & flush the stream. +chklen txa +cmpchar cmp >$FFFFFF If we have copied all the chars, beq check2 - bcs done -check2 cpy #512 - bcc getchar + bcs done all done. +check2 cpy #512 If stream length < 512, + bcc getchar continue copying characters. -_flush sty index - phx - long a - Write WriteParm - Flush flushparm - short a - plx - ldy #0 - bra next +_flush sty index Save length of stream. + phx Hold source string offset on stack. + long a SWITCH TO FULL-WORD MEMORY MODE. + Write WriteParm Write the stream to stdout + Flush flushparm and flush it. + short a SWITCH TO SINGLE-BYTE MEMORY MODE. + plx Restore source string offset to X-reg. + ldy #0 Set stream length to 0. + bra chklen -done sty index - long a - unlock mutex - rts +; Arrive here when null character is encountered. +done sty index Save stream length in global. + +exit long a SWITCH TO FULL-WORD MEMORY MODE. + unlock mutex Allow others through. + rts Return to caller. END diff --git a/bin/gsh/sv.asm b/bin/gsh/sv.asm index 47e7734..6a8776e 100644 --- a/bin/gsh/sv.asm +++ b/bin/gsh/sv.asm @@ -6,7 +6,7 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: sv.asm,v 1.2 1998/04/24 15:38:45 gdr-ftp Exp $ +* $Id: sv.asm,v 1.3 1998/06/30 17:26:02 tribby Exp $ * ************************************************************************** * @@ -15,11 +15,14 @@ * * String Vector routines. * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/sv.mac -dummy start ; ends up in .root +dummysv start ; ends up in .root end setcom 60 diff --git a/bin/gsh/term.asm b/bin/gsh/term.asm index c0efdef..2a75366 100644 --- a/bin/gsh/term.asm +++ b/bin/gsh/term.asm @@ -6,7 +6,7 @@ * Jawaid Bazyar * Tim Meekins * -* $Id: term.asm,v 1.2 1998/04/24 15:38:47 gdr-ftp Exp $ +* $Id: term.asm,v 1.3 1998/06/30 17:26:04 tribby Exp $ * ************************************************************************** * @@ -15,11 +15,14 @@ * * Routines for dealing with Termcap under gsh. * +* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65 +* | | | | | | +* ^ ^ ^ ^ ^ ^ ************************************************************************** mcopy /obj/gno/bin/gsh/term.mac -dummy start ; ends up in .root +dummyterm start ; ends up in .root end setcom 60