Mercurial > bday
annotate bday.c @ 15:032af48d590b
reformating of the source code
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Mon, 24 Feb 2014 17:46:57 +0100 |
parents | a56120a4678f |
children | 79d22407a6be |
rev | line source |
---|---|
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
1 /* |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
2 bday -- Birthday/Anniversary reminder |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
3 |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
4 (c) 2007,2014 markus schnalke <meillo@marmaro.de> |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
5 (c) 1994-1999 AS Mortimer |
8 | 6 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
7 This program is free software; you can redistribute it and/or |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
8 modify it under the terms of the GNU General Public License as |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
9 published by the Free Software Foundation; either version 2 of the |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
10 License, or (at your option) any later version. You may also |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
11 distribute it under the Artistic License, as comes with Perl. |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
12 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
16 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
18 along with this program; if not, write to the Free Software |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
8 | 20 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
21 You should also have recieved a copy of the Artistic license with |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
22 this program. |
8 | 23 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
24 ===================================================================== |
9
4f48b4f86e3d
added COPYRIGHT and COPYING; adjusted copyright hints in the code
meillo@marmaro.de
parents:
8
diff
changeset
|
25 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
26 Input is read through standard input. For example: bday < ~/.birthdays |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
27 The input (file) has to have the following format: |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
28 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
29 text=date flags |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
30 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
31 where: |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
32 date is yyyy-mm-dd |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
33 flags is ONE or ZERO of |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
34 bd for a birthday (default) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
35 ann for an anniversary |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
36 ev for an event |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
37 and zero or more of |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
38 w <n> to set the warn-in-advance time to n days |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
39 (don't include the brackets! :) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
40 to <date> |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
41 for <days> |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
42 to specify the length of time taken by an |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
43 event, for example a holiday. |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
44 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
45 Lines preceeded by # are treated as comments. |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
46 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
47 Note: If you deviate from this format, I cannot guarantee anything about |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
48 it's behaviour. In most cases, it will just quietly ignore the |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
49 error, which probably isn't ideal behaviour. Oh, well. |
8 | 50 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
51 ===================================================================== |
8 | 52 */ |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
53 |
7 | 54 |
8 | 55 /* standard time to warn in advance, when no explicit w flag is given. */ |
56 #define DEF_WARN 14 | |
7 | 57 |
58 | |
59 #include <stdarg.h> | |
60 #include <stdio.h> | |
61 #include <stdlib.h> | |
62 #include <string.h> | |
63 #include <sys/types.h> | |
64 #include <time.h> | |
65 #include <unistd.h> | |
66 | |
67 | |
68 | |
69 /* ========== Global constants and data types */ | |
70 | |
71 | |
72 /* month lengths etc */ | |
73 #define isleapyear(y) ((y)%4==0 && ((y)%100 != 0 || (y)%400 == 0)) | |
74 const unsigned MLENDAT[]; | |
75 #define mlen(m,y) (MLENDAT[(m)-1] != -1 ? MLENDAT[(m)-1] : (isleapyear((y)) ? 29 : 28)) | |
76 #define before(a,b) ((a).month < (b).month || ((a).month == (b).month && (a).day < (b).day)) | |
77 #define ydelta(a,b) ((int) (b).year - (a).year + before((a),(b))) | |
78 | |
79 /* -------- modifier flags */ | |
80 #define F_MTYPE 0x07 | |
81 #define F_TBIRTHDAY 1 | |
82 #define F_TANNIVERSARY 2 | |
83 #define F_TEVENT 3 | |
84 | |
85 /* flags processed immediately on encountering */ | |
86 #define F_MIMMEDIATE 0x24 | |
87 #define F_WTIME_P 0x08 | |
88 #define F_FORDAYS 0x16 | |
89 #define F_TODATE 0x24 | |
90 | |
8 | 91 struct _ftable {char* txt; unsigned flag;}; |
7 | 92 |
93 const struct _ftable FTABLE[]; | |
94 | |
95 struct date { | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
96 unsigned day; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
97 unsigned month; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
98 unsigned year; |
7 | 99 }; |
100 | |
101 struct event { | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
102 char* text; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
103 struct date date; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
104 struct date enddate; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
105 int warn; |
7 | 106 }; |
107 | |
108 typedef int (*prnfunc)(const char *); | |
109 | |
110 /* ========== Global Variables */ | |
111 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
112 struct event *readlist(void); |
7 | 113 void gettoday(void); |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
114 unsigned delta(struct date *); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
115 unsigned ddiff(struct date *D1, struct date *D2); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
116 void liststrings(struct event *evl, prnfunc outf); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
117 char *tdelta(struct date *d); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
118 char *ttime(int yr, int mn, int wk, int dy); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
119 int skptok(int j, char *ptr); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
120 int evcmp(const void *e1, const void *e2); |
7 | 121 |
122 | |
123 struct date today; | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
124 int iDWarn = DEF_WARN; |
7 | 125 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
126 const unsigned MLENDAT[] = {31,-1,31,30,31,30,31,31,30,31,30,31}; |
7 | 127 |
128 const struct _ftable FTABLE[] = { | |
129 {"bd", F_TBIRTHDAY}, | |
130 {"ann",F_TANNIVERSARY}, | |
131 {"ev", F_TEVENT}, | |
132 {"w", F_WTIME_P}, | |
133 {"to", F_TODATE}, | |
134 {"for", F_FORDAYS}, | |
135 {NULL, 0} | |
136 }; | |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 /* | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
144 xmalloc/xrealloc functions |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
145 Note: the x* functions are lifted straight from the GNU libc info docs |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
146 $Id: xmalloc.c,v 1.2 1999/01/16 17:08:59 andy Exp $ |
7 | 147 */ |
148 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
149 void * |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
150 xmalloc(size_t size) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
151 { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
152 register void *value = malloc (size); |
7 | 153 if (value == 0) { |
154 fprintf(stderr, "virtual memory exhausted\n"); | |
155 exit(1); | |
156 } | |
157 return value; | |
158 } | |
159 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
160 void * |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
161 xrealloc(void *ptr, size_t size) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
162 { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
163 register void *value = realloc (ptr, size); |
7 | 164 if (value == 0) { |
165 fprintf(stderr, "virtual memory exhausted\n"); | |
166 exit(1); | |
167 } | |
168 return value; | |
169 } | |
170 | |
8 | 171 |
7 | 172 /* ========== */ |
173 | |
174 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
175 /* |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
176 like strcat(), but lets the buffer automagically grow :-) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
177 (needs local variable "size" with the buffer size) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
178 */ |
7 | 179 #define append(where, what) do { \ |
180 if (strlen(what) > (size - strlen(where))) { \ | |
181 xrealloc(where, size + 128 + strlen(what)); \ | |
182 size += 128 + strlen(what); \ | |
183 } \ | |
184 strcat(where, what); \ | |
185 } while(0) | |
186 | |
187 /* ========== */ | |
188 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
189 /* |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
190 returns delta(d) in days, weeks, months, etc |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
191 the returned buffer is malloc()ed, do not forget to free() it |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
192 */ |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
193 char * |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
194 tdelta(struct date *d) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
195 { |
7 | 196 int dy, wk, mn, yr; |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
197 char *tmp; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
198 char *buf = xmalloc(128); |
7 | 199 int size = 128; |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
200 |
7 | 201 *buf = 0; |
202 switch (delta(d)) { | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
203 case 0: |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
204 append(buf, "today"); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
205 return buf; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
206 case 1: |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
207 append(buf, "tomorrow"); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
208 return buf; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
209 default: |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
210 /* like delta(), we ignore the year */ |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
211 yr = -before(*d, today); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
212 mn = d->month - today.month; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
213 dy = d->day - today.day; |
7 | 214 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
215 if (dy < 0) { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
216 dy += mlen(today.month, today.year); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
217 mn--; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
218 } |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
219 if (mn < 0) { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
220 mn += 12; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
221 yr++; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
222 } |
7 | 223 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
224 wk = (dy / 7); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
225 dy %= 7; |
7 | 226 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
227 append(buf, "in "); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
228 tmp = ttime(yr, mn, wk, dy); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
229 append(buf, tmp); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
230 free(tmp); |
7 | 231 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
232 return buf; |
7 | 233 } |
234 } | |
235 | |
236 | |
237 | |
238 | |
239 | |
240 /* | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
241 void |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
242 donum(n,txt) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
243 { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
244 if (n > 0) { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
245 snprintf(tmp, sizeof(tmp), "%d", n); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
246 append(buf, tmp); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
247 append(buf, " " txt); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
248 if (n != 1) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
249 append(buf, "s"); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
250 terms--; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
251 if (orgterms > 1) { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
252 if (terms == 1) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
253 append(buf, " and "); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
254 else if (terms > 1) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
255 append(buf, ", "); |
7 | 256 } |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
257 } |
7 | 258 } |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
259 */ |
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
260 |
7 | 261 |
262 #define donum(n,txt) do { \ | |
263 if (n > 0) { \ | |
264 snprintf(tmp, sizeof(tmp), "%d", n); \ | |
265 append(buf, tmp); \ | |
266 append(buf, " " txt); \ | |
267 if (n != 1) \ | |
268 append(buf, "s"); \ | |
269 terms--; \ | |
270 if (orgterms > 1) { \ | |
271 if (terms == 1) \ | |
272 append(buf, " and "); \ | |
273 else if (terms > 1) \ | |
274 append(buf, ", "); \ | |
275 } \ | |
276 } \ | |
277 } while(0) | |
278 | |
279 | |
280 /* returns allocated buffer, don't forget to free() */ | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
281 char * |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
282 ttime(int yr, int mn, int wk, int dy) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
283 { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
284 char *buf = xmalloc(128); |
7 | 285 int size = 128; |
286 int terms, orgterms; | |
287 char tmp[128]; | |
288 | |
289 *buf = 0; /* Initialize buffer */ | |
290 terms = orgterms = (yr!=0) + (mn!=0) + (wk!=0) + (dy!=0); | |
291 | |
292 donum(yr, "year"); | |
293 donum(mn, "month"); | |
294 donum(wk, "week"); | |
295 donum(dy, "day"); | |
296 | |
297 return buf; | |
298 } | |
299 #undef donum | |
300 | |
301 | |
302 | |
303 | |
304 | |
305 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
306 /* |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
307 lists the birthdays in their string format, one by one, and passes |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
308 the string to a function. |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
309 */ |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
310 void |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
311 liststrings(struct event *evl, prnfunc outf) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
312 { |
7 | 313 int i,j; |
314 char *buf, *tmp; | |
315 int size; | |
316 | |
317 for (i = 0; evl[i].text != NULL; i++) { | |
318 buf = xmalloc(128); | |
319 *buf = '\0'; | |
320 size = 128; | |
321 | |
322 if (evl[i].warn == -1 && delta(&(evl[i].date))==0) { | |
323 append(buf, evl[i].text); | |
324 } else if (evl[i].enddate.day == 0) { | |
325 if (delta(&(evl[i].date)) <= evl[i].warn) { | |
326 append(buf, evl[i].text); | |
327 append(buf, " "); | |
328 tmp = tdelta(&(evl[i].date)); | |
329 append(buf, tmp); | |
330 free(tmp); | |
331 } | |
332 } else { | |
333 if (delta(&(evl[i].date)) <= evl[i].warn) { | |
334 append(buf, evl[i].text); | |
335 append(buf, " for "); | |
14 | 336 /* +1 because, if the difference between two dates is one day, |
337 then the length of an event on those days is two days */ | |
7 | 338 j = ddiff(&(evl[i].date),&(evl[i].enddate)) + 1; |
339 tmp = ttime(0, 0, j/7, j%7); | |
340 append(buf, tmp); | |
341 free(tmp); | |
342 append(buf, " "); | |
343 tmp = tdelta(&(evl[i].date)); | |
344 append(buf, tmp); | |
345 } else if (delta(&(evl[i].enddate)) <= evl[i].warn) { | |
346 append(buf, evl[i].text); | |
347 append(buf, " "); | |
348 j = delta(&(evl[i].enddate)); | |
349 if (j) { | |
350 append(buf, "for "); | |
351 tmp = ttime(0, 0, j/7, j%7); | |
352 append(buf, tmp); | |
353 free(tmp); | |
354 append(buf, " longer"); | |
355 } else { | |
356 append(buf, "finishes today"); | |
357 } | |
358 } | |
359 } | |
360 if (*buf) { | |
361 append(buf, "."); | |
362 outf(buf); | |
363 } | |
364 free(buf); | |
365 } | |
366 } | |
367 | |
368 | |
369 | |
370 | |
371 | |
372 | |
373 | |
374 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
375 /* |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
376 sort the events by the time before the next time they come up, |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
377 putting those where the start has passed but we are still in the |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
378 time-period first |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
379 */ |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
380 int |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
381 evcmp(const void *p1, const void *p2) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
382 { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
383 struct event *e1=(struct event *) p1; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
384 struct event *e2=(struct event *) p2; |
8 | 385 unsigned d1, d2; |
7 | 386 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
387 /* |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
388 if the delta for the enddate is less than that for the start |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
389 date, then we have passed the start date but not yet the end |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
390 date, and so we should display the enddate; otherwise, we |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
391 should display the start date |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
392 */ |
7 | 393 |
394 d1=delta(&(e1->date)); | |
395 if (e1->enddate.day && delta(&(e1->enddate)) < d1) | |
396 d1=delta(&(e1->enddate)); | |
397 | |
398 d2=delta(&(e2->date)); | |
399 if (e2->enddate.day && delta(&(e2->enddate)) < d2) | |
400 d2=delta(&(e2->enddate)); | |
401 | |
402 if (d1 < d2) return -1; | |
8 | 403 if (d1 > d2) return 1; |
7 | 404 |
405 return strcmp(e1->text, e2->text); | |
406 } | |
407 | |
408 | |
409 | |
410 | |
411 | |
412 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
413 /* |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
414 difference in days between two dates |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
415 it is assumed that D1 < D2, and so the result is always positive |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
416 */ |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
417 unsigned |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
418 ddiff(struct date *D1, struct date *D2) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
419 { |
8 | 420 struct date d1, d2; |
421 int dd, m; | |
7 | 422 |
423 /* make working copies */ | |
8 | 424 d1 = *D1; |
425 d2 = *D2; | |
7 | 426 |
427 /* sort out zero years */ | |
428 if (d1.year == 0 || d2.year==0) { | |
429 if (d1.year != d2.year) { | |
430 if (d1.year == 0) { | |
8 | 431 if (before(d1,d2)) |
432 d1.year = d2.year; | |
433 else | |
434 d1.year = d2.year - 1; | |
435 } else { | |
436 if (before(d1, d2)) | |
437 d2.year = d1.year; | |
438 else | |
439 d2.year = d1.year + 1; | |
7 | 440 } |
441 } else { /* both years zero */ | |
8 | 442 if (before(d1, d2)) |
443 d1.year = d2.year = today.year; | |
7 | 444 else { |
8 | 445 d1.year = today.year; |
446 d2.year = d1.year + 1; | |
7 | 447 } |
448 } | |
449 } | |
450 | |
451 /* now we can actually do the comparison ... */ | |
8 | 452 dd = 0; |
7 | 453 |
454 /* to start with, we work in months */ | |
455 for (m=d1.month; m < d2.month + (d2.year-d1.year)*12; m++) | |
456 dd += mlen(((m-1)%12)+1, d1.year + m/12); | |
457 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
458 /* |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
459 and then we renormalise for the days within the months |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
460 the first month was included in our calculations |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
461 */ |
7 | 462 dd -= d1.day; |
463 /* but the last one wasn't */ | |
464 dd += d2.day; | |
465 | |
466 return dd; | |
467 } | |
468 | |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
475 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
476 /* |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
477 actually until the next anniversary of ... |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
478 */ |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
479 unsigned |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
480 delta(struct date *date) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
481 { |
7 | 482 struct date d; |
483 unsigned dt, mn; | |
484 | |
485 memcpy(&d, date, sizeof(struct date)); | |
486 | |
487 /* past the end of the year */ | |
488 if (before(d, today)) { | |
489 d.year = 1; | |
490 } else { | |
491 d.year = 0; | |
492 } | |
493 | |
8 | 494 for (mn = today.month, dt=0; mn < d.month + 12*d.year; mn++) { |
7 | 495 dt += mlen(((mn-1)%12) + 1,today.year + mn/12); |
8 | 496 } |
7 | 497 |
498 dt -= today.day; | |
499 dt += d.day; | |
500 | |
501 return dt; | |
502 } | |
503 | |
504 | |
505 | |
506 | |
507 | |
508 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
509 void |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
510 gettoday(void) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
511 { |
7 | 512 struct tm *tm; |
513 time_t t; | |
514 | |
515 time(&t); | |
516 tm = localtime(&t); | |
517 today.day = tm->tm_mday; | |
518 today.month = tm->tm_mon + 1; /* 1-12 instead of 0-11 */ | |
519 today.year = tm->tm_year + 1900; | |
520 } | |
521 | |
522 | |
523 | |
524 | |
525 | |
526 | |
527 | |
528 | |
529 | |
530 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
531 struct event * |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
532 readlist() |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
533 { |
7 | 534 int i, j, k, l, d; |
535 struct event *evl; | |
536 char buf[1024], buf2[1024]; | |
537 char *ptr; | |
538 unsigned flags; | |
539 | |
540 /* initialise */ | |
541 gettoday(); | |
542 | |
543 for (i = 0, evl = NULL; fgets(buf, sizeof(buf), stdin) != NULL; i++) { | |
544 evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1)); | |
545 | |
546 /* ignore comments and empty lines */ | |
547 if (*buf == '#' || *buf == '\n') { | |
548 i--; | |
549 continue; | |
550 } | |
551 | |
552 /* parse string in buf */ | |
553 ptr = strrchr(buf, '='); /* allow '=' in text */ | |
554 | |
555 /* not a valid line, so ignore it! Cool, huh? */ | |
556 /* Attention: only recognizes lines without '=' */ | |
557 if (ptr == NULL) { | |
558 fprintf(stderr, "WARNING: Invalid line in input:\n%s", buf); | |
559 i--; | |
560 continue; | |
561 } | |
562 | |
563 *(ptr++) = 0; | |
564 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
565 j = sscanf(ptr, "%u-%u-%u", &(evl[i].date.year), |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
566 &(evl[i].date.month), &(evl[i].date.day)); |
7 | 567 /* ... unless it wasn't read, in which case set it to zero */ |
568 if (j==2) { | |
569 evl[i].date.year = 0; | |
570 } | |
571 | |
572 | |
573 /* parse flags */ | |
574 | |
575 evl[i].warn = iDWarn; | |
576 evl[i].enddate.day = 0; | |
577 evl[i].enddate.month = 0; | |
578 evl[i].enddate.year = 0; | |
579 | |
580 flags = 0; | |
581 j = 0; | |
582 | |
583 while(j = skptok(j, ptr), ptr[j] != 0) { | |
584 for (k = 0; FTABLE[k].txt != NULL && strncmp(FTABLE[k].txt, ptr + j, strlen(FTABLE[k].txt)); k++) { | |
585 } | |
586 | |
587 switch (FTABLE[k].flag) { | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
588 case F_WTIME_P: /* w <n> -- sets warning time */ |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
589 sscanf(ptr + j, "w %u", &(evl[i].warn)); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
590 break; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
591 case F_FORDAYS: /* for <days> -- sets the duration of the event */ |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
592 sscanf(ptr + j, "for %u", &d); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
593 evl[i].enddate=evl[i].date; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
594 for (l = 1; l < d; l++) { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
595 evl[i].enddate.day++; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
596 if (evl[i].enddate.day > mlen(evl[i].enddate.month, evl[i].enddate.year)) { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
597 evl[i].enddate.month++; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
598 evl[i].enddate.day = 1; |
7 | 599 } |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
600 if (evl[i].enddate.month > 12) { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
601 evl[i].enddate.year++; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
602 evl[i].enddate.month = 1; |
7 | 603 } |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
604 } |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
605 break; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
606 case F_TODATE: /* to <date> -- sets the end date of the event */ |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
607 l = sscanf(ptr + j, "to %u-%u-%u", &(evl[i].enddate.year), &(evl[i].enddate.month), &(evl[i].enddate.day)); |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
608 if (l == 2) { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
609 evl[i].enddate.year = 0; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
610 } |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
611 break; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
612 case 0: |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
613 break; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
614 default: |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
615 flags |= FTABLE[k].flag; |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
616 break; |
7 | 617 } |
618 } | |
619 | |
620 | |
621 /* construct event text */ | |
622 | |
623 switch(flags & F_MTYPE) { | |
624 case F_TBIRTHDAY: | |
625 default: /* assume it's a birthday */ | |
626 if (evl[i].date.year != 0) { | |
627 int tmp_age = ydelta(evl[i].date, today); | |
628 if (tmp_age != 1) { | |
629 sprintf(buf2, "%s is %d years old", buf, tmp_age); | |
630 } else { | |
631 sprintf(buf2, "%s is %d year old", buf, tmp_age); | |
632 } | |
633 } else { | |
634 sprintf(buf2, "%s has a birthday", buf); | |
635 } | |
636 break; | |
637 case F_TANNIVERSARY: | |
638 if (evl[i].date.year != 0) { | |
639 sprintf(buf2, "%s %d years ago", buf, ydelta(evl[i].date, today)); | |
640 } else { | |
641 strcpy(buf2, buf); | |
642 } | |
643 break; | |
644 case F_TEVENT: | |
645 /* if a year was specified, and this warning isn't for it, ignore! */ | |
14 | 646 if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) |
647 && (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) { | |
7 | 648 i--; |
649 continue; | |
650 } | |
651 strcpy(buf2, buf); | |
652 break; | |
653 } | |
654 evl[i].text = strdup(buf2); | |
655 } | |
656 | |
657 evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1)); | |
658 evl[i].date.day = 0; | |
659 evl[i].date.month = 0; | |
660 evl[i].date.year = 0; | |
661 evl[i].text = (char *) NULL; | |
662 | |
663 fclose(stdin); | |
664 | |
665 /* NB uses i from above */ | |
666 qsort(evl, i, sizeof(struct event), evcmp); | |
667 return evl; | |
668 } | |
669 | |
670 | |
671 | |
672 | |
673 | |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
674 int |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
675 skptok(int j, char *ptr) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
676 { |
7 | 677 for (; ptr[j] != 0 && ptr[j] != ' ' && ptr[j] != '\t' ; j++); |
678 for (; ptr[j] != 0 && (ptr[j] == ' ' || ptr[j] == '\t'); j++); | |
679 | |
680 return j; | |
681 } | |
682 | |
683 | |
684 | |
685 | |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
686 |
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
687 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
688 int |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
689 main(int argc, char *argv[]) |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
690 { |
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
691 while (--argc > 0 && (*++argv)[0] == '-') { |
5
5af6bf2cb271
reads only stdin now, no files anymore; removed -f option aswell; code beatifing
meillo@marmaro.de
parents:
3
diff
changeset
|
692 if (strcmp(argv[0], "-W") == 0) { |
6 | 693 /* TODO: catch if no value given */ |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
694 iDWarn = atoi((++argv)[0]); |
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
695 argc--; |
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
696 } else { |
3
dc2f94280b01
new Makefile; removed MinWarn and MaxWarn; adjusted manpage
meillo@marmaro.de
parents:
0
diff
changeset
|
697 fprintf(stderr, "unknown option %s\n", argv[0]); |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
698 exit(1); |
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
699 } |
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
700 } |
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
701 |
6 | 702 liststrings(readlist(), puts); |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
703 |
15
032af48d590b
reformating of the source code
markus schnalke <meillo@marmaro.de>
parents:
14
diff
changeset
|
704 return 0; |
0
22b6e71de68e
initial commit; codebase from birthday; just the needed stuff; substituted getopt by own code
meillo@marmaro.de
parents:
diff
changeset
|
705 } |