Changes for gsh version 2.0d7:

Fixed several memory leaks.

Prefix command without any parameter (to list the prefixes) would cause
memory corruption when prefix had been invoked previously with a parameter.

Sourcing a command file from within an exec file could cause gsh to
wait forever, depending upon the commands executed in the sourced file.

All built-in commands return appropriate status: 1 for error, 0 for no error.

Fixed several cases where incorrect value was set in $status.

Added usage strings for tset, hash, commands, and history.

Fixed memory corruption error when edit command had no parameters.

When system() is called with pointer = NULL or with a command string that
causes gsh to detect an error (e.g., incompatibility with | and <), return
status of -1. In other cases, return process's status rather than always 0.

System would crash when output from a non-forked command was piped to
another process; for example   clear | cat > /tmp/list
This commit is contained in:
tribby 1998-12-21 23:57:08 +00:00
parent 7ec020a057
commit e7f2691599
18 changed files with 653 additions and 323 deletions

View File

@ -1,19 +1,10 @@
Last updated: Oct. 25, 1998 By: Dave Tribby
Last updated: Dec. 18, 1998 By: Dave Tribby
For more bug reports, see http://www.gno.org/~gno/bugs.html
Completed items are reported in file UpdateLog.
Executing the following exec file often results in a hang:
# Create exec file
set tmpcmd=/tmp/testcmds
echo "echo Sourcing $tmpcmd" > $tmpcmd
echo "/bin/ps -l" >> $tmpcmd
chtyp -l exec $tmpcmd
# Source that file; usually doesn't return
source $tmpcmd
Allow redirection of built-in commands' I/O even if they aren't forked.
Rather than have each built-in command always be either forked or
@ -21,7 +12,7 @@ non-forked, check dynamically and only fork when it's really necessary
(background or piped).
Identify limits built into gsh and how they can be changed; for example,
size of $PATH <= 256; max programs in hash table = 256.
command line cannot expand to > 1024 characters.
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
@ -31,8 +22,6 @@ 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.
Usage for alias and hash
Gsh requires the v2.0.4 ltermcap to link. A new version of the termcap
library is proposed for GNO v2.0.6, and gsh may require updates.
@ -48,7 +37,7 @@ In expandvars (expand.asm):
Add error checking if out buf gets too big (> 1024)
Get rid of fixed buffers
[ -- below this line...probably not -- ]
[ -- below this line...probably never will be done -- ]
write new memory management.

View File

@ -1,6 +1,76 @@
GSH 2.0 UPDATES
^^^^^^^^^^^^^^^
Dec 20 98 [dmt] For calls to system(), if input pointer is null or
lower level routines detect an error, return -1. This change
caused change to internal routine execute(): return -1 rather
than 0 when an error is detected.
Detect when non-forked builtin or directory name as command
is combined with piped I/O, and ensure that situation is
properly cleaned up. (Formerly, "clear | cat > /tmp/list"
would cause a nasty crash.)
Dec 18 98 [dmt] In execute() (cmd.asm), when child process isn't active
and has no entry in the pid list, assume that pchild() has
already set $status rather than forcing $status to 0.
Dec 17 98 [dmt] argv and argc parameters were reversed in PrintHistory().
This didn't make a difference until argc was checked for != 0.
Dec 16 98 [dmt] Added waitstatus address parameters to command() and
invoke() so completion status can be reported from unforked
builtin commands. Added code in execute() to set status
reported from unforked builtin commands.
Reviewed all built-in commands to ensure they report 0 for
no error and 1 for error.
Fixed memory corruption error when edit command had no
parameters (it called free1024 with random address).
Added usage strings for tset, hash, commands, and history.
Dec 13 98 [dmt] Resolved (or at least closed the window of opportunity
on) defects reported in Oct. 6 and 10 entries. When a process
terminated quickly [kill(pid,0) returned -1], that child's
termination could interfere with detecting the next child's
termination. Solution: Modify removejentry() (jobs.asm) to
return 1 if entry is in list (indicating we expected status
from it) and 0 if it isn't. Modify execute (cmd.asm) to get
status via wait() if and only if removejobentry() returns 1.
Previously, the following exec file often resulted in a hang:
# Create exec file
set tmpcmd=/tmp/testcmds
echo "echo Sourcing $tmpcmd" > $tmpcmd
echo "/bin/ps -l" >> $tmpcmd
chtyp -l exec $tmpcmd
# Source that file; usually doesn't return
source $tmpcmd
Dec 5 98 [dmt] If either glogin file rehashed (for login shells only),
that hash table's memory pointer was overwritten but not
deallocated in shell (shell.asm). Fixed by adding a call to
dispose_hash before calling hashpath.
Nov 29 98 [dmt] Fix memory leak: deallocate name returned by hash
search in invoke (invoke.asm) and which (builtin.asm).
Deallocate path string in invoke by passing it as a new
parameter to argfree, so that it is deallocated only after
the child process is done with it.
Nov 28 98 [dmt] When allocating memory for return string containing
full path in search (hash.asm), add lengths of path + name + 1
rather than path + 33.
Nov 18 98 [dmt] Fix memory leak: when null command was encountered,
the empty command line and argv array were not deallocated.
Nov 12 98 [dmt] prefix command without parameters should not try to
deallocate PRecPath, since it was not used. Causes corruption
when PRecPath contains a value; fixed by jumping to done
rather than finish. Also, jump into "allloop" earlier and
avoid 9 lines of duplicate code.
Nov 2 98 [dmt] Changes to this point checked-in to master archive.
Released as version 2.0d6
Oct 29 98 [dmt] Defect introduced into 2.0d5 fixed: when background job
completed, GetCmdLine thought there was an error on stdin. It
printed a bogus error message and then quit.

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: alias.asm,v 1.6 1998/09/08 16:53:05 tribby Exp $
* $Id: alias.asm,v 1.7 1998/12/21 23:57:04 tribby Exp $
*
**************************************************************************
*
@ -25,7 +25,7 @@
* Returns with status=0 in Accumulator
*
* unalias subroutine (4:argv,2:argc)
* Returns with status=0 in Accumulator
* return 2:status
*
* initalias jsr/rts with no parameters
*
@ -240,16 +240,12 @@ spacestr dc c' ',h'00'
unalias START
space equ 1
argc equ space+3
argv equ argc+2
end equ argv+4
status equ 0
space equ status+2
; subroutine (4:argv,2:argc),space
subroutine (4:argv,2:argc),space
tsc
phd
tcd
stz status
lda argc
dec a
@ -258,6 +254,7 @@ end equ argv+4
ldx #^Usage
lda #USage
jsr errputs
inc status Return status = 1.
bra done
loop add2 argv,#4,argv
@ -273,19 +270,7 @@ loop add2 argv,#4,argv
bra loop
done lda space
sta end-3
lda space+1
sta end-2
pld
tsc
clc
adc #end-4
tcs
lda #0
rtl
done return 2:status
Usage dc c'Usage: unalias name ...',h'0d00'

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: bufpool.asm,v 1.5 1998/09/08 16:53:05 tribby Exp $
* $Id: bufpool.asm,v 1.6 1998/12/21 23:57:04 tribby Exp $
*
**************************************************************************
*
@ -22,9 +22,10 @@
**************************************************************************
*
* Interfaces defined in this file:
* The alloc routines are a jsl without any stack params.
* The alloc routine is a jsl without any stack params.
* Pointer to requested buffer is returned in X/A registers.
* alloc1024
* The free routine takes the address from the X/A registers
* free1024
*
* bufpool data:
@ -40,7 +41,7 @@ dummybufpool start ; ends up in .root
**************************************************************************
*
* get a buffer of size 1024
* Get a buffer of size 1024
*
**************************************************************************
@ -50,16 +51,16 @@ alloc1024 START
lock pool1024mutex
lda pool1024
ora pool1024+2
lda pool1024 If pool pointer
ora pool1024+2 isn't NULL,
beq allocbuf
phd
ph4 pool1024
ph4 pool1024 Push pool pointer on stack.
tsc
tcd
lda [1]
sta pool1024
lda [1] Replace pool pointer with
sta pool1024 the address it points to.
ldy #2
lda [1],y
sta pool1024+2
@ -67,8 +68,11 @@ alloc1024 START
pla
plx
pld
rtl
rtl Return to caller.
;
; No memory in free pool; must allocate a new block.
;
allocbuf unlock pool1024mutex
ph4 #1024
~NEW
@ -78,7 +82,7 @@ allocbuf unlock pool1024mutex
**************************************************************************
*
* free a buffer of size 1024
* Free a buffer of size 1024, putting it into the free pool
*
**************************************************************************
@ -92,32 +96,33 @@ free1024 START
tsc
tcd
lock pool1024mutex
lda pool1024
sta [1]
lda pool1024 Move current head of pool list
sta [1] into the buffer being freed.
ldy #2
lda pool1024+2
sta [1],y
lda 1
sta pool1024
lda 1 Put address of buffer being freed
sta pool1024 into the pool list head.
lda 3
sta pool1024+2
unlock pool1024mutex
pla
plx
pld
rtl
rtl Return to caller.
END
**************************************************************************
*
* buffer pool data
* Buffer pool data
*
**************************************************************************
bufpool DATA
pool1024 dc i4'0'
pool1024mutex key
pool1024 dc i4'0' Head of free pool list.
pool1024mutex key Mutual exclusion when modifying list.
END

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: builtin.asm,v 1.7 1998/10/26 17:04:49 tribby Exp $
* $Id: builtin.asm,v 1.8 1998/12/21 23:57:04 tribby Exp $
*
**************************************************************************
*
@ -129,8 +129,9 @@ foundit ldy #4
pei (argv)
pei (argc)
ourproc jsl >$FFFFFF ;might want to mutex this!!!!!!
sta val
sta val Save return status.
ph4 #0 (no path)
pei (argc)
pei (argv+2)
pei (argv)
@ -403,6 +404,7 @@ getinfo GetFileInfo GRec
bcc ok
ohshit sta ErrError
ErrorGS Err
inc status Return status = 1.
bra done
ok if2 GRecFT,eq,#$F,ok2
@ -412,6 +414,7 @@ ok if2 GRecFT,eq,#$F,ok2
ldx #^direrr
lda #direrr
jsr errputs
inc status Return status = 1.
bra done
;
@ -440,7 +443,7 @@ exit unlock cdmutex
adc #end-4
tcs
tay Put return status in Accumulator.
tya Put return status in Accumulator.
rtl
@ -498,10 +501,12 @@ end equ argv+4
ldx #^Usage
lda #Usage
jsr errputs
ldy #1 Return status = 1.
bra exit
clearit jsr clearscrn
jsr flush
ldy #0 Return status = 0.
exit lda space
sta end-3
@ -513,7 +518,7 @@ exit lda space
adc #end-4
tcs
lda #0
tya
rtl
@ -537,7 +542,8 @@ echo START
val equ 1
nl equ val+2 flag: was -n option set?
ptr equ nl+2
space equ ptr+4
status equ ptr+4
space equ status+2
argc equ space+3
argv equ argc+2
end equ argv+4
@ -553,6 +559,7 @@ end equ argv+4
phd
tcd
stz status Clear return status.
stz nl Clear the -n flag.
dec argc Decrement argument counter.
jeq done Done if no more arguments.
@ -578,6 +585,7 @@ end equ argv+4
showusage ldx #^Usage Incorrect parameter usage:
lda #Usage display the usage string.
jsr errputs
inc status Return status = 1.
jmp exit
gotn iny
@ -662,7 +670,7 @@ done lda nl If "-n" flag isn't set,
jsr newline add a newline.
exit jsr flush Print the buffer.
ldy status
* Clear parameters from stack and return from subroutine.
@ -676,7 +684,7 @@ exit jsr flush Print the buffer.
adc #end-4
tcs
lda #0
tya
rtl
@ -716,6 +724,7 @@ end equ argv+4
ldx #^Usage print the usage string.
lda #Usage
jsr errputs
ldy #1 Return status = 1.
bra exit
wait lock pwdmutex
@ -744,6 +753,7 @@ freebuf ph4 ptr Free the buffer.
jsl nullfree
done unlock pwdmutex
ldy #0 Return status = 0.
exit lda space Deallocate stack space
sta end-3 and return to the caller.
@ -755,7 +765,7 @@ exit lda space Deallocate stack space
adc #end-4
tcs
lda #0 Return status always 0.
tya Return status.
rtl
@ -779,8 +789,10 @@ which START
using hashdata
ptr equ 1
file equ ptr+4
space equ file+4
sptr equ ptr+4
file equ sptr+4
status equ file+4
space equ status+2
argc equ space+3
argv equ argc+2
end equ argv+4
@ -793,13 +805,16 @@ end equ argv+4
tcs
phd
tcd
stz status Clear return status.
;
; display usage if no arguments given
; Display usage if no argument
;
if2 argc,ge,#2,loop
ldx #^whicherr
lda #whicherr
jsr errputs
inc status Return status = 1
jmp exit
;
; loop through each argument
@ -858,7 +873,12 @@ tryhash pei (file+2)
;
; It was hashed, so say so.
;
foundhash jsr puts
foundhash sta sptr
stx sptr+2
jsr puts
pei (sptr+2) Free memory allocated
pei (sptr) by search to hold full path.
jsl nullfree
jmp nextarg
;
; It must be in the current prefix, so check it out.
@ -928,7 +948,8 @@ donecwd unlock pwdmutex
nextarg jsr newline
jmp loop
exit lda space
exit ldy status
lda space
sta end-3
lda space+1
sta end-2
@ -938,7 +959,7 @@ exit lda space
adc #end-4
tcs
lda #0
tya
rtl
@ -962,7 +983,7 @@ GRecAuxType ds 4
* PREFIX: builtin command
* syntax: prefix [num [prefix]]
*
* sets prefix number num to prefix
* sets prefix number num to prefix or print list of all prefixes
*
**************************************************************************
@ -971,7 +992,8 @@ prefix START
dir equ 1
numstr equ dir+4
pfxnum equ numstr+4
space equ pfxnum+2
status equ pfxnum+2
space equ status+2
argc equ space+3
argv equ argc+2
end equ argv+4
@ -987,6 +1009,7 @@ end equ argv+4
lock mutex
stz status Clear return status.
lda argc Get number of arguments.
dec a
beq showall If no parameters, show all prefixes.
@ -998,7 +1021,9 @@ end equ argv+4
ldx #^usage
lda #usage
jsr errputs
jmp done
jmp badstat
; -------------------------------------------------------------------
;
; No parameters provided: show all the prefixes
;
@ -1016,16 +1041,7 @@ showall anop
ldx #^bootstr
lda #bootstr
jsr puts
ldx dir+2
lda dir X/A = address of
clc text (four bytes
adc #4 beyond start).
bcc doputs
inx
doputs jsr puts Print the directory name
jsr newline and a newline.
bra nextall Jump into the all loop.
bra printid Jump into the loop
allloop lda pfxnum
pha
@ -1042,7 +1058,7 @@ allloop lda pfxnum
Int2Dec (pfxnum,#pfxstr,#2,#0)
ldx #^pfxstr
lda #pfxstr
jsr puts
printid jsr puts
ldx dir+2
lda dir X/A = address of
clc text (four bytes
@ -1056,8 +1072,9 @@ nextall ph4 dir Free the GS/OS result buffer
jsl nullfree allocated for pathname.
bumppfx inc pfxnum Bump the prefix number.
if2 pfxnum,cc,#32,allloop
jmp finish
jmp done
; -------------------------------------------------------------------
;
; One parameter provided: show a single prefix
;
@ -1103,6 +1120,7 @@ donewline jsr newline
jsl nullfree allocated for pathname.
jmp done
; -------------------------------------------------------------------
;
; Two parameters provided: set a prefix
;
@ -1149,6 +1167,7 @@ ok if2 GRecFT,eq,#$F,ok2 If filetype != $F,
ldx #^direrr print error message
lda #direrr 'Not a directory'
jsr errputs
badstat inc status Return status = 1.
bra done
ok2 SetPrefix PRec Set the prefix.
@ -1156,13 +1175,22 @@ ok2 SetPrefix PRec Set the prefix.
ldx #^errorstr print error message
lda #errorstr 'could not set prefix,
jsr errputs pathname may not exist.'
inc status Return status = 1.
; -------------------------------------------------------------------
;
; All done: cleanup and return
;
finish ph4 PRecPath Free the name string buffer.
jsl nullfree
;
; Exit through here if PRecPath wasn't used
;
done unlock mutex
ldy status
lda space
sta end-3
lda space+1
@ -1173,7 +1201,7 @@ done unlock mutex
adc #end-4
tcs
lda #0
tya
rtl
@ -1228,14 +1256,12 @@ ErrError ds 2 Error number
rehash START
unhash ENTRY
space equ 1
argc equ space+3
argv equ argc+2
end equ argv+4
status equ 0
space equ status+2
tsc
phd
tcd
subroutine (4:argv,2:argc),space
stz status
lda argc
dec a
@ -1251,6 +1277,7 @@ end equ argv+4
jsr errputs
lda #13
jsr errputchar
inc status Return status = 1.
bra exit
doit jsr dispose_hash ;remove old table
@ -1266,19 +1293,7 @@ doit jsr dispose_hash ;remove old table
if2 @a,eq,#'u',exit ;if 'rehash' do the hashing.
jsl hashpath ;hash the path
exit lda space
sta end-3
lda space+1
sta end-2
pld
tsc
clc
adc #end-4
tcs
lda #0
rtl
exit return 2:status
Usage dc c'Usage: ',h'00'
@ -1322,16 +1337,20 @@ setdebug START
arg equ 0
newdebug equ arg+4
mode equ newdebug+2
space equ mode+2
status equ mode+2
space equ status+2
subroutine (4:argv,2:argc),space
stz status
lda argc
dec a
bne ok
showusage ldx #^usage
lda #usage
jsr errputs
inc status Return status = 1.
jmp return
ok stz mode
@ -1377,7 +1396,7 @@ turnnext sta newdebug
done setdebug newdebug
mv2 newdebug,globaldebug
return return 2:#0
return return 2:status
findflag incad arg
ldy #0
@ -1472,16 +1491,20 @@ ps2 equ t+4
pr2 equ ps2+4
pr equ pr2+4
ps equ pr+4
space equ ps+4
status equ ps+4
space equ status+2
subroutine (4:argv,2:argc),space
stz status
lda argc
dec a
beq ok
showusage ldx #^usage
lda #usage
jsr errputs
inc status Return status = 1.
jmp return
ok getuid
@ -1494,6 +1517,7 @@ ok getuid
ldx #^kvmerrstr
lda #kvmerrstr
jsr errputs
inc status Return status = 1.
jmp done
ok2 ldx #^header
@ -1679,7 +1703,7 @@ skip jmp loop
done kvm_close ps
return return 2:#0
return return 2:status
usage dc c'Usage: ps',h'0d00'
kvmerrstr dc c'ps: error in kvm_open()',h'0d00'
@ -1723,11 +1747,24 @@ hashbi START
sv equ 0
q equ sv+4
p equ q+4
space equ p+4
status equ p+4
space equ status+2
subroutine (4:argv,2:argc),space
ph2 t_size Get size of hash table.
stz status
lda argc
dec a
beq dohash
ldx #^Usage
lda #Usage
jsr errputs
inc status Return status = 1.
bra exit
dohash ph2 t_size Get size of hash table.
jsl sv_alloc Allocate a string vector array.
sta sv
stx sv+2
@ -1791,7 +1828,9 @@ doneadd anop
pei (sv)
jsl sv_dispose Dispose of the string vector memory.
exit return 2:#0
exit return 2:status
usage dc c'Usage: hash',h'0d00'
END
@ -1859,11 +1898,24 @@ cmdbi START
using BuiltinData
sv equ 0
space equ sv+4
status equ sv+4
space equ status+2
subroutine (4:argv,2:argc),space
ph2 #50
stz status
lda argc
dec a
beq docmds
ldx #^Usage
lda #Usage
jsr errputs
inc status Return status = 1.
bra exit
docmds ph2 #50
jsl sv_alloc
sta sv
@ -1903,6 +1955,8 @@ doneadd anop
pei (sv)
jsl sv_dispose
exit return 2:#0
exit return 2:status
usage dc c'Usage: commands',h'0d00'
END

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: cmd.asm,v 1.7 1998/10/26 17:04:49 tribby Exp $
* $Id: cmd.asm,v 1.8 1998/12/21 23:57:05 tribby Exp $
*
**************************************************************************
*
@ -27,11 +27,11 @@
* Returns value of token in Accumulator
*
* command subroutine (4:waitpid,2:inpipe,2:jobflag,2:inpipe2,
* 4:pipesem,4:stream)
* 4:pipesem,4:stream,4:awaitstatus)
* Called by execute to act on a single command
* Returns next token in Accumulator
*
* argfree subroutine (2:argc,4:argv)
* argfree subroutine (4:path,2:argc,4:argv)
*
* ShellExec subroutine (4:path,2:argc,4:argv,2:jobflag)
* Reads and executes commands from an exec file.
@ -348,7 +348,8 @@ temp equ append+2
argc equ temp+4
token equ argc+2
space equ token+2
stream equ space+3
awaitstatus equ space+3
stream equ awaitstatus+4
pipesem equ stream+4
inpipe2 equ pipesem+4
jobflag equ inpipe2+2
@ -356,7 +357,7 @@ inpipe equ jobflag+2
waitpid equ inpipe+2
end equ waitpid+4
; subroutine (4:waitpid,2:inpipe,2:jobflag,2:inpipe2,4:pipesem,4:stream),space
; subroutine (4:waitpid,2:inpipe,2:jobflag,2:inpipe2,4:pipesem,4:stream,4:awaitstatus),space
tsc
sec
@ -612,7 +613,15 @@ tok_eof anop
lda #spcmdstr specify a command before redirecting.
jsr errputs
nulldone lda #0 Clear the waitpid
nulldone anop
pei (cmdline+2) Free buffers
pei (cmdline) allocated for
jsl nullfree command line
pei (argv+2) and argv.
pei (argv)
jsl nullfree
lda #0 Clear the waitpid
sta [waitpid] and return as if
lda #T_NULL nothing were parsed.
jmp exit
@ -639,7 +648,7 @@ bar2 clc Calculate 32-bit address
adc #pipefds pipefds in X and A.
ldx #0
pipe @xa Allocate 2 file descriptor pipe
; >> NOTE: what if pipes return errors?
; >> NOTE: what if pipe returns error?
;
; Call invoke param size:name
@ -668,16 +677,24 @@ run2 phx
pei (pipefds) 2: pipeout2 (allocated: write end)
pei (pipesem+2) 4: pipesem (param passed in)
pei (pipesem)
pei (awaitstatus+2) 4: awaitstatus (address) [New for v2.0]
pei (awaitstatus)
lda #-1 Set waitstatus = -1; it will be set to
sta [awaitstatus] 0 or 1 iff unforked builtin is called.
jsl invoke
sta pid
cmp #-1
beq exit
cmp #-1 If invoke detected an error,
beq exit all done.
; If next token is "|", recursively call command.
if2 token,ne,#T_BAR,run3
lda #-1 Pre-set for error flag.
ldx pid If no child was forked,
beq exit all done.
pei (waitpid+2) 4: waitpid
pei (waitpid)
pei (pipefds) 2: inpipe
@ -687,6 +704,8 @@ run2 phx
pei (pipesem)
pei (stream+2) 4: stream
pei (stream)
pei (awaitstatus+2) 4: awaitstatus
pei (awaitstatus)
jsl command
bra exit
@ -694,9 +713,10 @@ run3 lda pid
sta [waitpid]
lda token
; clean up
exit pha
;
; Free allocated memory and return to caller
;
exit pha Hold return status on stack.
lda dstfile
ora dstfile+2
@ -726,7 +746,7 @@ ex3 anop
lda word
jsl free1024
ply
ply Get return value.
lda space
sta end-3
@ -741,14 +761,18 @@ ex3 anop
tya
rtl
error ldx #^err00
;
; Print error message, deallocate memory, and return with value -1
;
error ldx #^err00 (Add high word of error address)
jsr errputs
tok_error pei (cmdline+2)
pei (cmdline)
jsl nullfree
exit1a pei (argc)
ph4 #0 (no path to be freed)
pei (argc)
pei (argv+2)
pei (argv)
jsl argfree
@ -779,9 +803,13 @@ argfree START
space equ 0
subroutine (2:argc,4:argv),space
subroutine (4:path,2:argc,4:argv),space
free1 lda argc
pei path+2 Free the path.
pei path
jsl nullfree
free1 lda argc Free each of the argv elements.
beq free2
dec a
asl2 a
@ -795,7 +823,8 @@ free1 lda argc
jsl nullfree
dec argc
bra free1
free2 pei (argv+2)
free2 pei (argv+2) Free the argv array.
pei (argv)
jsl nullfree
return
@ -1135,10 +1164,10 @@ execute START
exebuf equ 1
pipesem equ exebuf+4
ptr2 equ pipesem+2
waitstatus equ ptr2+4
ptr equ waitstatus+2
pid equ ptr+4
ptr_glob equ pipesem+2
waitstatus equ ptr_glob+4
ptr_envexp equ waitstatus+2
pid equ ptr_envexp+4
term equ pid+2
cmdstrt equ term+2
cmdend equ cmdstrt+4
@ -1284,48 +1313,48 @@ expand anop
pei (cmdstrt+2)
pei (cmdstrt)
jsl expandvars
sta ptr_envexp
stx ptr_envexp+2
; Expand wildcard characters in the modified command line
phx
pha
sta ptr
stx ptr+2
jsl glob
sta ptr_glob
stx ptr_glob+2
; Expand aliases in the modified command line
; Expand aliases in the modified command line (final expansion)
phx
pha
sta ptr2
stx ptr2+2
jsl expandalias
phx
pha
sta exebuf
stx exebuf+2
phx Put exebuf on stack for
pha nullfree at endcmd.
* >> Temporary debug code: echo expanded command if echo is set.
using vardata
lda varecho
ldy varecho
beq noecho
ldx exebuf+2
lda exebuf
jsr puts
jsr puts NOTE: x/a = exebuf
jsr newline
noecho anop
ldx ptr+2
lda ptr
ldx ptr_envexp+2 Free memory allocated
lda ptr_envexp for env var expansion
jsl free1024
ldx ptr2+2
lda ptr2
ldx ptr_glob+2 and globbing.
lda ptr_glob
jsl free1024
;
; If exebuf pointer is null, bail out.
; >> NOTE: if exebuf is checked for null, shouldn't the other ptrs?
;
lda exebuf
ora exebuf+2
bne loop
pla
pla
stz term
@ -1334,7 +1363,7 @@ noecho anop
* command subroutine (4:waitpid,2:inpipe,2:jobflag,2:inpipe2,
* 4:pipesem,4:stream)
* 4:pipesem,4:stream,4:awaitstatus)
loop pea 0 ;Bank 0 waitpid (hi)
tdc
clc
@ -1353,23 +1382,39 @@ loop pea 0 ;Bank 0 waitpid (hi)
clc
adc #exebuf
pha stream (low)
pea 0 ;Bank 0 status (hi) [New: v2.0]
tdc
clc
adc #waitstatus
pha status (low)
jsl command
sta term
jmi noerrexit
sta term Save result in term.
jmi errexit If < 0, all done.
lda pid
jeq donewait
; If waitstatus != -1, executed command was a non-forked builtin,
; and waitstatus is its completion status.
lda waitstatus
cmp #-1
jeq noerrexit
beq chkpid
jsr setstatus Set $status.
bra godonewait No need to wait.
lda jobflag
jeq jobwait
chkpid lda pid Get child process id.
beq godonewait If 0 (no fork), no need to wait.
cmp #-1 If -1 (error), all done.
jeq errexit
signal (#SIGINT,#0)
phx
pha
signal (#SIGTSTP,#0)
lda jobflag If jobflag is set,
beq jobwait do more complicated wait.
;
; Uncomplicated wait: simply call wait() to get child's termination status
;
signal (#SIGINT,#0) Use default interrupt and
phx keyboard stop signal handlers,
pha and put address of current
signal (#SIGTSTP,#0) handlers on the stack.
phx
pha
@ -1384,53 +1429,79 @@ otherwait anop
lda waitstatus
and #$FF
cmp #$7F Check for WSTOPPED status.
beq otherwait
lda waitstatus
jsr setstatus
beq otherwait Something else...wait again.
pla
plx
lda waitstatus
jsr setstatus Set process's $status.
pla Restore gsh's interrupt and
plx keyboard stop signal handlers.
signal (#SIGTSTP,@xa)
pla
plx
signal (#SIGINT,@xa)
bra donewait
godonewait bra donewait
;
; jobflag = 0: need more complicated wait for child
;
jobwait anop
signal (#SIGCHLD,#pchild) Ensure child sig handler active.
phx Save address of previous sig handler.
pha
kill (pid,#0) If child no longer exists,
kill (pid,#0) If child no longer exists
beq wait4job
pei pid
jsl removejentry Remove it from the list.
bra setwstat
wait4job jsl pwait Otherwise, wait for it.
setwstat stz waitstatus
pla Restore previous child completion
jsl removejentry Remove its pid from the list.
beq restoresigh Pid not in list: assume $status set.
ldx #0
clc
tdc
adc #waitstatus
wait @xa Get child completion status.
lda waitstatus
jsr setstatus Set process's $status.
bra restoresigh
;
; Child is active: wait for it to complete and get its status.
; NOTE: $status is set by SIGCHLD signal handler, pchild
;
wait4job jsl pwait Wait for child using pchild
restoresigh pla Restore previous child completion
plx signal handler.
signal (#SIGCHLD,@xa)
; If command detected EOF terminator, all done
donewait if2 term,eq,#T_EOF,noerrexit
lda [exebuf] If not at end of line,
;
; Done waiting for completion status. Check the token last parsed
; from the command line.
;
donewait if2 term,eq,#T_EOF,endcmd If last token was EOF
lda [exebuf] or if next character is \0,
and #$FF
beq exit
jmp loop process the next command.
beq endcmd all done with this command.
jmp loop Process the next command.
;
; NOTE: non-forked builtins have no mechanism to return command status
; Underlying routine detected an error. Set waitstatus = -1
;
errexit lda #-1
sta waitstatus
noerrexit stz waitstatus
exit jsl nullfree
lda term ;make sure we return -1 if error
;
; We have completed processing of a command
;
endcmd jsl nullfree Free exebuf (addr on stack).
lda term Return -1 if error
bmi chk_cmd
lda waitstatus
xba
lda waitstatus Get completion status, and convert
xba from wait() format to byte value.
and #$FF
;
@ -1488,14 +1559,15 @@ space equ retval+2
lda str If user passes a
ora str+2 null pointer,
bne makecall
ina return 1 to caller.
dec a return -1 to caller.
bra setrtn
;
; Let execute(str,1) do the work
;
makecall pei (str+2)
pei (str)
ph2 #1 jobflag=1 says we're called by system
ph2 #1 jobflag=1
jsl execute
;
; Set status and go back to the caller

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: dir.asm,v 1.7 1998/10/26 17:04:50 tribby Exp $
* $Id: dir.asm,v 1.8 1998/12/21 23:57:05 tribby Exp $
*
**************************************************************************
*
@ -79,10 +79,12 @@ dirs START
using DirData
arg equ 0
space equ arg+4
status equ arg+4
space equ status+2
subroutine (4:argv,2:argc),space
stz status
lda argc
dec a
beq showshort
@ -107,6 +109,7 @@ space equ arg+4
using ldx #^usingstr
lda #usingstr
jsr errputs
inc status Return status = 1.
bra exit
showlong jsl dotods Set top of stack to current directory.
@ -118,7 +121,7 @@ showshort jsl dotods Set top of stack to current directory.
pea 1
jsl showdir
exit return 2:#0
exit return 2:status
usingstr dc c'usage: dirs [-l]',h'0d00'
@ -141,10 +144,12 @@ pushd START
count equ 0
p equ count+2
arg equ p+4
space equ arg+4
status equ arg+4
space equ status+2
subroutine (4:argv,2:argc),space
stz status
lda argc Get number of arguments.
dec a If no parameters,
beq xchange exchange top two dirs on stack.
@ -283,6 +288,7 @@ godir anop
ldx #^errfull print error message.
lda #errfull
prerrmsg jsr errputs
inc status Return status = 1.
bra exit
stackok anop
jsl dotods Set top of stack to current directory.
@ -306,7 +312,7 @@ done lda varpushdsil If $PUSHDSILENT not defined,
pea 1
jsl showdir show the directory stack.
exit return 2:#0
exit return 2:status
usagestr dc c'usage: pushd [+n | dir]',h'0d00'
err1 dc c'pushd: No other directory',h'0d00'
@ -333,10 +339,12 @@ popd START
count equ 0
arg equ count+2
space equ arg+4
status equ arg+4
space equ status+2
subroutine (4:argv,2:argc),space
stz status
lda argc
dec a
jeq noarg
@ -356,6 +364,7 @@ space equ arg+4
using ldx #^usingstr
lda #usingstr
jsr errputs
inc status Return status = 1.
jmp exit
plus add4 arg,#1,arg
@ -377,6 +386,7 @@ plus add4 arg,#1,arg
pluserr ldx #^err2
lda #err2
jsr errputs
inc status Return status = 1.
bra exit
doplus jsl dotods Set top of stack to current directory.
@ -408,6 +418,7 @@ noarg lda tods
ldx #^err1
lda #err1
jsr errputs
inc status Return status = 1.
bra exit
noarg0 lda tods
@ -437,7 +448,7 @@ gototop lda tods
pea 1
jsl showdir
exit return 2:#0
exit return 2:status
usingstr dc c'Usage: popd [+n]',h'0d00'
err1 dc c'popd: Directory stack empty',h'0d00'

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: edit.asm,v 1.8 1998/11/02 17:40:56 tribby Exp $
* $Id: edit.asm,v 1.9 1998/12/21 23:57:06 tribby Exp $
*
**************************************************************************
*
@ -1733,17 +1733,21 @@ bindkey START
str equ 0
func equ str+4
arg equ func+2
space equ arg+4
status equ arg+4
space equ status+2
subroutine (4:argv,2:argc),space
stz status
lda argc
dec a
bne ok
showusage ldx #^usage
lda #usage
jsr errputs
jmp exit
inc status
bra goexit
ok dec argc
add2 argv,#4,argv
@ -1765,7 +1769,7 @@ ok dec argc
list ldx #^liststr
lda #liststr
jsr puts
jmp exit
bra goexit
startbind lda argc
dec a
@ -1797,8 +1801,8 @@ nofind pla
ldx #^errstr
lda #errstr
jsr errputs
lda #-1
jmp exit
inc status
goexit bra exit
foundit pla
lsr a
@ -1838,7 +1842,7 @@ foundit pla
pei (str)
jsl nullfree
exit return
exit return 2:status
usage dc c'Usage: bindkey [-l] function string',h'0d00'
errstr dc c': undefined function',h'0d00'

View File

@ -1,7 +1,7 @@
/*
* Resources for version and comment
*
* $Id: gsh.rez,v 1.7 1998/11/02 17:40:56 tribby Exp $
* $Id: gsh.rez,v 1.8 1998/12/21 23:57:06 tribby Exp $
*/
#define PROG "gsh"
@ -16,7 +16,7 @@
resource rVersion (1, purgeable3) {
{ 2, 0, 0, /* Version 2.0.0 */
development, /* development|alpha|beta|final|release */
6 }, /* non-final release number */
7 }, /* non-final release number */
verUS, /* Country */
PROG, /* Program name */
DESC

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: hash.asm,v 1.6 1998/09/08 16:53:09 tribby Exp $
* $Id: hash.asm,v 1.7 1998/12/21 23:57:06 tribby Exp $
*
**************************************************************************
*
@ -361,7 +361,8 @@ done anop
search START
ptr equ 1
full_path equ ptr+4
name_len equ ptr+4
full_path equ name_len+2
qh equ full_path+4
space equ qh+2
paths equ space+3
@ -428,6 +429,12 @@ found lda [ptr]
sta ptr
ldx paths+2
stx ptr+2
pei (file+2)
pei (file)
jsr cstrlen Get length of prog name.
sta name_len
ldy #2
lda [ptr],y
pha
@ -435,8 +442,8 @@ found lda [ptr]
pha
jsr cstrlen Get length of path.
pha
clc
adc #33 Add 33 (max prog name size + 1)
sec
adc name_len Add name length + 1 (carry bit).
pea 0
pha
~NEW Allocate memory,

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: history.asm,v 1.6 1998/09/08 16:53:10 tribby Exp $
* $Id: history.asm,v 1.7 1998/12/21 23:57:06 tribby Exp $
*
**************************************************************************
*
@ -584,11 +584,24 @@ PrintHistory START
using global
ptr equ 0
space equ ptr+4
status equ ptr+4
space equ status+2
subroutine (2:argc,4:argv),space
subroutine (4:argv,2:argc),space
lda historyptr
stz status
lda argc
dec a
beq chkptr
ldx #^usage
lda #usage
jsr errputs
inc status Return status = 1.
bra done
chkptr lda historyptr
ora historyptr+2
beq done
@ -626,12 +639,14 @@ ok jsr puts
next dec num
bra loop1
done return 2:#0
done return 2:status
numbstr dc c'0000: ',h'00'
num ds 2
count ds 2
usage dc c'Usage: history',h'0d00'
END
;=========================================================================

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: invoke.asm,v 1.8 1998/10/26 17:04:50 tribby Exp $
* $Id: invoke.asm,v 1.9 1998/12/21 23:57:06 tribby Exp $
*
**************************************************************************
*
@ -29,7 +29,7 @@
*
* invoke subroutine (2:argc,4:argv,4:sfile,4:dfile,4:efile,2:app,
* 2:eapp,2:bg,4:cline,2:jobflag,2:pipein,2:pipeout,
* 2:pipein2,2:pipeout2,4:pipesem)
* 2:pipein2,2:pipeout2,4:pipesem,4:awaitstatus)
* return 2:rtnval
*
**************************************************************************
@ -226,12 +226,15 @@ biflag equ p+4
ptr equ biflag+2
rtnval equ ptr+4 Return pid, -1 (error), or 0 (no fork)
cpath equ rtnval+2
space equ cpath+4
hpath equ cpath+4
space equ hpath+4
subroutine (2:argc,4:argv,4:sfile,4:dfile,4:efile,2:app,2:eapp,2:bg,4:cline,2:jobflag,2:pipein,2:pipeout,2:pipein2,2:pipeout2,4:pipesem),space
subroutine (2:argc,4:argv,4:sfile,4:dfile,4:efile,2:app,2:eapp,2:bg,4:cline,2:jobflag,2:pipein,2:pipeout,2:pipein2,2:pipeout2,4:pipesem,4:awaitstatus),space
ld2 -1,rtnval
stz biflag Clear built-in flag.
stz biflag Clear built-in flag
stz hpath and address from hash table.
stz hpath+2
lda argc If number of arguments == 0,
bne chknull nothing to do. (Shouldn't happen
@ -275,6 +278,8 @@ chknull ldy #2 Move 1st argument
changeit sta cpath Use full path from
stx cpath+2 hash table.
sta hpath Save adddress for deallocation.
stx hpath+2
;
; Get information about the command's filename
@ -437,8 +442,14 @@ doDir lock cdmutex
mv4 GRecPath,PRecPath
SetPrefix PRec
unlock cdmutex
stz rtnval Return value: no fork done.
jmp free
pei (ptr+2) Free memory used to hold
pei (ptr) GS/OS string with path.
jsl nullfree
lda #0 Completion status = 0.
;
; Rest of cleanup is shared with non-forked builtin
;
jmp nfcleanup
*
* ---------------------------------------------------------------
@ -470,7 +481,8 @@ doShell anop
; Forked shell starts here...
;
exec0 anop
ph2 _argc ;for argfree
ph4 _hpath argfree parameters.
ph2 _argc
ph4 _argv
ph4 _cpath ShellExec parameters
@ -549,8 +561,18 @@ noforkbuiltin anop
pei (argv+2)
pei (argv)
jsl builtin
stz rtnval Return value: no fork done.
bra done
and #$00FF Make return status look like result of
xba wait(): high-order byte = status.
nfcleanup anop
sta [awaitstatus]
stz rtnval Return value (pid) = no fork done.
;
; There might be a process waiting on a pipe
;
lda [pipesem]
sta _semaphore
bra chkpipe
*
* ---------------------------------------------------------------
@ -569,8 +591,8 @@ notfound pei (ptr+2)
lda #err2 'Command not found.'
jsr errputs
lda pipein
beq notfound0
chkpipe lda pipein
beq done
; Input being piped into a command that was not found.
@ -585,14 +607,15 @@ notfound pei (ptr+2)
inc a
kill (@a,#9) Kill all processes in that group.
sigpause #0
notfound0 anop
done cop $7F
lda biflag If built-in flag is clear,
bne skipfrarg
pei (argc) free arguments.
pei (hpath+2) Free arguments.
pei (hpath)
pei (argc)
pei (argv+2)
pei (argv)
jsl argfree
@ -625,6 +648,7 @@ prefork lock fork_mutex Lock the fork mutual exclusion.
mv2 eapp,_eapp
mv4 cline,_cline
mv4 cpath,_cpath
mv4 hpath,_hpath
mv2 argc,_argc
mv4 argv,_argv
mv2 pipein,_pipein
@ -703,7 +727,7 @@ infork phk Make sure data bank register
lda _jobflag If jobflag == 0,
bne infork0b
Open ttyopen
Open ttyopen Open tty.
jcs errinfork
lda _pipein
@ -786,6 +810,7 @@ _app dc i2'0'
_eapp dc i2'0'
_cline dc i4'0'
_cpath dc i4'0'
_hpath dc i4'0'
_pipein dc i2'0'
_pipeout dc i2'0'
_pipein2 dc i2'0'
@ -803,7 +828,7 @@ err2 dc c': Command not found.',h'0d00'
deadstr dc c'Cannot fork (too many processes?)',h'0d00' ;try a spoon
; Parameter block for GS/OC call GetFileInfo
; Parameter block for GS/OS call GetFileInfo
GRec dc i'4' pCount (# of parameters)
GRecPath ds 4 pathname (input; ptr to GS/OS string)
ds 2 access (access attributes)

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: jobs.asm,v 1.7 1998/10/26 17:04:50 tribby Exp $
* $Id: jobs.asm,v 1.8 1998/12/21 23:57:06 tribby Exp $
*
**************************************************************************
*
@ -81,8 +81,8 @@ pwait START
using pdata
waitpid equ 1
oldsig equ waitpid+2
mypid equ 1
oldsig equ mypid+2
p equ oldsig+4
space equ p+4
end equ space+3
@ -97,7 +97,7 @@ end equ space+3
tcd
getpid Get process ID.
sta waitpid
sta mypid
;
; Start of loop that waits for child processes to complete
@ -125,15 +125,15 @@ loop sta p Save job entry pointer in p.
ldy #p_flags Get entry's job status flags.
lda [p],y
and #PFOREGND+PRUNNING
cmp #PFOREGND+PRUNNING
bne getnext
cmp #PFOREGND+PRUNNING If running in foreground,
bne getnext look at the next entry.
ldy #p_pid Get entry's process ID.
lda [p],y
cmp waitpid
beq getnext
cmp mypid If it's this processes' pid,
beq getnext look at the next entry.
; check if the process is actually running..if it is not, report to the
; Check if the process is actually running..if it is not, report to the
; user that a stale process was detected and remove it from job control.
unlock plistmutex
@ -510,14 +510,14 @@ end equ code+2
wait @xa
sta pid
;
; search for the job that has finished.
; Search job list for the process that has finished.
;
lda pjoblist
ldx pjoblist+2
lookloop sta p
stx p+2
ora p+2
jeq done
ora p+2 If at end of job list,
jeq done the process was not found.
ldy #p_jobid
lda [p],y
cmp pid
@ -528,8 +528,9 @@ lookloop sta p
ldy #p_next
lda [p],y
bra lookloop
;
; see how wait was signaled.
; See how wait was signaled.
;
lookfound anop
lda waitstatus
@ -660,7 +661,8 @@ valstat_text dc c'000' Text (up to three digits)
;====================================================================
;
; remove an entry in the job list, based on process number
; Remove an entry in the job list, based on process number
; Return with A-reg = 1 if found, 0 if not found
;
;====================================================================
@ -670,7 +672,8 @@ removejentry START
p equ 1
prev equ p+4
space equ prev+4
found equ prev+4
space equ found+2
pid equ space+3 process id
end equ pid+2
@ -683,6 +686,7 @@ end equ pid+2
phd
tcd
stz found
stz prev
stz prev+2
lock plistmutex Ensure list doesn't change.
@ -710,7 +714,8 @@ loop sta p Get next entry in job list.
;
; Entry found: adjust linked list pointers
;
gotit ora2 prev,prev+2,@a If prev != NULL,
gotit inc found found = TRUE
ora2 prev,prev+2,@a If prev != NULL,
beq gotit2
ldy #p_next prev->next = p->next
lda [p],y
@ -830,6 +835,7 @@ gotmax mv2 prev,pmaxindex
done anop
unlock plistmutex
ldy found
lda space+1
sta end-2
lda space
@ -839,6 +845,7 @@ done anop
clc
adc #end-4
tcs
tya Return value = found flag.
rtl
@ -900,11 +907,13 @@ jobs START
pidflag equ 0
pp equ pidflag+2
count equ pp+4
space equ count+2
status equ count+2
space equ status+2
subroutine (4:argv,2:argc),space
stz pidflag
stz status
lda argc
dec a
beq cont
@ -913,6 +922,7 @@ space equ count+2
shit ldx #^Usage
lda #Usage
jsr errputs
inc status Return status = 1.
jmp done
grab ldy #4
@ -959,7 +969,7 @@ next inc count
beq loop
bcc loop
done return 2:#0
done return 2:status
Usage dc c'Usage: jobs [-l]',h'0d00'
@ -980,7 +990,8 @@ ptr equ 1
arg equ ptr+4
signum equ arg+4
pid equ signum+2
space equ pid+2
status equ pid+2
space equ status+2
argc equ space+3
argv equ argc+2
end equ argv+4
@ -994,6 +1005,8 @@ end equ argv+4
phd
tcd
stz status
lda argc
dec a
bne init
@ -1001,6 +1014,7 @@ end equ argv+4
ldx #^Usage
lda #Usage
jsr errputs
inc status Return status = 1.
jmp done
init stz pid
@ -1047,6 +1061,7 @@ init stz pid
ohshitnum ldx #^err1
lda #err1
jsr errputs
inc status Return status = 1.
jmp done
getname lda [arg]
@ -1074,6 +1089,7 @@ nameloop pei (arg+2)
ldx #^err3
lda #err3
jsr errputs
inc status Return status = 1.
bra done
next dec argc
@ -1097,6 +1113,7 @@ getpid pei (arg+2)
ldx #^err2
lda #err2
jsr errputs
inc status Return status = 1.
bra done
lister ldx #^liststr
@ -1107,6 +1124,7 @@ lister ldx #^liststr
killnull ldx #^err4
lda #err4
jsr errputs
inc status Return status = 1.
bra done
dokill kill (pid,signum)
@ -1115,8 +1133,10 @@ dokill kill (pid,signum)
ldx #^err2
lda #err2
jsr errputs
inc status Return status = 1.
done lda space
done ldy status
lda space
sta end-3
lda space+1
sta end-2
@ -1126,7 +1146,7 @@ done lda space
adc #end-4
tcs
lda #0
tya
rtl
@ -1188,10 +1208,12 @@ fg START
pid equ 0
p equ pid+2
space equ p+4
status equ p+4
space equ status+2
subroutine (4:argv,2:argc),space
stz status
lda argc
dec a
bne getit
@ -1278,8 +1300,9 @@ whoashit ldx #^err01
nojob ldx #^err03
lda #err03
puterr jsr errputs
inc status Return status = 1.
done return 2:#0
done return 2:status
usage dc c'Usage: fg [%job | pid]',h'0d00'
err01 dc c'fg: No job to foreground.',h'0d00'
@ -1301,10 +1324,12 @@ bg START
pid equ 0
p equ pid+2
space equ p+4
status equ p+4
space equ status+2
subroutine (4:argv,2:argc),space
stz status
lda argc
dec a
bne getit
@ -1389,8 +1414,9 @@ whoashit ldx #^err01
nojob ldx #^err03
lda #err03
puterr jsr errputs
inc status Return status = 1
done return 2:#0
done return 2:status
usage dc c'Usage: bg [%job | pid]',h'0d00'
err01 dc c'bg: No job to background.',h'0d00'
@ -1412,10 +1438,12 @@ stop START
pid equ 0
p equ pid+2
space equ p+4
status equ p+4
space equ status+4
subroutine (4:argv,2:argc),space
stz status
lda argc
dec a
bne getit
@ -1478,8 +1506,9 @@ whoashit ldx #^err01
nojob ldx #^err03
lda #err03
puterr jsr errputs
inc status Return status = 1.
done return 2:#0
done return 2:status
usage dc c'Usage: stop [%job | pid]',h'0d00'
err01 dc c'stop: No job to stop.',h'0d00'

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: orca.asm,v 1.6 1998/09/08 16:53:12 tribby Exp $
* $Id: orca.asm,v 1.7 1998/12/21 23:57:07 tribby Exp $
*
**************************************************************************
*
@ -62,7 +62,8 @@ space equ outPath+4
lda #enofile no filename specified
jsr errputs
lda #1
bra seterr
sta retval
jmp donedealloc
; Allocate memory for sFile, inPath, and outPath

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: shell.asm,v 1.7 1998/10/26 17:04:51 tribby Exp $
* $Id: shell.asm,v 1.8 1998/12/21 23:57:07 tribby Exp $
*
**************************************************************************
*
@ -207,7 +207,8 @@ fastskip2 anop
bne didit
jsr readterm
didit anop
jsl hashpath Hash $PATH.
jsr dispose_hash Remove old table (if set in
jsl hashpath login files) and hash $PATH.
ld2 1,hash_print Set hash print flag.
;

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: shellutil.asm,v 1.6 1998/09/08 16:53:13 tribby Exp $
* $Id: shellutil.asm,v 1.7 1998/12/21 23:57:08 tribby Exp $
*
**************************************************************************
*
@ -19,6 +19,57 @@
* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65
* | | | | | |
* ^ ^ ^ ^ ^ ^
**************************************************************************
*
* Interfaces defined in this file:
*
* tolower Convert the accumulator to lower case
* {accumulator = character}
* jsr tolower
* {if acc was uppercase it's now lowercase; else no change}
*
* toslash Convert ':' to '/'
* {accumulator = character}
* jsr toslash
* {if acc was ':', it's now '/'; otherwise no change}
*
* lowercstr Convert a c string to lower case
* {push address of c string on stack}
* jsr lowercstr
*
* cstrlen Get the length of a c string
* {push address of c string on stack}
* jsr cstrlen
* {return with len of string in acc}
*
* copycstr Copy one string to another. Assumes an alloccstr has been
* performed on destination.
*
* cmpcstr Compare two c strings. Return 0 if equal, -1 if less than,
* +1 if greater
*
* cmpdcstr Compare two downshifted c strings. Return 0 if equal,
* -1 if less than, +1 if greater
*
* c2gsstr Allocate memory, then convert a c string to a GS/OS string
* (caller must dispose when done)
*
* catcstr Takes two strings, concats into a newly created string.
*
* nullfree Call ~DISPOSE if pointer is not NULL
*
* newlineX Print a carriage return and a newline, unless "newline" shell
* var is set.
*
* getenv Get value of indicated environment variable; pass in addr of a
* GS/OS string, and pass back addr of allocated GS/OS result
* buffer (with null byte added at end).
* subroutine (4:var)
* return 4:ptr
*
* rmemcpy
* subroutine (2:num,4:src,4:dest)
*
**************************************************************************
mcopy /obj/gno/bin/gsh/shellutil.mac
@ -479,7 +530,7 @@ newline ENTRY
* is written in assembly! :)
*
* For gsh 2.0: pass in addr of a GS/OS string, and pass back addr of
* allocated GS/OS result buffer (with null word added at end), not c-strings.
* allocated GS/OS result buffer (with null byte added at end), not c-strings.
*
**************************************************************************
@ -582,11 +633,17 @@ TempRBlen ds 2 Value's length returned here.
END
**************************************************************************
*
* Copy src bytes to destination address
*
**************************************************************************
rmemcpy START
subroutine (2:num,4:src,4:dest),0
ldy num
beq done
ldy num Get length of src.
beq done Done if == 0.
tya
dey
bit #1

View File

@ -7,7 +7,7 @@
* Tim Meekins
* Derek Taubert
*
* $Id: shellvar.asm,v 1.6 1998/09/08 16:53:13 tribby Exp $
* $Id: shellvar.asm,v 1.7 1998/12/21 23:57:08 tribby Exp $
*
**************************************************************************
*
@ -20,6 +20,20 @@
* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65
* | | | | | |
* ^ ^ ^ ^ ^ ^
**************************************************************************
*
* Interfaces defined in this file:
*
* updatevars subroutine (4:var,2:flag),space ;flag 1: set, 0: unset
* InitVars jsr without any parameters
*
* Remainder are interfaces to builtin commands with interface
* subroutine (4:argv,2:argc)
* returns status in accumulator
* export
* set (setenv is alternate entry point)
* unset
*
**************************************************************************
mcopy /obj/gno/bin/gsh/shellvar.mac
@ -46,7 +60,8 @@ arg equ 1
valbuf equ arg+4
varbuf equ valbuf+4
exflag equ varbuf+4
space equ exflag+2
status equ exflag+2
space equ status+2
argc equ space+3
argv equ argc+2
end equ argv+4
@ -90,6 +105,8 @@ setenv ENTRY
;
startcmd anop
stz status
lda argc If no parameter provided,
dec a
beq showvars list all variables.
@ -112,6 +129,7 @@ startcmd anop
showusage ldx #^Usage
lda #Usage
jsr errputs
inc status Return status = 1.
jmp exit
;
@ -133,7 +151,8 @@ showvars anop
jsl nullfree
svwhoops ld2 $201,ErrError report memory error
ErrorGS Err
jmp exit and exit.
inc status set return status = 1
jmp exit and exit.
startshow anop
lda #1022 Store buffer len == 1022 in value
@ -225,6 +244,7 @@ unixstyle cpy #0
ldx #^error1
lda #error1 Print error message:
jsr errputs 'Variable not specified'
inc status Return status = 1.
jmp doneset
unix0 short a Store '\0' on
lda #0 on top of '='
@ -304,6 +324,7 @@ showonevar anop
notdef ldx #^error2 'Variable not defined'
lda #error2
jsr errputs
inc status Return status = 1.
bra doneone
def ldx RSexport X = export flag.
@ -320,7 +341,8 @@ doneone anop
doneset unlock setmutex
exit lda space
exit ldy status
lda space
sta end-3
lda space+1
sta end-2
@ -329,7 +351,7 @@ exit lda space
adc #end-4
tcs
lda #0 Return status = 0.
tya Return status
rtl
@ -443,23 +465,19 @@ ErrError ds 2 Error number
export START
space equ 1
argc equ space+3
argv equ argc+2
end equ argv+4
status equ 0
space equ status+2
; subroutine (4:argv,2:argc),space
tsc
phd
tcd
subroutine (4:argv,2:argc),space
stz status
lda argc Get parameter count.
dec a If < 1
bne loop
ldx #^Usage Print usage string
lda #Usage
jsr errputs
inc status
bra done and terminate.
;
@ -490,19 +508,7 @@ loop anop
bra loop
done lda space
sta end-3
lda space+1
sta end-2
pld
tsc
clc
adc #end-4
tcs
lda #0
rtl
done return 2:status
expmutex key
@ -529,16 +535,12 @@ Usage dc c'Usage: export var ...',h'0d00'
unset START
space equ 1
argc equ space+3
argv equ argc+2
end equ argv+4
status equ 0
space equ status+2
; subroutine (4:argv,2:argc),space
subroutine (4:argv,2:argc),space
tsc
phd
tcd
stz status
lda argc Get parameter count.
dec a If < 1
@ -546,7 +548,8 @@ end equ argv+4
ldx #^Usage Print usage string
lda #Usage
jsr errputs
bra done and terminate.
inc status set return status = 1
bra done and terminate.
;
; Loop to process all the variables to export
@ -584,19 +587,7 @@ loop anop
bra loop
done lda space
sta end-3
lda space+1
sta end-2
pld
tsc
clc
adc #end-4
tcs
lda #0
rtl
done return 2:status
unsmutex key

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: term.asm,v 1.7 1998/10/26 17:04:51 tribby Exp $
* $Id: term.asm,v 1.8 1998/12/21 23:57:08 tribby Exp $
*
**************************************************************************
*
@ -501,13 +501,27 @@ tset START
using global
space equ 0
status equ 0
space equ status+2
subroutine (4:argv,2:argc),space
jsr readterm
stz status
lda argc
dec a
beq doterm
return
ldx #^Usage
lda #Usage
jsr errputs
inc status Return status = 1.
bra exit
doterm jsr readterm
exit return 2:status
usage dc c'Usage: tset',h'0d00'
END