OPEN "funtions.txt" FOR INPUT AS #1
OPEN "function.txt" FOR OUTPUT AS #2
lne = 0
lnes$ = SPACE$(10000)
cp = 1
DO
LINE INPUT #1, a$
IF LEFT$(a$, 1) = "!" THEN
lx = LEN(a$) - 1
MID$(lnes$, cp, LEN(a$)) = CHR$(lx) + RIGHT$(a$, lx) + SPACE$(4)
lne = lne + 1
'PRINT a$, lx
cp = cp + LEN(a$) + 4
END IF
LOOP UNTIL EOF(1)

cp = 1
FOR a = 1 TO lne
b = ASC(MID$(lnes$, cp, 1))
dt$ = UCASE$(MID$(lnes$, cp + 1, b))
'PRINT dt$, b
cp = cp + (b + 5)
st = 0
lln = 0
SEEK #1, 1
DO
lln = lln + 1
LINE INPUT #1, a$
IF RIGHT$(a$, 1) = ":" AND st = 1 THEN
cp1 = 1
FOR c = 1 TO lne
b = ASC(MID$(lnes$, cp1, 1))
dt1$ = UCASE$(MID$(lnes$, cp1 + 1, b))
cp1 = cp1 + (b + 5)
'STOP
IF dt1$ = UCASE$(LEFT$(a$, LEN(a$) - 1)) THEN
st = 0
MID$(lnes$, cp - 2, 2) = MKI$(lln - 1)
END IF
NEXT c
END IF

IF UCASE$(a$) = dt$ + ":" AND st = 0 THEN
MID$(lnes$, cp - 4, 2) = MKI$(lln)
st = 1
END IF

IF EOF(1) AND st = 1 THEN
st = 0
MID$(lnes$, cp - 2, 2) = MKI$(lln)
END IF

LOOP UNTIL EOF(1)
NEXT a

'STOP
SEEK #1, 1
DO
lln = lln + 1
LINE INPUT #1, a$
IF LEFT$(a$, 1) = "!" THEN
cp1 = 1
FOR c = 1 TO lne
b = ASC(MID$(lnes$, cp1, 1))
dt1$ = MID$(lnes$, cp1 + 1, b)
cp1 = cp1 + (b + 5)

IF dt1$ = RIGHT$(a$, LEN(a$) - 1) THEN
l1$ = STR$(CVI(MID$(lnes$, cp1 - 4, 2)))
l2$ = STR$(CVI(MID$(lnes$, cp1 - 2, 2)))
'STOP
PRINT #2, a$ + l1$ + l2$
END IF
NEXT c
END IF

IF LEFT$(a$, 1) <> "!" THEN
PRINT #2, a$
END IF

LOOP UNTIL EOF(1)
CLOSE #2
CLOSE #1

