mandoc.c (a66b65d0) | mandoc.c (aa2d850a) |
---|---|
1/* $Id: mandoc.c,v 1.4 2009/12/22 23:58:00 schwarze Exp $ */ | 1/* $Id: mandoc.c,v 1.5 2009/12/23 22:30:17 schwarze Exp $ */ |
2/* 3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --- 6 unchanged lines hidden (view full) --- 16 */ 17#include <sys/types.h> 18 19#include <assert.h> 20#include <ctype.h> 21#include <stdlib.h> 22#include <stdio.h> 23#include <string.h> | 2/* 3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --- 6 unchanged lines hidden (view full) --- 16 */ 17#include <sys/types.h> 18 19#include <assert.h> 20#include <ctype.h> 21#include <stdlib.h> 22#include <stdio.h> 23#include <string.h> |
24#include <time.h> |
|
24 25#include "libmandoc.h" 26 | 25 26#include "libmandoc.h" 27 |
28static int a2time(time_t *, const char *, const char *); 29 30 |
|
27int 28mandoc_special(const char *p) 29{ 30 int c; 31 32 if ('\\' != *p++) 33 return(0); 34 --- 123 unchanged lines hidden (view full) --- 158 p = strdup(ptr); 159 if (NULL == p) { 160 perror(NULL); 161 exit(EXIT_FAILURE); 162 } 163 164 return(p); 165} | 31int 32mandoc_special(const char *p) 33{ 34 int c; 35 36 if ('\\' != *p++) 37 return(0); 38 --- 123 unchanged lines hidden (view full) --- 162 p = strdup(ptr); 163 if (NULL == p) { 164 perror(NULL); 165 exit(EXIT_FAILURE); 166 } 167 168 return(p); 169} |
170 171 172static int 173a2time(time_t *t, const char *fmt, const char *p) 174{ 175 struct tm tm; 176 char *pp; 177 178 memset(&tm, 0, sizeof(struct tm)); 179 180 pp = strptime(p, fmt, &tm); 181 if (NULL != pp && '\0' == *pp) { 182 *t = mktime(&tm); 183 return(1); 184 } 185 186 return(0); 187} 188 189 190/* 191 * Convert from a manual date string (see mdoc(7) and man(7)) into a 192 * date according to the stipulated date type. 193 */ 194time_t 195mandoc_a2time(int flags, const char *p) 196{ 197 time_t t; 198 199 if (MTIME_MDOCDATE & flags) { 200 if (0 == strcmp(p, "$" "Mdocdate$")) 201 return(time(NULL)); 202 if (a2time(&t, "$" "Mdocdate: %b %d %Y $", p)) 203 return(t); 204 } 205 206 if (MTIME_CANONICAL & flags || MTIME_REDUCED & flags) 207 if (a2time(&t, "%b %d, %Y", p)) 208 return(t); 209 210 if (MTIME_ISO_8601 & flags) 211 if (a2time(&t, "%Y-%m-%d", p)) 212 return(t); 213 214 if (MTIME_REDUCED & flags) { 215 if (a2time(&t, "%d, %Y", p)) 216 return(t); 217 if (a2time(&t, "%Y", p)) 218 return(t); 219 } 220 221 return(0); 222} 223 |
|