~ubuntu-branches/ubuntu/natty/ncdu/natty

« back to all changes in this revision

Viewing changes to src/exclude.c

  • Committer: Bazaar Package Importer
  • Author(s): Eugene V. Lyubimkin
  • Date: 2009-10-12 13:36:53 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091012133653-fnkpopxwkqo6yu2a
Tags: 1.5-1
* New maintainer. Thanks for work, Luca Bedogni. (Closes: #550266)
  - Fixed segfault on empty directory. (Closes: #472294)
  - Use IEEE 1541 GiB not GB units. (Closes: #539553)
* New upstream release. (Closes: #522307, #531845)
* debian/patches:
  - Removed, all fixes applied upstream.
* debian/rules:
  - Rewritten using debhelper 7.
* debian/control:
  - Bumped build-dependency on debhelper to (>= 7).
  - Dropped weird build-dependency on debconf.
  - Dropped build-dependency on dpatch.
  - Bumped Standards-Version to 3.8.3, no changes needed.
  - Tiny capitalness correction in the long description.
* debian/compat:
  - Bumped to 7.
* debian/watch:
  - Removed auto-uupdate command, useless for me.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* ncdu - NCurses Disk Usage 
2
2
    
3
 
  Copyright (c) 2007 Yoran Heling
 
3
  Copyright (c) 2007-2009 Yoran Heling
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
23
23
 
24
24
*/
25
25
 
26
 
#include "ncdu.h"
 
26
#include "exclude.h"
 
27
 
 
28
#include <stdio.h>
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
#include <fnmatch.h>
27
32
 
28
33
 
29
34
struct exclude {
30
35
  char *pattern;
31
36
  struct exclude *next;
32
 
};
33
 
 
34
 
struct exclude *excludes = NULL,
35
 
               *last = NULL;
36
 
 
37
 
 
38
 
 
39
 
void addExclude(char *pat) {
40
 
  struct exclude *n;
41
 
 
42
 
  n = (struct exclude *) malloc(sizeof(struct exclude));
43
 
  n->pattern = (char *) malloc(strlen(pat)+1);
44
 
  strcpy(n->pattern, pat);
45
 
  n->next = NULL;
46
 
 
47
 
  if(excludes == NULL) {
48
 
    excludes = n;
49
 
    last = excludes;
50
 
  } else {
51
 
    last->next = n;
52
 
    last = last->next;
53
 
  }
 
37
} *excludes = NULL;
 
38
 
 
39
 
 
40
 
 
41
void exclude_add(char *pat) {
 
42
  struct exclude **n;
 
43
 
 
44
  n = &excludes;
 
45
  while(*n != NULL)
 
46
    n = &((*n)->next);
 
47
 
 
48
  *n = (struct exclude *) calloc(1, sizeof(struct exclude));
 
49
  (*n)->pattern = (char *) malloc(strlen(pat)+1);
 
50
  strcpy((*n)->pattern, pat);
54
51
}
55
52
 
56
53
 
57
 
int addExcludeFile(char *file) {
 
54
int exclude_addfile(char *file) {
58
55
  FILE *f;
59
56
  char buf[256];
60
57
  int len;
61
58
 
62
59
  if((f = fopen(file, "r")) == NULL)
63
 
    return(1);
 
60
    return 1;
64
61
 
65
62
  while(fgets(buf, 256, f) != NULL) {
66
63
    len = strlen(buf)-1;
68
65
      buf[len--] = '\0';
69
66
    if(len < 0)
70
67
      continue;
71
 
    addExclude(buf);
 
68
    exclude_add(buf);
72
69
  }
73
70
 
74
71
  fclose(f);
75
 
  return(0);
 
72
  return 0;
76
73
}
77
74
 
78
75
 
79
 
int matchExclude(char *path) {
80
 
  struct exclude *n = excludes;
 
76
int exclude_match(char *path) {
 
77
  struct exclude *n;
81
78
  char *c;
82
 
  int matched = 0;
83
 
 
84
 
  if(excludes == NULL)
85
 
    return(0);
86
 
  
87
 
  do {
88
 
    matched = !fnmatch(n->pattern, path, 0);
89
 
    for(c = path; *c && !matched; c++)
90
 
      if(*c == '/' && c[1] != '/')
91
 
        matched = !fnmatch(n->pattern, c+1, 0);
92
 
  } while((n = n->next) != NULL && !matched);
93
 
 
94
 
  return(matched);
 
79
 
 
80
  for(n=excludes; n!=NULL; n=n->next) {
 
81
    if(!fnmatch(n->pattern, path, 0))
 
82
      return 1;
 
83
    for(c = path; *c; c++)
 
84
      if(*c == '/' && c[1] != '/' && !fnmatch(n->pattern, c+1, 0))
 
85
        return 1;
 
86
  }
 
87
  return 0;
 
88
}
 
89
 
 
90
 
 
91
void exclude_clear() {
 
92
  struct exclude *n, *l;
 
93
 
 
94
  for(n=excludes; n!=NULL; n=l) {
 
95
    l = n->next;
 
96
    free(n);
 
97
  }
 
98
  excludes = NULL;
95
99
}
96
100