parsetime.c (86848) | parsetime.c (87208) |
---|---|
1/* 2 * parsetime.c - parse time for at(1) 3 * Copyright (C) 1993, 1994 Thomas Koenig 4 * 5 * modifications for English-language times 6 * Copyright (C) 1993 David Parsons 7 * 8 * Redistribution and use in source and binary forms, with or without --- 21 unchanged lines hidden (view full) --- 30 * |NOON | |[TOMORROW] | 31 * |MIDNIGHT | |[DAY OF WEEK] | 32 * \TEATIME / |NUMBER [SLASH NUMBER [SLASH NUMBER]]| 33 * \PLUS NUMBER MINUTES|HOURS|DAYS|WEEKS/ 34 */ 35 36#ifndef lint 37static const char rcsid[] = | 1/* 2 * parsetime.c - parse time for at(1) 3 * Copyright (C) 1993, 1994 Thomas Koenig 4 * 5 * modifications for English-language times 6 * Copyright (C) 1993 David Parsons 7 * 8 * Redistribution and use in source and binary forms, with or without --- 21 unchanged lines hidden (view full) --- 30 * |NOON | |[TOMORROW] | 31 * |MIDNIGHT | |[DAY OF WEEK] | 32 * \TEATIME / |NUMBER [SLASH NUMBER [SLASH NUMBER]]| 33 * \PLUS NUMBER MINUTES|HOURS|DAYS|WEEKS/ 34 */ 35 36#ifndef lint 37static const char rcsid[] = |
38 "$FreeBSD: head/usr.bin/at/parsetime.c 86848 2001-11-24 10:43:53Z brian $"; | 38 "$FreeBSD: head/usr.bin/at/parsetime.c 87208 2001-12-02 12:26:18Z markm $"; |
39#endif /* not lint */ 40 41/* System Headers */ 42 43#include <sys/types.h> 44#include <ctype.h> 45#include <err.h> 46#include <errno.h> --- 5 unchanged lines hidden (view full) --- 52#ifndef __FreeBSD__ 53#include <getopt.h> 54#endif 55 56/* Local headers */ 57 58#include "at.h" 59#include "panic.h" | 39#endif /* not lint */ 40 41/* System Headers */ 42 43#include <sys/types.h> 44#include <ctype.h> 45#include <err.h> 46#include <errno.h> --- 5 unchanged lines hidden (view full) --- 52#ifndef __FreeBSD__ 53#include <getopt.h> 54#endif 55 56/* Local headers */ 57 58#include "at.h" 59#include "panic.h" |
60#include "parsetime.h" |
|
60 61 62/* Structures and unions */ 63 64enum { /* symbols */ 65 MIDNIGHT, NOON, TEATIME, 66 PM, AM, TOMORROW, TODAY, NOW, 67 MINUTES, HOURS, DAYS, WEEKS, MONTHS, YEARS, 68 NUMBER, PLUS, DOT, SLASH, ID, JUNK, 69 JAN, FEB, MAR, APR, MAY, JUN, 70 JUL, AUG, SEP, OCT, NOV, DEC, 71 SUN, MON, TUE, WED, THU, FRI, SAT 72 }; 73 74/* parse translation table - table driven parsers can be your FRIEND! 75 */ 76struct { | 61 62 63/* Structures and unions */ 64 65enum { /* symbols */ 66 MIDNIGHT, NOON, TEATIME, 67 PM, AM, TOMORROW, TODAY, NOW, 68 MINUTES, HOURS, DAYS, WEEKS, MONTHS, YEARS, 69 NUMBER, PLUS, DOT, SLASH, ID, JUNK, 70 JAN, FEB, MAR, APR, MAY, JUN, 71 JUL, AUG, SEP, OCT, NOV, DEC, 72 SUN, MON, TUE, WED, THU, FRI, SAT 73 }; 74 75/* parse translation table - table driven parsers can be your FRIEND! 76 */ 77struct { |
77 char *name; /* token name */ | 78 const char *name; /* token name */ |
78 int value; /* token id */ 79 int plural; /* is this plural? */ 80} Specials[] = { 81 { "midnight", MIDNIGHT,0 }, /* 00:00:00 of today or tomorrow */ 82 { "noon", NOON,0 }, /* 12:00:00 of today or tomorrow */ 83 { "teatime", TEATIME,0 }, /* 16:00:00 of today or tomorrow */ 84 { "am", AM,0 }, /* morning times for 0-12 clock */ 85 { "pm", PM,0 }, /* evening times for 0-12 clock */ --- 68 unchanged lines hidden (view full) --- 154/* Local functions */ 155 156/* 157 * parse a token, checking if it's something special to us 158 */ 159static int 160parse_token(char *arg) 161{ | 79 int value; /* token id */ 80 int plural; /* is this plural? */ 81} Specials[] = { 82 { "midnight", MIDNIGHT,0 }, /* 00:00:00 of today or tomorrow */ 83 { "noon", NOON,0 }, /* 12:00:00 of today or tomorrow */ 84 { "teatime", TEATIME,0 }, /* 16:00:00 of today or tomorrow */ 85 { "am", AM,0 }, /* morning times for 0-12 clock */ 86 { "pm", PM,0 }, /* evening times for 0-12 clock */ --- 68 unchanged lines hidden (view full) --- 155/* Local functions */ 156 157/* 158 * parse a token, checking if it's something special to us 159 */ 160static int 161parse_token(char *arg) 162{ |
162 int i; | 163 size_t i; |
163 164 for (i=0; i<(sizeof Specials/sizeof Specials[0]); i++) 165 if (strcasecmp(Specials[i].name, arg) == 0) { 166 sc_tokplur = Specials[i].plural; 167 return sc_tokid = Specials[i].value; 168 } 169 170 /* not special - must be some random id */ --- 17 unchanged lines hidden (view full) --- 188 if ((sc_token = malloc(sc_len)) == NULL) 189 errx(EXIT_FAILURE, "virtual memory exhausted"); 190} /* init_scanner */ 191 192/* 193 * token() fetches a token from the input stream 194 */ 195static int | 164 165 for (i=0; i<(sizeof Specials/sizeof Specials[0]); i++) 166 if (strcasecmp(Specials[i].name, arg) == 0) { 167 sc_tokplur = Specials[i].plural; 168 return sc_tokid = Specials[i].value; 169 } 170 171 /* not special - must be some random id */ --- 17 unchanged lines hidden (view full) --- 189 if ((sc_token = malloc(sc_len)) == NULL) 190 errx(EXIT_FAILURE, "virtual memory exhausted"); 191} /* init_scanner */ 192 193/* 194 * token() fetches a token from the input stream 195 */ 196static int |
196token() | 197token(void) |
197{ 198 int idx; 199 200 while (1) { 201 memset(sc_token, 0, sc_len); 202 sc_tokid = EOF; 203 sc_tokplur = 0; 204 idx = 0; --- 435 unchanged lines hidden --- | 198{ 199 int idx; 200 201 while (1) { 202 memset(sc_token, 0, sc_len); 203 sc_tokid = EOF; 204 sc_tokplur = 0; 205 idx = 0; --- 435 unchanged lines hidden --- |