gno/bin/gsh/main.asm
tribby 01902c1b91 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

194 lines
3.4 KiB
NASM

**************************************************************************
*
* The GNO Shell Project
*
* Developed by:
* Jawaid Bazyar
* Tim Meekins
*
* $Id: main.asm,v 1.5 1998/07/20 16:23:08 tribby Exp $
*
**************************************************************************
*
* MAIN.ASM
* By Tim Meekins
* Modified by Dave Tribby for GNO 2.0.6
*
* Note: text set up for tabs at col 16, 22, 41, 49, 57, 65
* | | | | | |
* ^ ^ ^ ^ ^ ^
**************************************************************************
mcopy /obj/gno/bin/gsh/main.mac
setcom 60
**************************************************************************
; Segment for direct-page and stack
stack data STACK ; ends up in main.root
kind $12
; Define direct-page/stack and fill it with question marks it can be
; examined for how much is used.
dc 128c'??' ; 256 bytes
dc 128c'??' ; 512 bytes total
dc 128c'????' ; 1024 bytes total
dc 128c'????????' ; 2048 bytes total
end
**************************************************************************
init START
; Call the code to emulate C program startup:
; store Accumulator in ~USER_ID, X- and Y- registers as ~COMMANDLINE
; start up memory manager (~MM_INIT)
; parse commandline (via ~GNO_PARSEARG) and push argc and arvg on stack
jml ~GNO_COMMAND
; Control continues with the entry point "MAIN". When MAIN returns to
; ~GNO_COMMAND via rtl, it frees argv and argc before doing its own rtl.
END
MAIN START
using global
p equ 0
arg equ p+4
space equ arg+4
subroutine (2:argc,4:argv),space
kernStatus @a
bcc ok
ErrWriteCString #str
jmp done
ok stz FastFlag
stz CmdFlag
stz ExecFlag
; Parse gsh's command-line arguments.
argloop dec argc Decrement argument count.
beq go_start If none left, ready to start working.
clc
lda argv Point to next
adc #4 argument pointer.
sta argv
ldy #2
lda [argv] Set arg to point to
sta arg the argument text.
lda [argv],y
sta arg+2
lda [arg] Get first character
and #$FF of argument.
cmp #'-' If it's a "-",
beq intoption handle as an option.
; Parse remaining args as a command to run (in ExecCmd)
inc ExecFlag
inc FastFlag
ph4 #1024
jsl ~NEW
sta ExecCmd
sta p
stx ExecCmd+2
stx p+2
cmd3 ldy #0
cmd0 lda [arg],y
and #$ff
beq cmd1
sta [p],y
iny
bra cmd0
cmd1 lda #' '
sta [p],y
sec ;inc a
tya
adc p
sta p
dec argc
beq cmd2
clc
lda argv
adc #4
sta argv
ldy #2
lda [argv]
sta arg
lda [argv],y
sta arg+2
bra cmd3
cmd2 lda #0
sta [p]
go_start bra start
; Parse an argument as an option (first character is "-")
intoption ldy #1
optloop lda [arg],y
and #$FF
beq nextarg
cmp #'f'
beq optf
cmp #'c'
beq parsec
; Option is not recognized.
showusage ErrWriteCString #usage
bra done
; Option = "-f": Skip history, gshrc
optf inc FastFlag
nextopt iny
bra optloop
nextarg cpy #1
beq showusage
jmp argloop
; Option = "-c": execute shell commands found in file named by next argument
parsec clc
lda argv
adc #4
sta argv
dec argc
beq showusage
inc CmdFlag
inc FastFlag
mv4 argv,CmdArgV
mv2 argc,CmdArgC
;
; When preliminary setup is complete, control transfers to here!
;
start case on
jsl shell
case off
done return
str dc h'0d0a0a'
dc c'Before gsh may be run, the GNO/ME system, or kernel, must be running.'
dc h'0d0a0a00'
usage dc c'Usage: gsh [-cf] [argument...]',h'0d0a00'
END