SRStringGadget Swap +nwFirstGadget ! ; \ give window a ptr to gadgets
: CorrectRunTimePtrs ( -- )
InitStrGadget
RIntuitext>Text \ Give Req. Intuitexts ptrs to text
SRGadgetIntuitexts>SRTexts
SRStrGadget>SRBoolGadgets
SRBoolGadget>Border
SRBoolGadget>Text
Window>Data
Intuitext>SRString
SRGadget>SRIntuitext ;
CREATE MoleWtTable
1008 , 4003 , 6941 , 9012 ,
10810 , 12011 , 14007 , 15999 ,
18998 , 20179 , 22990 , 24305 ,
26982 , 28086 , 30974 , 32060 ,
35453 , 39948 , 39102 , 40080 ,
44956 , 47900 , 50941 , 51996 ,
54938 , 55847 , 58933 , 58710 ,
63546 , 65370 , 69720 , 72590 ,
74922 , 78960 , 79904 , 83800 ,
85468 , 87620 , 88906 , 91220 ,
92906 , 95940 , 98906 , 101070 ,
102906 , 106400 , 107868 , 112400 ,
114820 , 118690 , 121750 , 127600 ,
126905 , 131300 , 132906 , 137340 ,
138906 , 178490 , 180948 , 183850 ,
186200 , 190200 , 192220 , 195090 ,
196967 , 200590 , 204370 , 207200 ,
208981 , 210000 , 210000 , 222000 ,
223000 , 226025 , 227000 , 140120 ,
140908 , 144240 , 147000 , 150400 ,
151960 , 157250 , 158925 , 162500 ,
164930 , 167260 , 168934 , 173040 ,
174970 , 232038 , 231036 , 238029 ,
237048 , 242000 , 243000 , 247000 ,
247000 , 251000 , 254000 , 253000 ,
256000 , 254000 , 257000 ,
\ a few extras for shortcuts - Me=CH3, Et=CH3CH2, Vi=CH2CH, Ph=C6H5
15035 , 29062 , 27046 , 77106 ,
CREATE El$
," H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcCePrNdPmSmEuGdTbDyHoErTmYbLuThPaU NpPuAmCmBkCfEsFmMdNoLrMeEtViPh"
CREATE |StrBuf 10 ALLOT \ A buffer for parsing the string
: NMatch ( addr$\$cnt\addr\cnt -- [#instring] or [0] ) \ find str at addr$
LOCALS| LStr AStr LStr2 AStr2 | \ in str at addr
LStr LStr2 - \ set up to match from start
\ to LStr chars from end of Str1
0 TO LStr \ Now use LStr to count our position in the string Str1
0 DO
AStr2 LStr2 AStr I + -TEXT \ Loop through and check for match
NOT IF
I 1+ TO LStr \ If found, set LStr to the char cnt.
THEN
LOOP LStr ;
: fdInString ( -- [#instr] or [0] ) \ look for valid element in El$
|StrBuf 1+ 2 \ pointer to string buffer and
\ length of single elemment ( 2 chars)
El$ DUP 1+ SWAP C@ 1+ \ pointer to string holding all element names
\ and the length
NMATCH ; \ look for match
VARIABLE >Formula \ ptr to next char to parse
VARIABLE >StrBuf \ a temporary buffer to parse strings in
VARIABLE >EndFormula \ ptr to the end of the string
VARIABLE ErrorFlag
VARIABLE ParenCnt \ counts the number of unresolved parentheses
0 ErrorFlag !
: InitPtr ( -- ) \ Initialize pointers for string transfer
|SRString >Formula ! \ Init. to beginning of String Gad. buffer
|StrBuf 1+ >StrBuf ! \ Init. to beginning of temp. str. buffer
|SRString DUP 0$Len + >EndFormula ! ; \ init. ptr. to end of formula
: GetNextChar ( --char ) \ Get the next character in the formula
>Formula @ C@ ;
: AdvancePtr ( -- ) \ Increment pointer in formula to next Char
1 >Formula +! ;
: ResetBuf ( -- ) \ fills strbuf with spaces and sets str length to 2
|StrBuf 2 OVER C! \ set string length to 2 characters
1+ DUP 9 + SWAP DO 32 I C! LOOP \ fill the rest of the buffer with blanks
|StrBuf 1+ >StrBuf ! ; \ set pointer to first char in (now empty) buffer
: AtomWt@ ( #inStr -- Molewt ) \ Get the Atomic Wt. out of the table
1+ 2/ 1- 4* MoleWtTable + @ ;
: TestCap ( -- ) \ test if letter pointed to by >Formula is
>Formula @ C@ 65 90 RANGE \ a capital letter
If >StrBuf @ C! Else \ if so move to buffer
1 ErrorFlag ! \ otherwise set errorflag - invalid formula
THEN \ Increment pointers
1 DUP >Formula +! >StrBuf +! ;
: TestLow ( -- ) \ Test if letter pointed to by >Formula is
>Formula @ C@ 97 122 RANGE \ lower case letter
IF >StrBuf @ C! \ if so move to buffer
1 >Formula +! \ and increment pointer & remove from stack
ELSE DROP THEN ; \ or remove non lower case from stack
: NumCheck ( n--flag ) \ check if n is an ASCII number
48 57 RANGE SWAP DROP ;
: TestNum ( --) \ If the string at the current >Formula
>Formula @ \ is a numeric string, then evaluate
LOCALS| EndNum | \ and multiply top of stack by that amount
BEGIN EndNum C@ NumCheck While
EndNum 1+ TO EndNum REPEAT
EndNum >Formula @ - DUP
IF DUP >Formula @ SWAP $>NUMBER DROP
SWAP >Formula +! * ELSE DROP THEN ;
: NotDone? ( -- flag) \ flag=-1 if not done
ErrorFlag @ IF 0 ELSE >Formula @ >EndFormula @ - 0< THEN ;
: OpenParen ( -- 0 )
1 >Formula +! \ Increment ptr to next char in formula