Monday, February 28, 2011

Harbour/xharbour Diff (1/57) - COMPILE TIME SUPPORT FOR MERGING MULTIPLE .PRG MODULES by Przemyslaw Czerpak

Clipper allows to compile many .prg modules included by @.clp and/or SET PROCEDURE TO ... / DO ... [ WITH ... ] into single output object. In such compilation it supports, separated for each .prg file, file wide declarations when -n switch is used and allows to use more then one static function with the same name if each of them is declared in different .prg modules. This code illustrates such situation:

/***** t1. prg *****/
static s := "t01:s"
static s1 := "t01:s1"
proc main()
? "===="
? s, s1
p1();p2();p3()
? "===="
do t2
? "===="
return
proc p1 ; ? "t01:p1"
static proc p2 ; ? "t01:p2"
static proc p3 ; ? "t01:p3"
init proc pi ; ? "init t01:pi"
exit proc pe ; ? "exit t01:pe"

/***** t2. prg *****/
static s := "t02:s"
static s2 := "t02:s2"
proc t2()
? s, s2
p1();p2();p3()
return
static proc p1 ; ? "t02:p1"
proc p2 ; ? "t02:p2"
static proc p3 ; ? "t02:p3"
init proc pi ; ? "init t02:pi"
exit proc pe ; ? "exit t02:pe"

It needs -n switch for file wide declarations and uses static/init/exit functions with the same names but declared in different modules. It can be compiled and linked by Clipper and Harbour, i.e.:


cl t1.prg /n/w/es2
or:
hbmk2 t1.prg -n -w -es2
and then executed.

xHarbour does not have such functionality and above code has to be adopted to work with this compiler. Additionally it does not work well with case sensitive file systems what can be seen in above example where it converts "t1" to "T1" and then tries to include "T1.prg".

For users which have old Clipper code written for DOS file systems with mixed upper and lower letters in file names used directly or indirectly by procedure name, Harbour provides compile time switches which enable automatic filename conversions for all files opened by compiler:


-fn[:[l|u]|-] set filename casing (l=lower u=upper)
-fd[:[l|u]|-] set directory casing (l=lower u=upper)
-fp[:] set path separator
-fs[-] turn filename space trimming on or off (default)
 

This functionality is also local to Harbour so cannot be used with xHarbour as workaround for above problem though it should be easy to add it to this compiler in the future.

Both compilers support runtime switches for file name conversions.
 

SET FILECASE LOWER | UPPER | MIXED
SET DIRCASE LOWER | UPPER | MIXED
SET DIRSEPARATOR
set( _SET_TRIMFILENAME, )


which can be used in programs not intended to work with different file system(s) and with different OS(s).

More at http://harbour-project.svn.sourceforge.net/viewvc/harbour-project/trunk/harbour/doc/xhb-diff.txt

No comments:

Post a Comment