SQLite

Check-in [2b850aca1e]
Login

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

Overview
Comment:Make it buildable. Pull test program from testee. Zap stray fprintf().
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | console-io-lib
Files: files | file ages | folders
SHA3-256: 2b850aca1e76805a0358064318a765fa66ce394d015936fd47683d74ca4c187e
User & Date: larrybr 2023-11-05 23:55:41.214
Context
2023-11-06
00:15
Make MSVC accept it, too. (Cannot use static const int as part of a constant expression?) (check-in: bb278d2496 user: larrybr tags: console-io-lib)
2023-11-05
23:55
Make it buildable. Pull test program from testee. Zap stray fprintf(). (check-in: 2b850aca1e user: larrybr tags: console-io-lib)
19:42
Input working. No line-editor provisions yet. (WIP, but suitable for testing.) (check-in: e8568b1d92 user: larrybr tags: console-io-lib)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/console_io.c.
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
      if( ix==0 ){
        consoleInfo.haveInput = 1;
        consoleInfo.stdinEof = 0;
      }else{
        consoleInfo.outputIx |= ix;
      }
      SetConsoleMode(ppst->hx, cm);
      fprintf(stderr, "consMode[%d]: %02x -> %02x\n", ix, ppst->consMode, cm);
#endif
      rv |= (CSCS_InConsole<<ix);
    }
    if( ix > 0 ) fflush(apf[ix]);
#if SHELL_CON_TRANSLATE == 2
    _setmode(_fileno(apf[ix]), _O_U8TEXT);
    _setmode(_fileno(apf[ix]), _O_TEXT);







<







129
130
131
132
133
134
135

136
137
138
139
140
141
142
      if( ix==0 ){
        consoleInfo.haveInput = 1;
        consoleInfo.stdinEof = 0;
      }else{
        consoleInfo.outputIx |= ix;
      }
      SetConsoleMode(ppst->hx, cm);

#endif
      rv |= (CSCS_InConsole<<ix);
    }
    if( ix > 0 ) fflush(apf[ix]);
#if SHELL_CON_TRANSLATE == 2
    _setmode(_fileno(apf[ix]), _O_U8TEXT);
    _setmode(_fileno(apf[ix]), _O_TEXT);
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
      BOOL bRC = ReadConsoleW(consoleInfo.pst[0].hx, wcBuf, na, &nbr, 0);
      if( bRC && nbr>0 && (wcBuf[nbr-1]&0xF800)==0xD800 ){
        /* Last WHAR read is first of a UTF-16 surrogate pair. Grab its mate. */
        DWORD nbrx;
        bRC &= ReadConsoleW(consoleInfo.pst[0].hx, wcBuf+nbr, 1, &nbrx, 0);
        if( bRC ) nbr += nbrx;
      }
      hd(wcBuf,nbr);
      if( !bRC || (noc==0 && nbr==0) ) return 0;
      if( nbr > 0 ){
        int nmb = WideCharToMultiByte(CP_UTF8, 0, wcBuf,nbr,0,0,0,0);
        if( nmb != 0 && noc+nmb <= ncMax ){
          int iseg = noc;
          nmb = WideCharToMultiByte(CP_UTF8, 0, wcBuf,nbr,cBuf+noc,nmb,0,0);
          noc += nmb;







<







265
266
267
268
269
270
271

272
273
274
275
276
277
278
      BOOL bRC = ReadConsoleW(consoleInfo.pst[0].hx, wcBuf, na, &nbr, 0);
      if( bRC && nbr>0 && (wcBuf[nbr-1]&0xF800)==0xD800 ){
        /* Last WHAR read is first of a UTF-16 surrogate pair. Grab its mate. */
        DWORD nbrx;
        bRC &= ReadConsoleW(consoleInfo.pst[0].hx, wcBuf+nbr, 1, &nbrx, 0);
        if( bRC ) nbr += nbrx;
      }

      if( !bRC || (noc==0 && nbr==0) ) return 0;
      if( nbr > 0 ){
        int nmb = WideCharToMultiByte(CP_UTF8, 0, wcBuf,nbr,0,0,0,0);
        if( nmb != 0 && noc+nmb <= ncMax ){
          int iseg = noc;
          nmb = WideCharToMultiByte(CP_UTF8, 0, wcBuf,nbr,cBuf+noc,nmb,0,0);
          noc += nmb;
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
  }else{
#endif
    return fgets(cBuf, ncMax, pfIn);
#if SHELL_CON_TRANSLATE
  }
#endif
}

#ifdef TEST_CIO
// cl -Zi -I. -DWIN32 -DTEST_CIO sqlite3.c src/console_io.c -Fecio.exe
// gcc -I. -DWIN32 -DTEST_CIO sqlite3.c src/console_io.c -o cio.exe
const char *prompts[] = { "main", "cont" };
Prompts goofy = { 2, prompts };

int main(int na, char *av[]){
  ConsoleStdConsStreams cc = consoleClassifySetup(stdin, stdout, stderr);
  const char *zt = "Math: ±×÷∂∆∙√∞∩∫≈≠≡≤≥\n"
    "Hiragana: 亜唖娃阿哀愛挨姶逢葵茜穐悪握渥旭葦芦鯵梓圧斡扱"
    "宛姐虻飴絢綾鮎或粟袷安庵按暗案闇鞍杏\n"
    "Simplified Chinese: 餐参蚕残惭惨灿掺孱骖璨粲黪\n"
    "Geometric Shapes: ■□▪▫▲△▼▽◆◇◊○◌◎●◢◣◤◥◦\n"
    "Boxes single: ─━│┃┄┅┆┇┈┉┊┋ ┌┍┎┏┐┑┒┓└┕┖┗┘┙┚┛├┝┞┟┠┡┢┣┤┥┦┧┨┩┪┫┬┭┮┯┰┱┲┳"
    "┴┵┶┷┸┹┺┻┼┽┾┿╀╁╂╃╄╅╆╇╈╉╊╋\n"
    "Boxes double: ═║╒╓╔╕╖╗╘╙╚╛╜╝╞╟╠╡╢╣╤╥╦╧╨╩╪╫╬\n"
    "Rounded corners and diagonals: ╭╮╯╰╱╲╳\n"
    ;
  char inBuf[150];
  setTextMode(stdout, 1);
  setTextMode(stderr, 1);
  fprintfUtf8(stderr, "Console streams: %d, CP_UTF8 valid: %d\n", cc,
              IsValidCodePage(CP_UTF8));
  fprintfUtf8(stdout, "%s=%d\n", "∑(1st 7 primes)", 42);
  fprintfUtf8(stderr, "%s\n", "∫ (1/x) dx ≡ ln(x)");
  fprintfUtf8(stdout, "%s", zt);
  fprintfUtf8(stderr, "Entering input/echo loop."
              " Type or copy/paste, or EOF to exit.\n");
  while( fprintfUtf8(stdout,"? ") && fgetsUtf8(inBuf, sizeof(inBuf), stdin) ){
    fprintfUtf8(stdout, "! %s", inBuf);
  }
  consoleRestore();
  return 0;
}
#endif /* defined(TEST_CIO) */







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
308
309
310
311
312
313
314




































  }else{
#endif
    return fgets(cBuf, ncMax, pfIn);
#if SHELL_CON_TRANSLATE
  }
#endif
}




































Changes to src/console_io.h.
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39




40
41
42
43
44
45
46
** conditional compilation in their source for their console I/O.
**
** The symbols and functionality exposed here are not a public API.
** This code may change in tandem with other project code as needed.
*/

#ifndef INT_LINKAGE
# define INT_LINKAGE /* Linkage will be external to translation unit. */
# include <stdio.h>
# include <stdlib.h>
# include <limits.h>
# if defined(_WIN32) || defined(WIN32)
#  undef WIN32_LEAN_AND_MEAN
#  define WIN32_LEAN_AND_MEAN
#  include <windows.h>
#  include <io.h>
#  include <fcntl.h>
# endif
#endif





/* Define enum for use with following function. */
typedef enum ConsoleStdConsStreams {
  CSCS_NoConsole = 0,
  CSCS_InConsole = 1, CSCS_OutConsole = 2, CSCS_ErrConsole = 4,
  CSCS_AnyConsole = 0x7
} ConsoleStdConsStreams;







|











>
>
>
>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
** conditional compilation in their source for their console I/O.
**
** The symbols and functionality exposed here are not a public API.
** This code may change in tandem with other project code as needed.
*/

#ifndef INT_LINKAGE
# define INT_LINKAGE extern /* Linkage external to translation unit. */
# include <stdio.h>
# include <stdlib.h>
# include <limits.h>
# if defined(_WIN32) || defined(WIN32)
#  undef WIN32_LEAN_AND_MEAN
#  define WIN32_LEAN_AND_MEAN
#  include <windows.h>
#  include <io.h>
#  include <fcntl.h>
# endif
#endif

#ifndef SQLITE3_H
# include "sqlite3.h"
#endif

/* Define enum for use with following function. */
typedef enum ConsoleStdConsStreams {
  CSCS_NoConsole = 0,
  CSCS_InConsole = 1, CSCS_OutConsole = 2, CSCS_ErrConsole = 4,
  CSCS_AnyConsole = 0x7
} ConsoleStdConsStreams;