; IF.COM ; Utilitaire pour SUBMIT de soumission conditionnelle ; ; Mis au domaine public par: Robert Cabane ; 2 rue de la Pierre Levee 75011 PARIS ; ; Usage: IF ; Caractere de choix: ? pour afficher le message suivant suivi de: ( O/N ) ? ; et attendre au clavier O ou N ( Oui ou Non ) ; Caracteres de comparaison: = ( egalite ) et # ( difference ) ; Les deux chaines qui suivent, separees par un espace, sont comparees. ; La deuxieme chaine peut inclure le caractere ambigu: ? . Dans ce cas, le ; caractere correspondant de la premiere chaine n'est pas pris en compte. ; Caracteres d'existence: & ( existence ) et / ( non-existence ) ; Le fichier repondant au nom indique est recherche dans le Directory. ; Dans tous les cas, si l'action se termine sans succes, un code d'erreur est ; positionne; de sorte que la commande suivante, si elle commence par un : , ne ; sera pas executee. ; ; Exemple: IF # $1 $2 ; :REN XYZ.001=$1 ; IF & $2 ; :IF ?Ce fichier existe, effacement ; :ERA $2 ; IF / $1 ; :DIR ; ; NOTE: Les utilitaires du CP/M+ mettent un code d'erreur en cas d'erreur ; majeure ( par exemple, erreur physique, unite de disques inconnue...) ; Voir a ce sujet la fonction BDOS 45. ; Le compilateur BCPL de ARNOR met un code d'erreur en cas de compilation ; interrompue. ; ; Enhancements by Oliver Pretzel: ; To check the existence of a file in a different user area, follow the ; symbol & or / by the user number (if both are specified,user number ; must precede drive, but they can be separated by spaces). ; ; IF /0 M:pascal.com ; :pip M:=pascal.com ; ; The = # command has been enhanced to cope correctly with empty strings ; (previously it crashed). Thus IF = $1 will return an error code if $1 is ; defined, while IF = $1 $2 will return an error code if $1 but not $2 exists. ; ; IF also sets/unsets the user byte 6 in the SCB. A subsequent if can check ; this by using IF + (previous IF successful) and IF - (previous IF ; unsuccessful). Note that after a successful use of IF - you must continue ; with IF +. ; ; IF ?continue basic ; :pip M:= basic.com ; IF + ; :basic ; IF - ; :pip M:= pascal.com ; IF + ; :pascal ; .Z80 ; ; ORG 100H BDOS EQU 5 SCBGET EQU 49 ERRCOD EQU 108 START: LD HL,81H CALL SKIP LD DE,0 JP NC,ERREUR CP "?" JP Z,MESS CP "/" JP NZ,SUITE1 LD (NEGFLA),DE JP EXIST SUITE1: CP "&" JP Z,EXIST CP "#" JP NZ,SUITE2 LD (NEGFLA),DE JP EGAL SUITE2: CP "=" JP Z,EGAL CP "-" JP NZ,SUITE3 LD (NEGFLA),DE JP IFCONT SUITE3: CP "+" JP NZ,ERREUR ; IFCONT: ; tests whether previous if failed or not. LD C,SCBGET LD DE,SCBASK CALL BDOS OR A JP NZ,ERREUR SCF JP CODE ; ; Cas des caracteres = et # ( egaux ou differents ) ; EGAL: CALL SKIP1 LD B,0 JP NC,EMPT0 PUSH HL LOOP: LD A,(HL) OR A JP Z,ERR1 INC B INC HL CP " " JP NZ,LOOP DEC HL CALL SKIP JP NC,ERR1 LD C,0 PUSH HL LOOP2: LD A,(HL) INC C INC HL OR A JP Z,TRAITE CP " " JP NZ,LOOP2 ; TRAITE: LD A,C SUB B JP NZ,ERR2 POP DE POP HL DEC B LOOP3: LD A,(DE) CP "?" ; caractere ambigu JP Z,CONT CP (HL) JP NZ,ERREUR CONT: INC HL INC DE DJNZ LOOP3 EMPT0: SCF JP CODE ; ; Cas du caractere ? : message ; MESS: INC HL MESS1: LD A,(HL) OR A JP Z,OUI PUSH HL LD C,2 LD E,A CALL BDOS POP HL INC HL JP MESS1 OUI: LD DE,OUINON LD C,9 CALL BDOS TEST: LD C,1 CALL BDOS CP "N" JP Z,ERREUR CP "n" JP Z,ERREUR CP 3 ; CTRL-C JP Z,ERREUR CP "Y" JP Z,OK CP "y" JP NZ,TEST OK: SCF JR CODE ; ERR2: POP HL ERR1: POP HL ERREUR: OR A ; Carry=0 CODE: LD A,(NEGFLA) LD D,A LD E,40H SBC A,A XOR D LD D,A LD (NEGFLA),A ; Fixer code de retour LD C,ERRCOD CALL BDOS LD C,SCBGET LD DE,SCBPB JP BDOS ; SKIP1: ; Sauter caracteres jusqu'au prochain espace ; LD A,(HL) OR A RET Z CP " " INC HL JR NZ,SKIP1 ; SKIP: ; Sauter espaces SKIP2: LD A,(HL) INC HL CP " " JR Z,SKIP2 DEC HL ; Fin de la ligne de commande ? OR A RET Z SCF RET ; ; Cas des caracteres & et / ( fichier existe ou n'existe pas ) ; EXIST: INC HL CALL SKIP CP "0" JR C,EXIST1 CP ":" JR NC,EXIST1 LD E,A ; BDOS user only checks low 4 bits. INC HL CP "1" JR NZ,SETUSR LD A,(HL) CP "0" JR C,SETUSR CP "6" JR NC,SETUSR ADD A,10 LD E,A INC HL SETUSR: PUSH HL LD C,32 CALL BDOS POP HL EXIST1: CALL SKIP ; this check is to allow usage 11:file.ext CP ":" JR NZ,EXIST2 INC HL EXIST2: LD (TAMPON),HL LD DE,TAMPON LD C,152 CALL BDOS LD DE,FCB LD C,17 CALL BDOS CP 255 JP Z,ERREUR SCF JP CODE ; SCBPB: DEFB 6,255 NEGFLA: DEFB 255,0 SCBASK: DEFB 6,0 OUINON: DEFM "( Y/N ) ? $" TAMPON: DEFS 2 DEFW FCB FCB: DEFS 36 ; FIN: END