/*
**  $VER: ImportTermPB-DFA.rexx 0.001 (12 Feb 1996)  **
**
**        © 1996 Andreas Mixich
**        original Arexx script by Kay Drangmeister
**
**
**  PROGRAMNAME:
**      ImportTermPB-DFA.rexx
**
**  FUNCTION:
**      Reads out the number, name and comment of all TERM phonebook entry and
**      add them to DFA.
**
**  $HISTORY:
**
**   12 Feb 1996 : 0.01 : initial release
*/


SIGNAL ON SYNTAX
SIGNAL ON ERROR

OPTIONS RESULTS

PortName = 'IFFMASTER.1'
LF = '0a'x
TAB = '09'x

ADDRESS VALUE PortName

IFFMACTIVE=1
IF ~SHOW('Ports',PortName) THEN DO
    IFFMACTIVE=0
    ADDRESS 'COMMAND' 'Run >NIL: GFX:Tools/IFFMaster'
    ADDRESS 'COMMAND' 'WaitForPort '||PortName
    IF ~SHOW('Ports',PortName) THEN EXIT 10
END


'load term:config/phonebook.prefs'
'entries'
nument=RESULT
'limithex bytes 16'     /* we ignore hex dumps */

count=0
DO i=0 FOR nument;
    'cursorpos 'i
    'chunkid'
    ID=RESULT
    IF ID='PHON' THEN DO
        count=count+1
        'chunkstruct sepstring "|"'
        phon=RESULT
        PARSE VAR phon . '|' name '0a'x . '|' phone '0a'x . '|' comment '0a'x .
        name.count=strip(name,'B','"')
        phone.count=strip(phone,'B','"')
        comment.count = strip(comment,'B','"')
    END
END

ADDRESS DFA

DO i = 1 TO count
    'NEW FIRST "BBS" NAME "'||name.i||'" PHONE "'||phone.i||'" COMMENT "'||comment.i||'"'
    'POPUP'
END

IF IFFMACTIVE=0 THEN
    DO
    ADDRESS Value portname
    'quit'     /* we started IFFMaster ourselves, so close it */
    END

EXIT(0)

/* what to do on an error */
ERROR:
SYNTAX:

    SAY '+++ Error' rc 'in line' sigl '-' ERRORTEXT(rc)
    SAY SOURCELINE(sigl)

EXIT(rc)