home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 3 Comm
/
03-Comm.zip
/
cimgcp.cmd
< prev
next >
Wrap
OS/2 REXX Batch file
|
1995-01-11
|
6KB
|
199 lines
/* CIMGCP.CMD Copyright 1994 by William J. Hinkle [75300,2050] */
/* This Rexx script translates WinCIM address books to GCP USERID.CIS
Just run it from an OS/2 command line or a desktop program object
If you have trouble with this, I'd like to hear about it, but:
"Use this at your own risk: all responsibility is disclaimed!"
This is free for individuals to use and distribute.
Update: 27 Nov 1994. If a , comma is found in a CIM name, it is assumed
that the name is in the "last, first" form and so
is reversed for the GCP address book.
*/
uppert = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lowert = "abcdefghijklmnopqrstuvwxyz"
SIGNAL ON HALT
gcpok = ""
DO UNTIL gcpok = "READY:"
IF gcpok <> "" THEN DO
SAY
SAY gcpaddr "could not be found."
SAY "Hint: check your Golden CommPass directory!"
END
SAY "Please enter the drive:path to the Golden CommPass Address Book USERID.CIS."
SAY "Just [Enter] for C:\GCP\ or [Ctrl+C][Enter] to quit: ";
PARSE PULL gcppath
cimpath = STRIP(gcppath,"B")
IF gcppath = "" THEN
gcppath = "C:\GCP\"
ELSE DO
IF RIGHT(gcppath,1) <> "\" & RIGHT(gcppath,1) <> ":" THEN DO
gcppath = gcppath || "\"
END
END
gcpaddr = gcppath || "USERID.CIS"
IF STREAM(gcpaddr,"C","QUERY EXISTS") <> "" THEN DO
SAY "Did you already save" gcpaddr "just in case...? [Y/N][Enter]:"
PARSE UPPER PULL strdat
IF strdat <> "Y" THEN DO
SAY "You'd better do that right now, and try this again later!"
EXIT
END
END
gcpok = STREAM(gcpaddr,"C","OPEN WRITE")
END
SAY
cimok = ""
DO UNTIL cimok = "READY:"
IF cimok <> "" THEN DO
SAY
SAY cimaddr "could not be found."
SAY "Hint: check your DOS CIM directory, or CSERVE\SUPPORT for WinCIM"
END
SAY "Please enter the drive:directory to the CIM Address Book ADDRBOOK.DAT."
SAY "Just [Enter] for C:\CSERVE\SUPPORT\ or [Ctrl+C][Enter] to quit: ";
PARSE PULL cimpath
cimpath = STRIP(cimpath,"B")
IF cimpath = "" THEN
cimpath = "C:\CSERVE\SUPPORT\"
ELSE DO
IF RIGHT(cimpath,1) <> "\" & RIGHT(cimpath,1) <> ":" THEN DO
cimpath = cimpath || "\"
END
END
cimaddr = cimpath || "ADDRBOOK.DAT"
cimok = STREAM(cimaddr,"C","OPEN READ")
END
SAY
IF cimok = "READY:" & gcpok = "READY:" THEN DO
cimtype = C2D(CHARIN(cimaddr,1,1))
IF cimtype = 1 THEN DO
SAY "DOS CIM Address Book"
slen = 1
END
ELSE IF cimtype = 2 THEN DO
SAY "WinCIM Address Book"
slen = 2
END
ELSE DO
SAY "Unknown CIM address book type:" cimtype
SIGNAL HALT
END
nnames = C2D(REVERSE(CHARIN(cimaddr,2,slen)),slen)
cimpos = 2 + slen
SAY "There are" nnames "names and/or groups:"
ncnt = 0
isagroup = 0
group.0.0 = 0
DO nnames
IF cimtype = 2 THEN DO
/* get the name index (+32768 if group) */
ncnt = C2D(REVERSE(CHARIN(cimaddr,cimpos,2)))
cimpos = cimpos + 2
isagroup = (ncnt >= 32768)
IF isagroup THEN ncnt = ncnt - 32768
END
ELSE ncnt = ncnt + 1
/* get the name */
slen = C2D(CHARIN(cimaddr,cimpos,1))
strdat = CHARIN(cimaddr,cimpos+1,slen)
cimpos = cimpos + 1 + slen
IF isagroup THEN DO /* acquire group list of name indices */
nametxt = strdat
/* get the number of names in the group */
slen = C2D(CHARIN(cimaddr,cimpos,1))
cimpos = cimpos + 1
group.0.0 = group.0.0 + 1
gcnt = group.0.0
group.0.gcnt = nametxt
group.gcnt.0 = slen
DO gix = 1 TO slen
group.gcnt.gix = C2D(REVERSE(CHARIN(cimaddr,cimpos,2)),2)
cimpos = cimpos + 2
END
/* skip 0-pad byte */
cimpos = cimpos + 1
nametxt = "Group:" nametxt "(" || slen "names)"
END
ELSE DO /* acquire name information */
/* reverse name if comma is found: last, first => first last */
endsurname = POS(",", strdat)
IF endsurname > 0 THEN DO
strdat = SUBSTR(strdat,endsurname+1) || ,
" " || ,
SUBSTR(strdat,1,endsurname-1)
END
/* reconstitute and fix case of name */
nametxt = ""
DO nsegcnt = 1 TO words(strdat)
nameseg = WORD(strdat,nsegcnt)
nametxt = nametxt || OVERLAY(TRANSLATE(SUBSTR(nameseg,2),lowert,uppert),nameseg,2) || " "
END
/* get the PPN */
slen = C2D(CHARIN(cimaddr,cimpos,1))
strdat = STRIP(CHARIN(cimaddr,cimpos+1,slen),"B")
cimpos = cimpos + 1 + slen
nametxt = nametxt strdat
/* get the comments */
slen = C2D(CHARIN(cimaddr,cimpos,1))
strdat = STRIP(CHARIN(cimaddr,cimpos+1,slen),"B")
cimpos = cimpos + 1 + slen
IF strdat <> "" THEN DO
/* un-comment this to change case of comments */
/*
strdat = OVERLAY(TRANSLATE(SUBSTR(strdat,2),lowert,uppert),strdat,2)
*/
/* blank out any @b0x0A combos (CIM endline) and 0x0D0A (WINCIM) */
eolpos = 1
IF cimtype = 1 THEN DO FOREVER
eolpos = POS("@b" || "0A"x,strdat,eolpos)
IF eolpos = 0 THEN LEAVE
strdat = DELSTR(strdat,eolpos,2)
END
ELSE IF cimtype = 2 THEN DO FOREVER
eolpos = POS("0D0A"x, strdat,eolpos)
IF eolpos = 0 THEN LEAVE
strdat = DELSTR(strdat,eolpos,1)
END
strdat = TRANSLATE(strdat," ","0A"x)
END
nametxt = nametxt '|' strdat
/* see if any group names can be appended */
DO gcnt = 1 TO group.0.0
DO gix = 1 TO group.gcnt.0
IF group.gcnt.gix = ncnt THEN DO
nametxt = nametxt "[" || group.0.gcnt || "]"
LEAVE gix
END
END
END
END
/* mention the name on-screen */
SAY "#" ncnt "=" nametxt
/* write the new address for GCP if it isn't a group */
IF \ isagroup THEN DO
IF LINEOUT(gcpaddr,nametxt) <> 0 & \ isagroup THEN DO
SAY "Gagged writing to" gcpaddr "!"
LEAVE nnames
END
END
END
END
HALT:
IF POS(cimok,"NOTREADY:") = 1 THEN SAY "Couldn't find the CIM address book file!"
ELSE IF cimok = "READY:" THEN CALL STREAM cimaddr,"C","CLOSE"
IF POS(gcpok,"NOTREADY:") = 1 THEN SAY "Couldn't find the GCP address book file!"
ELSE IF gcpok <> "READY:" THEN CALL STREAM gcpaddr,"C","CLOSE"
EXIT