MODULE PIC; (* Sohail Aslam. 09/16/84 This module is the main driver for the PIC program. It first invokes PassOne to build a chain of PIC elements by parsing User's commands. PassTwo then goes through the chain and does the actual plotting. *) FROM CmdLineArgs IMPORT Getarg; FROM Tools IMPORT String, MakeStr, Ctoi, Ctor; FROM DIG IMPORT GDeviceType; FROM PicADT IMPORT PicADTDebug, PrintChain; FROM PicPasses IMPORT (* VAR *) Pass1Debug, (* PROC *) PassOne, PassTwo ; FROM InOut IMPORT in, WriteString, WriteLn; FROM FileSystem IMPORT Open,Close,Reset,Done; VAR bug, pchain, Fine : BOOLEAN; arg, device : ARRAY [ 1..8 ] OF CHAR; cmdfile, gfile : ARRAY [1..32] OF CHAR; px, py : REAL; baud : INTEGER; Echo : BOOLEAN; PROCEDURE usage( ); BEGIN WriteString("usage: pic cmdfile graffile device [px py]" ); WriteString(" [-Echo] [-Pchain]" ); WriteLn; WriteString(" where device can be hp7220|hp7221|hp7470|"); WriteString("hp7575|hp7550|vt125" ); WriteLn; WriteLn; HALT END usage; PROCEDURE Scmp( s1 : ARRAY OF CHAR; (* in *) s2 : ARRAY OF CHAR (* in *) ) : BOOLEAN; (* Compare strings s1 and s2. return TRUE if strings match. The comparison loop is controlled by length of the shorter of the two. *) VAR len1, len2, lend, i : CARDINAL; BEGIN len1 := HIGH( s1 ); len2 := HIGH( s2 ); lend := len1; IF len2 < len1 THEN lend := len2 END; FOR i := 0 TO lend DO IF CAP( s1[i] ) # CAP( s2[i] ) THEN RETURN FALSE END END; RETURN TRUE; END Scmp; PROCEDURE Setpapersize( ); VAR s : String; BEGIN px := 11.0; py := 8.5; IF Getarg( arg ) THEN IF arg[1] = "-" THEN RETURN END; MakeStr( arg, s ); px := Ctor( s ); IF px <= 0.0 THEN px := 11.0 END END; IF Getarg( arg ) THEN IF arg[1] = "-" THEN RETURN END; MakeStr( arg, s ); py := Ctor( s ); IF py <= 0.0 THEN py := 8.5 END END END Setpapersize; PROCEDURE Setbaud( ); VAR s : String; BEGIN baud := 1200; IF Getarg( arg ) THEN IF arg[1] = "-" THEN RETURN END; MakeStr( arg, s ); baud := Ctoi( s ); IF( baud <= 0 ) OR ( baud > 9600 ) THEN baud := 1200 END END END Setbaud; BEGIN IF NOT Getarg( cmdfile ) THEN usage END; IF NOT Getarg( gfile ) THEN usage END; IF NOT Getarg( device ) THEN usage END; IF( CAP(device[1]) = 'H' ) AND ( CAP(device[2]) = 'P' ) THEN Setpapersize( ) ELSIF( CAP(device[1]) = 'T' ) AND ( CAP(device[2]) = 'E' ) THEN Setbaud( ) END; Echo := FALSE; bug := FALSE; pchain := FALSE; (* If Setpapersize or Setbaud did not get the right args, this repeat will allow scanning of the current arg vector prior to getting any more. *) REPEAT IF ( arg[1] = "-" ) THEN IF CAP( arg[2] ) = "D" THEN bug := TRUE ELSIF CAP( arg[2] ) = "P" THEN pchain := TRUE ELSIF CAP( arg[2] ) = "E" THEN Echo := TRUE END END UNTIL NOT Getarg( arg ); PicADTDebug := bug; Pass1Debug := bug; Open( in, cmdfile, FALSE ); IF NOT Done() THEN WriteString( "Can't open " ); WriteString( cmdfile ); WriteLn; WriteLn; HALT END; Reset( in ); WriteString("Begin parsing of commands in file: " ); WriteString( cmdfile ); WriteLn; Fine := PassOne( Echo ); IF NOT Fine THEN WriteString("Trouble in parsing" ); WriteLn; END; IF pchain THEN PrintChain( ) END; WriteString("Placing graphics commands on: " ); WriteString( gfile ); WriteString(" for device: " ); WriteString( device ); WriteLn; IF Scmp( device, "vt125" ) THEN PassTwo( gfile, vt125, 1200, 5.8, 3.622 ) ELSIF Scmp( device, "hp7220" ) THEN PassTwo( gfile, hp7220 , 15, px,py ) ELSIF Scmp( device, "hp7221" ) THEN PassTwo( gfile, hp7221 , 15, px,py ) ELSIF Scmp( device, "hp7470" ) THEN PassTwo( gfile, hp7470 , 15, px,py ) ELSIF Scmp( device, "hp7475" ) THEN PassTwo( gfile, hp7475 , 15, px,py ) ELSIF Scmp( device, "hp7550" ) THEN PassTwo( gfile, hp7550 , 15, px,py ) ELSIF Scmp( device, "tek" ) THEN PassTwo( gfile, tek , baud, 14.5, 10.9) ELSE WriteString( "Unknown device: " ); WriteString( device ); WriteString( " - Abort " ); WriteLn; HALT; END; WriteString("End of PIC" ); WriteLn END PIC.