;**************************************************************************
;
; CANTDO.M68    -       "Can't Do" Shell program
;
;       Written by:  Dave Heyliger - AMUS Staff
;
;       Purpose: To scan all keyboard input and make sure the
;                command entered is "aok" to perform. If a match
;                is found in the "can't do" list, then the user
;                "can't do" this command.
;
;       Usage: Entering in CANTDO from the dot will allow this JOB
;              to only do the commands that are NOT found in the
;              CANTDO list at the end of this source file. You may
;              "FORCE JOB CANTDO" from within AMOSL.INI as the last
;              command in the list of FORCEing if you want the user
;              to come up under the CANTDO shell upon boot.
;
;       IMPORTANT: if you have a user in the CANTDO shell, be sure
;                  the user "exits out" of the CANTDO shell before
;                  LOGOFF. You should create some simple command
;                  file called "BYE" or whatever, place this command
;                  file in the CMD: account, and have all users of
;                  CANTDO use this command file to log off the system.
;                  All this command file does is execute the two character
;                  "escape sequence" before executing the LOGOFF program.
;
;                  Example:    :S
;                              ~+
;                              :R
;                              LOGOFF
;
;                  It will also be up to you to figure out how you would
;                  like CANTDO to "come back up" on the JOB that has just
;                  performed the BYE command.
;
;**************************************************************************

       SEARCH  SYS                             ;standards....
       SEARCH  SYSSYM
       SEARCH  TRM

       VMAJOR=1                                ;original by Dave Heyliger
       VMINOR=0
       VEDIT=100

;DEFINE some useful macros...
;-----------------------------

DEFINE  PRTTAB  AA,BB
       PUSH    D1
       MOVB    #AA,D1
       LSLW    D1,#10
       MOVB    #BB,D1
       TCRT
       POP     D1
ENDM

DEFINE  CLRCTC                  ;clear out a ^C when user hits one (fool them)
       PUSH    A6              ;"black box"
       PUSH    D7
       JOBIDX  A6              ;A6 now contains pointer to JOBIDX (JOBSTS)
       MOVW    #J.CCC,D7       ;Reg. D7 contains ^C abort flag
       COMW    D7              ;logical one's complement (0->1 and 1->0)
       ANDW    D7,@A6          ;flag is now turned OFF
       POP     D7              ;restore originalS
       POP     A6
ENDM

DEFINE  CTC                     ;"set ctrlc"
       PUSH    A6              ;"black box"
       JOBIDX  A6              ;point to JOBIDX (JOBSTS)
       LEA     A6,JOBTYP(A6)   ;A6 points to JOBTYP word
       ORW     #J.CCA,@A6      ;^C set
       POP     A6              ;restore original
ENDM


       ;START OF PROGRAM HERE!
       ;set control C
       CTC                             ;set control C (just in case)

       ;perform the following loop over and over:
LOOP:   PRTTAB  -1,12.                  ;bright output
       TYPE    <.>                     ;simulate the AMOS dot
       KBD                             ;get the input
       CTRLC   HITCC                   ;go here if user executes a ^C
       TRM                             ;just a CR hit?
       BEQ     LOOP                    ;yup, type another dot

       ;user entered something other than just a CR. Setup pointers for scan
       LEA     A4,CANTDO               ;point A4 to commands not allowed
       LEA     A5,LSTEND               ;point A5 to end of the list
       PUSH    A2                      ;save the command line

       ;look for a match in the CANTDO list
LOOK:   CMP     A4,A5                   ;end of the list?
       JEQ     DOIT                    ;yup, they can do it
10$:    CMPB    (A2)+,(A4)+             ;look for letter match
       BNE     NMATCH                  ;if not equal, no match
       CMPB    @A4,#0                  ;at end of a cantdo command?
       BNE     10$                     ;nope, not yet

       ;matched a command in CANTDO, but at end of origianl command line?
       CMPB    @A2,#'/                 ;no slashes allowed
       BEQ     20$                     ;so go here if there is one
       CMPB    @A2,#40                 ;no spaces either
       BEQ     20$                     ;go here if so
       CMPB    @A2,#'[                 ;same goes for brackets
       BEQ     20$                     ;go here if so
       CMPB    @A2,#15                 ;at a CR on the original command line?
       BNE     NMATCH                  ;nope, no match!
20$:    POP     A2                      ;match! Adjust stack
       LEA     A2,NONO                 ;point to no-no message
       TTYL    @A2                     ;type it out
       JMP     LOOP                    ;and start ALL over.

       ;didn't find a match yet
NMATCH: MOV     @SP,A2                  ;point A2 back to original command
       JMP     LOOK                    ;and relook some more

       ;looked through the entire list, no match found, so do command.
       ;HOWEVER, see if user knows secret code to get out. If they entered
       ;the secret code, get them out of CANTDO. (original version is "~+"
       ;
       ;NOTE: to change the secret code (a two character sequence), simply
       ;      change the "~" and the "+" to any two funny characters you
       ;      want. If you then re-assemble this program, these two chars
       ;      will get you out of CANTDO.
       ;
DOIT:   POP     A2                      ;point to original command
       CMPB    @A2,#'~                 ;first exit character?
       BNE     10$                     ;nope
       CMPB    1(A2),#'+               ;second exit character?
       JEQ     EXIT                    ;if equal, get em out
10$:    AMOS                            ;else execute the command entered
       JMP     LOOP                    ;and start all over

       ;come here on a ^C
HITCC:  CLRCTC                          ;clear control C
       TYPECR  <^C>                    ;simulate a ^C
       JMP     LOOP                    ;and start again

       ;Error message can be anything you like. Original has "?What?"
NONO:   ASCII   /?What?/                ;error message
       BYTE    15,12,0                 ;CRLF null
       EVEN                            ;even out the next lable below


       ;Here is where you define all of the commands that users "can't do".
       ;For each command you want in the CANTDO list, enter in
       ;
       ;                       ASCIZ   /command/
       ;
       ;Make sure that the last item in the list is EVEN (right before the
       ;LSTEND: label. Every time you add a new command to the CANTDO list,
       ;you must re-assemble the program.
       ;
       ;Note: if you define a command such as DIR to be a can't do command,
       ;      then this program will not allow DIR, DIR/ etc. DIRSEQ will
       ;      be allowed, however. I hope you get my drift.
       ;
CANTDO: ASCIZ   /DIR/
       ASCIZ   /TYPE/
       ASCIZ   /SYSTAT/
       ASCIZ   /SYSTEM/
       EVEN
LSTEND: WORD    0

EXIT:   CRLF
       EXIT
       END