File: DBrm.c

package info (click to toggle)
dazzdb 1.0%2Bgit20180908.0bd5e07-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 536 kB
  • sloc: ansic: 9,177; makefile: 200
file content (65 lines) | stat: -rw-r--r-- 1,484 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/********************************************************************************************
 *
 *  Remove a list of .db databases
 *     Delete all the files for the given data bases <name>.db ... (there are a couple
 *     of hidden . files for each DB, and these are removed too.)  Do not use "rm" to
 *     remove a database.
 *
 *  Author:  Gene Myers
 *  Date  :  July 2013
 *
 ********************************************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "DB.h"

static char *Usage = "[-v] <path:db|dam> ... ";

static int VERBOSE;

static void HANDLER(char *path, char *exten)
{ (void) exten;
  if (unlink(path) != 0)
    fprintf(stderr,"%s: [WARNING] Couldn't delete file %s\n",Prog_Name,path);
  else if (VERBOSE)
    fprintf(stderr,"  Deleting %s\n",path);
}

int main(int argc, char *argv[])
{
  //  Process arguments

  { int  i, j, k;
    int  flags[128];

    ARG_INIT("DBrm")

    j = 1;
    for (i = 1; i < argc; i++)
      if (argv[i][0] == '-')
        { ARG_FLAGS("v") }
      else
        argv[j++] = argv[i];
    argc = j;

    VERBOSE = flags['v'];

    if (argc <= 1)
      { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
        exit (1);
      }
  }

  { int i;

    for (i = 1; i < argc; i++)
      if (List_DB_Files(argv[i],HANDLER) < 0)
        fprintf(stderr,"%s: [WARNING] Could not find database %s\n",Prog_Name,argv[i]);
  }

  exit (0);
}