Exemplo n.º 1
0
TA_RetCode TA_FileSeqClose( TA_FileHandle *handle )
{
   TA_PROLOG
   TA_RetCode retCode;
   TA_FileHandlePriv *fileHandlePriv;
   TA_SystemGlobal *global;
   #if defined( USE_WIN32_API )
   DWORD win32Error;
   BOOL retValue;
   #endif

   TA_TRACE_BEGIN(  TA_FileSeqClose );

   retCode = TA_GetGlobal(  &TA_SystemGlobalControl, (void **)&global );
   if( retCode != TA_SUCCESS )
   {
      TA_TRACE_RETURN( retCode );
   }

   TA_ASSERT( handle != NULL );

   fileHandlePriv = (TA_FileHandlePriv *)handle;

   if( fileHandlePriv )
   {
      #if defined( USE_WIN32_API )
         if( fileHandlePriv->handle != INVALID_HANDLE_VALUE )
         {
            retValue = CloseHandle( fileHandlePriv->handle );
            if( retValue == 0 )
            {
               win32Error = GetLastError();
               global->lastError = win32Error;
               TA_FATAL(  NULL, 0, win32Error );
            }
         }
         if( fileHandlePriv->allocBuffer )
         {
            freeDiskBuffer( fileHandlePriv->allocBuffer,
                            fileHandlePriv->allocBufferSize );
         }
      #endif

      #if defined( USE_OSLAYER )
         if( fileHandlePriv->handle != NULL )
            fclose( fileHandlePriv->handle );
         if( fileHandlePriv->allocBuffer )
            TA_Free(  fileHandlePriv->allocBuffer );
      #endif

      if( fileHandlePriv->streamAccess )
      {
         TA_StreamAccessFree( fileHandlePriv->streamAccess );
      }

      TA_Free(  fileHandlePriv );
   }

   TA_TRACE_RETURN( TA_SUCCESS );
}
Exemplo n.º 2
0
/**** Local functions definitions.     ****/
static TA_RetCode doAdjustments( TA_DecodingParam *localDecodingParam,
                                 TA_String *yahooName,
                                 TA_PrivateYahooHandle *yahooHandle,
                                 const char *overideServerAddr,
                                 TA_ParamForAddData  *paramForAddData )
{
   TA_RetCode retCode;
   TA_WebPage *webPage;
   TA_Stream *stream;
   TA_StreamAccess *streamAccess;
   TA_AdjustDataParse adjustDataParse;

   adjustDataParse.paramForAddData = paramForAddData;
   adjustDataParse.yahooHandle = yahooHandle;

   /* Get the split/value adjustments from the Yahoo! web site */
   retCode = TA_WebPageAllocFromYahooName( localDecodingParam,
                                           TA_StringToChar(yahooName),
                                           overideServerAddr,
                                           &webPage, paramForAddData );

   if( retCode != TA_SUCCESS )
      return retCode;

   /* Parse the dividend/split information */
   stream = webPage->content;  
   streamAccess = TA_StreamAccessAlloc( stream );

   if( !streamAccess )
   {
      TA_WebPageFree( webPage );
      return TA_ALLOC_ERR;
   }

   retCode = TA_StreamAccessSearch( streamAccess, "Monthly" );
   if( retCode == TA_SUCCESS )
   {
      retCode = TA_StreamAccessSearch( streamAccess, "Last" );
      if( retCode == TA_SUCCESS )
      {
          /* Find the table of data. */
          retCode = TA_StreamAccessSearch( streamAccess, "yfnc_datamodoutline1" );;
          if( retCode == TA_SUCCESS )
          {
             retCode = TA_StreamAccessGetHTMLTable( streamAccess,
                                                    200,
                                                    processAdjustmentTable,
                                                    &adjustDataParse );
          }
      }
   }

   TA_StreamAccessFree( streamAccess );
   TA_WebPageFree( webPage );

   return retCode;   
}
Exemplo n.º 3
0
static unsigned int nbCommaField( TA_Stream *csvFile )
{
   TA_RetCode retCode;
   TA_StreamAccess *streamAccess;
   unsigned int nbComma;
   unsigned char data;

   streamAccess = TA_StreamAccessAlloc( csvFile );
   if( !streamAccess )
      return 0;

   nbComma = 0;

#ifdef WIN32
#pragma warning( disable : 4127 ) /* Disable 'conditional expression is constant' */
#endif
   while(1)
   {
      retCode = TA_StreamAccessGetByte( streamAccess, &data );
      if( retCode != TA_SUCCESS )
      {
         TA_StreamAccessFree( streamAccess );
         return 0;
      }
      if( data == ',' )
         nbComma++;
      else if( data == '\n' )
      {
         TA_StreamAccessFree( streamAccess );
         return nbComma + 1;
      }
   }
#ifdef WIN32
#pragma warning( default : 4127 ) /* Restore warning settings. */
#endif
}
Exemplo n.º 4
0
static TA_RetCode internalMarketPageAlloc( TA_Libc *libHandle,
                                           const TA_DecodingParam *decodingParam,
                                           const char *yahooName,
                                           TA_YahooMarketPage **allocatedMarketPage )
{
   TA_RetCode retCode;
   TA_WebPage *webPage;
   TA_YahooMarketPage *marketPage;
   TA_StreamAccess *streamAccess;

   retCode = TA_WebPageAllocFromYahooName( libHandle,
                                           decodingParam,
                                           yahooName,
                                           &webPage );
                                              
   if( retCode != TA_SUCCESS )
      return retCode;

   /* Allocate the structure who will contained the extracted data */
   marketPage = (TA_YahooMarketPage *)TA_Malloc( libHandle, sizeof( TA_YahooMarketPage ) );
   if( !marketPage )
   {
      TA_WebPageFree( webPage );
      return TA_ALLOC_ERR;
   }
   memset( marketPage, 0, sizeof( TA_YahooMarketPage ) );

   marketPage->magicNb = TA_MARKET_PAGE_MAGIC_NB;
   marketPage->libHandle = libHandle;

   /* From this point, internalMarketPageFree can be safely called. */
    
   /* Extract the data by parsing the Web Page. */
   streamAccess = TA_StreamAccessAlloc( webPage->content );
   retCode = parseMarketPage( libHandle,
                              decodingParam,
                              streamAccess,
                              marketPage );

   if( retCode != TA_SUCCESS )
   {
      TA_StreamAccessFree( streamAccess );
      TA_WebPageFree( webPage );
      internalMarketPageFree( marketPage );
      return retCode;
   }

   retCode = TA_StreamAccessFree( streamAccess );
   if( retCode != TA_SUCCESS )
   {
      TA_WebPageFree( webPage );
      internalMarketPageFree( marketPage );
      return retCode;
   }

   retCode = TA_WebPageFree( webPage );
   if( retCode != TA_SUCCESS )
   {
      internalMarketPageFree( marketPage );
      return retCode;
   }
   
   /* Success. Return the result to the caller. */  
   *allocatedMarketPage = marketPage;

   return TA_SUCCESS;
}