示例#1
0
bool FbImportBook::Save()
{
	if (!m_ok || m_md5sum.IsEmpty()) return false;

	int id_book = FindByMD5();

	if (m_parser && m_parser->IsOk()) {
		return id_book ? AppendFile(id_book) : AppendBook();
	} else {
		if (id_book == 0) wxLogMessage(_("Skip entry: %s"), m_filename.c_str());
		return id_book && AppendFile(id_book);
	}
}
示例#2
0
void Logger::Console(std::string message)
{
	if((Verbosity & VL_CONSOLE_OUT) == VL_CONSOLE_OUT)
	{
		Print(message);
	}

	if((Verbosity & VL_CONSOLE_FILE) == VL_CONSOLE_FILE)
	{
		AppendFile(CONSOLE_OUT, message);
	}
}
示例#3
0
const OTString & OTPaths::GlobalConfigFile()
{
	if (m_strGlobalConfigFile.Exists()) return m_strGlobalConfigFile;  //got it, lets return it.

	OTString strGlobalConfigFile("");

	if(!AppendFile(strGlobalConfigFile,AppDataFolder(),OT_INIT_CONFIG_FILENAME)) OT_ASSERT(false);

	m_strGlobalConfigFile = strGlobalConfigFile;

	return m_strGlobalConfigFile;
}
示例#4
0
void Logger::Error(std::string message)
{
	if((Verbosity & VL_ERROR_OUT) == VL_ERROR_OUT)
	{
		Print("Error: " + message);
	}

	if((Verbosity & VL_ERROR_FILE) == VL_ERROR_FILE)
	{
		AppendFile(ERROR_OUT, message);
	}
}
示例#5
0
// Overloaded function where the data is read from a file on disk.
bool ZipFile::AppendFile(QString fileName, QString fileNameOnDisk, QString comment)
{
	if (!zf)
		return false;

	QFile file(fileNameOnDisk);
	if (!file.open(QIODevice::ReadOnly))
		return false;

	QByteArray ba = file.readAll();

	return AppendFile(fileName, ba, comment);
}
示例#6
0
const String& OTPaths::GlobalConfigFile()
{
    if (s_strGlobalConfigFile.Exists())
        return s_strGlobalConfigFile; // got it, lets return it.

    String strGlobalConfigFile("");

    if (!AppendFile(strGlobalConfigFile, AppDataFolder(),
                    OT_INIT_CONFIG_FILENAME))
        OT_FAIL;

    s_strGlobalConfigFile = strGlobalConfigFile;

    return s_strGlobalConfigFile;
}
FC_ARSTAT FC_CArFile::appendToFileRaw(HANDLE hFile)
{
    FC_ARSTAT ret;

    if(m_pParent->m_pAr->m_firstFatalError != FC_AR_OK)
        return FC_AR_ERR_INERROR;

    SetFilePointer(m_hData, m_dwOffset, NULL, FILE_BEGIN);
    ret = AppendFile(m_hData, hFile, m_dwBytesRaw);
    if(ret == FC_AR_IO_READ_FILE)
    {
        m_pParent->m_pAr->m_firstFatalError = FC_AR_CORRUPTED;
        return FC_AR_CORRUPTED;
    }
    return FC_AR_OK;

}
示例#8
0
/*---------------------------------------------------------------------------
                               CmdAppendFile
---------------------------------------------------------------------------*/
void CmdAppendFile( WNDATTR *wndattr )
{
 char *filename;


   FileDlg.cbSize = sizeof( FILEDLG );
   FileDlg.fl = FDS_CENTER | FDS_OPEN_DIALOG;

   WinFileDlg( HWND_DESKTOP, wndattr->Client, &FileDlg );

   filename = FileDlg.szFullFile;
   if (FileDlg.lReturn == DID_OK) {
      if (*filename != '\0') {
         AppendFile( wndattr, filename, TRUE, NULLHANDLE );
      }
   }

   return;
}
示例#9
0
文件: log.c 项目: superymk/tpmdos
void LogVerbose(char* fmt,...)
{
	va_list args;
	char temp_str[LOG_MSG_LENGTH] = { 0 };
    char final_str[LOG_MSG_LENGTH] = {0};
    char log_fn[MAX_FILEPATH_LEN];

	va_start (args, fmt);
	vsprintf (temp_str, fmt, args);
    
    GenerateFilePath (log_fn, VERBOSELOG_FILEPATH);
    GetCurrentTime(final_str);
    
    strcat(final_str, temp_str);
    final_str[LOG_MSG_LENGTH - 1] = '\0';
    
    AppendFile (log_fn, final_str, strlen(final_str));
    va_end(args);
}
示例#10
0
int CFileTar::CreateTar(char *TarFName, char *TarPath)
{
	char tarfullpath[_MAX_PATH];
	if(TarPath==NULL)
		strcpy(tarfullpath,FilePath);
	else
		strcpy(tarfullpath,TarPath);
	if(tarfullpath[strlen(tarfullpath)-1]!='\\')
		strcat(tarfullpath,"\\");
	strcat(tarfullpath,TarFName);
	int fdout;
	int ret;
	int i;
	if((fdout=_open(tarfullpath,_O_CREAT|_O_WRONLY|_O_BINARY|_O_TRUNC,
		_S_IWRITE))<0)
	{
		_close(fdout);
		return 1;
	}	
	ret=_write(fdout,&m_TarHeader,sizeof TarHeader);
	int ssize=m_TarHeader.GetCount()*sizeof (TarIndex)+sizeof(TarHeader);
	for(i=1;i<=m_TarHeader.GetCount();i++)
	{
		m_pTarIndex[i]->Start=ssize;
		ret=_write(fdout,m_pTarIndex[i],sizeof(TarIndex));
		ssize += m_pTarIndex[i]->Size;
	}
	for(i=1;i<=m_TarHeader.GetCount();i++)
	{
		char filetoadd[_MAX_PATH];
		strcpy(filetoadd,FilePath);
		strcat(filetoadd,m_pTarIndex[i]->FileName);		
		AppendFile(fdout,filetoadd);
	}
	
	_close(fdout);
	return 0;
}
示例#11
0
文件: sfs-copy.c 项目: mingpen/OpenNT
/*---------------------------------------------------------------------------------*/
 void SplitUtilityGroupRequests ( CCB_Header * h )
/*---------------------------------------------------------------------------------*/
   {
      switch ( h -> RequestCode )
	{
	   case AppendFileRequest:
	     AppendFile ( h );
	     break;

	   case CollateFilesRequest:
	     SplitCollateFilesRequests ( h );
	     break;

	   case CopyFileRequest:
             SfsCopyFile ( h );
	     break;

	   default:
	     NotifyAndActAsProper ( ErrorRequestNotSupported );
	     break;
	}
      return;
   }
示例#12
0
CDlgAbout::CDlgAbout(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CDlgAbout)
{
    ui->setupUi(this);
    CTool::SetWindowsGeometry(this);
 
    QString szVersion(tr("Version:%1.%2.%3.%4").arg(QString::number(REVISION_VERSION_NUMBER),
                                                 QString::number(MINOR_VERSION_NUMBER),
                                                 QString::number(REVISION_VERSION_NUMBER),
                                                 BUILD_VERSION
                                                    ));
    ui->lbVersion->setText(szVersion);
    ui->lbDate->setText(tr("Build date:%1 %2").arg(__DATE__, __TIME__));
    ui->lbAuthor->setText(tr("Author: KangLin\nEmail or MSN:[email protected]"));
    ui->lbHome->setOpenExternalLinks(true);
    ui->lbHome->setText(tr("Home page:") + "<a href=\"https://github.com/KangLin/rabbitim\">https://github.com/KangLin/rabbitim</a>");
    ui->lbCopyright->setText(tr(" Copyright (C) 2014 - %1 KangLin Studio").arg(QString::number(QDate::currentDate().year())));

    QString szFile;
#ifdef MOBILE
    szFile = ":/file/ChangeLog";
    AppendFile(ui->txtChange, szFile);
    szFile = ":/file/License";
    AppendFile(ui->txtLicense, szFile);
    szFile = ":/file/Authors";
    AppendFile(ui->txtThinks, szFile);
#else
    szFile = CGlobal::Instance()->GetDirApplication() + QDir::separator() + "ChangeLog.md";
    AppendFile(ui->txtChange, szFile);
    szFile = CGlobal::Instance()->GetDirApplication() + QDir::separator() + "License.md";
    AppendFile(ui->txtLicense, szFile);
    szFile = CGlobal::Instance()->GetDirApplication() + QDir::separator() + "Authors.txt";
    AppendFile(ui->txtThinks, szFile);
#endif
}
示例#13
0
文件: libnf.c 项目: Lukas955/nf-tools
/* only simple wrapper to nfdump function */
int lnf_open(lnf_file_t **lnf_filep, const char * filename, unsigned int flags, const char * ident) {
	int i;
	lnf_file_t *lnf_file;

	lnf_file = malloc(sizeof(lnf_file_t));
	
	if (lnf_file == NULL) {
		return LNF_ERR_NOMEM;
	}


	lnf_file->flags = flags;
	/* open file in either read only or write only mode */
#ifdef LNF_THREADS
   	pthread_mutex_lock(&lnf_nfdump_filter_mutex);
#endif
	if (flags & LNF_APPEND) {

		lnf_file->nffile = AppendFile((char *)filename);

	} else if (flags & LNF_WRITE) {

		lnf_file->nffile = OpenNewFile((char *)filename, NULL, flags & LNF_COMP, 
								flags & LNF_ANON, (char *)ident);

	} else {

		lnf_file->nffile = OpenFile((char *)filename, NULL);

	}
#ifdef LNF_THREADS
   	pthread_mutex_unlock(&lnf_nfdump_filter_mutex);
#endif

	if (lnf_file->nffile == NULL) {
		free(lnf_file);
		return LNF_ERR_OTHER;;
	}

	lnf_file->blk_record_remains = 0;
	lnf_file->processed_blocks  = 0;
	lnf_file->processed_bytes  = 0;
	lnf_file->skipped_blocks  = 0;
#ifdef LNF_THREADS
    pthread_mutex_lock(&lnf_nfdump_filter_mutex);
#endif
	lnf_file->extension_map_list = InitExtensionMaps(NEEDS_EXTENSION_LIST);

	lnf_file->lnf_map_list = NULL;

	i = 1;
	lnf_file->max_num_extensions = 0;
	while ( extension_descriptor[i++].id )
		lnf_file->max_num_extensions++;

#ifdef LNF_THREADS
    pthread_mutex_unlock(&lnf_nfdump_filter_mutex);
#endif

	*lnf_filep = lnf_file;

	return LNF_OK;
}
示例#14
0
ULONG CFormData::ProcessForm()
{
	CStringA startPart = "--" + CStringA(m_sBoundary) + "\r\n";
	Append(startPart);

	BOOL bHasFields = FALSE;

	//STLOG_WRITE("%s(%d): Ponto de apoio", __FUNCTION__, __LINE__);

	// Varrer os fields primeiro
	POSITION p1 = m_items.GetStartPosition();
	while(p1)
	{
		CStringW key1;
		CFormItem *pAttr;
		m_items.GetNextAssoc(p1, key1, pAttr);
		if(!pAttr->m_bFile)
		{
			bHasFields = TRUE;
			CStringW s;
			s.Format(FIELD_BOUND, pAttr->m_name, pAttr->m_value);
			Append(CStringA(s));
		}

		if(p1 != NULL)
		{
			startPart = "--" + CStringA(m_sBoundary) + "\r\n";
			Append(startPart);
		}
	}

	//STLOG_WRITE("%s(%d): Ponto de apoio", __FUNCTION__, __LINE__);

	BOOL bFirst = TRUE;
	// Varrer os files
	p1 = m_items.GetStartPosition();
	while(p1)
	{
		CStringW key1;
		CFormItem *pAttr;
		m_items.GetNextAssoc(p1, key1, pAttr);
		if(pAttr->m_bFile)
		{
			if(bFirst && bHasFields)
			{
				startPart = "--" + CStringA(m_sBoundary) + "\r\n";
				Append(startPart);
				bFirst = FALSE;
			}

			CStringW sFileName = pAttr->m_value;
			if(sFileName.Find('\\') >= 0 || sFileName.Find('/') >= 0)
			{
				int pos = sFileName.ReverseFind('\\');
				if(pos < 0)
					pos = sFileName.ReverseFind('/');

				sFileName = sFileName.Mid(pos+1);
			}

			CStringW s;
			s.Format(FILE_BOUND, pAttr->m_name, sFileName, pAttr->m_mime);
			Append(CStringA(s));

			Append("\r\n");

			AppendFile(pAttr->m_value);

			Append("\r\n");

			if(p1 != NULL)
			{
				startPart = "--" + CStringA(m_sBoundary) + "\r\n";
				Append(startPart);
			}
		}
	}

	startPart = "--" + CStringA(m_sBoundary) + "--\r\n";
	Append(startPart);

	//STLOG_WRITE("%s(%d): Ponto de apoio", __FUNCTION__, __LINE__);
	//STLOG_WRITE("%s(%d): Buffer: %s", __FUNCTION__, __LINE__, m_buffer.GetData());

	return m_buffer.GetCount();
}
示例#15
0
文件: bash.c 项目: axelmuhr/Helios-NG
int main(int argc, char *argv[])
{
  DIR *d;
  int c;
#ifdef SLEAKTEST
  int slt=0;
#endif

  cautious=0;  /* If set, we do a filesystem check after every operation */
  verbose=0;   /* If set, print out lots of info as we go along */
  releasingMem=0;  /* Memory situation is OK at the moment */


  if ( (safetyBlock=malloc(SAFETYBLOCKSIZE)) == NULL )
    {
      printf("No memory to allocate safety block!\n");
      exit(2);
    }

  for (c=1; c<argc; c++)
    if (!strcmp(argv[c], "-s"))
      {
	int seed=atoi(argv[++c]);
	srand(seed);
	printf("Random number generator seed set to %d\n", seed);
      }
    else if ( !strcmp(argv[c], "-cautious") || !strcmp(argv[c], "-c") )
      cautious=1;
    else if (!strcmp(argv[c], "-verbose") || !strcmp(argv[c], "-v") )
      verbose=1;
#ifdef SLEAKTEST
    else if (!strcmp(argv[c], "-slt"))
      slt=1;
#endif
    else
      {
#ifdef SLEAKTEST
	printf("Usage: %s [-s <seed>] -cautious -verbose -slt\n", argv[0]);
#else
	printf("Usage: %s [-s <seed>] -cautious -verbose\n", argv[0]);
#endif
	exit(2);
      }

  /* If the root directory doesn't yet exist, create it */
  if ( (d=opendir(ROOTDIR)) == NULL) 
  { if ( mkdir(ROOTDIR, S_IRWXU) )
    { printf("Can't create root directory %s\n", ROOTDIR);
      exit(2);
    }
  }
  else 
  { if ( closedir(d)!=0 )
    { printf("Can't close root directory %s - this shouldn't happen!",
	     ROOTDIR);
      exit(2);
    }
  }

  while (1)
  { int operation, veriFlag, am;
    Directory *dir, *subDir;

    fflush(stdout);

    veriFlag=1;

    /* First get a handle on some directory within the FS */

#if 0
    if ( ((d=opendir(ROOTDIR)) == NULL) )
    { printf("Can't open root directory %s\n", ROOTDIR);

      /* Assume that the open failed because we ran out of memory: */
      /* try to free some & carry on */
      free(safetyBlock);
      ReleaseMem();
      continue;
    }
#endif

    if ( (dir=malloc(sizeof(Directory))) == NULL)
    { printf("Can't allocate memory for root directory struct\n");
      
      /* Try to free some memory in case we've run out */
      free(safetyBlock);
      ReleaseMem();
      continue;
    }

    dir->DirLevel=0;
    dir->DirNumFiles=-1;  /* -1 means that we don't know how many files */
    dir->DirNumSub=-1;    /* and subdirectories this directory contains */
    strcpy(dir->DirPathName, ROOTDIR);
    if ( (subDir=TreeWander(dir)) == NULL )
      continue;

    /* If simply looking for storage leaks, loop executing TreeWander */
    /* but not calling the functions which modify the filesystem.     */

       
#ifdef SLEAKTEST
    if (!slt)
    {
#endif
    /* Now randomly choose an operation to perform on this directory or */
    /* its contents                                                     */
    operation=rand()*(LAST_OP+1)/RAND_MAX;

    /* Perform the operation - returns 0 if unsuccessful */

    if ( (operation>=OPS_DELETE_DIR_LOW) && 
	      (operation<=OPS_DELETE_DIR_HIGH) )
      veriFlag=DeleteDir(subDir);

    else if ( (operation>=OPS_DELETE_FILE_LOW) && 
	      (operation<=OPS_DELETE_FILE_HIGH) )
      veriFlag=DeleteFile(subDir);

    else if ((am=(word)Malloc(-5)) > MINMEMFREE) {
    	if ( (operation>=OPS_CREATE_FILE_LOW) && 
		 (operation<=OPS_CREATE_FILE_HIGH) )
	      veriFlag=CreateFile(subDir);

	    else if ( (operation>=OPS_APPEND_FILE_LOW) && 
		      (operation<=OPS_APPEND_FILE_HIGH) )
	      veriFlag=AppendFile(subDir);

	    else if ( (operation>=OPS_CREATE_DIR_LOW) && 
		      (operation<=OPS_CREATE_DIR_HIGH) )
	      veriFlag=CreateDir(subDir);
	}
	else if (verbose) printf("No create operations as available memory (%d) < %d'\n",am, MINMEMFREE);

    /* Even if none of the filesystem operations above have failed,  */
    /* we do filesystem checks at random intervals anyway.           */

    /* If we're running in 'cautious' mode we do a check after every */
    /* operation.                                                    */

    if (veriFlag != 0)
      veriFlag=rand()*(VERI_FREQ+1)/RAND_MAX;
    if (!veriFlag || cautious) 
      VerifyFS();

#ifdef SLEAKTEST
    }
#endif

    /* Tidy up before next iteration */
    free(subDir);
  }
}
示例#16
0
文件: hash.cpp 项目: weihuoya/gameswf
Res Hash::AppendFile(const string& filename) {
    return AppendFile(filename.c_str());
}
示例#17
0
 void HierTreeCtrl::OnCreateFile()
 {
     wxTreeItemId rootItem = GetRootItem();
     wxTreeItemId newItem = AppendFile(rootItem, "New File");
     EditLabel(newItem);
 }
示例#18
0
// 保存文件
bool CScpMedia::CScpFile::SaveData( const int index, const char * data, int len , MultiDesc *desc )
{
	// 先检测数据的正确性
	if ( data == NULL || len == 0 || index > _desc._total ){
		OUT_ERROR( NULL, 0, "ftp" , "file index %d total %d len %d" , index, _desc._total , len ) ;
		return false ;
	}

	_last = time(NULL) ;
	// 如果只有一个数据包直接保存
	if ( _desc._total == 1 ) {
		// 保存到本地文件目录
		if ( ! AppendFile( _desc._path.c_str(), data, len ) ) {
			OUT_ERROR( NULL, 0, "scpmedia" , "ftp save file to path %s failed" , _desc._path.c_str() ) ;
			return false ;
		}
		// 拷贝返回数据
		desc->Copy( _desc ) ;

		OUT_INFO( NULL, 0, "scpmedia" , "ftp save file path %s" , _desc._path.c_str() ) ;

		return true ;
	}
	// 如果索引值超过了最大包数则直接返回
	if ( index > (int)_vec.size() ) {
		OUT_ERROR( NULL, 0, "scpmedia" , "ftp save file index %d over max total %d" , index, _vec.size()  ) ;
		return false ;
	}
	// 取得索引值
	MemFile *p = _vec[index-1] ;
	if ( p->_ptr == NULL ) {
		// 如第一上传的数据才记录上传正确的包数
		++ _cur ;
		// 开辟新的空间
		p->_ptr    = new char[len] ;

	} else {
		// 如果这一次传上数据长度要大于上一次上传长度
		if ( p->_len < len ) {
			// 释放原来的内存
			delete [] p->_ptr ;
			p->_ptr   = new char[len] ;
		}
	}

	p->_len    = len ;
	p->_index  = index ;
	memcpy( p->_ptr, data, len ) ;

	if ( (int)_cur != _desc._total ) {
		OUT_INFO( NULL, 0, "scpmedia" , "scp save index file %d, current count %d total %d" , index, _cur, _desc._total ) ;
		return false ;
	}

	// 如果所有数据包都保存成功,则直接保存成文件
	for ( size_t i = 0; i < _vec.size(); ++ i ) {
		p = _vec[i] ;
		if ( p->_ptr == NULL || p->_len == 0 ){
			continue;
		}
		// 保存文件,处理文件各块
		AppendFile( _desc._path.c_str(), p->_ptr, p->_len ) ;
	}
	// 拷贝返回数据
	desc->Copy( _desc ) ;

	OUT_INFO( NULL, 0, "scpmedia" , "ftp save file path %s" , _desc._path.c_str() ) ;

	return true ;
}
示例#19
0
文件: compose.c 项目: mingpen/OpenNT
/*  DoAppend - append the passed messages and files to the message being composed
 *
 *  usage:
 *      Append <-m msg list> <-f[b] file name #1>...<-f file name #n>
 *
 *  arguments:
 *      hWnd        window for commands
 *      p           character pointer to beginning of arguments
 *      operation   TRUE => the Append command
 *                  FALSE => internal call, e.g. EnterComposer
 *
 *  return value:
 *      none.
 */
VOID PASCAL INTERNAL DoAppend ( HW hWnd, PSTR p, INT operation )
{
    FLAG        msgListApp = FALSE;
    FLAG        binaryApp = FALSE;
    FLAG        error = FALSE;
    UINT        flags;
    UCHAR       buffer [ MAXLINELEN ];
    UCHAR       optChar, modChar;

    if ( hCompose != NULL )
        SendMessage ( hCompose, CLOSEFILE, 0 );

    if ( operation && !*p )
        p = strPERIOD;

    while ( *( p = whiteskip (p)) != '\0' ) {
        error = TRUE;
        flags = F_FIXFROM;
        if ( *p == '-' || *p == '/' ) {
            optChar = *++p;
            modChar = *++p; /* either a blank or 'b' */
            p++;
            p = whiteskip (p);
        }
        else
            optChar = 'M';
        switch ( tolower ( optChar ) ) {
        case 'm' :
            if ( msgListApp )
                SendMessage ( hWnd, DISPLAY, "Only 1 message list allowed, extra ignored." );
            else if ( *p != '\0' ) {
                msgListApp = TRUE;
                strcpy ( buffer, p );
                *( whitescan ( buffer ) ) = '\0';
                if ( modChar != 'n' )
                    flags |= ( optChar == 'm' ) ? F_TABMSG : F_INDENTMSG;
                error = AppendMsgs ( hWnd, buffer, pCompFile, flags );
            }
            break;
        case 'f' :
            if ( *p != '\0' ) {
                strcpy ( buffer, p );
                *( whitescan ( buffer ) ) = '\0';
                if ( modChar != 'n' )
                    flags |= ( optChar == 'f' ) ? F_TABMSG : F_INDENTMSG;
                if ( modChar == ' ' || modChar == 'n' )
                    error = AppendFile ( hWnd, buffer, pCompFile, flags );
                else if ( tolower ( modChar ) == 'b' && !binaryApp ) {
                    error = AppendBinary ( buffer, pCompFile );
                    SendMessage(hWnd, DISPLAY, buffer);  // BUGBUG: debug code
                    SendMessage(hWnd, DISPLAY, pCompFile);  // BUGBUG: debug code
                    binaryApp = TRUE;
                }
            }
            break;
        default :
            break;
        }
        p = whitescan ( p );
        if ( error ) {
            SendMessage ( hWnd, DISPLAY, "Error in append list, not all were appended." );
            break;
        }
    }

    if ( hCompose != NULL )
        SendMessage ( hCompose, REOPNFILE, 1 );
}
示例#20
0
int main(int argc, char *argv[])
{
    RLOG_FILE_HEADER header;
    RLOG_State_list *pState;

    int nNumInputs;
    IRLOG_IOStruct *pInput;
    IRLOG_IOStruct **ppInput;

    int nMaxRank = 0;
    int nMinRank = MAX_RANK;
    int nNumStates = 0;
    int type, length;
    int nMaxLevel = 0;
    int nNumLevels = 0;
    int nTotalNumEvents = 0;
    int nNumEvents;
    RecursionStruct *pLevel;
    FILE *fout;
    int i, j;
    int nRank;

    if (argc < 3)
    {
	MPL_error_printf("Usage:\nirlog2rlog out.rlog in0.irlog in1.irlog ...\nirlog2rlog out.rlog n\n");
	return 0;
    }

    if (argc == 3 && IsNumber(argv[2]))
    {
	GenerateNewArgv(&argc, &argv, atoi(argv[2]));
    }

    nNumInputs = argc - 2;

    /* open the output rlog file */
    fout = fopen(argv[1], "wb");
    if (fout == NULL)
    {
	MPL_error_printf("unable to open output file '%s'\n", argv[1]);
	return -1;
    }

    /* read the arrows from all the files in order */
    ppInput = (IRLOG_IOStruct**)MPL_malloc(nNumInputs * sizeof(IRLOG_IOStruct*));
    for (i=0; i<nNumInputs; i++)
    {
	ppInput[i] = IRLOG_CreateInputStruct(argv[i+2]);
	if (ppInput[i] == NULL)
	{
	    MPL_error_printf("Unable to create an input structure for '%s', skipping\n", argv[i+2]);
	}
    }
    for (i=0; i<nNumInputs; i++)
    {
	if (ppInput[i] == NULL)
	{
	    for (j=i; j<nNumInputs-1; j++)
		ppInput[j] = ppInput[j+1];
	    nNumInputs--;
	    i--;
	}
    }
    MPL_msg_printf("reading the arrows from all the input files.\n");fflush(stdout);
    ReadAllArrows(ppInput, nNumInputs);

    nNumInputs = argc - 2;

    /* read, parse and save all the data from the irlog files */
    for (i=0; i<nNumInputs; i++)
    {
	pInput = IRLOG_CreateInputStruct(argv[i+2]);
	if (pInput == NULL)
	{
	    MPL_error_printf("Unable to create an input structure for '%s', skipping\n", argv[i+2]);
	}
	else
	{
	    MPL_msg_printf("reading irlog file: %s\n", argv[i+2]);fflush(stdout);
	    for(;;)
	    {
		switch (pInput->header.type)
		{
		case RLOG_STATE_TYPE:
		    SaveState(&pInput->record.state);
		    break;
		case RLOG_COMM_TYPE:
		    nMaxRank = (pInput->record.comm.rank > nMaxRank) ? pInput->record.comm.rank : nMaxRank;
		    nMinRank = (pInput->record.comm.rank < nMinRank) ? pInput->record.comm.rank : nMinRank;
		    break;
		case RLOG_IARROW_TYPE:
		    /* SaveArrow(&pInput->record.iarrow); */
		    break;
		case RLOG_EVENT_TYPE:
		    SaveEvent(&pInput->record.event);
		    break;
		default:
		    MPL_error_printf("Unknown irlog record type: %d\n", pInput->header.type);
		    break;
		}
		
		if (IRLOG_GetNextRecord(pInput))
		{
		    IRLOG_CloseInputStruct(&pInput);
		    break;
		}
	    }
	}
    }

    /* set the fields in the header */
    header.nMinRank = FindMinRank(g_pLevel);
    header.nMaxRank = FindMaxRank(g_pLevel);
    if (nMinRank != header.nMinRank)
	MPL_error_printf("minimum event rank %d does not equal the minimum comm record rank %d\n", header.nMinRank, nMinRank);
    if (nMaxRank != header.nMaxRank)
	MPL_error_printf("maximum event rank %d does not equal the maximum comm record rank %d\n", header.nMaxRank, nMaxRank);

    /* write header */
    MPL_msg_printf("writing header.\n");fflush(stdout);
    type = RLOG_HEADER_SECTION;
    length = sizeof(RLOG_FILE_HEADER);
    /* fwrite(&type, sizeof(int), 1, fout); */
    WriteFileData(&type, sizeof(int), fout);
    /* fwrite(&length, sizeof(int), 1, fout);*/
    WriteFileData(&length, sizeof(int), fout);
    /* fwrite(&header, sizeof(RLOG_FILE_HEADER), 1, fout); */
    WriteFileData(&header, sizeof(RLOG_FILE_HEADER), fout);

    /* write states */
    if (g_pList)
    {
	MPL_msg_printf("writing states.\n");fflush(stdout);
    }
    pState = g_pList;
    while (pState)
    {
	nNumStates++;
	pState = pState->next;
    }
    type = RLOG_STATE_SECTION;
    length = nNumStates * sizeof(RLOG_STATE);
    /* fwrite(&type, sizeof(int), 1, fout); */
    WriteFileData(&type, sizeof(int), fout);
    /* fwrite(&length, sizeof(int), 1, fout); */
    WriteFileData(&length, sizeof(int), fout);
    pState = g_pList;
    while (pState)
    {
	/* fwrite(pState, sizeof(RLOG_STATE), 1, fout); */
	WriteFileData(pState, sizeof(RLOG_STATE), fout);
	pState = pState->next;
    }

    /* write arrows */
    if (g_fArrow)
    {
	MPL_msg_printf("writing arrows.\n");fflush(stdout);
	type = RLOG_ARROW_SECTION;
	length = ftell(g_fArrow);
	/* fwrite(&type, sizeof(int), 1, fout); */
	WriteFileData(&type, sizeof(int), fout);
	/* fwrite(&length, sizeof(int), 1, fout); */
	WriteFileData(&length, sizeof(int), fout);
	AppendFile(fout, g_fArrow);
    }

    /* write events */
    while (g_pLevel)
    {
	pLevel = FindMinLevel(g_pLevel);
	nNumLevels = FindMaxRecursion(g_pLevel, pLevel->rank);
	nRank = pLevel->rank;

	/* count the events for this rank */
	nNumEvents = 0;
	for (i=0; i<nNumLevels; i++)
	{
	    pLevel = GetLevel(pLevel->rank, i);
	    nNumEvents += pLevel->num_events;
	}
	/* write an event section for this rank */
	type = RLOG_EVENT_SECTION;
	length = sizeof(int) + sizeof(int) + (nNumLevels * sizeof(int)) + (nNumEvents * sizeof(RLOG_EVENT));
	/* fwrite(&type, sizeof(int), 1, fout); */
	WriteFileData(&type, sizeof(int), fout);
	/* fwrite(&length, sizeof(int), 1, fout); */
	WriteFileData(&length, sizeof(int), fout);
        /* fwrite(&nRank, sizeof(int), 1, fout); */
	WriteFileData(&nRank, sizeof(int), fout);
	/* fwrite(&nNumLevels, sizeof(int), 1, fout); */
	WriteFileData(&nNumLevels, sizeof(int), fout);
	for (i=0; i<nNumLevels; i++)
	{
	    pLevel = GetLevel(nRank, i);
	    /* fwrite(&pLevel->num_events, sizeof(int), 1, fout); */
	    WriteFileData(&pLevel->num_events, sizeof(int), fout);
	}
	for (i=0; i<nNumLevels; i++)
	{
	    MPL_msg_printf("writing event level %d:%d\n", nRank, i);fflush(stdout);
	    pLevel = GetLevel(nRank, i);
	    AppendFile(fout, pLevel->fout);
	}
	/* remove this rank from the list of levels */
	RemoveLevel(nRank);
    }

    /* free resources */
    while (g_pList)
    {
	pState = g_pList;
	g_pList = g_pList->next;
	MPL_free(pState);
    }
    if (g_fArrow)
    {
	fclose(g_fArrow);
	unlink(g_pszArrowFilename);
    }

    if (s_bFreeArgv)
	MPL_free(argv);

    return 0;
}
FC_ARSTAT FC_CArchive::writeToTmp(
    const void* pvData,
    const TCHAR*pszDiskFile,
    DWORD*      pdwBytes,
    DWORD*      pdwOffset,
    HANDLE*     phFileTmp
)
{

    if(m_firstFatalError != FC_AR_OK)
        return FC_AR_ERR_INERROR;


    if(m_hFileTmpPut == INVALID_HANDLE_VALUE)
    {
        //open tmp file:
        m_szTmpPutFile.load(m_fileName);
        if(!MakeTmpAr(m_szTmpPutFile))
        {
            SetLastError(TYPE_E_CANTCREATETMPFILE);
            m_lastIOErrFile.load(m_szTmpPutFile);
            m_firstFatalError = FC_AR_IO_WRITE_FILE;
            return FC_AR_IO_WRITE_FILE;
        }

        m_hFileTmpPut =  CreateFile(
                             m_szTmpPutFile,              // file name
                             GENERIC_WRITE|
                             GENERIC_READ,                // access mode
                             FILE_SHARE_READ|
                             FILE_SHARE_WRITE,            // share mode
                             NULL,                        // SD
                             CREATE_ALWAYS,               // how to create
                             FILE_FLAG_SEQUENTIAL_SCAN|
                             FILE_ATTRIBUTE_TEMPORARY |
                             FILE_FLAG_DELETE_ON_CLOSE,   // file attributes
                             NULL                         // handle to template file
                         );

        if(m_hFileTmpPut == INVALID_HANDLE_VALUE)
        {
            m_lastIOErrFile.load(m_szTmpPutFile);
            m_firstFatalError = FC_AR_IO_WRITE_FILE;
            return FC_AR_IO_WRITE_FILE;
        }

        assert(m_dwTmpPutCurrPos==0);
        m_dwTmpPutCurrPos = 0;
    }

    //write to disk and remember the offset in FC_CArFile:
    //aways seek to the eof, file pointer colud have changed
    //if a newly inserted file has been re-read:
    SetFilePointer(m_hFileTmpPut, m_dwTmpPutCurrPos, NULL, FILE_BEGIN);



    if(pszDiskFile)
    {
        HANDLE hFileDisk;

        //open file and check max file size:
        hFileDisk  = CreateFile(pszDiskFile,GENERIC_READ,FILE_SHARE_READ,NULL,
                                OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,NULL);

        if(hFileDisk==INVALID_HANDLE_VALUE)
        {
            m_lastIOErrFile.load(pszDiskFile);
            return FC_AR_IO_READ_FILE;
        }

        *pdwBytes  = GetFileSize(hFileDisk, NULL);
        if (*pdwBytes == 0xFFFFFFFF)
        {
            m_lastIOErrFile.load(pszDiskFile);
            CloseHandle(hFileDisk);
            return FC_AR_IO_READ_FILE;
        }

        if(this->m_bDoEncodeData)
        {
            char* pDecoded = new char[*pdwBytes?*pdwBytes:1];//may be file size 0, cannot alloc 0 chars...
            DWORD dw;
            if(!ReadFile(hFileDisk, pDecoded, *pdwBytes, &dw, NULL) || *pdwBytes!=dw)
            {
                delete(pDecoded);
                CloseHandle(hFileDisk);
                return FC_AR_IO_READ_FILE;
            }
            char* pEncoded = new char[*pdwBytes + 64];
            DWORD nEncoded;
            FC_DESEncodeBlock(FC_DES_NORMAL, FC_AR_PW, pDecoded, *pdwBytes, pEncoded, &nEncoded);

            CloseHandle(hFileDisk);
            delete(pDecoded);

            *pdwBytes = nEncoded;

            if(!WrtFile(m_hFileTmpPut, pEncoded, nEncoded))
            {
                delete (pEncoded);
                m_firstFatalError = FC_AR_IO_WRITE_FILE;
                m_lastIOErrFile.load(m_szTmpPutFile);
                return FC_AR_IO_WRITE_FILE;
            }
            delete (pEncoded);
        }
        else
        {
            FC_ARSTAT ret = AppendFile(hFileDisk, m_hFileTmpPut, *pdwBytes);
            CloseHandle(hFileDisk);
            if(ret!=FC_AR_OK)
            {
                m_firstFatalError = FC_AR_IO_WRITE_FILE;
                m_lastIOErrFile.load(ret==FC_AR_IO_READ_FILE ? pszDiskFile : m_szTmpPutFile);
                return ret;
            }
        }
    }
    else
    {
        if(this->m_bDoEncodeData)
        {
            char* pEncoded = new char[*pdwBytes + 64];
            DWORD nEncoded;
            FC_DESEncodeBlock(FC_DES_NORMAL, FC_AR_PW, (const char*)pvData, *pdwBytes, pEncoded, &nEncoded);

            *pdwBytes = nEncoded;

            if(!WrtFile(m_hFileTmpPut, pEncoded, nEncoded))
            {
                delete (pEncoded);
                m_firstFatalError = FC_AR_IO_WRITE_FILE;
                m_lastIOErrFile.load(m_szTmpPutFile);
                return FC_AR_IO_WRITE_FILE;
            }
            delete (pEncoded);
        }
        else if(!WrtFile(m_hFileTmpPut, pvData, *pdwBytes))
        {
            m_firstFatalError = FC_AR_IO_WRITE_FILE;
            m_lastIOErrFile.load(m_szTmpPutFile);
            return FC_AR_IO_WRITE_FILE;
        }
    }


    *pdwOffset = m_dwTmpPutCurrPos;
    *phFileTmp = m_hFileTmpPut;
    m_dwTmpPutCurrPos += *pdwBytes;

    return FC_AR_OK;
}