(*PROBABLY OBSOLETE DEFINITION MODULE Misc;*)
DEFINITION MODULE Misc;

        (********************************************************)
        (*                                                      *)
        (*                   Monitor for FtpServer              *)
        (*                 Miscellaneous procedures             *)
        (*                                                      *)
        (*    Started:        29 March 2000                     *)
        (*    Last edited:    9 December 2018                   *)
        (*    Status:         OK                                *)
        (*                                                      *)
        (********************************************************)


(*
FROM SYSTEM IMPORT
    (* type *)  LOC, CARD16, CARD32;
*)
FROM Arith64 IMPORT
    (* type *)  CARD64;

(*
TYPE
    CharArrayPointer = POINTER TO ARRAY [0..MAX(CARDINAL) DIV 4] OF CHAR;

*)
(*
PROCEDURE EVAL (f: ARRAY OF LOC);

    (* A do-nothing procedure - we use it for evaluating a function and *)
    (* ignoring the result.                                             *)

PROCEDURE Swap2 (val: CARD16): CARD16;

    (* Returns the argument value in byte-reversed order.  This is needed       *)
    (* because network byte order is most significant byte first, whereas our   *)
    (* local host order is least significant byte first.                        *)

PROCEDURE Swap4 (val: CARD32): CARD32;

    (* Returns the argument value in byte-reversed order.  This is needed       *)
    (* because network byte order is most significant byte first, whereas our   *)
    (* local host order is least significant byte first.                        *)

PROCEDURE NameIsNumeric (VAR (*INOUT*) name: ARRAY OF CHAR): BOOLEAN;

    (* Returns TRUE iff name has the form N.N.N.N or [N.N.N.N] where each N is  *)
    (* a decimal number.  (The present version actually accepts an arbitrary    *)
    (* number of numbers separated by dots.)  As a side-effect, we also strip   *)
    (* the square brackets if they are present.                                 *)

PROCEDURE IPToString (IP: ARRAY OF LOC;  EncloseInBrackets: BOOLEAN;
                                VAR (*OUT*) result: ARRAY OF CHAR);

    (* Converts a four-byte IP address (in network byte order) to a             *)
    (* human-readable form.  There must be at least 15 character positions      *)
    (* available in the result array, or 17 if EncloseInBrackets is TRUE.       *)

PROCEDURE ConvertCard (number: CARDINAL;  VAR (*OUT*) result: ARRAY OF CHAR;
                                          VAR (*INOUT*) pos: CARDINAL);

    (* Converts number to decimal, left justified starting at result[pos].      *)
    (* On return pos is updated to the next unused array index.                 *)

PROCEDURE Card64ToString (number: CARD64;  VAR (*OUT*) result: ARRAY OF CHAR;
                                           VAR (*INOUT*) pos: CARDINAL);

    (* Converts number to decimal, left justified starting at result[pos].      *)
    (* On return pos is updated to the next unused array index.                 *)
*)
PROCEDURE StringToCard64 (VAR (*IN*) string: ARRAY OF CHAR;
                                          VAR (*INOUT*) pos: CARDINAL): CARD64;

    (* Reads a decimal number starting at string[pos], updates pos.     *)
    (* This is the same as StringToCard, below, except that we do the   *)
    (* calculation in 64-bit arithmetic.                                *)
(*
PROCEDURE StringToCard (VAR (*IN*) string: ARRAY OF CHAR;
                                          VAR (*INOUT*) pos: CARDINAL): CARDINAL;

    (* Reads a decimal number starting at string[pos], updates pos. *)

PROCEDURE StringToIPAddress (VAR (*IN*) name: ARRAY OF CHAR;
                                          VAR (*INOUT*) pos: CARDINAL): CARDINAL;

    (* Converts a string of the form N.N.N.N or [N.N.N.N], where each N is a    *)
    (* decimal number, starting at name[pos] and updating pos.  We assume that  *)
    (* the caller has already checked for syntactic correctness.                *)
*)

END Misc.

