! ! CLI.IMP ! !Revision history: ! 001 21-Jun-88 PSR Rewrote the whole of Parse Command Line to permit ! -thing x-y ! where x-y is a value, not the value x and the keyword -y %from IMP %include Heap ! ! External references ! %externalintegerfnspec StoI %alias "3L_IMP_S_TO_I" (%string(31) S) %externalstring(255)%fnspec Cli Param %alias "3L_IMP_CLI_PARAM" %recordformat Cfm(%record(Cfm)%name Link, %string(255)%name Switch, Value) %constrecord(Cfm)%name CfmType == 0 %ownrecord(Cfm)%name Switches == 0 %own %integer Parsed = 0 %routine Parse Command Line {001} %integer P, Lim, Sym, Quote = 0, Mod = 0 %string(255) C String Parsed = 1 C String = Cli Param %routine Next Sym P = P+1 %if P > Lim %start Sym = NL %else Sym = Charno(C String, P) ! Quote %if Sym = '"' %start Quote = 256 Next Sym %else %if Sym = '"' ! 256 Quote = 0 Next Sym %if Sym = '"' %start Quote = 256 Sym = Sym ! 256 %finish %else %if 'a' <= Sym <= 'z' Sym = Sym-Mod %finish %finish %end P = 0; Lim = Length(C String) %routine Push(%string(255) Key) {001} %record(Cfm)%name C == NEW(CfmType) {001} C_Link == Switches; Switches == C {001} C_Switch == Heap String(Key) {001} C_Value == String(0) {001} %end {001} %routine Get Word(%string(255)%name W, %integername Key) {001} W = "" {001} Key = 0 {001} Mod = 0 {001} %cycle {001} Next Sym {001} %return %if Sym = NL {001} %if Sym = ' ' %start {ignore leading spaces} {001} %continue %if W = "" {001} %return {001} %finish {001} %if Sym = '-' %and W = "" %start {001} Key = 1; Mod = 32 {001} %continue {001} %finish {001} W = W.Tostring(Sym) {Note: implied &255} {001} %repeat {001} %end {001} %string(255) W {001} %integer T {001} %cycle {001} Get Word(W, T) {001} %exit %if W = "" {001} %if T = 0 %start {ordinary word} {001} Push("FILE") %if Switches == NIL {001} %if Switches_Value == String(0) %start {001} Switches_Value == Heap String(W) {001} %else {001} Event_Message = - {001} "Spurious command line value """.W."""" {001} %signal 15,1 {001} %finish {001} %else {a switch} {001} Push(W) {001} %finish {001} %repeat {001} %end {001} %record(Cfm)%map Find(%string(255)%name Pattern) %record(Cfm)%name C %integer Len Parse Command Line %if Parsed = 0 To Upper(Pattern) C == Switches %while C ## NIL %cycle Len = Length(C_Switch) %result == C %if Len <= Length(Pattern) - %and Substring(Pattern, 1, Len) = C_Switch C == C_Link %repeat %result == NIL %end %external %string(255)%fn Qualifier S %alias "3L_IMP_QUALIFIER_S" - (%string(255) Text) %record(Cfm)%name C == Find(Text) %result = "" %if C == NIL %or C_Value == String(0) %result = C_Value %end %external %predicate Qualifier Present %alias "3L_IMP_QUALIFIER_PRESENT" - (%string(255) Text) %false %if Find(Text) == NIL %true %end %external %integer %function Qualifier I %alias "3L_IMP_QUALIFIER_I" - (%string(255) Text) %record(Cfm)%name C == Find(Text) %result = 0 %if C == NIL %or C_Value == String(0) %result = StoI(C_Value) { %Signal 3,1,char if Text not valid } %end