File: conf.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 (203 lines) | stat: -rw-r--r-- 3,722 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* 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"
#include "conf.h"

int set_columns(void *data)
{
    if ((unsigned long) data < 0)
        return 1;

    if (columns_set())
        return 0;

    nc->defs[DEF_COLS] = ((int *) data)[0];
    return 0;
}

int check_theme(void *data)
{
    if (((unsigned long) data < 0) || (((unsigned long) data) > 7)) {
        return 1;
    }

    return 0;
}

int set_rate(void *data)
{
    struct feed *cur = get_feed(((char **) data)[1]);
    int num = ((int *) data)[0];

    if (cur) {
        if (num <= 0)
            cur->rate = 0;
        else
            cur->rate = num;

        return 0;
    }

    return 1;
}

int set_max(void *data)
{
    struct feed *cur = get_feed(((char **) data)[1]);
    int num = ((int *) data)[0];
    if (cur) {
        if (num <= 0)
            cur->keep = 0;
        else
            cur->keep = num;

        return 0;
    }

    return 1;
}

int set_show(void *data)
{
    struct feed *cur = get_feed(((char **) data)[1]);
    int num = ((int *) data)[0];

    if (cur) {
        if (num <= 0)
            cur->show = 0;
        else
            cur->show = num;

        return 0;
    }

    return 1;
}

int set_def(int def, int num)
{
    if (num < 0)
        nc->defs[def] = 0;
    else
        nc->defs[def] = num;

    return 0;
}

int set_def_max(void *data)
{
    return set_def(DEF_MAX, ((int *) data)[0]);
}

int set_def_rate(void *data)
{
    return set_def(DEF_RATE, ((int *) data)[0]);
}

int set_def_show(void *data)
{
    return set_def(DEF_SHOW, ((int *) data)[0]);
}

int set_theme(void *data)
{
    if ((((int *) data)[0] >= 1) && (((int *) data)[0] <= 8)) {
        nc->themes[((int *) data)[0] - 1].fg = ((int *) data)[1];
        nc->themes[((int *) data)[0] - 1].bg = ((int *) data)[2];
    }
    return 0;
}

int set_browser_wait(void *data)
{
    if (((int *) data)[0])
        nc->bits |= CFG_BITS_BROWSER_WAIT;
    else
        nc->bits &= ~(CFG_BITS_BROWSER_WAIT);

    return 0;
}

void escape_filter(char *line)
{
    char *sub = line;

    while ((sub = strstr(sub, "\\n")) != NULL) {
        if (sub != line) {
            if (sub[-1] != '\\')
                sub[0] = '\n';
            else
                sub--;
            memmove(&sub[1], &sub[2], strlen(sub) - 1);
        } else {
            sub[0] = '\n';
            memmove(&sub[1], &sub[2], strlen(sub) - 1);
        }

        sub++;
    }
}

int set_browser(void *data)
{
    nc->browser_line = ((char **) data)[0];
    return 0;
}

int set_wget(void *data)
{
    nc->wget_line = ((char **) data)[0];
    return 0;
}

int set_desc_filter(void *data)
{
    nc->desc_filter_line = ((char **) data)[0];
    return 0;
}

int set_story_filter(void *data)
{
    nc->story_filter_line = ((char **) data)[0];
    return 0;
}

int set_title_escape(void *data)
{
    escape_filter(((char **) data)[0]);
    nc->title_string = ((char **) data)[0];
    return 0;
}

int set_story_escape(void *data)
{
    escape_filter(((char **) data)[0]);
    nc->story_string = ((char **) data)[0];
    return 0;
}

int set_r_story_escape(void *data)
{
    escape_filter(((char **) data)[0]);
    nc->r_story_string = ((char **) data)[0];
    return 0;
}

int set_u_story_escape(void *data)
{
    escape_filter(((char **) data)[0]);
    nc->u_story_string = ((char **) data)[0];
    return 0;
}

int set_reader_escape(void *data)
{
    escape_filter(((char **) data)[0]);
    nc->descr_string = ((char **) data)[0];
    return 0;
}