gwenhywfar  5.10.1
gsa/create.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 createArchive(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_CreateArchive(sr, aname);
80  if (rv<0) {
81  fprintf(stderr, "ERROR: Error creating archive (%d)\n", rv);
82  return 2;
83  }
84 
85  rv=GWEN_Sar_CloseArchive(sr, 0);
86  if (rv<0) {
87  fprintf(stderr, "ERROR: Error closing archive (%d)\n", rv);
88  return 2;
89  }
90 
91 
92  return 0;
93 }
94 
95 
96 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
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
#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
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
int createArchive(GWEN_DB_NODE *dbArgs, int argc, char **argv)
Definition: gsa/create.c:22
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_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
int GWEN_Sar_CreateArchive(GWEN_SAR *sr, const char *aname)
Definition: sar.c:92
#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