# define SQLITE_CDECL
#endif
-#ifndef SQLITE_SHELL_FIDDLE
-
#ifndef SHELL_NO_SYSINC
# include <stdarg.h>
# include <string.h>
# include "sqlite3.h"
#endif
-#if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT
-# ifndef SHELL_NO_SYSINC
-# include <io.h>
-# include <fcntl.h>
-# undef WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
+#ifndef SQLITE_CIO_NO_TRANSLATE
+# if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT
+# ifndef SHELL_NO_SYSINC
+# include <io.h>
+# include <fcntl.h>
+# undef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+# endif
+# define CIO_WIN_WC_XLATE 1 /* Use WCHAR Windows APIs for console I/O */
+# else
+# ifndef SHELL_NO_SYSINC
+# include <unistd.h>
+# endif
+# define CIO_WIN_WC_XLATE 0 /* Use plain C library stream I/O at console */
# endif
-# define SHELL_CON_TRANSLATE 1 /* Use WCHAR Windows APIs for console I/O */
#else
-# ifndef SHELL_NO_SYSINC
-# include <unistd.h>
-# endif
-# define SHELL_CON_TRANSLATE 0 /* Use plain C library stream I/O at console */
+# define CIO_WIN_WC_XLATE 0 /* Not exposing translation routines at all */
#endif
-#if SHELL_CON_TRANSLATE
+#if CIO_WIN_WC_XLATE
/* Character used to represent a known-incomplete UTF-8 char group (�) */
static WCHAR cBadGroup = 0xfffd;
#endif
-#if SHELL_CON_TRANSLATE
+#if CIO_WIN_WC_XLATE
static HANDLE handleOfFile(FILE *pf){
int fileDesc = _fileno(pf);
union { intptr_t osfh; HANDLE fh; } fid = {
}
#endif
+#ifndef SQLITE_CIO_NO_TRANSLATE
typedef struct PerStreamTags {
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
HANDLE hx;
DWORD consMode;
char acIncomplete[4];
-#else
+# else
short reachesConsole;
-#endif
+# endif
FILE *pf;
} PerStreamTags;
/* Define NULL-like value for things which can validly be 0. */
-#define SHELL_INVALID_FILE_PTR ((FILE *)~0)
-#if SHELL_CON_TRANSLATE
-# define SHELL_INVALID_CONS_MODE 0xFFFF0000
-#endif
+# define SHELL_INVALID_FILE_PTR ((FILE *)~0)
+# if CIO_WIN_WC_XLATE
+# define SHELL_INVALID_CONS_MODE 0xFFFF0000
+# endif
-#if SHELL_CON_TRANSLATE
-# define PST_INITIALIZER { INVALID_HANDLE_VALUE, SHELL_INVALID_CONS_MODE, \
+# if CIO_WIN_WC_XLATE
+# define PST_INITIALIZER { INVALID_HANDLE_VALUE, SHELL_INVALID_CONS_MODE, \
{0,0,0,0}, SHELL_INVALID_FILE_PTR }
-#else
-# define PST_INITIALIZER { 0, SHELL_INVALID_FILE_PTR }
-#endif
+# else
+# define PST_INITIALIZER { 0, SHELL_INVALID_FILE_PTR }
+# endif
/* Quickly say whether a known output is going to the console. */
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
static short pstReachesConsole(PerStreamTags *ppst){
-# if SHELL_CON_TRANSLATE
return (ppst->hx != INVALID_HANDLE_VALUE);
+}
# else
- return (ppst->reachesConsole != 0);
+# define pstReachesConsole(ppst) 0
# endif
-}
-#else
-# define pstReachesConsole(ppst) 0
-#endif
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
static void restoreConsoleArb(PerStreamTags *ppst){
if( pstReachesConsole(ppst) ) SetConsoleMode(ppst->hx, ppst->consMode);
}
-#else
-# define restoreConsoleArb(ppst)
-#endif
+# else
+# define restoreConsoleArb(ppst)
+# endif
/* Say whether FILE* appears to be a console, collect associated info. */
static short streamOfConsole(FILE *pf, /* out */ PerStreamTags *ppst){
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
short rv = 0;
DWORD dwCM = SHELL_INVALID_CONS_MODE;
HANDLE fh = handleOfFile(pf);
ppst->hx = (rv)? fh : INVALID_HANDLE_VALUE;
ppst->consMode = dwCM;
return rv;
-#else
+# else
ppst->pf = pf;
ppst->reachesConsole = ( (short)isatty(fileno(pf)) );
return ppst->reachesConsole;
-#endif
+# endif
}
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
/* Define console modes for use with the Windows Console API. */
-# define SHELL_CONI_MODE \
+# define SHELL_CONI_MODE \
(ENABLE_ECHO_INPUT | ENABLE_INSERT_MODE | ENABLE_LINE_INPUT | 0x80 \
| ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS | ENABLE_PROCESSED_INPUT)
-# define SHELL_CONO_MODE (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT \
+# define SHELL_CONO_MODE (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT \
| ENABLE_VIRTUAL_TERMINAL_PROCESSING)
-#endif
+# endif
typedef struct ConsoleInfo {
PerStreamTags pstSetup[3];
SQLITE_INTERNAL_LINKAGE FILE* invalidFileStream = (FILE *)~0;
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
static void maybeSetupAsConsole(PerStreamTags *ppst, short odir){
if( pstReachesConsole(ppst) ){
DWORD cm = odir? SHELL_CONO_MODE : SHELL_CONI_MODE;
SetConsoleMode(ppst->hx, cm);
}
}
-#else
-# define maybeSetupAsConsole(ppst,odir)
-#endif
+# else
+# define maybeSetupAsConsole(ppst,odir)
+# endif
SQLITE_INTERNAL_LINKAGE void consoleRenewSetup(void){
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
int ix = 0;
while( ix < 6 ){
PerStreamTags *ppst = (ix<3)?
maybeSetupAsConsole(ppst, (ix % 3)>0);
++ix;
}
-#endif
+# endif
}
SQLITE_INTERNAL_LINKAGE StreamsAreConsole
}
SQLITE_INTERNAL_LINKAGE void SQLITE_CDECL consoleRestore( void ){
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
static ConsoleInfo *pci = &consoleInfo;
if( pci->sacSetup ){
int ix;
}
}
}
-#endif
+# endif
}
+#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */
-#ifdef CONSIO_INPUT_REDIR
+#ifdef SQLITE_CIO_INPUT_REDIR
/* Say whether given FILE* is among those known, via either
** consoleClassifySetup() or set{Output,Error}Stream, as
** readable, and return an associated PerStreamTags pointer
}
#endif
+#ifndef SQLITE_CIO_NO_TRANSLATE
/* Say whether given FILE* is among those known, via either
** consoleClassifySetup() or set{Output,Error}Stream, as
** writable, and return an associated PerStreamTags pointer
SQLITE_INTERNAL_LINKAGE FILE *setOutputStream(FILE *pf){
return designateEmitStream(pf, 1);
}
-#ifdef CONSIO_SET_ERROR_STREAM
+# ifdef CONSIO_SET_ERROR_STREAM
SQLITE_INTERNAL_LINKAGE FILE *setErrorStream(FILE *pf){
return designateEmitStream(pf, 2);
}
-#endif
+# endif
+#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */
-#if SHELL_CON_TRANSLATE
+#ifndef SQLITE_CIO_NO_SETMODE
+# if CIO_WIN_WC_XLATE
static void setModeFlushQ(FILE *pf, short bFlush, int mode){
if( bFlush ) fflush(pf);
_setmode(_fileno(pf), mode);
}
-#else
-# define setModeFlushQ(f, b, m) if(b) fflush(f)
-#endif
+# else
+# define setModeFlushQ(f, b, m) if(b) fflush(f)
+# endif
SQLITE_INTERNAL_LINKAGE void setBinaryMode(FILE *pf, short bFlush){
setModeFlushQ(pf, bFlush, _O_BINARY);
SQLITE_INTERNAL_LINKAGE void setTextMode(FILE *pf, short bFlush){
setModeFlushQ(pf, bFlush, _O_TEXT);
}
-#undef setModeFlushQ
+# undef setModeFlushQ
-#else /* defined(SQLITE_SHELL_FIDDLE) */
+#else /* defined(SQLITE_CIO_NO_SETMODE) */
# define setBinaryMode(f, bFlush) do{ if((bFlush)) fflush(f); }while(0)
# define setTextMode(f, bFlush) do{ if((bFlush)) fflush(f); }while(0)
-#endif /* defined(SQLITE_SHELL_FIDDLE) */
+#endif /* defined(SQLITE_CIO_NO_SETMODE) */
-#ifndef SQLITE_SHELL_FIDDLE
-
-#if SHELL_CON_TRANSLATE
+#ifndef SQLITE_CIO_NO_TRANSLATE
+# if CIO_WIN_WC_XLATE
/* Write buffer cBuf as output to stream known to reach console,
** limited to ncTake char's. Return ncTake on success, else 0. */
static int conZstrEmit(PerStreamTags *ppst, const char *z, int ncTake){
return rv;
}else return 0;
}
-#endif /* SHELL_CON_TRANSLATE */
+# endif /* CIO_WIN_WC_XLATE */
-#ifdef CONSIO_GET_EMIT_STREAM
+# ifdef CONSIO_GET_EMIT_STREAM
static PerStreamTags * getDesignatedEmitStream(FILE *pf, unsigned chix,
PerStreamTags *ppst){
PerStreamTags *rv = isKnownWritable(pf);
streamOfConsole(pf, ppst);
return ppst;
}
-#endif
+# endif
/* Get stream info, either for designated output or error stream when
** chix equals 1 or 2, or for an arbitrary stream when chix == 0.
int rv;
FILE *pfOut;
PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
PerStreamTags *ppst = getEmitStreamInfo(1, &pst, &pfOut);
-#else
+# else
getEmitStreamInfo(1, &pst, &pfOut);
-#endif
+# endif
assert(zFormat!=0);
va_start(ap, zFormat);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
if( pstReachesConsole(ppst) ){
rv = conioVmPrintf(ppst, zFormat, ap);
}else{
-#endif
+# endif
rv = vfprintf(pfOut, zFormat, ap);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
}
-#endif
+# endif
va_end(ap);
return rv;
}
int rv;
FILE *pfErr;
PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
PerStreamTags *ppst = getEmitStreamInfo(2, &pst, &pfErr);
-#else
+# else
getEmitStreamInfo(2, &pst, &pfErr);
-#endif
+# endif
assert(zFormat!=0);
va_start(ap, zFormat);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
if( pstReachesConsole(ppst) ){
rv = conioVmPrintf(ppst, zFormat, ap);
}else{
-#endif
+# endif
rv = vfprintf(pfErr, zFormat, ap);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
}
-#endif
+# endif
va_end(ap);
return rv;
}
va_list ap;
int rv;
PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
PerStreamTags *ppst = getEmitStreamInfo(0, &pst, &pfO);
-#else
+# else
getEmitStreamInfo(0, &pst, &pfO);
-#endif
+# endif
assert(zFormat!=0);
va_start(ap, zFormat);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
if( pstReachesConsole(ppst) ){
maybeSetupAsConsole(ppst, 1);
rv = conioVmPrintf(ppst, zFormat, ap);
if( 0 == isKnownWritable(ppst->pf) ) restoreConsoleArb(ppst);
}else{
-#endif
+# endif
rv = vfprintf(pfO, zFormat, ap);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
}
-#endif
+# endif
va_end(ap);
return rv;
}
SQLITE_INTERNAL_LINKAGE int fPutsUtf8(const char *z, FILE *pfO){
PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
PerStreamTags *ppst = getEmitStreamInfo(0, &pst, &pfO);
-#else
+# else
getEmitStreamInfo(0, &pst, &pfO);
-#endif
+# endif
assert(z!=0);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
if( pstReachesConsole(ppst) ){
int rv;
maybeSetupAsConsole(ppst, 1);
if( 0 == isKnownWritable(ppst->pf) ) restoreConsoleArb(ppst);
return rv;
}else {
-#endif
+# endif
return (fputs(z, pfO)<0)? 0 : (int)strlen(z);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
}
-#endif
+# endif
}
SQLITE_INTERNAL_LINKAGE int ePutsUtf8(const char *z){
FILE *pfErr;
PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
PerStreamTags *ppst = getEmitStreamInfo(2, &pst, &pfErr);
-#else
+# else
getEmitStreamInfo(2, &pst, &pfErr);
-#endif
+# endif
assert(z!=0);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
if( pstReachesConsole(ppst) ) return conZstrEmit(ppst, z, (int)strlen(z));
else {
-#endif
+# endif
return (fputs(z, pfErr)<0)? 0 : (int)strlen(z);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
}
-#endif
+# endif
}
SQLITE_INTERNAL_LINKAGE int oPutsUtf8(const char *z){
FILE *pfOut;
PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
PerStreamTags *ppst = getEmitStreamInfo(1, &pst, &pfOut);
-#else
+# else
getEmitStreamInfo(1, &pst, &pfOut);
-#endif
+# endif
assert(z!=0);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
if( pstReachesConsole(ppst) ) return conZstrEmit(ppst, z, (int)strlen(z));
else {
-#endif
+# endif
return (fputs(z, pfOut)<0)? 0 : (int)strlen(z);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
}
-#endif
+# endif
}
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
+#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */
+#if !(defined(SQLITE_CIO_NO_UTF8SCAN) && defined(SQLITE_CIO_NO_TRANSLATE))
/* Skip over as much z[] input char sequence as is valid UTF-8,
** limited per nAccept char's or whole characters and containing
** no char cn such that ((1<<cn) & ccm)!=0. On return, the
}
return z;
}
+#endif /*!(defined(SQLITE_CIO_NO_UTF8SCAN)&&defined(SQLITE_CIO_NO_TRANSLATE))*/
-#ifdef SQLITE_SHELL_FIDDLE
-# define oPutbUtf8(z,n,cM) fwrite(z,1,n,stdout)
-
-static int oprintf(const char *zFmt, ...){
- va_list ap;
- int rv;
- va_start(ap, zFmt);
- rv = vfprintf(stdout, zFmt, ap);
- va_end(ap);
- return rv;
-}
-static int eprintf(const char *zFmt, ...){
- va_list ap;
- int rv;
- va_start(ap, zFmt);
- rv = vfprintf(stderr, zFmt, ap);
- va_end(ap);
- return rv;
-}
-#else
-
+#ifndef SQLITE_CIO_NO_TRANSLATE
SQLITE_INTERNAL_LINKAGE int
-fPutbUtf8(FILE *pfO, const char *cBuf, int nAccept, long ctrlMask){
- const char *zPast = zSkipValidUtf8(cBuf, nAccept, ctrlMask);
- int ncConsume = (int)(zPast - cBuf);
- if( pfO == 0 ) return ncConsume;
-#if SHELL_CON_TRANSLATE
+fPutbUtf8(FILE *pfO, const char *cBuf, int nAccept){
+ assert(pfO!=0);
+# if CIO_WIN_WC_XLATE
PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */
PerStreamTags *ppst = getEmitStreamInfo(0, &pst, &pfO);
if( pstReachesConsole(ppst) ){
int rv;
maybeSetupAsConsole(ppst, 1);
- rv = conZstrEmit(ppst, cBuf, ncConsume);
+ rv = conZstrEmit(ppst, cBuf, nAccept);
if( 0 == isKnownWritable(ppst->pf) ) restoreConsoleArb(ppst);
return rv;
}else {
-#endif
- return (int)fwrite(cBuf, 1, ncConsume, pfO);
-#if SHELL_CON_TRANSLATE
+# endif
+ return (int)fwrite(cBuf, 1, nAccept, pfO);
+# if CIO_WIN_WC_XLATE
}
-#endif
+# endif
}
SQLITE_INTERNAL_LINKAGE int
-oPutbUtf8(const char *cBuf, int nAccept, long ctrlMask){
+oPutbUtf8(const char *cBuf, int nAccept){
FILE *pfOut;
- const char *zPast = zSkipValidUtf8(cBuf, nAccept, ctrlMask);
- int ncConsume = (int)(zPast - cBuf);
PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
PerStreamTags *ppst = getEmitStreamInfo(1, &pst, &pfOut);
-#else
+# else
getEmitStreamInfo(1, &pst, &pfOut);
-#endif
-#if SHELL_CON_TRANSLATE
+# endif
+# if CIO_WIN_WC_XLATE
if( pstReachesConsole(ppst) ){
- return conZstrEmit(ppst, cBuf, ncConsume);
+ return conZstrEmit(ppst, cBuf, nAccept);
}else {
-#endif
- return (int)fwrite(cBuf, 1, ncConsume, pfOut);
-#if SHELL_CON_TRANSLATE
+# endif
+ return (int)fwrite(cBuf, 1, nAccept, pfOut);
+# if CIO_WIN_WC_XLATE
}
-#endif
+# endif
}
-#ifdef CONSIO_EPUTB
+# ifdef CONSIO_EPUTB
SQLITE_INTERNAL_LINKAGE int
-ePutbUtf8(const char *cBuf, int nAccept, long ctrlMask){
+ePutbUtf8(const char *cBuf, int nAccept){
FILE *pfErr;
- const char *zPast = zSkipValidUtf8(cBuf, nAccept, ctrlMask);
- int ncConsume = (int)(zPast - cBuf);
PerStreamTags pst = PST_INITIALIZER; /* for unknown streams */
PerStreamTags *ppst = getEmitStreamInfo(2, &pst, &pfErr);
-# if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
if( pstReachesConsole(ppst) ){
- return conZstrEmit(ppst, cBuf, ncConsume);
+ return conZstrEmit(ppst, cBuf, nAccept);
}else {
-# endif
- return (int)fwrite(cBuf, 1, ncConsume, pfErr);
-# if SHELL_CON_TRANSLATE
+# endif
+ return (int)fwrite(cBuf, 1, nAccept, pfErr);
+# if CIO_WIN_WC_XLATE
}
-# endif
+# endif
}
-#endif /* defined(CONSIO_EPUTB) */
+# endif /* defined(CONSIO_EPUTB) */
SQLITE_INTERNAL_LINKAGE char* fGetsUtf8(char *cBuf, int ncMax, FILE *pfIn){
if( pfIn==0 ) pfIn = stdin;
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
if( pfIn == consoleInfo.pstSetup[0].pf
&& (consoleInfo.sacSetup & SAC_InConsole)!=0 ){
-# if SHELL_CON_TRANSLATE==1
-# define SHELL_GULP 150 /* Count of WCHARS to be gulped at a time */
+# if CIO_WIN_WC_XLATE==1
+# define SHELL_GULP 150 /* Count of WCHARS to be gulped at a time */
WCHAR wcBuf[SHELL_GULP+1];
int lend = 0, noc = 0;
if( ncMax > 0 ) cBuf[0] = 0;
while( noc < ncMax-8-1 && !lend ){
/* There is room for at least 2 more characters and a 0-terminator. */
int na = (ncMax > SHELL_GULP*4+1 + noc)? SHELL_GULP : (ncMax-1 - noc)/4;
-# undef SHELL_GULP
+# undef SHELL_GULP
DWORD nbr = 0;
BOOL bRC = ReadConsoleW(consoleInfo.pstSetup[0].hx, wcBuf, na, &nbr, 0);
if( bRC && nbr>0 && (wcBuf[nbr-1]&0xF800)==0xD800 ){
cBuf[noc] = 0;
return cBuf;
}else return 0;
-# endif
+# endif
}else{
-#endif
+# endif
return fgets(cBuf, ncMax, pfIn);
-#if SHELL_CON_TRANSLATE
+# if CIO_WIN_WC_XLATE
}
-#endif
+# endif
}
+#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */
+#undef CIO_WIN_WC_XLATE
#undef SHELL_INVALID_FILE_PTR
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
# include "sqlite3.h"
#endif
+#ifndef SQLITE_CIO_NO_CLASSIFY
+
/* Define enum for use with following function. */
typedef enum StreamsAreConsole {
SAC_NoConsole = 0,
SAC_AnyConsole = 0x7
} StreamsAreConsole;
-#ifndef SQLITE_SHELL_FIDDLE
/*
** Classify the three standard I/O streams according to whether
** they are connected to a console attached to the process.
*/
SQLITE_INTERNAL_LINKAGE void SQLITE_CDECL consoleRestore( void );
+#else /* defined(SQLITE_CIO_NO_CLASSIFY) */
+# define consoleClassifySetup(i,o,e)
+# define consoleRenewSetup()
+# define consoleRestore()
+#endif /* defined(SQLITE_CIO_NO_CLASSIFY) */
+
+#ifndef SQLITE_CIO_NO_REDIRECT
/*
** Set stream to be used for the functions below which write
** to "the designated X stream", where X is Output or Error.
*/
SQLITE_INTERNAL_LINKAGE FILE *invalidFileStream;
SQLITE_INTERNAL_LINKAGE FILE *setOutputStream(FILE *pf);
-#ifdef CONSIO_SET_ERROR_STREAM
+# ifdef CONSIO_SET_ERROR_STREAM
SQLITE_INTERNAL_LINKAGE FILE *setErrorStream(FILE *pf);
-#endif
+# endif
+#else
+# define setOutputStream(pf)
+# define setErrorStream(pf)
+#endif /* !defined(SQLITE_CIO_NO_REDIRECT) */
+#ifndef SQLITE_CIO_NO_TRANSLATE
/*
** Emit output like fprintf(). If the output is going to the
** console and translation from UTF-8 is necessary, perform
/*
** Emit output like fPutsUtf8(), except that the length of the
-** accepted char or character sequence may be limited by nAccept.
-**
-** The magnitude and sign of nAccept control what nAccept limits.
-** If positive, nAccept limits the number of char's accepted.
-** If negative, it limits the number of valid input characters.
-** Obtain the behavior of {f,o,e}PutsUtf8 with nAccept==INT_MAX.
+** accepted char or character sequence is limited by nAccept.
**
** Returns the number of accepted char values.
-**
-** When ctrlMask!=0, it specifies a set of control characters not
-** accepted as input, so that cBuf[abs(N)] on return will be one
-** of the non-accepted characters unless nAccept limited the scan.
-** Each bit in ctrlMask, 1<<cn, directs cn to not be accepted.
-**
-** The cBuf content will only be accessad up to the lesser of the
-** limits specified by nAccept or a terminator char. It need not
-** have a sentinel unless the nAccept limit exceeds the content.
-** A common sentinel is '\x00', selected with ctrlMask == 1L .
-**
-** Special-case treatment occurs when fPutbUtf8() is given a NULL
-** pfOut argument; No output is attempted, but the return value
-** will still reflect the above conditions.
*/
SQLITE_INTERNAL_LINKAGE int
-fPutbUtf8(FILE *pfOut, const char *cBuf, int nAccept, long ctrlMask);
+fPutbUtf8(FILE *pfOut, const char *cBuf, int nAccept);
/* Like fPutbUtf8 except stream is always the designated output. */
SQLITE_INTERNAL_LINKAGE int
-oPutbUtf8(const char *cBuf, int nAccept, long ctrlMask);
+oPutbUtf8(const char *cBuf, int nAccept);
/* Like fPutbUtf8 except stream is always the designated error. */
#ifdef CONSIO_EPUTB
SQLITE_INTERNAL_LINKAGE int
-ePutbUtf8(const char *cBuf, int nAccept, long ctrlMask);
+ePutbUtf8(const char *cBuf, int nAccept);
#endif
/*
/* Like fGetsUtf8 except stream is always the designated input. */
/* SQLITE_INTERNAL_LINKAGE char* iGetsUtf8(char *cBuf, int ncMax); */
+#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */
+
+#ifndef SQLITE_CIO_NO_SETMODE
/*
** Set given stream for binary mode, where newline translation is
** not done, or for text mode where, for some platforms, newlines
*/
SQLITE_INTERNAL_LINKAGE void setBinaryMode(FILE *, short bFlush);
SQLITE_INTERNAL_LINKAGE void setTextMode(FILE *, short bFlush);
+#endif
-#if 0 /* For use with line editor. (not yet used) */
+#ifdef SQLITE_CIO_PROMPTED_IN
typedef struct Prompts {
int numPrompts;
const char **azPrompts;
} Prompts;
-#endif
/*
** Macros for use of a line editor.
** This function may call upon services of a line-editing
** library to interactively collect line edited input.
*/
-#if 0 /* not yet implemented */
SQLITE_INTERNAL_LINKAGE char *
shellGetLine(FILE *pfIn, char *zBufPrior, int nLen,
short isContinuation, Prompts azPrompt);
-#endif
+#endif /* defined(SQLITE_CIO_PROMPTED_IN) */
/*
** TBD: Define an interface for application(s) to generate
** completion candidates for use by the line-editor.
** may have to establish console operating mode, possibly
** in a way that interferes with the above functionality.
*/
-#endif /* !defined(SQLITE_SHELL_FIDDLE) */
+#if !(defined(SQLITE_CIO_NO_UTF8SCAN)&&defined(SQLITE_CIO_NO_TRANSLATE))
/* Skip over as much z[] input char sequence as is valid UTF-8,
** limited per nAccept char's or whole characters and containing
** no char cn such that ((1<<cn) & ccm)!=0. On return, the
*/
SQLITE_INTERNAL_LINKAGE const char*
zSkipValidUtf8(const char *z, int nAccept, long ccm);
+
+#endif
extern LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText);
#endif
+/* Use console I/O package as a direct INCLUDE. */
#define SQLITE_INTERNAL_LINKAGE static
+#ifdef SQLITE_SHELL_FIDDLE
+/* Deselect most features from the console I/O package for Fiddle. */
+# define SQLITE_CIO_NO_REDIRECT
+# define SQLITE_CIO_NO_CLASSIFY
+# define SQLITE_CIO_NO_TRANSLATE
+# define SQLITE_CIO_NO_SETMODE
+#endif
INCLUDE ../ext/consio/console_io.h
INCLUDE ../ext/consio/console_io.c
#ifndef SQLITE_SHELL_FIDDLE
-
/* From here onward, fgets() is redirected to the console_io library. */
# define fgets(b,n,f) fGetsUtf8(b,n,f)
/*
* oputf(f, ...) => emit varargs per format f to default stream
* eputz(z) => emit 0-terminated string z to error stream
* eputf(f, ...) => emit varargs per format f to error stream
+ * oputb(b, n) => emit char buffer b[0..n-1] to default stream
*
* Note that the default stream is whatever has been last set via:
* setOutputStream(FILE *pf)
# define oputf oPrintfUtf8
# define eputz(z) ePutsUtf8(z)
# define eputf ePrintfUtf8
-
+# define oputb(buf,na) oPutbUtf8(buf,na)
#else
/* For Fiddle, all console handling and emit redirection is omitted. */
-# define sputz(s,z) fputs(z,s)
-# define sputf fprintf
+# define sputz(fp,z) fputs(z,fp)
+# define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__)
# define oputz(z) fputs(z,stdout)
-# define oputf oprintf
+# define oputf(fmt, ...) printf(fmt,__VA_ARGS__)
# define eputz(z) fputs(z,stderr)
-# define eputf eprintf
+# define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__)
+# define oputb(buf,na) fwrite(buf,1,na,stdout)
#endif
/* True if the timer is enabled */
const char *pcDQBSRO = anyOfInStr(z, zDQBSRO, ~(size_t)0);
const char *pcPast = zSkipValidUtf8(z, INT_MAX, ctrlMask);
const char *pcEnd = (pcDQBSRO && pcDQBSRO < pcPast)? pcDQBSRO : pcPast;
- if( pcEnd > z ) oPutbUtf8(z, (int)(pcEnd-z), 0);
+ if( pcEnd > z ) oputb(z, (int)(pcEnd-z));
if( (c = *pcEnd)==0 ) break;
++pcEnd;
switch( c ){
const char *pcPast = zSkipValidUtf8(z, (int)(pcLimit-z), ctrlMask);
const char *pcEnd = (pcDQBS && pcDQBS < pcPast)? pcDQBS : pcPast;
if( pcEnd > z ){
- oPutbUtf8(z, (int)(pcEnd-z), 0);
+ oputb(z, (int)(pcEnd-z));
z = pcEnd;
}
if( z >= pcLimit ) break;
&& cli_strcmp(zFile,"on")!=0
&& cli_strcmp(zFile,"off")!=0
){
- sputf(stdout, "cannot set .log to anything other"
+ sputz(stdout, "cannot set .log to anything other"
" than \"on\" or \"off\"\n");
zFile = "off";
}
}
static void sayAbnormalExit(void){
- if( seenInterrupt ) eputf("Program interrupted.\n");
+ if( seenInterrupt ) eputz("Program interrupted.\n");
}
#ifndef SQLITE_SHELL_IS_UTF8