annotate src/util.c @ 206:eb2589384836 noffle

[svn] * TODO: Update the TODO list. * src/util.c: When updating timestamp files, write new stamp to temp file and rename, so failure with e.g. full disc doesn't leave an empty stamp file.
author bears
date Wed, 14 Nov 2001 10:56:42 +0000
parents 027608dbd16b
children ffb1848a39db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
1 /*
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
2 util.c
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
3
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
4 $Id: util.c 325 2001-11-14 10:56:42Z bears $
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
5 */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
6
45
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
7 #if HAVE_CONFIG_H
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
8 #include <config.h>
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
9 #endif
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
10
54
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
11 #if TIME_WITH_SYS_TIME
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
12 #include <sys/time.h>
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
13 #include <time.h>
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
14 #else
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
15 #if HAVE_SYS_TIME_H
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
16 #include <sys/time.h>
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
17 #else
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
18 #include <time.h>
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
19 #endif
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
20 #endif
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
21
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
22 #include <errno.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
23 #include <ctype.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
24 #include <sys/types.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
25 #include <sys/stat.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
26 #include <fcntl.h>
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
27 #include <stdlib.h>
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
28 #include <unistd.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
29 #include "configfile.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
30 #include "log.h"
197
24d4cd032da5 [svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents: 186
diff changeset
31 #include "portable.h"
24d4cd032da5 [svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents: 186
diff changeset
32 #include "util.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
33 #include "wildmat.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
34
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
35 #if defined(UTIL_TEST)
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
36 #define Log_err printf
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
37 #endif
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
38
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
39 static const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
40 nextWhiteSpace( const char *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
41 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
42 while ( *p && ! isspace( *p ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
43 ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
44 return p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
45 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
46
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
47 static const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
48 nextNonWhiteSpace( const char *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
49 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
50 while ( *p && isspace( *p ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
51 ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
52 return p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
53 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
54
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
55 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
56 Utl_restOfLn( const char *line, unsigned int token )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
57 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
58 unsigned int i;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
59 const char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
60
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
61 p = line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
62 for ( i = 0; i < token; ++i )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
63 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
64 p = nextNonWhiteSpace( p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
65 p = nextWhiteSpace( p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
66 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
67 p = nextNonWhiteSpace( p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
68 return p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
69 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
70
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
71 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
72 Utl_getLn( Str result, const char *pos )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
73 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
74 int len = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
75 const char *p = pos;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
76
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
77 if ( ! p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
78 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
79 while ( *p != '\n' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
80 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
81 if ( *p == '\0' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
82 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
83 if ( len > 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
84 Log_err( "Line not terminated by newline: '%s'", pos );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
85 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
86 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
87 *(result++) = *(p++);
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
88 ++len;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
89 if ( len >= MAXCHAR - 1 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
90 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
91 *result = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
92 Log_err( "Utl_getLn: line too long: %s", result );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
93 return ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
94 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
95 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
96 *result = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
97 return ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
98
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
99 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
100
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
101 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
102 Utl_ungetLn( const char *str, const char *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
103 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
104 if ( str == p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
105 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
106 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
107 if ( *p != '\n' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
108 {
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 164
diff changeset
109 Log_err( "Utl_ungetLn: not at beginning of line" );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
110 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
111 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
112 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
113 while ( TRUE )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
114 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
115 if ( p == str )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
116 return p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
117 if ( *p == '\n' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
118 return p + 1;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
119 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
120 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
121 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
122
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
123 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
124 Utl_getHeaderLn( Str result, const char *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
125 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
126 const char * res = Utl_getLn( result, p );
202
mirkol
parents: 197
diff changeset
127 Bool not_too_long_header = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
128
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
129 /* Look for followon line if this isn't a blank line. */
109
2bedacfe1ba7 [svn] Fix header line reading buf
bears
parents: 91
diff changeset
130 if ( res != NULL && result[ 0 ] != '\0' && ! isspace( result[ 0 ] ) )
87
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
131 for(;;)
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
132 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
133 Str nextLine;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
134 const char *here;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
135
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
136 here = res;
87
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
137 nextLine[ 0 ] = '\0';
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
138 res = Utl_getLn( nextLine, res );
87
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
139 if ( res == NULL || nextLine[ 0 ] == '\0'
109
2bedacfe1ba7 [svn] Fix header line reading buf
bears
parents: 91
diff changeset
140 || ! isspace( nextLine[ 0 ] ) )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
141 {
87
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
142 res = here;
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
143 break;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
144 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
145 else
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
146 {
202
mirkol
parents: 197
diff changeset
147 if ( not_too_long_header &&
mirkol
parents: 197
diff changeset
148 ( MAXCHAR > ( strlen( result ) + strlen( nextLine ) + 1 ) ) )
mirkol
parents: 197
diff changeset
149 {
mirkol
parents: 197
diff changeset
150 Utl_catStr( result, "\n" );
mirkol
parents: 197
diff changeset
151 Utl_catStr( result, nextLine );
mirkol
parents: 197
diff changeset
152 }
mirkol
parents: 197
diff changeset
153 else
mirkol
parents: 197
diff changeset
154 {
mirkol
parents: 197
diff changeset
155 Log_err( "Utl_getHeaderLn: skipped continued header: %s", nextLine );
mirkol
parents: 197
diff changeset
156 not_too_long_header = FALSE;
mirkol
parents: 197
diff changeset
157 /* Now let poor little noffle skip the header continuations. */
mirkol
parents: 197
diff changeset
158 /* We really need to up the size limit of headers much */
mirkol
parents: 197
diff changeset
159 /* higher than MAXCHAR = 2048. mliss */
mirkol
parents: 197
diff changeset
160 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
161 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
162 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
163
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
164 return res;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
165 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
166
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
167 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
168 Utl_toLower( Str line )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
169 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
170 char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
171
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
172 p = line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
173 while ( *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
174 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
175 *p = tolower( *p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
176 ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
177 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
178 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
179
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
180 char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
181 Utl_stripWhiteSpace( char *line )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
182 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
183 char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
184
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
185 while ( isspace( *line ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
186 ++line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
187 p = line + strlen( line ) - 1;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
188 while ( isspace( *p ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
189 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
190 *p = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
191 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
192 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
193 return line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
194 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
195
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
196 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
197 Utl_stripComment( char *line )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
198 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
199 for ( ; *line != '\0'; line++ )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
200 if ( *line =='#' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
201 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
202 *line = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
203 break;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
204 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
205 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
206
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
207 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
208 Utl_cpyStr( Str dst, const char *src )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
209 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
210 dst[ 0 ] = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
211 strncat( dst, src, MAXCHAR );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
212 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
213
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
214 void
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
215 Utl_cpyStrN( Str dst, const char *src, int n )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
216 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
217 if ( n > MAXCHAR )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
218 n = MAXCHAR;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
219 dst[ 0 ] = '\0';
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
220 strncat( dst, src, (size_t)n );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
221 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
222
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
223 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
224 Utl_catStr( Str dst, const char *src )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
225 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
226 strncat( dst, src, MAXCHAR - strlen( dst ) );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
227 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
228
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
229 void
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
230 Utl_catStrN( Str dst, const char *src, int n )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
231 {
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
232 size_t un;
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
233
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
234 ASSERT( n >= 0 );
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
235 un = (size_t)n;
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
236 if ( un > MAXCHAR - strlen( dst ) )
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
237 un = MAXCHAR - strlen( dst );
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
238 strncat( dst, src, un );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
239 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
240
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
241 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
242 Utl_stamp( Str file )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
243 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
244 FILE *f;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
245 time_t t;
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
246 Str tmpfname;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
247
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
248 snprintf( tmpfname, MAXCHAR, "%s/.#%d.stamp.update",
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
249 Cfg_spoolDir(), (int) getpid() );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
250 time( &t );
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
251 if ( ! ( f = fopen( tmpfname, "w" ) ) )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
252 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
253 Log_err( "Could not open %s for writing (%s)",
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
254 tmpfname, strerror( errno ) );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
255 return;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
256 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
257 fprintf( f, "%lu\n", t );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
258 fclose( f );
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
259 if ( ferror( f ) )
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
260 {
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
261 Log_err( "Error stamping into file %s: %s",
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
262 tmpfname, strerror( errno ) );
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
263
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
264 }
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
265 else
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
266 {
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
267 if ( rename( tmpfname, file ) < 0 )
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
268 Log_err( "Rename of stamp file %s to %s failed: %s",
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
269 tmpfname, file, strerror( errno ) );
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
270 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
271 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
272
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
273 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
274 Utl_getStamp( time_t *result, Str file )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
275 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
276 FILE *f;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
277
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
278 if ( ! ( f = fopen( file, "r" ) ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
279 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
280 if ( fscanf( f, "%lu", result ) != 1 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
281 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
282 Log_err( "File %s corrupted", file );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
283 fclose( f );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
284 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
285 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
286 fclose( f );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
287 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
288 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
289
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
290 static const char *DOTW[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
291 "Sat", NULL };
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
292 static const char *MON[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
293 "Aug", "Sep", "Oct", "Nov", "Dec", NULL };
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
294
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
295 /*
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
296 * Calculate the difference between local time and GMT. This is INN's
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
297 * 'always-works' method. It assumes the time differences is < 24hrs.
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
298 * Sounds reasonable to me. It also assumes it can ignore seconds.
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
299 * Returns GMT - localtime minutes. It will also trash the localtime/
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
300 * gmtime/etc. static buffer.
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
301 */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
302 static int
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
303 tzDiff( void )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
304 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
305 time_t now;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
306 struct tm local, gmt, *tm;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
307 static time_t nextCalc = 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
308 static int res = 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
309
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
310 now = time( NULL );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
311 if ( now < nextCalc )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
312 return res;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
313
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
314 tm = localtime( &now );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
315 if ( tm == NULL )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
316 return 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
317 local = *tm;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
318 tm = gmtime( &now );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
319 if ( tm == NULL )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
320 return 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
321 gmt = *tm;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
322
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
323 res = gmt.tm_yday - local.tm_yday;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
324 if ( res < -1 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
325 res = -1; /* Year rollover? */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
326 else if ( res > 1 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
327 res = 1;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
328
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
329 res *= 24;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
330 res += gmt.tm_hour - local.tm_hour;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
331 res *= 60;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
332 res += gmt.tm_min - local.tm_min;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
333
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
334 /* Need to recalc at start of next hour */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
335 nextCalc = now + ( 60 - local.tm_sec ) + 60 * ( 59 - local.tm_min );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
336
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
337 return res;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
338 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
339
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
340 void
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
341 Utl_newsDate( time_t t, Str res )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
342 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
343 struct tm *local;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
344 long tzdiff, hoffset, moffset;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
345
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
346 tzdiff = - tzDiff();
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
347
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
348 local = localtime( &t );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
349 if ( local == NULL )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
350 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
351 Utl_cpyStr( res, "** localtime failure **" );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
352 return;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
353 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
354
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
355 hoffset = tzdiff / 60;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
356 moffset = tzdiff % 60;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
357 if ( moffset < 0 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
358 moffset = - moffset;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
359
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
360 sprintf( res, "%s, %d %s %4d %02d:%02d:%02d %+03ld%02ld",
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
361 DOTW[local->tm_wday], local->tm_mday,
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
362 MON[local->tm_mon], local->tm_year + 1900,
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
363 local->tm_hour, local->tm_min, local->tm_sec,
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
364 hoffset, moffset );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
365 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
366
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
367 time_t
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
368 Utl_parseNewsDate( const char *s )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
369 {
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
370 struct tm tm;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
371 int wday, offset, tzoffset;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
372 char *p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
373 time_t res;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
374
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
375 memset( &tm, 0, sizeof( tm ) );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
376 wday = -1;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
377 tm.tm_isdst = -1;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
378
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
379 s = nextNonWhiteSpace( s );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
380
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
381 /* Is this the day number, or a weekday? */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
382 if ( ! isdigit( *s ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
383 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
384 if ( strlen( s ) < 4 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
385 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
386
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
387 for ( wday = 0; DOTW[ wday ] != NULL; wday++ )
186
7d1f26e7c728 [svn] Remove case sensitivity in date parse.
bears
parents: 185
diff changeset
388 if ( strncasecmp( DOTW[ wday ], s, 3 ) == 0 )
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
389 break;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
390
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
391 if( DOTW[ wday ] == NULL || s[3] != ',' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
392 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
393
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
394 s += 4;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
395 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
396
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
397 /* Get the day number */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
398 tm.tm_mday = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
399 if ( p == s )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
400 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
401 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
402
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
403 /* Look for month name */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
404 s = nextNonWhiteSpace( s );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
405 if ( strlen( s ) < 4 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
406 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
407 for ( tm.tm_mon = 0; MON[ tm.tm_mon ] != NULL; tm.tm_mon++ )
186
7d1f26e7c728 [svn] Remove case sensitivity in date parse.
bears
parents: 185
diff changeset
408 if ( strncasecmp( MON[ tm.tm_mon ], s, 3 ) == 0 )
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
409 break;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
410
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
411 if ( MON[ tm.tm_mon ] == NULL )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
412 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
413 s += 3;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
414
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
415 /* Year next */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
416 tm.tm_year = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
417 if ( p == s || ( tm.tm_year >= 100 && tm.tm_year < 1900 ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
418 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
419 if ( tm.tm_year >= 1900 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
420 tm.tm_year -= 1900;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
421 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
422
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
423 /* Hours */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
424 tm.tm_hour = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
425 if ( p == s || *p != ':' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
426 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
427 s = ++p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
428
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
429 /* Minutes */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
430 tm.tm_min = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
431 if ( p == s || ( *p != ':' && *p != ' ' ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
432 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
433 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
434
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
435 /* Seconds */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
436 if ( *s == ':' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
437 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
438 s++;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
439 tm.tm_sec = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
440 if ( p == s )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
441 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
442 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
443 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
444
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
445 /* GMT/UT or timezone offset */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
446 tzoffset = 0;
202
mirkol
parents: 197
diff changeset
447 s = nextNonWhiteSpace( s );
186
7d1f26e7c728 [svn] Remove case sensitivity in date parse.
bears
parents: 185
diff changeset
448 if ( strncasecmp( s, "GMT", 3) == 0 )
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
449 s += 3;
186
7d1f26e7c728 [svn] Remove case sensitivity in date parse.
bears
parents: 185
diff changeset
450 else if ( strncasecmp( s, "UT", 2 ) == 0 )
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
451 s += 2;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
452 else
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
453 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
454 offset = (int) strtol( s, &p, 10 );
202
mirkol
parents: 197
diff changeset
455 if ( p == s )
mirkol
parents: 197
diff changeset
456 return (time_t) -1;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
457 s = p;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
458 tzoffset = ( offset / 100 ) * 60 + ( offset % 100 );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
459 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
460
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
461 /* Check for following junk */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
462 if ( *s != '\0' && ! isspace( *s ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
463 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
464
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
465 res = mktime( &tm );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
466 if ( res == (time_t) -1 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
467 return res;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
468
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
469 if ( wday >= 0 && wday != tm.tm_wday )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
470 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
471
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
472 /* Remove local time diff from res to give time as if GMT */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
473 res -= tzDiff() * 60;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
474
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
475 /* And now adjust for tzoffset */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
476 res -= tzoffset * 60;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
477
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
478 return res;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
479 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
480
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
481 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
482 Utl_allocAndCpy( char **dst, const char *src )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
483 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
484 int len = strlen( src );
45
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
485 if ( ! ( *dst = malloc( (size_t)len + 1 ) ) )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
486 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
487 Log_err( "Cannot allocate string with length %lu", strlen( src ) );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
488 exit( EXIT_FAILURE );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
489 }
45
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
490 memcpy( *dst, src, (size_t)len + 1 );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
491 }
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
492
164
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
493 sig_t
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
494 Utl_installSignalHandler( int sig, sig_t handler )
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
495 {
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
496 struct sigaction act, oldAct;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
497
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
498 act.sa_handler = handler;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
499 sigemptyset( &act.sa_mask );
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
500 act.sa_flags = 0;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
501 if ( sig != SIGALRM )
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
502 act.sa_flags |= SA_RESTART;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
503 if ( sigaction( sig, &act, &oldAct ) < 0 )
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
504 return SIG_ERR;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
505 return oldAct.sa_handler;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
506 }
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
507
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
508 #if defined(UTIL_TEST)
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
509
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
510 /* Test code borrowed from wildmat.c. Yep, still uses gets(). */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
511 extern char *gets();
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
512
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
513 int
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
514 main()
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
515 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
516 Str line;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
517 time_t t;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
518
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
519 printf( "Util date tester. Enter date to test.\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
520 printf( "A blank line exits the program.\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
521
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
522 for ( ; ; )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
523 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
524 t = time( NULL );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
525 Utl_newsDate( t, line );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
526 printf( "\n(%s) Enter date: ", line );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
527 (void) fflush( stdout );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
528 if ( gets( line ) == NULL || line[0] == '\0' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
529 break;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
530
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
531 t = Utl_parseNewsDate( line );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
532 if ( t == (time_t) -1 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
533 printf( "Date parse failed\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
534 else
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
535 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
536 Utl_newsDate( t, line );
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
537 printf( "Utl_newsDate -> '%s'\n", line );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
538 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
539 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
540
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
541 exit(0);
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
542 /* NOTREACHED */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
543 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
544 #endif