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
|
/*
Copyright (C) 2006 by Jonas Kramer
Published under the terms of the GNU General Public License (GPL).
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "settings.h"
#include "autoban.h"
#include "getln.h"
/*
Check if a given artist is banned completely (it appears in
"~/.shell-fm/autoban").
*/
int banned(const char * artist) {
FILE * fd;
signed match = 0;
char * line = NULL;
unsigned int size = 0;
if(!artist)
return 0;
if(!(fd = fopen(rcpath("autoban"), "r")))
return 0;
while(!feof(fd) && !match) {
char * ptr;
if(!getln(& line, & size, fd))
continue;
if(strlen(line) > 1) {
if((ptr = strrchr(line, 10)) != NULL)
* ptr = (char) 0;
match = (strlen(line) == strlen(artist))
&& !strncasecmp(line, artist, strlen(line));
}
}
if(line)
free(line);
fclose(fd);
return match;
}
/* Ban an artist by adding it to the autoban file. */
int autoban(const char * artist) {
FILE * fd;
const char * file = rcpath("autoban");
if(!artist)
return 0;
if(!(fd = fopen(file, "a"))) {
printf("Sorry, %s could not be written.\n", file);
return 0;
}
fprintf(fd, "%s\n", artist);
fclose(fd);
return !0;
}
|