Added new download option to the manual.
[shell-fm.git] / source / autoban.c
blob4f23e8194d74865f5e5d79bd33a5cc2f3a87a6e4
1 /*
2 Copyright (C) 2006 by Jonas Kramer
3 Published under the terms of the GNU General Public License (GPL).
4 */
6 #define _GNU_SOURCE
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
13 #include "settings.h"
14 #include "autoban.h"
15 #include "getln.h"
18 int banned(const char * artist) {
19 FILE * fd;
20 signed match = 0;
21 char * line = NULL;
22 unsigned int size = 0;
24 if(!artist)
25 return 0;
27 if(!(fd = fopen(rcpath("autoban"), "r")))
28 return 0;
30 while(!feof(fd) && !match) {
31 char * ptr;
32 if(!getln(& line, & size, fd))
33 continue;
35 if(strlen(line) > 1) {
36 if((ptr = strrchr(line, 10)) != NULL)
37 * ptr = (char) 0;
38 match = !strncasecmp(line, artist, strlen(line));
42 if(line)
43 free(line);
45 fclose(fd);
46 return match;
49 int autoban(const char * artist) {
50 FILE * fd;
51 const char * file = rcpath("autoban");
53 if(!artist)
54 return 0;
56 if(!(fd = fopen(file, "a"))) {
57 printf("Sorry, %s could not be written.\n", file);
58 return 0;
61 fprintf(fd, "%s\n", artist);
62 fclose(fd);
64 return !0;