示例#1
0
/* -------------------------- */
char *ct_at_exact_forward (char *pcString, size_t sStrLen,
                           char *pcMatch, size_t sMatchLen,
                           size_t *psMatchStrLen)
{

  size_t sPos;
  
  HB_TRACE(HB_TR_DEBUG, ("ct_at_exact_forward (\"%s\", %u, \"%s\", %u, %p)",
                          pcString, sStrLen, pcMatch, sMatchLen, psMatchStrLen));
  
  if ((sMatchLen == 0) || (sStrLen < sMatchLen))
    return (NULL);

  sPos = hb_strAt (pcMatch, sMatchLen, pcString, sStrLen);
  if (sPos == 0)
  {
    return (NULL);
  }
  else
  {
    if (psMatchStrLen != NULL)
      *psMatchStrLen = sMatchLen;
    return (pcString+sPos-1);
  }

}
示例#2
0
文件: sdf1.c 项目: AmericoBalboa/core
static HB_ERRCODE hb_sdfReadRecord( SDFAREAP pArea )
{
   HB_USHORT uiRead, uiToRead, uiEolPos;

   HB_TRACE( HB_TR_DEBUG, ( "hb_sdfReadRecord(%p)", pArea ) );

   uiToRead = pArea->uiRecordLen + pArea->uiEolLen + 2;
   uiRead = ( HB_USHORT ) hb_fileReadAt( pArea->pFile, pArea->pRecord, uiToRead,
                                         pArea->nRecordOffset );
   if( uiRead > 0 && uiRead < uiToRead && pArea->pRecord[ uiRead - 1 ] == '\032' )
      --uiRead;

   if( uiRead == 0 )
   {
      pArea->area.fEof = HB_TRUE;
      pArea->fPositioned = HB_FALSE;
      hb_sdfClearRecordBuffer( pArea );
   }
   else
   {
      pArea->area.fEof = HB_FALSE;
      pArea->fPositioned = HB_TRUE;
      uiEolPos = ( HB_USHORT ) hb_strAt( pArea->szEol, pArea->uiEolLen,
                                         ( const char * ) pArea->pRecord,
                                         uiRead );
      if( uiEolPos )
      {
         --uiEolPos;
         if( uiRead < uiToRead && uiRead == uiEolPos + pArea->uiEolLen )
            pArea->nNextOffset = ( HB_FOFFSET ) -1;
         else
            pArea->nNextOffset = pArea->nRecordOffset + uiEolPos + pArea->uiEolLen;

         if( uiEolPos < pArea->uiRecordLen )
            memset( pArea->pRecord + uiEolPos, ' ', pArea->uiRecordLen - uiEolPos );
      }
      else
      {
         if( uiRead < uiToRead )
            pArea->nNextOffset = ( HB_FOFFSET ) -1;
         else
            pArea->nNextOffset = 0;

         if( uiRead < pArea->uiRecordLen )
            memset( pArea->pRecord + uiRead, ' ', pArea->uiRecordLen - uiRead );
      }

      if( uiEolPos != pArea->uiRecordLen )
         memcpy( pArea->pRecord + pArea->uiRecordLen,
                 pArea->szEol, pArea->uiEolLen );
   }

   return HB_SUCCESS;
}
示例#3
0
文件: sdf1.c 项目: AmericoBalboa/core
static HB_ERRCODE hb_sdfNextRecord( SDFAREAP pArea )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_sdfNextRecord(%p)", pArea ) );

   if( ! pArea->fPositioned )
      pArea->nNextOffset = ( HB_FOFFSET ) -1;
   else
   {
      if( pArea->nNextOffset == 0 )
      {
         HB_USHORT uiRead, uiToRead, uiEolPos, uiRest = 0;
         HB_FOFFSET ulOffset = pArea->nRecordOffset;

         uiToRead = pArea->uiRecordLen + pArea->uiEolLen + 2;

         do
         {
            uiRead = ( HB_USHORT ) hb_fileReadAt( pArea->pFile, pArea->pRecord + uiRest,
                                                  uiToRead - uiRest, ulOffset + uiRest ) + uiRest;
            if( uiRead > 0 && uiRead < uiToRead &&
                pArea->pRecord[ uiRead - 1 ] == '\032' )
               --uiRead;

            uiEolPos = ( HB_USHORT ) hb_strAt( pArea->szEol, pArea->uiEolLen,
                                               ( const char * ) pArea->pRecord,
                                               uiRead );
            if( uiEolPos )
            {
               --uiEolPos;
               if( uiRead < uiToRead && uiRead == uiEolPos + pArea->uiEolLen )
                  pArea->nNextOffset = ( HB_FOFFSET ) -1;
               else
                  pArea->nNextOffset = ulOffset + uiEolPos + pArea->uiEolLen;
            }
            else if( uiRead < uiToRead )
            {
               pArea->nNextOffset = ( HB_FOFFSET ) -1;
            }
            else
            {
               if( pArea->uiEolLen > 1 )
               {
                  uiRest = pArea->uiEolLen - 1;
                  memcpy( pArea->pRecord, pArea->pRecord + uiRead - uiRest, uiRest );
               }
               ulOffset += uiRead - uiRest;
            }
         }
         while( pArea->nNextOffset == 0 );
      }
      pArea->ulRecNo++;
   }

   if( pArea->nNextOffset == ( HB_FOFFSET ) -1 )
   {
      pArea->area.fEof = HB_TRUE;
      pArea->fPositioned = HB_FALSE;
      hb_sdfClearRecordBuffer( pArea );
      return HB_SUCCESS;
   }

   pArea->nRecordOffset = pArea->nNextOffset;
   return hb_sdfReadRecord( pArea );
}
示例#4
0
文件: pp.c 项目: laszlojuhasz/hbtest1
static void OutTable( DEFINES * endDefine, COMMANDS * endCommand )
{
  FILE *handl_o;
  int ipos, len_mpatt = 0, len_value;
  int num;
  DEFINES * stdef1 = hb_pp_topDefine, * stdef2 = NULL, * stdef3;
  COMMANDS * stcmd1 = hb_pp_topCommand, * stcmd2 = NULL, * stcmd3;

  HB_TRACE(HB_TR_DEBUG, ("OutTable(%p, %p)", endDefine, endCommand));

  while( stdef1 != endDefine )
    {
      stdef3 = stdef1->last;
      stdef1->last = stdef2;
      stdef2 = stdef1;
      stdef1 = stdef3;
    }
  while( stcmd1 != endCommand )
    {
      stcmd3 = stcmd1->last;
      stcmd1->last = stcmd2;
      stcmd2 = stcmd1;
      stcmd1 = stcmd3;
    }

  if( ( handl_o = fopen( "hbpp.out", "wt" ) ) == NULL )
    {
      printf( "\nCan't open hbpp.out\n" );
      return;
    }

  num = 1;
  while( stdef2 != NULL )
    {
      fprintf( handl_o, "\n   static DEFINES sD___%i = ", num );
      fprintf( handl_o, "{\"%s\",", stdef2->name );
      if( stdef2->pars )
        fprintf( handl_o, "\"%s\",", stdef2->pars );
      else
        fprintf( handl_o, "NULL," );
      fprintf( handl_o, "%d,", stdef2->npars );
      if( stdef2->value )
        fprintf( handl_o, "\"%s\"", stdef2->value );
      else
        fprintf( handl_o, "NULL" );
      if( num == 1 )
        fprintf( handl_o, ", NULL };" );
      else
        fprintf( handl_o, ", &sD___%i };", num - 1 );
      stdef2 = stdef2->last;
      num++;
    }
  fprintf( handl_o, "\n   DEFINES * hb_pp_topDefine = " );
  if( num == 1 )
    fprintf( handl_o, "NULL;" );
  else
    fprintf( handl_o, " = &sD___%i;\n", num - 1 );

  num = 1;
  while( stcmd2 != NULL )
    {
      fprintf( handl_o, "\n   static COMMANDS sC___%i = ", num );
      fprintf( handl_o, "{%d,\"%s\",", stcmd2->com_or_xcom, stcmd2->name );
      if( stcmd2->mpatt != NULL )
        {
          len_mpatt = hb_pp_strocpy( s_szLine, stcmd2->mpatt );
          while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_mpatt ) ) > 0 )
            {
              hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_mpatt );
              len_mpatt++;
            }
          fprintf( handl_o, "\"%s\",", s_szLine );
        }
      else
        fprintf( handl_o, "NULL," );
      if( stcmd2->value != NULL )
        {
          len_value = hb_pp_strocpy( s_szLine, stcmd2->value );
          while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_value ) ) > 0 )
            {
              hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_value );
              len_value++;
            }
          if( len_mpatt + len_value > 80 )
            fprintf( handl_o, "\n       " );
          fprintf( handl_o, "\"%s\"", s_szLine );
        }
      else fprintf( handl_o, "NULL" );
      if( num == 1 )
        fprintf( handl_o, ",NULL };" );
      else
        fprintf( handl_o, ",&sC___%i };", num - 1 );
      stcmd2 = stcmd2->last;
      num++;
    }
  fprintf( handl_o, "\n   COMMANDS * hb_pp_topCommand = " );
  if( num == 1 )
    fprintf( handl_o, "NULL;" );
  else
    fprintf( handl_o, " = &sC___%i;\n", num - 1 );

  stcmd1 = hb_pp_topTranslate;
  stcmd2 = NULL;
  while( stcmd1 != NULL )
    {
      stcmd3 = stcmd1->last;
      stcmd1->last = stcmd2;
      stcmd2 = stcmd1;
      stcmd1 = stcmd3;
    }
  num = 1;
  while( stcmd2 != NULL )
    {
      fprintf( handl_o, "\n   static COMMANDS sC___%i = ", num );
      fprintf( handl_o, "{%d,\"%s\",", stcmd2->com_or_xcom, stcmd2->name );
      if( stcmd2->mpatt != NULL )
        {
          len_mpatt = hb_pp_strocpy( s_szLine, stcmd2->mpatt );
          while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_mpatt ) ) > 0 )
            {
              hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_mpatt );
              len_mpatt++;
            }
          fprintf( handl_o, "\"%s\",", s_szLine );
        }
      else
        fprintf( handl_o, "NULL," );
      if( stcmd2->value != NULL )
        {
          len_value = hb_pp_strocpy( s_szLine, stcmd2->value );
          while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_value ) ) > 0 )
            {
              hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_value );
              len_value++;
            }
          if( len_mpatt + len_value > 80 )
            fprintf( handl_o, "\n       " );
          fprintf( handl_o, "\"%s\"", s_szLine );
        }
      else fprintf( handl_o, "NULL" );
      if( num == 1 )
        fprintf( handl_o, ",NULL };" );
      else
        fprintf( handl_o, ",&sC___%i };", num - 1 );
      stcmd2 = stcmd2->last;
      num++;
    }
  fprintf( handl_o, "\n   COMMANDS * hb_pp_topTranslate = " );
  if( num == 1 )
    fprintf( handl_o, "NULL;" );
  else
    fprintf( handl_o, " = &sT___%i;", num );

  fclose( handl_o );
}