?? strftime.c
字號:
/***
*_store_num() - Convert a number to ascii and copy it
*
*Purpose:
* Convert the supplied number to decimal and store
* in the output buffer. Update both the count and
* buffer pointers.
*
* *** For internal use with strftime() only ***
*
*Entry:
* int num = pointer to integer value
* int digits = # of ascii digits to put into 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_num (
int num,
int digits,
char **out,
size_t *count
)
{
int temp=0;
if (__no_lead_zeros) {
_store_number (num, out, count);
return;
}
if ((size_t)digits < *count) {
for (digits--; (digits+1); digits--) {
(*out)[digits] = (char)('0' + num % 10);
num /= 10;
temp++;
}
*out += temp;
*count -= temp;
}
else
*count = 0;
}
/***
*_store_number() - Convert positive integer to string
*
*Purpose:
* Convert positive integer to a string and store it in the output
* buffer with no null terminator. Update both the count and
* buffer pointers.
*
* Differs from _store_num in that the precision is not specified,
* and no leading zeros are added.
*
* *** For internal use with strftime() only ***
*
* Created from xtoi.c
*
*Entry:
* int num = pointer to integer value
* char **out = address of pointer to output string
* size_t *count = address of char count (space in output area)
*
*Exit:
* none
*
*Exceptions:
* The buffer is filled until it is out of space. There is no
* way to tell beforehand (as in _store_num) if the buffer will
* run out of space.
*
*******************************************************************************/
static void __cdecl _store_number (
int num,
char **out,
size_t *count
)
{
char *p; /* pointer to traverse string */
char *firstdig; /* pointer to first digit */
char temp; /* temp char */
p = *out;
/* put the digits in the buffer in reverse order */
if (*count > 1)
{
do {
*p++ = (char) (num % 10 + '0');
(*count)--;
} while ((num/=10) > 0 && *count > 1);
}
firstdig = *out; /* firstdig points to first digit */
*out = p; /* return pointer to next space */
p--; /* p points to last digit */
/* reverse the buffer */
do {
temp = *p;
*p-- = *firstdig;
*firstdig++ = temp; /* swap *p and *firstdig */
} while (firstdig < p); /* repeat until halfway */
}
/***
*_store_winword() - Store date/time in WinWord format
*
*Purpose:
* Format the date/time in the supplied WinWord format
* and store it in the supplied buffer.
*
* *** For internal use with strftime() only ***
*
* The WinWord format is converted token by token to
* strftime conversion specifiers. _expandtime is then called to
* do the work. The WinWord format is expected to be a
* character string (not wide-chars).
*
*Entry:
* const char **format = address of pointer to WinWord format
* const struct tm *tmptr = pointer to time/date structure
* char **out = 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 _store_winword (
const char *format,
const struct tm *tmptr,
char **out,
size_t *count,
struct __lc_time_data *lc_time
)
{
char specifier;
const char *p;
int repeat;
char *ampmstr;
while (*format && *count != 0)
{
specifier = 0; /* indicate no match */
__no_lead_zeros = 0; /* default is print leading zeros */
/* count the number of repetitions of this character */
for (repeat=0, p=format; *p++ == *format; repeat++);
/* leave p pointing to the beginning of the next token */
p--;
/* switch on ascii format character and determine specifier */
switch (*format)
{
case 'M':
switch (repeat)
{
case 1: __no_lead_zeros = 1; /* fall thru */
case 2: specifier = 'm'; break;
case 3: specifier = 'b'; break;
case 4: specifier = 'B'; break;
} break;
case 'd':
switch (repeat)
{
case 1: __no_lead_zeros = 1; /* fall thru */
case 2: specifier = 'd'; break;
case 3: specifier = 'a'; break;
case 4: specifier = 'A'; break;
} break;
case 'y':
switch (repeat)
{
case 2: specifier = 'y'; break;
case 4: specifier = 'Y'; break;
} break;
case 'h':
switch (repeat)
{
case 1: __no_lead_zeros = 1; /* fall thru */
case 2: specifier = 'I'; break;
} break;
case 'H':
switch (repeat)
{
case 1: __no_lead_zeros = 1; /* fall thru */
case 2: specifier = 'H'; break;
} break;
case 'm':
switch (repeat)
{
case 1: __no_lead_zeros = 1; /* fall thru */
case 2: specifier = 'M'; break;
} break;
case 's': /* for compatibility; not strictly WinWord */
switch (repeat)
{
case 1: __no_lead_zeros = 1; /* fall thru */
case 2: specifier = 'S'; break;
} break;
case 'A':
case 'a':
if (!_stricmp(format, "am/pm"))
p = format + 5;
else if (!_stricmp(format, "a/p"))
p = format + 3;
specifier = 'p';
break;
case 't': /* t or tt time marker suffix */
if ( tmptr->tm_hour <= 11 )
ampmstr = lc_time->ampm[0];
else
ampmstr = lc_time->ampm[1];
while ( (repeat > 0) && (*count > 0) )
{
if ( isleadbyte((int)*ampmstr) &&
(*count > 1) )
{
*(*out)++ = *ampmstr++;
(*count)--;
}
*(*out)++ = *ampmstr++;
(*count)--;
repeat--;
}
format = p;
continue;
case '\'': /* literal string */
if (repeat & 1) /* odd number */
{
format += repeat;
while (*format && *count != 0)
{
if (*format == '\'')
{
format++;
break;
}
if ( isleadbyte((int)*format) &&
(*count > 1) )
{
*(*out)++ = *format++;
(*count)--;
}
*(*out)++ = *format++;
(*count)--;
}
}
else { /* even number */
format += repeat;
}
continue;
default: /* non-control char, print it */
break;
} /* switch */
/* expand specifier, or copy literal if specifier not found */
if (specifier)
{
_expandtime(specifier, tmptr, out, count, lc_time);
format = p; /* bump format up to the next token */
} else {
if (isleadbyte((int)*format))
{
*(*out)++ = *format++;
(*count)--;
}
*(*out)++ = *format++;
(*count)--;
}
} /* while */
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -