/ PROGRAM Int ;Mp main program (with files) dquote=42 space=40 esc=33 cr=15 .mcall gmcr$,dir$,exst$s,fsrsz$ inflag: .word 0 outflag: .word 0 argv: .blkw 30. ;allow 30 args argvp: .word 0 ;pointer to next argv to stuff argc: .word 0 ;assume no args gcmd: gmcr$ data=gcmd+g.mcrb ;address of the data in the buffer. .even .blkw 3 ;just for safety at end of buffer. length: .word 0 ;dsw returned from g mcr line. gp: .word data ;point to the data (getc pointer) moreln: .word flag1: .word fa: .word ;file address (of the string) access: .word .even start: setd seti ;for C programs call m extern argv,argvp,argc,gcmd,length,gp,moreln,flag1,fa,$dsw e%s r0 10 function m is local clr argc ;initialize it anyway dir$ #gcmd ;get the command line mov $dsw,length ;and length (or error indicator) IF length GT #0 ;should be pos if a line there. BEGIN CODE ;so it will reach mov #argv+2,argvp ;init arg pointer mov #data,argv ;set first one manually clr moreln clr flag1 LET r0 = length + #data ;end of cmd line (-> to cr) IFB -1(r0) = #space dec r0 FI movb #cr,(r0)+ ;extra cr at end (or kill last blank) movb #cr,(r0)+ movb #cr,(r0)+ DO WHILE moreln = #0 Call getc ;get char into r0 SELECT case r0 of CASEB #76 ;> red stdout call skipfile mov r0,fa outflag := 1 if cs call ppp fi IFB @fa = #76 ;>> access := "append" br red1 elseifb @fa = #'= ;>= access := "update" red1: inc fa ;skip = if bopen[stdout,fa,access,"rsx"] ne 1 jmp nofile fi ELSE ;reg create if bopen[stdout,fa,"write","rsx"] ne 1 jmp nofile fi FI BREAK CASEB #74 ;< red stdin call skipfile ;skip over file, r0 gets string addr. mov r0,fa inflag := 1 if cs fi bopen[stdin,fa,"read","rsx"] if r0 ne 1 jmp nofile fi BREAK CASEB #dquote call getc ;eat up a char call argstart ;start pointer after the " call ungetc ;backup now DO FOREVER call getc IFB r0 = #dquote OR r0 = #esc OR r0 = #cr BREAK FI OD IF r0 = #dquote call delim1 call getc ELSE call delim1 FI BREAK CASE #space ;Space call delim1 inc flag1 call getc ;look ahead one for the end call ungetc ;put it back IF r0 = #cr OR r0 = #esc inc moreln ;done call delim ;put the delimiter there BREAK FI BREAK CASE #cr ;cr inc moreln call delim1 BREAK CASE #esc ;esc inc moreln call delim1 BREAK DEFAULT IF flag1 NE #0 call argstart clr flag1 FI ESAC OD END CODE FI IF argc GT #0 mov argc,r0 ;this is the last parm is null fixup kludge asl r0 add #argv-2,r0 mov (r0),r0 ;get address of beginning of last arg IFB (r0) = #0 dec argc FI FI if inflag = 0 bopen[stdin,"ti:","read","rsx"] fi if outflag = 0 bopen[stdout,"ti:","write","rsx"] fi main[argc,#argv] ;call user mov r0,r4 endup: bclose[stdin] bclose[stdout] exst$s r4 ppp: rts pc getc: ;get a char movb @gp,r0 bic #177600,r0 ;7 bit ascii inc gp ;next pointer rts pc ungetc: ;put back 1 char dec gp rts pc delim1: ;make delim a null and incr argc inc argc delim: ;make delim a null push r0 mov gp,r0 ;get pointer to delim+1 clrb -1(r0) ;and clear delim position pop r0 rts pc argstart: ;set pointer to start of arg push r0 LET r0 = gp - #1 mov r0,@argvp add #2,argvp ;update to next position pop r0 rts pc skipfile: ;skip to end of file name push r3 mov gp,r3 ;save address of string beginning DO FOREVER ;loop till done call getc IF r0 = #space OR r0 = #cr OR r0 = #esc ;any end char BREAK FI OD call delim IF r0 NE #space ;check for last arg inc moreln ;and end scan up top FI mov r3,r0 ;set return pop r3 rts pc nofile: mov #4,r4 jmp endup i%dout .end start