⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parse_date.g.c

📁 a little DFA compiler.
💻 C
📖 第 1 页 / 共 5 页
字号:
			s->tok = buf;			s->ptr = &buf[s->ptr - s->bot];			cursor = &buf[cursor - s->bot];			s->pos = &buf[s->pos - s->bot];			s->lim = &buf[s->lim - s->bot];			s->top = &s->lim[BSIZE];			free(s->bot);			s->bot = buf;		}		if((cnt = read(s->fd, (char*) s->lim, BSIZE)) != BSIZE){			s->eof = &s->lim[cnt]; *(s->eof)++ = '\n';		}		s->lim += cnt;	}	return cursor;}#endifstatic timelib_sll timelib_meridian(char **ptr, timelib_sll h){	timelib_sll retval = 0;	while (!strchr("AaPp", **ptr)) {		++*ptr;	}	if (**ptr == 'a' || **ptr == 'A') {		if (h == 12) {			retval = -12;		}	} else if (h != 12) {		retval = 12;	}	++*ptr;	if (**ptr == '.') {		*ptr += 3;	} else {		++*ptr;	}	return retval;}static char *timelib_string(Scanner *s){	char *tmp = calloc(1, s->cur - s->tok + 1);	memcpy(tmp, s->tok, s->cur - s->tok);	return tmp;}static timelib_sll timelib_get_nr(char **ptr, int max_length){	char *begin, *end, *str;	timelib_sll tmp_nr = -1;	int len = 0;	while ((**ptr < '0') || (**ptr > '9')) {		if (**ptr == '\0') {			return -1;		}		++*ptr;	}	begin = *ptr;	while ((**ptr >= '0') && (**ptr <= '9') && len < max_length) {		++*ptr;		++len;	}	end = *ptr;	str = calloc(1, end - begin + 1);	memcpy(str, begin, end - begin);	tmp_nr = strtoll(str, NULL, 10);	free(str);	return tmp_nr;}static void timelib_skip_day_suffix(char **ptr){	if (isspace(**ptr)) {		return;	}	if (!strncasecmp(*ptr, "nd", 2) || !strncasecmp(*ptr, "rd", 2) ||!strncasecmp(*ptr, "st", 2) || !strncasecmp(*ptr, "th", 2)) {		*ptr += 2;	}}static double timelib_get_frac_nr(char **ptr, int max_length){	char *begin, *end, *str;	double tmp_nr = -1;	int len = 0;	while ((**ptr != '.') && ((**ptr < '0') || (**ptr > '9'))) {		if (**ptr == '\0') {			return -1;		}		++*ptr;	}	begin = *ptr;	while (((**ptr == '.') || ((**ptr >= '0') && (**ptr <= '9'))) && len < max_length) {		++*ptr;		++len;	}	end = *ptr;	str = calloc(1, end - begin + 1);	memcpy(str, begin, end - begin);	tmp_nr = strtod(str, NULL);	free(str);	return tmp_nr;}static timelib_ull timelib_get_unsigned_nr(char **ptr, int max_length){	timelib_ull dir = 1;	while (((**ptr < '0') || (**ptr > '9')) && (**ptr != '+') && (**ptr != '-')) {		if (**ptr == '\0') {			return -1;		}		++*ptr;	}	if (**ptr == '+') {		++*ptr;	} else if (**ptr == '-') {		dir = -1;		++*ptr;	}	return dir * timelib_get_nr(ptr, max_length);}static long timelib_parse_tz_cor(char **ptr){	char *begin = *ptr, *end;	long  tmp;	while (**ptr != '\0') {		++*ptr;	}	end = *ptr;	switch (end - begin) {		case 1:		case 2:			return HOUR(strtol(begin, NULL, 10));			break;		case 3:		case 4:			if (begin[1] == ':') {				tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 2, NULL, 10);				return tmp;			} else if (begin[2] == ':') {				tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);				return tmp;			} else {				tmp = strtol(begin, NULL, 10);				return HOUR(tmp / 100) + tmp % 100;			}		case 5:			tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);			return tmp;	}	return 0;}static timelib_sll timelib_lookup_relative_text(char **ptr, int *behavior){	char *word;	char *begin = *ptr, *end;	timelib_sll  value = 0;	const timelib_lookup_table *tp;	while ((**ptr >= 'A' && **ptr <= 'Z') || (**ptr >= 'a' && **ptr <= 'z')) {		++*ptr;	}	end = *ptr;	word = calloc(1, end - begin + 1);	memcpy(word, begin, end - begin);	for (tp = timelib_reltext_lookup; tp->name; tp++) {		if (strcasecmp(word, tp->name) == 0) {			value = tp->value;			*behavior = tp->type;		}	}	free(word);	return value;}static timelib_sll timelib_get_relative_text(char **ptr, int *behavior){	while (**ptr == ' ' || **ptr == '-' || **ptr == '/') {		++*ptr;	}	return timelib_lookup_relative_text(ptr, behavior);}static long timelib_lookup_month(char **ptr){	char *word;	char *begin = *ptr, *end;	long  value = 0;	const timelib_lookup_table *tp;	while ((**ptr >= 'A' && **ptr <= 'Z') || (**ptr >= 'a' && **ptr <= 'z')) {		++*ptr;	}	end = *ptr;	word = calloc(1, end - begin + 1);	memcpy(word, begin, end - begin);	for (tp = timelib_month_lookup; tp->name; tp++) {		if (strcasecmp(word, tp->name) == 0) {			value = tp->value;		}	}	free(word);	return value;}static long timelib_get_month(char **ptr){	while (**ptr == ' ' || **ptr == '-' || **ptr == '.' || **ptr == '/') {		++*ptr;	}	return timelib_lookup_month(ptr);}static void timelib_eat_spaces(char **ptr){	while (**ptr == ' ') {		++*ptr;	}}static const timelib_relunit* timelib_lookup_relunit(char **ptr){	char *word;	char *begin = *ptr, *end;	const timelib_relunit *tp, *value = NULL;	while (**ptr != '\0' && **ptr != ' ') {		++*ptr;	}	end = *ptr;	word = calloc(1, end - begin + 1);	memcpy(word, begin, end - begin);	for (tp = timelib_relunit_lookup; tp->name; tp++) {		if (strcasecmp(word, tp->name) == 0) {			value = tp;			break;		}	}	free(word);	return value;}static void timelib_set_relative(char **ptr, timelib_sll amount, int behavior, Scanner *s){	const timelib_relunit* relunit;	relunit = timelib_lookup_relunit(ptr);	switch (relunit->unit) {		case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break;		case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break;		case TIMELIB_HOUR:   s->time->relative.h += amount * relunit->multiplier; break;		case TIMELIB_DAY:    s->time->relative.d += amount * relunit->multiplier; break;		case TIMELIB_MONTH:  s->time->relative.m += amount * relunit->multiplier; break;		case TIMELIB_YEAR:   s->time->relative.y += amount * relunit->multiplier; break;		case TIMELIB_WEEKDAY:			TIMELIB_HAVE_WEEKDAY_RELATIVE();			TIMELIB_UNHAVE_TIME();			s->time->relative.d += (amount > 0 ? amount - 1 : amount) * 7;			s->time->relative.weekday = relunit->multiplier;			s->time->relative.weekday_behavior = behavior;			break;	}}static timelib_tz_lookup_table* zone_search(const char *word, long gmtoffset, int isdst){	int first_found = 0;	timelib_tz_lookup_table  *tp, *first_found_elem;	timelib_tz_lookup_table  *fmp;	if (strcasecmp("utc", word) == 0 || strcasecmp("gmt", word) == 0) {		return timelib_timezone_utc;	}		for (tp = timelib_timezone_lookup; tp->name; tp++) {		if (strcasecmp(word, tp->name) == 0) {			if (!first_found) {				first_found = 1;				first_found_elem = tp;				if (gmtoffset == -1) {					return tp;				}			}			if (tp->gmtoffset == gmtoffset) {				return tp;			}		}	}	if (first_found) {		return first_found_elem;	}	/* Still didn't find anything, let's find the zone solely based on	 * offset/isdst then */	for (fmp = timelib_timezone_fallbackmap; fmp->name; fmp++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -