1997-11-18 05:31:00 +00:00
|
|
|
**************************************************************************
|
|
|
|
*
|
|
|
|
* The GNO Shell Project
|
|
|
|
*
|
|
|
|
* Developed by:
|
|
|
|
* Jawaid Bazyar
|
|
|
|
* Tim Meekins
|
|
|
|
*
|
Changes for gsh version 2.0d8:
Fixed several mutual exclusion problems, including a particularly nasty
one that would cause gsh to loop forever inside the memory manager. (You
could identify this one by the "BRA (-23)" at the bottom of the infinite
loop.)
Fixed the string vector print routine to properly handle all numbers of
entries in the hash table. Previously, it would always print duplicate
entries if there were < 6 commands hashed, and would sometimes print
duplicates (depending on previous contents of an internal table) for
other numbers of commands.
gsh would wait on background processes started from an exec file
(executed, not sourced). Now the exec file does not wait on the process,
but the background process is not associated with the parent shell after
the exec file terminates.
Made gsh globbing work more like csh: if none of the requested patterns
are found, print "No match" and exit.
At startup, if /etc/glogin, $HOME/glogin, or $HOME/gshrc does not exist,
don't report a "file not found" error message. (PR#100)
1998-12-31 18:29:14 +00:00
|
|
|
* $Id: shellutil.asm,v 1.8 1998/12/31 18:29:14 tribby Exp $
|
1998-04-24 15:38:47 +00:00
|
|
|
*
|
1997-11-18 05:31:00 +00:00
|
|
|
**************************************************************************
|
|
|
|
*
|
|
|
|
* SHELLUTIL.ASM
|
|
|
|
* By Tim Meekins
|
1998-08-03 17:30:30 +00:00
|
|
|
* Modified by Dave Tribby for GNO 2.0.6
|
1997-11-18 05:31:00 +00:00
|
|
|
*
|
|
|
|
* Utility functions used by the shell. Mainly string functions.
|
|
|
|
*
|
Major changes to gsh with this checkin:
* When ~ is parsed and next character is a delimiter, make sure contents
of expanded $HOME match the user's delimiter.
* When wildcard patterns don't match, rather than terminating the command
gsh now prints "No match: <pattern> ignored" and passes the command line
minus the unmatched patterns on to be executed.
* Modified echo command so it doesn't add a blank to the end.
* Make "clear" and "source" built-ins non-forked commands. Unforking
"source" allows prefixes to be set in files that are sourced.
* Add loop to parse a single command (removing leading whitespace) before
sending it off to be expanded and executed. Skip null lines and comments
at this level. This allows later commands that depend upon variables set
in the 1st command to work; e.g.: set t_num=1 ; echo "Test number $t_num"
Also fixes problems seen when tab was first character of multiple lines.
* Initialize environment variable flags at startup (for echo, nodirexec,
nonewline, noglob, nobeep, pushdsilent, term, and ignoreeof). Set
flag when env var is set in upper or lower case (formerly, only worked
with lower case).
* Lots of places two-word addresses are incremented using inc, without
checking for overflow into the high-order word. As these are discovered,
they are changed to use adc on both words.
See file UpdateLog for detailed list of changes.
1998-06-30 17:26:04 +00:00
|
|
|
* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65
|
|
|
|
* | | | | | |
|
|
|
|
* ^ ^ ^ ^ ^ ^
|
1998-12-21 23:57:08 +00:00
|
|
|
**************************************************************************
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
*
|
1997-11-18 05:31:00 +00:00
|
|
|
**************************************************************************
|
|
|
|
|
1998-04-24 15:38:47 +00:00
|
|
|
mcopy /obj/gno/bin/gsh/shellutil.mac
|
|
|
|
|
Major changes to gsh with this checkin:
* When ~ is parsed and next character is a delimiter, make sure contents
of expanded $HOME match the user's delimiter.
* When wildcard patterns don't match, rather than terminating the command
gsh now prints "No match: <pattern> ignored" and passes the command line
minus the unmatched patterns on to be executed.
* Modified echo command so it doesn't add a blank to the end.
* Make "clear" and "source" built-ins non-forked commands. Unforking
"source" allows prefixes to be set in files that are sourced.
* Add loop to parse a single command (removing leading whitespace) before
sending it off to be expanded and executed. Skip null lines and comments
at this level. This allows later commands that depend upon variables set
in the 1st command to work; e.g.: set t_num=1 ; echo "Test number $t_num"
Also fixes problems seen when tab was first character of multiple lines.
* Initialize environment variable flags at startup (for echo, nodirexec,
nonewline, noglob, nobeep, pushdsilent, term, and ignoreeof). Set
flag when env var is set in upper or lower case (formerly, only worked
with lower case).
* Lots of places two-word addresses are incremented using inc, without
checking for overflow into the high-order word. As these are discovered,
they are changed to use adc on both words.
See file UpdateLog for detailed list of changes.
1998-06-30 17:26:04 +00:00
|
|
|
dummyshellutil start ; ends up in .root
|
1998-04-24 15:38:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
setcom 60
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
;=========================================================================
|
|
|
|
;
|
|
|
|
; Convert the accumulator to lower case.
|
|
|
|
;
|
|
|
|
;=========================================================================
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
tolower START
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
cmp #'A'
|
|
|
|
bcc done
|
|
|
|
cmp #'Z'+1
|
|
|
|
bcs done
|
|
|
|
adc #'a'-'A'
|
|
|
|
done rts
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
END
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
;=========================================================================
|
|
|
|
;
|
|
|
|
; Convert ':' to '/'
|
|
|
|
;
|
|
|
|
;=========================================================================
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
toslash START
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
cmp #':'
|
|
|
|
bne done
|
|
|
|
lda #'/'
|
|
|
|
done rts
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
END
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
;=========================================================================
|
|
|
|
;
|
|
|
|
; Convert a c string to lower case
|
|
|
|
;
|
|
|
|
;=========================================================================
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
lowercstr START
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
space equ 1
|
|
|
|
p equ space+2
|
|
|
|
end equ p+4
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
tsc
|
|
|
|
phd
|
|
|
|
tcd
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
short a
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
ldy #-1
|
|
|
|
loop iny
|
|
|
|
lda [p],y
|
|
|
|
beq done
|
1997-11-18 05:31:00 +00:00
|
|
|
cmp #'A'
|
|
|
|
bcc loop
|
|
|
|
cmp #'Z'+1
|
|
|
|
bcs loop
|
|
|
|
adc #'a'-'A'
|
1998-09-08 16:53:14 +00:00
|
|
|
sta [p],y
|
|
|
|
bra loop
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
done rep #$21
|
1997-11-18 05:31:00 +00:00
|
|
|
longa on
|
1998-09-08 16:53:14 +00:00
|
|
|
lda space
|
|
|
|
sta end-2
|
|
|
|
pld
|
|
|
|
tsc
|
|
|
|
adc #end-3
|
|
|
|
tcs
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
rts
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
END
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
;=========================================================================
|
|
|
|
;
|
|
|
|
; Get the length of a c string.
|
|
|
|
;
|
|
|
|
;=========================================================================
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
cstrlen START
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
space equ 1
|
|
|
|
p equ space+2
|
|
|
|
end equ p+4
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
tsc
|
|
|
|
phd
|
|
|
|
tcd
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
short a
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
ldy #0
|
|
|
|
loop lda [p],y
|
|
|
|
beq done
|
|
|
|
iny
|
|
|
|
bra loop
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
done rep #$21
|
1997-11-18 05:31:00 +00:00
|
|
|
longa on
|
1998-09-08 16:53:14 +00:00
|
|
|
lda space
|
|
|
|
sta end-2
|
|
|
|
pld
|
|
|
|
tsc
|
|
|
|
adc #end-3
|
|
|
|
tcs
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
tya
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
rts
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
END
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
;=========================================================================
|
|
|
|
;
|
|
|
|
; Copy one string to another. Assumes an alloccstr has been performed on
|
|
|
|
; destination.
|
|
|
|
;
|
|
|
|
;=========================================================================
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
copycstr START
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
space equ 1
|
|
|
|
q equ space+2
|
|
|
|
p equ q+4
|
|
|
|
end equ p+4
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
tsc
|
|
|
|
phd
|
|
|
|
tcd
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
short a
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
ldy #0
|
|
|
|
loop lda [p],y
|
|
|
|
beq done
|
|
|
|
sta [q],y
|
|
|
|
iny
|
|
|
|
bra loop
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
done sta [q],y
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
rep #$21
|
1997-11-18 05:31:00 +00:00
|
|
|
longa on
|
1998-09-08 16:53:14 +00:00
|
|
|
lda space
|
|
|
|
sta end-2
|
|
|
|
pld
|
|
|
|
tsc
|
|
|
|
adc #end-3
|
|
|
|
tcs
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
rts
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
END
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
;=========================================================================
|
|
|
|
;
|
|
|
|
; Compare two c strings. Return 0 if equal, -1 if less than, +1 greater
|
|
|
|
;
|
|
|
|
;=========================================================================
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
cmpcstr START
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
space equ 1
|
|
|
|
q equ space+2
|
|
|
|
p equ q+4
|
|
|
|
end equ p+4
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
tsc
|
|
|
|
phd
|
|
|
|
tcd
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
short a
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
ldx #0
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
strloop lda [p],y
|
|
|
|
beq strchk
|
|
|
|
cmp [q],y
|
|
|
|
bne notequal
|
|
|
|
iny
|
|
|
|
bra strloop
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
strchk lda [q],y
|
|
|
|
beq done
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
lessthan dex
|
|
|
|
bra done
|
|
|
|
|
|
|
|
notequal bcc lessthan
|
|
|
|
inx
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
done rep #$21
|
1997-11-18 05:31:00 +00:00
|
|
|
longa on
|
1998-09-08 16:53:14 +00:00
|
|
|
lda space
|
|
|
|
sta end-2
|
|
|
|
pld
|
|
|
|
tsc
|
|
|
|
adc #end-3
|
|
|
|
tcs
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
txa
|
|
|
|
rts
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
END
|
1997-11-18 05:31:00 +00:00
|
|
|
|
Major changes to gsh with this checkin:
* When ~ is parsed and next character is a delimiter, make sure contents
of expanded $HOME match the user's delimiter.
* When wildcard patterns don't match, rather than terminating the command
gsh now prints "No match: <pattern> ignored" and passes the command line
minus the unmatched patterns on to be executed.
* Modified echo command so it doesn't add a blank to the end.
* Make "clear" and "source" built-ins non-forked commands. Unforking
"source" allows prefixes to be set in files that are sourced.
* Add loop to parse a single command (removing leading whitespace) before
sending it off to be expanded and executed. Skip null lines and comments
at this level. This allows later commands that depend upon variables set
in the 1st command to work; e.g.: set t_num=1 ; echo "Test number $t_num"
Also fixes problems seen when tab was first character of multiple lines.
* Initialize environment variable flags at startup (for echo, nodirexec,
nonewline, noglob, nobeep, pushdsilent, term, and ignoreeof). Set
flag when env var is set in upper or lower case (formerly, only worked
with lower case).
* Lots of places two-word addresses are incremented using inc, without
checking for overflow into the high-order word. As these are discovered,
they are changed to use adc on both words.
See file UpdateLog for detailed list of changes.
1998-06-30 17:26:04 +00:00
|
|
|
;=========================================================================
|
|
|
|
;
|
|
|
|
; Compare two downshifted c strings. Return 0 if ==, -1 if <, +1 >
|
|
|
|
;
|
|
|
|
;=========================================================================
|
|
|
|
|
1998-08-03 17:30:30 +00:00
|
|
|
cmpdcstr START
|
Major changes to gsh with this checkin:
* When ~ is parsed and next character is a delimiter, make sure contents
of expanded $HOME match the user's delimiter.
* When wildcard patterns don't match, rather than terminating the command
gsh now prints "No match: <pattern> ignored" and passes the command line
minus the unmatched patterns on to be executed.
* Modified echo command so it doesn't add a blank to the end.
* Make "clear" and "source" built-ins non-forked commands. Unforking
"source" allows prefixes to be set in files that are sourced.
* Add loop to parse a single command (removing leading whitespace) before
sending it off to be expanded and executed. Skip null lines and comments
at this level. This allows later commands that depend upon variables set
in the 1st command to work; e.g.: set t_num=1 ; echo "Test number $t_num"
Also fixes problems seen when tab was first character of multiple lines.
* Initialize environment variable flags at startup (for echo, nodirexec,
nonewline, noglob, nobeep, pushdsilent, term, and ignoreeof). Set
flag when env var is set in upper or lower case (formerly, only worked
with lower case).
* Lots of places two-word addresses are incremented using inc, without
checking for overflow into the high-order word. As these are discovered,
they are changed to use adc on both words.
See file UpdateLog for detailed list of changes.
1998-06-30 17:26:04 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
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
|
Major changes to gsh with this checkin:
* When ~ is parsed and next character is a delimiter, make sure contents
of expanded $HOME match the user's delimiter.
* When wildcard patterns don't match, rather than terminating the command
gsh now prints "No match: <pattern> ignored" and passes the command line
minus the unmatched patterns on to be executed.
* Modified echo command so it doesn't add a blank to the end.
* Make "clear" and "source" built-ins non-forked commands. Unforking
"source" allows prefixes to be set in files that are sourced.
* Add loop to parse a single command (removing leading whitespace) before
sending it off to be expanded and executed. Skip null lines and comments
at this level. This allows later commands that depend upon variables set
in the 1st command to work; e.g.: set t_num=1 ; echo "Test number $t_num"
Also fixes problems seen when tab was first character of multiple lines.
* Initialize environment variable flags at startup (for echo, nodirexec,
nonewline, noglob, nobeep, pushdsilent, term, and ignoreeof). Set
flag when env var is set in upper or lower case (formerly, only worked
with lower case).
* Lots of places two-word addresses are incremented using inc, without
checking for overflow into the high-order word. As these are discovered,
they are changed to use adc on both words.
See file UpdateLog for detailed list of changes.
1998-06-30 17:26:04 +00:00
|
|
|
|
|
|
|
lessthan dex
|
|
|
|
bra done
|
|
|
|
|
|
|
|
notequal bcc lessthan
|
|
|
|
inx
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
done anop
|
|
|
|
lda space
|
|
|
|
sta end-2
|
|
|
|
pld
|
|
|
|
tsc
|
|
|
|
clc
|
|
|
|
adc #end-3
|
|
|
|
tcs
|
Major changes to gsh with this checkin:
* When ~ is parsed and next character is a delimiter, make sure contents
of expanded $HOME match the user's delimiter.
* When wildcard patterns don't match, rather than terminating the command
gsh now prints "No match: <pattern> ignored" and passes the command line
minus the unmatched patterns on to be executed.
* Modified echo command so it doesn't add a blank to the end.
* Make "clear" and "source" built-ins non-forked commands. Unforking
"source" allows prefixes to be set in files that are sourced.
* Add loop to parse a single command (removing leading whitespace) before
sending it off to be expanded and executed. Skip null lines and comments
at this level. This allows later commands that depend upon variables set
in the 1st command to work; e.g.: set t_num=1 ; echo "Test number $t_num"
Also fixes problems seen when tab was first character of multiple lines.
* Initialize environment variable flags at startup (for echo, nodirexec,
nonewline, noglob, nobeep, pushdsilent, term, and ignoreeof). Set
flag when env var is set in upper or lower case (formerly, only worked
with lower case).
* Lots of places two-word addresses are incremented using inc, without
checking for overflow into the high-order word. As these are discovered,
they are changed to use adc on both words.
See file UpdateLog for detailed list of changes.
1998-06-30 17:26:04 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
txa
|
|
|
|
rts
|
Major changes to gsh with this checkin:
* When ~ is parsed and next character is a delimiter, make sure contents
of expanded $HOME match the user's delimiter.
* When wildcard patterns don't match, rather than terminating the command
gsh now prints "No match: <pattern> ignored" and passes the command line
minus the unmatched patterns on to be executed.
* Modified echo command so it doesn't add a blank to the end.
* Make "clear" and "source" built-ins non-forked commands. Unforking
"source" allows prefixes to be set in files that are sourced.
* Add loop to parse a single command (removing leading whitespace) before
sending it off to be expanded and executed. Skip null lines and comments
at this level. This allows later commands that depend upon variables set
in the 1st command to work; e.g.: set t_num=1 ; echo "Test number $t_num"
Also fixes problems seen when tab was first character of multiple lines.
* Initialize environment variable flags at startup (for echo, nodirexec,
nonewline, noglob, nobeep, pushdsilent, term, and ignoreeof). Set
flag when env var is set in upper or lower case (formerly, only worked
with lower case).
* Lots of places two-word addresses are incremented using inc, without
checking for overflow into the high-order word. As these are discovered,
they are changed to use adc on both words.
See file UpdateLog for detailed list of changes.
1998-06-30 17:26:04 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
END
|
Major changes to gsh with this checkin:
* When ~ is parsed and next character is a delimiter, make sure contents
of expanded $HOME match the user's delimiter.
* When wildcard patterns don't match, rather than terminating the command
gsh now prints "No match: <pattern> ignored" and passes the command line
minus the unmatched patterns on to be executed.
* Modified echo command so it doesn't add a blank to the end.
* Make "clear" and "source" built-ins non-forked commands. Unforking
"source" allows prefixes to be set in files that are sourced.
* Add loop to parse a single command (removing leading whitespace) before
sending it off to be expanded and executed. Skip null lines and comments
at this level. This allows later commands that depend upon variables set
in the 1st command to work; e.g.: set t_num=1 ; echo "Test number $t_num"
Also fixes problems seen when tab was first character of multiple lines.
* Initialize environment variable flags at startup (for echo, nodirexec,
nonewline, noglob, nobeep, pushdsilent, term, and ignoreeof). Set
flag when env var is set in upper or lower case (formerly, only worked
with lower case).
* Lots of places two-word addresses are incremented using inc, without
checking for overflow into the high-order word. As these are discovered,
they are changed to use adc on both words.
See file UpdateLog for detailed list of changes.
1998-06-30 17:26:04 +00:00
|
|
|
|
1997-11-18 05:31:00 +00:00
|
|
|
;=========================================================================
|
|
|
|
;
|
|
|
|
; Convert a c string to a GS/OS string (don't forget to dispose when done)
|
|
|
|
;
|
|
|
|
;=========================================================================
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
c2gsstr START
|
|
|
|
|
|
|
|
len equ 1
|
|
|
|
gstr equ len+2
|
|
|
|
space equ gstr+4
|
|
|
|
cstr equ space+2
|
|
|
|
end equ cstr+4
|
|
|
|
|
|
|
|
tsc
|
|
|
|
sec
|
|
|
|
sbc #space-1
|
|
|
|
tcs
|
|
|
|
phd
|
|
|
|
tcd
|
|
|
|
|
|
|
|
pei (cstr+2)
|
|
|
|
pei (cstr)
|
|
|
|
jsr cstrlen
|
|
|
|
sta len
|
1997-11-18 05:31:00 +00:00
|
|
|
adc #3
|
1998-09-08 16:53:14 +00:00
|
|
|
pea 0
|
|
|
|
pha
|
|
|
|
~NEW
|
|
|
|
sta gstr
|
|
|
|
stx gstr+2
|
1998-07-20 16:23:11 +00:00
|
|
|
incad @xa
|
|
|
|
incad @xa
|
1998-09-08 16:53:14 +00:00
|
|
|
pei (cstr+2)
|
|
|
|
pei (cstr)
|
|
|
|
phx
|
|
|
|
pha
|
|
|
|
jsr copycstr
|
|
|
|
lda len
|
|
|
|
sta [gstr]
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
ldx gstr+2
|
|
|
|
ldy gstr
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
lda space
|
|
|
|
sta end-2
|
|
|
|
pld
|
|
|
|
tsc
|
|
|
|
adc #end-3
|
|
|
|
tcs
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
tya
|
|
|
|
rts
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
END
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
;=========================================================================
|
|
|
|
;
|
|
|
|
; Takes two strings, concats into a newly created string.
|
|
|
|
;
|
|
|
|
;=========================================================================
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
catcstr START
|
|
|
|
|
1997-11-18 05:31:00 +00:00
|
|
|
new equ 1
|
1998-09-08 16:53:14 +00:00
|
|
|
space equ new+4
|
|
|
|
q equ space+2
|
|
|
|
p equ q+4
|
|
|
|
end equ p+4
|
|
|
|
|
|
|
|
tsc
|
|
|
|
sec
|
|
|
|
sbc #space-1
|
|
|
|
tcs
|
|
|
|
phd
|
|
|
|
tcd
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
pei (p+2)
|
|
|
|
pei (p)
|
|
|
|
jsr cstrlen
|
|
|
|
pha
|
|
|
|
pei (q+2)
|
|
|
|
pei (q)
|
|
|
|
jsr cstrlen
|
|
|
|
adc 1,s
|
|
|
|
inc a
|
|
|
|
inc a
|
|
|
|
plx
|
|
|
|
pea 0
|
|
|
|
pha
|
1998-08-03 17:30:30 +00:00
|
|
|
~NEW
|
1997-11-18 05:31:00 +00:00
|
|
|
sta new
|
|
|
|
stx new+2
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
copy1 lda [p],y
|
|
|
|
and #$FF
|
|
|
|
beq copy2
|
|
|
|
sta [new],y
|
|
|
|
iny
|
|
|
|
bra copy1
|
|
|
|
copy2 lda [q]
|
|
|
|
and #$FF
|
|
|
|
sta [new],y
|
|
|
|
beq done
|
|
|
|
iny
|
1998-07-20 16:23:11 +00:00
|
|
|
incad q
|
1997-11-18 05:31:00 +00:00
|
|
|
bra copy2
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
done ldx new+2
|
1997-11-18 05:31:00 +00:00
|
|
|
ldy new
|
1998-09-08 16:53:14 +00:00
|
|
|
lda space
|
|
|
|
sta end-2
|
|
|
|
pld
|
|
|
|
tsc
|
|
|
|
clc
|
|
|
|
adc #end-3
|
|
|
|
tcs
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
tya
|
|
|
|
rts
|
1997-11-18 05:31:00 +00:00
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
END
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
;=====================================================================
|
|
|
|
;
|
|
|
|
; call ~DISPOSE if pointer is not NULL
|
|
|
|
;
|
|
|
|
;=====================================================================
|
|
|
|
|
|
|
|
nullfree START
|
1998-09-08 16:53:14 +00:00
|
|
|
|
Changes for gsh version 2.0d8:
Fixed several mutual exclusion problems, including a particularly nasty
one that would cause gsh to loop forever inside the memory manager. (You
could identify this one by the "BRA (-23)" at the bottom of the infinite
loop.)
Fixed the string vector print routine to properly handle all numbers of
entries in the hash table. Previously, it would always print duplicate
entries if there were < 6 commands hashed, and would sometimes print
duplicates (depending on previous contents of an internal table) for
other numbers of commands.
gsh would wait on background processes started from an exec file
(executed, not sourced). Now the exec file does not wait on the process,
but the background process is not associated with the parent shell after
the exec file terminates.
Made gsh globbing work more like csh: if none of the requested patterns
are found, print "No match" and exit.
At startup, if /etc/glogin, $HOME/glogin, or $HOME/gshrc does not exist,
don't report a "file not found" error message. (PR#100)
1998-12-31 18:29:14 +00:00
|
|
|
lda 4,s Hold address
|
|
|
|
tay parameter in
|
|
|
|
lda 6,s X and Y registers.
|
|
|
|
tax
|
|
|
|
lda 2,s Move return
|
|
|
|
sta 6,s address on
|
|
|
|
lda 1,s the stack.
|
1997-11-18 05:31:00 +00:00
|
|
|
sta 5,s
|
Changes for gsh version 2.0d8:
Fixed several mutual exclusion problems, including a particularly nasty
one that would cause gsh to loop forever inside the memory manager. (You
could identify this one by the "BRA (-23)" at the bottom of the infinite
loop.)
Fixed the string vector print routine to properly handle all numbers of
entries in the hash table. Previously, it would always print duplicate
entries if there were < 6 commands hashed, and would sometimes print
duplicates (depending on previous contents of an internal table) for
other numbers of commands.
gsh would wait on background processes started from an exec file
(executed, not sourced). Now the exec file does not wait on the process,
but the background process is not associated with the parent shell after
the exec file terminates.
Made gsh globbing work more like csh: if none of the requested patterns
are found, print "No match" and exit.
At startup, if /etc/glogin, $HOME/glogin, or $HOME/gshrc does not exist,
don't report a "file not found" error message. (PR#100)
1998-12-31 18:29:14 +00:00
|
|
|
tya Put address
|
|
|
|
sta 1,s parameter back
|
|
|
|
txa on the stack.
|
|
|
|
sta 3,s
|
|
|
|
|
|
|
|
ora 1,s If address is NULL,
|
|
|
|
bne ok
|
|
|
|
plx clean up stack
|
1997-11-18 05:31:00 +00:00
|
|
|
plx
|
Changes for gsh version 2.0d8:
Fixed several mutual exclusion problems, including a particularly nasty
one that would cause gsh to loop forever inside the memory manager. (You
could identify this one by the "BRA (-23)" at the bottom of the infinite
loop.)
Fixed the string vector print routine to properly handle all numbers of
entries in the hash table. Previously, it would always print duplicate
entries if there were < 6 commands hashed, and would sometimes print
duplicates (depending on previous contents of an internal table) for
other numbers of commands.
gsh would wait on background processes started from an exec file
(executed, not sourced). Now the exec file does not wait on the process,
but the background process is not associated with the parent shell after
the exec file terminates.
Made gsh globbing work more like csh: if none of the requested patterns
are found, print "No match" and exit.
At startup, if /etc/glogin, $HOME/glogin, or $HOME/gshrc does not exist,
don't report a "file not found" error message. (PR#100)
1998-12-31 18:29:14 +00:00
|
|
|
rtl and return to caller.
|
|
|
|
|
|
|
|
ok ~DISPOSE NOTE: macro locks/unlocks mem mutex
|
|
|
|
|
1997-11-18 05:31:00 +00:00
|
|
|
rtl
|
|
|
|
|
Changes for gsh version 2.0d8:
Fixed several mutual exclusion problems, including a particularly nasty
one that would cause gsh to loop forever inside the memory manager. (You
could identify this one by the "BRA (-23)" at the bottom of the infinite
loop.)
Fixed the string vector print routine to properly handle all numbers of
entries in the hash table. Previously, it would always print duplicate
entries if there were < 6 commands hashed, and would sometimes print
duplicates (depending on previous contents of an internal table) for
other numbers of commands.
gsh would wait on background processes started from an exec file
(executed, not sourced). Now the exec file does not wait on the process,
but the background process is not associated with the parent shell after
the exec file terminates.
Made gsh globbing work more like csh: if none of the requested patterns
are found, print "No match" and exit.
At startup, if /etc/glogin, $HOME/glogin, or $HOME/gshrc does not exist,
don't report a "file not found" error message. (PR#100)
1998-12-31 18:29:14 +00:00
|
|
|
END
|
1997-11-18 05:31:00 +00:00
|
|
|
|
Changes for gsh version 2.0d8:
Fixed several mutual exclusion problems, including a particularly nasty
one that would cause gsh to loop forever inside the memory manager. (You
could identify this one by the "BRA (-23)" at the bottom of the infinite
loop.)
Fixed the string vector print routine to properly handle all numbers of
entries in the hash table. Previously, it would always print duplicate
entries if there were < 6 commands hashed, and would sometimes print
duplicates (depending on previous contents of an internal table) for
other numbers of commands.
gsh would wait on background processes started from an exec file
(executed, not sourced). Now the exec file does not wait on the process,
but the background process is not associated with the parent shell after
the exec file terminates.
Made gsh globbing work more like csh: if none of the requested patterns
are found, print "No match" and exit.
At startup, if /etc/glogin, $HOME/glogin, or $HOME/gshrc does not exist,
don't report a "file not found" error message. (PR#100)
1998-12-31 18:29:14 +00:00
|
|
|
;=====================================================================
|
|
|
|
;
|
|
|
|
; Data area that holds memory manager mutual exclusion key,
|
|
|
|
; which is referenced in the ~NEW and ~DISPOSE macros
|
|
|
|
;
|
|
|
|
;=====================================================================
|
|
|
|
memglobal DATA
|
|
|
|
memmutex key
|
1997-11-18 05:31:00 +00:00
|
|
|
END
|
|
|
|
|
|
|
|
;=====================================================================
|
|
|
|
;
|
|
|
|
; Print a carriage return and a newline, unless "newline" shell var
|
|
|
|
; is set.
|
|
|
|
;
|
|
|
|
;=====================================================================
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
newlineX START
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
using vardata
|
|
|
|
|
|
|
|
lda varnewline
|
|
|
|
beq newline
|
1998-09-08 16:53:14 +00:00
|
|
|
rts
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
;=====================================================================
|
|
|
|
;
|
|
|
|
; Print a carriage return and a newline
|
|
|
|
;
|
|
|
|
;=====================================================================
|
|
|
|
|
1998-09-08 16:53:14 +00:00
|
|
|
newline ENTRY
|
1997-11-18 05:31:00 +00:00
|
|
|
|
|
|
|
lda #13
|
|
|
|
jmp putchar
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
**************************************************************************
|
|
|
|
*
|
|
|
|
* Quick little routine for reading variables and converting to
|
|
|
|
* null terminated strings. We could probably just link the Orca/C
|
|
|
|
* library getenv(), but lets stay Orca-free, after all, that's why this
|
|
|
|
* is written in assembly! :)
|
|
|
|
*
|
1998-07-20 16:23:11 +00:00
|
|
|
* For gsh 2.0: pass in addr of a GS/OS string, and pass back addr of
|
1998-12-21 23:57:08 +00:00
|
|
|
* allocated GS/OS result buffer (with null byte added at end), not c-strings.
|
1997-11-18 05:31:00 +00:00
|
|
|
*
|
|
|
|
**************************************************************************
|
|
|
|
|
|
|
|
getenv START
|
1998-09-08 16:53:14 +00:00
|
|
|
|
1998-07-20 16:23:11 +00:00
|
|
|
len equ 1
|
|
|
|
retval equ len+2
|
1997-11-18 05:31:00 +00:00
|
|
|
space equ retval+4
|
|
|
|
var equ space+3
|
|
|
|
end equ var+4
|
|
|
|
|
|
|
|
; subroutine (4:var),space
|
|
|
|
|
|
|
|
tsc
|
|
|
|
sec
|
|
|
|
sbc #space-1
|
|
|
|
tcs
|
|
|
|
phd
|
|
|
|
tcd
|
|
|
|
|
|
|
|
lock mutex
|
|
|
|
;
|
1998-07-20 16:23:11 +00:00
|
|
|
; Get the variable's length using ReadVariableGS
|
|
|
|
; Set up parameter block:
|
|
|
|
mv4 var,RVname Addr of name, from user.
|
1998-09-08 16:53:14 +00:00
|
|
|
ld4 TempResultBuf,RVresult Use temporary result buf.
|
1998-07-20 16:23:11 +00:00
|
|
|
ReadVariableGS ReadVar Get length.
|
1997-11-18 05:31:00 +00:00
|
|
|
;
|
1998-07-20 16:23:11 +00:00
|
|
|
; Allocate memory for value string
|
1997-11-18 05:31:00 +00:00
|
|
|
;
|
1998-07-20 16:23:11 +00:00
|
|
|
lda TempRBlen Get length of value.
|
|
|
|
bne notnull Return null if 0.
|
|
|
|
sta retval
|
|
|
|
sta retval+2
|
|
|
|
bra exit
|
|
|
|
|
|
|
|
notnull inc2 a Add 4 bytes for result buf len words.
|
|
|
|
inc2 a
|
|
|
|
sta len Save result buf len.
|
|
|
|
inc a Add 1 more for terminating null byte.
|
1997-11-18 05:31:00 +00:00
|
|
|
pea 0
|
|
|
|
pha
|
1998-08-03 17:30:30 +00:00
|
|
|
~NEW Request the memory.
|
1998-07-20 16:23:11 +00:00
|
|
|
sta RVresult Store address in ReadVariable
|
|
|
|
stx RVresult+2 parameter block and
|
|
|
|
sta retval direct page pointer.
|
1997-11-18 05:31:00 +00:00
|
|
|
stx retval+2
|
1998-07-20 16:23:11 +00:00
|
|
|
ora retval+2 If address == NULL,
|
|
|
|
beq exit return NULL to user.
|
|
|
|
|
|
|
|
lda len Store result buffer length
|
|
|
|
sta [retval] at beginning of buf.
|
1997-11-18 05:31:00 +00:00
|
|
|
;
|
1998-07-20 16:23:11 +00:00
|
|
|
; Read the full value into the allocated memory
|
1997-11-18 05:31:00 +00:00
|
|
|
;
|
1998-07-20 16:23:11 +00:00
|
|
|
ReadVariableGS ReadVar
|
|
|
|
;
|
|
|
|
; Add null byte at end of text to make it work as a C string
|
|
|
|
;
|
|
|
|
ldy TempRBlen Get length of value,
|
|
|
|
iny4 + 4 (for length words at start)
|
|
|
|
lda #0 Store zero at end of string.
|
|
|
|
short a
|
1997-11-18 05:31:00 +00:00
|
|
|
sta [retval],y
|
1998-07-20 16:23:11 +00:00
|
|
|
long a
|
1997-11-18 05:31:00 +00:00
|
|
|
;
|
1998-07-20 16:23:11 +00:00
|
|
|
; All done.
|
1997-11-18 05:31:00 +00:00
|
|
|
;
|
|
|
|
exit unlock mutex
|
1998-07-20 16:23:11 +00:00
|
|
|
|
1997-11-18 05:31:00 +00:00
|
|
|
ldy retval
|
|
|
|
ldx retval+2
|
1998-07-20 16:23:11 +00:00
|
|
|
|
1997-11-18 05:31:00 +00:00
|
|
|
lda space+1
|
|
|
|
sta end-2
|
|
|
|
lda space
|
|
|
|
sta end-3
|
|
|
|
pld
|
|
|
|
tsc
|
|
|
|
clc
|
|
|
|
adc #end-4
|
|
|
|
tcs
|
|
|
|
tya
|
|
|
|
|
|
|
|
rtl
|
1998-09-08 16:53:14 +00:00
|
|
|
|
1997-11-18 05:31:00 +00:00
|
|
|
mutex key
|
|
|
|
|
1998-07-20 16:23:11 +00:00
|
|
|
; Parameter block for shell ReadVariableGS call (p 423 in ORCA/M manual)
|
|
|
|
ReadVar anop
|
|
|
|
dc i2'3' pCount
|
|
|
|
RVname ds 4 Pointer to name (passed by user)
|
|
|
|
RVresult ds 4 GS/OS Output buffer ptr
|
|
|
|
RVexpflag ds 2 export flag
|
|
|
|
|
|
|
|
; GS/OS result buffer for getting the full length of the PATH env var.
|
|
|
|
TempResultBuf dc i2'5' Only five bytes total.
|
|
|
|
TempRBlen ds 2 Value's length returned here.
|
|
|
|
ds 1 Only 1 byte for value.
|
|
|
|
|
1997-11-18 05:31:00 +00:00
|
|
|
END
|
|
|
|
|
1998-12-21 23:57:08 +00:00
|
|
|
**************************************************************************
|
|
|
|
*
|
|
|
|
* Copy src bytes to destination address
|
|
|
|
*
|
|
|
|
**************************************************************************
|
|
|
|
|
1997-11-18 05:31:00 +00:00
|
|
|
rmemcpy START
|
|
|
|
subroutine (2:num,4:src,4:dest),0
|
|
|
|
|
1998-12-21 23:57:08 +00:00
|
|
|
ldy num Get length of src.
|
|
|
|
beq done Done if == 0.
|
1997-11-18 05:31:00 +00:00
|
|
|
tya
|
|
|
|
dey
|
|
|
|
bit #1
|
|
|
|
bne odd
|
|
|
|
dey
|
|
|
|
bra lp1
|
|
|
|
odd short m
|
|
|
|
lda [src],y
|
|
|
|
sta [dest],y
|
|
|
|
long m
|
|
|
|
dey
|
|
|
|
dey
|
|
|
|
bmi done
|
|
|
|
lp1 lda [src],y
|
|
|
|
sta [dest],y
|
|
|
|
dey
|
|
|
|
dey
|
1998-09-08 16:53:14 +00:00
|
|
|
bpl lp1
|
1997-11-18 05:31:00 +00:00
|
|
|
done return
|
|
|
|
END
|