Mercurial > noffle
comparison src/over.c @ 43:2842f50feb55 noffle
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
control.c, control.h, database.c, database.h, dynamicstring.c,
dynamicstring.h, fetch.c, fetch.h, fetchlist.c, fetchlist.h, group.c,
group.h, itemlist.c, itemlist.h, lock.c, lock.h, log.c, log.h, noffle.c,
online.c, online.h, outgoing.c, outgoing.h, over.c, over.h, post.c, post.h,
protocol.c, protocol.h, pseudo.c, pseudo.h, request.c, request.h, server.c,
server.h, util.c, util.h, wildmat.c, wildmat.h: Moved files to the
subdirectory src/
* Makefile.am, acconfig.h, configure.in, docs/Makefile.am, src/Makefile.am,
Makefile.in, aclocal.m4, config.h.in, configure, install-sh, missing,
mkinstalldirs, stamp-h.in, docs/Makefile.in, src/Makefile.in: Added files.
They are used by aclocal, autoheader, autoconf and automake.
* src/config.c, src/config.h: Renamed to configfile.c and configfile.h,
because configure will generate a config.h file itself.
* src/client.c, src/content.c, src/database.c, src/fetch.c, src/fetchlist.c,
src/group.c, src/lock.c, src/noffle.c, src/online.c, src/outgoing.c,
src/over.c, src/pseudo.c, src/request.c, src/server.c, src/util.c:
Changed '#include "config.h"' to '#include "configfile.h"'.
* src/client.c, src/content.c, src/database.c, src/fetch.c, src/fetchlist.c,
src/group.c, src/lock.c, src/online.c, src/outgoing.c, src/post.c,
src/protocol.c, src/request.c, src/server.c: Files now #include <config.h>.
Added missing <stdio.h>. This removes the warnings about snprintf() not
being declared.
* Makefile: Removed. This is now generated by configure.
author | uh1763 |
---|---|
date | Fri, 05 May 2000 22:45:56 +0100 |
parents | |
children | 32ba1198c6fa |
comparison
equal
deleted
inserted
replaced
42:2467ff423c15 | 43:2842f50feb55 |
---|---|
1 /* | |
2 over.c | |
3 | |
4 $Id: over.c 49 2000-05-05 21:45:56Z uh1763 $ | |
5 */ | |
6 | |
7 #include <errno.h> | |
8 #include <time.h> | |
9 #include "configfile.h" | |
10 #include "content.h" | |
11 #include "database.h" | |
12 #include "fetchlist.h" | |
13 #include "log.h" | |
14 #include "util.h" | |
15 #include "protocol.h" | |
16 #include "pseudo.h" | |
17 | |
18 struct Over | |
19 { | |
20 int numb; /* message number of the overviewed article */ | |
21 char *subj; | |
22 char *from; | |
23 char *date; | |
24 char *msgId; | |
25 char *ref; | |
26 size_t bytes; | |
27 size_t lines; | |
28 time_t time; | |
29 }; | |
30 | |
31 Over * | |
32 new_Over( const char *subj, const char *from, | |
33 const char *date, const char *msgId, char *ref, | |
34 size_t bytes, size_t lines ) | |
35 { | |
36 Over *ov; | |
37 | |
38 if ( ! ( ov = (Over *)malloc( sizeof( Over ) ) ) ) | |
39 { | |
40 Log_err( "Cannot allocate Over" ); | |
41 exit( EXIT_FAILURE ); | |
42 } | |
43 ov->numb = 0; | |
44 Utl_allocAndCpy( &ov->subj, subj ); | |
45 Utl_allocAndCpy( &ov->from, from ); | |
46 Utl_allocAndCpy( &ov->date, date ); | |
47 Utl_allocAndCpy( &ov->msgId, msgId ); | |
48 Utl_allocAndCpy( &ov->ref, ref ); | |
49 ov->bytes = bytes; | |
50 ov->lines = lines; | |
51 return ov; | |
52 } | |
53 | |
54 void | |
55 del_Over( Over *self ) | |
56 { | |
57 if ( ! self ) | |
58 return; | |
59 free( self->subj ); | |
60 self->subj = NULL; | |
61 free( self->from ); | |
62 self->from = NULL; | |
63 free( self->date ); | |
64 self->date = NULL; | |
65 free( self->msgId ); | |
66 self->msgId = NULL; | |
67 free( self->ref ); | |
68 self->ref = NULL; | |
69 free( self ); | |
70 } | |
71 | |
72 int | |
73 Ov_numb( const Over *self ) | |
74 { | |
75 return self->numb; | |
76 } | |
77 | |
78 const char * | |
79 Ov_subj( const Over *self ) | |
80 { | |
81 return self->subj; | |
82 } | |
83 | |
84 const char * | |
85 Ov_from( const Over *self ) | |
86 { | |
87 return self->from; | |
88 } | |
89 | |
90 const char * | |
91 Ov_date( const Over *self ) | |
92 { | |
93 return self->date; | |
94 } | |
95 | |
96 const char * | |
97 Ov_msgId( const Over *self ) | |
98 { | |
99 return self->msgId; | |
100 } | |
101 | |
102 const char * | |
103 Ov_ref( const Over *self ) | |
104 { | |
105 return self->ref; | |
106 } | |
107 | |
108 size_t | |
109 Ov_bytes( const Over *self ) | |
110 { | |
111 return self->bytes; | |
112 } | |
113 | |
114 size_t | |
115 Ov_lines( const Over *self ) | |
116 { | |
117 return self->lines; | |
118 } | |
119 | |
120 void | |
121 Ov_setNumb( Over *self, int numb ) | |
122 { | |
123 self->numb = numb; | |
124 } | |
125 | |
126 Bool | |
127 Ov_write( const Over *self, FILE *f ) | |
128 { | |
129 return ( fprintf( f, "%i\t%s\t%s\t%s\t%s\t%s\t%d\t%d\n", | |
130 self->numb, self->subj, | |
131 self->from, self->date, self->msgId, | |
132 self->ref, self->bytes, | |
133 self->lines ) > 0 ); | |
134 } | |
135 | |
136 static const char * | |
137 readField( Str result, const char *p ) | |
138 { | |
139 size_t len; | |
140 char *r; | |
141 | |
142 if ( ! p ) | |
143 return NULL; | |
144 r = result; | |
145 *r = '\0'; | |
146 len = 0; | |
147 while ( *p != '\t' && *p != '\n' ) | |
148 { | |
149 if ( ! *p ) | |
150 return p; | |
151 *(r++) = *(p++); | |
152 ++len; | |
153 if ( len >= MAXCHAR - 1 ) | |
154 { | |
155 *r = '\0'; | |
156 Log_err( "Field in overview too long: %s", r ); | |
157 return ++p; | |
158 } | |
159 } | |
160 *r = '\0'; | |
161 return ++p; | |
162 } | |
163 | |
164 /* read Over-struct from line */ | |
165 Over * | |
166 Ov_read( char *line ) | |
167 { | |
168 size_t bytes, lines; | |
169 const char *p; | |
170 Over *result; | |
171 int numb; | |
172 Str t, subj, from, date, msgId, ref; | |
173 | |
174 p = readField( t, line ); | |
175 if ( sscanf( t, "%i", &numb ) != 1 ) | |
176 return NULL; | |
177 p = readField( subj, p ); | |
178 p = readField( from, p ); | |
179 p = readField( date, p ); | |
180 p = readField( msgId, p ); | |
181 p = readField( ref, p ); | |
182 p = readField( t, p ); | |
183 if ( sscanf( t, "%d", &bytes ) != 1 ) | |
184 return NULL; | |
185 p = readField( t, p ); | |
186 if ( sscanf( t, "%d", &lines ) != 1 ) | |
187 return NULL; | |
188 result = new_Over( subj, from, date, msgId, ref, bytes, lines ); | |
189 Ov_setNumb( result, numb ); | |
190 return result; | |
191 } |