annotate src/util.c @ 127:3c71e28c8eef noffle

[svn] Release-1-0 mergedocs/NOTES
author bears
date Tue, 25 Jul 2000 13:14:54 +0100
parents 2bedacfe1ba7
children 94f2e5607772
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
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
4 $Id: util.c 183 2000-07-25 12:14:54Z 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 "util.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
23 #include <errno.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
24 #include <ctype.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
25 #include <sys/types.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
26 #include <sys/stat.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
27 #include <fcntl.h>
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
28 #include <stdlib.h>
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
29 #include <unistd.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
30 #include "configfile.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
31 #include "log.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
32 #include "wildmat.h"
54
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
33 #include "portable.h"
43
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 #define Log_dbg printf
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
38 #endif
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
39
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
40 static const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
41 nextWhiteSpace( const char *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
42 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
43 while ( *p && ! isspace( *p ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
44 ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
45 return p;
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
48 static const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
49 nextNonWhiteSpace( const char *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
50 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
51 while ( *p && isspace( *p ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
52 ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
53 return p;
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
56 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
57 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
58 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
59 unsigned int i;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
60 const char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
61
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
62 p = line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
63 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
64 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
65 p = nextNonWhiteSpace( p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
66 p = nextWhiteSpace( p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
67 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
68 p = nextNonWhiteSpace( p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
69 return p;
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
72 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
73 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
74 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
75 int len = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
76 const char *p = pos;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
77
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
78 if ( ! p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
79 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
80 while ( *p != '\n' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
81 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
82 if ( *p == '\0' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
83 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
84 if ( len > 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
85 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
86 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
87 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
88 *(result++) = *(p++);
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
89 ++len;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
90 if ( len >= MAXCHAR - 1 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
91 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
92 *result = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
93 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
94 return ++p;
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 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
97 *result = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
98 return ++p;
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
102 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
103 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
104 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
105 if ( str == p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
106 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
107 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
108 if ( *p != '\n' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
109 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
110 Log_dbg( "Utl_ungetLn: not at beginning of line" );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
111 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
112 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
113 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
114 while ( TRUE )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
115 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
116 if ( p == str )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
117 return p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
118 if ( *p == '\n' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
119 return p + 1;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
120 --p;
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
124 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
125 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
126 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
127 const char * res = Utl_getLn( result, p );
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 {
87
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
147 Utl_catStr( result, "\n" );
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
148 Utl_catStr( result, nextLine );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
149 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
150 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
151
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
152 return res;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
153 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
154
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
155 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
156 Utl_toLower( Str line )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
157 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
158 char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
159
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
160 p = line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
161 while ( *p )
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 *p = tolower( *p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
164 ++p;
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
168 char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
169 Utl_stripWhiteSpace( char *line )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
170 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
171 char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
172
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
173 while ( isspace( *line ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
174 ++line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
175 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
176 while ( isspace( *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 *p = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
179 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
180 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
181 return 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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
184 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
185 Utl_stripComment( char *line )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
186 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
187 for ( ; *line != '\0'; line++ )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
188 if ( *line =='#' )
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 *line = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
191 break;
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 }
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 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
196 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
197 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
198 dst[ 0 ] = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
199 strncat( dst, src, MAXCHAR );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
200 }
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 void
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
203 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
204 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
205 if ( n > MAXCHAR )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
206 n = MAXCHAR;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
207 dst[ 0 ] = '\0';
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
208 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
209 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
210
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
211 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
212 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
213 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
214 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
215 }
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 void
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
218 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
219 {
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
220 size_t un;
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
221
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
222 ASSERT( n >= 0 );
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
223 un = (size_t)n;
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
224 if ( un > MAXCHAR - strlen( dst ) )
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
225 un = MAXCHAR - strlen( dst );
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
226 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
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
230 Utl_stamp( Str file )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
231 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
232 FILE *f;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
233 time_t t;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
234
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
235 time( &t );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
236 if ( ! ( f = fopen( file, "w" ) ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
237 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
238 Log_err( "Could not open %s for writing (%s)",
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
239 file, strerror( errno ) );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
240 return;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
241 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
242 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
243 fclose( f );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
244 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
245
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
246 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
247 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
248 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
249 FILE *f;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
250
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
251 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
252 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
253 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
254 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
255 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
256 fclose( f );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
257 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
258 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
259 fclose( f );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
260 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
261 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
262
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
263 static const char *DOTW[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
264 "Sat", NULL };
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
265 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
266 "Aug", "Sep", "Oct", "Nov", "Dec", NULL };
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
267
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
268 /*
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
269 * Calculate the difference between local time and GMT. This is INN's
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
270 * 'always-works' method. It assumes the time differences is < 24hrs.
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
271 * Sounds reasonable to me. It also assumes it can ignore seconds.
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
272 * Returns GMT - localtime minutes. It will also trash the localtime/
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
273 * gmtime/etc. static buffer.
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
274 */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
275 static int
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
276 tzDiff( void )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
277 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
278 time_t now;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
279 struct tm local, gmt, *tm;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
280 static time_t nextCalc = 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
281 static int res = 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
282
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
283 now = time( NULL );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
284 if ( now < nextCalc )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
285 return res;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
286
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
287 tm = localtime( &now );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
288 if ( tm == NULL )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
289 return 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
290 local = *tm;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
291 tm = gmtime( &now );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
292 if ( tm == NULL )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
293 return 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
294 gmt = *tm;
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 res = gmt.tm_yday - local.tm_yday;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
297 if ( res < -1 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
298 res = -1; /* Year rollover? */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
299 else if ( res > 1 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
300 res = 1;
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 res *= 24;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
303 res += gmt.tm_hour - local.tm_hour;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
304 res *= 60;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
305 res += gmt.tm_min - local.tm_min;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
306
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
307 /* Need to recalc at start of next hour */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
308 nextCalc = now + ( 60 - local.tm_sec ) + 60 * ( 59 - local.tm_min );
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 return res;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
311 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
312
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
313 void
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
314 Utl_newsDate( time_t t, Str res )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
315 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
316 struct tm *local;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
317 long tzdiff, hoffset, moffset;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
318
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
319 tzdiff = - tzDiff();
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
320
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
321 local = localtime( &t );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
322 if ( local == NULL )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
323 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
324 Utl_cpyStr( res, "** localtime failure **" );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
325 return;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
326 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
327
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
328 hoffset = tzdiff / 60;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
329 moffset = tzdiff % 60;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
330 if ( moffset < 0 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
331 moffset = - moffset;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
332
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
333 sprintf( res, "%s, %d %s %4d %02d:%02d:%02d %+03ld%02ld",
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
334 DOTW[local->tm_wday], local->tm_mday,
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
335 MON[local->tm_mon], local->tm_year + 1900,
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
336 local->tm_hour, local->tm_min, local->tm_sec,
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
337 hoffset, moffset );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
338 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
339
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
340 time_t
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
341 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
342 {
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
343 struct tm tm;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
344 int wday, offset, tzoffset;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
345 char *p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
346 time_t res;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
347
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
348 memset( &tm, 0, sizeof( tm ) );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
349 wday = -1;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
350 tm.tm_isdst = -1;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
351
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
352 s = nextNonWhiteSpace( s );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
353
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
354 /* Is this the day number, or a weekday? */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
355 if ( ! isdigit( *s ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
356 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
357 if ( strlen( s ) < 4 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
358 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
359
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
360 for ( wday = 0; DOTW[ wday ] != NULL; wday++ )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
361 if ( strncmp( DOTW[ wday ], s, 3 ) == 0 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
362 break;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
363
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
364 if( DOTW[ wday ] == NULL || s[3] != ',' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
365 return (time_t) -1;
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 s += 4;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
368 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
369
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
370 /* Get the day number */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
371 tm.tm_mday = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
372 if ( p == s )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
373 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
374 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
375
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
376 /* Look for month name */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
377 s = nextNonWhiteSpace( s );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
378 if ( strlen( s ) < 4 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
379 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
380 for ( tm.tm_mon = 0; MON[ tm.tm_mon ] != NULL; tm.tm_mon++ )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
381 if ( strncmp( MON[ tm.tm_mon ], s, 3 ) == 0 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
382 break;
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 ( MON[ tm.tm_mon ] == NULL )
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 s += 3;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
387
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
388 /* Year next */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
389 tm.tm_year = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
390 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
391 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
392 if ( tm.tm_year >= 1900 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
393 tm.tm_year -= 1900;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
394 s = p;
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 /* Hours */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
397 tm.tm_hour = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
398 if ( p == s || *p != ':' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
399 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
400 s = ++p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
401
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
402 /* Minutes */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
403 tm.tm_min = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
404 if ( p == s || ( *p != ':' && *p != ' ' ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
405 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
406 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
407
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
408 /* Seconds */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
409 if ( *s == ':' )
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 s++;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
412 tm.tm_sec = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
413 if ( p == s )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
414 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
415 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
416 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
417
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
418 /* GMT/UT or timezone offset */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
419 tzoffset = 0;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
420 while ( isspace( *s ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
421 s++;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
422 if ( strncmp( s, "GMT", 3) == 0 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
423 s += 3;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
424 else if ( strncmp( s, "UT", 2 ) == 0 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
425 s += 2;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
426 else
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
427 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
428 offset = (int) strtol( s, &p, 10 );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
429 s = p;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
430 tzoffset = ( offset / 100 ) * 60 + ( offset % 100 );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
431 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
432
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
433 /* Check for following junk */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
434 if ( *s != '\0' && ! isspace( *s ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
435 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
436
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
437 res = mktime( &tm );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
438 if ( res == (time_t) -1 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
439 return res;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
440
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
441 if ( wday >= 0 && wday != tm.tm_wday )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
442 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
443
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
444 /* Remove local time diff from res to give time as if GMT */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
445 res -= tzDiff() * 60;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
446
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
447 /* And now adjust for tzoffset */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
448 res -= tzoffset * 60;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
449
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
450 return res;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
451 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
452
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
453 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
454 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
455 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
456 int len = strlen( src );
45
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
457 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
458 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
459 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
460 exit( EXIT_FAILURE );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
461 }
45
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
462 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
463 }
91
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 #if defined(UTIL_TEST)
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
466
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
467 /* Test code borrowed from wildmat.c. Yep, still uses gets(). */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
468 extern char *gets();
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
469
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
470 int
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
471 main()
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
472 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
473 Str line;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
474 time_t t;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
475
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
476 printf( "Util date tester. Enter date to test.\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
477 printf( "A blank line exits the program.\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
478
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
479 for ( ; ; )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
480 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
481 t = time( NULL );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
482 Utl_newsDate( t, line );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
483 printf( "\n(%s) Enter date: ", line );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
484 (void) fflush( stdout );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
485 if ( gets( line ) == NULL || line[0] == '\0' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
486 break;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
487
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
488 t = Utl_parseNewsDate( line );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
489 if ( t == (time_t) -1 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
490 printf( "Date parse failed\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
491 else
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
492 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
493 Utl_newsDate( t, line );
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
494 printf( "Utl_newsDate -> '%s'\n", line );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
495 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
496 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
497
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
498 exit(0);
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
499 /* NOTREACHED */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
500 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
501 #endif