hbmisc

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  
c:\harbour\contrib\hbmisc
dates2.c
TypeFunctionSourceLine
BOOLhb_isleapyear( int iYear )
BOOL hb_isleapyear( int iYear )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_isleapyear(%d)", iYear));

   return ( iYear % 4 == 0 && iYear % 100 != 0 ) || ( iYear % 400 == 0 );
}
dates2.c75
INThb_daysinmonth( int iYear, int iMonth )
int hb_daysinmonth( int iYear, int iMonth )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_daysinmonth(%d, %d)", iYear, iMonth));

   if( iMonth > 0 && iMonth < 13 )
      return s_daysinmonth[ iMonth - 1 ] + 
             ( ( iMonth == 2 && hb_isleapyear( iYear ) ) ? 1 : 0 );
   else
      return 0;
}
dates2.c82
INThb_doy( int iYear, int iMonth, int iDay )
int hb_doy( int iYear, int iMonth, int iDay )
{
   int i;
   int iDoy = 0;

   HB_TRACE(HB_TR_DEBUG, ("hb_doy(%d, %d, %d)", iYear, iMonth, iDay));

   for( i = 1; i < iMonth; i++ )
      iDoy += hb_daysinmonth( iYear, i );

   return iDoy + iDay;
}
dates2.c93
INThb_wom( int iYear, int iMonth, int iDay )
int hb_wom( int iYear, int iMonth, int iDay )
{
   int iWom;

   HB_TRACE(HB_TR_DEBUG, ("hb_wom(%d, %d, %d)", iYear, iMonth, iDay));

   iWom = iDay + hb_dateDOW( iYear, iMonth, 1 ) - 1;
   if( iWom > 0 )
      return ( iWom - hb_dateDOW( iYear, iMonth, iDay ) ) / 7 + 1;
   else
      return 0;
}
dates2.c106
INThb_woy( int iYear, int iMonth, int iDay, BOOL bISO )
int hb_woy( int iYear, int iMonth, int iDay, BOOL bISO )
{
   int iWeek, n;

   HB_TRACE(HB_TR_DEBUG, ("hb_woy(%d, %d, %d, %d)", iYear, iMonth, iDay, (int) bISO));

   iDay = hb_doy( iYear, iMonth, iDay );
   n = ( ( ( 1 - ( bISO ? 1 : 0 ) ) % 7 ) ) - 1;
   iDay += ( n > 0 ) ? 1 : 0;
   iWeek = iDay / 7;
   if( bISO )
      iWeek += ( n < 4 ) ? 1 : 0;
   else
      ++iWeek;

   return iWeek;
}
dates2.c119
HB_FUNCAMONTHS(void)
HB_FUNC( AMONTHS )
{
   PHB_ITEM pReturn = hb_itemArrayNew( 12 );    /* Create array */
   int i;

   for( i = 0; i < 12; i++ )
   {
      PHB_ITEM pString = hb_itemPutC( NULL, ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_MONTH + i ) );
      hb_itemArrayPut( pReturn, i+1, pString );
      hb_itemRelease( pString );
   }
   hb_itemReturn( pReturn );
   hb_itemRelease( pReturn );
}
dates2.c137
HB_FUNCADAYS(void)
HB_FUNC( ADAYS )
{
   PHB_ITEM pReturn = hb_itemArrayNew( 7 );    /* Create array */
   int i;

   for( i = 0; i < 7; i++ )
   {
      PHB_ITEM pString = hb_itemPutC( NULL, ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_DAY + i ) );
      hb_itemArrayPut( pReturn, i + 1, pString );
      hb_itemRelease( pString );
   }
   hb_itemReturn( pReturn );
   hb_itemRelease( pReturn );
}
dates2.c152
HB_FUNCISLEAPYEAR(void)
HB_FUNC( ISLEAPYEAR )
{
   PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );

   if( pDate )
   {
      int iYear, iMonth, iDay;

      hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay );
      hb_retl( hb_isleapyear( iYear ) );
   }
   else
      hb_retl( FALSE );
}
dates2.c167
HB_FUNCDAYSINMONTH(void)
HB_FUNC( DAYSINMONTH )
{
   PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );

   if( pDate )
   {
      int iYear, iMonth, iDay;

      hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay );
      hb_retni( hb_daysinmonth( iYear, iMonth ) );
   }
   else
      hb_retni( 0 );
}
dates2.c182
HB_FUNCEOM(void)
HB_FUNC( EOM )
{
   PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );

   if( pDate )
   {
      int iYear, iMonth, iDay;

      hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay );
      hb_retd( iYear, iMonth, hb_daysinmonth( iYear, iMonth ) );
   }
   else
      hb_retdl( 0 );
}
dates2.c197
HB_FUNCBOM(void)
HB_FUNC( BOM )
{
   PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );

   if( pDate )
   {
      int iYear, iMonth, iDay;

      hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay );
      hb_retd( iYear, iMonth, 1 );
   }
   else
      hb_retdl( 0 );
}
dates2.c212
HB_FUNCWOM(void)
HB_FUNC( WOM )
{
   PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );

   if( pDate )
   {
      int iYear, iMonth, iDay;

      hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay );
      hb_retni( hb_wom( iYear, iMonth, iDay ) );
   }
   else
      hb_retni( 0 );
}
dates2.c227
HB_FUNCDOY(void)
HB_FUNC( DOY )
{
   PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );

   if( pDate )
   {
      int iYear, iMonth, iDay;

      hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay );
      hb_retni( hb_doy( iYear, iMonth, iDay ) );
   }
   else
      hb_retni( 0 );
}
dates2.c242
HB_FUNCWOY(void)
HB_FUNC( WOY )
{
   PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );

   if( pDate )
   {
      int iYear, iMonth, iDay;

      hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay );
      hb_retni( hb_woy( iYear, iMonth, iDay, ISLOG( 2 ) ? hb_parl( 2 ) : TRUE ) );
   }
   else
      hb_retni( 0 );
}
dates2.c259
HB_FUNCEOY(void)
HB_FUNC( EOY )
{
   PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );

   if( pDate )
   {
      int iYear, iMonth, iDay;

      hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay );
      hb_retd( iYear, 12, 31 );
   }
   else
      hb_retdl( 0 );
}
dates2.c274
HB_FUNCBOY(void)
HB_FUNC( BOY )
{
   PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );

   if( pDate )
   {
      int iYear, iMonth, iDay;

      hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay );
      hb_retd( iYear, 1, 1 );
   }
   else
      hb_retdl( 0 );
}
dates2.c289
hb_f.c
TypeFunctionSourceLine
HB_FUNCHB_FUSE(void)
HB_FUNC( HB_FUSE )
{
   PHB_ITEM arg1_it = hb_param( 1, HB_IT_STRING );
   PHB_ITEM arg2_it = hb_param( 2, HB_IT_NUMERIC );
   int open_flags;

   if ( arg1_it ) {

     if( arg2_it )
         open_flags = hb_parni( 2 );
     else
         open_flags = 0;

      handles[area]  = hb_fsOpen( ( BYTE * ) hb_parc( 1 ), ( SHORT ) open_flags );
      offset[area]   = 0;
      recno[area]    = 1;
      b              = ( char * ) hb_xgrab( b_size );
      c              = ( char * ) hb_xgrab( c_size );
      lastbyte[area] = hb_fsSeek( handles[ area ], 0L, FS_END );
      isEof[area] = ( lastbyte[ area ] == 0 );
      hb_retni( handles[ area ] );
   }
   else {
      hb_fsClose( handles[area] );
      hb_xfree( b );
      hb_xfree( c );
      hb_retni( 1 );
      recno[area]    = 0L;
      offset[area]   = 0L;
      handles[area]  = 0;
      last_rec[area] = 0L;
      last_off[area] = 0L;
      lastbyte[area] = 0L;
      isEof[area]    = 0;
   }
}
hb_f.c71
HB_FUNCHB_FRECNO(void)
HB_FUNC( HB_FRECNO )
{
   hb_retnl( recno[ area ] );
}
hb_f.c109
STATIC LONGhb_hbfskip( int recs )
static long hb_hbfskip( int recs )
{
   long read_pos;
   long read_len;
   long x, y;

   HB_TRACE(HB_TR_DEBUG, ("hb_hbskip(%d)", recs));

   if ( recs > 0 ) {
      for (y = 0; y < recs; y++ ) {
         hb_fsSeek( handles[area], offset[area], FS_SET );
         read_len = hb_fsRead( handles[area], ( BYTE * ) b, b_size );
         for (x = 0; x < read_len; x++ ) {
            if ( ((*(b + x) == 13) && (*(b + x + 1) == 10)) ||
                 ((*(b + x) == 10) && (*(b + x + 1) == 13)) ) {
               break;
            }
         }
         if ( (offset[area] + x + 2) < lastbyte[area] ) {
            isEof[area] = FALSE;
            offset[area] += (x + 2);
            recno[area] += 1;
         }
         else
            isEof[area] = TRUE;
      }
   }
   else {
      recs = -recs;
      isEof[area] = FALSE;

      if ( (recno[area] - recs) < 1 )
         return( 1 );

      for (y = recs; y > 0; y-- ) {
         if ( offset[area] - b_size < 0L ) {
            read_pos = 0;
            read_len = (size_t)offset[area];
         }
         else {
            read_pos = (size_t)(offset[area] - b_size);
            read_len = b_size;
         }

         hb_fsSeek( handles[area], read_pos, FS_SET );
         read_len = hb_fsRead( handles[area], ( BYTE * ) b, ( USHORT )read_len );

         for (x = read_len - 4; x >= 0; x-- ) {
            if ( ((*(b + x) == 13) && (*(b + x + 1) == 10)) ||
                 ((*(b + x) == 10) && (*(b + x + 1) == 13)) ) {
               break;
            }
         }
         if ( x < 0 ) {
            offset[area] = 0;
            recno[area] = 1;
         }
         else {
            offset[area] = read_pos + x + 2;
            recno[area]--;
         }
      }
   }

   return ( recno[area] );
}
hb_f.c115
HB_FUNCHB_FSKIP(void)
HB_FUNC( HB_FSKIP )
{
   hb_hbfskip( ISNUM( 1 ) ? hb_parni(1) : 1 );
}
hb_f.c182
HB_FUNCHB_FREADLN(void)
HB_FUNC( HB_FREADLN )
{
   int x;
   long read;

   hb_fsSeek( handles[area], offset[area], FS_SET );
   read = hb_fsRead( handles[area], ( BYTE * ) b, b_size );

   for ( x = 0; x < b_size; x++ ) {
      if ( ((*(b + x) == 13) && (*(b + x + 1) == 10)) ||
           ((*(b + x) == 10) && (*(b + x + 1) == 13)) ||
           (*(b + x) == 26) || ( x >= (int)read) ) {
         break;
      }
   }
   hb_retclen( b, x );

}
hb_f.c187
HB_FUNCHB_FEOF(void)
HB_FUNC( HB_FEOF )
{
   hb_retl( isEof[area] );
}
hb_f.c206
HB_FUNCHB_FGOTO(void)
HB_FUNC( HB_FGOTO )
{
   long target;
   long last;

   target = hb_parnl(1);

   if ( recno[area] > target ) {
      while ( recno[area] != target )   {
         last = recno[area];
         hb_hbfskip(-1);
         if ( recno[area] == last )
            break;
      }
   }
   else {
      while ( recno[area] != target ) {
         last = recno[area];
         hb_hbfskip(1);
         if ( recno[area] == last )
            break;
      }
   }
}
hb_f.c211
HB_FUNCHB_FGOBOTTOM(void)
HB_FUNC( HB_FGOBOTTOM )
{
   int x;
   int len;
   long loc, last;

   if ( last_rec[area] != 0 ) {
      recno[area] = last_rec[area];
      offset[area] = last_off[area];
   }
   else {

      loc = 0L;

      last = offset[area];
      do {
         hb_fsSeek( handles[area], offset[area], FS_SET );
         len = hb_fsRead(  handles[area], ( BYTE * ) c, c_size );
         for ( x = 0; x < len; x++ ) {
            if ( ((*(c + x) == 13) && (*(c + x + 1) == 10)) ||
                 ((*(c + x) == 10) && (*(c + x + 1) == 13)) ||
                 ( x - loc > b_size ) ) {
               last = offset[area] + loc;
               recno[area]++;
               x++;
               loc = x + 1;
            }
         }
         offset[area] += loc;

      } while ( len == c_size );

      last_rec[area] = --recno[area];
      last_off[area] = last;
   }
}
hb_f.c236
HB_FUNCHB_FGOTOP(void)
HB_FUNC( HB_FGOTOP )
{
   offset[area] = 0L;
   recno[area] = 1L;
   isEof[area] = (lastbyte[area] == 0);
}
hb_f.c273
HB_FUNCHB_FLASTREC(void)
HB_FUNC( HB_FLASTREC )
{
   long old_rec;
   long old_offset;
   int  bIsEof;

   old_rec = recno[area];
   old_offset = offset[area];
   bIsEof  = isEof[area];

   HB_FUNC_EXEC( HB_FGOBOTTOM );
   hb_retnl( last_rec[area] );

   recno[area]  = old_rec;
   offset[area] = old_offset;
   isEof[area]  = bIsEof  ;
}
hb_f.c280
HB_FUNCHB_FSELECT(void)
HB_FUNC( HB_FSELECT )
{
   hb_retni( area + 1 );

   if ( ISNUM(1) )
      area = hb_parni(1) - 1;
}
hb_f.c298
HB_FUNCHB_FINFO(void)
HB_FUNC( HB_FINFO )                     /* used for debugging */
{
   hb_reta( 6 );
   hb_storni( area+1,         -1, 1);
   hb_storni( last_rec[area], -1, 2);
   hb_storni( recno[area],    -1, 3);
   hb_storni( offset[area],   -1, 4);
   hb_storni( lastbyte[area], -1, 5);
   hb_storl ( isEof[area],    -1, 6);
}
hb_f.c306
HB_FUNCHB_FREADANDSKIP(void)
HB_FUNC( HB_FREADANDSKIP )
{
/* ------------------------------------------------
   Warning: This is a rogue function! It is a first shot at adding the logic
   to read .csv records that respect CRLF embedded within quotes.
   It is very common, especially with Microsoft products, for
   comma-separated files to allow a field (usually an address field)
   to have hard returns within it. These records appear corrupted to any
   reader that presumes all hard returns are record separators.

   This function is useful right now to loop through a CSV file
   while !hb_feof(), but it does NOT recognize the same record count
   and positioning that the other functions in this file use.
   It does its own skip and read, so an entire file can be read
   sequentially with just this function.
   -BH
 --------------------------------------------------*/
   long x =  0;
   long read;
   BOOL bInField = 0, bHasCRLF = FALSE;

   hb_fsSeek( handles[area], offset[area], FS_SET );
   read = hb_fsRead( handles[area], ( BYTE * ) b, b_size );

   while (  x < read )
   {
      if ( *(b + x) == '"' )
      {
         bInField = !bInField ;
         x++;
         continue;
      }
      if ( bInField )
      {
         x++;
         continue;
      }
      if(  ((*(b + x) == 13) && x < read-1 && (*(b + x + 1) == 10)) ||
           ((*(b + x) == 10) && x < read-1 && (*(b + x + 1) == 13)) )
      {
         x += 2;
         bHasCRLF = TRUE;
         break;
      }
      x++;
   }

   offset[area] = offset[area] + x;
   recno[area] += 1;
   /* See if there's more to read */
   if ( !isEof[area] )
      isEof[area] = (lastbyte[area] <= offset[area] + 1) ;

   hb_retclen( b, x - (bHasCRLF ? 2 : 0) );
}
hb_f.c317
spd.c
TypeFunctionSourceLine
STATIC VOIDSTAItm( PHB_ITEM pItmPar )
static void STAItm( PHB_ITEM pItmPar )
{
   ULONG i, ulItmPar = hb_itemGetCLen( pItmPar );
   char *cRes, *c, *cItmPar = hb_itemGetCPtr( pItmPar );

   for( i = 3, c = cItmPar; *c; c++ ){
      if( *c == '\'' ) i++;   /* Count ' Tokens */
   }
   cRes = (char *)hb_xgrab( ulItmPar + i * sizeof(char) );
   i = 0; c = cItmPar; cRes[i++] = '\'';
   while( *c ){
      if( *c == '\'' ) cRes[i++] = '\'';
      cRes[i++] = *c++;
   }
   cRes[i++] = '\''; /* cRes[i] = '\0'; */
   hb_itemPutCLPtr( pItmPar, cRes, i );
}
spd.c58
STATIC ULONGSCItm( char *cBuffer, ULONG ulMaxBuf, char *cParFrm, int iCOut, int IsIndW, int iIndWidth, int IsIndP, int iIndPrec, PHB_ITEM pItmPar )
static ULONG SCItm( char *cBuffer, ULONG ulMaxBuf, char *cParFrm, int iCOut, int IsIndW, int iIndWidth, int IsIndP, int iIndPrec, PHB_ITEM pItmPar )
{
   ULONG s;

   /* NOTE: In DJGPP (4.2.3) snprintf() will be preprocessed to sprintf(), which
            makes ulMaxBuf unused, and this in turn causes a warning, so we're
            manually suppressing it. [vszakats] */
   #if defined(__DJGPP__)
      HB_SYMBOL_UNUSED( ulMaxBuf );
   #endif

   if( IsIndW && IsIndP ){
      switch( iCOut ){
      case 'p':
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec, hb_itemGetPtr( pItmPar ) );
         break;
      case 's': case 'S':
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec, hb_itemGetCPtr( pItmPar ) );
         break;
      case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec, hb_itemGetND( pItmPar ) );
         break;
      /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
      default:
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, iIndWidth, iIndPrec, (HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar )) );
      }
   }else if( IsIndW || IsIndP ){
      int iInd = (IsIndW ? iIndWidth : iIndPrec);

      switch( iCOut ){
      case 'p':
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetPtr( pItmPar ) );
         break;
      case 's': case 'S':
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetCPtr( pItmPar ) );
         break;
      case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, hb_itemGetND( pItmPar ) );
         break;
      /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
      default:
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, iInd, (HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar )) );
      }
   }else{
      switch( iCOut ){
      case 'p':
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetPtr( pItmPar ) );
         break;
      case 's': case 'S':
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetCPtr( pItmPar ) );
         break;
      case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A':
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, hb_itemGetND( pItmPar ) );
         break;
      /* case 'c': case 'C': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': */
      default:
         s = snprintf( cBuffer, ulMaxBuf, cParFrm, (HB_IS_LONG( pItmPar ) ? hb_itemGetNL( pItmPar ) : hb_itemGetNI( pItmPar )) );
      }
   }
   return s;
}
spd.c76
HB_FUNCSQL_SPRINTF(void)
HB_FUNC( SQL_SPRINTF )
{
   ULONG ulItmFrm;
   char *cRes, *cItmFrm;
   int argc = hb_pcount() - 1;
   PHB_ITEM pItmFrm = hb_param( 1, HB_IT_STRING );

   if( !pItmFrm || (cItmFrm = hb_itemGetCPtr( pItmFrm )) == NULL ){
      hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, 1, hb_paramError( 1 ) );
   }else if( (ulItmFrm = hb_itemGetCLen( pItmFrm )) == 0 ){
      hb_retc( NULL );
   }else if( !argc ){
      cRes = (char *)hb_xgrab( ulItmFrm + sizeof(char) );
      memcpy( cRes, cItmFrm, ulItmFrm + sizeof(char) );
      hb_retclen_buffer( cRes, ulItmFrm );
   }else{
      PHB_ITEM pItmPar, pItmCpy;
      char *cIntMod, *cBuffer, *cParFrm, *c;
      int p, arg, iCOut, IsType, IsIndW, IsIndP, iIndWidth, iIndPrec, iErrorPar = 0;
      ULONG s, f, i, ulWidth, ulParPos = 0, ulResPos = 0, ulMaxBuf = DK_INCBUF, ulMaxRes = DK_INCRES;
      static char cToken[] = "stcdiouxXaAeEfgGpnSC";

      cIntMod = NULL;
      cRes = (char *)hb_xgrab( ulMaxRes );
      cBuffer = (char *)hb_xgrab( ulMaxBuf );
      cParFrm = (char *)hb_xgrab( ulItmFrm + sizeof(char) );

      for( p = 0; p < argc; /* Not p++ by support index & indirect arguments */ ){

         c = cItmFrm + ulParPos;
         s = f = i = ulWidth = arg = iCOut = IsType = IsIndW = iIndWidth = IsIndP = iIndPrec = 0;
         do{   /* Get Par Format */
            cParFrm[i++] = *c;
            if( f && *c == '%' ){
               f = ulWidth = IsIndW = IsIndP = 0;
            }else if( f && !ulWidth && *c >= '0' && *c <= '9' ){
               ulWidth = atol( c );
            }else if( f && *c == '.' ){
               if( f++ == 2 ) iErrorPar = 1;
            }else if( f && *c == '*' ){
               if( f == 2 ){
                  if( IsIndP ){
                     f = 3; iErrorPar = 1;
                  }else{
                     IsIndP = 1;
                  }
               }else if( !IsIndW ){
                  IsIndW = 1;
               }else{
                  f = 3; iErrorPar = 1;
               }
            }else if( f && *c == '$' ){
               if( ulWidth && IsIndP && !iIndPrec ){
                  iIndPrec = ulWidth;
                  iCOut = '*';
               }else if( ulWidth && IsIndW && !iIndWidth ){
                  iIndWidth = ulWidth;
                  ulWidth = 0; iCOut = '*';
               }else if( ulWidth && !arg ){
                  arg = ulWidth;
                  ulWidth = 0; iCOut = '%';
               }else{
                  f = 3; iErrorPar = 1;
               }
               while( i && cParFrm[--i] != iCOut ) {};
               ++i; iCOut = 0;
            }else if( f && *c == '{' ){
               if( s ){
                  f = 3; iErrorPar = 1;
               }else{   /* Remove Internal Modifier */
                  if( cIntMod == NULL ){
                     cIntMod = (char *)hb_xgrab( ulItmFrm + sizeof(char) );
                  }
                  while( *c++ && *c != '}' ) cIntMod[s++] = *c;
                  --i; cIntMod[s] = '\0';
                  if( *(c - 1) == '\0' ){
                     f = 3; iErrorPar = 1;
                  }
               }
            }else if( f && strchr(cToken, *c) ){
               f = 3; iCOut = *c;
            }else if( *c == '%' ){
               f = 1;
            }
            c++;
         }while( f < 3 && *c ); cParFrm[f = i] = '\0';
         if( iErrorPar ) break;

         if( iCOut == 't' ){
            if( cParFrm[f - 2] == '%' ){
               IsType = 1; iCOut = cParFrm[f - 1] = 's';
            }else{
               iErrorPar = 1; break;
            }
         }

         if( IsIndW  ){ /* Get Par Indirectly Width Item */
            pItmPar = hb_param( (iIndWidth ? iIndWidth + 1 :  p++ + 2), HB_IT_INTEGER );
            if( pItmPar ){
               if( (iIndWidth = hb_itemGetNI( pItmPar )) < 0 ){
                  ulWidth = -iIndWidth;
               }else{
                  ulWidth = iIndWidth;
               }
            }else{
               iErrorPar = 1; break;
            }
         }

         if( IsIndP ){  /* Get Par Indirectly Precision Item */
            pItmPar = hb_param( (iIndPrec ? iIndPrec + 1 :  p++ + 2), HB_IT_INTEGER );
            if( pItmPar ){
               iIndPrec = hb_itemGetNI( pItmPar );
            }else{
               iErrorPar = 1; break;
            }
         }

         if( !arg && *c && p == argc - 1 ){ /* No more Par Items */
            do{ cParFrm[i++] = *c; }while( *c++ ); i--;
         }  /* i == strlen(cParFrm) */

         pItmPar = hb_param( (arg ? arg + 1 :  p++ + 2), HB_IT_ANY );   /* Get Par Item */
         if( !pItmPar ){
            iErrorPar = 1; break;
         }

         if( !iCOut || iCOut == 'n' ){ /* Par Text Out */

            for( f = i, i = 0; i < f; i++ ){ /* Change %% with % */
               if( cParFrm[i] == '%' && cParFrm[i + 1] == '%' ){
                  memcpy( cParFrm + i, cParFrm + i + 1, f - i );
                  f--;
               }
            }  /* i == strlen(cParFrm) */
            if( iCOut ){
               for( f = 0; f < i; f++ ){  /* Erase %n */
                  if( cParFrm[f] == '%' && cParFrm[f + 1] == 'n' ){
                     memcpy( cParFrm + f, cParFrm + f + 2, i - f - 1 );
                     break;
                  }
               }  /* f == Index % of n */
               if( f < i ){
                  i -= 2;  /* i == strlen(cParFrm) */
                  hb_itemPutNL( pItmPar, ulResPos + f );
               }else{
                  iErrorPar = 1; break;
               }
            }
            if( (f = i + sizeof(char)) > ulMaxBuf ){
               ulMaxBuf += f + DK_INCBUF;
               cBuffer = (char *)hb_xrealloc( cBuffer, ulMaxBuf );
            }
            hb_strncpy( cBuffer, cParFrm, i ); s = i;

         }else{   /* Par Item sprintf() Out */

#        ifdef HB_IT_NULL
            if( (HB_IS_NIL( pItmPar ) || HB_IS_NULL( pItmPar )) ){
#        else
            if( HB_IS_NIL( pItmPar ) ){
#        endif
               ulWidth = f; IsIndW = IsIndP = 0;
               while( cParFrm[--f] != '%' ) {};
               iCOut = cParFrm[f + 1] = 's'; /* Change format with %s */
               memcpy( cParFrm + f + 2, cParFrm + ulWidth, i - ulWidth + 1 );
               i -= ulWidth - f - 2;   /* i == strlen(cParFrm) */
               if( (f = i + 5) > ulMaxBuf ){ /* size of "NULL" == 5 */
                  ulMaxBuf += f + DK_INCBUF;
                  cBuffer = (char *)hb_xrealloc( cBuffer, ulMaxBuf );
               }
               hb_itemCopy( pItmCpy = hb_itemNew( NULL ), pItmPar );
               hb_itemPutCL( pItmCpy, "NULL", 4 );
               s = SCItm( cBuffer, ulMaxBuf, cParFrm, iCOut, IsIndW, iIndWidth, IsIndP, iIndPrec, pItmCpy );
               hb_itemRelease( pItmCpy );

            }else if( HB_IS_STRING( pItmPar ) && (iCOut == 's' || iCOut == 'S') ){
               if( IsType ){
                  hb_itemCopy( pItmCpy = hb_itemNew( NULL ), pItmPar ); pItmPar = pItmCpy;
                  STAItm( pItmPar );
               }
               f = hb_itemGetCLen( pItmPar );
               if( (f = i + HB_MAX(ulWidth, f)) > ulMaxBuf ){
                  ulMaxBuf += f + DK_INCBUF;
                  cBuffer = (char *)hb_xrealloc( cBuffer, ulMaxBuf );
               }
               s = SCItm( cBuffer, ulMaxBuf, cParFrm, iCOut, IsIndW, iIndWidth, IsIndP, iIndPrec, pItmPar );
               if( IsType ) hb_itemRelease( pItmPar );

            }else if( HB_IS_DATE( pItmPar ) && iCOut == 's' ){
               char cDTBuf[ 19 ], cDTFrm[ 28 ]; /* 26 + 2 if %t and change format time */

               if( s ){ /* Internal Modifier */
                  for( f = 0; cIntMod[f] && cIntMod[f] != ' '; f++ ) {};
                  if( f != s ) cIntMod[f++] = '\0';   /* Date & Time */
               }

#           ifdef __XHARBOUR__
               if( HB_IS_DATETIME( pItmPar ) ){
                  hb_datetimeFormat( hb_itemGetDTS( pItmPar, cDTBuf ), cDTFrm,
                                       (s ? cIntMod : (IsType ? "YYYY-MM-DD" : hb_setGetDateFormat())),
                                       (s ? cIntMod + f : "HH:MM:SS") );
                  if( s ){
                     if( !cIntMod[0] ){
                        memcpy( cDTFrm, cDTFrm + 1, 27 );   /* LTrim 1 space if only Time */
                     }else if( cDTFrm[s] == ' ' ){
                        cDTFrm[s] = '\0'; /* RTrim 1 space if only Date */
                     }
                  }
               }else
#           endif
                  hb_dateFormat( hb_itemGetDS( pItmPar, cDTBuf ), cDTFrm,
                                    (s ? cIntMod : (IsType ? "YYYY-MM-DD" : hb_setGetDateFormat())) );

               if( (f = i + HB_MAX(ulWidth, 28)) > ulMaxBuf ){
                  ulMaxBuf += f + DK_INCBUF;
                  cBuffer = (char *)hb_xrealloc( cBuffer, ulMaxBuf );
               }
               hb_itemCopy( pItmCpy = hb_itemNew( NULL ), pItmPar );
               hb_itemPutC( pItmCpy, cDTFrm );
               if( IsType ) STAItm( pItmCpy );
               s = SCItm( cBuffer, ulMaxBuf, cParFrm, iCOut, IsIndW, iIndWidth, IsIndP, iIndPrec, pItmCpy );
               hb_itemRelease( pItmCpy );

            }else if( HB_IS_LOGICAL( pItmPar ) ){

               if( s ){ /* Internal Modifier */
                  for( f = 0; cIntMod[f] && cIntMod[f] != ','; f++ ) {};
                  if( f != s ) cIntMod[f++] = '\0';   /* TRUE & FALSE */
               }
               if( iCOut == 's' ){
                  hb_itemCopy( pItmCpy = hb_itemNew( NULL ), pItmPar ); pItmPar = pItmCpy;
                  hb_itemPutC( pItmPar, (hb_itemGetL( pItmPar ) ? (s ? cIntMod : "TRUE") : (s ? cIntMod + f : "FALSE")) );
               }
               if( (f = i + (iCOut == 's' ? HB_MAX(ulWidth, (s ? s : 6)) : HB_MAX(ulWidth, DK_BLKBUF))) > ulMaxBuf ){
                  ulMaxBuf += f + DK_INCBUF;   /* size of "FALSE" == 6 */
                  cBuffer = (char *)hb_xrealloc( cBuffer, ulMaxBuf );
               }
               s = SCItm( cBuffer, ulMaxBuf, cParFrm, iCOut, IsIndW, iIndWidth, IsIndP, iIndPrec, pItmPar );
               if( iCOut == 's' ) hb_itemRelease( pItmPar );

            }else if( iCOut == 's' ){
               char *cTrimStr, *cStr = hb_itemStr( pItmPar, NULL, NULL );

               if( cStr ){
                  f = strlen( cStr ); cTrimStr = hb_strLTrim( cStr, &f );
                  if( (f = i + HB_MAX(ulWidth, f)) > ulMaxBuf ){
                     ulMaxBuf += f + DK_INCBUF;
                     cBuffer = (char *)hb_xrealloc( cBuffer, ulMaxBuf );
                  }
                  hb_itemCopy( pItmCpy = hb_itemNew( NULL ), pItmPar );
                  hb_itemPutCL( pItmCpy, cTrimStr, f );
                  s = SCItm( cBuffer, ulMaxBuf, cParFrm, iCOut, IsIndW, iIndWidth, IsIndP, iIndPrec, pItmCpy );
                  hb_itemRelease( pItmCpy ); hb_xfree( cStr );
               }else{
                  iErrorPar = p + 2; break;
               }

            }else if( HB_IS_NUMERIC( pItmPar ) || HB_IS_POINTER( pItmPar ) ){
               if( (f = i + HB_MAX(ulWidth, DK_BLKBUF)) > ulMaxBuf ){
                  ulMaxBuf += f + DK_INCBUF;
                  cBuffer = (char *)hb_xrealloc( cBuffer, ulMaxBuf );
               }
               s = SCItm( cBuffer, ulMaxBuf, cParFrm, iCOut, IsIndW, iIndWidth, IsIndP, iIndPrec, pItmPar );

            }else{
               iErrorPar = p + 2; break;
            }
         }

         if( (f = s + ulResPos + sizeof(char)) > ulMaxRes ){
            ulMaxRes += f + DK_INCRES;
            cRes = (char *)hb_xrealloc( cRes, ulMaxRes );
         }
         hb_strncpy( cRes + ulResPos, cBuffer, s ); ulResPos += s;

         if( (ulParPos = c - cItmFrm) >= ulItmFrm ){
            break;   /* No more Par Format */
         }
      }
      if( cIntMod ) hb_xfree( cIntMod );
      hb_xfree( cParFrm ); hb_xfree( cBuffer );
      if( iErrorPar ){
         hb_xfree( cRes );
         if( iErrorPar > 1 ){
            hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, 2, hb_paramError( 1 ), hb_paramError( iErrorPar ) );
         }else{
            hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, 1, hb_paramError( 1 ) );
         }
      }else{
         hb_retclen_buffer( cRes, ulResPos );
      }
   }
}
spd.c180
strfmt.c
TypeFunctionSourceLine
HB_FUNCSTRFORMAT(void)
HB_FUNC( STRFORMAT )
{
   ULONG nParNum = hb_pcount();

   if( nParNum >= 1 )
   {
      char * pszMask = hb_parc( 1 );
      ULONG  nMaskLen = hb_parclen( 1 );
      ULONG  nMaskPos;
      ULONG  nPos;
   
      ULONG  nRetValLen;
      char * pszRetVal;
      char * pszRetValSave;

      STRPAR strpar[ HB_STRFORMAT_PARNUM_MAX_ ];

      memset( &strpar, 0, sizeof( strpar ) );

      nParNum--;

      if( nParNum > HB_STRFORMAT_PARNUM_MAX_ )
         nParNum = HB_STRFORMAT_PARNUM_MAX_;
      
      /* Calculate length of return value */
      nRetValLen = 0;
      for( nMaskPos = 0; nMaskPos < nMaskLen; nMaskPos++ )
      {
         if( pszMask[ nMaskPos ] == '%' )
         {
            nMaskPos++;
      
            if( pszMask[ nMaskPos ] == '%' )
               nRetValLen++;
            else if( pszMask[ nMaskPos ] >= '1' && pszMask[ nMaskPos ] <= ( int )( nParNum + '0' ) )
            {
               nPos = pszMask[ nMaskPos ] - '1';

               strpar[ nPos ].raw = hb_itemString( hb_param( POS_TO_PAR( nPos ), HB_IT_ANY ), &strpar[ nPos ].ulLen, &strpar[ nPos ].bFreeReq );

               /* AllTrim() */
               strpar[ nPos ].ulLen = hb_strRTrimLen( strpar[ nPos ].raw, strpar[ nPos ].ulLen, FALSE );
               strpar[ nPos ].buffer = hb_strLTrim( strpar[ nPos ].raw, &strpar[ nPos ].ulLen );

               nRetValLen += strpar[ nPos ].ulLen;
            }
         }
         else
            nRetValLen++;
      }
      
      /* Assemble return value */
      pszRetVal = pszRetValSave = ( char * ) hb_xgrab( nRetValLen + 1 );
      for( nMaskPos = 0; nMaskPos < nMaskLen; nMaskPos++ )
      {
         if( pszMask[ nMaskPos ] == '%' )
         {
            nMaskPos++;
      
            if( pszMask[ nMaskPos ] == '%' )
               *pszRetVal++ = pszMask[ nMaskPos ];
            else if( pszMask[ nMaskPos ] >= '1' && pszMask[ nMaskPos ] <= ( int ) ( nParNum + '0' ) )
            {
               nPos = pszMask[ nMaskPos ] - '1';
      
               memcpy( pszRetVal, strpar[ nPos ].buffer, strpar[ nPos ].ulLen );
               pszRetVal += strpar[ nPos ].ulLen;
            }
         }
         else
            *pszRetVal++ = pszMask[ nMaskPos ];
      }

      hb_retclen_buffer( pszRetValSave, nRetValLen );

      /* Free parameter buffers */ 
      for( nPos = 0; nPos < HB_STRFORMAT_PARNUM_MAX_; nPos++ )
      {
         if( strpar[ nPos ].raw && strpar[ nPos ].bFreeReq )
            hb_xfree( strpar[ nPos ].raw );
      }
   }
   else
      hb_retc_null();
}
strfmt.c70
stringsx.c
TypeFunctionSourceLine
STATIC CONST CHAR hb_strtoken(char *szText, long lText, long lIndex, char cDelimiter, long *lLen)
static const char *hb_strtoken(char *szText,
                               long lText,
                               long lIndex,
                               char cDelimiter,
                               long *lLen)
{
  long wStart;
  long wEnd = 0;
  long wCounter = 0;

  HB_TRACE(HB_TR_DEBUG, ("hb_strtoken(%s, %ld, %ld, %d, %p)", szText, lText, lIndex, (int) cDelimiter, lLen));
   
  do
    {
      wStart = wEnd;

      if( cDelimiter != ' ' )
        {
          if( szText[wStart] == cDelimiter )
            wStart++;
        }
      else
        {
          while( wStart < lText && szText[wStart] == cDelimiter )
            wStart++;
        }

      if( wStart < lText && szText[wStart] != cDelimiter )
        {
          wEnd = wStart + 1;

          while( wEnd < lText && szText[wEnd] != cDelimiter )
            wEnd++;
        }
      else
        wEnd = wStart;
    } while( wCounter++ < lIndex - 1 && wEnd < lText );

  if( wCounter < lIndex )
    {
      *lLen = 0;
      return "";
    }
  else
    {
      *lLen = wEnd - wStart;
      return szText + wStart;
    }
}
stringsx.c9
HB_FUNCSTRTOKEN(void)
HB_FUNC( STRTOKEN )
{
  const char *szText;
  long lIndex = hb_parnl(2);
  char cDelimiter = *hb_parc(3);
  long lLen;

  if( !cDelimiter )
    cDelimiter = ' ';

  szText = hb_strtoken(hb_parc(1), hb_parclen(1), lIndex, cDelimiter, &lLen);

  hb_stornl(lLen, 4);
  hb_retclen(szText, lLen);
}
stringsx.c59
HB_FUNCSTRDUMP(void)
HB_FUNC( STRDUMP )
{
  char *szText = hb_parc(1);
  long i, lLength = hb_parclen(1);
  for( i = 0; i < lLength; i++ )
    printf("%d ", szText[i]);
  printf("\n");
}
stringsx.c76
HB_FUNCROT13(void)
HB_FUNC( ROT13 )
{
  if( ISCHAR(1) )
    {
      char *szText = hb_parc( 1 );
      ULONG i, lLen = hb_parclen( 1 );
      char *szResult = (char*)hb_xgrab(lLen + 1);

      for( i = 0; i < lLen; i++ )
        {
          char c = szText[i];
          if( (c >= 'A' && c <= 'M') || (c >= 'a' && c <= 'm') )
            c += 13;
          else if( (c >= 'N' && c <= 'Z') || (c >= 'n' && c <= 'z') )
            c -= 13;

          szResult[i] = c;
        }
      hb_retclen(szResult, lLen);
      hb_xfree(szResult);
    }
  else
    hb_retc(NULL);
}
stringsx.c86
fileread.prg
TypeFunctionSourceLine
METHODNew( cFile, nSize )
   METHOD New( cFile, nSize )  // Create a new class instance
fileread.prg34
METHODOpen( nMode )
   METHOD Open( nMode )        // Open the file for reading
fileread.prg35
METHODClose()
   METHOD Close()              // Close the file when done
fileread.prg36
METHODReadLine()
   METHOD ReadLine()           // Read a line from the file
fileread.prg37
METHODName()
   METHOD Name()               // Retunrs the file name
fileread.prg38
METHODIsOpen()
   METHOD IsOpen()             // Returns .T. if file is open
fileread.prg39
METHODMoreToRead()
   METHOD MoreToRead()         // Returns .T. if more to be read
fileread.prg40
METHODError()
   METHOD Error()              // Returns .T. if error occurred
fileread.prg41
METHODErrorNo()
   METHOD ErrorNo()            // Returns current error code
fileread.prg42
METHODErrorMsg( cText )
   METHOD ErrorMsg( cText )    // Returns formatted error message

   PROTECTED:
fileread.prg43
METHODEOL_pos()
   METHOD EOL_pos()

END CLASS
fileread.prg47
TFILEREAD:METHODNew( cFile, nSize ) CLASS TFileRead
METHOD New( cFile, nSize ) CLASS TFileRead

   IF nSize == NIL .OR. nSize < 1
      // The readahead size can be set to as little as 1 byte, or as much as
      // 65535 bytes, but venturing out of bounds forces the default size.
      nSize := oF_DEFAULT_READ_SIZE
   ENDIF

   ::cFile     := cFile             // Save the file name
   ::nHan      := -1                // It's not open yet
   ::lEOF      := .T.               // So it must be at EOF
   ::nError    := 0                 // But there haven't been any errors
   ::nLastOp   := oF_CREATE_OBJECT  // Because we just created the class
   ::cBuffer   := ""                // and nothing has been read yet
   ::nReadSize := nSize             // But will be in this size chunks

   RETURN Self
fileread.prg51
TFILEREAD:METHODOpen( nMode ) CLASS TFileRead
METHOD Open( nMode ) CLASS TFileRead

   IF ::nHan == -1
      // Only open the file if it isn't already open.
      IF nMode == NIL
         nMode := FO_READ + FO_SHARED   // Default to shared read-only mode
      ENDIF
      ::nLastOp := oF_OPEN_FILE
      ::nHan := FOPEN( ::cFile, nMode )   // Try to open the file
      IF ::nHan == -1
         ::nError := FERROR()       // It didn't work
         ::lEOF   := .T.            // So force EOF
      ELSE
         ::nError := 0              // It worked
         ::lEOF   := .F.            // So clear EOF
      ENDIF
   ELSE
      // The file is already open, so rewind to the beginning.
      IF FSEEK( ::nHan, 0 ) == 0
         ::lEOF := .F.              // Definitely not at EOF
      ELSE
         ::nError := FERROR()       // Save error code if not at BOF
      ENDIF
      ::cBuffer := ""               // Clear the readahead buffer
   ENDIF

   RETURN Self
fileread.prg69
TFILEREAD:METHODReadLine() CLASS TFileRead
METHOD ReadLine() CLASS TFileRead
   LOCAL cLine := ""
   LOCAL nPos

   ::nLastOp := oF_READ_FILE

   IF ::nHan == -1
      ::nError := -1                // Set unknown error if file not open
   ELSE
      // Is there a whole line in the readahead buffer?
      nPos := ::EOL_pos()
      WHILE ( nPos <= 0 .OR. nPos > LEN( ::cBuffer ) - 3 ) .AND. !::lEOF
         // Either no or maybe, but there is possibly more to be read.
         // Maybe means that we found either a CR or an LF, but we don't
         // have enough characters to discriminate between the three types
         // of end of line conditions that the class recognizes (see below).
         cLine := FREADSTR( ::nHan, ::nReadSize )
         IF EMPTY( cLine )
            // There was nothing more to be read. Why? (Error or EOF.)
            ::nError := FERROR()
            IF ::nError == 0
               // Because the file is at EOF.
               ::lEOF := .T.
            ENDIF
         ELSE
            // Add what was read to the readahead buffer.
            ::cBuffer += cLine
            cLine := ""
         ENDIF
         // Is there a whole line in the readahead buffer yet?
         nPos := ::EOL_pos()
      END WHILE
      // Is there a whole line in the readahead buffer?
      IF nPos <= 0
         // No, which means that there is nothing left in the file either, so
         // return the entire buffer contents as the last line in the file.
         cLine := ::cBuffer
         ::cBuffer := ""
      ELSE
         // Yes. Is there anything in the line?
         IF nPos > 1
            // Yes, so return the contents.
            cLine := LEFT( ::cBuffer, nPos - 1 )
         ELSE
            // No, so return an empty string.
            cLine := ""
         ENDIF
         // Deal with multiple possible end of line conditions.
         DO CASE
            CASE SUBSTR( ::cBuffer, nPos, 3 ) == CHR( 13 ) + CHR( 13 ) + CHR( 10 )
               // It's a messed up DOS newline (such as that created by a program
               // that uses "\r\n" as newline when writing to a text mode file,
               // which causes the '\n' to expand to "\r\n", giving "\r\r\n").
               nPos += 3
            CASE SUBSTR( ::cBuffer, nPos, 2 ) == CHR( 13 ) + CHR( 10 )
               // It's a standard DOS newline
               nPos += 2
            OTHERWISE
               // It's probably a Mac or Unix newline
               nPos++
         ENDCASE
         ::cBuffer := SUBSTR( ::cBuffer, nPos )
      ENDIF
   ENDIF

   RETURN cLine
fileread.prg97
TFILEREAD:METHODEOL_pos() CLASS TFileRead
METHOD EOL_pos() CLASS TFileRead
   LOCAL nCRpos, nLFpos, nPos

   // Look for both CR and LF in the file read buffer.
   nCRpos := AT( CHR( 13 ), ::cBuffer )
   nLFpos := AT( CHR( 10 ), ::cBuffer )
   DO CASE
      CASE nCRpos == 0
         // If there's no CR, use the LF position.
         nPos := nLFpos
      CASE nLFpos == 0
         // If there's no LF, use the CR position.
         nPos := nCRpos
      OTHERWISE
         // If there's both a CR and an LF, use the position of the first one.
         nPos := MIN( nCRpos, nLFpos )
   ENDCASE

   RETURN nPos
fileread.prg164
TFILEREAD:METHODClose() CLASS TFileRead
METHOD Close() CLASS TFileRead

   ::nLastOp := oF_CLOSE_FILE
   ::lEOF := .T.
   // Is the file already closed.
   IF ::nHan == -1
      // Yes, so indicate an unknown error.
      ::nError := -1
   ELSE
      // No, so close it already!
      FCLOSE( ::nHan )
      ::nError := FERROR()
      ::nHan   := -1                // The file is no longer open
      ::lEOF   := .T.               // So force an EOF condition
   ENDIF

   RETURN Self
fileread.prg184
TFILEREAD:METHODName() CLASS TFileRead
METHOD Name() CLASS TFileRead
   // Returns the filename associated with this class instance.
   RETURN ::cFile
fileread.prg202
TFILEREAD:METHODIsOpen() CLASS TFileRead
METHOD IsOpen() CLASS TFileRead
   // Returns .T. if the file is open.
   RETURN ::nHan != -1
fileread.prg206
TFILEREAD:METHODMoreToRead() CLASS TFileRead
METHOD MoreToRead() CLASS TFileRead
   // Returns .T. if there is more to be read from either the file or the
   // readahead buffer. Only when both are exhausted is there no more to read.
   RETURN !::lEOF .OR. !EMPTY( ::cBuffer )
fileread.prg210
TFILEREAD:METHODError() CLASS TFileRead
METHOD Error() CLASS TFileRead
   // Returns .T. if an error was recorded.
   RETURN ::nError != 0
fileread.prg215
TFILEREAD:METHODErrorNo() CLASS TFileRead
METHOD ErrorNo() CLASS TFileRead
   // Returns the last error code that was recorded.
   RETURN ::nError
fileread.prg219
TFILEREAD:METHODErrorMsg( cText ) CLASS TFileRead
METHOD ErrorMsg( cText ) CLASS TFileRead
   STATIC s_cAction := {"on", "creating object for", "opening", "reading from", "closing"}

   LOCAL cMessage, nTemp

   // Has an error been recorded?
   IF ::nError == 0
      // No, so report that.
      cMessage := "No errors have been recorded for " + ::cFile
   ELSE
      // Yes, so format a nice error message, while avoiding a bounds error.
      IF ::nLastOp < oF_ERROR_MIN .OR. ::nLastOp > oF_ERROR_MAX
         nTemp := 1
      ELSE
         nTemp := ::nLastOp + 1
      ENDIF
      cMessage := iif( EMPTY( cText ), "", cText ) + "Error " + ALLTRIM( STR( ::nError ) ) + " " + s_cAction[ nTemp ] + " " + ::cFile
   ENDIF

   RETURN cMessage
fileread.prg223
nconvert.prg
TypeFunctionSourceLine
FUNCTIONIsBin(cString)
FUNCTION IsBin(cString)
   local nX,lFlag:=.t.
   cString:=AllTrim(cString)
   FOR nX:=1 to Len(cString)
      IF !(SubStr(cString,nX,1) $"01")
         lFlag:=.F.
         EXIT
      ENDIF
   NEXT nX
   RETURN(lFlag)
nconvert.prg53
FUNCTIONIsOctal(cString)
FUNCTION IsOctal(cString)
   local nX,lFlag:=.t.
   cString:=AllTrim(cString)
   FOR nX:=1 to Len(cString)
      if !(SubStr(cString,nX,1) $"01234567")
         lFlag:=.f.
         EXIT
      ENDIF
   NEXT nX
   RETURN(lFlag)
nconvert.prg64
FUNCTIONIsDec(cString)
FUNCTION IsDec(cString)
   local nX,lFlag:=.t.
   cString:=AllTrim(cString)
   FOR nX:=1 to Len(cString)
      if !(SubStr(cString,nX,1) $"0123456789")
         lFlag:=.f.
         EXIT
      ENDIF
   NEXT nX
   RETURN(lFlag)
nconvert.prg75
FUNCTIONIsHexa(cString)
FUNCTION IsHexa(cString)
   local nX,lFlag:=.t.
   cString:=AllTrim(cString)
   FOR nX:=1 to Len(cString)
      if !(SubStr(cString,nX,1) $"0123456789ABCDEF")
         lFlag:=.f.
         EXIT
      ENDIF
   NEXT nX
   RETURN(lFlag)
nconvert.prg86
FUNCTIONDecToBin(nNumber)
FUNCTION DecToBin(nNumber)
   local cNewString:=''
   local nTemp:=0
   WHILE(nNumber > 0)
      nTemp:=(nNumber%2)
      cNewString:=SubStr('01',(nTemp+1),1)+cNewString
      nNumber:=Int((nNumber-nTemp)/2)
   ENDDO
   RETURN(cNewString)
nconvert.prg97
FUNCTIONDecToOctal(nNumber)
FUNCTION DecToOctal(nNumber)
   local cNewString:=''
   local nTemp:=0
   WHILE(nNumber > 0)
      nTemp:=(nNumber%8)
      cNewString:=SubStr('01234567',(nTemp+1),1)+cNewString
      nNumber:=Int((nNumber-nTemp)/8)
   ENDDO
   RETURN(cNewString)
nconvert.prg107
FUNCTIONDecToHexa(nNumber)
FUNCTION DecToHexa(nNumber)
   local cNewString:=''
   local nTemp:=0
   WHILE(nNumber > 0)
      nTemp:=(nNumber%16)
      cNewString:=SubStr('0123456789ABCDEF',(nTemp+1),1)+cNewString
      nNumber:=Int((nNumber-nTemp)/16)
   ENDDO
   RETURN(cNewString)
nconvert.prg117
FUNCTIONBinToDec(cString)
FUNCTION BinToDec(cString)
   local nNumber:=0,nX:=0
   local cNewString:=AllTrim(cString)
   local nLen:=Len(cNewString)
   FOR nX:=1 to nLen
      nNumber+=(At(SubStr(cNewString,nX,1),'01')-1)*;
        (2**(nLen-nX))
   NEXT nX
   RETURN(nNumber)
nconvert.prg127
FUNCTIONOctalToDec(cString)
FUNCTION OctalToDec(cString)
   local nNumber:=0,nX:=0
   local cNewString:=AllTrim(cString)
   local nLen:=Len(cNewString)
   FOR nX:=1 to nLen
      nNumber+=(At(SubStr(cNewString,nX,1),'01234567')-1)*;
         (8**(nLen-nX))
   NEXT nX
   RETURN(nNumber)
nconvert.prg137
FUNCTIONHexaToDec(cString)
FUNCTION HexaToDec(cString)
   local nNumber:=0,nX:=0
   local cNewString:=AllTrim(cString)
   local nLen:=Len(cNewString)
   FOR nX:=1 to nLen
      nNumber+=(At(SubStr(cNewString,nX,1),'0123456789ABCDEF')-1)*;
         (16**(nLen-nX))
   NEXT nX
   RETURN nNumber
nconvert.prg147
numtxten.prg
TypeFunctionSourceLine
FUNCTIONNumToTxtEN( nValue )
FUNCTION NumToTxtEN( nValue )
   LOCAL cRetVal := ""

   IF nValue == 0
      RETURN "zero"
   ENDIF

   IF nValue < 0
      nValue := -nValue
      cRetVal += "minus "
   ENDIF

   IF nValue >= 1000000
      IF nValue >= 100000000
         cRetVal += int_to_string( Int( nValue / 100000000 ) ) + " hundred "
         nValue -= 100000000 * Int( nValue / 100000000 )
      ENDIF
      IF nValue >= 1000000
         cRetVal += int_to_string( Int( nValue / 1000000 ) ) + " "
         nValue -= 1000000 * Int( nValue / 1000000 )
      ENDIF
      cRetVal += "million "
   ENDIF
   IF nValue >= 1000
      IF nValue >= 100000
         cRetVal += int_to_string( Int( nValue / 100000 ) ) + " hundred "
         nValue -= 100000 * Int( nValue / 100000 )
      ENDIF
      IF nValue >= 1000
         cRetVal += int_to_string( Int( nValue / 1000 ) ) + " "
         nValue -= 1000 * Int( nValue / 1000 )
      ENDIF
      cRetVal += "thousand "
   ENDIF
   IF nValue >= 100
      cRetVal += int_to_string( Int( nValue / 100 ) ) + " hundred "
      nValue -= 100 * Int( nValue / 100 )
   ENDIF
   IF nValue >= 1
      cRetVal += int_to_string( Int( nValue ) )
      nValue -= Int( nValue )
   ENDIF

   RETURN RTrim( cRetVal )
numtxten.prg10
STATIC FUNCTIONint_to_string( nValue )
STATIC FUNCTION int_to_string( nValue )
   LOCAL cRetVal
   LOCAL aArray1 := {;
        "one"        ,;
        "two"        ,;
        "three"      ,;
        "four"       ,;
        "five"       ,;
        "six"        ,;
        "seven"      ,;
        "eight"      ,;
        "nine"       ,;
        "ten"        ,;
        "eleven"     ,;
        "twelve"     ,;
        "thirteen"   ,;
        "fourteen"   ,;
        "fifteen"    ,;
        "sixteen"    ,;
        "seventeen"  ,;
        "eighteen"   ,;
        "nineteen"   }

   LOCAL aArray2 := {;
        "ten"        ,;
        "twenty"     ,;
        "thirty"     ,;
        "forty"      ,;
        "fifty"      ,;
        "sixty"      ,;
        "seventy"    ,;
        "eighty"     ,;
        "ninety"     }

   IF nValue < 20
      cRetVal := aArray1[ nValue ]
   ELSE
      cRetVal := aArray2[ Int( nValue / 10 ) ]
      nValue -= 10 * Int( nValue / 10 )
      IF Int( nValue ) >= 1
         cRetVal += " " + aArray1[ Int( nValue ) ]
      ENDIF
   ENDIF

   RETURN cRetVal
numtxten.prg55
numtxthu.prg
TypeFunctionSourceLine
FUNCTIONNumToTxtHU( nValue )
FUNCTION NumToTxtHU( nValue )
   LOCAL aTort := { "tized", "sz zad", "ezred", "t¡zezred", "sz zezred", "milliomod", "milli rdod" }
   LOCAL cRetVal
   LOCAL tmp, tmp1, tmp2

   IF nValue < 0
      nValue := -nValue
      cRetVal := "m¡nusz "
   ELSE
      cRetVal := ""
   ENDIF

   IF Int( nValue ) == 0
      cRetVal += "nulla"
   ENDIF

   cRetVal += NumToTxtRaw( tmp := Int( nValue ) )

   IF ( tmp := ( nValue - tmp ) ) > 0 .AND. tmp < 1

      tmp1 := Len( tmp2 := SubStr( Str( tmp, 8, 6 ), 3 ) )

      WHILE SubStr( tmp2, tmp1, 1 ) == "0" .AND. tmp1 > 0
         tmp1--
      ENDDO

      cRetVal += " eg‚sz " + NumToTxtRaw( tmp * ( 10 ^ tmp1 ) ) + iif( tmp1 >= 1 .AND. tmp1 <= Len( aTort ), " " + aTort[ tmp1 ], "" )
   ENDIF

   RETURN cRetVal
numtxthu.prg53
STATIC FUNCTIONNumToTxtRaw( nValue )
STATIC FUNCTION NumToTxtRaw( nValue )
   LOCAL aEgesz  := { "", "ezer" , "milli¢", "milli rd", "billi¢" , "trilli¢", "kvadrilli¢", "kvintilli¢" } // , "szextilli¢", "szeptilli¢", "oktilli¢", "nontilli¢" }
   LOCAL aEgyes  := { "", "egy"  , "kett‹" , "h rom"   , "n‚gy"   , "”t"     , "hat"       , "h‚t"       , "nyolc"     , "kilenc" }
   LOCAL aTizes1 := { "", "t¡z"  , "h£sz"  , "harminc" , "negyven", "”tven"  , "hatvan"    , "hetven"    , "nyolcvan"  , "kilencven" }
   LOCAL aTizes2 := { "", "tizen", "huszon", "harminc" , "negyven", "”tven"  , "hatvan"    , "hetven"    , "nyolcvan"  , "kilencven" }

   LOCAL aDigit
   LOCAL nLen
   LOCAL cValue
   LOCAL tmp

   cValue := LTrim( Str( nValue, 20, 0 ) )
   cValue := PadL( cValue, ( Int( Max( Len( cValue ) - 1, 0 ) / 3 ) + 1 ) * 3, "0" )

   aDigit := Array( nLen := Len( cValue ) )
   FOR tmp := 1 TO nLen
      aDigit[ tmp ] := Val( SubStr( cValue, tmp, 1 ) )
   NEXT

   cValue := ""
   FOR tmp := 1 TO nLen - 2 STEP 3

      IF aDigit[ tmp     ] != 0 .OR. ;
         aDigit[ tmp + 1 ] != 0 .OR. ;
         aDigit[ tmp + 2 ] != 0

         cValue += iif( Empty( cValue ), "", "-") +;
                   iif( aDigit[ tmp ] != 0, aEgyes[ aDigit[ tmp ] + 1 ] + "sz z", "" ) +;
                   iif( aDigit[ tmp + 2 ] == 0, aTizes1[ aDigit[ tmp + 1 ] + 1 ], aTizes2[ aDigit[ tmp + 1 ] + 1 ] ) +;
                   aEgyes[ aDigit[ tmp + 2 ] + 1 ] +;
                   aEgesz[ ( Int( ( nLen - tmp ) / 3 ) ) + 1 ]
      ENDIF
   NEXT

   RETURN cValue
numtxthu.prg84
stringp.prg
TypeFunctionSourceLine
FUNCTIONDefault( xArg, xDef )
function Default( xArg, xDef )
return iif( ValType(xArg) != ValType(xDef), xDef, xArg )
stringp.prg59
FUNCTIONToChar( xTxt, cSeparator, lDebug )
function ToChar( xTxt, cSeparator, lDebug )

   local cValTxt
   local cOut
   local n
   local nLen
   local aData

   cSeparator := Default( cSeparator, " " )
   lDebug     := Default( lDebug,     .F. )
   cValTxt    := ValType( xTxt )

   do case
      case cValTxt=="C" .or. cValTxt=="M"       // Character
         cOut := iif( lDebug, '"'+xTxt+'"', xTxt )

      case cValTxt=="N"                         // Numeric
         cOut := Alltrim(Str(xTxt))

      case cValTxt=="U"                         // Nothing to write
         cOut := iif( lDebug, "NIL", "" )

      case cValTxt=="D"                         // Date
         cOut := TransForm(xTxt, "")

      case cValTxt=="L"                         // Logical
         if lDebug
            cOut := iif( xTxt, ".T.", ".F." )
         else
            cOut := iif( xTxt, "True", "False" )
         endif

      case cValTxt=="A"                         // Array
         if lDebug
            cOut := "{"
         else
            cOut := ""
         endif
         nLen := Len( xTxt )
         for n := 1 to nLen                     // For each item : Recurse !
            cOut += ToChar( xTxt[n], cSeparator, lDebug )
            if n != nLen
               cOut += cSeparator
            endif
         next n
         if lDebug
            cOut += "}"
         endif

      case cValTxt=="B"                         // Codeblock
         if lDebug
            cOut := "Block"
         else
            cOut := Eval( xTxt )
         endif

      case cValTxt=="O"                         // Object
         if lDebug
            cOut  := xTxt:ClassName() + "(#" + ToChar( xTxt:ClassH() ) + "):{"
            aData := __objGetValueList( xTxt )
            nLen  := Len( aData )
            for n := 1 to nLen                     // For each item : Recurse !
               cOut += aData[n][HB_OO_DATA_SYMBOL] + ":" + ;
                       ToChar( aData[n][HB_OO_DATA_VALUE], cSeparator, lDebug )
               if n != nLen
                  cOut += cSeparator
               endif
            next n
            cOut += "}"
         else
            cOut := ToChar( xTxt:Run(), cSeparator, lDebug )
         endif

   endcase

return cOut
stringp.prg85
FUNCTIONDebug( xItem )
function Debug( xItem )

   QOut( ToChar( xItem, ", ", .T. ) )

return xItem
stringp.prg168
twirler.prg
TypeFunctionSourceLine
CLASSTwirler
class Twirler
   var n_Row
   var n_Col
   var n_Index
   var n_Seconds
   var n_Smooth
   var c_Chars
   var c_Title
   method new( nRow, nCol, cTitle, cChars )
   method twirl()
   method show()
   method hide()
end class
twirler.prg13
TWIRLER:METHODnew( nRow, nCol, cTitle, cChars, nSmooth ) class Twirler
method new( nRow, nCol, cTitle, cChars, nSmooth ) class Twirler
   ::n_Row := nRow
   ::n_Col := nCol
   ::n_Smooth := nSmooth
   ::c_Chars := iif( EMPTY( cChars ), "|/-\", cChars )
   ::c_Title := cTitle
   IF EMPTY( ::c_Title )
      ::c_Title := ""
   END IF
   ::n_Col += LEN( ::c_Title )
return Self
twirler.prg27
TWIRLER:METHODtwirl() class Twirler
method twirl() class Twirler
local nSeconds := SECONDS()
   IF EMPTY( ::n_Seconds ) .OR. nSeconds - ::n_Seconds >= ::n_Smooth .OR. nSeconds < ::n_Seconds
      @ ::n_Row, ::n_Col SAY SUBSTR( ::c_Chars, ::n_Index, 1 )
      ::n_Index++
      if ::n_Index > LEN( ::c_Chars )
         ::n_Index := 1
      end if
      IF !EMPTY( ::n_Seconds )
         ::n_Seconds := nSeconds
      END IF
   END IF
return Self
twirler.prg39
TWIRLER:METHODshow() class Twirler
method show() class Twirler
   ::n_Index := 1
   IF ! EMPTY( ::n_Smooth )
      ::n_Seconds := -::n_Smooth
   END IF
   @ ::n_Row, ::n_Col - LEN( ::c_Title ) SAY ::c_Title
return Self
twirler.prg53
TWIRLER:METHODhide() class Twirler
method hide() class Twirler
   @ ::n_Row, ::n_Col - LEN( ::c_Title ) SAY SPACE( LEN( ::c_Title ) + 1 )
return Self
twirler.prg61

Page url: http://www.yourdomain.com/help/index.html?hbmisc.htm