gwenhywfar  5.10.1
tools/gsa/list.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Sat Jun 25 2011
3  copyright : (C) 2011 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * Please see toplevel file COPYING for license details *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 #include "globals.h"
15 
16 #include <gwenhywfar/debug.h>
17 #include <gwenhywfar/sar.h>
18 
19 
20 
21 
22 int listArchive(GWEN_DB_NODE *dbArgs, int argc, char **argv)
23 {
24  GWEN_DB_NODE *db;
25  const char *aname;
26  GWEN_SAR *sr;
27  int rv;
28  const GWEN_ARGS args[]= {
29  {
30  GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
31  GWEN_ArgsType_Char, /* type */
32  "archive", /* name */
33  1, /* minnum */
34  1, /* maxnum */
35  "a", /* short option */
36  "archive", /* long option */
37  "Specify the archive file name", /* short description */
38  "Specify the archive file name" /* long description */
39  },
40  {
42  GWEN_ArgsType_Int, /* type */
43  "help", /* name */
44  0, /* minnum */
45  0, /* maxnum */
46  "h", /* short option */
47  "help", /* long option */
48  "Show this help screen", /* short description */
49  "Show this help screen" /* long description */
50  }
51  };
52 
53  db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
54  rv=GWEN_Args_Check(argc, argv, 1,
56  args,
57  db);
58  if (rv==GWEN_ARGS_RESULT_ERROR) {
59  fprintf(stderr, "ERROR: Could not parse arguments\n");
60  return 1;
61  }
62  else if (rv==GWEN_ARGS_RESULT_HELP) {
63  GWEN_BUFFER *ubuf;
64 
65  ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
66  if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
67  fprintf(stderr, "ERROR: Could not create help string\n");
68  return 1;
69  }
70  fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
71  GWEN_Buffer_free(ubuf);
72  return 0;
73  }
74 
75  aname=GWEN_DB_GetCharValue(db, "archive", 0, NULL);
76  assert(aname);
77 
78  sr=GWEN_Sar_new();
79  rv=GWEN_Sar_OpenArchive(sr, aname,
82  if (rv<0) {
83  fprintf(stderr, "ERROR: Error opening archive (%d)\n", rv);
84  return 2;
85  }
86  else {
87  const GWEN_SAR_FILEHEADER_LIST *fhl;
88 
89  fhl=GWEN_Sar_GetHeaders(sr);
90  if (fhl) {
91  const GWEN_SAR_FILEHEADER *fh;
92 
94  while (fh) {
95  const char *s;
96 
98  fprintf(stdout, "%s\n", s?s:"(noname)");
99 
101  }
102  }
103 
104  rv=GWEN_Sar_CloseArchive(sr, 0);
105  if (rv<0) {
106  fprintf(stderr, "ERROR: Error closing archive (%d)\n", rv);
107  return 2;
108  }
109 
110  return 0;
111  }
112 }
113 
114 
115 
116 
117 
118 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
int listArchive(GWEN_DB_NODE *dbArgs, int argc, char **argv)
#define GWEN_SYNCIO_FILE_FLAGS_READ
Definition: syncio_file.h:53
GWEN_SAR * GWEN_Sar_new(void)
Definition: sar.c:50
int GWEN_Sar_CloseArchive(GWEN_SAR *sr, int abandon)
Definition: sar.c:181
#define NULL
Definition: binreloc.c:300
const GWEN_SAR_FILEHEADER_LIST * GWEN_Sar_GetHeaders(GWEN_SAR *sr)
Definition: sar.c:1837
GWEN_SAR_FILEHEADER * GWEN_SarFileHeader_List_Next(const GWEN_SAR_FILEHEADER *element)
#define GWEN_ARGS_FLAGS_HELP
Definition: src/base/args.h:52
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
#define GWEN_ARGS_RESULT_HELP
Definition: src/base/args.h:58
#define GWEN_ARGS_RESULT_ERROR
Definition: src/base/args.h:57
GWEN_SAR_FILEHEADER * GWEN_SarFileHeader_List_First(const GWEN_SAR_FILEHEADER_LIST *l)
int GWEN_Args_Usage(const GWEN_ARGS *args, GWEN_BUFFER *ubuf, GWEN_ARGS_OUTTYPE ot)
#define GWEN_ARGS_MODE_ALLOW_FREEPARAM
Definition: src/base/args.h:54
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition: db.c:971
struct GWEN_SAR_FILEHEADER GWEN_SAR_FILEHEADER
GWEN_DB_NODE * GWEN_DB_GetGroup(GWEN_DB_NODE *n, uint32_t flags, const char *path)
Definition: db.c:1381
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
#define GWEN_ARGS_FLAGS_LAST
Definition: src/base/args.h:51
int GWEN_Sar_OpenArchive(GWEN_SAR *sr, const char *aname, GWEN_SYNCIO_FILE_CREATIONMODE cm, uint32_t acc)
Definition: sar.c:134
int GWEN_Args_Check(int argc, char **argv, int startAt, uint32_t mode, const GWEN_ARGS *args, GWEN_DB_NODE *db)
Definition: src/base/args.c:45
const char * GWEN_SarFileHeader_GetPath(const GWEN_SAR_FILEHEADER *p_struct)
#define GWEN_ARGS_FLAGS_HAS_ARGUMENT
Definition: src/base/args.h:50
#define GWEN_DB_FLAGS_DEFAULT
Definition: db.h:168
struct GWEN_SAR GWEN_SAR
Definition: sar.h:37