RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: rpm/rpmio/ Makefile.am tmagic.c

From: Jeff Johnson <jbj@rpm5.org>
Date: Tue 31 Jul 2007 - 20:25:33 CEST
Message-Id: <20070731182533.3A1EE34844A@rpm5.org>
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
  Module: rpm                              Date:   31-Jul-2007 20:25:33
  Branch: HEAD                             Handle: 2007073119253300

  Added files:
    rpm/rpmio               tmagic.c
  Modified files:
    rpm/rpmio               Makefile.am

  Log:
    toy magic dispatch harness.

  Summary:
    Revision    Changes     Path
    1.103       +4  -1      rpm/rpmio/Makefile.am
    1.1         +83 -0      rpm/rpmio/tmagic.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/rpmio/Makefile.am
  ============================================================================
  $ cvs diff -u -r1.102 -r1.103 Makefile.am
  --- rpm/rpmio/Makefile.am	29 Jul 2007 14:02:34 -0000	1.102
  +++ rpm/rpmio/Makefile.am	31 Jul 2007 18:25:33 -0000	1.103
  @@ -6,7 +6,7 @@
   
   EXTRA_DIST = tax.c tdir.c tfts.c tget.c thkp.c tput.c tglob.c tinv.c tkey.c trpmio.c lookup3.c librpmio.vers
   
  -EXTRA_PROGRAMS = tax tdir tfts tget thkp tmacro tput tglob tinv tkey trpmio tsw dumpasn1 lookup3
  +EXTRA_PROGRAMS = tax tdir tfts tget thkp tmacro tput tglob tinv tkey tmagic trpmio tsw dumpasn1 lookup3
   
   AM_CPPFLAGS = \
   	-I$(srcdir) \
  @@ -116,6 +116,9 @@
   tmacro.o:  macro.c
   	$(COMPILE) -DDEBUG_MACROS -o $@ -c $<
   
  +tmagic_SOURCES = tmagic.c
  +tmagic_LDADD = $(RPM_LDADD)
  +
   tput_SOURCES = tput.c
   tput_LDADD = $(RPM_LDADD)
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/tmagic.c
  ============================================================================
  $ cvs diff -u -r0 -r1.1 tmagic.c
  --- /dev/null	2007-07-31 20:22:00 +0200
  +++ tmagic.c	2007-07-31 20:25:33 +0200
  @@ -0,0 +1,83 @@
  +#include "system.h"
  +
  +#include <rpmio_internal.h>
  +#include <rpmmessages.h>
  +#include <rpmmacro.h>
  +#include <popt.h>
  +
  +#include "magic.h"
  +
  +#include "debug.h"
  +
  +static int _debug = 0;
  +
  +#define	FNPATH		"tmagic.test"
  +static char * fnpath = FNPATH;
  +
  +static void readFile(const char * path)
  +{
  +    FD_t fd;
  +
  +fprintf(stderr, "===== %s\n", path);
  +    fd = Fopen(path, "r");
  +    if (fd != NULL) {
  +	char buf[BUFSIZ];
  +	size_t len = Fread(buf, 1, sizeof(buf), fd);
  +	int xx;
  +        xx = Fclose(fd);
  +
  +	if (len > 0)
  +	    fwrite(buf, 1, len, stderr);
  +    }
  +}
  +
  +static struct poptOption optionsTable[] = {
  + { "debug", 'd', POPT_ARG_VAL,	&_debug, -1,		NULL, NULL },
  + { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
  +	N_("debug protocol data stream"), NULL},
  + { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
  +	N_("debug rpmio I/O"), NULL},
  + { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
  +	N_("debug URL cache handling"), NULL},
  + { "verbose", 'v', 0, 0, 'v',				NULL, NULL },
  +  POPT_AUTOHELP
  +  POPT_TABLEEND
  +};
  +
  +int
  +main(int argc, const char *argv[])
  +{
  +    poptContext optCon = poptGetContext(argv[0], argc, argv, optionsTable, 0);
  +    int msflags = MAGIC_CHECK;
  +    magic_t ms = NULL;
  +    const char * magicfile = NULL;
  +    int rc;
  +    int xx;
  +
  +    while ((rc = poptGetNextOpt(optCon)) > 0) {
  +	switch (rc) {
  +	case 'v':
  +	    rpmIncreaseVerbosity();
  +	    /*@switchbreak@*/ break;
  +	default:
  +            /*@switchbreak@*/ break;
  +	}
  +    }
  +
  +    ms = magic_open(msflags);
  +assert(ms);
  +    xx = magic_load(ms, magicfile);
  +
  +    if (_debug) {
  +	rpmIncreaseVerbosity();
  +	rpmIncreaseVerbosity();
  +    }
  +
  +    readFile(fnpath);
  +
  +    if (ms)
  +	magic_close(ms);
  +/*@i@*/ urlFreeCache();
  +
  +    return 0;
  +}
  @@ .
Received on Tue Jul 31 20:25:33 2007
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.