📄 output.c
字号:
*ifdef _UNICODE
*void write_multi_char(wchar_t ch, int num, FILE *f, int *pnumwritten)
*endif
*void write_multi_char(int ch, int num, FILE *f, int *pnumwritten)
*
*Purpose:
* Writes num copies of a character to the given file/console. If no error occurs,
* then *pnumwritten is incremented by num; otherwise, *pnumwritten is set
* to -1. If num is negative, it is treated as zero.
*
*Entry:
* int ch - character to write
* int num - number of times to write the characters
* FILE *f - file to write to
* int *pnumwritten - pointer to integer to update with total chars written
*
*Exit:
* No return value.
*
*Exceptions:
*
*******************************************************************************/
#ifdef CPRFLAG
LOCAL(void) write_multi_char (
int ch,
int num,
int *pnumwritten
)
{
while (num-- > 0) {
write_char(ch, pnumwritten);
if (*pnumwritten == -1)
break;
}
}
#else /* CPRFLAG */
#ifdef _UNICODE
LOCAL(void) write_multi_char (
wchar_t ch,
int num,
FILE *f,
int *pnumwritten
)
#else /* _UNICODE */
LOCAL(void) write_multi_char (
int ch,
int num,
FILE *f,
int *pnumwritten
)
#endif /* _UNICODE */
{
while (num-- > 0) {
write_char(ch, f, pnumwritten);
if (*pnumwritten == -1)
break;
}
}
#endif /* CPRFLAG */
/***
*void write_string(char *string, int len, int *pnumwritten)
*void write_string(char *string, int len, FILE *f, int *pnumwritten)
*ifdef _UNICODE
*void write_string(wchar_t *string, int len, FILE *f, int *pnumwritten)
*endif
*void write_wstring(wchar_t *string, int len, int *pnumwritten)
*void write_wstring(wchar_t *string, int len, FILE *f, int *pnumwritten)
*
*Purpose:
* Writes a string of the given length to the given file. If no error occurs,
* then *pnumwritten is incremented by len; otherwise, *pnumwritten is set
* to -1. If len is negative, it is treated as zero.
*
*Entry:
* char *string - string to write (NOT null-terminated)
* int len - length of string
* FILE *f - file to write to
* int *pnumwritten - pointer to integer to update with total chars written
*
*Exit:
* No return value.
*
*Exceptions:
*
*******************************************************************************/
#ifdef CPRFLAG
LOCAL(void) write_string (
char *string,
int len,
int *pnumwritten
)
{
while (len-- > 0) {
write_char(*string++, pnumwritten);
if (*pnumwritten == -1)
break;
}
}
#else /* CPRFLAG */
#if _UNICODE
LOCAL(void) write_string (
wchar_t *string,
int len,
FILE *f,
int *pnumwritten
)
#else /* _UNICODE */
LOCAL(void) write_string (
char *string,
int len,
FILE *f,
int *pnumwritten
)
#endif /* _UNICODE */
{
while (len-- > 0) {
write_char(*string++, f, pnumwritten);
if (*pnumwritten == -1)
break;
}
}
#endif /* CPRFLAG */
/***
*int get_int_arg(va_list *pargptr)
*
*Purpose:
* Gets an int argument off the given argument list and updates *pargptr.
*
*Entry:
* va_list *pargptr - pointer to argument list; updated by function
*
*Exit:
* Returns the integer argument read from the argument list.
*
*Exceptions:
*
*******************************************************************************/
__inline int __cdecl get_int_arg (
va_list *pargptr
)
{
return va_arg(*pargptr, int);
}
/***
*long get_long_arg(va_list *pargptr)
*
*Purpose:
* Gets an long argument off the given argument list and updates *pargptr.
*
*Entry:
* va_list *pargptr - pointer to argument list; updated by function
*
*Exit:
* Returns the long argument read from the argument list.
*
*Exceptions:
*
*******************************************************************************/
#if !LONG_IS_INT
__inline long __cdecl get_long_arg (
va_list *pargptr
)
{
return va_arg(*pargptr, long);
}
#endif /* !LONG_IS_INT */
#if _INTEGRAL_MAX_BITS >= 64
__inline __int64 __cdecl get_int64_arg (
va_list *pargptr
)
{
return va_arg(*pargptr, __int64);
}
#endif /* _INTEGRAL_MAX_BITS >= 64 */
#ifndef _UNICODE
/***
*short get_short_arg(va_list *pargptr)
*
*Purpose:
* Gets a short argument off the given argument list and updates *pargptr.
* *** CURRENTLY ONLY USED TO GET A WCHAR_T, IFDEF _INTL ***
*
*Entry:
* va_list *pargptr - pointer to argument list; updated by function
*
*Exit:
* Returns the short argument read from the argument list.
*
*Exceptions:
*
*******************************************************************************/
#if !SHORT_IS_INT
__inline short __cdecl get_short_arg (
va_list *pargptr
)
{
return va_arg(*pargptr, short);
}
#endif /* !SHORT_IS_INT */
#endif /* _UNICODE */
#else /* _WIN32 */
#if defined (_M_MPPC) || defined (_M_M68K)
#include <cruntime.h>
#include <limits.h>
#include <string.h>
#include <stddef.h>
#include <stdio.h>
#include <stdarg.h>
#include <cvt.h>
#include <conio.h>
#include <internal.h>
#include <fltintrn.h>
#include <tchar.h>
#include <stdlib.h>
#include <ctype.h>
#include <dbgint.h>
/*
* Code under if defined(_WIN32_) && !defined(_DOSX32_) && !defined(_INTL)
* is partial international support written by NT developers. This code
* should be removed when international sources are merged with orville.
*/
/* this macro defines a function which is private and as fast as possible: */
/* for example, in C 6.0, it might be static _fastcall <type> near. */
#define LOCAL(x) static x __cdecl
/* int/long/short/pointer sizes */
/* the following should be set depending on the sizes of various types */
#define LONG_IS_INT 1 /* 1 means long is same size as int */
#define SHORT_IS_INT 0 /* 1 means short is same size as int */
#define PTR_IS_INT 1 /* 1 means ptr is same size as int */
#define PTR_IS_LONG 1 /* 1 means ptr is same size as long */
#ifdef _M_MPPC
#define LONGDOUBLE_IS_DOUBLE 1 /* 1 means long double is same as double */
#else /* _M_MPPC */
#define LONGDOUBLE_IS_DOUBLE 0 /* 1 means long double is same as double */
#endif /* _M_MPPC */
#ifndef _INTEGRAL_MAX_BITS
#define _INTEGRAL_MAX_BITS 64
#endif /* _INTEGRAL_MAX_BITS */
#if LONG_IS_INT
#define get_long_arg(x) (long)get_int_arg(x)
#endif /* LONG_IS_INT */
#if PTR_IS_INT
#define get_ptr_arg(x) (void *)get_int_arg(x)
#elif PTR_IS_LONG
#define get_ptr_arg(x) (void *)get_long_arg(x)
#else /* PTR_IS_LONG */
#error Size of pointer must be same as size of int or long
#endif /* PTR_IS_LONG */
/* CONSTANTS */
/* size of conversion buffer (ANSI-specified minimum is 509) */
#define BUFFERSIZE 512
#if BUFFERSIZE < CVTBUFSIZE
#error Conversion buffer too small for max double.
#endif /* BUFFERSIZE < CVTBUFSIZE */
/* flag definitions */
#define FL_SIGN 0x0001 /* put plus or minus in front */
#define FL_SIGNSP 0x0002 /* put space or minus in front */
#define FL_LEFT 0x0004 /* left justify */
#define FL_LEADZERO 0x0008 /* pad with leading zeros */
#define FL_LONG 0x0010 /* long value given */
#define FL_SHORT 0x0020 /* short value given */
#define FL_SIGNED 0x0040 /* signed data given */
#define FL_ALTERNATE 0x0080 /* alternate form requested */
#define FL_NEGATIVE 0x0100 /* value is negative */
#define FL_FORCEOCTAL 0x0200 /* force leading '0' for octals */
#define FL_LONGDOUBLE 0x0400 /* long double value given */
#define FL_WIDECHAR 0x0800 /* wide characters */
#define FL_I64 0x08000 /* __int64 value given */
/* state definitions */
enum STATE {
ST_NORMAL, /* normal state; outputting literal chars */
ST_PERCENT, /* just read '%' */
ST_FLAG, /* just read flag character */
ST_WIDTH, /* just read width specifier */
ST_DOT, /* just read '.' */
ST_PRECIS, /* just read precision specifier */
ST_SIZE, /* just read size specifier */
ST_TYPE /* just read type specifier */
};
#define NUMSTATES (ST_TYPE + 1)
/* character type values */
enum CHARTYPE {
CH_OTHER, /* character with no special meaning */
CH_PERCENT, /* '%' */
CH_DOT, /* '.' */
CH_STAR, /* '*' */
CH_ZERO, /* '0' */
CH_DIGIT, /* '1'..'9' */
CH_FLAG, /* ' ', '+', '-', '#' */
CH_SIZE, /* 'h', 'l', 'L', 'N', 'F', 'w' */
CH_TYPE /* type specifying character */
};
/* static data (read only, since we are re-entrant) */
static char *nullstring = "(null)"; /* string to print on null ptr */
#ifdef _UNICODE
static wchar_t *wnullstring = L"(null)";/* string to print on null ptr */
#endif /* _UNICODE */
/* The state table. This table is actually two tables combined into one. */
/* The lower nybble of each byte gives the character class of any */
/* character; while the uper nybble of the byte gives the next state */
/* to enter. See the macros below the table for details. */
/* */
/* The table is generated by maketabc.c -- use this program to make */
/* changes. */
static char lookuptable[] = {
0x06, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00,
0x10, 0x00, 0x03, 0x06, 0x00, 0x06, 0x02, 0x10,
0x04, 0x45, 0x45, 0x45, 0x05, 0x05, 0x05, 0x05,
0x05, 0x35, 0x30, 0x00, 0x50, 0x00, 0x00, 0x00,
0x00, 0x20, 0x28, 0x38, 0x50, 0x58, 0x07, 0x08,
0x00, 0x37, 0x30, 0x30, 0x57, 0x50, 0x07, 0x00,
0x00, 0x20, 0x20, 0x08, 0x00, 0x00, 0x00, 0x00,
0x08, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00,
0x00, 0x70, 0x70, 0x78, 0x78, 0x78, 0x78, 0x08,
0x07, 0x08, 0x00, 0x00, 0x07, 0x00, 0x08, 0x08,
0x08, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x08,
0x08
};
#define find_char_class(c) \
((c) < ' ' || (c) > 'x' ? \
CH_OTHER \
: \
lookuptable[(c)-' '] & 0xF)
#define find_next_state(class, state) \
(lookuptable[(class) * NUMSTATES + (state)] >> 4)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -