File: filter.c

package info (click to toggle)
nrss 0.3.9-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, lenny, squeeze, stretch, wheezy
  • size: 204 kB
  • ctags: 380
  • sloc: ansic: 2,603; makefile: 74
file content (58 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download
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
/* NRSS - ncurses RSS reader
   Copyright (C) 2007 Jack Miller <jjm2n4@umr.edu>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 2 as 
   published by the Free Software Foundation.
*/
#include "nrss.h"

char *read_string_from_fd(int source)
{
    char *str = NULL;
    char *tmp = NULL;
    char *buff = xmalloc(BUFFER + 1);
    int len = 0;

    while ((len = read(source, buff, BUFFER)) > 0) {
        buff[len] = 0;

        if (str) {
            tmp = concat(str, buff);
            free(str);
            str = tmp;
        } else
            str = strdup(buff);
    }

    free(buff);
    return str;
}


void write_string_to_fd(const char *str, int dest)
{
    size_t len = 0;
    size_t index = 0;
    size_t bytes = 0;

    if (!str)
        return;

    len = strlen(str);
    while (index < len) {
        bytes = write(dest, &(str[index]), len - index);
        index += bytes;
    }
}

char *filter_description(char *str)
{
    char *filtered_string = NULL;

    if (!nc->desc_filter_line)
        return NULL;

    filtered_string = filter_string(str, nc->desc_filter_line);
    return filtered_string;
}