home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pmos2002.zip / SRC / fieldedi.mod < prev    next >
Text File  |  1998-01-28  |  9KB  |  242 lines

  1. IMPLEMENTATION MODULE FieldEditor;
  2.  
  3.         (********************************************************)
  4.         (*                                                      *)
  5.         (*              Screen editing utilities                *)
  6.         (*                                                      *)
  7.         (*  Programmer:         P. Moylan                       *)
  8.         (*  Last edited:        9 November 1997                 *)
  9.         (*  Status:             Seems to be OK                  *)
  10.         (*                                                      *)
  11.         (********************************************************)
  12.  
  13. FROM SYSTEM IMPORT
  14.     (* type *)  CARD8, ADDRESS;
  15.  
  16. FROM Storage IMPORT
  17.     (* proc *)  ALLOCATE, DEALLOCATE;
  18.  
  19. FROM Windows IMPORT
  20.     (* type *)  Window,
  21.     (* proc *)  WriteString, EditString;
  22.  
  23. FROM NumericIO IMPORT
  24.     (* proc *)  WriteHexByte, EditHexByte, WriteRJCard, EditCardinal;
  25.  
  26. FROM RealIO IMPORT
  27.     (* proc *)  WriteReal, EditReal;
  28.  
  29. (************************************************************************)
  30.  
  31. TYPE
  32.     BytePtr = POINTER TO CARD8;
  33.     CardPtr = POINTER TO CARDINAL;
  34.     RealPtr = POINTER TO REAL;
  35.     (*
  36.     <* M2EXTENSIONS + *>
  37.     StringPtr = POINTER TO ARRAY OF CHAR;
  38.     <* M2EXTENSIONS - *>
  39.     *)
  40.     StringPtr = POINTER TO ARRAY [0..511] OF CHAR;
  41.  
  42.     FieldType =  POINTER TO RECORD
  43.                                 FieldWriter: WriteProc;
  44.                                 FieldEditor: EditProc;
  45.                             END (*RECORD*);
  46.  
  47. (************************************************************************)
  48. (*              SCREEN OUTPUT FOR THE PREDEFINED TYPES                  *)
  49. (************************************************************************)
  50.  
  51. PROCEDURE WriteCardinalField (w: Window;  p: ADDRESS;  width: CARDINAL);
  52.  
  53.     VAR address: CardPtr;
  54.  
  55.     BEGIN
  56.         address := p;
  57.         WriteRJCard (w, address^, width);
  58.     END WriteCardinalField;
  59.  
  60. (************************************************************************)
  61.  
  62. PROCEDURE WriteByteField (w: Window;  p: ADDRESS;  width: CARDINAL);
  63.  
  64.     VAR address: BytePtr;
  65.  
  66.     BEGIN
  67.         address := p;
  68.         WriteHexByte (w, address^);
  69.     END WriteByteField;
  70.  
  71. (************************************************************************)
  72.  
  73. PROCEDURE WriteRealField (w: Window;  p: ADDRESS;  width: CARDINAL);
  74.  
  75.     VAR address: RealPtr;
  76.  
  77.     BEGIN
  78.         address := p;
  79.         WriteReal (w, address^, width);
  80.     END WriteRealField;
  81.  
  82. (************************************************************************)
  83.  
  84. PROCEDURE WriteStringField (w: Window;  p: ADDRESS;  width: CARDINAL);
  85.  
  86.     VAR address: StringPtr;
  87.  
  88.     BEGIN
  89.         address := p;
  90.         WriteString (w, address^);
  91.     END WriteStringField;
  92.  
  93. (************************************************************************)
  94. (*                  EDITORS FOR THE PREDEFINED TYPES                    *)
  95. (************************************************************************)
  96.  
  97. PROCEDURE EditByteField (w: Window;  VAR (*INOUT*) p: ADDRESS;  width: CARDINAL);
  98.  
  99.     VAR address: BytePtr;
  100.  
  101.     BEGIN
  102.         address := p;
  103.         EditHexByte (w, address^);
  104.     END EditByteField;
  105.  
  106. (************************************************************************)
  107.  
  108. PROCEDURE EditCardinalField (w: Window;  VAR (*INOUT*) p: ADDRESS;  width: CARDINAL);
  109.  
  110.     VAR address: CardPtr;
  111.  
  112.     BEGIN
  113.         address := p;
  114.         EditCardinal (w, address^, width);
  115.     END EditCardinalField;
  116.  
  117. (************************************************************************)
  118.  
  119. PROCEDURE EditRealField (w: Window;  VAR (*INOUT*) p: ADDRESS;  width: CARDINAL);
  120.  
  121.     VAR address: RealPtr;
  122.  
  123.     BEGIN
  124.         address := p;
  125.         EditReal (w, address^, width);
  126.     END EditRealField;
  127.  
  128. (************************************************************************)
  129.  
  130. PROCEDURE EditStringField (w: Window;  VAR (*INOUT*) p: ADDRESS;  width: CARDINAL);
  131.  
  132.     VAR address: StringPtr;
  133.  
  134.     BEGIN
  135.         address := p;
  136.         EditString (w, address^, width);
  137.     END EditStringField;
  138.  
  139. (************************************************************************)
  140. (*                         COMPARING TYPES                              *)
  141. (************************************************************************)
  142.  
  143. PROCEDURE SameType (t1, t2: FieldType): BOOLEAN;
  144.  
  145.     (* Returns TRUE iff t1 = t2.        *)
  146.  
  147.     BEGIN
  148.         RETURN t1 = t2;
  149.     END SameType;
  150.  
  151. (************************************************************************)
  152. (*                      DEFINING A NEW TYPE                             *)
  153. (************************************************************************)
  154.  
  155. PROCEDURE DefineFieldType (Writer: WriteProc;  Editor: EditProc): FieldType;
  156.  
  157.     (* Introduces a new field type into the system.  Writer is a        *)
  158.     (* user-supplied procedure to write a variable of the new type.     *)
  159.     (* Editor is the user-supplied procedure for editing a variable of  *)
  160.     (* that type.                                                       *)
  161.  
  162.     VAR result: FieldType;
  163.  
  164.     BEGIN
  165.         NEW (result);
  166.         WITH result^ DO
  167.             FieldWriter := Writer;
  168.             FieldEditor := Editor;
  169.         END (*WITH*);
  170.         RETURN result;
  171.     END DefineFieldType;
  172.  
  173. (************************************************************************)
  174.  
  175. PROCEDURE DiscardFieldType (type: FieldType);
  176.  
  177.     (* A notification from the user that this type will not be used     *)
  178.     (* again (unless it is redefined by another call to procedure       *)
  179.     (* DefineFieldType).  Use of this procedure is optional, but is     *)
  180.     (* recommended for the sake of "clean" memory management.           *)
  181.  
  182.     BEGIN
  183.         DISPOSE (type);
  184.     END DiscardFieldType;
  185.  
  186. (************************************************************************)
  187. (*                          SCREEN OUTPUT                               *)
  188. (************************************************************************)
  189.  
  190. PROCEDURE WriteField (w: Window;  address: ADDRESS;  type: FieldType;
  191.                                                         width: CARDINAL);
  192.  
  193.     (* Writes address^ on the screen at the current cursor position in  *)
  194.     (* window w.  The width parameter specifies how many character      *)
  195.     (* positions to use.  Use width=0 for variable-width fields for     *)
  196.     (* which the write procedure for that type must work out the width. *)
  197.  
  198.     BEGIN
  199.         WITH type^ DO
  200.             FieldWriter (w, address, width);
  201.         END (*WITH*);
  202.     END WriteField;
  203.  
  204. (************************************************************************)
  205. (*                           THE EDITOR                                 *)
  206. (************************************************************************)
  207.  
  208. PROCEDURE EditField (w: Window;  VAR (*INOUT*) address: ADDRESS;
  209.                                 type: FieldType;  width: CARDINAL);
  210.  
  211.     (* Edits the variable at the given address, and of the given type,  *)
  212.     (* at the current cursor position in window w.  The width parameter *)
  213.     (* specifies how many character positions are to be used on the     *)
  214.     (* screen.  Set width=0 for variable-width fields where the editor  *)
  215.     (* must determine the width.  We leave this procedure on seeing a   *)
  216.     (* keyboard character which does not belong to us.  The cursor is   *)
  217.     (* left just beyond the last character of the field as it is        *)
  218.     (* displayed.  The terminating keystroke is returned to the         *)
  219.     (* keyboard driver so that it can still be read by the caller.      *)
  220.  
  221.     BEGIN
  222.         WITH type^ DO
  223.             FieldEditor (w, address, width);
  224.         END (*WITH*);
  225.     END EditField;
  226.  
  227. (************************************************************************)
  228. (*                      SETTING UP THE PREDEFINED TYPES                 *)
  229. (************************************************************************)
  230.  
  231. BEGIN
  232.     Byte := DefineFieldType (WriteByteField, EditByteField);
  233.     Cardinal := DefineFieldType (WriteCardinalField, EditCardinalField);
  234.     Real := DefineFieldType (WriteRealField, EditRealField);
  235.     String := DefineFieldType (WriteStringField, EditStringField);
  236. FINALLY
  237.     DiscardFieldType (Byte);
  238.     DiscardFieldType (Cardinal);  DiscardFieldType (Real);
  239.     DiscardFieldType (String);
  240. END FieldEditor.
  241.  
  242.