-- File: FilerImpl.mesa - last edit:
-- BJackson.pa         23-Jun-85  0:07:09

-- Copyright (C) 1985 by Xerox Corporation. All rights reserved.

DIRECTORY
  FileName USING [AllocVFN, FreeVFN, VirtualFilename],
  FileTransfer USING [
    Connection, Copy, Create, Delete, Error, ErrorCode, SetPrimaryCredentials,
    SetSecondaryCredentials],
  Put USING [Line, LongString],
  Filer;

FilerImpl: PROGRAM IMPORTS FileName, FileTransfer, Put EXPORTS Filer =
  BEGIN

  agentName: LONG STRING = "PrintAgent.Demo";
  agentDirectory: LONG STRING = "Cedar";
  agentPassword: LONG STRING = "SIGPLAN";

  msg: ARRAY FileTransfer.ErrorCode OF LONG STRING = [
    "(00) illegalParameters"L, "(01) invalidObject"L, "(02) notAStream"L,
    "(03) ==??=="L, "(04) illegalLogin"L, "(05) illegalConnect"L,
    "(06) skipFile"L, "(07) skipOperation"L, "(08) cantModify"L, "(09) retry"L,
    "(10) directoryFull"L, "(11) notFound"L, "(12) accessDenied"L,
    "(13) spare3"L, "(14) spare4"L, "(15) ==??=="L, "(16) ==??=="L,
    "(17) ==??=="L, "(18) ==??=="L, "(19) ==??=="L, "(20) ==??=="L,
    "(21) ==??=="L, "(22) ==??=="L, "(23) ==??=="L, "(24) ==??=="L,
    "(25) ==??=="L, "(26) ==??=="L, "(27) ==??=="L, "(28) ==??=="L,
    "(29) ==??=="L, "(30) ==??=="L, "(31) unknown"L];

  fromconn: FileTransfer.Connection ← NIL;
  fromvfn: FileName.VirtualFilename;
  toconn: FileTransfer.Connection ← NIL;
  tovfn: FileName.VirtualFilename;

  File: PUBLIC PROCEDURE [from, to: LONG STRING] =
    BEGIN
    failed: BOOLEAN ← FALSE;

    tovfn ← FileName.AllocVFN[to];
    fromvfn ← FileName.AllocVFN[from];

    FileTransfer.Copy[
      sourceFile: fromvfn, destFile: tovfn, sourceConn: fromconn,
      destConn: toconn, veto: NIL, showDates: FALSE !
      FileTransfer.Error => {
        Put.LongString[NIL, "FileTransfer.Error in File.Copy: "L];
        Put.Line[NIL, msg[code]];
        SELECT code FROM
          illegalParameters, invalidObject, notAStream, illegalLogin,
            illegalConnect, skipOperation, cantModify, retry, directoryFull,
            notFound, accessDenied, skipFile, unknown => {
            failed ← TRUE; CONTINUE};
          ENDCASE;
        }];

    IF (NOT failed) THEN
      FileTransfer.Delete[
        conn: fromconn, file: fromvfn, veto: NIL !
        FileTransfer.Error => {CONTINUE}];

    FileName.FreeVFN[tovfn];
    FileName.FreeVFN[fromvfn];


    END;  <<File>>

  Init: PROCEDURE =
    BEGIN
    toconn ← FileTransfer.Create[];
    fromconn ← FileTransfer.Create[];

    FileTransfer.SetPrimaryCredentials[
      conn: toconn, user: agentName, password: agentPassword];

    --    FileTransfer.SetSecondaryCredentials[
    --      conn: toconn, connectName: agentDirectory,
    --      connectPassword: agentPassword];

    END;  <<Init>>

  <<Main>>
  Init[];
  END...	<<FilerImpl>>