19990915-14:04 GMT+1

This commit is contained in:
Viktor Szakats
1999-09-15 12:21:21 +00:00
parent 19275f2525
commit fa1ba7e4f2
9 changed files with 234 additions and 144 deletions

View File

@@ -1,2 +1,8 @@
dos
dos/*
linux
linux/*
os2
os2/*
win32
win32/*

View File

@@ -1,3 +1,33 @@
19990915-14:04 GMT+1 Victor Szel <info@szelvesz.hu>
* source/rtl/dir.c
include/directry.ch
! printf()s commented out, proper (but silent) error handling added.
+ Now using directry.ch for the array format.
+ A TODO: added about changing the file composing/decomposing functionality
to hb_fsFNameSplit()/Merge() functions.
+ NOTE added that the third parameter is a Harbour extension.
% Some small logic streamlining.
* Some variable names changes, some variable scopes adjusted.
* source/compiler/genobj32.c
+ Every static thing is now declared static.
+ Missing prototypes added.
* source/rtl/hardcr.c
source/rtl/mtran.c
source/tools/dates2.c
* Slight change in the format of the copyright header, the text itself
has not changed.
* source/rtl/filesys.c
+ hb_fnFNameMerge() - TOFIX: added again about the lack of buffer overlow
handling.
* .cvsignore
! DOS/LINUX/OS2 GNU Make systems working directories added.
* doc/hdr_tpl.txt
+ Some fine tunings, see the files own history. The copyright text hasn't
changed. Version 1.7
* include/std.ch
include/Makefile
+ Added a skeleton and a TODO for the STD.CH file.
19990915-11:15 GMT+1 Victor Szel <info@szelvesz.hu>
* source/rtl/dir.c
! Two warnings fixed about possibly missing paranthesis.

View File

@@ -1,61 +1,57 @@
/*
* $Id$
*/
(proposal)
/* NOTE: - Please use these template for your new files, replace parts
between curly braces {} with the appropriate text.
- You can find a history at the end of the file. */
FILE HEADER TEMPLATE
====================
/*
* $Id$
/*
* {one-liner description about the purpose of this source file}
*
* Copyright 1999 {list of individual authors and e-mail addresses}
* Part of the Harbour Project: http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version, with one exception:
*
* The exception is that if you link the Harbour Runtime Library (HRL)
* and/or the Harbour Virtual Machine (HVM) with other files to produce
* an executable, this does not by itself cause the resulting executable
* to be covered by the GNU General Public License. Your use of that
* executable is in no way restricted on account of linking the HRL
* and/or HVM code into it.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
* their web site at http://www.gnu.org/).
*
*/
FILE HEADER TEMPLATE (OPTIONAL ADDITION FOR PARTIAL COPYRIGHTS)
===============================================================
/*
Harbour Project source code
(one/two-liner description about the purpose of this source file)
Copyright 1999 (list of individual authors)
www - http://www.harbour-project.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version, with one exception:
The exception is that if you link the Harbour Runtime Library (HRL)
and/or the Harbour Virtual Machine (HVM) with other files to produce
an executable, this does not by itself cause the resulting executable
to be covered by the GNU General Public License. Your use of that
executable is in no way restricted on account of linking the HRL
and/or HVM code into it.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
their web site at http://www.gnu.org/).
V 1.6 Victor Szel RCS Id section separated from
Licenc text.
V 1.5 Victor Szel Small name correction.
V 1.4 David G. Holm Removed "(C)" from Copyright notice
Put author's name rather than date
next to each version number, because
the RCS tracks dates, but only tracks
CVS user names, not author names.
V 1.3 Victor Szel Description line changed to be a
template, too.
V 1.2 David G. Holm Added HRL/HVM license exception for
executables. Added GNU web site.
Replaced "?" in copyright statement
with "(list of individual authors)".
V 1.1 Victor Szel Added templates for file and function
headers. Committed to CVS.
V 1.0 Victor Szel Initial version.
*/
* The following parts are Copyright of the individual authors.
* Part of the Harbour Project: http://www.harbour-project.org
*
* Copyright 1999 {name} <{e-mail address}>
* {function or subsystem name}
*
* See doc/licence.txt for licensing terms.
*
*/
FUNCTION HEADER TEMPLATE
========================
@@ -88,7 +84,8 @@ FUNCTION HEADER TEMPLATE
* $END$
*/
Example:
FUNCTION HEADER EXAMPLE
=======================
/* $DOC$
* $FUNCNAME$
@@ -133,3 +130,33 @@ Example:
* $END$
*/
/* ------------------------------------------------------------------------- */
/*
* History of this file
* ====================
*
* V 1.7 Victor Szel History separated from the file header
* template. Slight changes in the format
* of the header. Removed "(proposal)"
* from the top of the file. Added partial
* copyright header template.
* V 1.6 Victor Szel RCS Id section separated from
* Licenc text.
* V 1.5 Victor Szel Small name correction.
* V 1.4 David G. Holm Removed "(C)" from Copyright notice
* Put author's name rather than date
* next to each version number, because
* the RCS tracks dates, but only tracks
* CVS user names, not author names.
* V 1.3 Victor Szel Description line changed to be a
* template, too.
* V 1.2 David G. Holm Added HRL/HVM license exception for
* executables. Added GNU web site.
* Replaced "?" in copyright statement
* with "(list of individual authors)".
* V 1.1 Victor Szel Added templates for file and function
* headers. Committed to CVS.
* V 1.0 Victor Szel Initial version.
*
*/

View File

@@ -52,6 +52,7 @@ PRG_HEADERS=\
set.ch \
setcurs.ch \
simpleio.ch \
std.ch \
API_HEADERS=\
caundoc.api \

View File

@@ -2,6 +2,8 @@
* $Id$
*/
/* NOTE: This file is also used by C code. */
#ifndef _DIRECTRY_CH
#define _DIRECTRY_CH

12
harbour/include/std.ch Normal file
View File

@@ -0,0 +1,12 @@
/*
* $Id$
*/
#ifndef _STD_CH
#define _STD_CH
#include "set.ch"
/* TODO: Fill this file. */
#endif /* _STD_CH */

View File

@@ -38,27 +38,32 @@
#include "pcode.h"
#include "hberrors.h"
static ULONG GetSymbolsSize( void );
static PCOMSYMBOL GetFirstSymbol( void );
static char * GetSymbolName( ULONG ulPos );
static ULONG GetPCodesSize( void );
static ULONG GetSymbolsAmount( void );
static BOOL IsExternal( ULONG ulSymbol );
static WORD GetExternalPos( char * szExternal );
static void GenerateLocalNames( FILE * hObjFile );
static void GenerateSymbolsSegment( FILE * hObjFile );
static void GenerateDataSegment( FILE * hObjFile );
static void GenerateCodeSegment( FILE * hObjFile );
static void GenerateExternals( FILE * hObjFile );
static void putbyte( BYTE b, FILE * hObjFile );
static void putword( WORD w, FILE * hObjFile );
static void CompiledFileName( FILE * hObjFile, char * szFileName );
static void CompilerVersion( FILE * hObjFile, char * szVersion );
static void LocalNames( FILE * hObjFile, char * szNames[] );
static void ExternalNames( FILE * hObjFile, char * szNames[] );
static void Fixup( FILE * hObjFile, BYTE bType, WORD wOffset, BYTE bFlags, BYTE bSymbol );
static void CodeSegment( FILE * hObjFile, BYTE * prgCode, ULONG ulPrgLen, WORD wFunctions );
static void DataSegment( FILE * hObjFile, BYTE * symbol, WORD wSymLen, WORD wSymbols, ULONG ulTotalSize );
static void DefineSegment( FILE * hObjFile, BYTE bName, BYTE bClass, WORD wLen );
static void PubDef( FILE * hObjFile, char * szName, WORD wSegment, WORD wOffset );
static void Fixup( FILE * hObjFile, BYTE bType, WORD wOffset, BYTE bFlags, BYTE bSymbol );
static void EnumeratedData( FILE * hObjFile, BYTE bSegment, BYTE * pData, WORD wLen, WORD wOffset );
static void GroupDef( FILE * hObjFile, BYTE bName, BYTE * aSegs );
static void End( FILE * hObjFile );
static void CodeSegment( FILE * hObjFile, BYTE * prgCode, ULONG ulPrgLen,
WORD wFunctions );
static void DataSegment( FILE * hObjFile, BYTE * symbol, WORD wSymLen,
WORD wSymbols, ULONG ulTotalSize );
static void GenerateLocalNames( FILE * hObjFile );
static void GenerateExternals( FILE * hObjFile );
static void GenerateCodeSegment( FILE * hObjFile );
static void GenerateDataSegment( FILE * hObjFile );
static void GenerateSymbolsSegment( FILE * hObjFile );
static void GroupDef( FILE * hObjFile, BYTE bName, BYTE * aSegs );
static BYTE prgFunction[] = { 0x68, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00,
0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x83, 0xC4, 0x08, 0xC3 };
@@ -144,7 +149,7 @@ static ULONG GetPCodesSize( void )
return ulTotal;
}
ULONG GetSymbolsAmount( void )
static ULONG GetSymbolsAmount( void )
{
PCOMSYMBOL pSymbol = GetFirstSymbol();
ULONG ulAmount = 1;
@@ -157,7 +162,7 @@ ULONG GetSymbolsAmount( void )
return ulAmount;
}
BOOL IsExternal( ULONG ulSymbol )
static BOOL IsExternal( ULONG ulSymbol )
{
PCOMSYMBOL pSymbol = GetFirstSymbol();
ULONG ul = 0;
@@ -168,7 +173,7 @@ BOOL IsExternal( ULONG ulSymbol )
return ! GetFunction( pSymbol->szName );
}
WORD GetExternalPos( char * szExternal )
static WORD GetExternalPos( char * szExternal )
{
WORD w = 0;
@@ -324,7 +329,7 @@ static void putbyte( BYTE b, FILE * hObjFile )
fputc( b, hObjFile );
}
void putword( WORD w, FILE * hObjFile )
static void putword( WORD w, FILE * hObjFile )
{
putbyte( LOBYTE( w ), hObjFile );
putbyte( HIBYTE( w ), hObjFile );

View File

@@ -20,6 +20,7 @@
* been requested.
*
*/
/*
* Notes from the fringe... <ptucker@sympatico.ca>
*
@@ -59,6 +60,7 @@
* TODO: - Volume label support
* - check that path support vis stat works on all platforms
* - UNC Support? ie: dir \\myserver\root
* - Use hb_fsFNameSplit()/Merge() for filename composing/decomposing.
*
*/
@@ -75,6 +77,7 @@
#include <ctype.h>
#include "extend.h"
#include "itemapi.h"
#include "directry.ch"
#if defined(__GNUC__)
#include <sys/types.h>
@@ -394,14 +397,37 @@ static BYTE * HarbourMaskToAttributes( USHORT usMask, BYTE * byAttrib )
return byAttrib;
}
/* NOTE: The third (lEightDotThree) parameter is a Harbour extension. */
HARBOUR HB_DIRECTORY( void )
{
#if defined(HAVE_POSIX_IO)
PHB_ITEM arg1_it = hb_param( 1, IT_STRING );
PHB_ITEM arg2_it = hb_param( 2, IT_STRING );
PHB_ITEM arg3_it = hb_param( 3, IT_LOGICAL );
PHB_ITEM pDirSpec = hb_param( 1, IT_STRING );
PHB_ITEM pAttributes = hb_param( 2, IT_STRING );
PHB_ITEM pEightDotThree = hb_param( 3, IT_LOGICAL );
char fullfile[ _POSIX_PATH_MAX + 1 ];
char filename[ _POSIX_PATH_MAX + 1 ];
char pattern[ _POSIX_PATH_MAX + 1 ];
char dirname[ _POSIX_PATH_MAX + 1 ];
char string[ _POSIX_PATH_MAX + 1 ];
char pfname[ _POSIX_PATH_MAX + 1 ];
char pfext[ _POSIX_PATH_MAX + 1 ];
char fname[ _POSIX_PATH_MAX + 1 ];
char fext[ _POSIX_PATH_MAX + 1 ];
BOOL bEightDotThree;
char ddate[ 9 ];
char ttime[ 9 ];
char aatrib[ 17 ];
int attrib;
long fsize;
time_t ftime;
char * pos;
int iDirnameLen;
USHORT usosMask;
USHORT ushbMask = FA_ARCH;
PHB_ITEM pDir;
struct stat statbuf;
struct tm * ft;
@@ -420,47 +446,18 @@ HARBOUR HB_DIRECTORY( void )
DIR * dir;
#endif
char fullfile[ _POSIX_PATH_MAX + 1 ];
char filename[ _POSIX_PATH_MAX + 1 ];
char pattern[ _POSIX_PATH_MAX + 1 ];
char dirname[ _POSIX_PATH_MAX + 1 ];
char string[ _POSIX_PATH_MAX + 1 ];
char pfname[ _POSIX_PATH_MAX + 1 ];
char pfext[ _POSIX_PATH_MAX + 1 ];
char fname[ _POSIX_PATH_MAX + 1 ];
char fext[ _POSIX_PATH_MAX + 1 ];
BOOL blEightDotThree = FALSE;
char ddate[ 9 ];
char ttime[ 9 ];
char aatrib[ 17 ];
int attrib;
long fsize;
time_t ftime;
char * pos;
int iDirnameLen;
USHORT usosMask;
USHORT ushbMask = FA_ARCH;
PHB_ITEM pdir;
PHB_ITEM psubarray;
PHB_ITEM pfilename;
PHB_ITEM psize;
PHB_ITEM pdate;
PHB_ITEM ptime;
PHB_ITEM pattr;
dirname[ 0 ] = '\0';
pattern[ 0 ] = '\0';
/* Get the passed attributes and convert them to Harbour Flags */
if( arg2_it && hb_parclen( 2 ) >= 1 )
ushbMask |= HarbourAttributesToMask( ( BYTE * ) hb_parc( 2 ) );
if( pAttributes && hb_itemGetCLen( pAttributes ) >= 1 )
ushbMask |= HarbourAttributesToMask( ( BYTE * ) hb_itemGetCPtr( pAttributes ) );
/* Translate Harbour Flags into OS specific flags */
usosMask = HarbourToOsMask( ushbMask );
/* Do we want 8.3 support? */
if( arg3_it )
blEightDotThree = ( hb_parl( 3 ) ? TRUE : FALSE );
bEightDotThree = ( pEightDotThree ? hb_itemGetL( pEightDotThree ) : FALSE );
pattern[ 0 ] = '\0';
@@ -471,9 +468,9 @@ HARBOUR HB_DIRECTORY( void )
/* get rid of anything else */
ushbMask = FA_LABEL;
if( arg1_it )
if( pDirSpec )
{
strcpy( string, hb_parc( 1 ) );
strcpy( string, hb_itemGetCPtr( pDirSpec ) );
pos = strrchr( string, ':' );
if( pos )
*( ++pos ) = '\0';
@@ -485,9 +482,9 @@ HARBOUR HB_DIRECTORY( void )
}
else
{
if( arg1_it )
if( pDirSpec )
{
strcpy( string, hb_parc( 1 ) );
strcpy( string, hb_itemGetCPtr( pDirSpec ) );
pos = strrchr( string, OS_PATH_DELIMITER );
if( pos )
{
@@ -542,7 +539,7 @@ HARBOUR HB_DIRECTORY( void )
/* should have drive,directory in dirname and filespec in pattern */
tzset();
pdir = hb_itemArrayNew( 0 );
pDir = hb_itemArrayNew( 0 );
#if defined(_MSC_VER)
@@ -557,7 +554,7 @@ HARBOUR HB_DIRECTORY( void )
strcat( string, entry.name );
/* this needs the full path to the file */
if( blEightDotThree )
if( bEightDotThree )
GetShortPathName( string, string, _POSIX_PATH_MAX );
#elif defined(__IBMCPP__)
@@ -571,18 +568,23 @@ HARBOUR HB_DIRECTORY( void )
#else
#if defined(__WATCOMC__)
/* opendir in Watcom doesn't like the path delimiter at the end of a string */
dirname[ iDirnameLen ] = '.';
dirname[ iDirnameLen+1 ] = '\0';
dirname[ iDirnameLen ] = '.';
dirname[ iDirnameLen + 1 ] = '\0';
#endif
dir = opendir( dirname );
#if defined(__WATCOMC__)
dirname[ iDirnameLen ] = '\0';
#endif
if( NULL == dir )
{
/* TODO: proper error handling */
/* debug code
printf( "\n invalid dirname %s ", dirname );
while( 0 == getchar() );
*/
hb_itemReturn( pDir );
hb_itemRelease( pDir );
return;
}
/* now put everything into an array */
@@ -593,7 +595,7 @@ HARBOUR HB_DIRECTORY( void )
#endif
pos = strrchr( string, OS_PATH_DELIMITER );
if( pos )
pos = strrchr( pos+1, '.' );
pos = strrchr( pos + 1, '.' );
else
pos = strrchr( string, '.' );
@@ -607,7 +609,7 @@ HARBOUR HB_DIRECTORY( void )
pos = strrchr( string, OS_PATH_DELIMITER );
if( pos )
strcpy( fname, pos +1 );
strcpy( fname, pos + 1 );
else
strcpy( fname, string );
@@ -624,7 +626,7 @@ HARBOUR HB_DIRECTORY( void )
#if defined(_MSC_VER)
/* due to short-name support: reconstruct the filename */
if( blEightDotThree )
if( bEightDotThree )
{
pos = strrchr( string, OS_PATH_DELIMITER );
if( pos )
@@ -658,13 +660,7 @@ HARBOUR HB_DIRECTORY( void )
strcat( fullfile, filename );
if( -1 == stat( fullfile, &statbuf ) )
{
/* TODO: proper error handling */
printf( "\n invalid file %s ", fullfile );
while( 0 == getchar() );
}
else
if( -1 != stat( fullfile, &statbuf ) )
{
fsize = statbuf.st_size;
ftime = statbuf.st_mtime;
@@ -678,7 +674,7 @@ HARBOUR HB_DIRECTORY( void )
#else
#if defined(_MSC_VER)
attrib = entry.attrib;
if( blEightDotThree )
if( bEightDotThree )
{
/* need to strip off the path */
pos = strrchr( filename, OS_PATH_DELIMITER );
@@ -715,34 +711,42 @@ HARBOUR HB_DIRECTORY( void )
*/
}
/* debug code
else
{
printf( "\n invalid file %s ", fullfile );
while( 0 == getchar() );
}
*/
if( !( ( ( ushbMask & FA_HIDDEN ) == 0 && ( attrib & FA_HIDDEN ) > 0 ) ||
( ( ushbMask & FA_SYSTEM ) == 0 && ( attrib & FA_SYSTEM ) > 0 ) ||
( ( ushbMask & FA_DIREC ) == 0 && ( attrib & FA_DIREC ) > 0 ) ) )
{
/* array cname, csize, ddate, ctime, cattributes */
pfilename = hb_itemPutC( NULL, filename );
psize = hb_itemPutNL( NULL, fsize );
pdate = hb_itemPutDS( NULL, ddate );
ptime = hb_itemPutC( NULL, ttime );
pattr = hb_itemPutC( NULL, ( char * ) HarbourMaskToAttributes( attrib, ( BYTE * ) aatrib ) );
psubarray = hb_itemArrayNew( 5 );
hb_itemArrayPut( psubarray, 1, pfilename );
hb_itemArrayPut( psubarray, 2, psize );
hb_itemArrayPut( psubarray, 3, pdate );
hb_itemArrayPut( psubarray, 4, ptime );
hb_itemArrayPut( psubarray, 5, pattr );
PHB_ITEM pSubarray = hb_itemArrayNew( F_LEN );
PHB_ITEM pFilename = hb_itemPutC( NULL, filename );
PHB_ITEM pSize = hb_itemPutNL( NULL, fsize );
PHB_ITEM pDate = hb_itemPutDS( NULL, ddate );
PHB_ITEM pTime = hb_itemPutC( NULL, ttime );
PHB_ITEM pAttr = hb_itemPutC( NULL, ( char * ) HarbourMaskToAttributes( attrib, ( BYTE * ) aatrib ) );
hb_itemArrayPut( pSubarray, F_NAME, pFilename );
hb_itemArrayPut( pSubarray, F_SIZE, pSize );
hb_itemArrayPut( pSubarray, F_DATE, pDate );
hb_itemArrayPut( pSubarray, F_TIME, pTime );
hb_itemArrayPut( pSubarray, F_ATTR, pAttr );
/* NOTE: Simply ignores the situation where the array length
limit is reached. */
hb_arrayAdd( pdir, psubarray );
hb_arrayAdd( pDir, pSubarray );
hb_itemRelease( pfilename );
hb_itemRelease( psize );
hb_itemRelease( pdate );
hb_itemRelease( ptime );
hb_itemRelease( pattr );
hb_itemRelease( psubarray );
hb_itemRelease( pFilename );
hb_itemRelease( pSize );
hb_itemRelease( pDate );
hb_itemRelease( pTime );
hb_itemRelease( pAttr );
hb_itemRelease( pSubarray );
}
}
}
@@ -756,8 +760,8 @@ HARBOUR HB_DIRECTORY( void )
closedir( dir );
#endif
hb_itemReturn( pdir ); /* DIRECTORY() returns an array */
hb_itemRelease( pdir );
hb_itemReturn( pDir ); /* DIRECTORY() returns an array */
hb_itemRelease( pDir );
#if defined(_MSC_VER) || defined(__IBMCPP__)
@@ -765,3 +769,4 @@ HARBOUR HB_DIRECTORY( void )
#endif
#endif /* HAVE_POSIX_IO */
}

View File

@@ -1437,6 +1437,8 @@ PHB_FNAME hb_fsFNameSplit( char * szFileName )
return pFileName;
}
/* TOFIX: Add a check for buffer overrun sitiuations. */
/* This function joins path, name and extension into a string with a filename */
char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName )
{