HbRun

HbRun is a console interpreter and program ( command file / script file / .prg / .hrb ) runner for the Harbour Language.

Addendum: a clarification by Przemek:

HBRUN is a simple wrapper to Harbour compiler so the same syntax as in
Cl*pper is supported:

DO <filename>[.prg]

only .prg is accepted as extension and it’s default so you do not
have to set it explicitly.

( In Harbour Users Google group, under “hbmk2 and the Dot Prompt” topic:

It can work as interpreter when invoked without parameters or can execute xBase / Harbour source code in .prg file or compiled Harbour Portable Objects (.hrb) file given as parameter.

Type of file is recognized by extension used with <file> parameter. If not given then .hrb is used.

In other words, HbRun can be use in both interpret  and batch mode.

Regarding parameter given or not, when calling HbRun this ‘mode’ determined by program itself. If a parameter ( usually a .prg or .hrb file name ) given, program run in ‘batch’ mode, runs (executes) given script file and end. If no parameter given, program enter interpreter mode.

Using HbRun as an interpreter, may be very useful, productive, and educative for xBase programmers. Too many xBase programmers was learned everything, including   DBF file system and xBase programming language by famous “dot prompt”. Today many xBase programmers uses HbRun daily basis.

When HbRun begin, open a console screen with two basic area: status bars at top and dot prompt line at bottom.

Status bars :

 hbrunStatLines

Dot prompt is quite simple visually: a dot and a  line in inverse color beginning with a blinking cursor :

 hbRunDotPrompt

You may enter here a command to see the result.

For example “DIR” command will give a list of database (.dbf) files in current directory:

hbRun_Dir

SET COLO TO “GR+/N” command will remember you old days :

hbRun_Dir2

The DIR command can be used with DOS style “filter / skeleton” parameter :

DIR *.PRG
DIR *.*

etc.

Inspecting any table ( .dbf file ) is very simple:

USE CLIENTS
BROWSE ()

 hbrunBrowse

 Expand a little:

SET COLO TO “GB+/N”
USE CLIENTS
BROWSE( 3, 10, 24, 60 )

hbrunBrowse2

If you plan to use this snap frequently, make a .prg file (say brwclien.prg) with this three line and run it with DO command:

DO BRWCLIEN

Sometime LIST command may be better:

LIST CL_ID, CLI_SNAM, CLI_NAME, CLI_TLF

hbrun_list

 You can add FOR clause to the LIST command:

LIST CL_ID, CLI_SNAM, CLI_NAME, CLI_TLF FOR RECN() < 10

or

LIST CL_ID, CLI_SNAM, CLI_NAME, CLI_TLF FOR EMPTY( CLI_TLF )

The structure info of a table frequently requires while daily work to xBase Programmers.

Here three small programs for obtain structure info of a table. Usage is quite simple: open ( USE ) your table and enter DO <prgFileName>; for example:

USE CLIENT
DO LISTSTRU
or
DO DISPSTRU
or
DO SAVESTRU

 Notes :

–      To avoid some possible screen metric conflicts caused by default console (DOS box) settings of OS, may be useful some adjusting before invoke HbRun; such as:

MODE CON LINES=48 COLS=128

–       “?” command may be useful as a built-in calculator :

? 2*2           // 4
? 2**8          // 256
? SQRT( 81 )    // 9

–      HbRun keep a “history” for commands entered (for a limited count of commands of course). You can access (and re-enter when required) by using up and down keys. Moreover this history may be usable after re-invoke HbRun.

–      Though Harbour Language is essential, some legal Harbour commands / functions may be un-recognizable by HbRun.

–      Though some legal statements works in interpret mode, may not works in batch mode (such as Browse() ).

Last Note : No further explanation required for experienced xBase programmers; try, see and learn.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Examples :

 
/*
 DispStru.prg 

 Display structure of current table ( .dbf file ) on screen.

*/
MEMVAR ASTRUCT, NTOTLEN
IF EMPTY( ALIAS() )
   SETCOLOR( "R/N" )
   ? "No active table in the current work area !", LTRIM( STR( SELECT() ) )
ELSE 
   @ 3, 0 CLEA TO MAXROW() - 1, MAXCOL()
   aStruct := DBSTRUCT()
   nTotLen := 1
   AEVAL( aStruct, { | a1Field | nTotLen += a1Field[ 3 ] } )
   AEVAL( aStruct, { | a1Field, n1FieldNo | ;
   aStruct[ n1FieldNo ] := STR( n1FieldNo, 3 ) + " " +;
                           PADR( a1Field[ 1 ], 12 ) +;
                           PADC( a1Field[ 2 ], 4 ) +;
                           PADL( a1Field[ 3 ], 5 ) +;
                           PADL( a1Field[ 4 ], 3 ) } )
   ? "Structure of database :", DBINFO( 10 )
   ? "Number of data records :", LTRIM( STR( LASTREC() ) )
   ? "Date of last update :", LUPDATE()
   ? "Fld Name Type Width Dec"
   ? "--- ---------- ---- ----- ---"
   @ 21,0 SAY "** Total ** " + PADL( nTotLen, 6 )
   ACHOICE( 8, 0, 20, 30, aStruct ) 
ENDIF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
 ListStru.prg 

 List structure of current table ( .dbf file ) on screen.

*/
MEMVAR ASTRUCT, NTOTLEN
IF EMPTY( ALIAS() )
   SETCOLOR( "R/N" )
   ? "No active table in the current work area !", LTRIM( STR( SELECT() ) )
ELSE 
   @ 3, 0 CLEA TO MAXROW() - 1, MAXCOL()
   aStruct := DBSTRUCT()
   nTotLen := 1
   AEVAL( aStruct, { | a1Field | nTotLen += a1Field[ 3 ] } ) 
   AEVAL( aStruct, { | a1Field, n1FieldNo | ;
   aStruct[ n1FieldNo ] := STR( n1FieldNo, 3 ) + " " +;
                           PADR( a1Field[ 1 ], 12 ) +;
                           PADC( a1Field[ 2 ], 4 ) +;
                           PADL( a1Field[ 3 ], 5 ) +;
                           PADL( a1Field[ 4 ], 3 ) } )
   ? "Structure of database :", DBINFO( 10 )
   ? "Number of data records :", LTRIM( STR( LASTREC() ) )
   ? "Date of last update :", LUPDATE()
   ? "Fld Name Type Width Dec"
   ? "--- ---------- ---- ----- ---"
   AEVAL( aStruct, { | c1Field | QOUT( c1Field ) } ) 
   ? "** Total ** ", PADL( nTotLen, 5 )
ENDIF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
SaveStru.prg

 Save structure of current table ( .dbf file ) to a file.

 Notes :

 - This program uses ListStru.prg
 - Name of target file constructed at line 18; 
   if required you may use alternate ways or
   simply using a constant.
*/
MEMVAR AlteFName
IF EMPTY( ALIAS() )
   SETCOLOR( "R/N" )
   ? "No active table in the current work area !", LTRIM( STR( SELECT() ) )
ELSE 
   AlteFName := LEFT( ALIAS(), 4 ) + "STRU" 
   SET ALTE TO &AlteFName
   SET ALTE ON
   DO LISTSTRU
   SET ALTE OFF
   SET ALTE TO
ENDIF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User Interface Terms

Background Color :

The color that appears behind displayed text of another color (the foreground color).

See Also: Foreground Color

Column :

A numeric value that represents a position on the display screen or on the printed page.

Console Input/Output :

A style of operation of the keyboard and display that emulates a simple typewriter-like interface. Console input echoes each key typed and provides processing for the backspace and return keys. Console output wraps to the next line when the output reaches the right edge of the visible display, and scrolls the display when the output reaches the bottom of the visible display.

See Also: Full-screen Input/Output

Cursor :

An onscreen indicator used to show the current keyboard input focus and is displayed as a block or underline character. The cursor moves in response to characters or control keys typed by the user.

Enhanced Color :

The color used to display GETs or PROMPTs (if INTENSITY is ON).

See Also: Standard Color

Foreground Color :

The color of text appearing on the screen, usually on a different colored background.

See Also: Background Color

Full-screen Input/Output :

A style of operation of the keyboard and display used for complex data entry and display tasks. Full-screen input and output are generally performed using the @..SAY, @..GET and READ commands. Full-screen output is distinguished from console-style output by the fact that control characters (e.g., backspace, carriage return) are not processed, and wrapping and scrolling do not occur at the boundaries of the visible display area.

See Also: Console Input/Output

Highlight :

Indicates input focus for menus, browsers, or GETs. With menus and browsers, the currently selected item or cell has input focus and is displayed in the current enhanced color or inverse video. With GETs, the current GET is highlighted in the current enhanced color or inverse video while the other GETs are displayed in the current standard color if an unselected color setting is active.

See Also: Cell, Enhanced Color, Input Focus, Standard Color

Input Focus :

The GET, browse cell, or menu item where user interaction can take place is said to have input focus. The item with input focus usually is displayed in enhanced color or inverse video.

Insert Mode :

A data entry mode entered when the user presses the insert key. When this mode is active, characters are inserted at the cursor position. Text to the right of the cursor is shifted right.

See Also: Overstrike Mode

Keyboard Buffer :

An area of memory dedicated to storing input from the keyboard while a program is unable to process the input. When the program is able to accept the input, the keyboard buffer is emptied.

Menu :

An onscreen list of choices from which the user selects. Menus range from simple to elaborate forms. Two examples are menus that pull down from the top of the screen (an elaborate type requiring more programming), or a simple list of numbered items from which the user selects by entering the appropriate number.

Overstrike Mode :

A data entry mode entered when the user presses the insert key. When this mode is active, characters are entered at the cursor position and text to the right of the cursor remains stationary.

Picture :

A string that defines the format for data entry or display in a GET, SAY, or the return value of TRANSFORM(). Picture strings are comprised of functions which affect the formatting as a whole and a series of template characters that affect formatting on a character by character basis.

See Also: Template

Prompt :

A series of characters displayed on the screen indicating that input from the keyboard is expected.

Relative Addressing :

To refer to a memory address, array element, screen location, or printer location with respect to another value, rather than referring to a specific address or element.

Row :

A numeric expression that evaluates to an integer identifying a screen or printer row position.

See Also: Column, Field, Record

Scoreboard :

An area of the display on line 0 beginning at column 60 that displays status information during certain data entry operations.

Scrolling :

The action that takes place when the user attempts to move the cursor or highlight beyond the window boundary to access information not currently displayed.

See Also: Window

Standard Color :

The color pair definition that is used by all output options (such as SAY and ?), with the exception of GETs and PROMPTs, that use the enhanced color pair.

See Also : Enhanced Color

Template :

A mask that specifies the format in which data should be displayed. For example, you might want to store phone numbers as “9999999999” to save space, but use a template to display the number to the user as “(999) 999-9999.”

Typeahead Buffer :

See : Keyboard Buffer

Unselected Color :

The color pair definition used to display all but the current GET or the GET that has input focus. If this color setting is specified, the current GET is displayed using the current enhanced color.

See Also: Enhanced Color

User Function :

A user-defined function called by ACHOICE(), DBEDIT(), or MEMOEDIT() to handle key exceptions. A user function is supplied to one of these functions by passing a parameter consisting of a string containing the function’s name.

User Interface :

The way a program interacts with its user (i.e., menu operation and selection, data input methods, etc.)

Wait State :

A wait state is any mode that extracts keys from the keyboard except for INKEY(). These modes include ACHOICE(), DBEDIT(), MEMOEDIT(), ACCEPT, INPUT, READ and WAIT.

Window :

A rectangular screen region used for display. A window may be the same size or smaller than the physical screen. Attempting to display information that extends beyond the specified boundaries of the window clips the output at the window edge.

Word Wrapping :

The process of continuing the current text on the next line of a display when a boundary is reached and breaking the text on a word boundary.