io.c (15066) | io.c (15714) |
---|---|
1/* 2 * Copyright (c) 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint | 1/* 2 * Copyright (c) 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint |
35static char copyright[] = | 35static const char copyright[] = |
36"@(#) Copyright (c) 1989, 1993\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint | 36"@(#) Copyright (c) 1989, 1993\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint |
41static char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; | 41static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; |
42#endif /* not lint */ 43 44#include <sys/param.h> 45#include <stdio.h> 46#include <ctype.h> 47#include <sys/types.h> 48#include <sys/stat.h> 49#include <unistd.h> 50#include <err.h> 51#include <errno.h> | 42#endif /* not lint */ 43 44#include <sys/param.h> 45#include <stdio.h> 46#include <ctype.h> 47#include <sys/types.h> 48#include <sys/stat.h> 49#include <unistd.h> 50#include <err.h> 51#include <errno.h> |
52#include <locale.h> |
|
52#include <string.h> 53#include <sys/uio.h> 54#include <sys/time.h> 55#include <stdlib.h> 56#include <pwd.h> 57#include <sys/wait.h> 58 59#include "pathnames.h" 60#include "calendar.h" 61 62 63char *calendarFile = "calendar"; /* default calendar file */ 64char *calendarHome = ".calendar"; /* HOME */ 65char *calendarNoMail = "nomail"; /* don't sent mail if this file exist */ 66 67struct iovec header[] = { | 53#include <string.h> 54#include <sys/uio.h> 55#include <sys/time.h> 56#include <stdlib.h> 57#include <pwd.h> 58#include <sys/wait.h> 59 60#include "pathnames.h" 61#include "calendar.h" 62 63 64char *calendarFile = "calendar"; /* default calendar file */ 65char *calendarHome = ".calendar"; /* HOME */ 66char *calendarNoMail = "nomail"; /* don't sent mail if this file exist */ 67 68struct iovec header[] = { |
68 "From: ", 6, 69 NULL, 0, 70 " (Reminder Service)\nTo: ", 24, 71 NULL, 0, 72 "\nSubject: ", 10, 73 NULL, 0, 74 "'s Calendar\nPrecedence: bulk\n\n", 30, | 69 {"From: ", 6}, 70 {NULL, 0}, 71 {" (Reminder Service)\nTo: ", 24}, 72 {NULL, 0}, 73 {"\nSubject: ", 10}, 74 {NULL, 0}, 75 {"'s Calendar\nPrecedence: bulk\n\n", 30}, |
75}; 76 77 78void 79cal() 80{ 81 register int printing; 82 register char *p; 83 FILE *fp; | 76}; 77 78 79void 80cal() 81{ 82 register int printing; 83 register char *p; 84 FILE *fp; |
84 int ch; | 85 int ch, l; |
85 int month; 86 int day; 87 int var; 88 char buf[2048 + 1]; 89 90 if ((fp = opencal()) == NULL) 91 return; 92 for (printing = 0; fgets(buf, sizeof(buf), stdin) != NULL;) { 93 if ((p = strchr(buf, '\n')) != NULL) 94 *p = '\0'; 95 else 96 while ((ch = getchar()) != '\n' && ch != EOF); | 86 int month; 87 int day; 88 int var; 89 char buf[2048 + 1]; 90 91 if ((fp = opencal()) == NULL) 92 return; 93 for (printing = 0; fgets(buf, sizeof(buf), stdin) != NULL;) { 94 if ((p = strchr(buf, '\n')) != NULL) 95 *p = '\0'; 96 else 97 while ((ch = getchar()) != '\n' && ch != EOF); |
98 for (l = strlen(buf); 99 l > 0 && isspace((unsigned char)buf[l - 1]); 100 l--) 101 ; 102 buf[l] = '\0'; |
|
97 if (buf[0] == '\0') 98 continue; | 103 if (buf[0] == '\0') 104 continue; |
105 if (strncmp(buf, "LANG=", 5) == 0) { 106 (void) setlocale(LC_ALL, buf + 5); 107 setnnames(); 108 continue; 109 } |
|
99 if (buf[0] != '\t') { 100 printing = isnow(buf, &month, &day, &var) ? 1 : 0; 101 if ((p = strchr(buf, '\t')) == NULL) 102 continue; 103 if (p > buf && p[-1] == '*') 104 var = 1; 105 if (printing) 106 (void)fprintf(fp, "%.2d/%.2d%c%s\n", month, --- 8 unchanged lines hidden (view full) --- 115int 116getfield(p, endp, flags) 117 char *p, **endp; 118 int *flags; 119{ 120 int val, var; 121 char *start, savech; 122 | 110 if (buf[0] != '\t') { 111 printing = isnow(buf, &month, &day, &var) ? 1 : 0; 112 if ((p = strchr(buf, '\t')) == NULL) 113 continue; 114 if (p > buf && p[-1] == '*') 115 var = 1; 116 if (printing) 117 (void)fprintf(fp, "%.2d/%.2d%c%s\n", month, --- 8 unchanged lines hidden (view full) --- 126int 127getfield(p, endp, flags) 128 char *p, **endp; 129 int *flags; 130{ 131 int val, var; 132 char *start, savech; 133 |
123 for (; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p); | 134 for (; !isdigit((unsigned char)*p) && !isalpha((unsigned char)*p) && *p != '*'; ++p); |
124 if (*p == '*') { /* `*' is current month */ 125 *flags |= F_ISMONTH; 126 *endp = p+1; 127 return (tp->tm_mon + 1); 128 } | 135 if (*p == '*') { /* `*' is current month */ 136 *flags |= F_ISMONTH; 137 *endp = p+1; 138 return (tp->tm_mon + 1); 139 } |
129 if (isdigit(*p)) { | 140 if (isdigit((unsigned char)*p)) { |
130 val = strtol(p, &p, 10); /* if 0, it's failure */ | 141 val = strtol(p, &p, 10); /* if 0, it's failure */ |
131 for (; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p); | 142 for (; !isdigit((unsigned char)*p) && !isalpha((unsigned char)*p) && *p != '*'; ++p); |
132 *endp = p; 133 return (val); 134 } | 143 *endp = p; 144 return (val); 145 } |
135 for (start = p; isalpha(*++p);); | 146 for (start = p; isalpha((unsigned char)*++p);); |
136 137 /* Sunday-1 */ 138 if (*p == '+' || *p == '-') | 147 148 /* Sunday-1 */ 149 if (*p == '+' || *p == '-') |
139 for(; isdigit(*++p);); | 150 for(; isdigit((unsigned char)*++p);); |
140 141 savech = *p; 142 *p = '\0'; 143 144 /* Month */ 145 if ((val = getmonth(start)) != 0) 146 *flags |= F_ISMONTH; 147 --- 10 unchanged lines hidden (view full) --- 158#endif 159 } 160 } 161 162 /* Easter */ 163 else if ((val = geteaster(start, tp->tm_year + 1900)) != 0) 164 *flags |= F_EASTER; 165 | 151 152 savech = *p; 153 *p = '\0'; 154 155 /* Month */ 156 if ((val = getmonth(start)) != 0) 157 *flags |= F_ISMONTH; 158 --- 10 unchanged lines hidden (view full) --- 169#endif 170 } 171 } 172 173 /* Easter */ 174 else if ((val = geteaster(start, tp->tm_year + 1900)) != 0) 175 *flags |= F_EASTER; 176 |
177 /* Paskha */ 178 else if ((val = getpaskha(start, tp->tm_year + 1900)) != 0) 179 *flags |= F_EASTER; 180 |
|
166 /* undefined rest */ 167 else { 168 *p = savech; 169 return (0); 170 } | 181 /* undefined rest */ 182 else { 183 *p = savech; 184 return (0); 185 } |
171 for (*p = savech; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p); | 186 for (*p = savech; !isdigit((unsigned char)*p) && !isalpha((unsigned char)*p) && *p != '*'; ++p); |
172 *endp = p; 173 return (val); 174} 175 176char path[MAXPATHLEN + 1]; 177 178FILE * 179opencal() --- 103 unchanged lines hidden --- | 187 *endp = p; 188 return (val); 189} 190 191char path[MAXPATHLEN + 1]; 192 193FILE * 194opencal() --- 103 unchanged lines hidden --- |