Files
harbour-core/harbour/contrib/libnf/dispc.c
Przemyslaw Czerpak a290c984e7 2006-02-04 17:05 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/harbour.spec
  * harbour/make_bsd.sh
  * harbour/make_drw.sh
  * harbour/make_gnu.sh
  * harbour/make_rpm.sh
  * harbour/make_tgz.sh
  * harbour/bin/hb-func.sh
  * harbour/bin/pack_src.sh
  * harbour/config/c.cf
  * harbour/config/global.cf
  * harbour/config/rules.cf
  * harbour/config/darwin/gcc.cf
  * harbour/config/darwin/global.cf
  * harbour/config/dos/djgpp.cf
  * harbour/config/dos/global.cf
  * harbour/config/dos/install.cf
  * harbour/config/dos/owatcom.cf
  * harbour/config/hpux/gcc.cf
  * harbour/config/hpux/global.cf
  * harbour/config/linux/gcc.cf
  * harbour/config/linux/global.cf
  * harbour/config/linux/owatcom.cf
  * harbour/config/sunos/gcc.cf
  * harbour/config/w32/watcom.cf
    * include ADSRDD by default in RPMs
    * updated for new RPM which does not accept some old tags
    * set -fPIC on 64bit platforms
    + added /etc/harbour/hb-charmap.def
    * updated for new GT system and drivers

  * harbour/contrib/dot/pp.prg
  * harbour/contrib/dot/pp_harb.ch
    * use _APMAIN as startup function
    * cleaned direct access to item internals

  * harbour/contrib/libct/Makefile
  + harbour/contrib/libct/ctwfunc.c
  + harbour/contrib/libct/ctwin.c
  + harbour/contrib/libct/ctwin.h
    * added CT3 like Window System - it's a GT driver which inherits
      from the existing one and adds CTW functionality

  * harbour/contrib/libct/screen1.c
    * updated for GTAPI modifications

  * harbour/contrib/libnf/Makefile
  * harbour/contrib/libnf/chdir.c
  * harbour/contrib/libnf/mkdir.c
  * harbour/contrib/libnf/rmdir.c
    * use hb_fs*() API functions instead of calling DOS interrupts
      Now NF dir functions works on all platforms - it will be nice
      to update other functions too.

  * harbour/contrib/libnf/dispc.c
  * harbour/contrib/libnf/ftattr.c
    * updated for GT API modifications, some of this code still depends
      on EGA/VGA video buffer so will work only if user will force in GT
      using it - it will be nice to rewrite them

  * harbour/contrib/odbc/odbc.c
  * harbour/contrib/ole/ole2.c
    * casting and cleaning direct access to item internals

  * harbour/contrib/rdd_ads/ads1.c
  * harbour/contrib/rdd_ads/adsfunc.c
  * harbour/contrib/rdd_ads/adsmgmnt.c
    * synced with xHarbour

  * harbour/include/Makefile
    * added new header files

  + harbour/include/hbgtinfo.ch
    + added GTI_* defintions for hb_gtInfo() function.
      This function works in similar way to dbInfo() in RDD.
      The GTI_* definitions are taken from xHarbour "as is" and
      they should be cleaned - not all functionality are supported
      in Harbour and some others should be implemented in differ
      way then in xHarbour.

  + harbour/include/hbgtcore.h
  * harbour/include/hbapigt.h
    * new GTAPI
      hbgtcore.h file should not be included by user code
      it's only for internal use in GT drivers
    * HB_inkey_enum changed to int - this is bit field not enumerated type.
      Many of C/C++ compilers forbid bit operations on enum types and
      forcing it by casting which finally exceeds the enum range is defined
      as bug because it may badly interacts with some compiler optimizations

  * harbour/include/hbapi.h
  * harbour/include/hbapicdp.h
  * harbour/include/hbapierr.h
  * harbour/include/hbapifs.h
  * harbour/include/hbapiitm.h
  * harbour/include/hbapilng.h
  * harbour/include/hbapirdd.h
  * harbour/include/hbdate.h
  * harbour/include/hbdefs.h
  * harbour/include/hbinit.h
  * harbour/include/hbpcode.h
  * harbour/include/hbrdddbf.h
  * harbour/include/hbset.h
  * harbour/include/hbstack.h
  * harbour/include/hbvm.h
  * harbour/include/hbvmopt.h
  * harbour/include/hbvmpub.h
    * separated internal and external API. Now the definitions for
      internal HVM structures and functions are excluded by default
      they could be enabled if user include hbvmopt.h before other
      header files. Such operation should be done _ONLY_ by core
      code - if 3-rd party developers make sth like that then it's
      for their own risk and such code may stop to work with next
      Harbour versions. Without hbvmopt.h the internal structures
      like HB_ITEM, HB_DYNS, ... are  mapped to 'void' so there is
      no way to access their members so we can modify them in the
      future without afford for 3-rd party code.
      There is one small exception 'type' should be the first member
      for HB_ITEM structure because I used a small ugly hack in
      HB_IS_*() macros with castin PHB_ITEM to HB_TYPE* - it works
      without speed overhead but if you think that it will be
      better/cleaner to not use such tricks then it's enough to
      change HB_ITEM_TYPE() definitions in hbvmpub.h - see note.
    * cleared the usage of HB_EXPORT - to avoid problems with some C/C++
      compilers we agreed that the only one common way of using HB_EXPORT
      is adding it ad begining of declaration - please keep this convention
      in the future.
    + added new functions:
      hb_extIsObject(), hb_codeblockId(), hb_idleSleep(),
      hb_fsGetOsHandle(),
      hb_dynsymFindSymbol(), hb_dynsymGetSymbol(),
      hb_dynsymSymbol(), hb_dynsymName(),
      hb_dynsymMemvarHandle(), hb_dynsymAreaHandle(), hb_dynsymSetAreaHandle()
    * changed hb_arrayClone() declaration to:
         PHB_ITEM hb_arrayClone( PHB_ITEM pArray )
    * changed hb_arrayFromParams() declaration to:
         PHB_ITEM hb_arrayFromParams( int iLevel )
      The previous version needed a pointer to stack relocatable area
      so any stack resizing could cause GPF.

  * harbour/include/inkey.ch
    * added definitions for extended mouse keys/events and some key
      combinations

  * harbour/source/codepage/uc1250.c
  * harbour/source/codepage/uc1251.c
  * harbour/source/codepage/uc1253.c
  * harbour/source/codepage/uc1257.c
  * harbour/source/codepage/uc737.c
  * harbour/source/codepage/uc850.c
  * harbour/source/codepage/uc852.c
  * harbour/source/codepage/uc866.c
  * harbour/source/codepage/uc88591b.c
  * harbour/source/codepage/uc8859_1.c
  * harbour/source/codepage/uc8859_2.c
  * harbour/source/codepage/uc8859_5.c
  * harbour/source/codepage/uckoi8.c
  * harbour/source/codepage/uckoi8u.c
  * harbour/source/codepage/ucmaz.c
    * updated unicode values for characters in rabge 1-31 to keep
      DOS compatibility

  * harbour/source/common/expropt1.c
  * harbour/source/common/hbarch.c
  * harbour/source/common/hbdate.c
  * harbour/source/common/hbstr.c
  * harbour/source/common/hbver.c
    * keep HB_EXPORT at the beginning of function declaration

  * harbour/include/hbpcode.h
  * harbour/include/hbcomp.h
  * harbour/source/compiler/harbour.c
  * harbour/source/compiler/harbour.y
  * harbour/source/compiler/hbfix.c
  + harbour/source/compiler/hbdead.c
  * harbour/source/compiler/hbpcode.c
  + harbour/source/compiler/hbstripl.c
    % rewritten jump optimization
      ! fixed some minor problems
      * do not optimize jumps and local variable access by shorter
        PCODE version and HB_P_NOOP when jump optimization is
        disabled, this is a note I left in source code in few places:
         /*
          * optimizing jumps here by shorting them and setting HB_P_NOOPs
          * only slow down the compilation process for three reasons:
          * 1. When it's dummy jump to next instruction we need two passes
          *    in hb_compOptimizeJumps() to fully remove it
          * 2. hb_compOptimizeJumps() also make jump shortcutting in each pass
          * 3. When Jump Optimization is disabled (-kJ) then it cause slowness
          *    at runtime because we will have more HVM loops: first  for the
          *    shorter jump and next for the HB_P_NOOP PCODE(s)
          * [druzuz]
          */

      + added support for multi passes in jump/dead code elimination
        (hb_compOptimizeJumps())
        By default is set upto three passes.
        Now hb_compOptimizeJumps() keeps all compiler internal data clean
        on exist and can be called any times and does not change other
        compiler's functions behaviors
      + added dummy jumps elimination
      + added optimization for:
            IF .T.
            IF .F.
            WHILE .T.
            WHILE .F.
         etc.
      * restored empty BEGIN/RECOVER sequence block elimination
        if Jump Optimization is enabled then it marks the block
        with HB_P_NOOPS else it cut the generated PCODE
      + added dead code eliminator (new functions hb_compCodeTraceMarkDead()/
        hb_compPCodeTrace() - it works only when Jump Optimization is
        not disabled)
      As a result of the above we have smaller and faster PCODE.

      I do not think that we will have meta code support in the reasonable
      time and because I need some valid compiler data/structures like
      updated table of all jumps for real C code (not PCODE in .c files)
      generation then I decide to make some modifications and the above
      is in practice a side effect of this work.

  * harbour/source/rdd/dbcmd.c
  * harbour/source/rdd/dbf1.c
  * harbour/source/rdd/rddord.prg
  * harbour/source/rdd/workarea.c
  * harbour/source/rdd/dbfcdx/dbfcdx1.c
  * harbour/source/rdd/dbffpt/dbffpt1.c
  * harbour/source/rdd/dbfntx/dbfntx1.c
  * harbour/source/rdd/nulsys/nulsys.c
    * synced with my modifications in xHarbour
    * updated for API modifications

  * harbour/source/rtl/Makefile
    + added gtsys.c, gtfunc.c, hbgtcore.c

  * harbour/source/rtl/accept.c
  * harbour/source/rtl/alert.prg
  * harbour/source/rtl/cdpapi.c
  * harbour/source/rtl/console.c
  * harbour/source/rtl/dates.c
  * harbour/source/rtl/do.c
  * harbour/source/rtl/errorapi.c
  * harbour/source/rtl/errorsys.prg
  * harbour/source/rtl/file.c
  * harbour/source/rtl/fserror.c
  * harbour/source/rtl/fstemp.c
  * harbour/source/rtl/hbffind.c
  * harbour/source/rtl/idle.c
  * harbour/source/rtl/math.c
  * harbour/source/rtl/oldclear.c
  * harbour/source/rtl/strmatch.c
  * harbour/source/rtl/strpeek.c
  * harbour/source/rtl/valtype.c
  * harbour/source/rtl/xsavescr.c
    * updated for API modifications
    * cleaned some compiler warnings

  * harbour/source/rtl/filesys.c
    + added hb_fsGetOsHandle()
    * updated for API modifications

  * harbour/source/rtl/gt.c
  * harbour/source/rtl/gtapi.c
  * harbour/source/rtl/gtapiu.c
  + harbour/source/rtl/gtfunc.c
  + harbour/source/rtl/gtsys.c
  + harbour/source/rtl/hbgtcore.c
  * harbour/source/rtl/inkey.c
  * harbour/source/rtl/maxrow.c
  * harbour/source/rtl/mouseapi.c
  * harbour/source/rtl/setcolor.c
  * harbour/source/rtl/setposbs.c
  * harbour/source/rtl/shadow.c
    * new GT API code

  * harbour/source/rtl/saverest.c
    * changed default behavior in SEVESCREEN/RESTSCREEN with parameters
      out of screen range to be Clipper compatible. Added last logical
      parameter to keep previous behavior for programs which begins to
      use it.

  * harbour/source/rtl/seconds.c
    * include missing header file to fix C++ compilation
    * make hb_secondsCPU global function

  * harbour/source/rtl/set.c
    * make HB_SET_TYPEAHEAD Clipper compatible

  * harbour/source/rtl/gtcgi/Makefile
  * harbour/source/rtl/gtcgi/gtcgi.c
  - harbour/source/rtl/gtcgi/mousecgi.c
    * rewritten for new GT API
      some detail behaviors has been changed but I think the current
      implementation is better for CGI programs output - please check
      and fix me if necessary

  * harbour/source/rtl/gtcrs/Makefile
  - harbour/source/rtl/gtcrs/charmap.prg
  + harbour/source/rtl/gtcrs/chrmap.c
  - harbour/source/rtl/gtcrs/debug.map
  - harbour/source/rtl/gtcrs/eterm.map
  * harbour/source/rtl/gtcrs/gtcrs.c
  + harbour/source/rtl/gtcrs/gtcrs.h
  + harbour/source/rtl/gtcrs/hb-charmap.def
  - harbour/source/rtl/gtcrs/kbdcrs.c
  - harbour/source/rtl/gtcrs/keymap.prg
  - harbour/source/rtl/gtcrs/linux.map
  - harbour/source/rtl/gtcrs/mousecrs.c
    * new GTCRS based on my xHarbour and Flagship curses code
      Please not that at runtime it looks for a file
      /etc/harbour/hb-charmap.def where user can fully tune output
      for his terminal. This file is included with proper path in
      binaries created by make_rpm.sh and make_tgz.sh
      Ryszard I've removed some of your extensions which are no longer
      necessary and some other (keyboard sequence redefinition) should
      be done in a little bit differ way. I would like to talk about it
      when you test current code.
      Added support for extended mouse keys (middle button and wheel).

  * harbour/source/rtl/gtdos/Makefile
  * harbour/source/rtl/gtdos/gtdos.c
  - harbour/source/rtl/gtdos/mousedos.c
    * rewritten for new GT API
      Fixed some small problems, finished mouse code which for DJGPP
      is fully Clipper compatible with real mouse SAVE/RESTORE code.
      For other compilers it should be updated depending on memory
      model and used DPMI driver (if any).

  * harbour/source/rtl/gtos2/Makefile
  * harbour/source/rtl/gtos2/gtos2.c
  - harbour/source/rtl/gtos2/mouseos2.c
    * rewritten for new GT API
      Fixed some problems and finished the mouse code.
      Please test it - I made all modifications without OS2 and
      I was not able to make any test. I'm interesting in information
      if it works and the speed difference - f.e. results from
      tests/vidtest.prg run with previous and current version.

  * harbour/source/rtl/gtpca/Makefile
  * harbour/source/rtl/gtpca/gtpca.c
  - harbour/source/rtl/gtpca/kbdos2.gcc
  - harbour/source/rtl/gtpca/mousepca.c
    * rewritten for new GT API
      and finished so now it's full functional GT driver
      I'm interesting in keyboard sequences used by PC-ANSI drivers
      in DOS so it will be possible to implement also support for
      extended keys input.

  * harbour/source/rtl/gtsln/Makefile
  * harbour/source/rtl/gtsln/gtsln.c
  + harbour/source/rtl/gtsln/gtsln.h
  * harbour/source/rtl/gtsln/kbsln.c
  * harbour/source/rtl/gtsln/keytrans.c
  * harbour/source/rtl/gtsln/mousesln.c
    * rewritten for new GT API basing on current xHarbour code
      added support for slang 1.4x patched for UNICODE (Debian
      patches used by most of current Linux distributions) and
      slang 2.x - It's unicode ready, tries to detect terminal mode
      (utf-8/iso) at startup and switch the internal logic to
      iso/unicode mode. When compiled with slang 1.4x or 2.x
      and terminal is in UTF-8 it can display all characters like
      in DOS if only used font have them or good fall-back table is
      loaded (f.e. the one created by QRCZAK)
      Added support for extended mouse keys (middle button and wheel).

  * harbour/source/rtl/gtstd/Makefile
  * harbour/source/rtl/gtstd/gtstd.c
  - harbour/source/rtl/gtstd/mousestd.c
    * rewritten for new GT API
      Now it can work as full screen GT driver redrawing the previous
      screen contents from internal GT core buffers. I run with this
      GT some of my programs and they work quite well ;-) of course
      without colors.

  * harbour/source/rtl/gtwin/Makefile
  * harbour/source/rtl/gtwin/gtwin.c
  - harbour/source/rtl/gtwin/mousewin.c
    * updated for new GT API

  + harbour/source/rtl/gtxwc/Makefile
  + harbour/source/rtl/gtxwc/gtxwc.c
  + harbour/source/rtl/gtxwc/gtxwc.h
    * new XWindow Console GT driver based on my and Giancarlo Niccolai
      code form xHarbour - this GT can work in XWindow environment only
      and create its own window for  console output. It delays the
      initialization to the moment when user try to display anything on
      the screen so even without X Window system programs which uses this
      GT can work as long as use only outstd/outerr output.

  * harbour/source/vm/arrays.c
    * updated for API modifications
    + added hb_arrayId(),
    * changed hb_arrayClone() declaration to:
         HB_EXPORT PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray )
    * changed hb_arrayFromParams() declaration to:
         PHB_ITEM hb_arrayFromParams( int iLevel )

  * harbour/source/vm/arrayshb.c
    * updated for API modifications
    + added new parameter iLevel to function HB_APARAMS()

  * harbour/source/vm/classes.c
  * harbour/source/vm/cmdarg.c
  * harbour/source/vm/dynlibhb.c
  * harbour/source/vm/estack.c
  * harbour/source/vm/fm.c
  * harbour/source/vm/garbage.c
  * harbour/source/vm/maindll.c
  * harbour/source/vm/maindllh.c
  * harbour/source/vm/maindllp.c
  * harbour/source/vm/mainstd.c
  * harbour/source/vm/mainwin.c
  * harbour/source/vm/memvars.c
  * harbour/source/vm/pcount.c
  * harbour/source/vm/proc.c
    * updated for API modifications

  * harbour/source/vm/codebloc.c
    * updated for API modifications
    + added hb_codeblockId()

  * harbour/source/vm/dynsym.c
    * updated for API modifications
    + added new functions:
      hb_dynsymFindSymbol(), hb_dynsymGetSymbol(),
      hb_dynsymSymbol(), hb_dynsymName(),
      hb_dynsymMemvarHandle(), hb_dynsymAreaHandle(), hb_dynsymSetAreaHandle()

  * harbour/source/vm/eval.c
    * updated for API modifications
    * call hb_vmPushState()/hb_vmPopState() in hb_itemDo()/hb_itemDoC()
      functions - it's necessary to make HVM reentrant safe.

  * harbour/source/vm/extend.c
    * updated for API modifications
    + added hb_extIsObject() similar to existing hb_extIsArray()

  * harbour/source/vm/hvm.c
    * updated for API modifications
    + added new functions: hb_vmPushState(), hb_vmPopState()
      which save/restore HVM state (the top stack value which can be
      processed and return item and maybe sth else in the future) making
      HVM ready for reentrant.

  * harbour/source/vm/itemapi.c
    * updated for API modifications
    + added new function:
         HB_EXPORT PHB_SYMB hb_itemGetSymbol( PHB_ITEM pItem );
    ! fixed bug in hb_itemPutNInt()

  * harbour/tests/Makefile
  * harbour/utils/hbdoc/Makefile
  * harbour/utils/hbextern/Makefile
  * harbour/utils/hbmake/Makefile
  * harbour/utils/hbrun/Makefile
  * harbour/utils/hbtest/Makefile
    - removed badly added: dbfntx, dbfcdx, dbffpt, hbsix libraries.
      what broke GNU make compilation for some compilers
      This libraries should be included automatically when RDD lib
      is included by *.cf files

   Summary:
      The whole patch (cvs diff -uN) is ~1.5MB length and I cannot describe
      everything in details - sorry but it was too much modifications in
      one commit so now just some of general notes.
      The header files included as is does not have any information about
      internal HVM structures and some functions. In practice only HB_SYMB
      is public and it has to be public for .c files generated from .prg
      so I force the fixed size of this structure (alignment independent)
      by redefining some members to union with void * - it's a little bit
      ugly trick but it effectively eliminates the problem of linking
      binaries compiled with differ alignment C compiler switches.
      The structures like HB_ITEM, HB_CODEBLOCK, HB_STACK, HB_DYNS are not
      longer defined and pointers to the defined as void * - like in Clipper
      the ITEM structure. It caused that I had to add some new functions
      to make some operation still possible to implement. If I missed sth
      and any of you will have a problem with your code then please inform
      me about it and after a small discussion on Harbour developers list
      we can decide if other functions should be added.
      The internal API is still accessible. It's enough to include "hbvmopt.h"
      file before other header files to enable it. Now only files in
      source/vm directory include it.
      The 3-rd party code which does not include hbvmopt.h (or tries to
      set some internals macros) should be safe for future HVM modifications
      and will work also with new binaries so 3-rd party library developers
      should remember about it. If they won't then it's only their and
      their clients problem not Harbour developers.
      With this modifications I also create new GT model which is similar
      to the one used by RDD with multi inheritance. It can be quite easy
      extended to simultaneously load more then one GT subsystem (sth like
      work areas in RDD) but I left it for the future when someone may
      need it. hbapigt.h file now contains only information about public
      functions and does not have any code which depends on current
      internal implementation - it should be backword compatible as long
      as somone did not try to use internal GT functions.
      The internal GT system use hbgtcore.h file which should not be
      included by 3-rd party code as long as someone will not make new
      GT driver. The internal GT code is new so I expect that it will
      be changed yet in the nearest future (I'm waiting for other developers
      feedback) and in such case any 3-rd party GTs will have to be updated.
      How it works:
         The base GT driver (GTNUL) is fully functional GT driver which
         makes all operations on memory buffer. After each screen write
         Flush() method is called which check for dispcount() and if
         it's 0 then call Refresh() method to update modified area by
         Redraw() method. This method is dummy in GTNUL and external
         output with this GT can be reached by outstd()/outerr() which
         are now redirected to GT methods. A simple GT driver may overload
         only Refresh() method to give full screen output.
         Application can use only this GT driver and it seems to be very
         good choice for GUI and background daemon/service programs.
         This GT is loaded at startup then all other GTs can be loaded
         later and inherit from the previously loaded GT drivers.
         The new GT driver can overload as much method as wants/needs.
         Now all GT operations are implemented as GT method so GT driver
         can easy change their default behavior, f.e. it may fully overload
         color parsing methods and use differ or extended to Clipper color
         definitions.
         I rewrote all existing GTs to work with new GT model.
         OS2 users - please test GTOS2 which I was not able to test and
         see the note in Redraw() method. If possible please make some
         speed tests.
         In fact now there is much more internal operations then it was
         before but because they are done on memory only then current
         code is much faster in this GT drivers which so far makes all
         operations on real video area. I made some tests with GTNUL
         and tests/vidtest.prg and the total overhead is minimal. Now
         dipbegin()/dispend() in practice does not cost anything so it
         gives additional speed improvement in application which extensively
         use it.
         More then one GT driver can be linked with final binaries and
         chose on application startup by //GT<NAME> switch and/or environment
         variable HB_GT=<name>
         In the RTL is new GT function GTSYS() which works in similar way
         to RDDSYS() in RDD subsystem and for linking default GT driver
         for given platform. When RTL is compiled the default GT driver
         is set to HB_GT_DEFAULT envvar and if not exist to HB_GT_LIB
         envvar and if it also does not exist to hard coded platfom GTs
         (see source/rtl/gtsys.c and source/rtl/Makefile for rules)
         Adding to source code:
            ANNOUNCE GTSYS
         disable linking the default GT driver and:
            REQUEST HB_GT_<name>
         for linking given (<name>) GT driver, f.e.: REQUEST HB_GT_WIN
         If you are working in SH environment (Linux and other *nixes users,
         DJGPP bash, MinGW shell then it's possible to use -gt<name> switch
         in hblnk / hbmk scripts to force linking GT drivers (it could be
         repeated with different <name>) and the first one becomes the default
         one. F.e.:
            xhbmk -m -n -w -es2 -gtcrs -gtsln -gtstd -gtpca vidtest.prg
         Usually the GT driver are loaded at HVM startup but it's possible
         to load it later. I created new GT driver CTW which gives full
         CT3 like Window system. The CT3 extended driver change the behavior
         of some function in Clipper extended driver, f.e WRITECON() or
         SETPOS() with parameters out of screen range. So I implemented it
         CTW as RT GTs which is loaded when some of CTWIN function is used
         (f.e. WOPEN()/WBOARD()) and inherits from any existing GT driver.
         This is full CT3 WIN implementation with all detail behaviors I
         found (with some CT3 bug fixes). It does not have any CT3 limitations
         and can be used for any virtual screen/window size though I hardcoded
         CT3 limitation for backword compatibility. If somone will want to
         remove it then it will be enough to delete few lines from ctwin.c
         file. I'm not CTWIN Clipper user so maybe I missed some side effects
         in this driver and was not able to well test it so if you will find
         any incompatibilities then please inform me.
         THe default GT buffer uses 32bit character cell internally but
         in savescreen/restscreen it uses VGA compatible two bytes character
         cell. Some GT drivers may want to use differ character cell.
         Now GTCRS and GTSLN use 32bit character cell by default. They
         need additional information about character set (box/normal) to
         properly display box characters. It is possible to force in this
         GT drivers using Clipper compatible character cell by calling:
            hb_gtInfo( GTI_COMPATBUFFER, <lCompat> ) -> <lPreviousSeting>
         but in may cause that box drawing characters will be lost in
         some countries after RESTSCREEN(). It will depend on used code
         page.
         HB_GTINFO() is new function which works in similar way to DBINFO()
         in RDD. It allows to retrieve/change some of GT driver settings.
         GTI_* actions are defined in hbgtinfo.ch - it has all GTI_*
         definitions used in xHarbour. Now in Harbour only few of them
         are implemented.
         The new three .prg functions:
            HB_SETKEYCP( <cTermCP> [,<cHostCP>] )
            HB_SETDISPCP( <cTermCP> [,<cHostCP>] [,<lBoxChar>] )
            HB_SETTERMCP( <cTermCP> [,<cHostCP>] [,<lBoxChar>] )
         have been added. They set automatic input (HB_SETKEYCP)
         and output (HB_SETDISPCP) (or both: HB_SETTERMCP) character
         translation. They are also important for some GTs which
         informing them about used internal code page for unicode
         translation (GTXWC, GTSLN) and/or chosing proper character
         set (standard/alternate) for letters and other (f.e. box
         drawing characters) (GTCRS, GTSLN),
            <cTermCP> is encoding used on external (terminal) side
            <cHostCP> is encoding used internally, if not given then
                      current code page set HB_SETCODEPAGE() is used.
                      some of GTs which uses unicode output may
                      ignore <cTermCP>
            <lBoxChar> is optional parameter which interacts with dispbox()
                       output disabling switching to alternate character
                       set in some GTs. It effectively causes that if internal
                       (host) code page contains some letters on the box char
                       positions then they will be shown also by box drawing
                       functions like dispbox() instead of CP437 characters.
                       In some cases it could be useful. By default lBoxChar
                       is not set and GTs which can switch between standard
                       and alternate character set (GTCRS, GTSLN) will try to
                       use alternate character set for box drawing functions.

      Victor: I removed some of your functions. They can be very easy
      implemented with hb_gt_GetChar()/hb_gt_PutChar() but I do not want to
      make them part of documented external API because some GT drivers may
      want to use absolutely differ color definitions and they will stop to
      work so I do not want to make this functions documented external API.

      Ryszard: Setting alternative debug keys does not longer work.
      I like such possibilities but it should be implemented in differ
      way to f.e. using HB_GTINFO interface to allow low level GT driver
      extensions, f.e. in *nixes using CTRL+[A-Z] and SIGINT, SIGQUIT,
      SIGTSTP signals for real asynchronous setting of debug/cancel flag
      without keyboard polling from main HVM loop. I would like to discus
      about such more general solution.

   *** Please updated non GNU make files ***
2006-02-04 16:16:48 +00:00

940 lines
26 KiB
C

/*
* $Id$
*/
/*
* File......: DISPC.C
* Author....: Mike Taylor
* CIS ID....: ?
*
* This is an original work by Mike Taylor and is placed in the
* public domain.
*
* Modification history:
* ---------------------
*
* Rev 1.10 22 Apr 2004 15:32:00 David G. Holm <dholm@jsd-llc.com>
* Corrected all hb_fsSeek calls to use FS_ defines instead of using
* redefined SEEK_ ones that conflict with the C-level SEEK_ defines.
* Rev 1.9 ? ?
* An unknown number of changes were made between Rev 1.8 and Rev 1.10.
*
* Rev 1.8 24 May 2002 19:25:00 David G. Holm <dholm@jsd-llc.com>
* Fixed some problems that caused C++ compiles to fail.
*
* Rev 1.7 29 Mar 2002 17:00:00 Walter Negro <anegro@overnet.com.ar>
* Ported to Harbour
*
* Rev 1.6 01 Jan 1995 03:01:00 TED
* Changed some prototypes to eliminate compiler warnings.
*
* Rev 1.5 14 Feb 1994 16:58:42 GLENN
* Steve Tyrakowski and Kevin Maher modified to be CPMI-compliant.
*
* Rev 1.4 18 Nov 1991 02:20:20 GLENN
* Mike fixed a bug in _ft_dfinit() related to allocating memory. Some
* users had been reporting problems, but everyone who tested this patch
* reported success.
*
* Rev 1.3 17 Aug 1991 15:25:46 GLENN
* Don Caton fixed some spelling errors in the doc
*
* Rev 1.2 15 Aug 1991 23:08:14 GLENN
* Forest Belt proofread/edited/cleaned up doc
*
* Rev 1.1 14 Jun 1991 19:53:42 GLENN
* Minor edit to file header
*
* Rev 1.0 01 Apr 1991 01:02:46 GLENN
* Nanforum Toolkit
*
*
*/
/* NOTE: we need this to prevent base types redefinition */
#define _CLIPDEFS_H
#include "hbdefs.h"
#include "hbapi.h"
#include "hbapifs.h"
#include "hbapigt.h"
#include "fm.api"
#include "inkey.ch"
#define OFF 0
#define ON (!OFF)
#define NO 0
#define YES (!NO)
#define OK 0
#define K_STRING 0
#define K_LIST (!K_STRING)
#define CR ((char) 13)
#define LF ((char) 10)
#define FEOF ((char) 26)
#define READONLY 0 /* open file modes */
#define WRITEONLY 1
#define READWRITE 2
#define BUFFERSIZE 4096 /* maximum size of the file buffer */
#define MAXLINE 255 /* default maximum size of a line */
#define TABSET 8
long buffoffset; /* offset into buffer of current line */
long fsize; /* file size in bytes */
int bufftop, buffbot; /* first and last character in buffer */
int wintop, winbot; /* first and last character in window */
int winrow, wincol; /* row and column of window highlight */
int sline, eline; /* start and end line of window */
int scol, ecol; /* start and end col of window */
int height, width; /* height and width of window */
int infile; /* input file handle */
int maxlin; /* line size */
int buffsize; /* buffer size */
int hlight; /* highlight attribute */
int norm; /* normal attribute */
int kcount; /* number of keys in terminate key list*/
int colinc; /* col increment amount */
int brows; /* browse flag */
char refresh; /* YES means refresh screen */
char kstr[25]; /* terminate key string */
int keylist[24]; /* terminate key list */
int keytype; /* K_STRING or K_LIST */
int isallocated; /* if buffers were allocated */
char *buffer; /* file buffer pointer */
char *lbuff; /* line buffer pointer */
char *vseg; /* video segment variable */
/* prototypes */
static int keyin(void);
static void chattr(int x, int y, int len, int attr);
static long getblock(long offset);
static void buff_align(void);
static void win_align(void);
static void disp_update(int offset);
static void windown(void);
static void winup(void);
static void linedown(void);
static void lineup(void);
static void filetop(void);
static void filebot(void);
static void strcpyn(char *dest, const char *source, int len);
/*
* chattr() replace the color attribute with a new one starting at
* location x, y and going for length len.
*
*/
static void chattr(int x, int y, int len, int attr)
{
int i;
char *vmem;
vmem = vseg + (y * (width + 1) * 2) + (x * 2) + 1;
/* calc the screen memory coord */
for (i = 0; i <= len; i++, vmem += 2) /* write the new attribute value */
*vmem = (char) attr;
}
/*
* function getblock() reads the text file and returns the a block.
* the variables offset and buffsize tell it where to start reading and
* how many bytes to try to read. if the block read in would not fill
* the buffer then the offset is adjusted so that the start or end of
* of the file is positioned at the head or tail of the buffer.
*
* it returns the offset into the file of the first byte of the buffer.
*
*/
static long getblock(long offset)
{
/*
set the file pointer to the proper offset
and if an error occured then check to see
if a positive offset was requested, if so
then set the pointer to the offset from
the end of the file, otherwise set it from
the beginning of the file.
*/
hb_fsSeek( infile, offset, FS_SET );
/* read in the file and set the buffer bottom variable equal */
/* to the number of bytes actually read in. */
buffbot = hb_fsReadLarge( infile, ( BYTE * ) buffer, buffsize );
/* if a full buffer's worth was not read in, make it full. */
if (( buffbot != buffsize ) && ( fsize > buffsize ))
{
if ( offset > 0 )
hb_fsSeek( infile, (long) -buffsize, FS_END );
else
hb_fsSeek( infile, (long) buffsize, FS_SET );
buffbot = hb_fsReadLarge( infile, ( BYTE * ) buffer, buffsize );
}
/* return the actual file position */
return( hb_fsSeek( infile, 0L, FS_RELATIVE ) - buffbot);
}
/*
* buff_align makes sure the buffer top and bottom variables point
* to actual complete lines of text.
*
*/
static void buff_align()
{
int i;
bufftop = 0;
buffbot = buffsize;
if ( buffoffset != 0L ) /* if the buffoffset is otherthan 0 */
{
i = bufftop; /* start at the top of the file and scan */
/* forward until a CR is reached. */
while (( buffer[i] != CR ) && ( i < buffbot ))
i++;
bufftop = i + 2;
}
/* if the buffer offset is not a complete */
/* buffer's length away from the file end */
if ( buffoffset + ((long) buffbot) != fsize )
{
/*
if the file position of the last byte
of the buffer would end up past the
end of the file, then the buffer does
contain a complete buffer full and the
buffer end pointer needs to be set to
the last character of the file.
*/
if ( buffoffset + ((long) buffbot) > fsize )
buffbot = (int) (fsize - buffoffset);
i = buffbot; /* point the end of the buffer to a valid */
/* complete text line. */
while (( buffer[i] != CR ) && ( i > bufftop ))
i--;
buffbot = i + 2;
}
}
/*
* win_align takes the value for wintop and then figures out where
* winbot would be. if winbot would extend past the end of the
* buffer, then the top of the window is adjusted to ensure that a full
* screen of text will appear. This simplifies the cursor routines.
*
*/
static void win_align()
{
int i;
winbot = wintop; /* find out if there is enough text for */
i = 0; /* full window. */
while (( winbot < buffbot ) && ( i < height ))
{
if ( buffer[winbot] == CR )
i++;
winbot++;
}
if ( i < height ) /* if there is not a full window, */
{
/* then retrofit winbot to the end of a line */
while ( buffer[winbot] != LF && winbot > bufftop)
winbot--;
wintop = winbot;
i = 0; /* and setup wintop */
while (( wintop > bufftop ) && ( i <= height ))
{
if ( buffer[wintop] == LF )
i++;
wintop--;
}
if ( wintop != bufftop )
wintop += 2;
}
}
/*
* this routine displays the actual text in the window. This is done
* by taking each line and placing it in a string. the screen line
* is then taken from the appropriate group of characters in the string.
* this allows a window to page left-right across the buffer without
* having to use any complex algorithm to calc the needed chars.
*
*/
static void disp_update(int offset)
{
int line, col, pos, i;
char *vmem;
refresh = NO;
line = 0;
while ( line < height )
{
/*
calculate the initial position, this save execution
time because each column is considered as a offset
from the line start
*/
pos = (line * (width + 1) * 2);
/* copy string to temp buffer */
for (i = 0; buffer[offset] != CR && offset <= winbot; offset++)
{
if ( i <= maxlin )
{
if (buffer[offset] == '\t') /* check for a tab */
{
lbuff[i++] = ' '; /* pad with spaces */
while (i % TABSET && i <= maxlin) /* until tab stop */
lbuff[i++] = ' '; /* is reached or EOL */
}
else lbuff[i++] = buffer[offset];
}
}
for (; i <= maxlin; i++) /* fill out with spaces */
lbuff[i] = ' ';
/* place the proper characters onto the screen */
for (i = wincol, col = 0; col <= width; col++)
{
vmem = vseg + pos + (col * 2);
*vmem = lbuff[i++];
}
line += 1;
offset += 2;
}
hb_gtRest( sline, scol, eline, ecol, vseg );
}
/*
* move the window pointers so that a new window's worth of information
* is visible. it adjusts the pointers within the buffer and if necessary
* it calls the getblock function to load in a new buffer
*
*/
static void winup()
{
int k;
long i, j;
refresh = YES;
k = wintop - 3;
while (( buffer[k] != CR ) && ( k > bufftop ))
k--;
if ( k >= bufftop )
{
if (buffer[k] == CR) k += 2;
wintop = k;
k = winbot - 3;
while ( buffer[k] != CR )
k--;
winbot = k + 2;
}
else
if ( ((long) bufftop) + buffoffset > 0 && fsize > buffsize )
{
i = buffoffset + wintop;
j = buffoffset - ((long) (buffsize / 2));
if ( j < 0 )
j = 0;
buffoffset = getblock(j);
wintop = ((int) (i - buffoffset));
buff_align();
win_align();
}
}
/*
* move the window pointers so that a new window's worth of information
* is visible. it adjusts the pointers within the buffer and if necessary
* it calls the getblock function to load in a new buffer
*
*/
static void windown()
{
int k;
long i, j;
refresh = YES;
k = winbot;
while (( buffer[k] != CR ) && ( k <= buffbot ))
k++;
k += 2;
if ( k <= buffbot )
{
winbot = k;
k = wintop;
while ( buffer[k] != CR )
k++;
wintop = k + 2;
}
else
if ( (((long) buffbot) + buffoffset) < fsize && fsize > buffsize)
{
i = buffoffset + wintop;
j = i;
if ( j > fsize )
j = fsize - ((long) buffsize);
buffoffset = getblock(j);
if ( i < buffoffset )
wintop = 0;
else
wintop = ((int) (i - buffoffset));
buff_align();
win_align();
}
}
/* move the cursor one line down */
static void linedown()
{
if ( winrow < eline ) /* if cursor not at last line */
winrow += 1;
else /* otherwise adjust the window top variable */
windown();
}
/* move the cursor one line up */
static void lineup()
{
if ( winrow > sline )
winrow -= 1;
else
winup();
}
/* go to the top of the file */
static void filetop()
{
if ( buffoffset != 0 )
{
buffoffset = getblock(0L);
buff_align();
}
refresh = YES;
wintop = (int) buffoffset;
winrow = sline;
wincol = 0;
win_align();
}
/* goto the bottom of the file */
static void filebot()
{
if ( (((long) buffbot) + buffoffset) < fsize && fsize > buffsize )
{
buffoffset = getblock(fsize + 1);
buff_align();
}
refresh = YES;
wintop = buffbot - 3;
winrow = eline;
wincol = 0;
win_align();
}
HB_FUNC( _FT_DFINIT )
{
int rval, i, j;
ULONG ulSize;
rval = 0;
sline = hb_parni(2); /* top row of window */
scol = hb_parni(3); /* left col */
eline = hb_parni(4); /* bottom row */
ecol = hb_parni(5); /* right col */
width = ecol - scol; /* calc width of window */
height = eline - sline + 1; /* calc height of window */
hb_gtRectSize( sline, scol, eline, ecol, &ulSize );
vseg = (char * ) hb_xalloc( ulSize );
if (vseg != NULL)
hb_gtSave( sline, scol, eline, ecol, vseg );
maxlin = hb_parni(12);
buffsize = hb_parni(13); /* yes - load value */
buffer = (char *) hb_xalloc(buffsize); /* allocate memory */
lbuff = (char *) hb_xalloc(maxlin + 1); /* for buffers */
isallocated = !(buffer == NULL || lbuff == NULL || vseg == NULL);
/* memory allocated? */
if (isallocated == FALSE)
{
rval = 8; /* return error code 8 (memory) */
if (buffer != NULL) hb_xfree(buffer);
if (lbuff != NULL) hb_xfree(lbuff);
if (vseg != NULL) hb_xfree(vseg);
}
else /* get parameters */
{
infile = hb_parni(1); /* file handle */
j = hb_parni(6); /* starting line value */
norm = hb_parni(7); /* normal color attribute */
hlight = hb_parni(8); /* highlight color attribute */
if ((hb_parinfo(9) && 512) == 512) /* if array */
{
keytype = K_LIST;
kcount = hb_parinfa( 9, 0 );
if (kcount > 24)
kcount = 24;
for (i = 1; i <= kcount; i++)
keylist[i - 1] = hb_parni( 9, i ); /* get exit key list */
}
else
{
keytype = K_STRING;
kcount = hb_parclen( 9 );
if (kcount > 24)
kcount = 24;
strcpyn(kstr, hb_parc(9), kcount); /* get exit key string */
}
brows = hb_parl(10); /* get browse flag */
colinc = hb_parni(11); /* column skip value */
bufftop = 0; /* init buffer top pointer */
buffbot = buffsize; /* init buffer bottom pointer */
buffoffset = 0; /* curr line offset into buffer */
winrow = sline; /* init window row */
wincol = 0; /* init window col */
wintop = 0; /* init window top pointer */
winbot = 0; /* init window bottom pointer */
/* get file size */
fsize = hb_fsSeek( infile, 0L, FS_END ) - 1;
/* get the first block */
hb_fsSeek( infile, 0L, FS_SET );
/* if block less than buffsize */
if ( fsize < ((long) buffbot) )
buffbot = (int) fsize; /* then set buffer bottom */
/* set the current lines buffer offset pointer */
buffoffset = getblock((long) bufftop);
/* align buffer and window pointer to valid values */
buff_align();
win_align();
/* point line pointer to line passed by caller */
for (i = 1; i < j; i++)
linedown();
hb_gtRest( sline, scol, eline, ecol, vseg );
}
hb_retni(rval);
}
HB_FUNC ( _FT_DFCLOS )
{
if (isallocated == TRUE)
{
if (buffer != NULL) hb_xfree(buffer); /* free up allocated buffer memory */
if (lbuff != NULL) hb_xfree(lbuff);
if (vseg != NULL) hb_xfree(vseg);
}
}
/* $DOC$
* $FUNCNAME$
* FT_DISPFILE()
* $CATEGORY$
* File I/O
* $ONELINER$
* Browse a text file
* $SYNTAX$
* FT_DISPFILE() -> cExitkey
* $ARGUMENTS$
* None
* $RETURNS$
* The ASCII keystroke that terminated FT_DISPFILE()
* $DESCRIPTION$
* This routine displays a text file within a defined window using as
* little memory as possible. The text file to display has to be
* present or an error value of 0 is returned (as a character.)
*
* Assumptions: The routine assumes that all lines are terminated
* with a CR/LF sequence (0x0d and 0x0a).
*
* Note: Make sure you allocate a buffer large enough to hold
* enough data for the number of lines that you have
* in the window. Use the following formula as a
* guideline - buffer size = (# of line) + 1 * RMargin
* this is the smallest you should make the buffer and
* for normal use I recommend 4096 bytes.
*
* Cursor Keys: Up, Down - moves the highlight line
* Left, Right - moves the window over nColSkip col's
* Home - moves the window to the far left
* End - moves the window to the nRMargin column
* PgUp, PgDn - moves the highlight one page
* Ctrl-PgUp - moves the highlight to the file top
* Ctrl-PgDn - moves the highlight to the file bottom
* Ctrl-Right - moves the window 16 col's to the right
* Ctrl-Left - moves the window 16 col's to the left
*
* Esc, Return - terminates the function
*
* All other keys are ignored unless they are specified
* within cExitKeys parameter. This list will tell the
* routine what keys terminate the function. Special
* keys must be passed by a unique value and that value
* can be found by looking in the keys.h file.
* $EXAMPLES$
* @ 4,9 TO 11,71
*
* FT_DFSETUP("test.txt", 5, 10, 10, 70, 1, 7, 15,;
* "AaBb" + Chr(143), .T., 5, 132, 4096)
*
* cKey = FT_DISPFILE()
*
* FT_DFCLOSE()
*
* @ 20,0 SAY "Key that terminated FT_DISPFILE() was: " + '[' + cKey + ']'
* $SEEALSO$
* FT_DFSETUP() FT_DFCLOSE()
* $END$
*/
HB_FUNC( FT_DISPFILE )
{
int i, done;
char rval[2];
int ch;
/* make sure buffers were allocated and file was opened */
if (isallocated == TRUE && infile > 0)
{
done = NO;
refresh = YES;
/* draw inside of window with normal color attribute */
for (i = 0; i < height; i++)
chattr(0, i, width, norm);
hb_gtRest( sline, scol, eline, ecol, vseg );
/* main processing loop -- terminated by user key press */
do
{
if ( refresh == YES ) /* redraw window contents? */
disp_update(wintop);
hb_gtRest( sline, scol, eline, ecol, vseg );
/* if not browse, highlight the current line */
if ( brows == NO )
chattr(0, winrow - sline, width, hlight);
hb_gtRest( sline, scol, eline, ecol, vseg );
hb_gtSetPos( winrow, scol );
ch = keyin(); /* get user key press */
/* if not browse, then un-highlight current line */
if ( brows == NO )
chattr(0, winrow - sline, width, norm);
hb_gtRest( sline, scol, eline, ecol, vseg );
/* figure out what the user wants to do */
switch (ch)
{
case K_DOWN : if ( brows == YES ) /* if browse flag */
winrow = eline; /* is set, force */
/* active line to */
linedown(); /* be last line */
break;
case K_UP : if ( brows == YES ) /* if browse flag */
winrow = sline; /* is set, force */
/* active line to */
lineup(); /* be first line */
break;
case K_LEFT : wincol -= colinc; /* move cursor */
refresh = YES; /* to the left */
if ( wincol < 0 )
wincol = 0;
break;
case K_RIGHT : wincol += colinc; /* move cursor */
refresh = YES; /* to the right */
if ( wincol > (maxlin - width) )
wincol = maxlin - width;
break;
case K_HOME : wincol = 0; /* move cursor */
refresh = YES; /* to first col */
break;
/* move cursor to last col */
case K_END : wincol = maxlin - width;
refresh = YES;
break;
case K_CTRL_LEFT : wincol -= 16; /* move cursor */
refresh = YES; /* 16 col to left */
if ( wincol < 0 )
wincol = 0;
break;
case K_CTRL_RIGHT : wincol += 16; /* move cursor */
refresh = YES; /* 16 col to right */
if ( wincol > (maxlin - width) )
wincol = maxlin - width;
break;
case K_PGUP : for (i = 0; i < height; i++) /* move window */
winup(); /* up one page */
break;
case K_PGDN : for (i = 0; i < height; i++) /* move window */
windown(); /* down 1 page */
break;
case K_CTRL_PGUP : filetop(); /* move cursor to */
break; /* to top of file */
case K_CTRL_PGDN : filebot(); /* move cursor to */
break; /* to bot of file */
case K_ENTER : done = YES; /* carriage return */
break; /* terminates */
case K_ESC : done = YES; /* escape key */
break; /* terminates */
/* scan key list and see if key pressed is there */
default : if (keytype == K_STRING)
{
for (i = 0; i <= kcount; i++)
if ((ch > 0) && (ch < 256))
if ( (int) kstr[i] == ch )
done = YES;
break; /* if so terminate */
}
else
{
for (i = 0; i < kcount; i++)
if ( keylist[i] == ch )
done = YES;
break;
}
}
} while ( done == NO );
}
else
ch = 0;
/* store the key pressed as a character to be returned */
/* return key value to caller */
if (keytype == K_STRING)
{
rval[0] = (char) ch;
rval[1] = '\0';
hb_retc( rval );
}
else
hb_retni( ch );
}
/*
* keyin() gets the next key typed and does any translation needed.
* Some keys are converted to a common name - like the up arrow is
* converted to the UP value which also is the Ctrl-E value. This
* allows the Wordstar-like control keys to be used. Only extended
* keys are translated - the values of the defines were chosen to
* match up with the non-extended key codes.
*
*/
static int keyin()
{
int ch;
ch = 0;
while ( ch == 0x00 ) /* check to see if it's extended */
{
ch = hb_inkeyTranslate( hb_gtReadKey( 0 ), 0 );
if (ch == 257) /* error compiling with bcc55 */
ch = 27; /* ESC with CapsLock ON = 257, with CapsLock OFF = 27 */
hb_idleState();
}
return ( ch );
}
static void strcpyn( char *dest, const char *source, int len )
{
int i;
for (i = 0; i < len; i++)
dest[i] = source[i];
dest[len+1] = 0x00;
}