SQLite

Check-in [1546546287]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Passing shell tests on Linux and Windows. A number of FILE* API content transfer calls are diverted to the consio library via macros.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | win-dupe-crt-fio
Files: files | file ages | folders
SHA3-256: 15465462872d22028f5e954e399c2431854e4ec56436061c74250ed73c1980f7
User & Date: larrybr 2024-09-20 17:38:35.583
Context
2024-09-20
17:38
Passing shell tests on Linux and Windows. A number of FILE* API content transfer calls are diverted to the consio library via macros. (Leaf check-in: 1546546287 user: larrybr tags: win-dupe-crt-fio)
14:18
Fix flub in cfWrite(). (for Win32) (check-in: 3884ddb4dc user: larrybr tags: win-dupe-crt-fio)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/consio/console_io.c.
775
776
777
778
779
780
781

















782
783
784
785
786
787
788
  }else{
    return cfGets(cBuf, ncMax, pfIn);
  }
# else
  return fgets(cBuf, ncMax, pfIn);
# endif
}

















#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */

#if defined(_MSC_VER)
# pragma warning(default : 4204)
#endif

#undef SHELL_INVALID_FILE_PTR







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
  }else{
    return cfGets(cBuf, ncMax, pfIn);
  }
# else
  return fgets(cBuf, ncMax, pfIn);
# endif
}

# if CIO_WIN_WC_XLATE && !defined(SQLITE_CIO_NO_FGETC)
SQLITE_INTERNAL_LINKAGE int fGetCh(FILE *pfIn){
  struct FileAltIds fai = altIdsOfFile(pfIn);
  int fmode = _setmode(fai.fd, _O_BINARY);
  BOOL eatCR = (fmode & _O_TEXT)!=0;
  _setmode(fai.fd, fmode);
  while( 1 ){
    DWORD nr, rf;
    char ci;
    rf = ReadFile(fai.fh, &ci, 1, &nr, 0);
    if( !rf || nr<1 ) return -1;
    if( !eatCR || ci!='\r' ) return (int)(unsigned char)ci;
  }
}
# endif

#endif /* !defined(SQLITE_CIO_NO_TRANSLATE) */

#if defined(_MSC_VER)
# pragma warning(default : 4204)
#endif

#undef SHELL_INVALID_FILE_PTR
Changes to ext/consio/console_io.h.
279
280
281
282
283
284
285











































286
287
** limited per nAccept char's or whole characters and containing
** no char cn such that ((1<<cn) & ccm)!=0. On return, the
** sequence z:return (inclusive:exclusive) is validated UTF-8.
** Limit: nAccept>=0 => char count, nAccept<0 => character
 */
SQLITE_INTERNAL_LINKAGE const char*
zSkipValidUtf8(const char *z, int nAccept, long ccm);












































#endif







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
** limited per nAccept char's or whole characters and containing
** no char cn such that ((1<<cn) & ccm)!=0. On return, the
** sequence z:return (inclusive:exclusive) is validated UTF-8.
** Limit: nAccept>=0 => char count, nAccept<0 => character
 */
SQLITE_INTERNAL_LINKAGE const char*
zSkipValidUtf8(const char *z, int nAccept, long ccm);
#endif

#if !defined(SQLITE_CIO_NO_TRANSLATE) \
 && (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT
/* For Win32 builds, block most FILE* API content transfers. */
# define getc() assert(0)
# define fputc(c,fp) assert(0)
# define putc(c,fp) assert(0)
# define getchar() assert(0)
# define gets() assert(0)
# define putchar(c) assert(0)
# define ungetc(c,fp) assert(0)
# define scanf assert(0)
# define fscanf assert(0)
# define vscanf assert(0)
# define vfscanf assert(0)

/* Leave ftell, fgetpos, fseek, fsetpos, rewind, fread and fwrite alone.
 * They are used in the ext/misc/fileio.c extension embedded in the CLI.
 */

/* Block feof because we do not trust it mixed with Win32 file I/O. */
# define feof(fp) assert(0)

/* Divert a few FILE* content transfers which have good substitutes. */
# define fflush(fp) fFlushBuffer(fp)
# define fgets(b,n,fp) fGetsUtf8(b,n,fp)
# define fputs fPutsUtf8
# define puts(z) oPutsUtf8(z)
# define printf oPrintfUtf8
# define fprintf fPrintfUtf8

# ifndef SQLITE_CIO_NO_FGETC
/* As a dispensation for .import's char-at-a-time parsing, provide an
 * equivalent which gets them via ReadFile(), without UTF-8 translation.
 * They could (conceivably) come from the console, with odd results.
 */
SQLITE_INTERNAL_LINKAGE int fGetCh(FILE *pfIn);
#  define fgetc(fp) fGetCh(fp)
# else
#  define fgetc(fp) assert(0),0
# endif


#endif
Changes to src/shell.c.in.
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# define SQLITE_CIO_NO_FLUSH
#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)
/*
 * Define macros for emitting output text in various ways:
 *  sputz(s, z)      => emit 0-terminated string z to given stream s
 *  sputf(s, f, ...) => emit varargs per format f to given stream s
 *  oputz(z)         => emit 0-terminated string z to default stream
 *  oputf(f, ...)    => emit varargs per format f to default stream
 *  eputz(z)         => emit 0-terminated string z to error stream







<
<







249
250
251
252
253
254
255


256
257
258
259
260
261
262
# define SQLITE_CIO_NO_FLUSH
#endif
INCLUDE ../ext/consio/console_io.h
INCLUDE ../ext/consio/console_io.c

#ifndef SQLITE_SHELL_FIDDLE



/*
 * Define macros for emitting output text in various ways:
 *  sputz(s, z)      => emit 0-terminated string z to given stream s
 *  sputf(s, f, ...) => emit varargs per format f to given stream s
 *  oputz(z)         => emit 0-terminated string z to default stream
 *  oputf(f, ...)    => emit varargs per format f to default stream
 *  eputz(z)         => emit 0-terminated string z to error stream
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# define sputz(s,z) fPutsUtf8(z,s)
# define sputf fPrintfUtf8
# define oputz(z) oPutsUtf8(z)
# define oputf oPrintfUtf8
# define eputz(z) ePutsUtf8(z)
# define eputf ePrintfUtf8
# define oputb(buf,na) oPutbUtf8(buf,na)
# define fflush(s) fFlushBuffer(s);

#else
/* For Fiddle, all console handling and emit redirection is omitted. */
/* These next 3 macros are for emitting formatted output. When complaints
 * from the WASM build are issued for non-formatted output, when a mere
 * string literal is to be emitted, the ?putz(z) forms should be used.
 * (This permits compile-time checking of format string / argument mismatch.)







<







274
275
276
277
278
279
280

281
282
283
284
285
286
287
# define sputz(s,z) fPutsUtf8(z,s)
# define sputf fPrintfUtf8
# define oputz(z) oPutsUtf8(z)
# 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. */
/* These next 3 macros are for emitting formatted output. When complaints
 * from the WASM build are issued for non-formatted output, when a mere
 * string literal is to be emitted, the ?putz(z) forms should be used.
 * (This permits compile-time checking of format string / argument mismatch.)