1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 1, or (at your option)
** any later version.
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Author : Alexandre Parenteau <aubonbeurre@hotmail.com> --- December 1997
*/
/*
* MultiFiles.h --- class to store multiple files by directory
*/
#include "stdafx.h"
#include <stdlib.h>
#include <string.h>
#include "MultiFiles.h"
#include "CvsArgs.h"
#include "AppConsole.h"
#include "CPStr.h"
#include "AppGlue.h"
#include <errno.h>
#ifdef WIN32
# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
static char THIS_FILE[] = __FILE__;
# endif
#endif /* WIN32 */
void MultiFilesEntry::setdir(const char *newdir)
{
dir = newdir;
}
void MultiFilesEntry::add(const char *file, const UFSSpec *spec, const char *currRevision)
{
FileEntry entry(file, spec, currRevision);
files.push_back(entry);
}
void MultiFiles::newdir(const char *dir)
{
MultiFilesEntry entry(dir);
dirs.push_back(dir);
}
void MultiFiles::newfile(const char *file, const UFSSpec *spec, const char *currRevision)
{
if(dirs.size() == 0)
return;
MultiFilesEntry & entry = dirs[dirs.size() - 1];
entry.add(file, spec, currRevision);
}
bool MultiFiles::next(void)
{
if(pos == -1)
pos = 0;
else
{
// only the mac uses MultiFiles for now in such a fashion.
// it also means that cvs should be finished with the last round.
++pos;
if((size_t)pos < dirs.size())
WaitForCvs();
}
return (size_t)pos < dirs.size();
}
char *MultiFiles::add(CvsArgs & args)
{
if(pos < 0 || (size_t)pos >= dirs.size())
return 0L;
MultiFilesEntry & entry = dirs[pos];
std::vector<FileEntry>::const_iterator i;
for(i = entry.files.begin(); i != entry.files.end(); ++i)
{
args.addfile((*i).file, entry.dir, &(*i).spec, (*i).currRev);
}
return entry.dir;
}
bool MultiFiles::get (int index, CStr & path, CStr & fileName, CStr &currRev)
{
if(pos < 0 || (size_t)pos >= dirs.size())
return false;
MultiFilesEntry & entry = dirs[pos];
if(index < 0 || (size_t)index >= entry.files.size())
return false;
path = entry.dir;
fileName = entry.files[index].file;
currRev = entry.files[index].currRev;
return true;
}
int MultiFiles::NumFiles(void) const
{
int locpos = pos;
if(locpos == -1)
locpos = 0;
if((size_t)locpos >= dirs.size())
return 0;
const MultiFilesEntry & entry = dirs[locpos];
return entry.files.size();
}
void MultiFiles::reset()
{
dirs.erase(dirs.begin(), dirs.end());
pos = -1;
}
|