annotate src/util.c @ 91:93cc929329eb noffle

[svn] Date output change and now date parsing
author bears
date Fri, 19 May 2000 16:12:45 +0100
parents bf8c97460fd7
children 2bedacfe1ba7
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
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
4 $Id: util.c 110 2000-05-19 15:12:45Z 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. */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
130 if ( res != NULL && !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'
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
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
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
268 void
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
269 Utl_newsDate( time_t t, Str res )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
270 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
271 struct tm local, localAsGmt;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
272 time_t tlocalAsGmt;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
273 int tzdiff, hoffset, moffset;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
274
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
275 local = *localtime( &t );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
276 memset( &localAsGmt, 0, sizeof( localAsGmt ) );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
277 localAsGmt.tm_sec = local.tm_sec;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
278 localAsGmt.tm_min = local.tm_min;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
279 localAsGmt.tm_hour = local.tm_hour;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
280 localAsGmt.tm_mday = local.tm_mday;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
281 localAsGmt.tm_mon = local.tm_mon;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
282 localAsGmt.tm_year = local.tm_year;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
283 tlocalAsGmt = mktime( &localAsGmt );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
284 tzdiff = (int) ( ( (long) difftime( tlocalAsGmt, t ) ) / 60 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
285 hoffset = tzdiff / 60;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
286 moffset = tzdiff % 60;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
287 if ( moffset < 0 ) moffset = -moffset;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
288
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
289 sprintf( res, "%s, %d %s %4d %02d:%02d:%02d %+03d%02d",
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
290 DOTW[local.tm_wday], local.tm_mday,
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
291 MON[local.tm_mon], local.tm_year + 1900,
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
292 local.tm_hour, local.tm_min, local.tm_sec,
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
293 hoffset, moffset );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
294 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
295
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
296 time_t
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
297 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
298 {
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
299 struct tm tm;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
300 int wday, tzoffset, hoffset, moffset;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
301 char *p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
302 time_t res;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
303
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
304 memset( &tm, 0, sizeof( tm ) );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
305 wday = -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
306
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
307 s = nextNonWhiteSpace( s );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
308
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
309 /* Is this the day number, or a weekday? */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
310 if ( ! isdigit( *s ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
311 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
312 if ( strlen( s ) < 4 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
313 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
314
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
315 for ( wday = 0; DOTW[ wday ] != NULL; wday++ )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
316 if ( strncmp( DOTW[ wday ], s, 3 ) == 0 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
317 break;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
318
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
319 if( DOTW[ wday ] == NULL || s[3] != ',' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
320 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
321
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
322 s += 4;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
323 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
324
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
325 /* Get the day number */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
326 tm.tm_mday = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
327 if ( p == s )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
328 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
329 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
330
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
331 /* Look for month name */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
332 s = nextNonWhiteSpace( s );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
333 if ( strlen( s ) < 4 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
334 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
335 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
336 if ( strncmp( MON[ tm.tm_mon ], s, 3 ) == 0 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
337 break;
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 if ( MON[ tm.tm_mon ] == NULL )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
340 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
341 s += 3;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
342
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
343 /* Year next */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
344 tm.tm_year = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
345 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
346 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
347 if ( tm.tm_year >= 1900 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
348 tm.tm_year -= 1900;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
349 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
350
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
351 /* Hours */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
352 tm.tm_hour = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
353 if ( p == s || *p != ':' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
354 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
355 s = ++p;
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 /* Minutes */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
358 tm.tm_min = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
359 if ( p == s || ( *p != ':' && *p != ' ' ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
360 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
361 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
362
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
363 /* Seconds */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
364 if ( *s == ':' )
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 s++;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
367 tm.tm_sec = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
368 if ( p == s )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
369 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
370 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
371 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
372
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
373 /* GMT/UT or timezone offset */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
374 tzoffset = 0;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
375 while ( isspace( *s ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
376 s++;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
377 if ( strncmp( s, "GMT", 3) == 0 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
378 s += 3;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
379 else if ( strncmp( s, "UT", 2 ) == 0 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
380 s += 2;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
381 else
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
382 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
383 tzoffset = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
384 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
385 }
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 /* Check for following junk */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
388 if ( *s != '\0' && ! isspace( *s ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
389 return (time_t) -1;
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 res = mktime( &tm );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
392 if ( res == (time_t) -1 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
393 return res;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
394
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
395 if ( wday >= 0 && wday != tm.tm_wday )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
396 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
397
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
398 moffset = tzoffset % 100;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
399 hoffset = tzoffset / 100;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
400 res = res - ( ( hoffset * 60 + moffset ) * 60 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
401 return res;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
402 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
403
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
404 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
405 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
406 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
407 int len = strlen( src );
45
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
408 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
409 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
410 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
411 exit( EXIT_FAILURE );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
412 }
45
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
413 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
414 }
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
415
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
416 #if defined(UTIL_TEST)
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 /* Test code borrowed from wildmat.c. Yep, still uses gets(). */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
419 extern char *gets();
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
420
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
421 int
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
422 main()
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
423 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
424 Str line;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
425 time_t t;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
426
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
427 printf( "Util date tester. Enter date to test.\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
428 printf( "A blank line exits the program.\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
429
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
430 for ( ; ; )
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 printf( "\nEnter date: " );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
433 (void) fflush( stdout );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
434 if ( gets( line ) == NULL || line[0] == '\0' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
435 break;
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 t = Utl_parseNewsDate( line );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
438 if ( t == (time_t) -1 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
439 printf( "Date parse failed\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
440 else
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
441 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
442 Utl_newsDate( t, line );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
443 printf( "Utl_newsDate -> '%s'\nctime() -> '%s'\n",
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
444 line, ctime( &t ) );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
445 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
446 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
447
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
448 exit(0);
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
449 /* NOTREACHED */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
450 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
451 #endif