pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/rpm2pkg Update "rpm2pkg" package to version 2...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/1d996cc501bf
branches:  trunk
changeset: 469019:1d996cc501bf
user:      tron <tron%pkgsrc.org@localhost>
date:      Wed Feb 18 21:29:37 2004 +0000

description:
Update "rpm2pkg" package to version 2.0. Changes since version 1.3:
- added support for RPM archive compress with bzip2 as used by e.g.
  SuSE Linux 8.2.
- (hopefully) made portable
- rewrote ugly code for handling "-s" command line option
- converted source to KNF

diffstat:

 pkgtools/rpm2pkg/Makefile        |    21 +-
 pkgtools/rpm2pkg/files/rpm2pkg.c |  1440 +++++++++++++++++++++----------------
 2 files changed, 824 insertions(+), 637 deletions(-)

diffs (truncated from 1609 to 300 lines):

diff -r 089b3a04dbf6 -r 1d996cc501bf pkgtools/rpm2pkg/Makefile
--- a/pkgtools/rpm2pkg/Makefile Wed Feb 18 21:29:10 2004 +0000
+++ b/pkgtools/rpm2pkg/Makefile Wed Feb 18 21:29:37 2004 +0000
@@ -1,13 +1,12 @@
-# $NetBSD: Makefile,v 1.21 2004/02/08 04:03:15 jlam Exp $
+# $NetBSD: Makefile,v 1.22 2004/02/18 21:29:37 tron Exp $
 
-DISTNAME=      rpm2pkg-1.3
-PKGREVISION=                   1
+DISTNAME=      rpm2pkg-2.0
 CATEGORIES=    pkgtools
 MASTER_SITES=  # empty
 DISTFILES=     # empty
 
 MAINTAINER=    tron%NetBSD.org@localhost
-HOMEPAGE=      ftp://ftp.NetBSD.org/pub/NetBSD/packages/pkgsrc/Packages.txt
+HOMEPAGE=      http://www.netbsd.org/Documentation/pkgsrc/
 COMMENT=       Convert RPM archives to NetBSD packages
 
 CONFLICTS+=    suse-base<=6.4
@@ -16,17 +15,25 @@
 USE_BUILDLINK2=        YES
 NO_CHECKSUM=   YES
 
-CFLAGS+=       ${BUILDLINK_CPPFLAGS.rpm}
-LIBS=          -lrpm -lintl -lz
+CPPFLAGS+=     ${BUILDLINK_CPPFLAGS.bzip2} ${BUILDLINK_CPPFLAGS.rpm} \
+               ${BUILDLINK_CPPFLAGS.zlib}
+LIBS=          -lrpm -lintl -lz -lbz2
+
+.include "../../mk/bsd.prefs.mk"
+
+.if (${CC} == gcc)
+CFLAGS+=       -Wall
+.endif
 
 do-build:
-       ${CC} ${CFLAGS} ${LDFLAGS} -o ${WRKSRC}/rpm2pkg \
+       ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -o ${WRKSRC}/rpm2pkg \
                ${FILESDIR}/rpm2pkg.c ${LIBS}
 
 do-install:
        ${INSTALL_PROGRAM} ${WRKSRC}/rpm2pkg ${PREFIX}/sbin
        ${INSTALL_MAN} ${FILESDIR}/rpm2pkg.8 ${PREFIX}/man/man8
 
+.include "../../archivers/bzip2/buildlink2.mk"
 .include "../../devel/zlib/buildlink2.mk"
 .include "../../misc/rpm/buildlink2.mk"
 
diff -r 089b3a04dbf6 -r 1d996cc501bf pkgtools/rpm2pkg/files/rpm2pkg.c
--- a/pkgtools/rpm2pkg/files/rpm2pkg.c  Wed Feb 18 21:29:10 2004 +0000
+++ b/pkgtools/rpm2pkg/files/rpm2pkg.c  Wed Feb 18 21:29:37 2004 +0000
@@ -1,8 +1,36 @@
-/*
+/*     $NetBSD: rpm2pkg.c,v 1.4 2004/02/18 21:29:37 tron Exp $ */
 
-       $NetBSD: rpm2pkg.c,v 1.3 2002/12/09 15:16:27 tron Exp $
-
-*/
+/*-
+ * Copyright (c) 2004 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matthias Scheler.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -14,10 +42,27 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <cpio.h>
+#include <bzlib.h>
 #include <rpmlib.h>
 #include <zlib.h>
 
+#define C_IRUSR                        0000400
+#define C_IWUSR                        0000200
+#define C_IXUSR                        0000100
+#define C_IRGRP                        0000040
+#define C_IWGRP                        0000020
+#define C_IXGRP                        0000010
+#define C_IROTH                        0000004
+#define C_IWOTH                        0000002
+#define C_IXOTH                        0000001
+#define C_ISUID                        0004000
+#define C_ISGID                        0002000
+#define C_ISVTX                        0001000
+#define C_ISDIR                        0040000
+#define C_ISREG                        0100000
+#define C_ISCHR                        0020000
+#define C_ISLNK                        0120000
+ 
 char CPIOMagic[] = {'0','7','0','7','0','1'};
 
 #define CPIO_END_MARKER                "TRAILER!!!"
@@ -31,726 +76,861 @@
 
 #define CP_IFMT                        0170000
 
-#define TRUE  1
-#define FALSE 0
+#define        TRUE    1
+#define        FALSE   0
 
-#define GZREAD(s,b,l) (gzread((s),(b),(l))==l)
-
-extern char *__progname;
+typedef struct ModeMapStruct {
+       unsigned long   mm_CPIOMode;
+       mode_t          mm_SysMode;
+} ModeMap;
 
-struct ModeMap
- {
-  long   mm_CPIOMode;
-  mode_t mm_SysMode;
- };
-struct ModeMap ModeMapTab[] =
- {
-  {C_IRUSR,S_IRUSR},
-  {C_IWUSR,S_IWUSR},
-  {C_IXUSR,S_IXUSR},
-  {C_IRGRP,S_IRGRP},
-  {C_IWGRP,S_IWGRP},
-  {C_IXGRP,S_IXGRP},
-  {C_IROTH,S_IROTH},
-  {C_IWOTH,S_IWOTH},
-  {C_IXOTH,S_IXOTH},
-  {C_ISUID,S_ISUID},
-  {C_ISGID,S_ISGID},
-  {C_ISVTX,S_ISVTX},
-  {0,0}
- };
+ModeMap ModeMapTab[] = {
+       {C_IRUSR, S_IRUSR},
+       {C_IWUSR, S_IWUSR},
+       {C_IXUSR, S_IXUSR},
+       {C_IRGRP, S_IRGRP},
+       {C_IWGRP, S_IWGRP},
+       {C_IXGRP, S_IXGRP},
+       {C_IROTH, S_IROTH},
+       {C_IWOTH, S_IWOTH},
+       {C_IXOTH, S_IXOTH},
+       {C_ISUID, S_ISUID},
+       {C_ISGID, S_ISGID},
+       {C_ISVTX, S_ISVTX},
+       {0, 0}
+};
 
 typedef struct PListEntryStruct PListEntry;
-struct PListEntryStruct
- {
-  PListEntry *pe_Childs[2];
-  int pe_DirEmpty;
-  mode_t pe_DirMode;
-  long pe_INode;
-  char *pe_Link;
-  char pe_Name[1];
- };
+struct PListEntryStruct {
+       PListEntry      *pe_Childs[2];
+       int             pe_DirEmpty;
+       mode_t          pe_DirMode;
+       unsigned long   pe_INode;
+       char            *pe_Link;
+       char            pe_Name[1];
+};
 
-#define pe_Left  pe_Childs[0]
-#define pe_Right pe_Childs[1]
+#define        pe_Left         pe_Childs[0]
+#define        pe_Right        pe_Childs[1]
 
 typedef void PListEntryFunc(PListEntry *,FILE *);
 
-#define PLIST_ORDER_FORWARD  0
-#define PLIST_ORDER_BACKWARD 1
-
-PListEntry *InsertPListEntry(PListEntry **Tree,char *Name)
+#define        PLIST_ORDER_FORWARD     0
+#define        PLIST_ORDER_BACKWARD    1
 
-{
- PListEntry *Node;
-
- while ((Node=*Tree)!=NULL)
-  Tree=&((strcmp(Name,Node->pe_Name)<0)?Node->pe_Left:Node->pe_Right);
+#define INVERT_PLIST_ORDER(o)  (1 - (o))
 
- if ((Node=malloc(sizeof(PListEntry)+strlen(Name)))==NULL)
-  {
-   perror(__progname);
-   exit(EXIT_FAILURE);
-  }
+typedef struct FileHandleStruct {
+       FILE    *fh_File;
+       BZFILE  *fh_BZFile;
+       gzFile  *fh_GZFile;
+       off_t   fh_Pos;
+} FileHandle;
 
- Node->pe_Left=NULL;
- Node->pe_Right=NULL;
- Node->pe_DirEmpty=FALSE;
- Node->pe_INode=0;
- Node->pe_Link=NULL;
- (void)strcpy(Node->pe_Name,Name);
-
- return *Tree=Node;
+static int
+InitBuffer(void **Buffer,int *BufferSize)
+{
+       if (*Buffer == NULL) {
+               *BufferSize = sysconf(_SC_PAGESIZE) * 256;
+               if ((*Buffer = malloc(*BufferSize)) == NULL)
+                       return FALSE;
+       }
+       return TRUE;
 }
 
-PListEntry *FindPListEntry(PListEntry *Tree,char *Name)
-
-{
- while (Tree!=NULL)
-  {
-   int Result;
-
-   if ((Result=strcmp(Name,Tree->pe_Name))==0) break;
-   Tree=(Result<0)?Tree->pe_Left:Tree->pe_Right;
-  }
-
- return Tree;
-}
-
-void PListEntryFile(PListEntry *Node,FILE *Out)
-
+static void
+Close(FileHandle *fh)
 {
- (void)fputs(Node->pe_Name,Out);
- (void)fputc('\n',Out);
-}
-
-void PListEntryLink(PListEntry *Node,FILE *Out)
+       if (fh->fh_BZFile != NULL) {
+               int     bzerror;
 
-{
- (void)fprintf(Out,"@exec ln -fs %s %%D/%s\n",Node->pe_Link,Node->pe_Name);
- (void)fprintf(Out,"@unexec rm -f %%D/%s\n",Node->pe_Name);
-}
-
-void PListEntryMakeDir(PListEntry *Node,FILE *Out)
-
-{
- if (Node->pe_DirEmpty)
-  (void)fprintf(Out,
-                "@exec mkdir -m %o -p %%D/%s\n",
-                Node->pe_DirMode,
-                Node->pe_Name);
+               (void)BZ2_bzReadClose(&bzerror, fh->fh_BZFile);
+               (void)fclose(fh->fh_File);
+       } else {
+               (void)gzclose(fh->fh_GZFile);
+       }
+       free(fh);
 }
 
-void PListEntryRemoveDir(PListEntry *Node,FILE *Out)
-
-{
- (void)fprintf(Out,"@dirrm %s\n",Node->pe_Name);
-}



Home | Main Index | Thread Index | Old Index