?? strftime.c
字號:
if (*format == '#')
{
__alternate_form = 1;
format++;
}
_expandtime(*format, timeptr, &string, &left,
lc_time);
format++; /* skip format char */
break;
default:
/* store character, bump pointers, dec the char count */
if (isleadbyte((int)(*format)) && left > 1)
{
*string++ = *format++;
left--;
}
*string++ = *format++;
left--;
break;
}
}
/* All done. See if we terminated because we hit a null char or because
we ran out of space */
done:
_unlock_locale( local_lock_flag )
if (left > 0) {
/* Store a terminating null char and return the number of chars
we stored in the output string. */
*string = '\0';
return(maxsize-left);
}
else
return(0);
}
/***
*_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:
* none
*
*Exceptions:
*
*******************************************************************************/
static void __cdecl _expandtime (
char specifier,
const struct tm *timeptr,
char **string,
size_t *left,
struct __lc_time_data *lc_time
)
{
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 */
_store_str((char *)(lc_time->wday_abbr[timeptr->tm_wday]),
string, left);
break;
case('A'): /* full weekday name */
_store_str((char *)(lc_time->wday[timeptr->tm_wday]),
string, left);
break;
case('b'): /* abbreviated month name */
_store_str((char *)(lc_time->month_abbr[timeptr->tm_mon]),
string, left);
break;
case('B'): /* full month name */
_store_str((char *)(lc_time->month[timeptr->tm_mon]),
string, left);
break;
case('c'): /* date and time display */
if (__alternate_form)
{
__alternate_form = FALSE;
_store_winword(lc_time->ww_ldatefmt, timeptr, string, left, lc_time);
if (*left == 0)
return;
*(*string)++=' ';
(*left)--;
_store_winword(lc_time->ww_timefmt, timeptr, string, left, lc_time);
}
else {
_store_winword(lc_time->ww_sdatefmt, timeptr, string, left, lc_time);
if (*left == 0)
return;
*(*string)++=' ';
(*left)--;
_store_winword(lc_time->ww_timefmt, timeptr, string, left, lc_time);
}
break;
case('d'): /* mday in decimal (01-31) */
__no_lead_zeros = __alternate_form;
_store_num(timeptr->tm_mday, 2, string, left);
break;
case('H'): /* 24-hour decimal (00-23) */
__no_lead_zeros = __alternate_form;
_store_num(timeptr->tm_hour, 2, string, left);
break;
case('I'): /* 12-hour decimal (01-12) */
__no_lead_zeros = __alternate_form;
if (!(temp = timeptr->tm_hour%12))
temp=12;
_store_num(temp, 2, string, left);
break;
case('j'): /* yday in decimal (001-366) */
__no_lead_zeros = __alternate_form;
_store_num(timeptr->tm_yday+1, 3, string, left);
break;
case('m'): /* month in decimal (01-12) */
__no_lead_zeros = __alternate_form;
_store_num(timeptr->tm_mon+1, 2, string, left);
break;
case('M'): /* minute in decimal (00-59) */
__no_lead_zeros = __alternate_form;
_store_num(timeptr->tm_min, 2, string, left);
break;
case('p'): /* AM/PM designation */
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) */
__no_lead_zeros = __alternate_form;
_store_num(timeptr->tm_sec, 2, string, left);
break;
case('U'): /* sunday week number (00-53) */
__no_lead_zeros = __alternate_form;
wdaytemp = timeptr->tm_wday;
goto weeknum; /* join common code */
case('w'): /* week day in decimal (0-6) */
__no_lead_zeros = __alternate_form;
_store_num(timeptr->tm_wday, 1, string, left);
break;
case('W'): /* monday week number (00-53) */
__no_lead_zeros = __alternate_form;
if (timeptr->tm_wday == 0) /* monday based */
wdaytemp = 6;
else
wdaytemp = timeptr->tm_wday-1;
weeknum:
if (timeptr->tm_yday < wdaytemp)
temp=0;
else {
temp = timeptr->tm_yday/7;
if ((timeptr->tm_yday%7) >= wdaytemp)
temp++;
}
_store_num(temp, 2, string, left);
break;
case('x'): /* date display */
if (__alternate_form)
{
__alternate_form = FALSE;
_store_winword(lc_time->ww_ldatefmt, timeptr, string, left, lc_time);
}
else
{
_store_winword(lc_time->ww_sdatefmt, timeptr, string, left, lc_time);
}
break;
case('X'): /* time display */
__alternate_form = FALSE;
_store_winword(lc_time->ww_timefmt, timeptr, string, left, lc_time);
break;
case('y'): /* year w/o century (00-99) */
__no_lead_zeros = __alternate_form;
temp = timeptr->tm_year%100;
_store_num(temp, 2, string, left);
break;
case('Y'): /* year w/ century */
__no_lead_zeros = __alternate_form;
temp = (((timeptr->tm_year/100)+19)*100) +
(timeptr->tm_year%100);
_store_num(temp, 4, string, left);
break;
case('Z'): /* time zone name, if any */
case('z'): /* time zone name, if any */
#ifdef _MAC
_tzset(); /* Set time zone info */
#else /* _MAC */
__tzset(); /* Set time zone info */
#endif /* _MAC */
_store_str(_tzname[((timeptr->tm_isdst)?1:0)],
string, left);
break;
case('%'): /* percent sign */
*(*string)++ = '%';
(*left)--;
break;
default: /* unknown format directive */
/* ignore the directive and continue */
/* [ANSI: Behavior is undefined.] */
break;
} /* end % switch */
}
/***
*_store_str() - Copy a time string
*
*Purpose:
* Copy the supplied time string into the output string until
* (1) we hit a null in the time string, or (2) the given count
* goes to 0.
*
* *** For internal use with strftime() only ***
*
*Entry:
* char *in = pointer to null terminated time string
* char **out = address of pointer to output string
* size_t *count = address of char count (space in output area)
*
*Exit:
* none
*Exceptions:
*
*******************************************************************************/
static void __cdecl _store_str (
char *in,
char **out,
size_t *count
)
{
while ((*count != 0) && (*in != '\0')) {
*(*out)++ = *in++;
(*count)--;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -