/* YAM->Eucalyptus Address book conversion script v1.1
// by Deryk Robosson
// newlook@ameritech.net
// http://linux.tc3net.com
//
// v1.0 (24.10.97) Initial Creation
// v1.1 (25.10.97) (Gandalf) Corrected problem
//                 where the script would not add
//                 items with spaces in them.
*/
options results

yam_book = 'yam:.addressbook'

if ~show(ports,'EUCALYPTUS') then do
  say 'Eucalyptus must be running prior to running this script.'
  exit
end

if exists(yam_book) then do
  if open(file,yam_book,'R') then do
    do until eof(file)
      line=readln(file)
      select
        when pos('@USER',line) ~= 0 then do
          parse var line blah' 'name
          address = readln(file)
          realname = readln(file)
          if realname == '' then realname = name
          comment = readln(file)
          line = readln(file)
          address EUCALYPTUS 'NewAddress "'realname'" "'address'" COMMENTS "'comment'"'
        end
        when pos('@GROUP',line) ~= 0 then do
          parse var line cmd' 'gp
          address EUCALYPTUS 'NewAddress "'gp'" "" GROUP'
          line=readln(file) /* get group comment */
          address EUCALYPTUS 'EditAddress "'gp'" COMMENT "'line'"'
          line=readln(file) /* get first group item */
          do while (pos('@ENDGROUP',line) == 0)
            if pos('@USER',line) ~= 0 then do
              parse var line blah' 'name
              address = readln(file)
              realname = readln(file)
              if realname == '' then realname = name
              comment = readln(file)
              line = readln(file)
              address EUCALYPTUS 'NewAddress "'realname'" "'address'" COMMENTS "'comment'" MEMBER "'gp'"'
            end
            line=readln(file)
          end
          line=readln(file)
        end
        otherwise nop
      end
    end
  end
end
else do
  say 'Error locating 'yam_book'.'
  say 'Please check to see if 'yam_book' is a valid'
  say 'path and filename. If it is not, please edit'
  say 'the yam_book variable to point to the correct'
  say 'path and filename of the YAM address book.'
end
