void hb_ToLogFile( const char * sFile, const char * sTraceMsg, ... ) { if( s_bToLogFile ) { FILE * hFile; if( sFile == NULL ) { if( s_bEmptyLogFile ) { s_bEmptyLogFile = HB_FALSE; /* Empty the file if it exists. */ hFile = hb_fopen( "logfile.log", "w" ); } else hFile = hb_fopen( "logfile.log", "a" ); } else hFile = hb_fopen( sFile, "a" ); if( hFile ) { va_list ap; va_start( ap, sTraceMsg ); vfprintf( hFile, sTraceMsg, ap ); va_end( ap ); fclose( hFile ); } } }
static int hb_gt_chrmapread( const char * pszFile, const char * pszTerm, int * nTransTbl ) { int isTerm = -1; FILE * fp = hb_fopen( pszFile, "r" ); if( fp != NULL ) { char buf[ 256 ], * ptr, * pTerm; hb_strncpy( buf, pszTerm, sizeof( buf ) - 1 ); isTerm = 0; pTerm = buf; while( pTerm ) { if( ( ptr = strchr( pTerm, '/' ) ) != NULL ) *ptr++ = '\0'; if( *pTerm ) if( chrmap_parse( fp, pTerm, nTransTbl, pszFile ) > 0 ) isTerm = 1; pTerm = ptr; } fclose( fp ); } return isTerm; }
static int hb_pp_preprocesfile( PHB_PP_STATE pState, const char * szRuleFile, const char * szPPRuleFuncName ) { int iResult = 0; HB_SIZE nLen; while( hb_pp_nextLine( pState, &nLen ) != NULL && nLen ) ; if( szRuleFile ) { FILE * foutr; foutr = hb_fopen( szRuleFile, "w" ); if( ! foutr ) { #if ! defined( HB_OS_WIN_CE ) perror( szRuleFile ); #endif iResult = 1; } else { hb_pp_undefCompilerRules( pState ); hb_pp_generateRules( foutr, pState, szPPRuleFuncName ); fclose( foutr ); } } return iResult; }
/* Open a CSV File */ hb_csv_file_t *hb_open_csv_file( const char *filepath ) { hb_csv_file_t *file = NULL; FILE * fileref; if( filepath == NULL ) { return file; } fileref = hb_fopen(filepath, "r"); if( fileref == NULL ) { return file; } file = malloc( sizeof( hb_csv_file_t ) ); if( file == NULL ) { return file; } file->fileref = fileref; file->eof = 0; file->parse_state = CSV_PARSE_SEEK; file->curr_col = 0; file->curr_row = 0; return file; }
int hb_tr_level( void ) { if( s_level == -1 ) { char env[ HB_PATH_MAX ]; int enabled = s_enabled; /* protection against recursive or concurrent calls */ s_enabled = 0; s_level = HB_TR_DEFAULT; if( s_fp == NULL ) { if( hb_getenv_buffer( "HB_TR_OUTPUT", env, sizeof( env ) ) && env[ 0 ] != '\0' ) { s_fp = hb_fopen( env, s_mode ); if( s_fp == NULL ) s_fp = stderr; } else s_fp = stderr; } if( hb_getenv_buffer( "HB_TR_LEVEL", env, sizeof( env ) ) && env[ 0 ] != '\0' ) { int i; for( i = 0; i < HB_TR_LAST; ++i ) { if( hb_stricmp( env, s_slevel[ i ] ) == 0 || hb_stricmp( env, s_slevel[ i ] + 6 ) == 0 ) { s_level = i; break; } } } if( s_sysout < 0 ) { s_sysout = ( hb_getenv_buffer( "HB_TR_SYSOUT", env, sizeof( env ) ) && env[ 0 ] != '\0' ) ? 1 : 0; } if( s_flush < 0 ) { s_flush = ( hb_getenv_buffer( "HB_TR_FLUSH", env, sizeof( env ) ) && env[ 0 ] != '\0' ) ? 1 : 0; } s_enabled = enabled; } return s_level; }
void TraceLog( const char * sFile, const char * sTraceMsg, ... ) { FILE * hFile; BOOL bEmpty = FALSE; if( ! sTraceMsg ) return; if( s_bDoInit ) { s_bDoInit = FALSE; bEmpty = TRUE; hb_threadLockInit( S_TRACEMTX ); } hb_threadLock( S_TRACEMTX ); if( sFile == NULL ) { if( bEmpty ) /* Empty the file if it exists. */ hFile = hb_fopen( "trace.log", "w" ); else hFile = hb_fopen( "trace.log", "a" ); } else hFile = hb_fopen( sFile, "a" ); if( hFile ) { va_list ap; va_start( ap, sTraceMsg ); vfprintf( hFile, sTraceMsg, ap ); va_end( ap ); fclose( hFile ); } hb_threadUnLock( S_TRACEMTX ); }
static int hb_pp_preprocesfile( PHB_PP_STATE pState, char * szRuleFile, char* szWordFile ) { int iResult = 0; ULONG ulLen; FILE * fWord = NULL; while( hb_pp_nextLine( pState, &ulLen ) != NULL && ulLen ) ; if( szWordFile ) { fWord = hb_fopen( szWordFile, "w" ); if( ! fWord ) { perror( szWordFile ); iResult = 1; } } if( iResult == 0 && szRuleFile ) { FILE * foutr; foutr = hb_fopen( szRuleFile, "w" ); if( ! foutr ) { perror( szRuleFile ); iResult = 1; } else { hb_pp_undefCompilerRules( pState ); hb_pp_generateRules( foutr, fWord, pState ); fclose( foutr ); fclose( fWord ); } } return iResult; }
HB_BOOL hb_tracefile( const char * szFile ) { if( szFile && *szFile ) { FILE * fp = hb_fopen( szFile, s_mode ); if( fp ) { if( s_fp != NULL && s_fp != stderr ) fclose( s_fp ); s_fp = fp; return HB_TRUE; } } return HB_FALSE; }
void hb_traceInit( void ) { FILE * fpTrace; PHB_DYNS pTraceLog = hb_dynsymFind( "TRACELOG" ); if( s_bDoInit && pTraceLog && pTraceLog->pSymbol->value.pFunPtr && hb_fsFile( "trace.log" ) ) { s_bDoInit = FALSE; // Might have been initialized if TraceLog() was called before traceInit! hb_threadLockInit( S_TRACEMTX ); /* Empty the file if it exists. */ fpTrace = hb_fopen( "trace.log", "w" ); if( fpTrace ) fclose( fpTrace ); } }
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) { FILE* file = NULL; const char* mode_fopen = NULL; (void) opaque; if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) mode_fopen = "rb"; else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) mode_fopen = "r+b"; else if (mode & ZLIB_FILEFUNC_MODE_CREATE) mode_fopen = "wb"; if ((filename!=NULL) && (mode_fopen != NULL)) file = hb_fopen(filename, mode_fopen); return file; }
void hb_compGenPortObj( HB_COMP_DECL, PHB_FNAME pFileName ) { char szFileName[ HB_PATH_MAX ]; HB_SIZE nSize; HB_BYTE * pHrbBody; FILE * yyc; if( ! pFileName->szExtension ) pFileName->szExtension = ".hrb"; hb_fsFNameMerge( szFileName, pFileName ); yyc = hb_fopen( szFileName, "wb" ); if( ! yyc ) { hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_CREATE_OUTPUT, szFileName, NULL ); return; } if( ! HB_COMP_PARAM->fQuiet ) { char buffer[ 80 + HB_PATH_MAX - 1 ]; hb_snprintf( buffer, sizeof( buffer ), "Generating Harbour Portable Object output to \'%s\'... ", szFileName ); hb_compOutStd( HB_COMP_PARAM, buffer ); } hb_compGenBufPortObj( HB_COMP_PARAM, &pHrbBody, &nSize ); if( fwrite( pHrbBody, nSize, 1, yyc ) != 1 ) hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_FILE_WRITE, szFileName, NULL ); hb_xfree( pHrbBody ); fclose( yyc ); if( ! HB_COMP_PARAM->fQuiet ) hb_compOutStd( HB_COMP_PARAM, "Done.\n" ); }
static int hb_pp_parseChangelog( PHB_PP_STATE pState, const char * pszFileName, int iQuiet, int * piCommitRev, char ** pszCommitInfo ) { char * pszFree = NULL; int iResult = 0; FILE * file_in; char szToCheck[ HB_PATH_MAX ]; PHB_FNAME pFileName = hb_fsFNameSplit( pszFileName ); if( ! pFileName->szName ) { static const char * s_szNames[] = { "ChangeLog.txt", "CHANGES.txt", #if defined( HB_OS_DOS ) "ChangeLo.txt", "Change~1.txt", "Change~?.txt", "Chang~??.txt", #endif NULL }; int i = 0; if( ! pFileName->szPath ) pFileName->szPath = "../../../../.."; pszFileName = s_szNames[ i++ ]; while( pszFileName ) { pFileName->szName = pszFileName; hb_fsFNameMerge( szToCheck, pFileName ); if( hb_fsFileExists( szToCheck ) ) { pszFileName = szToCheck; break; } if( strchr( szToCheck, '?' ) != NULL ) { pszFree = hb_fsFileFind( szToCheck ); if( pszFree ) { pszFileName = pszFree; break; } } pszFileName = s_szNames[ i++ ]; } if( ! pszFileName ) pszFileName = s_szNames[ 0 ]; } hb_xfree( pFileName ); file_in = hb_fopen( pszFileName, "r" ); if( ! file_in ) { if( iQuiet < 2 ) { #if ! defined( HB_OS_WIN_CE ) perror( pszFileName ); #else fprintf( stderr, "Cannot open the %s file.\n", pszFileName ); #endif } iResult = 1; } else { char szLine[ 256 ]; char szLog[ 128 ]; int iLen; if( iQuiet == 0 ) fprintf( stdout, "Reading ChangeLog file: %s\n", pszFileName ); *szLog = '\0'; do { if( ! fgets( szLine, sizeof( szLine ), file_in ) ) break; if( ! *szLog ) { if( szLine[ 4 ] == '-' && szLine[ 7 ] == '-' && szLine[ 10 ] == ' ' && szLine[ 13 ] == ':' ) { hb_strncpy( szLog, szLine, sizeof( szLog ) - 1 ); iLen = ( int ) strlen( szLog ); while( iLen-- && HB_ISSPACE( szLog[ iLen ] ) ) szLog[ iLen ] = '\0'; } } } while( ! *szLog ); fclose( file_in ); if( ! *szLog ) { if( iQuiet < 2 ) fprintf( stderr, "Cannot find valid $" "Id entry in the %s file.\n", pszFileName ); iResult = 1; } else { *szLine = '"'; hb_strncpy( szLine + 1, szLog, sizeof( szLine ) - 3 ); iLen = ( int ) strlen( szLine ); szLine[ iLen ] = '"'; szLine[ ++iLen ] = '\0'; hb_pp_addDefine( pState, "HB_VER_COMMIT_INFO", szLine ); *pszCommitInfo = hb_strdup( szLog ); *piCommitRev = hb_pp_TimeStampToNum( pState, szLog ); } } if( pszFree ) hb_xfree( pszFree ); return iResult; }
void hb_errInternalRaw( HB_ERRCODE errCode, const char * szText, const char * szPar1, const char * szPar2 ) { char buffer[ 8192 ]; char file[ HB_PATH_MAX ]; const char * szFile, * szInfo; HB_BOOL fStack, fLang; HB_USHORT uiLine; int iLevel; FILE * hLog; HB_TRACE( HB_TR_DEBUG, ( "hb_errInternal(%d, %s, %s, %s)", errCode, szText, szPar1, szPar2 ) ); if( szPar1 == NULL ) szPar1 = ""; if( szPar2 == NULL ) szPar2 = ""; fStack = hb_stackId() != NULL; fLang = fStack && hb_langID() != NULL; szFile = fStack ? hb_setGetCPtr( HB_SET_HBOUTLOG ) : NULL; if( ! szFile ) szFile = "hb_out.log"; hLog = hb_fopen( szFile, "a+" ); if( hLog ) { char szTime[ 9 ]; int iYear, iMonth, iDay; hb_dateToday( &iYear, &iMonth, &iDay ); hb_dateTimeStr( szTime ); fprintf( hLog, "Application Internal Error - %s\n", hb_cmdargARGVN( 0 ) ); fprintf( hLog, "Terminated at: %04d-%02d-%02d %s\n", iYear, iMonth, iDay, szTime ); szInfo = fStack ? hb_setGetCPtr( HB_SET_HBOUTLOGINFO ) : NULL; if( szInfo && *szInfo ) fprintf( hLog, "Info: %s\n", szInfo ); } hb_conOutErr( hb_conNewLine(), 0 ); if( fLang ) hb_snprintf( buffer, sizeof( buffer ), hb_langDGetItem( HB_LANG_ITEM_BASE_ERRINTR ), errCode ); else hb_snprintf( buffer, sizeof( buffer ), "Unrecoverable error %d: ", errCode ); hb_conOutErr( buffer, 0 ); if( hLog ) fprintf( hLog, "%s", buffer ); if( ! szText && fLang ) szText = hb_langDGetItem( HB_LANG_ITEM_BASE_ERRINTR + errCode - 9000 ); if( szText ) hb_snprintf( buffer, sizeof( buffer ), szText, szPar1, szPar2 ); else buffer[ 0 ] = '\0'; hb_conOutErr( buffer, 0 ); hb_conOutErr( hb_conNewLine(), 0 ); if( hLog ) fprintf( hLog, "%s\n", buffer ); if( fStack && hb_stackTotalItems() ) { iLevel = 0; while( hb_procinfo( iLevel++, buffer, &uiLine, file ) ) { char msg[ HB_SYMBOL_NAME_LEN + HB_SYMBOL_NAME_LEN + 32 ]; hb_snprintf( msg, sizeof( msg ), "Called from %s(%hu)%s%s\n", buffer, uiLine, *file ? " in " : "", file ); hb_conOutErr( msg, 0 ); if( hLog ) fprintf( hLog, "%s", msg ); } } if( hLog ) { fprintf( hLog, "------------------------------------------------------------------------\n" ); fclose( hLog ); } }
static int decsrtInit( hb_work_object_t * w, hb_job_t * job ) { int retval = 1; hb_work_private_t * pv; hb_buffer_t *buffer; int i; hb_chapter_t * chapter; pv = calloc( 1, sizeof( hb_work_private_t ) ); if( pv ) { w->private_data = pv; pv->job = job; buffer = hb_buffer_init( 0 ); hb_fifo_push( w->fifo_in, buffer); pv->current_state = k_state_potential_new_entry; pv->number_of_entries = 0; pv->last_entry_number = 0; pv->current_time = 0; pv->subtitle = w->subtitle; /* * Figure out the start and stop times from teh chapters being * encoded - drop subtitle not in this range. */ pv->start_time = 0; for( i = 1; i < job->chapter_start; ++i ) { chapter = hb_list_item( job->list_chapter, i - 1 ); if( chapter ) { pv->start_time += chapter->duration; } else { hb_error( "Could not locate chapter %d for SRT start time", i ); retval = 0; } } pv->stop_time = pv->start_time; for( i = job->chapter_start; i <= job->chapter_end; ++i ) { chapter = hb_list_item( job->list_chapter, i - 1 ); if( chapter ) { pv->stop_time += chapter->duration; } else { hb_error( "Could not locate chapter %d for SRT start time", i ); retval = 0; } } hb_deep_log( 3, "SRT Start time %"PRId64", stop time %"PRId64, pv->start_time, pv->stop_time); pv->iconv_context = iconv_open( "utf-8", pv->subtitle->config.src_codeset ); if( pv->iconv_context == (iconv_t) -1 ) { hb_error("Could not open the iconv library with those file formats\n"); } else { memset( &pv->current_entry, 0, sizeof( srt_entry_t ) ); pv->file = hb_fopen(w->subtitle->config.src_filename, "r"); if( !pv->file ) { hb_error("Could not open the SRT subtitle file '%s'\n", w->subtitle->config.src_filename); } else { retval = 0; } } } if (!retval) { // Generate generic SSA Script Info. int height = job->title->geometry.height - job->crop[0] - job->crop[1]; int width = job->title->geometry.width - job->crop[2] - job->crop[3]; hb_subtitle_add_ssa_header(w->subtitle, "Arial", .066 * height, width, height); } return retval; }
static int hb_pp_parseRepoVer( PHB_PP_STATE pState, const char * pszFileName, int iQuiet, char ** pszCommitID, int * piCommitRev, char ** pszCommitInfo ) { FILE * file_in; char szId[ _VALUE_SIZE ]; char szDate[ _VALUE_SIZE ]; char szName[ _VALUE_SIZE ]; char szMail[ _VALUE_SIZE ]; char szCommitInfo[ _VALUE_SIZE ]; int iLen; *szId = *szDate = *szName = *szMail = *szCommitInfo = '\0'; file_in = hb_fopen( pszFileName, "r" ); if( ! file_in ) { if( iQuiet < 2 ) fprintf( stderr, "'%s' not found. Skipping.\n", pszFileName ); } else { char szLine[ 256 ]; char * pszValue; if( iQuiet == 0 ) fprintf( stdout, "Reading repository revision file: %s\n", pszFileName ); for( ;; ) { if( ! fgets( szLine, sizeof( szLine ), file_in ) ) break; if( ! *szId ) pszValue = szId; else if( ! *szDate ) pszValue = szDate; else if( ! *szName ) pszValue = szName; else if( ! *szMail ) pszValue = szMail; else break; { hb_strncpy( pszValue, szLine, _VALUE_SIZE - 1 ); iLen = ( int ) strlen( pszValue ); while( iLen-- && HB_ISSPACE( pszValue[ iLen ] ) ) pszValue[ iLen ] = '\0'; } } fclose( file_in ); } hb_pp_addDefine( pState, "HB_VER_COMMIT_ID", szId ); #if defined( HB_LEGACY_LEVEL4 ) hb_pp_addDefine( pState, "HB_VER_CHLID", szId ); #endif *pszCommitID = hb_strdup( szId ); if( szDate[ 0 ] && szName[ 0 ] && szMail[ 0 ] ) { iLen = ( int ) strlen( szMail ); while( iLen-- ) { if( szMail[ iLen ] == '@' ) szMail[ iLen ] = ' '; } #if defined( __HB_INCLUDE_MORE_COMMIT_INFO ) hb_snprintf( szCommitInfo, sizeof( szCommitInfo ), "%s %s (%s)", szDate, szName, szMail ); #else hb_snprintf( szCommitInfo, sizeof( szCommitInfo ), "%s", szDate ); HB_SYMBOL_UNUSED( szName ); HB_SYMBOL_UNUSED( szMail ); #endif if( *pszCommitInfo ) hb_xfree( *pszCommitInfo ); hb_pp_delDefine( pState, "HB_VER_COMMIT_INFO" ); hb_pp_addDefine( pState, "HB_VER_COMMIT_INFO", szCommitInfo ); *pszCommitInfo = hb_strdup( szCommitInfo ); *piCommitRev = hb_pp_TimeStampToNum( pState, szCommitInfo ); } return 0; }
static int hb_pp_generateVerInfo( char * szVerFile, char * szCVSID, char * szCVSDateID, char * szChangeLogID, char * szLastEntry ) { int iResult = 0; char * pszEnv; FILE * fout; fout = hb_fopen( szVerFile, "w" ); if( ! fout ) { #if ! defined( __MINGW32CE__ ) && ! defined( HB_OS_WIN_CE ) perror( szVerFile ); #endif iResult = 1; } else { fprintf( fout, "/*\n * $Id: ppgen.c 9869 2012-12-08 18:25:43Z andijahja $\n */\n\n/*\n" " * Harbour Project source code:\n" " * Version information and build time switches.\n" " *\n" " * Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>\n" " * www - http://www.harbour-project.org\n" " *\n" " * This file is generated automatically by Harbour preprocessor\n" " * and is covered by the same license as Harbour PP\n" " */\n\n" ); fprintf( fout, "\n#ifndef __HBVERBLD_INCLUDED" ); fprintf( fout, "\n#define __HBVERBLD_INCLUDED\n" ); if( szCVSID ) fprintf( fout, "\n#define HB_VER_CVSID\t\t%s\n", szCVSID ); if( szCVSDateID ) { fprintf( fout, "\n#if defined(HB_VER_BUILDDATE)" ); fprintf( fout, "\n#undef HB_VER_BUILDDATE" ); fprintf( fout, "\n#endif\n" ); fprintf( fout, "#define HB_VER_BUILDDATE\t%s\n", szCVSDateID ); } if( szChangeLogID ) { fprintf( fout, "\n#if defined(HB_VER_CHLCVS)" ); fprintf( fout, "\n#undef HB_VER_CHLCVS" ); fprintf( fout, "\n#endif\n" ); fprintf( fout, "\n#define HB_VER_CHLCVS\t\"%s\"\n", szChangeLogID ); } if( szLastEntry ) { fprintf( fout, "\n#if defined(HB_VER_LENTRY)" ); fprintf( fout, "\n#undef HB_VER_LENTRY" ); fprintf( fout, "\n#endif\n" ); fprintf( fout, "\n#define HB_VER_LENTRY\t\"%s\"\n", szLastEntry ); } pszEnv = hb_getenv( "C_USR" ); if( pszEnv ) { fprintf( fout, "\n#undef HB_VER_C_USR" ); fprintf( fout, "\n#define HB_VER_C_USR\t\"%s\"\n", pszEnv ); hb_xfree( pszEnv ); } pszEnv = hb_getenv( "L_USR" ); if( pszEnv ) { fprintf( fout, "\n#undef HB_VER_L_USR" ); fprintf( fout, "\n#define HB_VER_L_USR\t\"%s\"\n", pszEnv ); hb_xfree( pszEnv ); } pszEnv = hb_getenv( "PRG_USR" ); if( pszEnv ) { fprintf( fout, "\n#undef HB_VER_PRG_USR" ); fprintf( fout, "\n#define HB_VER_PRG_USR\t\"%s\"\n", pszEnv ); hb_xfree( pszEnv ); } fprintf( fout, "\n#endif /* __HBVERBLD_INCLUDED */\n" ); fclose( fout ); } return iResult; }
static int hb_pp_parseChangelog( PHB_PP_STATE pState, const char * pszFileName, BOOL fQuiet, char * piSVNID, char * piSVNDateID, char ** pszChangeLogID, char ** pszLastEntry ) { int iResult = 0; const char * pszFile; FILE * file_in; pszFile = pszFileName ? pszFileName : "../../../../ChangeLog"; do { if( hb_fsFileExists( pszFile ) ) break; pszFile += 3; } while( ! pszFileName && ( *pszFile == '.' || *pszFile == 'C' ) ); file_in = hb_fopen( pszFile, "r" ); if( ! file_in ) { if( ! fQuiet ) { #if ! defined( __MINGW32CE__ ) && ! defined( HB_OS_WIN_CE ) perror( pszFile ); #else fprintf( stderr, "Cannot open the %s file.\n", pszFile ); #endif } iResult = 1; } else { char szLine[ 256 ]; char szLine1[ 256 ]; char szId[ 128 ]; char szLog[ 128 ]; char * szFrom, * szTo; int iLen; *szId = *szLog = *szLine1 = '\0'; do { if( ! fgets( szLine, sizeof( szLine ), file_in ) ) break; if( ! *szId ) { szFrom = strstr( szLine, "$Id: " ); if( szFrom ) { szFrom += 5; szTo = strstr( szFrom, " $" ); if( szTo ) { *szTo = 0; } hb_strncpy( szId, szFrom, sizeof( szId ) - 1 ); hb_strncpy( szLine1, szLine + 1, sizeof( szLine1 ) - 1 ); } } else if( ! *szLog ) { if( szLine[ 4 ] == '-' && szLine[ 7 ] == '-' && szLine[ 10 ] == ' ' && szLine[ 13 ] == ':' ) { int iLen; hb_strncpy( szLog, szLine, sizeof( szLog ) - 1 ); iLen = strlen( szLog ); while( iLen-- && HB_ISSPACE( szLog[ iLen ] ) ) szLog[ iLen ] = '\0'; } } } while( ! *szLog ); fclose( file_in ); if( ! *szLog ) { if( ! fQuiet ) fprintf( stderr, "Cannot find valid $Id end log entry in the %s file.\n", pszFile ); iResult = 1; } else { char _szId[ 6 ]; int u = 0; hb_xmemset( _szId, 0, 6 ); *szLine = '"'; hb_strncpy( szLine + 1, szLog, sizeof( szLine ) - 3 ); iLen = strlen( szLine ); szLine[ iLen ] = '"'; szLine[ ++iLen ] = '\0'; hb_pp_addDefine( pState, "HB_VER_LENTRY", szLine ); *pszLastEntry = hb_strdup( szLog ); hb_strncpy( szLine + 1, szId, sizeof( szLine ) - 3 ); iLen = strlen( szLine ); szLine[ iLen ] = '"'; szLine[ ++iLen ] = '\0'; hb_pp_addDefine( pState, "HB_VER_CHLCVS", szLine ); *pszChangeLogID = hb_strdup( szId ); szFrom = strchr( szLine, ' ' ); if( szFrom ) { while( *szFrom == ' ' ) ++szFrom; iLen = 0; while( ! HB_ISSPACE( szFrom[ iLen ] ) ) { _szId[ u++ ] = szFrom[ iLen ]; ++iLen; } /* Latest CVS version before migration to SVN: ChangeLog,v 1.6768 2011/01/25 18:50:35 guerra000 */ if( iLen ) { #if 0 int iCurrentVersion = atoi( _szId ) + 6768; sprintf( _szId, "%i", iCurrentVersion ); hb_strncpy( piSVNID, _szId, strlen( _szId ) ); #else hb_strncpy( piSVNID, _szId, u ); #endif } else _szId[ 0 ] = 0; } if( _szId[ 0 ] ) { char szSVNDateID[ 10 ]; int iLen = 0, u = 0, wLen = ( int ) strlen( szLine1 ); char *szDate = NULL; *szSVNDateID ='\0'; do { if ( szLine1[ u ] == ' ' ) iLen ++; if ( iLen == 4 ) { iLen = u; szDate = szLine1 + iLen + 1; break; } ++u; } while ( u < wLen ); iLen = 0; u = 0; do { if (! ( szDate[ iLen ] == '-' ) ) szSVNDateID[ u++ ] = szDate[ iLen ]; if ( szDate[ iLen ] == ' ' ) break; ++iLen; } while( szDate [ iLen ] ); szSVNDateID[ u ] = 0; hb_strncpy( piSVNDateID, szSVNDateID, u ); hb_pp_addDefine( pState, "HB_VER_BUILDDATE", szSVNDateID ); hb_pp_addDefine( pState, "HB_VER_CVSID", _szId ); } else { if( ! fQuiet ) fprintf( stderr, "Unrecognized Id entry in the %s file.\n", pszFile ); iResult = 1; } } } return iResult; }
static int hb_pp_generateVerInfo( char * szVerFile, int iRevID, char * szChangeLogID, char * szLastEntry ) { int iResult = 0; char * pszEnv; FILE * fout; fout = hb_fopen( szVerFile, "w" ); if( ! fout ) { #if ! defined( HB_OS_WIN_CE ) perror( szVerFile ); #endif iResult = 1; } else { char * pszEscaped; fprintf( fout, "/*\n" " * Harbour Project source code:\n" " * Version information and build time switches.\n" " *\n" " * Copyright 2008-2014 Przemyslaw Czerpak <druzus / at / priv.onet.pl>\n" " * www - http://harbour-project.org\n" " *\n" " * This file is generated automatically by Harbour preprocessor\n" " * and is covered by the same license as Harbour PP\n" " */\n\n" ); fprintf( fout, "#define HB_VER_REVID %d\n", iRevID ); if( szChangeLogID ) { pszEscaped = hb_pp_escapeString( szChangeLogID ); fprintf( fout, "#define HB_VER_CHLID \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); } if( szLastEntry ) { pszEscaped = hb_pp_escapeString( szLastEntry ); fprintf( fout, "#define HB_VER_LENTRY \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); } pszEnv = hb_getenv( "HB_USER_CFLAGS" ); if( pszEnv ) { pszEscaped = hb_pp_escapeString( pszEnv ); fprintf( fout, "#define HB_VER_HB_USER_CFLAGS \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); hb_xfree( pszEnv ); } pszEnv = hb_getenv( "HB_USER_LDFLAGS" ); if( pszEnv ) { pszEscaped = hb_pp_escapeString( pszEnv ); fprintf( fout, "#define HB_VER_HB_USER_LDFLAGS \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); hb_xfree( pszEnv ); } pszEnv = hb_getenv( "HB_USER_PRGFLAGS" ); if( pszEnv ) { pszEscaped = hb_pp_escapeString( pszEnv ); fprintf( fout, "#define HB_VER_HB_USER_PRGFLAGS \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); hb_xfree( pszEnv ); } pszEnv = hb_getenv( "HB_PLATFORM" ); if( pszEnv ) { pszEscaped = hb_pp_escapeString( pszEnv ); fprintf( fout, "#define HB_PLATFORM \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); hb_xfree( pszEnv ); } pszEnv = hb_getenv( "HB_COMPILER" ); if( pszEnv ) { pszEscaped = hb_pp_escapeString( pszEnv ); fprintf( fout, "#define HB_COMPILER \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); hb_xfree( pszEnv ); } fclose( fout ); } return iResult; }
HB_BOOL hb_compI18nSave( HB_COMP_DECL, HB_BOOL fFinal ) { PHB_I18NTABLE pI18n; PHB_I18NSTRING pString; HB_FNAME FileName; char szFileName[ HB_PATH_MAX ]; char* szText; HB_UINT uiIndex, uiLine; FILE* file; pI18n = HB_COMP_PARAM->pI18n; if( ! pI18n ) return HB_FALSE; FileName.szPath = FileName.szName = FileName.szExtension = FileName.szDrive = NULL; if( HB_COMP_PARAM->pOutPath ) { FileName.szDrive = HB_COMP_PARAM->pOutPath->szDrive; FileName.szPath = HB_COMP_PARAM->pOutPath->szPath; } if( HB_COMP_PARAM->pI18nFileName ) { if( HB_COMP_PARAM->pI18nFileName->szName ) FileName.szName = HB_COMP_PARAM->pI18nFileName->szName; if( HB_COMP_PARAM->pI18nFileName->szExtension ) FileName.szExtension = HB_COMP_PARAM->pI18nFileName->szExtension; if( HB_COMP_PARAM->pI18nFileName->szPath ) { FileName.szDrive = HB_COMP_PARAM->pI18nFileName->szDrive; FileName.szPath = HB_COMP_PARAM->pI18nFileName->szPath; } } if( ! FileName.szName ) FileName.szName = HB_COMP_PARAM->pFileName->szName; else if( ! fFinal ) /* The exact file name was given generate single .pot file for * all compiled .prg files in final phase. */ return HB_FALSE; if( ! FileName.szExtension ) FileName.szExtension = ".pot"; hb_fsFNameMerge( szFileName, &FileName ); file = hb_fopen( szFileName, "w" ); if( ! file ) { hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_CREATE_OUTPUT, szFileName, NULL ); return HB_FALSE; } szText = hb_verHarbour(); fprintf( file, "#\n# This file is generated by %s\n#\n\n", szText ); hb_xfree( szText ); for( uiIndex = 0; uiIndex < pI18n->uiCount; uiIndex++ ) { pString = &pI18n->pString[ uiIndex ]; fprintf( file, "#: %s:%d", hb_compI18nFileName( szFileName, pString->pPos.szFile ), pString->pPos.uiLine ); for( uiLine = 0; uiLine < pString->uiPosCount; ++uiLine ) fprintf( file, " %s:%d", hb_compI18nFileName( szFileName, pString->pPosLst[ uiLine ].szFile ), pString->pPosLst[ uiLine ].uiLine ); fprintf( file, "\n#, c-format\n" ); if( pString->szContext ) { fprintf( file, "msgctxt \"" ); hb_compI18nEscapeString( file, pString->szContext ); fprintf( file, "\"\n" ); } fprintf( file, "msgid \"" ); hb_compI18nEscapeString( file, pString->szText ); for( uiLine = 0; uiLine < pString->uiPlurals; ++uiLine ) { if( uiLine == 0 ) fprintf( file, "\"\nmsgid_plural \"" ); else fprintf( file, "\"\nmsgid_plural%d \"", uiLine + 1 ); hb_compI18nEscapeString( file, pString->szPlurals[ uiLine ] ); } fprintf( file, "\"\nmsgstr%s \"\"\n\n", pString->uiPlurals ? "[0]" : "" ); } fclose( file ); return HB_TRUE; }
static int hb_pp_parseChangelog( PHB_PP_STATE pState, const char * pszFileName, int iQuiet, int * piRevID, char ** pszChangeLogID, char ** pszLastEntry ) { char * pszFree = NULL; int iResult = 0; FILE * file_in; char szToCheck[ HB_PATH_MAX ]; PHB_FNAME pFileName = hb_fsFNameSplit( pszFileName ); if( ! pFileName->szName ) { static const char * s_szNames[] = { "ChangeLog.txt", "CHANGES.txt", #if defined( HB_OS_DOS ) "ChangeLo.txt", "Change~1.txt", "Change~?.txt", "Chang~??.txt", #endif NULL }; int i = 0; if( ! pFileName->szPath ) pFileName->szPath = "../../../../.."; pszFileName = s_szNames[ i++ ]; while( pszFileName ) { pFileName->szName = pszFileName; hb_fsFNameMerge( szToCheck, pFileName ); if( hb_fsFileExists( szToCheck ) ) { pszFileName = szToCheck; break; } if( strchr( szToCheck, '?' ) != NULL ) { pszFree = hb_fsFileFind( szToCheck ); if( pszFree ) { pszFileName = pszFree; break; } } pszFileName = s_szNames[ i++ ]; } if( ! pszFileName ) pszFileName = s_szNames[ 0 ]; } hb_xfree( pFileName ); file_in = hb_fopen( pszFileName, "r" ); if( ! file_in ) { if( iQuiet < 2 ) { #if ! defined( HB_OS_WIN_CE ) perror( pszFileName ); #else fprintf( stderr, "Cannot open the %s file.\n", pszFileName ); #endif } iResult = 1; } else { char szLine[ 256 ]; char szId[ 128 ]; char szLog[ 128 ]; char * szFrom, * szTo; int iLen; if( iQuiet == 0 ) fprintf( stdout, "Reading ChangeLog file: %s\n", pszFileName ); *szId = *szLog = '\0'; do { if( ! fgets( szLine, sizeof( szLine ), file_in ) ) break; if( ! *szId ) { szFrom = strstr( szLine, "$" "Id" ); if( szFrom ) { szFrom += 3; szTo = strchr( szFrom, '$' ); if( szTo ) { /* Is it tarball source package? */ if( szTo == szFrom ) { /* we do not have revision number :-( */ hb_strncpy( szId, "unknown -1 (source tarball without keyword expanding)", sizeof( szId ) - 1 ); } else if( szTo - szFrom > 3 && szTo[ -1 ] == ' ' && szFrom[ 0 ] == ':' && szFrom[ 1 ] == ' ' ) { szTo[ -1 ] = '\0'; hb_strncpy( szId, szFrom + 2, sizeof( szId ) - 1 ); } } } } else if( ! *szLog ) { if( szLine[ 4 ] == '-' && szLine[ 7 ] == '-' && szLine[ 10 ] == ' ' && szLine[ 13 ] == ':' ) { hb_strncpy( szLog, szLine, sizeof( szLog ) - 1 ); iLen = ( int ) strlen( szLog ); while( iLen-- && HB_ISSPACE( szLog[ iLen ] ) ) szLog[ iLen ] = '\0'; } } } while( ! *szLog ); fclose( file_in ); if( ! *szLog ) { if( iQuiet < 2 ) fprintf( stderr, "Cannot find valid $" "Id entry in the %s file.\n", pszFileName ); iResult = 1; } else { char szRevID[ 18 ]; *szLine = '"'; hb_strncpy( szLine + 1, szLog, sizeof( szLine ) - 3 ); iLen = ( int ) strlen( szLine ); szLine[ iLen ] = '"'; szLine[ ++iLen ] = '\0'; hb_pp_addDefine( pState, "HB_VER_LENTRY", szLine ); *pszLastEntry = hb_strdup( szLog ); hb_strncpy( szLine + 1, szId, sizeof( szLine ) - 3 ); iLen = ( int ) strlen( szLine ); szLine[ iLen ] = '"'; szLine[ ++iLen ] = '\0'; hb_pp_addDefine( pState, "HB_VER_CHLID", szLine ); *pszChangeLogID = hb_strdup( szId ); if( strlen( szLog ) >= 16 ) { long lJulian = 0, lMilliSec = 0; int iUTC = 0; if( strlen( szLog ) >= 25 && szLog[ 17 ] == 'U' && szLog[ 18 ] == 'T' && szLog[ 19 ] == 'C' && ( szLog[ 20 ] == '+' || szLog[ 20 ] == '-' ) && HB_ISDIGIT( szLog[ 21 ] ) && HB_ISDIGIT( szLog[ 22 ] ) && HB_ISDIGIT( szLog[ 23 ] ) && HB_ISDIGIT( szLog[ 24 ] ) ) { iUTC = ( ( int ) ( szLog[ 21 ] - '0' ) * 10 + ( int ) ( szLog[ 22 ] - '0' ) ) * 60 + ( int ) ( szLog[ 23 ] - '0' ) * 10 + ( int ) ( szLog[ 24 ] - '0' ); } szLog[ 16 ] = '\0'; if( iUTC != 0 && hb_timeStampStrGetDT( szLog, &lJulian, &lMilliSec ) ) { hb_timeStampUnpackDT( hb_timeStampPackDT( lJulian, lMilliSec ) - ( double ) iUTC / ( 24 * 60 ), &lJulian, &lMilliSec ); } if( lJulian && lMilliSec ) { hb_timeStampStrRawPut( szRevID, lJulian, lMilliSec ); memmove( szRevID, szRevID + 2, 10 ); } else { szRevID[ 0 ] = szLog[ 2 ]; szRevID[ 1 ] = szLog[ 3 ]; szRevID[ 2 ] = szLog[ 5 ]; szRevID[ 3 ] = szLog[ 6 ]; szRevID[ 4 ] = szLog[ 8 ]; szRevID[ 5 ] = szLog[ 9 ]; szRevID[ 6 ] = szLog[ 11 ]; szRevID[ 7 ] = szLog[ 12 ]; szRevID[ 8 ] = szLog[ 14 ]; szRevID[ 9 ] = szLog[ 15 ]; } szRevID[ 10 ] = '\0'; } else szRevID[ 0 ] = '\0'; *piRevID = ( int ) hb_strValInt( szRevID, &iLen ); hb_pp_addDefine( pState, "HB_VER_REVID", szRevID ); #ifdef HB_LEGACY_LEVEL4 hb_pp_addDefine( pState, "HB_VER_SVNID", szRevID ); #endif } } if( pszFree ) hb_xfree( pszFree ); return iResult; }
static int decsrtInit( hb_work_object_t * w, hb_job_t * job ) { hb_work_private_t * pv; int i; hb_chapter_t * chapter; pv = calloc( 1, sizeof( hb_work_private_t ) ); if (pv == NULL) { goto fail; } w->private_data = pv; pv->job = job; pv->current_state = k_state_potential_new_entry; pv->number_of_entries = 0; pv->last_entry_number = 0; pv->current_time = 0; pv->subtitle = w->subtitle; /* * Figure out the start and stop times from the chapters being * encoded - drop subtitle not in this range. */ pv->start_time = 0; for( i = 1; i < job->chapter_start; ++i ) { chapter = hb_list_item( job->list_chapter, i - 1 ); if( chapter ) { pv->start_time += chapter->duration; } else { hb_error( "Could not locate chapter %d for SRT start time", i ); } } pv->stop_time = pv->start_time; for( i = job->chapter_start; i <= job->chapter_end; ++i ) { chapter = hb_list_item( job->list_chapter, i - 1 ); if( chapter ) { pv->stop_time += chapter->duration; } else { hb_error( "Could not locate chapter %d for SRT start time", i ); } } hb_deep_log(3, "SRT Start time %"PRId64", stop time %"PRId64, pv->start_time, pv->stop_time); if (job->pts_to_start != 0) { pv->start_time = AV_NOPTS_VALUE; } pv->iconv_context = iconv_open( "utf-8", pv->subtitle->config.src_codeset ); if( pv->iconv_context == (iconv_t) -1 ) { hb_error("Could not open the iconv library with those file formats\n"); goto fail; } else { memset( &pv->current_entry, 0, sizeof( srt_entry_t ) ); pv->file = hb_fopen(w->subtitle->config.src_filename, "r"); if( !pv->file ) { hb_error("Could not open the SRT subtitle file '%s'\n", w->subtitle->config.src_filename); goto fail; } } // Generate generic SSA Script Info. int height = job->title->geometry.height - job->crop[0] - job->crop[1]; int width = job->title->geometry.width - job->crop[2] - job->crop[3]; hb_subtitle_add_ssa_header(w->subtitle, HB_FONT_SANS, .066 * job->title->geometry.height, width, height); return 0; fail: if (pv != NULL) { if (pv->iconv_context != (iconv_t) -1) { iconv_close(pv->iconv_context); } if (pv->file != NULL) { fclose(pv->file); } free(pv); } return 1; }
static int hb_pp_generateVerInfo( char * szVerFile, int iCommitRev, char * szCommitInfo, char * szCommitID ) { int iResult = 0; FILE * fout; fout = hb_fopen( szVerFile, "w" ); if( ! fout ) { #if ! defined( HB_OS_WIN_CE ) perror( szVerFile ); #endif iResult = 1; } else { char * pszEnv; char * pszEscaped; fprintf( fout, "/*\n" " * Version information and build time switches.\n" " *\n" " * Copyright 2008-2016 Przemyslaw Czerpak <druzus / at / priv.onet.pl>\n" " *\n" " * This file is generated automatically by Harbour preprocessor\n" " * and is covered by the same license as Harbour PP\n" " */\n\n" ); if( szCommitID ) { pszEscaped = hb_pp_escapeString( szCommitID ); fprintf( fout, "#define HB_VER_COMMIT_ID \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); } fprintf( fout, "#define HB_VER_COMMIT_REV %d\n", iCommitRev ); if( szCommitInfo ) { pszEscaped = hb_pp_escapeString( szCommitInfo ); fprintf( fout, "#define HB_VER_COMMIT_INFO \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); } pszEnv = hb_getenv( "HB_USER_CFLAGS" ); if( pszEnv ) { pszEscaped = hb_pp_escapeString( pszEnv ); fprintf( fout, "#define HB_VER_HB_USER_CFLAGS \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); hb_xfree( pszEnv ); } pszEnv = hb_getenv( "HB_USER_LDFLAGS" ); if( pszEnv ) { pszEscaped = hb_pp_escapeString( pszEnv ); fprintf( fout, "#define HB_VER_HB_USER_LDFLAGS \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); hb_xfree( pszEnv ); } pszEnv = hb_getenv( "HB_USER_PRGFLAGS" ); if( pszEnv ) { pszEscaped = hb_pp_escapeString( pszEnv ); fprintf( fout, "#define HB_VER_HB_USER_PRGFLAGS \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); hb_xfree( pszEnv ); } pszEnv = hb_getenv( "HB_PLATFORM" ); if( pszEnv ) { pszEscaped = hb_pp_escapeString( pszEnv ); fprintf( fout, "#define HB_PLATFORM \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); hb_xfree( pszEnv ); } pszEnv = hb_getenv( "HB_COMPILER" ); if( pszEnv ) { pszEscaped = hb_pp_escapeString( pszEnv ); fprintf( fout, "#define HB_COMPILER \"%s\"\n", pszEscaped ); hb_xfree( pszEscaped ); hb_xfree( pszEnv ); } #if defined( HB_LEGACY_LEVEL4 ) fprintf( fout, "\n#define HB_VER_CHLID HB_VER_COMMIT_ID\n" ); fprintf( fout, "\n#define HB_VER_LENTRY HB_VER_COMMIT_INFO\n" ); #endif fclose( fout ); } return iResult; }