gwenhywfar  4.99.8beta
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  GWEN_DB_NODE *db;
24  const char *aname;
25  GWEN_SAR *sr;
26  int rv;
27  const GWEN_ARGS args[]={
28  {
29  GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
30  GWEN_ArgsType_Char, /* type */
31  "archive", /* name */
32  1, /* minnum */
33  1, /* maxnum */
34  "a", /* short option */
35  "archive", /* long option */
36  "Specify the archive file name", /* short description */
37  "Specify the archive file name" /* long description */
38  },
39  {
41  GWEN_ArgsType_Int, /* type */
42  "help", /* name */
43  0, /* minnum */
44  0, /* maxnum */
45  "h", /* short option */
46  "help", /* long option */
47  "Show this help screen", /* short description */
48  "Show this help screen" /* long description */
49  }
50  };
51 
52  db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
53  rv=GWEN_Args_Check(argc, argv, 1,
55  args,
56  db);
57  if (rv==GWEN_ARGS_RESULT_ERROR) {
58  fprintf(stderr, "ERROR: Could not parse arguments\n");
59  return 1;
60  }
61  else if (rv==GWEN_ARGS_RESULT_HELP) {
62  GWEN_BUFFER *ubuf;
63 
64  ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
65  if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
66  fprintf(stderr, "ERROR: Could not create help string\n");
67  return 1;
68  }
69  fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
70  GWEN_Buffer_free(ubuf);
71  return 0;
72  }
73 
74  aname=GWEN_DB_GetCharValue(db, "archive", 0, NULL);
75  assert(aname);
76 
77  sr=GWEN_Sar_new();
78  rv=GWEN_Sar_OpenArchive(sr, aname,
81  if (rv<0) {
82  fprintf(stderr, "ERROR: Error opening archive (%d)\n", rv);
83  return 2;
84  }
85  else {
86  const GWEN_SAR_FILEHEADER_LIST *fhl;
87 
88  fhl=GWEN_Sar_GetHeaders(sr);
89  if (fhl) {
90  const GWEN_SAR_FILEHEADER *fh;
91 
93  while(fh) {
94  const char *s;
95 
97  fprintf(stdout, "%s\n", s?s:"(noname)");
98 
100  }
101  }
102 
103  rv=GWEN_Sar_CloseArchive(sr, 0);
104  if (rv<0) {
105  fprintf(stderr, "ERROR: Error closing archive (%d)\n", rv);
106  return 2;
107  }
108 
109  return 0;
110  }
111 }
112 
113 
114 
115 
116 
117 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:223
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:176
#define NULL
Definition: binreloc.c:290
const GWEN_SAR_FILEHEADER_LIST * GWEN_Sar_GetHeaders(GWEN_SAR *sr)
Definition: sar.c:1796
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:38
#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:897
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:1260
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:83
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:41
#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:130
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