     (********************************************************************
      *                                                                  *
      *         Copyright (c) 1985 by                                    *
      *            Lewis Makepeace and Stan Zanarotti                    *
      *                                                                  *
      *                                                                  *
      *         All rights reserved.                                     *
      *                                                                  *
      ********************************************************************)

[inherit (
          'types.pen',
          'io.pen',
          'sys$library:starlet.pen',
          'system.pen'
)]
module error_stuff;

[hidden]
var saved_code : integer;












[hidden]
function up_shift(c:char):char;
begin
  if (ord(c)>=ord('a')) and (ord(c)<=ord('z')) then
    up_shift:=chr((ord(c)-ord('a'))+ord('A'))
  else
    up_shift:=c
end;  {up_shift}

[global] procedure error_handler (code:codes; str:string);
  { this is the main error procedure. it takes the code and
    prints the corresponding error message. }
var
  msg:string;
  out_line:string;
  message : packed array [1..80] of char;
  msglen : [word] 1..32767;

begin   { error_handler }
   case code of
      no_quota              :msg:='Out of disk quota.';
      no_such_trn           :msg:='Transaction does not exist.';
      inconsistent          :msg:='There is an inconsistency in the meeting file
.';
      no_current_mtg        :msg:='Not attending a meeting.';
      no_access             :msg:='No access for command.';
      not_deleted           :msg:='Transactions were not deleted.';
      already_attending     :msg:='already attending a meeting.';
      no_such_mtg           :msg:='Meeting does not exist.';
      names_same            :msg:='Meeting name duplicates short name.';
      deleted_trn           :msg:='Transaction has been expunged.';
      not_attend            :msg:='Not attending any meeting.';
      not_changed           :msg:='Meeting is not changed.';
      inv_name              :msg:='Invalid meeting name.';
      no_trns_selected      :msg:='Selected transactions were deleted.';
      no_more_mtgs          :msg:='no more meetings.';
      no_meetings           :msg:='No meetings found.';
      dup_mtg_name          :msg:='Meeting name already in use.';
      cli_absent            :msg:='Missing parameter.';
      dup_short_name        :msg:='Meeting name already in use.';
      error_in_start        :msg:='Unable to open meetings file.';
      file_open_already     :msg:='file currently in use.';
      file_not_found        :msg:='File does not exist.';
      file_error,
      file_operation_error  : begin
                                $getmsg (saved_code, msglen, message, 1);
                                msg := substr (message, 1, msglen);
                              end;
      dirty_master_file     :msg:='Invalid master directory file.';
      dirty_user_file       :msg:='Improper format in user directory file.';
      inv_spec              :msg:='Invalid transaction specifier.';
      no_more_trns          :msg:='no more transactions.';
      empty_trn             :msg:='Empty transaction not entered.';
      inv_num               :msg:='Invalid number.';
      inv_range             :msg:='Invalid range.';
      unrec_spec            :msg:='Unrecognized transaction specifier.';
      no_next_trn           :msg:='No more transactions.';
      no_prev_trn           :msg:='No previous transaction.';
      no_last_trn,
      no_first_trn          :msg:='Empty meeting.';
      no_nref_trn           :msg:='At end of chain.';
      no_pref_trn           :msg:='At beginning of chain.';
      no_current_trn        :msg:='No current transaction.';
      otherwise             begin
                              msg:='Unknown error code.';
                                writev (out_line, '   ', code);
                                put_output (out_line);
                            end;
  end;  {case}
  if length(str)<>0 then
    str[1]:=up_shift(str[1]);
  if length(msg)<> 0 then
    msg[1]:=up_shift(msg[1]);
  put_output(str+': '+msg);
end;    { error_handler }

[global]
function fstatus(rms_code:integer):codes;

begin
   saved_code := rms_code;
   if rms_code = rms_fnf then fstatus := file_not_found
   else if rms_code = 0  then fstatus := success
                         else fstatus := file_operation_error;
end;  {fstatus}

end.
