1fd592007cbabfa8162d463f0c6a019fd535bf14
[util-vserver.git] / src / parserpmdump.c
1 // $Id: parserpmdump.c,v 1.1 2003/09/29 22:01:57 ensc Exp $
2
3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on parserpmdump.cc by Jacques Gelinas
5 //  
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10 //  
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //  
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 /*
21         Litte utility to extract non config file from
22         an rpm --dump command.
23 */
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <sys/stat.h>
28 #include <alloca.h>
29
30
31 int main (int argc, char *argv[])
32 {
33         int     *tblen = alloca(argc * sizeof(int));
34         int     i;
35         char tmp[1000];
36
37         for (i=1; i<argc; i++) tblen[i] = strlen(argv[i]);
38         while (fgets(tmp,sizeof(tmp)-1,stdin)!=NULL){
39                 int i;
40                 // Check if the file is in an excluded directory
41                 for (i=1; i<argc; i++){
42                         if (strncmp(argv[i],tmp,tblen[i])==0) break;
43                 }
44                 if (i == argc){
45                         // Ok no match
46                         int last = strlen(tmp)-1;
47                         mode_t  mode=-1;
48                         int type=-1;
49                         char *start = tmp;
50                         int     i;
51                         
52                         if (last >= 0 && tmp[last] == '\n') tmp[last] = '\0';
53
54                         for (i=0; i<8; i++){
55                                 char *pt = start;
56                                 while (*pt > ' ') pt++;
57                                 if (*pt == ' ') *pt++ = '\0';
58                                 if (i == 4){
59                                         sscanf(start,"%o",&mode);
60                                 }else if (i==7){
61                                         type = atoi(start);
62                                 }
63                                 start = pt;
64                                         
65                         }                       
66                         if (S_ISREG(mode) && type == 0) printf ("%s\n",tmp);
67                 }
68         }
69         return 0;
70 }
71