⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gen_code.c

📁 股票主要技术指标源码
💻 C
📖 第 1 页 / 共 5 页
字号:
         printf( "Usage: gen_code\n");         printf( "\n" );                  printf( "  No parameter needed.\n" );         printf( "\n" );                  printf( "  This utility is useful only for developers adding new TA\n" );         printf( "  functions to TA-Lib.\n" );         printf( "\n" );                  printf( "  The interface definitions in c/src/ta_abstract/tables\n" );         printf( "  are used to generate code, documentation and some more.\n" );         printf( "\n" );         printf( "  The following files are updated or regenerated:\n" );         printf( "     1) ta-lib/c/include/ta_func.h\n" );         printf( "     2) ta-lib/c/include/ta_defs.h\n" );         printf( "     3) ta-lib/ta_func_list.txt\n" );         printf( "     4) ta-lib/c/src/ta_common/ta_retcode.*\n" );         printf( "     5) ta-lib/c/src/ta_abstract/ta_group_idx.c\n");              printf( "     6) ta-lib/c/src/ta_abstract/frames/*.*\n");         printf( "     7) ta-lib/swig/src/interface/ta_func.swg\n" );         printf( "     8) ta-lib/dotnet/src/Core/TA-Lib-Core.vcproj (Win32 only)\n" );         printf( "     9) ta-lib/dotnet/src/Core/TA-Lib-Core.h (Win32 only)\n" );         printf( "    10) ta-lib/c/src/ta_abstract/excel_glue.c (Win32 only)\n" );         printf( "    11) ta-lib/c/src/ta_abstract/java_defs.h (Win32 only)\n" );         printf( "    12) ta-lib/c/ide/msvc/lib_proj/ta_func/ta_func.dsp (Win32 only)\n" );         printf( "    13) ta-lib/java/src/com/tictactec/ta/lib/Core.java (Win32 only)\n" );         printf( "    14) ta-lib/java/src/com/tictactec/ta/lib/CoreAnnotated.java (Win32 only)\n" );         printf( "    15) ta-lib/ta_func_api.xml\n" );         printf( "    16) ta-lib/c/src/ta_abstract/ta_func_api.c\n" );         printf( "\n" );         printf( "  The function header, parameters and validation code of all TA\n" );         printf( "  function in c/src/ta_func are also updated.\n" );         printf( "\n" );         printf( "** Must be directly run from the 'bin' directory.\n" );         exit(-1);   }   printf( "gen_code V%s\n", TA_GetVersionString() );   retCode = TA_Initialize();   if( retCode != TA_SUCCESS )   {      printf( "\nCannot initialize the library\n");      return -1;   }   printf( "Now updating source code...\n" );   retValue = genCode( argc, argv );   retCode = TA_Shutdown();   if( retCode != TA_SUCCESS )   {      printf( "Shutdown failed (%d)\n", retCode );   }   return retValue;}/* The following I/O function allows to manipulate * more easily files. * * When opening the file, the caller can specifiy a * path relative to the position of the binary. * That is: ta-lib\c\bin * * 'templateFile' allows to create a new file using * a template. This template must contain one * line starting with '%%%GENCODE%%%'. * All character before this string are added to the output * file on fileOpen, and all character after this string are * added to the output file on fileClose. Obviously, all * character added to the file between fileOpen/fileClose * will replace the "%%%GENCODE%%%" line. * * 'templateFile' is ignored when FILE_READ is specified. * * Another advantage to use fileOpen and fileClose is that * the writing to the file is done "silently" in a temporary * file and the target file is touch only if there was actually * a modification to it. * * On failure, simply exit the software. */static void init_gToOpen( const char *filePath, const char *suffix ){      char *ptr;   #ifdef WIN32      const int sepChar = (int)'\\';   #else      const int sepChar = (int)'/';   #endif   strcpy( gToOpen, filePath );   if( suffix )      strcat( gToOpen, suffix );   /* Replace all directory separator with the    * one applicable for this OS.    */   ptr = gToOpen;   while( *ptr != '\0' )   {      if( (*ptr == '\\') || (*ptr == '/') )         *ptr = (char)sepChar;      ptr++;   }}static  FileHandle *fileOpen( const char *fileToOpen,                              const char *templateFile,                              int flags ){   FileHandle *retValue;   if( (fileToOpen == NULL) ||       ((flags&FILE_READ) && (templateFile != NULL)) )   {      printf( "Internal error line %d", __LINE__ );      return (FileHandle *)NULL;   }   retValue = TA_Malloc( sizeof(FileHandle) );   if( !retValue )   {      printf( "Memmory alloc error line %d", __LINE__ );      return (FileHandle *)NULL;   }   memset( retValue, 0, sizeof(FileHandle) );   retValue->flags = flags;   init_gToOpen( fileToOpen, NULL );   strcpy( retValue->f1_name, gToOpen );      /* First let's try to open the file. Might fail when    * for writing but that is ok. (the file might not exist).    */   if( flags&FILE_READ )   {            retValue->file = fopen( gToOpen, "r" );      if( retValue->file == NULL )      {         memset( retValue, 0, sizeof(FileHandle) );         TA_Free( retValue );         return (FileHandle *)NULL;      }   }   else if( flags&WRITE_ALWAYS )   {      retValue->file = fopen( gToOpen, "w" );      if( retValue->file == NULL )      {         memset( retValue, 0, sizeof(FileHandle) );         TA_Free( retValue );         return (FileHandle *)NULL;      }   }   else   {      retValue->file = fopen( gToOpen, "r" );      if( retValue->file )      {         /* Move pointer to fileTarget.  The file          * ptr will become the temporary file who          * is going to be truly write enabled.          */         retValue->fileTarget = retValue->file;         init_gToOpen( fileToOpen, ".tmp" );         strcpy( retValue->f2_name, gToOpen );         retValue->file = fopen( gToOpen, "w" );         if( !retValue->file )         {            fclose( retValue->fileTarget );            memset( retValue, 0, sizeof(FileHandle) );            TA_Free( retValue );            return (FileHandle *)NULL;         }       }       else       {         /* File does not exist, directly open for write          * no temporary will be used.          */         retValue->fileTarget = NULL;         retValue->file = fopen( gToOpen, "w" );         if( retValue->file == NULL )         {            memset( retValue, 0, sizeof(FileHandle) );            TA_Free( retValue );            return (FileHandle *)NULL;         }      }   }   if( !(flags&FILE_READ) )   {      /* Handle the template. */      if( templateFile )      {         init_gToOpen( templateFile, NULL );         retValue->templateFile = fopen( gToOpen, "r" );         if( retValue->templateFile == NULL )         {            if(retValue->fileTarget)   fclose( retValue->fileTarget );            if(retValue->file)         fclose( retValue->file );            if(retValue->templateFile) fclose( retValue->templateFile );            memset( retValue, 0, sizeof(FileHandle) );            TA_Free( retValue );            printf( "\nCannot open template [%s]\n", gToOpen );            return (FileHandle *)NULL;         }         /* Copy the header part of the template. */         if( skipToGenCode( fileToOpen, retValue->file, retValue->templateFile ) != 0 )         {            if(retValue->fileTarget)   fclose( retValue->fileTarget );            if(retValue->file)         fclose( retValue->file );            if(retValue->templateFile) fclose( retValue->templateFile );            memset( retValue, 0, sizeof(FileHandle) );            TA_Free( retValue );            return (FileHandle *)NULL;         }      }   }   return retValue;}static void fileClose( FileHandle *handle ){   if( !handle ) return;   /* Write remaining template info. */   if( handle->templateFile && handle->file )   {      while( fgets( gTempBuf, BUFFER_SIZE, handle->templateFile ) != NULL )      {         if( fputs( gTempBuf, handle->file ) == EOF )         {            printf( "Cannot write to output file! Disk Full? " );            break;         }      }      #if 0         /* Make sure the last line of the output           * finish with a carriage return. This may          * avoid warning from some compilers.          */         if( gTempBuf[0] != '\n' )	     {            fprintf( handle->file, "\n" );	     }      #endif   }   if(handle->fileTarget)   fclose( handle->fileTarget );   if(handle->templateFile) fclose( handle->templateFile );   if(handle->file)         fclose( handle->file );   if( !(handle->flags&FILE_READ) && !(handle->flags&WRITE_ALWAYS) && (handle->fileTarget != NULL))   {      if( !areFileSame( handle->f1_name, handle->f2_name ) )         copyFile( handle->f2_name, handle->f1_name );      fileDelete( handle->f2_name );         }   memset( handle, 0, sizeof(FileHandle) );      TA_Free( handle );}static void fileDelete( const char *fileToDelete ){   init_gToOpen( fileToDelete, NULL );   #if defined (WIN32)      DeleteFile (fileToDelete);   #else      unlink (fileToDelete);   #endif}static int genCode(int argc, char* argv[]){   TA_RetCode retCode;   unsigned int nbGroup;   #ifdef _MSC_VER   FileHandle *tempFile;   FileHandle *tempFileOut;   #endif   (void)argc; /* Get ride of compiler warning */   (void)argv; /* Get ride of compiler warning */   #ifdef _MSC_VER      /* Create .NET project files template */      #define FILE_NET_PROJ     "..\\..\\dotnet\\src\\Core\\TA-Lib-Core.vcproj"      #define FILE_NET_PROJ_TMP "..\\temp\\dotnetproj.tmp"      gOutProjFile = fileOpen( FILE_NET_PROJ, NULL, FILE_READ );      if( gOutProjFile == NULL )         {         printf( "\nCannot access [%s]\n", gToOpen );         return -1;      }      tempFile = fileOpen( FILE_NET_PROJ_TMP, NULL, FILE_WRITE|WRITE_ALWAYS );      if( tempFile == NULL )      {         printf( "Cannot create temporary .NET project file!\n" );         return -1;      }      if( createProjTemplate( gOutProjFile, tempFile ) != 0 )      {         printf( "Failed to parse and write the temporary .NET project file!\n" );         return -1;      }      fileClose(gOutProjFile);      fileClose(tempFile);      /* Create MSVC project files template */      #define FILE_MSVC_PROJ     "..\\..\\c\\ide\\msvc\\lib_proj\\ta_func\\ta_func.dsp"      #define FILE_MSVC_PROJ_TMP "..\\temp\\ta_func_dsp.tmp"      gOutMSVCProjFile = fileOpen( FILE_MSVC_PROJ, NULL, FILE_READ );      if( gOutMSVCProjFile == NULL )         {         printf( "\nCannot access [%s]\n", gToOpen );         return -1;      }      tempFile = fileOpen( FILE_MSVC_PROJ_TMP, NULL, FILE_WRITE|WRITE_ALWAYS );      if( tempFile == NULL )      {         printf( "Cannot create temporary MSVC project file!\n" );         return -1;      }      if( createMSVCProjTemplate( gOutMSVCProjFile, tempFile ) != 0 )      {         printf( "Failed to parse and write the temporary MSVC project file!\n" );         return -1;      }      fileClose(gOutMSVCProjFile);      fileClose(tempFile);      /* Create VS2005 project files template */      #define FILE_VS2005_PROJ     "..\\..\\c\\ide\\vs2005\\lib_proj\\ta_func\\ta_func.vcproj"      #define FILE_VS2005_PROJ_TMP "..\\temp\\ta_func_vcproj.tmp"      gOutVS2005ProjFile = fileOpen( FILE_VS2005_PROJ, NULL, FILE_READ );      if( gOutVS2005ProjFile == NULL )         {         printf( "\nCannot access [%s]\n", gToOpen );         return -1;      }      tempFile = fileOpen( FILE_VS2005_PROJ_TMP, NULL, FILE_WRITE|WRITE_ALWAYS );      if( tempFile == NULL )      {         printf( "Cannot create temporary VS2005 project file!\n" );         return -1;      }      if( createVS2005ProjTemplate( gOutVS2005ProjFile, tempFile ) != 0 )      {         printf( "Failed to parse and write the temporary VS2005 project file!\n" );         return -1;      }      fileClose(gOutVS2005ProjFile);      fileClose(tempFile);   #endif   #ifdef _MSC_VER   /* Create Java template for Core.java */   #define FILE_CORE_JAVA     "..\\..\\java\\src\\com\\tictactec\\ta\\lib\\Core.java"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -