Added startup protocol as requested by Devin Reed (PR#78) and Steve Reeves

(PR#85, PR#86):
   For login shells (command line starts with '-'),
	If $PATH doesn't start with ':' or contain a space,
	   change all ":" to " ".
	source /etc/glogin
	source $HOME/glogin
$HOME/gshrc is sourced afterward for both login and non-login shells.

Don't the print number of hashed commands (from "rehash") until all
initialization is completed.

Only pass exported environment variables to child processes, and prevent child
processes from changing parent's environment.

A null command followed by a redirection of stdout, for example
  > /tmp/list
would cause an error message "<garbage> not found" due to incorrect
setting of command buffer pointer.

Filename completion did not work following ">&" or ">" without a trailing
space.

Entabbed all the asm files, saving more than 36,000 bytes.
This commit is contained in:
tribby 1998-09-08 16:53:14 +00:00
parent 2e0ebb5392
commit 1dc5497309
24 changed files with 2868 additions and 2690 deletions

View File

@ -1,6 +1,43 @@
GSH 2.0 UPDATES
^^^^^^^^^^^^^^^
Sep 7 98 [dmt] Changes to this point checked-in to master archive.
Sep 7 98 [dmt] In "gettoken" (cmd.asm), decrement buf (pointer to
command line) when EOL is reached; otherwise if the character
following the command in the buffer is non-zero, the garbage
after the real command will be interpreted as another command.
Test case: "> /tmp/list" would cause "not found" error message.
Sep 6 98 [dmt] Added startup protocol as requested by Devin Reed
(PR#78) and Steve Reeves (PR#85, PR#86):
For login shells (command line starts with '-'),
If $PATH doesn't start with ':' or contain a space,
change all ":" to " ".
source /etc/glogin
source $HOME/glogin
($HOME/gshrc is sourced afterward for both login and non-login).
In rehash built-in command, don't the print number of hashed
until all initialization is completed.
Restored commented-out PushVariablesGS at start of "shell" in
shell.asm to keep subshells from changing parent's environment.
Aug 4 98 [dmt] Fixed defects in wordmatch (edit.asm) related to
recognizing commands versus filenames during tab and ctrl-D
filename completion. Suppose there is a file "filename" in the
current directory and you enter one of the following:
command >& filen
command >filen
and press tab. Instead of getting filename completion, you
would get a beep. In the first case, gsh thought the "&"
was putting the command in the background and filen was the
beginning of a command name rather than a filename. In the
second, gsh included the ">" in the filename match pattern.
Aug 3 98 [dmt] Entabbed all the asm files (saved >36,000 bytes).
Aug 3 98 [dmt] Changes to this point checked-in to master archive.
Aug 2 98 [dmt] Remove alloc256/free256 and associated data. Replace
with fixed 64-byte buffer for command filename (hash.asm)
and allocation of 261-byte buffer via ~NEW for shell

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: alias.asm,v 1.5 1998/08/03 17:30:25 tribby Exp $
* $Id: alias.asm,v 1.6 1998/09/08 16:53:05 tribby Exp $
*
**************************************************************************
*
@ -343,7 +343,8 @@ space equ buf+4
stx word+2
sta word
lda #0
sta [buf] ;In case we're called with empty string
sta [buf] In case we're called with empty string
sta [word]
;
; eat leading spaces
;

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: bufpool.asm,v 1.4 1998/08/03 17:30:26 tribby Exp $
* $Id: bufpool.asm,v 1.5 1998/09/08 16:53:05 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: builtin.asm,v 1.5 1998/08/03 17:30:26 tribby Exp $
* $Id: builtin.asm,v 1.6 1998/09/08 16:53:05 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: cmd.asm,v 1.5 1998/08/03 17:30:27 tribby Exp $
* $Id: cmd.asm,v 1.6 1998/09/08 16:53:07 tribby Exp $
*
**************************************************************************
*
@ -130,8 +130,9 @@ loop lda [buf]
if2 state,ne,#INWORD,loop2
jmp endword state INWORD: end the word.
loop2 if2 @a,ne,#GTGT,loop3
dec buf
loop2 anop
dec buf Went too far: back up pointer.
if2 @a,ne,#GTGT,loop3
lda #T_GT state GTGT: return single GT.
jmp done
@ -1100,7 +1101,7 @@ end equ cmdline+4
lda cmdline+2
sta cmdstrt+2
; Remove leading whitespace
; Skip over leading whitespace
chkws lda [cmdstrt] Get next character.
and #$FF

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: dir.asm,v 1.5 1998/08/03 17:30:27 tribby Exp $
* $Id: dir.asm,v 1.6 1998/09/08 16:53:07 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: edit.asm,v 1.5 1998/08/03 17:30:28 tribby Exp $
* $Id: edit.asm,v 1.6 1998/09/08 16:53:08 tribby Exp $
*
**************************************************************************
*
@ -73,6 +73,8 @@ kill_end_of_line gequ 19
toggle_cursor gequ 20
delete_char gequ 21
WORDGS_SIZE gequ 256 Size of buffer for word search
**************************************************************************
*
* get a command line from the user
@ -976,72 +978,90 @@ wordmatch START
using hashdata
using BuiltInData
lda #'/'
lda #'/' Default separator is "/".
sta sepstyle
ldx #0 ;for left counter
ldy cmdloc
beq atstart
lda cmdline,y ;if current char is space then
and #$FF ;char to left must be non-space
cmp #' '
bne findstart2
lda cmdline-1,y
and #$FF
ldx #0 Keep track of left moves in X-reg.
ldy cmdloc Y-reg = position on line.
beq atstart If 0, can't go any further.
lda cmdline,y If current
and #$FF character is
cmp #' ' space, and
bne findstart2 the one before
lda cmdline-1,y it is also a
and #$FF space,
cmp #' '
bne findstart
jmp beep
jmp beep beep at the user.
;
; move backwards to find start of word to expand
; Move backwards to find start of word to expand
;
findstart inx
dey
beq atstart
findstart2 lda cmdline-1,y
and #$FF
cmp #';'
beq atstart
cmp #'|'
findstart inx Count # of times we've moved left.
dey Decrement the buffer index.
beq atstart Done if all the way to start.
findstart2 lda cmdline-1,y Get the previous
and #$FF character.
cmp #';' Compare against shell
beq atstart characters that
cmp #'|' indicate a word break.
beq atstart
cmp #'&'
beq atstart
cmp #'>'
beq atstart
cmp #'<'
beq atstart
cmp #' '
bne findstart
bne findstart Stay in loop until one is found.
;
; isolate the word
; Y-reg points to start, X-reg contains number of positions to cursor.
; Search forward to isolate the current word.
;
atstart sty startpos
stx dir+1
stx dir+1 Ugh! Self-modifying code!!
ldx #0
isolate cpy cmdlen
beq gotiso
lda cmdline,y
and #$FF
cmp #' '
beq gotiso
isolate cpy cmdlen If at end of line,
beq gotiso cannot go any further.
lda cmdline,y Isolate the next character.
and #$FF Compare against shell
cmp #' ' characters that
beq gotiso indicate a word break.
cmp #';'
beq gotiso
cmp #'|'
beq gotiso
cmp #'&'
beq gotiso
sta wordgs_text,x
iny
inx
bra isolate
gotiso lda #0
sta wordgs_text,x
stx wordlen
sty cmdloc
cmp #'>'
beq gotiso
cmp #'<'
beq gotiso
sta wordgs_text,x Accumulate chars in comparison buffer.
iny Bump character index.
inx Bump number of chars in word.
cmp #WORDGS_SIZE-2 If we haven't filled the buffer,
bcc isolate keep accumulating characters.
jmp beep Otherwise, beep at the user.
;
; We've isolated the word in wordgs_text. X-reg = # of characters
; and Y-reg is the column number of the final character.
;
gotiso lda #0 Terminate string with
sta wordgs_text,x null byte.
stx wordlen Save length and
sty cmdloc position on input line.
txa
sec
dir sbc #0
sec Subtract the number of
dir sbc #0-0 character to original cursor.
beq nomove
tax
jsr moveright
jsr moveright Move cursor to end of word.
nomove anop
;
; start finding matches
; Look for a match: either a command (if word is in first position),
; a filename in the current directory, or a variable name.
;
stz nummatch
;
@ -1049,41 +1069,58 @@ nomove anop
; accurate...it should serve its purpose well at least.
;
lda #1
sta cmdflag ;first, assume it's a command
ldy startpos
beq gotflag
dey
beq gotflag
sta cmdflag Assume it's a command (flag=1).
ldy startpos If starting position
beq gotflag is 0
dey or 1,
beq gotflag it's a command.
flagskip lda cmdline,y
and #$FF
cmp #' '
bne chkflag
dey
flagskip lda cmdline,y Keep fetching previous
and #$FF characters until
cmp #' ' a non-space is
bne chkflag found, or we run
dey back to the beginning.
bpl flagskip
bra gotflag
;
; We've got the first non-space character before the word in question.
; If it's a meta- character indicating the end of a command, this must
; be the beginning of a new command. Otherwise it's an argument.
;
chkflag cmp #';'
beq gotflag
cmp #'|'
beq gotflag
; NOTE: & can be a command terminator, but also part of >& or >>&
cmp #'&'
beq gotflag
stz cmdflag
bne isarg Not "&"; must be an argument.
cpy #0 If at start of line (unusual for &!)
beq gotflag it must be a command.
lda cmdline-1,y Get character in front of "&".
cmp #'&>' Anything except '>'
bne gotflag means we've got a command.
isarg stz cmdflag Argument: cmdflag = 0.
;
; Now that we've established whether we're looking for a command or an
; argument, see if we're looking for a file name or a variable name
;
gotflag anop
;
; Check if the first character is '$', if so, match for variables ONLY
;
lda wordgs_text
and #$FF
cmp #'$'
jne filem
;
; The first character is '$': match for variables ONLY
;
ld2 1,idxIndex
varloop ReadIndexedGS idxParm
varloop ReadIndexedGS idxParm Get next variable name.
lda NameLen
beq vardone
cmp wordlen ;if shorter than word skip
cmp wordlen If shorter than word, skip
jcc nextvar
;
; Scan this variable name to see if it matches wordgs_text
@ -1101,7 +1138,7 @@ varscan lda wordgs_text,x
;
; We have a match between the variable name and word being typed
;
goodvar stz sepstyle Don't use ":" or "/"
goodvar stz sepstyle Don't use ":" or "/" separator.
gv02a anop
lda nummatch Get the number of matches.
@ -1143,7 +1180,8 @@ nextvar inc idxIndex
vardone rts Return from wordmatch
;
; Match by file names; start by moving wordgs_text + trailing "*" to a GS/OS string
; Match by file name wildcard; start by moving
; wordgs_text + trailing "*" to a GS/OS string
;
filem lda #1
sta iwFlags
@ -1198,7 +1236,7 @@ initit InitWildcardGS iwparm
filematch anop
NextWildcardGS nwparm
ldy NameLen Get length of name.
jeq filemdone
jeq filemdone If 0, there's no more to search.
cpy wordlen
beq filematch
@ -1294,8 +1332,8 @@ filemdone anop
;
; let's now look at the hashed files
;
p equ 0
q equ 4
p equ 0 Direct page
q equ 4 locations.
ldy wordlen ;remove '*' from above
lda #0
@ -1418,6 +1456,7 @@ bidone anop
done rts Return from wordmatch.
startpos ds 2
cmdflag ds 2
@ -1425,7 +1464,7 @@ cmdflag ds 2
; GS/OS string holding match word + wildcard "*"
;
wordgsbuf ds 2
wordgs_text ds 256
wordgs_text ds WORDGS_SIZE
;
; Parameter block for shell InitWildcardGS call (p 414 in ORCA/M manual)

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: expand.asm,v 1.5 1998/08/03 17:30:28 tribby Exp $
* $Id: expand.asm,v 1.6 1998/09/08 16:53:08 tribby Exp $
*
**************************************************************************
*

View File

@ -1,7 +1,7 @@
/*
* Resources for version and comment
*
* $Id: gsh.rez,v 1.4 1998/08/03 17:30:30 tribby Exp $
* $Id: gsh.rez,v 1.5 1998/09/08 16:53:09 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 */
3 }, /* non-final release number */
4 }, /* 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.5 1998/08/03 17:30:19 tribby Exp $
* $Id: hash.asm,v 1.6 1998/09/08 16:53:09 tribby Exp $
*
**************************************************************************
*
@ -1055,7 +1055,7 @@ filesdone anop
ph4 gsosbuf Free memory allocated for
jsl nullfree $PATH string.
lda hash_print If this is the first time,
lda hash_print If initialization isn't complete,
beq noprint don't print the # of files.
Int2Dec (hash_numexe,#hashnum,#3,#0)
@ -1063,7 +1063,7 @@ filesdone anop
lda #hashmsg
jsr puts
noprint ld2 1,hash_print Set print flag.
noprint anop
;
; Create the hash table from the file list.
@ -1166,6 +1166,6 @@ hash_paths dc 32i4'0' 32 paths max for now.
hash_files dc i4'0'
hash_table dc i4'0' Pointer to table (t_size entries)
hash_numexe dc i2'0' Number of hashed executables
hash_print dc i2'0' Print flag; 0 first time through
hash_print dc i2'0' Print flag; 0 until init is complete
END

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: history.asm,v 1.5 1998/08/03 17:30:20 tribby Exp $
* $Id: history.asm,v 1.6 1998/09/08 16:53:10 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: invoke.asm,v 1.6 1998/08/03 17:30:21 tribby Exp $
* $Id: invoke.asm,v 1.7 1998/09/08 16:53:10 tribby Exp $
*
**************************************************************************
*
@ -76,6 +76,7 @@ end equ sfile+4
tsc
phd
tcd
;
; Redirect standard input
;
@ -243,8 +244,8 @@ space equ dir+4
ora efile+2
beq nulldone
ldx #^hehstr print error message:
lda #hehstr ' specify a command before redirecting.'
ldx #^spcmdstr print error message:
lda #spcmdstr ' specify a command before redirecting.'
jsr errputs
nulldone jmp done
@ -737,8 +738,7 @@ _semaphore dc i2'0'
str dc c'[0]',h'0d00'
err1 dc c': Not executable.',h'0d00'
err2 dc c': Command not found.',h'0d00'
hehstr dc c'heh heh, next time you''ll need to specify a command '
dc c'before redirecting.',h'0d00'
spcmdstr dc c'Specify a command before redirecting.',h'0d00'
deadstr dc c'Cannot fork (too many processes?)',h'0d00' ;try a spoon

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: jobs.asm,v 1.5 1998/08/03 17:30:22 tribby Exp $
* $Id: jobs.asm,v 1.6 1998/09/08 16:53:10 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: main.asm,v 1.6 1998/08/03 17:30:22 tribby Exp $
* $Id: main.asm,v 1.7 1998/09/08 16:53:11 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: mmdebug.asm,v 1.3 1998/08/03 17:30:23 tribby Exp $
* $Id: mmdebug.asm,v 1.5 1998/12/21 23:57:07 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: orca.asm,v 1.5 1998/08/03 17:30:22 tribby Exp $
* $Id: orca.asm,v 1.6 1998/09/08 16:53:12 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: prompt.asm,v 1.5 1998/08/03 17:30:23 tribby Exp $
* $Id: prompt.asm,v 1.6 1998/09/08 16:53:12 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: shell.asm,v 1.5 1998/08/03 17:30:23 tribby Exp $
* $Id: shell.asm,v 1.6 1998/09/08 16:53:13 tribby Exp $
*
**************************************************************************
*
@ -29,7 +29,7 @@
* AppendHome subroutine (4:str)
* return 4:outPtr
*
* DoLogin jsr with no parameters
* Dogshrc jsr with no parameters
*
* signal2 subroutine (4:fubar)
*
@ -63,18 +63,20 @@ shell start
using pdata
using HistoryData
using termdata
using hashdata
p equ 0
space equ p+4
p equ 0 General pointer
cflag equ p+4 Flag: set when path converted
space equ cflag+2
subroutine (0:dummy),space
tsc Save stack pointer
sta cmdcontext in cmdcontext
tdc and direct page reg
sta cmddp ind cmddp.
sta cmddp in cmddp.
* PushVariables 0
PushVariablesGS NullPB Save environment variables.
Open ttyopen Open tty,
bcc settty checking for error.
@ -94,8 +96,8 @@ settty mv2 ttyref,gshtty
lda FastFlag If FastFlag is set,
bne fastskip1 skip copyright message.
lda gshpid ; only print the copyright msg
cmp #2 ; if not using login
lda gshpid Only print the copyright msg
cmp #2 if not using login
bne fastskip1
ldx #^gnostr
lda #gnostr
@ -119,17 +121,94 @@ fastskip1 anop
jsr initalias Set all AliasTable entries to 0.
jsr InitDStack Zero out directory stack.
jsr InitVars Set value of all env var flags.
;
; Check for login shell (argv[0] starts with '-')
;
mv4 ~COMMANDLINE,p Copy commandline addr to dir page.
ldy #8 Skip over shell identifier
lda [p],y to get first char of
and #$FF command name.
cmp #'-' If not '-',
bne nologin_init skip over login initialization.
; Change ":" to " " in $PATH if it doesn't start with ":" or contain a " "
ph4 #pathname Get $PATH environment variable string
jsl getenv
sta p Save address of allocated buffer.
stx p+2 in direct page variable
ora p+2 If null,
beq nopathconv no need to convert
stz cflag Initialize conversion flag = false.
ldy #4 Index over GS/OS length fields.
short m Use 8-bit mode.
lda [p],y
beq endpathconv If null string, or
cmp #':' if first character is ':',
beq endpathconv don't do the conversion.
bumpit iny
lda [p],y
beq endpathconv If at end of string, all done.
cmp #' ' If $PATH contains a space,
bne chkcolon
stz cflag abort the conversion.
bra endpathconv
chkcolon cmp #':' If next character is ':',
bne bumpit
lda #' ' change it to ' ', and
sta [p],y
sta cflag set conversion flag = true.
bra bumpit
endpathconv long m Back to 16-bit mode.
lda cflag If there was no conversion,
beq freepath skip the setting of $PATH.
clc Address of $PATH as a GS/OS
lda p output string is 2 bytes
adc #2 beyond the input string
sta SetValue starting address.
lda p+2
adc #0
sta SetValue+2
SetGS SetPB Set $PATH to the converted value.
freepath ph4 p Free the $PATH C string.
jsl nullfree
nopathconv anop
; Read and execute /etc/glogin
ph4 #etcglogin path = "/etc/glogin"
lda #0
pha argc = 0
pha argv = NULL
pha
pha jobflag = 0
jsl ShellExec
; Read and execute $HOME/glogin
jsr Doglogin
;
; Initialization that is not specific to login shells
;
nologin_init anop
lda FastFlag If fast startup flag isn't set,
bne fastskip2
jsr InitHistory Init: historyFN->"$HOME/history",
jsr ReadHistory read in history from disk,
jsr DoLogin and read $HOME/gshrc.
jsr Dogshrc and read $HOME/gshrc.
jsr newline
fastskip2 anop
lda didReadTerm
bne didit
jsr readterm
didit jsl hashpath ;hash $path
didit anop
jsl hashpath Hash $PATH.
ld2 1,hash_print Set hash print flag.
;
; Check for command-line arguments -c and -e
@ -164,6 +243,19 @@ cmdskip lda ExecFlag
jsl Execute
jmp done1
;
; Parameter block for shell SetGS calls (p 427 in ORCA/M manual)
;
SetPB dc i2'3' pCount
dc i4'pathname' Name (pointer to GS/OS string)
SetValue ds 4 Value (pointer to GS/OS string)
dc i2'1' Export flag
pathname gsstr 'path' GS/OS string
etcglogin dc c'/etc/glogin',h'00'
execskip anop
****************************************************************
@ -265,10 +357,17 @@ lastabort ds 2
;
;=========================================================================
DoLogin START
Dogshrc START
ph4 #gshrcName
jsl AppendHome
bra doit
; Alternate entry point: execute $HOME/glogin
Doglogin ENTRY
ph4 #gloginName
doit jsl AppendHome
phx Save pointer to GS/OS input
pha string for later.
@ -301,6 +400,7 @@ no_undf phx
rts
gshrcName dc c'/gshrc',h'00'
gloginName dc c'/glogin',h'00'
END
@ -449,7 +549,7 @@ ReadVar anop
RVresult ds 4 GS/OS Output buffer ptr
ds 2 export flag (returned)
;
; GS/OS result buffer for getting the full length of the PATH env var.
; GS/OS result buffer for getting the full length of the HOME env var.
;
TempResultBuf dc i2'5' Only five bytes total.
TempRBlen ds 2 Value's length returned here.

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: shellutil.asm,v 1.5 1998/08/03 17:30:24 tribby Exp $
* $Id: shellutil.asm,v 1.6 1998/09/08 16:53:13 tribby Exp $
*
**************************************************************************
*

View File

@ -7,7 +7,7 @@
* Tim Meekins
* Derek Taubert
*
* $Id: shellvar.asm,v 1.5 1998/08/03 17:30:24 tribby Exp $
* $Id: shellvar.asm,v 1.6 1998/09/08 16:53:13 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: stdio.asm,v 1.4 1998/08/03 17:30:24 tribby Exp $
* $Id: stdio.asm,v 1.5 1998/09/08 16:53:14 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: sv.asm,v 1.5 1998/08/03 17:30:25 tribby Exp $
* $Id: sv.asm,v 1.6 1998/09/08 16:53:14 tribby Exp $
*
**************************************************************************
*

View File

@ -6,7 +6,7 @@
* Jawaid Bazyar
* Tim Meekins
*
* $Id: term.asm,v 1.5 1998/08/03 17:30:25 tribby Exp $
* $Id: term.asm,v 1.6 1998/09/08 16:53:14 tribby Exp $
*
**************************************************************************
*