/**************************************************************************** Desc: *****************************************************************************/ RCODE F_DynamicList::dumpToFile() { RCODE rc = NE_FLM_OK; DLIST_NODE * pTmp; FLMUINT uiLoop; IF_FileHdl * pFileHdl = NULL; #define DLST_RESP_SIZE 256 char szResponse[ DLST_RESP_SIZE]; FLMUINT uiTermChar; FTX_SCREEN * pScreen; IF_FileSystem * pFileSystem = NULL; if( RC_BAD( rc = FlmGetFileSystem( &pFileSystem))) { goto Exit; } f_strcpy( szResponse, (const char *)DLIST_DUMPFILE_PATH); FTXWinGetScreen( m_pListWin, &pScreen); FTXGetInput( pScreen, "enter filename to dump to", szResponse, DLST_RESP_SIZE-1, &uiTermChar); if ( uiTermChar != FKB_ENTER) { goto Exit; } if (RC_BAD( rc = pFileSystem->doesFileExist( szResponse))) { //create file if it doesn't already exist if ( rc == NE_FLM_IO_PATH_NOT_FOUND) { rc = pFileSystem->createFile( szResponse, FLM_IO_RDWR, &pFileHdl); } else { goto Exit_local; } } else { rc = pFileSystem->openFile( szResponse, FLM_IO_RDWR, &pFileHdl); } TEST_RC_LOCAL( rc); { FLMUINT64 ui64FileSize = 0; FLMUINT uiBytesWritten = 0; //figure out size of file currently, so you can append to it pFileHdl->size( &ui64FileSize); pTmp = m_pFirst; uiLoop = 0; while( pTmp) { FLMBYTE * pszNextLine = (FLMBYTE*)(pTmp->pvData); TEST_RC_LOCAL( rc = pFileHdl->write( ui64FileSize, //offset to current file size f_strlen( (const char *)pszNextLine), pszNextLine, &uiBytesWritten)); ui64FileSize += uiBytesWritten; TEST_RC_LOCAL( rc = pFileHdl->write( ui64FileSize, //add in newline 1, (FLMBYTE*)"\n", &uiBytesWritten)); ui64FileSize += uiBytesWritten; pTmp = pTmp->pNext; } (void)pFileHdl->closeFile(); } Exit_local: {//give success/fail message char szMessage[ 256]; FLMUINT uiChar; FTXWinGetScreen( m_pListWin, &pScreen); if ( RC_OK( rc)) { f_sprintf( szMessage, "contents of focused list appended to %s", DLIST_DUMPFILE_PATH); } else { f_sprintf( szMessage, "error rc=%u dumping to file %s", (unsigned)rc, DLIST_DUMPFILE_PATH); } FTXDisplayMessage( pScreen, FLM_RED, FLM_WHITE, szMessage, "press ESC or ENTER to close dialog", &uiChar); } Exit: if (pFileHdl) { pFileHdl->Release(); pFileHdl = NULL; } if( pFileSystem) { pFileSystem->Release(); } return rc; }
/**************************************************************************** Desc: ****************************************************************************/ RCODE createUnitTest( const char * configPath, const char * buildNum, const char * environment, const char * user, unitTestData * uTD) { RCODE rc = FERR_OK; IF_FileHdl * pConfigFileHdl = NULL; IF_FileHdl * pCSVFileHdl = NULL; FLMBYTE buffer[ MAX_BUFFER_SIZE] = ""; FLMUINT uiSize = MAX_BUFFER_SIZE; FLMUINT64 ui64Tmp; char * strPos1 = NULL; char * strPos2 = NULL; IF_FileSystem * pFileSystem = NULL; if( !configPath || !buildNum || !environment || !uTD || !user) { flmAssert(0); } if( f_strlen(user) > MAX_SMALL_BUFFER_SIZE) { rc = RC_SET( FERR_CONV_DEST_OVERFLOW); goto Exit; } else { f_strcpy( uTD->userName, user); } if( f_strlen(environment) > MAX_SMALL_BUFFER_SIZE) { rc = RC_SET( FERR_CONV_DEST_OVERFLOW); goto Exit; } else { f_strcpy( uTD->environment, environment); } if( f_strlen( buildNum) > MAX_SMALL_BUFFER_SIZE) { rc = RC_SET( FERR_CONV_DEST_OVERFLOW); goto Exit; } else { f_strcpy( uTD->buildNumber, buildNum); } if( RC_BAD( rc = FlmGetFileSystem( &pFileSystem))) { goto Exit; } if( configPath[ 0]) { if( RC_BAD( rc = pFileSystem->openFile( configPath, FLM_IO_RDONLY | FLM_IO_SH_DENYNONE, &pConfigFileHdl))) { goto Exit; } if( RC_BAD( rc = pConfigFileHdl->size( &ui64Tmp))) { goto Exit; } uiSize = (FLMUINT)ui64Tmp; if( RC_BAD( rc = pConfigFileHdl->read( 0, uiSize, buffer, &uiSize))) { goto Exit; } #ifdef FLM_WIN { char szTemp[ MAX_BUFFER_SIZE]; char * pszTemp = szTemp; FLMUINT uiNewSize = uiSize; for( unsigned int i = 0; i < uiSize; i++) { if( ((i + 1) < uiSize) && (buffer[i] == 0x0D && buffer[ i + 1] == 0x0A)) { *pszTemp++ = 0x0A; i++; uiNewSize--; } else { *pszTemp++ = buffer[ i]; } } f_memcpy( buffer, szTemp, uiNewSize); uiSize = uiNewSize; } #endif // Get the FOLDER strPos1 = f_strchr( (const char *)buffer, ':'); strPos2 = f_strchr( (const char *)strPos1, '\n'); if( !strPos1 || !strPos2) { rc = RC_SET( FERR_FAILURE); goto Exit; } for( strPos1++; *strPos1 == ' ' || *strPos1 == '\t'; strPos1++); if( strPos2-strPos1 > MAX_SMALL_BUFFER_SIZE) { rc = RC_SET( FERR_CONV_DEST_OVERFLOW); goto Exit; } f_strncpy( uTD->folder, strPos1, strPos2-strPos1); uTD->folder[ strPos2 - strPos1] = '\0'; // Get the ATTRIBUTES strPos1 = f_strchr( (const char *)strPos1, ':'); strPos2 = f_strchr( (const char *)strPos1, '\n'); if( !strPos1 || !strPos2) { rc = RC_SET( FERR_FAILURE); goto Exit; } for( strPos1++;*strPos1 == ' ' || *strPos1 == '\t';strPos1++); if( strPos2-strPos1 > MAX_SMALL_BUFFER_SIZE) { rc = RC_SET( FERR_FAILURE); goto Exit; } f_strncpy( uTD->attrs, strPos1, strPos2-strPos1); uTD->attrs[strPos2-strPos1] = '\0'; // Get the CSVFILE strPos1 = f_strchr( (const char *)strPos1, ':'); strPos2 = f_strchr( (const char *)strPos1, '\n'); // Allow for possible \r if( *( --strPos2) != '\r') { strPos2++; } if( !strPos1 || !strPos2) { rc = RC_SET( FERR_FAILURE); goto Exit; } for( strPos1++;*strPos1 == ' ' || *strPos1 == '\t';strPos1++); if( strPos2-strPos1 > MAX_SMALL_BUFFER_SIZE) { rc = RC_SET( FERR_FAILURE); goto Exit; } f_strncpy( uTD->csvFilename, strPos1, strPos2-strPos1); uTD->csvFilename[ strPos2 - strPos1] = '\0'; if( RC_BAD( rc = pFileSystem->openFile( uTD->csvFilename, FLM_IO_RDWR | FLM_IO_SH_DENYNONE, &pCSVFileHdl))) { if ( rc == FERR_IO_PATH_NOT_FOUND) { // Create the file and write the header if( RC_BAD( rc = f_filecat( uTD->csvFilename, DATA_ORDER))) { goto Exit; } } } else { goto Exit; } } Exit: if( pConfigFileHdl) { pConfigFileHdl->Release(); } if( pCSVFileHdl) { pCSVFileHdl->Release(); } if( pFileSystem) { pFileSystem->Release(); } return( rc); }