/* Parse a number from a token */ VyParseTree* ParseNumberFromToken(VyToken* tok){ char* numData = tok->data; VyNumber** num = ParseNumber(numData); /* Check for errors in the parsing */ char* error = GetLastNumberParsingError(); if(error != NULL){ return ParseError(error); } /* If no errors, return the parsing result */ else{ VyParseTree* tree = MakeNum(); SetNumberData(tree, num); return tree; } }
/* %%Function:InitRnd %%Owner:bryanl */ InitRnd() { Assert(fInitialized); MakeNum(&numRndSeed, 0L, DttmCur(), 5); }
time_t Ns_ParseHttpTime(char *str) { char *s; struct tm tm; time_t t; if (str == NULL) { return 0; } /* * Find the comma after day-of-week * * Thursday, 10-Jun-93 01:29:59 GMT * ^ * +-- s * * Thu, 10 Jan 1993 01:29:59 GMT * ^ * +-- s */ s = strchr(str, ','); if (s != NULL) { /* * Advance S to the first non-space after the comma * which should be the first digit of the day. */ s++; while (*s && *s == ' ') { s++; } /* * Figure out which format it is in. If there is a hyphen, then * it must be the first format. */ if (strchr(s, '-') != NULL) { if (strlen(s) < 18) { return 0; } /* * The format is: * * Thursday, 10-Jun-93 01:29:59 GMT * ^ * +--s */ tm.tm_mday = MakeNum(s); tm.tm_mon = MakeMonth(s + 3); tm.tm_year = MakeNum(s + 7); tm.tm_hour = MakeNum(s + 10); tm.tm_min = MakeNum(s + 13); tm.tm_sec = MakeNum(s + 16); } else { if ((int) strlen(s) < 20) { return 0; } /* * The format is: * * Thu, 10 Jan 1993 01:29:59 GMT * ^ * +--s */ tm.tm_mday = MakeNum(s); tm.tm_mon = MakeMonth(s + 3); tm.tm_year = (100 * MakeNum(s + 7) - 1900) + MakeNum(s + 9); tm.tm_hour = MakeNum(s + 12); tm.tm_min = MakeNum(s + 15); tm.tm_sec = MakeNum(s + 18); } } else { /* * No commas, so it must be the third, fixed field, format: * * Wed Jun 9 01:29:59 1993 GMT * * Advance s to the first letter of the month. */ s = str; while (*s && *s == ' ') { s++; } if ((int) strlen(s) < 24) { return 0; } tm.tm_mday = MakeNum(s + 8); tm.tm_mon = MakeMonth(s + 4); tm.tm_year = MakeNum(s + 22); tm.tm_hour = MakeNum(s + 11); tm.tm_min = MakeNum(s + 14); tm.tm_sec = MakeNum(s + 17); } /* * If there are any impossible values, then return an error. */ if (tm.tm_sec < 0 || tm.tm_sec > 59 || tm.tm_min < 0 || tm.tm_min > 59 || tm.tm_hour < 0 || tm.tm_hour > 23 || tm.tm_mday < 1 || tm.tm_mday > 31 || tm.tm_mon < 0 || tm.tm_mon > 11 || tm.tm_year < 70 || tm.tm_year > 120) { return 0; } tm.tm_isdst = 0; #ifdef HAVE_TIMEGM t = timegm(&tm); #else t = mktime(&tm) - timezone; #endif return t; }