-- a program to run within Chipmonk -- last modified by Petit, October 13, 1981 8:00 PM -- written by Petit, October 9, 1981 2:04 PM DIRECTORY ppddefs, ppdefs, rldefs, AltoFileDefs, ZoneAllocDefs, StreamDefs, DirectoryDefs, StringDefs; rlin: PROGRAM IMPORTS ppdefs, StreamDefs, DirectoryDefs, rldefs, StringDefs EXPORTS rldefs = BEGIN OPEN ppddefs, rldefs, StreamDefs, DirectoryDefs, ppdefs, StringDefs; fHandle:DiskHandle; fp:AltoFileDefs.FP; myZone: PUBLIC UNCOUNTED ZONE; fileErr:PUBLIC SIGNAL=CODE; abbrt:PUBLIC SIGNAL=CODE; -- NEW FILE FORMAT: -- each gate is represented by one line of text, thus: -- ( <#> ) : ... -- Where is either for a single nor input -- or [ ... ] for an AND nor input -- is either space or comma. -- Node Names are identifiers (strings of and/or ) -- The "( <#> )" following the is the -- parameter (pullup strength) index. It is optional, and if -- it is left out the current default will be used. -- A line consisting of only: (<#>) will set the default. -- N.B.: identifiers are limited to 100 Characters! -- file ends with a line consisting of @ -- and ; are equivalent. Comma and space are equivalent. -- a line starting with (first non-blank chr) a minus (-) is ignored. itemType:TYPE = {ident,num,sep,lend,colon,lpar,rpar,lbrk,rbrk,fend,commt}; pinType:TYPE = {out,nor,firstAnd,and}; pinDef:TYPE = RECORD[nxt:LONG POINTER TO pinDef,node:INTEGER,type:pinType]; nodeNameList:TYPE = RECORD[nxt:LONG POINTER TO nodeNameList, node:INTEGER,name:STRING]; termChar:CHARACTER; dummytc:CHARACTER = 177C; pins,pnp:LONG POINTER TO pinDef; savePD:LONG POINTER TO pinDef_NIL; nnList:LONG POINTER TO nodeNameList; inputCircuit:PUBLIC PROCEDURE RETURNS[pnt:LONG POINTER TO GateList,dwCnt,maxNN:INTEGER] = BEGIN s:STRING; ok:BOOLEAN; typ:itemType; gc:LONG POINTER TO gateCharac; gat:LONG POINTER TO gate; gp,mostRecent:LONG POINTER TO GateList; norCnt,inCnt,i,a,parm:INTEGER; defparm:INTEGER_1;--default [ok,s,]_typeIn["Type File Name"L,"With Extension"L,""L]; IF NOT ok THEN SIGNAL abbrt; ok_openF[s]; pnt_NIL; pins_NIL; dwCnt_maxNN_0; nnList_NIL; WHILE NOT ok DO [ok,s,]_typeIn["No Such File"L,"Type File Name"L, "With Extension"L]; IF NOT ok THEN SIGNAL abbrt; ok_openF[s]; ENDLOOP; termChar_dummytc; DO [typ,s,a]_scan[]; IF typ=fend THEN EXIT; IF typ=commt THEN UNTIL typ=lend DO [typ,,]_scan[];ENDLOOP; IF typ=lend THEN LOOP; IF typ=lpar THEN BEGIN defparm_readNum[]; checkForChr[')]; [typ,,]_scan[]; IF typ#lend THEN SIGNAL fileErr; END ELSE IF typ#ident THEN SIGNAL fileErr ELSE BEGIN parm_defparm; enterPin[out,s]; [typ,,]_scan[]; IF typ=lpar THEN BEGIN parm_readNum[]; checkForChr[')]; [typ,,]_scan[]; END; IF typ#colon THEN SIGNAL fileErr; IF NOT parm IN parmaCnt THEN SIGNAL fileErr; norCnt_0; DO [typ,s,a]_scan[]; IF typ=lbrk THEN BEGIN [typ,s,a]_scan[]; IF typ#ident THEN SIGNAL fileErr; enterPin[firstAnd,s]; norCnt_norCnt+1; DO [typ,s,a]_scan[]; IF typ=rbrk THEN EXIT; IF typ#ident THEN SIGNAL fileErr; enterPin[and,s]; ENDLOOP; LOOP; END; IF typ=lend THEN EXIT; IF typ#ident THEN SIGNAL fileErr; norCnt_norCnt+1; enterPin[nor,s]; ENDLOOP; gc_GetSpace[SIZE[gateCharac[norCnt]]]; gc.norCnt_norCnt; inCnt_i_0; pnp_pins; WHILE pnp#NIL DO SELECT pnp.type FROM out => {pnp_pnp.nxt;LOOP}; nor => {inCnt_inCnt+1;gc.ands[i]_1;i_i+1;pnp_pnp.nxt}; firstAnd => BEGIN a_1; inCnt_inCnt+1; pnp_pnp.nxt; WHILE pnp#NIL AND pnp.type=and DO a_a+1; inCnt_inCnt+1; pnp_pnp.nxt; ENDLOOP; gc.ands[i]_a; i_i+1; END; ENDCASE; ENDLOOP; gc.inCnt_inCnt; gat_getGate[gc,parm]; gp_getNewGateList[inCnt]; i_0; pnp_pins; a_pnp.node; maxNN_MAX[maxNN,a]; gp.outNode_a; pnp_pnp.nxt; WHILE pnp#NIL DO a_pnp.node; gp.nodes[i]_a; maxNN_MAX[maxNN,a]; i_i+1; pnp_pnp.nxt; ENDLOOP; dwCnt_dwCnt+inCnt+1; gp.gat_gat; gp.nxt_NIL; IF pnt=NIL THEN pnt_gp ELSE mostRecent.nxt_gp; mostRecent_gp; freeupPins[]; END; ENDLOOP; END; checkForChr:PROCEDURE[c:CHARACTER] = BEGIN chr:CHARACTER; WHILE (chr_readChr[]) = ' OR chr=', OR chr=11C DO ENDLOOP; IF chr#c THEN SIGNAL fileErr; END; openF:PROCEDURE [fname: STRING] RETURNS [BOOLEAN] = BEGIN IF NOT DirectoryLookup[@fp, fname, FALSE] THEN RETURN[FALSE]; fHandle _ NewByteStream[fname, Read]; RETURN[TRUE]; END; readChr:PROCEDURE RETURNS[CHARACTER] = BEGIN c:CHARACTER_termChar; termChar_dummytc; IF c#dummytc THEN RETURN[c]; IF NOT fHandle.endof[fHandle] THEN RETURN[fHandle.get[fHandle]]; RETURN[15C]; END; readNum:PROCEDURE RETURNS[i:INTEGER] = BEGIN c:CHARACTER; i_0; WHILE (c_readChr[]) = ' OR c=', OR c=11C DO ENDLOOP; WHILE c IN ['0..'9] DO i_i*10+(c-'0); c_readChr[]; ENDLOOP; termChar_c; END; scan:PROCEDURE RETURNS[t:itemType,s:STRING,i:INTEGER] = BEGIN c:CHARACTER; ss:STRING_[100]; i_0; s_NIL; WHILE (c_readChr[]) = ' OR c=', OR c=11C DO ENDLOOP; t_num; IF NOT (c IN ['0..'9] OR c IN ['a..'z] OR c IN ['A..'Z]) THEN BEGIN SELECT c FROM ',,' => t_sep; ': => t_colon; 15C,'; => t_lend; '( => t_lpar; '[ => t_lbrk; '] => t_rbrk; ') => t_rpar; '@ => t_fend; '- => t_commt; ENDCASE => SIGNAL fileErr; RETURN; END; WHILE c IN ['0..'9] OR c IN ['a..'z] OR c IN ['A..'Z] DO IF t=num THEN BEGIN IF c IN ['0..'9] THEN i_i*10+(c-'0) ELSE t_ident; END; AppendChar[ss,c]; c_readChr[]; ENDLOOP; s_newString[ss]; termChar_c; END; getNewGateList:PROCEDURE[cnt:INTEGER] RETURNS[LONG POINTER TO GateList] = BEGIN RETURN[myZone.NEW[GateList[cnt]]]; END; enterPin:PROCEDURE[typ:pinType,s:STRING] = BEGIN p:LONG POINTER TO pinDef; pp:LONG POINTER TO pinDef_getPinDef[]; pp^_[NIL,enterNodeName[s],typ]; IF pins=NIL THEN pins_pp ELSE BEGIN p_pins; WHILE p.nxt#NIL DO p_p.nxt;ENDLOOP; p.nxt_pp; END; END; getPinDef:PROCEDURE RETURNS[p:LONG POINTER TO pinDef] = BEGIN IF savePD=NIL THEN RETURN[myZone.NEW[pinDef]]; p_savePD; savePD_p.nxt; END; freeupPins:PROCEDURE = BEGIN IF savePD=NIL THEN {savePD_pins;pins_NIL;RETURN}; pnp_savePD; WHILE pnp.nxt#NIL DO pnp_pnp.nxt;ENDLOOP; pnp.nxt_pins; pins_NIL; END; enterNodeName:PROCEDURE[s:STRING] RETURNS[INTEGER] = BEGIN n:INTEGER_0; nn:LONG POINTER TO nodeNameList_nnList; WHILE nn#NIL DO IF EquivalentString[s,nn.name] THEN RETURN[nn.node]; n_MAX[n,nn.node]; nn_nn.nxt; ENDLOOP; n_n+1; nn_myZone.NEW[nodeNameList]; nn.name_s; nn.node_n; nn.nxt_nnList; nnList_nn; RETURN[n]; END; END. -- of rlin (1792)