home *** CD-ROM | disk | FTP | other *** search
- Tp5wio is a Turbo Pascal Version 4.0 or 5.x Unit which consists of a
- collection of procedures and functions which assist in
- screen input/output. Many other uses in general programming are
- available as well. The strings used are defined as Pascal strings
- (string[255]) so you must be careful the string you are using is
- suitable for the screen. This was done to allow the routines to be
- used for printer or disk report generation as well as the screen.
- NOTE: This Pascal Unit will not work with Turbo Pascal Version 3.x
- without a lot of modification.
-
- This file contains the interface sections of tp5misc.pas and tp5wio.pas
- which defines the various routines and has a short comment about each one.
- Note that there are now two units created, TP5MISC.TPU and TP5WIO.TPU the
- tp5misc.pas file must be compiled and listed in the uses statement of your
- program first! The units must be compiled with the compiler you are
- using (either Version 4.0 or 5.0 or 5.5).
-
- All variables must be initialized by the user before calling a routine
- in this package or unusual results will happen (normal for Pascal
- anyway).
-
- The global variables fld and scrn deserve a short mention here, they
- are used to allow full screen and multi-screen input. Each variable
- is designed to be used in a repeat -- until loop where they will be
- adjusted by the program by the up/down arrow keys and the PgUp/Pgdn
- keys.
-
- The fld variable is updated after each screen input function (i.e.
- read_str, read_int, etc). Below is a short program fragment to show
- how this variable is used.
-
- fld := 1; { expecting to use the first case element }
- repeat
- case fld of
- 1 :read_int(intvar,3,20,5);
- 2 :read_str(name,20,20,6);
- 3 :read_str(address,30,20,7);
- end; {case}
- until (fld < 1) or (fld > 3);
-
- In the above example the cursor will start at x=20, y=5 and wait for a
- 3 character input which will be returned in the integer variable
- intvar. Return or down arrow will accept the input and move to the
- next field at x=20, y=6. Going off the top, off the bottom, Page Up,
- or Page Down will terminate the entries and exit the repeat - until
- loop.
-
- The scrn variable is used in an outer repeat - until loop which calls
- inner repeat - until loops (procedures) and allows multi-page input
- screens to be built. The scrn variable is not done automatically but
- you must call the procedure do_scrn_ctl to update it to a new value.
- Be sure to set the scrn variable to the starting screen before calling
- the routine which uses it.
-
- The window system is very simple but is adequate for many projects.
- There are only 10 windows allowed (though you may change it if
- desired) and if an error (invalid screen coordinates, out of heap space,
- to many windows) occurs, a message to that effect, including the reason
- for the error will be presented in the middle of the screen in a semi
- window (remember all windows are used). Any key will return to the DOS
- prompt with all windows already defined deleted. This should not happen
- in a production program, but is handy when developing a program.
-
- The endwindows procedure should be placed as the last statment in your
- program (if you are using the windows) to insure all windows are
- closed.
-
- Added the inv_col_flag which is set by the init section and is true if
- a color card is found. Along with this is the inv_color which is set
- to green, this color is used instead of inverting the foreground and
- background for highlighting. Both of these may be changed by the user
- program.
-
- This work has and is released to the Public Domain for whatever
- purposes you desire. Credit has been given to other authors where
- needed. Have fun with it --- Gerry Rohr --- Below is the definition
- of all procedures and functions available to the user.
-
- unit tp4wio;
- { -- Global I/O procedures to include in programs generally
- Much credit is due Bill Meacham who wrote the original file IO22.INC
- and released it to the public domain. Using that work this unit was
- created and added to by Gerald Rohr of Homogenized Software. As
- with Bill's work, this program is released to the Public Domain for
- all to use and modify.
- REVISION HISTORY
- ---------------------------------------------------------------------
- Ver 2.22 - Converted to a Turbo pascal V4 units. 30 Dec 87 gbr
- Ver 2.30 - Converted dates to longint types 19 Jan 88 gbr
- Ver 2.42 - Added global inv_flag for all write routines 08 Apr 88 gbr
- Ver 2.43 - Added long integer read and write routines 01 May 88 gbr
- Ver 2.43 - Added month and month/day routines 10 May 88 gbr
- Ver 3.00 - Replaced Window procedures/Reformated file 15 Jul 88 gbr
- Ver 3.10 - Moved Window error routines here 26 Aug 88 gbr
- Ver 3.20 - Added code and globals for color hi lights 27 Aug 88 gbr
- Ver 3.21 Fixed leading decimal point in read_real 02 Sep 88 gbr
- Ver 3.25 Added longint to/from packed string[4] 02 Sep 88 gbr
- Ver 3.26 Added sys_time global variable 07 Sep 88 gbr
- Ver 3.30 Recompiled with Turbo Pascal Version 5.0 29 Sep 88 gbr
- Ver 3.40 Added Month Name (string) 05 Oct 88 gbr
- Ver 3.50 Changed to use actual scan codes 30 Oct 88 gbr
- Ver 3.60 Added RW word, byte 18 Nov 88 gbr
- Ver 3.70 Moved many routines to tp5misc.tpu 10 Dec 88 gbr
- Ver 3.80 Added Vtp5wio function 24 Mar 89 gbr
- Ver 3.90 Added mk_dt_sts() date without century 28 Mar 89 gbr
- Ver 4.00 Added color definitions to windows 06 Jul 89 gbr
- Ver 4.10 Added openwind to open window with default col.07 Jul 89 gbr
- --------------------------------------------------------------------- }
-
- interface
-
- uses
- crt,dos;
-
- const
- fdslen = 29 ; { length of fulldatestring }
-
- type
- datestring = string[10] ; { 'MM/DD/YYYY' }
-
- fulldatestring = string[fdslen] ;
-
- juldate = record
- yr : integer ; { 0 .. 9999 }
- day : integer ; { 1 .. 366 }
- end ;
-
- juldatestring = string[8] ; { 'YYYY/DDD' }
-
- montharray = array [1 .. 13] of integer ;
-
- intst = string[2]; { string of an integer }
-
- var
- sys_date :longint;
- null_date :longint;
- null_date_str : datestring;
-
- fld, scrn : integer ; { For field & screen cursor control }
- macro :array[1..10] of string; { Function key macro storage }
- inv_flag :boolean; { if true all write routines inverse the screen,
- set to false by initialization. User uses
- this flag to control the screen attributes.}
- col_inv_flag :boolean; { true if color monitor, false if monochrome,
- set by initialization routine, User may change. }
- inv_color :byte; { color to use for inverse data if col_inv_flag
- is true. Defaults to green, but user may change. }
- in_window :boolean; { if true then we are in a window, used by the
- screen writing routines to high light screen
- data. NOTE high lighting can only be done when
- in_window flag is true. }
- reserv_wind :integer; { number of windows to reserve (not close) with
- endwindows procedure. Initialized to 0, use
- with multiple program files. }
- text_fg, { Text foreground color }
- text_bg, { Text background color }
- framefgnd, { window border color }
- framebkgnd, { window background color }
- title_color, { window title color }
- err_fg, { error message foreground }
- err_bg, { error message background }
- msg_fg, { message foreground }
- msg_bg { message background }
- :byte;
-
- The following procedures and functions are contained in TP5MISC.PAS:
-
- function wdtostr(n:word):st2;
- { converts word to packed two char string }
- function strtowd(s:st2):word;
- { converts packed two char string to word }
- function bttostr(n:byte):st2;
- { converts byte to packed char string }
- function strtobt(s:st2):byte;
- { converts packed char string to byte }
- function dbasetodate(s:string):longint;
- { convert the dbase sdf date dump (YYYYMMDD) to a longint with
- the same format }
- function datetodbase(var dbdate:longint):string;
- { convert the hs date record to dbase sdf date dump (YYYYMMDD) }
- function strtointeger(st:st5):integer;
- { Converts a string to integer value, returns -1 on error }
- function strtoword(st:st5):word;
- { Converts a string to word value, returns 0 on error }
- function strtobyte(st:st5):byte;
- { Converts a string to byte value, returns 0 on error }
- FUNCTION PAD (st : string ; ch : char ; i : integer) : string ;
- { Pad string with ch to length of i. }
- FUNCTION UPPER (st :string):string;
- { returns upper case of st }
- FUNCTION STRIPCH (instr:string ; inchar:char) : string ;
- {Strips leading instances of the character from the string}
- FUNCTION TRIM (st:string;len:integer):string;
- { Chops spaces from string or truncates at l length }
- FUNCTION CHOPCH (instr:string ; inchar:char) : string ;
- {Chops trailing instances of the character from the string}
- FUNCTION INTTOSTR(n:integer):st2;
- { converts integer to packed two char string }
- FUNCTION STRTOINT(s:st2):integer;
- { converts packed two char string to integer }
- FUNCTION LINTTOST4(n:longint):st4;
- { converts long integer to packed 4 character string }
- FUNCTION ST4TOLINT(s:st4):longint;
- { converts packed four character string to longint }
- { --- File tools --- }
- FUNCTION EXIST(FN : String) : boolean;
- { Returns true if file named by FN exists }
- FUNCTION REMOVE(FN : string):boolean;
- { Erases the file named by FN, returns TRUE if erased }
-
- The following functions and procedures are contained in tp5wio.pas, the
- file tp5wio.inc is included at compile time. Some of these functions
- and procedures require that tp5misc.tpu be available.
-
- PROCEDURE CLRLINE (col,row : integer);
- PROCEDURE BEEP ;
- PROCEDURE DO_FLD_CTL (key : integer);
- { Adjusts global FLD based on value of key, the ordinal value
- of last key pressed }
- PROCEDURE DO_SCRN_CTL ;
- { Checks value of FLD and adjusts value of SCRN accordingly }
- PROCEDURE WRITE_STR (st:string ; col,row:integer);
- PROCEDURE WRITE_TEMP(var ln:string;tmp:string;x,y:integer);
- { writes a string using a template. the string (ln) is printed
- left justified in the template using the filler locations.
- quits when the template is complete on the screen. Fills unused
- template filler locations with space. }
- PROCEDURE WRITE_INT (i:integer ; width,col,row:integer);
- PROCEDURE WRITE_WORD(i:word; width,col,row:integer);
- PROCEDURE WRITE_BYTE(i:byte;width,col,row:integer);
- PROCEDURE WRITE_LINT(lint:longint;width,col,row:integer);
- PROCEDURE SET_BOOL (var bool : boolean);
- { Sets boolean to be undefined, neither true nor false.
- Boolean is stored as one byte:
- $80 = undefined
- $01 = true
- $00 = false.
- Note : Turbo interprets $80 as true because it is greater than zero! }
- FUNCTION DEFINED (bool : boolean) : boolean ;
- { Determines whether the boolean is defined or not }
- PROCEDURE WRITE_BOOL (bool:boolean ; col, row:integer);
- PROCEDURE WRITE_REAL (r:real ; width,frac,col,row:integer);
- FUNCTION BUILD_STR (ch : char ; n : integer) : string ;
- { returns a string of length n of the character ch }
- PROCEDURE READ_STR (var st:string ; maxlen, col, row:integer);
- { Read String. This procedure gets input from the keyboard one
- character at a time and edits on the fly, rejecting invalid
- characters. COL and ROW tell where to begin the data input
- field, and MAXLEN is the maximum length of the string to be
- returned.
- Only use the Function keys for string input data, for other
- types of input will beep. }
- PROCEDURE READ_TEMP(var st:string;tmp:string;col, row:integer);
- { Read string with a template. This procedure gets input from
- the keyboard one character at a time and edits on the fly,
- rejecting invalid characters. tmp is a template which is filled
- in where filler characters exist, any other characters are displayed
- on the screen. Returned string does NOT have the template imbeded in
- it. COL and ROW tell where to begin the data input
- field, Max length of the string is the max length of the template.
- }
- PROCEDURE READ_INT (var int:integer ; maxlen, col, row:integer);
- { Read Integer. This procedure gets input from the keyboard
- one character at a time and edits on the fly, rejecting
- invalid characters. COL and ROW tell where to begin the data
- input field, and MAXLEN is the maximum length of the integer
- to be returned. }
- PROCEDURE READ_LINT (var lint:longint ; maxlen, col, row:integer);
- { Read LongInt. This procedure gets input from the keyboard
- one character at a time and edits on the fly, rejecting
- invalid characters. COL and ROW tell where to begin the data
- input field, and MAXLEN is the maximum length of the integer
- to be returned. }
- PROCEDURE READ_WORD(var wd:word; maxlen,col,row:integer);
- { Read Word. This procedure gets input from the keyboard
- one character at a time and edits on the fly, rejecting
- invalid characters. COL and ROW tell where to begin the data
- input field, and MAXLEN is the maximum length of the word
- to be returned. }
- PROCEDURE READ_BYTE(var bt:byte; maxlen,col,row:integer);
- { Read byte. This procedure gets input from the keyboard
- one character at a time and edits on the fly, rejecting
- invalid characters. COL and ROW tell where to begin the data
- input field, and MAXLEN is the maximum length of the byte
- to be returned. }
-
- FUNCTION EQUAL (r1,r2 : real) : boolean ;
- { tests functional equality of two real numbers -- 4/30/85 }
- FUNCTION GREATER (r1,r2 : real) : boolean ;
- { tests functional inequality of two real numbers -- 5/1/85 }
- PROCEDURE READ_REAL (var r:real ; maxlen,frac,col,row:integer);
- { Read Real. This procedure gets input from the keyboard
- one character at a time and edits on the fly, rejecting
- invalid characters. COL and ROW tell where to begin the data
- input field; MAXLEN is the maximum length of the string
- representation of the real number, including sign and decimal
- point; FRAC is the fractional part, the number of digits to
- right of the decimal point.
-
- Note -- In Turbo the maximum number of significant digits in
- decimal (not scientific) representation is 11. In TurboBCD,
- the maximum number of significant digits is 18. It is the
- programmer's responsibility to limit input and computed output
- to the maximum significant digits. }
- PROCEDURE READ_YN (var bool:boolean; col,row:integer);
- { Inputs "Y" OR "N" to boolean at column and row specified,
- prints "YES" or "NO."
- Note -- use this when the screen control will not return
- to the question and the boolean IS NOT defined before the
- user answers the question. Does not affect global FLD. }
- PROCEDURE READ_BOOL (var bool:boolean; col,row:integer);
- { Displays boolean at column and row specified, inputs "Y"
- or "N" to set new value of boolean, prints "YES" or "NO."
- Boolean is "forced;" user cannot cursor forward past undefined
- boolean. Pressing "Y" or "N" terminates entry.
- Boolean is stored as one byte:
- $80 = undefined
- $01 = true
- $00 = false.
- Note : Turbo interprets $80 as true because it is greater
- than zero! }
- PROCEDURE PAUSE ;
- {Prints message on bottom line, waits for user response.
- Changed from line 24 to line 23 for windows gbr}
- PROCEDURE HARD_PAUSE ;
- { Like Pause, but only accepts space bar or Escape and only
- goes forward. Changed from line 24 to line 23 for windows. gbr }
- PROCEDURE SHOW_MSG (msg : string);
- { Beeps, displays message centered on line 22, pauses }
- { changed from line 23 to line 22 for windows. gbr }
- FUNCTION MK_DT_ST (dt :longint) : datestring ;
- { Makes a string out of a date -- used for printing dates,
- includes century (ie MM/DD/YYYY) }
- FUNCTION MK_DT_STS(dt :longint) : datestring ;
- { Makes a string out of a date -- used for printing dates,
- does not include century (ie MM/DD/YY) }
- PROCEDURE WRITE_DATE (dt: longint ; col, row: integer);
- { Writes date at column and row specified }
- FUNCTION MK_JUL_DT_ST (jdt : juldate) : juldatestring ;
- { makes a string out of a julian date }
- PROCEDURE READ_DATE (var dt: longint ; col, row: integer);
- { Read date at column and row specified. If the user enters
- only two digits for the year, the procedure plugs the
- century as 1900 or 2000, but the user can enter all four
- digits to override the plug. }
- FUNCTION GREATER_DATE (dt1, dt2 : longint) : integer ;
- { Compares two dates, returns 0 if both equal, 1 if first is
- greater, 2 if second is greater. }
- PROCEDURE GREG_TO_JUL (dt : longint ; var jdt : juldate);
- { converts a gregorian date to a julian date }
- PROCEDURE JUL_TO_GREG (jdt : juldate ; var dt : longint);
- { converts a julian date to a gregorian date }
- PROCEDURE NEXT_DAY (var dt : longint);
- { Adds one day to the date }
- PROCEDURE PREV_DAY (var dt : longint);
- { Subtracts one day from the date }
- FUNCTION DATE_DIFF (dt1, dt2 : longint) : longint ;
- { computes the number of days between two dates }
- FUNCTION MONTH_DIFF (dt1, dt2 : longint ) : integer ;
- { Computes number of months between two dates, rounded.
- 30.4167 = 356/12, average number of days in a month. }
- FUNCTION EQUAL_DATE (dt1, dt2 : longint) : boolean ;
- { Tests whether two dates are equal }
- FUNCTION BUILD_FULL_DATE_STR (dt : longint) : fulldatestring ;
- { Build printable string of current date -- from ROS 3.4
- source code. }
- FUNCTION MONTH(dt:longint):integer;
- { returns the month portion of a date.}
- FUNCTION DAY(dt:longint):integer;
- { returns the day from the date }
- FUNCTION YEAR(dt:longint;centry:boolean):integer;
- { returns the year of a date. if the centry flag is true
- returns 4 digit year otherwise returns two digit year. }
- FUNCTION MONTH_NAME(mon:integer):string;
- { returns the month name given the month number (1-12) }
-
- { ---- window procedures Derived from article in Computer Language
- Magazine June 1988 by James Kerr ---- }
- PROCEDURE OPENWIND(wtitle:string;x1,y1,x2,y2:byte);
- { Works just like openwindow except uses the default colors
- for text foreground and background. Actually just calls
- openwindow with text_fg and text_bg
- }
- PROCEDURE OPENWINDOW(wtitle:string;x1,y1,x2,y2:byte;
- fgnd,bkgnd: byte);
- { wtitle is centered on the top border line of the window, x
- and y are the window coordinates, fgnd and bkgnd are the
- colors of the inside of the window (note the border is always
- white, if a window can not be opened, a message as to why will
- be displayed and the program exits
- }
- PROCEDURE CLOSEWINDOW;
- { closes the current open window, does nothing if no
- window to close. }
- PROCEDURE ENDWINDOWS;
- { close any open windows when exiting the windows system. Use
- as the last statment in program to insure return to
- enviroment you came from. The global reserv_wind is normally
- set to 0 allowing all windows to be closed, if using a
- multi file window program, reserv_wind can be set to the
- number of windows to be left open when a particular program
- terminates. Always set reserv_wind to 0 before the final
- program call to endwindows.
- }
-
- FUNCTION VTP5WIO:string;
- { Return a string which contains the version of this set of
- routines }
-
- I hope you enjoy these procedures and functions, and they help you
- develope programs as they have me.
-
- Gerry Rohr
- Homogenized Software
- RR#3
- Anamosa, Iowa 52205
-
-