home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / cimgcp.cmd < prev    next >
OS/2 REXX Batch file  |  1995-01-11  |  6KB  |  199 lines

  1. /* CIMGCP.CMD Copyright 1994 by William J. Hinkle [75300,2050] */
  2. /* This Rexx script translates WinCIM address books to GCP USERID.CIS
  3.    Just run it from an OS/2 command line or a desktop program object
  4.    If you have trouble with this, I'd like to hear about it, but: 
  5.    "Use this at your own risk: all responsibility is disclaimed!"
  6.    This is free for individuals to use and distribute.
  7.    Update: 27 Nov 1994.  If a , comma is found in a CIM name, it is assumed
  8.                          that the name is in the "last, first" form and so
  9.                          is reversed for the GCP address book.
  10. */
  11. uppert = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  12. lowert = "abcdefghijklmnopqrstuvwxyz"
  13. SIGNAL ON HALT
  14.  
  15. gcpok = ""
  16. DO UNTIL gcpok = "READY:"
  17.     IF gcpok <> "" THEN DO
  18.         SAY
  19.         SAY gcpaddr "could not be found."
  20.         SAY "Hint: check your Golden CommPass directory!"
  21.     END
  22.     SAY "Please enter the drive:path to the Golden CommPass Address Book USERID.CIS."
  23.     SAY "Just [Enter] for C:\GCP\ or [Ctrl+C][Enter] to quit: ";
  24.     PARSE PULL gcppath
  25.     cimpath = STRIP(gcppath,"B")
  26.     IF gcppath = "" THEN
  27.         gcppath = "C:\GCP\"
  28.     ELSE DO
  29.         IF RIGHT(gcppath,1) <> "\" & RIGHT(gcppath,1) <> ":" THEN DO
  30.             gcppath = gcppath || "\"
  31.         END
  32.     END
  33.     gcpaddr = gcppath || "USERID.CIS"
  34.     IF STREAM(gcpaddr,"C","QUERY EXISTS") <> "" THEN DO
  35.     SAY "Did you already save" gcpaddr "just in case...? [Y/N][Enter]:"
  36.     PARSE UPPER PULL strdat
  37.     IF strdat <> "Y" THEN DO
  38.         SAY "You'd better do that right now, and try this again later!"
  39.         EXIT
  40.     END
  41.     END
  42.     gcpok = STREAM(gcpaddr,"C","OPEN WRITE")
  43. END
  44.  
  45. SAY
  46.  
  47. cimok = ""
  48. DO UNTIL cimok = "READY:"
  49.     IF cimok <> "" THEN DO
  50.         SAY
  51.         SAY cimaddr "could not be found."
  52.         SAY "Hint: check your DOS CIM directory, or CSERVE\SUPPORT for WinCIM"
  53.     END
  54.     SAY "Please enter the drive:directory to the CIM Address Book ADDRBOOK.DAT."
  55.     SAY "Just [Enter] for C:\CSERVE\SUPPORT\ or [Ctrl+C][Enter] to quit: ";
  56.     PARSE PULL cimpath
  57.     cimpath = STRIP(cimpath,"B")
  58.     IF cimpath = "" THEN
  59.         cimpath = "C:\CSERVE\SUPPORT\"
  60.     ELSE DO
  61.         IF RIGHT(cimpath,1) <> "\" & RIGHT(cimpath,1) <> ":" THEN DO
  62.             cimpath = cimpath || "\"
  63.         END
  64.     END
  65.     cimaddr = cimpath || "ADDRBOOK.DAT"
  66.     cimok = STREAM(cimaddr,"C","OPEN READ")
  67. END
  68.  
  69. SAY
  70. IF cimok = "READY:" & gcpok = "READY:" THEN DO
  71.     cimtype = C2D(CHARIN(cimaddr,1,1))
  72.     IF cimtype = 1 THEN DO
  73.         SAY "DOS CIM Address Book"
  74.         slen = 1
  75.     END
  76.     ELSE IF cimtype = 2 THEN DO
  77.         SAY "WinCIM Address Book"
  78.         slen = 2
  79.     END
  80.     ELSE DO
  81.         SAY "Unknown CIM address book type:" cimtype
  82.         SIGNAL HALT
  83.     END
  84.  
  85.     nnames = C2D(REVERSE(CHARIN(cimaddr,2,slen)),slen)
  86.     cimpos = 2 + slen
  87.     SAY "There are" nnames "names and/or groups:"
  88.  
  89.     ncnt = 0
  90.     isagroup = 0
  91.     group.0.0 = 0
  92.     DO nnames
  93.         IF cimtype = 2 THEN DO
  94.             /* get the name index (+32768 if group) */
  95.             ncnt = C2D(REVERSE(CHARIN(cimaddr,cimpos,2)))
  96.             cimpos = cimpos + 2
  97.             isagroup = (ncnt >= 32768)
  98.             IF isagroup THEN ncnt = ncnt - 32768
  99.         END
  100.         ELSE ncnt = ncnt + 1
  101.  
  102.         /* get the name */
  103.         slen = C2D(CHARIN(cimaddr,cimpos,1))
  104.         strdat = CHARIN(cimaddr,cimpos+1,slen)
  105.         cimpos = cimpos + 1 + slen
  106.         IF isagroup THEN DO    /* acquire group list of name indices */
  107.             nametxt = strdat
  108.             /* get the number of names in the group */
  109.             slen = C2D(CHARIN(cimaddr,cimpos,1))
  110.             cimpos = cimpos + 1
  111.             group.0.0 = group.0.0 + 1
  112.             gcnt = group.0.0
  113.             group.0.gcnt = nametxt
  114.             group.gcnt.0 = slen
  115.             DO gix = 1 TO slen
  116.                 group.gcnt.gix = C2D(REVERSE(CHARIN(cimaddr,cimpos,2)),2)
  117.                 cimpos = cimpos + 2
  118.             END
  119.             /* skip 0-pad byte */
  120.             cimpos = cimpos + 1
  121.             nametxt = "Group:" nametxt "(" || slen "names)"
  122.         END
  123.         ELSE DO    /* acquire name information */
  124.             /* reverse name if comma is found: last, first => first last */
  125.             endsurname = POS(",", strdat)
  126.             IF endsurname > 0 THEN DO
  127.                 strdat = SUBSTR(strdat,endsurname+1) || ,
  128.                          " " || ,
  129.                          SUBSTR(strdat,1,endsurname-1)
  130.             END
  131.             /* reconstitute and fix case of name */
  132.             nametxt = ""
  133.             DO nsegcnt = 1 TO words(strdat)
  134.                 nameseg = WORD(strdat,nsegcnt)
  135.                 nametxt = nametxt || OVERLAY(TRANSLATE(SUBSTR(nameseg,2),lowert,uppert),nameseg,2) || " "
  136.             END
  137.  
  138.             /* get the PPN */
  139.             slen = C2D(CHARIN(cimaddr,cimpos,1))
  140.             strdat = STRIP(CHARIN(cimaddr,cimpos+1,slen),"B")
  141.             cimpos = cimpos + 1 + slen
  142.             nametxt = nametxt strdat
  143.  
  144.             /* get the comments */
  145.             slen = C2D(CHARIN(cimaddr,cimpos,1))
  146.             strdat = STRIP(CHARIN(cimaddr,cimpos+1,slen),"B")
  147.             cimpos = cimpos + 1 + slen
  148.             IF strdat <> "" THEN DO
  149.                 /* un-comment this to change case of comments */
  150.                 /*
  151.                 strdat = OVERLAY(TRANSLATE(SUBSTR(strdat,2),lowert,uppert),strdat,2)
  152.                 */
  153.                 /* blank out any @b0x0A combos (CIM endline) and 0x0D0A (WINCIM) */
  154.                 eolpos = 1
  155.                 IF cimtype = 1 THEN DO FOREVER
  156.                     eolpos = POS("@b" || "0A"x,strdat,eolpos)
  157.                     IF eolpos = 0 THEN LEAVE
  158.                     strdat = DELSTR(strdat,eolpos,2)
  159.                 END
  160.                 ELSE IF cimtype = 2 THEN DO FOREVER
  161.                     eolpos = POS("0D0A"x, strdat,eolpos)
  162.                     IF eolpos = 0 THEN LEAVE
  163.                     strdat = DELSTR(strdat,eolpos,1)
  164.                 END
  165.                 strdat = TRANSLATE(strdat," ","0A"x)
  166.             END
  167.             nametxt = nametxt '|' strdat
  168.  
  169.             /* see if any group names can be appended */
  170.             DO gcnt = 1 TO group.0.0
  171.                 DO gix = 1 TO group.gcnt.0
  172.                     IF group.gcnt.gix = ncnt THEN DO
  173.                         nametxt = nametxt "[" || group.0.gcnt || "]"
  174.                         LEAVE gix
  175.                     END
  176.                 END
  177.             END
  178.         END
  179.  
  180.         /* mention the name on-screen */
  181.         SAY "#" ncnt "=" nametxt
  182.         /* write the new address for GCP if it isn't a group */
  183.         IF \ isagroup THEN DO
  184.             IF LINEOUT(gcpaddr,nametxt) <> 0 & \ isagroup THEN DO
  185.                 SAY "Gagged writing to" gcpaddr "!"
  186.                 LEAVE nnames
  187.             END
  188.         END
  189.     END
  190. END
  191.  
  192.  
  193. HALT:
  194. IF POS(cimok,"NOTREADY:") = 1 THEN SAY "Couldn't find the CIM address book file!"
  195. ELSE IF cimok = "READY:" THEN CALL STREAM cimaddr,"C","CLOSE"
  196. IF POS(gcpok,"NOTREADY:") = 1 THEN SAY "Couldn't find the GCP address book file!"
  197. ELSE IF gcpok <> "READY:" THEN CALL STREAM gcpaddr,"C","CLOSE"
  198. EXIT
  199.