Browse Source

Sync

Author: jgg
Date: 1998-09-26 05:34:18 GMT
Sync
tags/debian/0.7.21
Arch Librarian 17 years ago
parent
commit
e1b74f61df
11 changed files with 187 additions and 128 deletions
  1. +38
    -1
      apt-pkg/contrib/cmndline.cc
  2. +6
    -2
      apt-pkg/contrib/cmndline.h
  3. +9
    -9
      apt-pkg/contrib/configuration.cc
  4. +3
    -3
      apt-pkg/init.cc
  5. +2
    -2
      apt-pkg/makefile
  6. +2
    -1
      apt-pkg/orderlist.cc
  7. +19
    -17
      apt-pkg/pkgcachegen.cc
  8. +14
    -5
      buildlib/config.h.in
  9. +1
    -0
      buildlib/environment.mak.in
  10. +81
    -87
      cmdline/apt-cache.cc
  11. +12
    -1
      configure.in

+ 38
- 1
apt-pkg/contrib/cmndline.cc View File

@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: cmndline.cc,v 1.1 1998/09/22 05:30:26 jgg Exp $
// $Id: cmndline.cc,v 1.2 1998/09/26 05:34:24 jgg Exp $
/* ######################################################################

Command Line Class - Sophisticated command line parser
@@ -22,6 +22,14 @@
CommandLine::CommandLine(Args *AList,Configuration *Conf) : ArgList(AList),
Conf(Conf), FileList(0)
{
}
/*}}}*/
// CommandLine::~CommandLine - Destructor /*{{{*/
// ---------------------------------------------------------------------
/* */
CommandLine::~CommandLine()
{
delete [] FileList;
}
/*}}}*/
// CommandLine::Parse - Main action member /*{{{*/
@@ -29,6 +37,7 @@ CommandLine::CommandLine(Args *AList,Configuration *Conf) : ArgList(AList),
/* */
bool CommandLine::Parse(int argc,const char **argv)
{
delete [] FileList;
FileList = new const char *[argc];
const char **Files = FileList;
int I;
@@ -99,6 +108,10 @@ bool CommandLine::Parse(int argc,const char **argv)
if (A->end() == true)
return _error->Error("Command line option %s is not understood",argv[I]);
// The option is not boolean
if (A->IsBoolean() == false)
return _error->Error("Command line option %s is not boolean",argv[I]);
}
// Deal with it.
@@ -164,6 +177,19 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[],
// Parse a configuration file
if ((A->Flags & ConfigFile) == ConfigFile)
return ReadConfigFile(*Conf,Argument);

// Arbitary item specification
if ((A->Flags & ArbItem) == ArbItem)
{
const char *J;
for (J = Argument; *J != 0 && *J != '='; J++);
if (*J == 0)
return _error->Error("Option %s: Configuration item sepecification must have an =.",argv[I]);

Conf->Set(string(Argument,J-Argument),string(J+1));
return true;
}
Conf->Set(A->ConfName,Argument);
return true;
@@ -278,3 +304,14 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[],
return true;
}
/*}}}*/
// CommandLine::FileSize - Count the number of filenames /*{{{*/
// ---------------------------------------------------------------------
/* */
unsigned int CommandLine::FileSize() const
{
unsigned int Count = 0;
for (const char **I = FileList; I != 0 && *I != 0; I++)
Count++;
return Count;
}
/*}}}*/

+ 6
- 2
apt-pkg/contrib/cmndline.h View File

@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: cmndline.h,v 1.1 1998/09/22 05:30:26 jgg Exp $
// $Id: cmndline.h,v 1.2 1998/09/26 05:34:25 jgg Exp $
/* ######################################################################

Command Line Class - Sophisticated command line parser
@@ -67,15 +67,18 @@ class CommandLine
IntLevel = (1 << 1),
Boolean = (1 << 2),
InvBoolean = (1 << 3),
ConfigFile = (1 << 4) | HasArg
ConfigFile = (1 << 4) | HasArg,
ArbItem = (1 << 5) | HasArg
};

const char **FileList;
bool Parse(int argc,const char **argv);
void ShowHelp();
unsigned int FileSize() const;
CommandLine(Args *AList,Configuration *Conf);
~CommandLine();
};

struct CommandLine::Args
@@ -86,6 +89,7 @@ struct CommandLine::Args
unsigned long Flags;
inline bool end() {return ShortOpt == 0 && LongOpt == 0;};
inline bool IsBoolean() {return Flags == 0 || (Flags & (Boolean|InvBoolean)) != 0;};
};
#endif

+ 9
- 9
apt-pkg/contrib/configuration.cc View File

@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: configuration.cc,v 1.4 1998/09/22 05:30:26 jgg Exp $
// $Id: configuration.cc,v 1.5 1998/09/26 05:34:26 jgg Exp $
/* ######################################################################

Configuration Class
@@ -156,17 +156,17 @@ bool Configuration::FindB(const char *Name,bool Default)
if (End == Itm->Value.c_str() || Res < 0 || Res > 1)
{
// Check for positives
if (strcasecmp(Itm->Value,"no") == 0 ||
strcasecmp(Itm->Value,"false") == 0 ||
strcasecmp(Itm->Value,"without") == 0 ||
strcasecmp(Itm->Value,"disable") == 0)
if (strcasecmp(Itm->Value.c_str(),"no") == 0 ||
strcasecmp(Itm->Value.c_str(),"false") == 0 ||
strcasecmp(Itm->Value.c_str(),"without") == 0 ||
strcasecmp(Itm->Value.c_str(),"disable") == 0)
return false;
// Check for negatives
if (strcasecmp(Itm->Value,"no") == 0 ||
strcasecmp(Itm->Value,"false") == 0 ||
strcasecmp(Itm->Value,"without") == 0 ||
strcasecmp(Itm->Value,"disable") == 0)
if (strcasecmp(Itm->Value.c_str(),"yes") == 0 ||
strcasecmp(Itm->Value.c_str(),"true") == 0 ||
strcasecmp(Itm->Value.c_str(),"with") == 0 ||
strcasecmp(Itm->Value.c_str(),"enable") == 0)
return false;
return Default;


+ 3
- 3
apt-pkg/init.cc View File

@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: init.cc,v 1.5 1998/09/22 05:30:24 jgg Exp $
// $Id: init.cc,v 1.6 1998/09/26 05:34:19 jgg Exp $
/* ######################################################################

Init - Initialize the package library
@@ -38,8 +38,8 @@ bool pkgInitialize(Configuration &Cnf)
// Cache
Cnf.Set("Dir::Cache","/tmp/");
Cnf.Set("Dir::Cache::archives","archives/");
Cnf.Set("Dir::Cache::srcpkgcache","srcpkgcache");
Cnf.Set("Dir::Cache::pkgcache","pkgcache");
Cnf.Set("Dir::Cache::srcpkgcache","srcpkgcache.bin");
Cnf.Set("Dir::Cache::pkgcache","pkgcache.bin");
// Configuration
Cnf.Set("Dir::Etc","/etc/apt/");


+ 2
- 2
apt-pkg/makefile View File

@@ -11,8 +11,8 @@ include ../buildlib/defaults.mak

# The library name
LIBRARY=apt-pkg
MAJOR=2
MINOR=0.0
MAJOR=2.0
MINOR=0
SLIBS=$(PTHREADLIB)

# Source code for the contributed non-core things


+ 2
- 1
apt-pkg/orderlist.cc View File

@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: orderlist.cc,v 1.2 1998/07/12 23:58:28 jgg Exp $
// $Id: orderlist.cc,v 1.3 1998/09/26 05:34:21 jgg Exp $
/* ######################################################################

Order List - Represents and Manipulates an ordered list of packages.
@@ -402,6 +402,7 @@ bool pkgOrderList::VisitProvides(DepIterator D)
bool pkgOrderList::VisitNode(PkgIterator Pkg)
{
// Looping or irrelevent.
// This should probably trancend not installed packages
if (Pkg.end() == true || IsFlag(Pkg,Added) == true ||
IsFlag(Pkg,AddPending) == true || IsFlag(Pkg,InList) == false)
return true;


+ 19
- 17
apt-pkg/pkgcachegen.cc View File

@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: pkgcachegen.cc,v 1.16 1998/09/18 02:42:38 jgg Exp $
// $Id: pkgcachegen.cc,v 1.17 1998/09/26 05:34:23 jgg Exp $
/* ######################################################################
Package Cache Generator - Generator for the cache structure.
@@ -323,6 +323,7 @@ bool pkgCacheGenerator::SelectFile(string File,unsigned long Flags)
CurrentFile->mtime = Buf.st_mtime;
CurrentFile->NextFile = Cache.HeaderP->FileList;
CurrentFile->Flags = Flags;
CurrentFile->ID = Cache.HeaderP->PackageFileCount;
PkgFileName = File;
Cache.HeaderP->FileList = CurrentFile - Cache.PkgFileP;
Cache.HeaderP->PackageFileCount++;
@@ -382,10 +383,25 @@ bool pkgSrcCacheCheck(pkgSourceList &List)
{
if (_error->PendingError() == true)
return false;
// Open the source package cache

string CacheFile = _config->FindDir("Dir::Cache::srcpkgcache");
string ListDir = _config->FindDir("Dir::State::lists");

// Count the number of missing files
int Missing = 0;
for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
{
string File = ListDir + URItoFileName(I->PackagesURI());
struct stat Buf;
if (stat(File.c_str(),&Buf) != 0)
{
_error->WarningE("stat","Couldn't stat source package list '%s' (%s)",
I->PackagesInfo().c_str(),File.c_str());
Missing++;
}
}
// Open the source package cache
if (FileExists(CacheFile) == false)
return false;
@@ -410,20 +426,6 @@ bool pkgSrcCacheCheck(pkgSourceList &List)
return false;
}

// Count the number of missing files
int Missing = 0;
for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
{
string File = ListDir + URItoFileName(I->PackagesURI());
struct stat Buf;
if (stat(File.c_str(),&Buf) != 0)
{
_error->WarningE("stat","Couldn't stat source package list '%s' (%s)",
I->PackagesInfo().c_str(),File.c_str());
Missing++;
}
}
// They are certianly out of sync
if (Cache.Head().PackageFileCount != List.size() - Missing)
return false;


+ 14
- 5
buildlib/config.h.in View File

@@ -4,17 +4,17 @@
byte first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN

/* The number of bytes in a unsigned char. */
#undef SIZEOF_UNSIGNED_CHAR
/* The number of bytes in a usigned char. */
#undef SIZEOF_CHAR

/* The number of bytes in a unsigned int. */
#undef SIZEOF_UNSIGNED_INT
#undef SIZEOF_INT

/* The number of bytes in a unsigned long. */
#undef SIZEOF_UNSIGNED_LONG
#undef SIZEOF_LONG

/* The number of bytes in a unsigned short. */
#undef SIZEOF_UNSIGNED_SHORT
#undef SIZEOF_SHORT

/* Define if we have libgpm. */
#undef HAVE_LIBGPM
@@ -24,3 +24,12 @@

/* Define if we have the X11 windowing system. */
#undef HAVE_X11

/* Define the architecture name string */
#undef ARCHITECTURE

/* The version number string */
#undef VERSION

/* The package name string */
#undef PACKAGE

+ 1
- 0
buildlib/environment.mak.in View File

@@ -24,3 +24,4 @@ X11LIB = @X11LIB@
GPMLIB = @GPMLIB@
SLANGLIB = @SLANGLIB@
XPMLIB = @XPMLIB@
PTHREADLIB = @PTHREADLIB@

+ 81
- 87
cmdline/apt-cache.cc View File

@@ -1,23 +1,14 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: apt-cache.cc,v 1.7 1998/09/22 05:30:30 jgg Exp $
// $Id: apt-cache.cc,v 1.8 1998/09/26 05:34:29 jgg Exp $
/* ######################################################################
apt-cache - Manages the cache file.
apt-cache - Manages the cache files
This program should eventually handle both low and high level
manipulation of the cache file. Depending how far things go it
might get quite a sophisticated UI.
Currently the command line is as follows:
apt-cache add cache file1:dist:ver file2:dist:ver ...
ie:
apt-cache add ./cache Pacakges:hamm:1.0

A usefull feature is 'upgradable' ie
apt-cache upgradable ./cache
will list .debs that should be installed to make all packages the latest
version.
apt-cache provides some functions fo manipulating the cache files.
It uses the command line interface common to all the APT tools. The
only really usefull function right now is dumpavail which is used
by the dselect method. Everything else is ment as a debug aide.
Returns 100 on failure, 0 on success.
@@ -33,52 +24,20 @@
#include <apt-pkg/cmndline.h>

#include <iostream.h>
#include <fstream.h>

#include <config.h>
/*}}}*/

string CacheFile;

// SplitArg - Split the triple /*{{{*/
// ---------------------------------------------------------------------
/* */
bool SplitArg(const char *Arg,string &File,string &Dist,string Ver)
{
const char *Start = Arg;
const char *I = Arg;
for (;*I != 0 && *I != ':'; I++);
if (*I != ':')
return _error->Error("Malformed argument %s, must be in file:dist:rev form",Arg);
File = string(Start,I - Start);

I++;
Start = I;
for (;*I != 0 && *I != ':'; I++);
if (*I != ':')
return _error->Error("Malformed argument %s, must be in file:dist:rev form",Arg);
Dist = string(Start,I - Start);
I++;
Start = I;
for (;*I != 0 && *I != ':'; I++);
if (I == Start)
return _error->Error("Malformed argument %s, must be in file:dist:rev form",Arg);
Ver = string(Start,I - Start);

return true;
}
/*}}}*/
// DumpPackage - Show a dump of a package record /*{{{*/
// ---------------------------------------------------------------------
/* */
bool DumpPackage(pkgCache &Cache,int argc,const char *argv[])
bool DumpPackage(pkgCache &Cache,CommandLine &CmdL)
{
for (int I = 0; I != argc; I++)
for (const char **I = CmdL.FileList + 1; *I != 0; I++)
{
pkgCache::PkgIterator Pkg = Cache.FindPkg(argv[I]);
pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
if (Pkg.end() == true)
{
_error->Warning("Unable to locate package %s",argv[0]);
_error->Warning("Unable to locate package %s",*I);
continue;
}

@@ -256,14 +215,14 @@ bool DumpAvail(pkgCache &Cache)
// DoAdd - Perform an adding operation /*{{{*/
// ---------------------------------------------------------------------
/* */
bool DoAdd(int argc,const char *argv[])
bool DoAdd(CommandLine &CmdL)
{
string FileName;
string Dist;
string Ver;
// Make sure there is at least one argument
if (CmdL.FileSize() <= 1)
return _error->Error("You must give at least one file name");
// Open the cache
FileFd CacheF(CacheFile,FileFd::WriteEmpty);
FileFd CacheF(_config->FindDir("Dir::Cache::srcpkgcache"),FileFd::ReadOnly);
if (_error->PendingError() == true)
return false;
@@ -276,19 +235,18 @@ bool DoAdd(int argc,const char *argv[])
if (_error->PendingError() == true)
return false;

for (int I = 0; I != argc; I++)
unsigned long Length = CmdL.FileSize() - 1;
for (const char **I = CmdL.FileList + 1; *I != 0; I++)
{
Progress.OverallProgress(I,argc,1,"Generating cache");
if (SplitArg(argv[I],FileName,Dist,Ver) == false)
return false;
Progress.OverallProgress(I - CmdL.FileList,Length,1,"Generating cache");
// Do the merge
FileFd TagF(FileName.c_str(),FileFd::ReadOnly);
FileFd TagF(*I,FileFd::ReadOnly);
debListParser Parser(TagF);
if (_error->PendingError() == true)
return _error->Error("Problem opening %s",FileName.c_str());
return _error->Error("Problem opening %s",*I);
if (Gen.SelectFile(FileName) == false)
if (Gen.SelectFile(*I) == false)
return _error->Error("Problem with SelectFile");
if (Gen.MergeList(Parser) == false)
@@ -312,46 +270,83 @@ bool GenCaches()
return pkgMakeStatusCache(List,Progress);
}
/*}}}*/
// ShowHelp - Show a help screen /*{{{*/
// ---------------------------------------------------------------------
/* */
int ShowHelp()
{
cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
" compiled on " << __DATE__ << " " << __TIME__ << endl;
cout << "Usage: apt-cache [options] command" << endl;
cout << " apt-cache [options] add file1 [file1 ...]" << endl;
cout << " apt-cache [options] showpkg pkg2 [pkg2 ...]" << endl;
cout << endl;
cout << "apt-cache is a low-level tool used to manipulate APT's binary" << endl;
cout << "cache files stored in " << _config->FindDir("Dir::Cache") << endl;
cout << "It is not ment for ordinary use only as a debug aide." << endl;
cout << endl;
cout << "Commands:" << endl;
cout << " add - Add an package file to the source cache" << endl;
cout << " gencaches - Build both the package and source cache" << endl;
cout << " showpkg - Show some general information for a single package" << endl;
cout << " stats - Show some basic statistics" << endl;
cout << " dump - Show the entire file in a terse form" << endl;
cout << " dumpavail - Print an available file to stdout" << endl;
cout << endl;
cout << "Options:" << endl;
cout << " -h This help text." << endl;
cout << " -p=? The package cache. [" << _config->FindDir("Dir::Cache::pkgcache") << ']' << endl;
cout << " -s=? The source cache. [" << _config->FindDir("Dir::Cache::srcpkgcache") << ']' << endl;
cout << " -q Disable progress indicator. " << endl;
cout << " -c=? Read this configuration file" << endl;
cout << " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl;
cout << "See the apt-cache(8) and apt.conf(8) manual pages for more information." << endl;
return 100;
}
/*}}}*/

int main(int argc,const char *argv[])
{
CommandLine::Args Args[] = {
{'h',"help","help",0},
{'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg},
{'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg},
{'q',"quiet","quiet",CommandLine::IntLevel},
{'c',"config-file",0,CommandLine::ConfigFile},
{'o',"option",0,CommandLine::ArbItem},
{0,0,0,0}};
CommandLine Cmds(Args,_config);
// Parse the command line and initialize the package library
CommandLine CmdL(Args,_config);
if (pkgInitialize(*_config) == false ||
Cmds.Parse(argc,argv) == false)
CmdL.Parse(argc,argv) == false)
{
_error->DumpErrors();
return 100;
}
cout << _config->Find("help") << endl;
// Check arguments.
if (argc < 3)
{
cerr << "Usage is apt-cache add cache file1:dist:ver file2:dist:ver ..." << endl;
return 100;
}

// See if the help should be shown
if (_config->FindB("help") == true ||
CmdL.FileSize() == 0)
return ShowHelp();
while (1)
{
CacheFile = argv[2];
if (strcmp(argv[1],"add") == 0)
if (strcmp(CmdL.FileList[0],"add") == 0)
{
DoAdd(argc - 3,argv + 3);
DoAdd(CmdL);
break;
}

if (strcmp(argv[1],"gencaches") == 0)
if (strcmp(CmdL.FileList[0],"gencaches") == 0)
{
GenCaches();
break;
}

// Open the cache file
FileFd CacheF(CacheFile,FileFd::ReadOnly);
FileFd CacheF(_config->FindDir("Dir::Cache::pkgcache"),FileFd::ReadOnly);
if (_error->PendingError() == true)
break;
@@ -363,32 +358,31 @@ int main(int argc,const char *argv[])
if (_error->PendingError() == true)
break;
if (strcmp(argv[1],"showpkg") == 0)
if (strcmp(CmdL.FileList[0],"showpkg") == 0)
{
CacheFile = argv[2];
DumpPackage(Cache,argc - 3,argv + 3);
DumpPackage(Cache,CmdL);
break;
}

if (strcmp(argv[1],"stats") == 0)
if (strcmp(CmdL.FileList[0],"stats") == 0)
{
Stats(Cache);
break;
}
if (strcmp(argv[1],"dump") == 0)
if (strcmp(CmdL.FileList[0],"dump") == 0)
{
Dump(Cache);
break;
}
if (strcmp(argv[1],"dumpavail") == 0)
if (strcmp(CmdL.FileList[0],"dumpavail") == 0)
{
DumpAvail(Cache);
break;
}
_error->Error("Invalid operation %s", argv[1]);
_error->Error("Invalid operation %s", CmdL.FileList[0]);
break;
}


+ 12
- 1
configure.in View File

@@ -12,6 +12,10 @@ AC_INIT(configure.in)
AC_CONFIG_AUX_DIR(buildlib)
AC_CONFIG_HEADER(include/config.h:buildlib/config.h.in)

dnl -- SET THIS TO THE RELEASE VERSION --
AC_DEFINE_UNQUOTED(VERSION,"0.3.0")
AC_DEFINE_UNQUOTED(PACKAGE,"apt")

dnl Tom's host stuff
tl_CHECK_TOOL_PREFIX dnl Initial guess

@@ -54,6 +58,13 @@ if test "$with_gpm" != "no"; then
AC_SUBST(GPMLIB)
fi

dnl Checks for pthread
AC_CHECK_LIB(pthread, pthread_create,[AC_DEFINE(HAVE_PTHREAD) PTHREADLIB="-lpthread"])
AC_SUBST(PTHREADLIB)
if test "$XPMLIB" != "-lXpm"; then
AC_MSG_ERROR(failed: I need posix threads, pthread)
fi

dnl Converts the ARCH to be the same as dpkg
AC_MSG_CHECKING(system architecture)
archset="`awk '$1 == "'$host_cpu'" { print $2 }' $srcdir/buildlib/archtable`"
@@ -61,7 +72,7 @@ if test "x$archset" = "x"; then
AC_MSG_ERROR(failed: use --host=)
fi
AC_MSG_RESULT($archset)
AC_DEFINE_UNQUOTED(PKG_DEB_ARCH,"$archset")
AC_DEFINE_UNQUOTED(ARCHITECTURE,"$archset")

dnl Check the sizes etc. of the architecture
changequote(,)


Loading…
Cancel
Save