-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension_test.c
77 lines (61 loc) · 2.33 KB
/
extension_test.c
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
66
67
68
69
70
71
72
73
74
75
76
/*
Copyright © 2007, The Board of Trustees of the University of Illinois.
This file is part of SSNiper.
SSNiper is open source software, released under the University of
Illinois/NCSA Open Source License. You should have received a copy of
this license in a file with the SSNiper distribution.
*/
#include "extension_test.h"
struct node *ext_skip_list = NULL;
extern char LOGBUF[LOG_BUF_SZ];
// ----------------------------------------------------------------------
// find_last() -- return a pointer to the last occurrence of the 'key'
// char in the string provided. This is accomplished by iterating back-
// wards from the end of the string. The last char and the first char
// will be skipped (which reduces the general usability of this
// function, admittedly).
// ----------------------------------------------------------------------
char * find_last(char * str, char key)
{
char *cursor;
for(cursor = str + strlen(str) - 2; cursor > str; cursor--)
if(*cursor == key)
return cursor + 1;
return NULL;
}
// ----------------------------------------------------------------------
// push_skip_ext() -- add to the list of strings that mark file
// extensions to be skipped. This just makes it look prettier than
// managing the list manually (and abstracts it in case I change the
// way it works).
// ----------------------------------------------------------------------
void push_skip_ext(char * desc)
{
char * buf;
buf = (char *)malloc(strlen(desc));
strncpy(buf, desc, strlen(desc)+1);
snprintf(LOGBUF, LOG_BUF_SZ, "skipping files with extension '%s'", buf);
slog(LOGBUF, LOG_INF);
ext_skip_list = append_list(ext_skip_list, buf);
}
// ----------------------------------------------------------------------
// skip_extension_p() -- Return a pointer to the extension identified
// if the extension is on the "skip list". If not, return NULL.
// ----------------------------------------------------------------------
char * skip_extension_p(char *filename)
{
struct node *cursor;
const char * extension;
extension = find_last(filename, '.');
if(extension)
{
for(cursor = ext_skip_list; cursor != NULL; cursor = cursor->next)
{
if(strcmp(extension, (char *)cursor->data) == 0)
{
return (char *)cursor->data;
}
}
}
return NULL;
}