Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From strftime.c
- /***
- *_expandtime() - Expand the conversion specifier
- *
- *Purpose:
- * Expand the given strftime conversion specifier using the time struct
- * and store it in the supplied buffer.
- *
- * The expansion is locale-dependent.
- *
- * *** For internal use with strftime() only ***
- *
- *Entry:
- * char specifier = strftime conversion specifier to expand
- * const struct tm *tmptr = pointer to time/date structure
- * char **string = address of pointer to output string
- * size_t *count = address of char count (space in output area)
- * struct __lc_time_data *lc_time = pointer to locale-specific info
- *
- *Exit:
- * BOOL true for success, false for failure
- *
- *Exceptions:
- *
- *******************************************************************************/
- static BOOL __cdecl _expandtime (
- _locale_t plocinfo,
- char specifier,
- const struct tm *timeptr,
- char **string,
- size_t *left,
- struct __lc_time_data *lc_time,
- unsigned alternate_form
- )
- {
- unsigned temp; /* temps */
- int wdaytemp;
- /* Use a copy of the appropriate __lc_time_data pointer. This
- should prevent the necessity of locking/unlocking in mthread
- code (if we can guarantee that the various __lc_time data
- structures are always in the same segment). contents of time
- strings structure can now change, so thus we do use locking */
- switch(specifier) { /* switch on specifier */
- case('a'): /* abbreviated weekday name */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_wday >=0 ) && ( timeptr->tm_wday <= 6 ) ), EINVAL, FALSE)
- _store_str((char *)(lc_time->wday_abbr[timeptr->tm_wday]),
- string, left);
- break;
- }
- case('A'): /* full weekday name */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_wday >=0 ) && ( timeptr->tm_wday <= 6 ) ), EINVAL, FALSE)
- _store_str((char *)(lc_time->wday[timeptr->tm_wday]),
- string, left);
- break;
- }
- case('b'): /* abbreviated month name */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_mon >=0 ) && ( timeptr->tm_mon <= 11 ) ), EINVAL, FALSE)
- _store_str((char *)(lc_time->month_abbr[timeptr->tm_mon]),
- string, left);
- break;
- }
- case('B'): /* full month name */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_mon >=0 ) && ( timeptr->tm_mon <= 11 ) ), EINVAL, FALSE)
- _store_str((char *)(lc_time->month[timeptr->tm_mon]),
- string, left);
- break;
- }
- case('c'): /* date and time display */
- if (alternate_form)
- {
- if(!_store_winword( plocinfo,
- WW_LDATEFMT,
- timeptr,
- string,
- left,
- lc_time))
- {
- return FALSE;
- }
- if (*left == 0)
- return FALSE;
- *(*string)++=' ';
- (*left)--;
- if(!_store_winword( plocinfo,
- WW_TIMEFMT,
- timeptr,
- string,
- left,
- lc_time))
- {
- return FALSE;
- }
- }
- else {
- if(!_store_winword( plocinfo,
- WW_SDATEFMT,
- timeptr,
- string,
- left,
- lc_time))
- {
- return FALSE;
- }
- if (*left == 0)
- return FALSE;
- *(*string)++=' ';
- (*left)--;
- if(!_store_winword( plocinfo,
- WW_TIMEFMT,
- timeptr,
- string,
- left,
- lc_time))
- {
- return FALSE;
- }
- }
- break;
- case('d'): /* mday in decimal (01-31) */
- /* pass alternate_form as the no leading zeros flag */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_mday >=1 ) && ( timeptr->tm_mday <= 31 ) ), EINVAL, FALSE)
- _store_num(timeptr->tm_mday, 2, string, left,
- alternate_form);
- break;
- }
- case('H'): /* 24-hour decimal (00-23) */
- /* pass alternate_form as the no leading zeros flag */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_hour >=0 ) && ( timeptr->tm_hour <= 23 ) ), EINVAL, FALSE)
- _store_num(timeptr->tm_hour, 2, string, left,
- alternate_form);
- break;
- }
- case('I'): /* 12-hour decimal (01-12) */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_hour >=0 ) && ( timeptr->tm_hour <= 23 ) ), EINVAL, FALSE)
- if (!(temp = timeptr->tm_hour%12))
- temp=12;
- /* pass alternate_form as the no leading zeros flag */
- _store_num(temp, 2, string, left, alternate_form);
- break;
- }
- case('j'): /* yday in decimal (001-366) */
- /* pass alternate_form as the no leading zeros flag */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_yday >=0 ) && ( timeptr->tm_yday <= 365 ) ), EINVAL, FALSE)
- _store_num(timeptr->tm_yday+1, 3, string, left,
- alternate_form);
- break;
- }
- case('m'): /* month in decimal (01-12) */
- /* pass alternate_form as the no leading zeros flag */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_mon >=0 ) && ( timeptr->tm_mon <= 11 ) ), EINVAL, FALSE)
- _store_num(timeptr->tm_mon+1, 2, string, left,
- alternate_form);
- break;
- }
- case('M'): /* minute in decimal (00-59) */
- /* pass alternate_form as the no leading zeros flag */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_min >=0 ) && ( timeptr->tm_min <= 59 ) ), EINVAL, FALSE)
- _store_num(timeptr->tm_min, 2, string, left,
- alternate_form);
- break;
- }
- case('p'): /* AM/PM designation */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_hour >=0 ) && ( timeptr->tm_hour <= 23 ) ), EINVAL, FALSE)
- if (timeptr->tm_hour <= 11)
- _store_str((char *)(lc_time->ampm[0]), string, left);
- else
- _store_str((char *)(lc_time->ampm[1]), string, left);
- break;
- }
- case('S'): /* secs in decimal (00-59) */
- /* pass alternate_form as the no leading zeros flag */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_sec >=0 ) && ( timeptr->tm_sec <= 59 ) ), EINVAL, FALSE)
- _store_num(timeptr->tm_sec, 2, string, left,
- alternate_form);
- break;
- }
- case('U'): /* sunday week number (00-53) */
- _VALIDATE_RETURN( ( ( timeptr->tm_wday >=0 ) && ( timeptr->tm_wday <= 6 ) ), EINVAL, FALSE)
- wdaytemp = timeptr->tm_wday;
- goto weeknum; /* join common code */
- case('w'): /* week day in decimal (0-6) */
- /* pass alternate_form as the no leading zeros flag */
- {
- _VALIDATE_RETURN( ( ( timeptr->tm_wday >=0 ) && ( timeptr->tm_wday <= 6 ) ), EINVAL, FALSE)
- _store_num(timeptr->tm_wday, 1, string, left,
- alternate_form);
- break;
- }
- case('W'): /* monday week number (00-53) */
- _VALIDATE_RETURN( ( ( timeptr->tm_wday >=0 ) && ( timeptr->tm_wday <= 6 ) ), EINVAL, FALSE)
- if (timeptr->tm_wday == 0) /* monday based */
- wdaytemp = 6;
- else
- wdaytemp = timeptr->tm_wday-1;
- weeknum:
- _VALIDATE_RETURN( ( ( timeptr->tm_yday >=0 ) && ( timeptr->tm_yday <= 365 ) ), EINVAL, FALSE)
- if (timeptr->tm_yday < wdaytemp)
- temp = 0;
- else {
- temp = timeptr->tm_yday/7;
- if ((timeptr->tm_yday%7) >= wdaytemp)
- temp++;
- }
- /* pass alternate_form as the no leading zeros flag */
- _store_num(temp, 2, string, left, alternate_form);
- break;
- case('x'): /* date display */
- if (alternate_form)
- {
- if(!_store_winword( plocinfo,
- WW_LDATEFMT,
- timeptr,
- string,
- left,
- lc_time))
- {
- return FALSE;
- }
- }
- else
- {
- if(!_store_winword( plocinfo,
- WW_SDATEFMT,
- timeptr,
- string,
- left,
- lc_time))
- {
- return FALSE;
- }
- }
- break;
- case('X'): /* time display */
- if(!_store_winword( plocinfo,
- WW_TIMEFMT,
- timeptr,
- string,
- left,
- lc_time))
- {
- return FALSE;
- }
- break;
- case('y'): /* year w/o century (00-99) */
- {
- _VALIDATE_RETURN( ( timeptr->tm_year >=0 ), EINVAL, FALSE)
- temp = timeptr->tm_year%100;
- /* pass alternate_form as the no leading zeros flag */
- _store_num(temp, 2, string, left, alternate_form);
- break;
- }
- case('Y'): /* year w/ century */
- {
- _VALIDATE_RETURN( ( timeptr->tm_year >= -1900 ) && ( timeptr->tm_year <= 8099 ), EINVAL, FALSE)
- temp = (((timeptr->tm_year/100)+19)*100) +
- (timeptr->tm_year%100);
- /* pass alternate_form as the no leading zeros flag */
- _store_num(temp, 4, string, left, alternate_form);
- break;
- }
- case('Z'): /* time zone name, if any */
- case('z'): /* time zone name, if any */
- __tzset(); /* Set time zone info */
- _BEGIN_SECURE_CRT_DEPRECATION_DISABLE
- _store_str(_tzname[((timeptr->tm_isdst)?1:0)],
- string, left);
- _END_SECURE_CRT_DEPRECATION_DISABLE
- break;
- case('%'): /* percent sign */
- *(*string)++ = '%';
- (*left)--;
- break;
- case('\004'): /* Workaround issue in older RogueWave libraries */
- case('\015'):
- break;
- default: /* unknown format directive */
- /* ignore the directive and continue */
- /* [ANSI: Behavior is undefined.] */
- _ASSERTE( ( "Invalid format directive" , 0 ) );
- return FALSE;
- break;
- } /* end % switch */
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment