#include "sqlite3.h"
#include "resfmt.h"
+#define COUNT(X) (sizeof(X)/sizeof(X[0]))
+
/* Report out-of-memory and die if the argument is NULL */
static void checkOOM(void *p){
if( p==0 ){
sqlite3_str_reset(pBuf);
}else
if( strncmp(zLine, "--eFormat=", 10)==0 ){
- const struct { const char *zFmt; int eMode; } aFmt[] = {
- { "line", RESFMT_Line, },
+ const struct { const char *z; int e; } aFmt[] = {
+ { "box", RESFMT_Box, },
{ "column", RESFMT_Column, },
- { "list", RESFMT_List, },
- { "html", RESFMT_Html, },
- { "insert", RESFMT_Insert, },
- { "tcl", RESFMT_Tcl, },
+ { "count", RESFMT_Count, },
{ "csv", RESFMT_Csv, },
- { "explain", RESFMT_Explain, },
- { "pretty", RESFMT_Pretty, },
{ "eqp", RESFMT_EQP, },
+ { "explain", RESFMT_Explain, },
+ { "html", RESFMT_Html, },
+ { "insert", RESFMT_Insert, },
{ "json", RESFMT_Json, },
+ { "line", RESFMT_Line, },
+ { "list", RESFMT_List, },
{ "markdown", RESFMT_Markdown, },
- { "table", RESFMT_Table, },
- { "box", RESFMT_Box, },
- { "count", RESFMT_Count, },
{ "off", RESFMT_Off, },
+ { "pretty", RESFMT_Pretty, },
+ { "table", RESFMT_Table, },
+ { "tcl", RESFMT_Tcl, },
{ "scanexp", RESFMT_ScanExp, },
- { "www", RESFMT_Www, },
};
int i;
- for(i=0; i<sizeof(aFmt)/sizeof(aFmt[0]); i++){
- if( strcmp(aFmt[i].zFmt,&zLine[10])==0 ){
- spec.eFormat = aFmt[i].eMode;
+ for(i=0; i<COUNT(aFmt); i++){
+ if( strcmp(aFmt[i].z,&zLine[10])==0 ){
+ spec.eFormat = aFmt[i].e;
+ break;
+ }
+ }
+ if( i>=COUNT(aFmt) ){
+ sqlite3_str *pMsg = sqlite3_str_new(0);
+ for(i=0; i<COUNT(aFmt); i++){
+ sqlite3_str_appendf(pMsg, " %s", aFmt[i].z);
+ }
+ fprintf(stderr, "%s:%d: no such format: \"%s\"\nChoices: %s\n",
+ zSrc, lineNum, &zLine[10], sqlite3_str_value(pMsg));
+ sqlite3_free(sqlite3_str_finish(pMsg));
+ }
+ }else
+ if( strncmp(zLine, "--eQuote=", 9)==0 ){
+ const struct { const char *z; int e; } aQuote[] = {
+ { "c", RESFMT_Q_C },
+ { "csv", RESFMT_Q_Csv },
+ { "html", RESFMT_Q_Html },
+ { "json", RESFMT_Q_Json },
+ { "off", RESFMT_Q_Off },
+ { "sql", RESFMT_Q_Sql },
+ { "tcl", RESFMT_Q_C },
+ };
+ int i;
+ for(i=0; i<COUNT(aQuote); i++){
+ if( strcmp(aQuote[i].z,&zLine[9])==0 ){
+ spec.eQuote = aQuote[i].e;
break;
}
}
- if( i>=sizeof(aFmt)/sizeof(aFmt[0]) ){
- fprintf(stderr, "%s:%d: no such format: \"%s\"\n",
- zSrc, lineNum, &zLine[10]);
+ if( i>=COUNT(aQuote) ){
+ sqlite3_str *pMsg = sqlite3_str_new(0);
+ for(i=0; i<COUNT(aQuote); i++){
+ sqlite3_str_appendf(pMsg, " %s", aQuote[i].z);
+ }
+ fprintf(stderr, "%s:%d: no such quoting style: \"%s\"\nChoices: %s\n",
+ zSrc, lineNum, &zLine[9], sqlite3_str_value(pMsg));
+ sqlite3_free(sqlite3_str_finish(pMsg));
}
}else
- if( strncmp(zLine, "--bQuote=", 9)==0 ){
- spec.bQuote = atoi(&zLine[9])!=0;
+ if( strncmp(zLine, "--eEscape=", 10)==0 ){
+ const struct { const char *z; int e; } aEscape[] = {
+ { "off", RESFMT_E_Off },
+ { "unicode", RESFMT_E_Unicode },
+ { "unix", RESFMT_E_Unix },
+ };
+ int i;
+ for(i=0; i<COUNT(aEscape); i++){
+ if( strcmp(aEscape[i].z,&zLine[10])==0 ){
+ spec.eEscape = aEscape[i].e;
+ break;
+ }
+ }
+ if( i>=COUNT(aEscape) ){
+ sqlite3_str *pMsg = sqlite3_str_new(0);
+ for(i=0; i<COUNT(aEscape); i++){
+ sqlite3_str_appendf(pMsg, " %s", aEscape[i].z);
+ }
+ fprintf(stderr, "%s:%d: no such escape mode: \"%s\"\nChoices: %s\n",
+ zSrc, lineNum, &zLine[10], sqlite3_str_value(pMsg));
+ sqlite3_free(sqlite3_str_finish(pMsg));
+ }
}else
if( strncmp(zLine, "--bShowCNames=", 14)==0 ){
spec.bShowCNames = atoi(&zLine[14])!=0;
int iVersion; /* Version number of this structure */
int eFormat; /* Output format */
unsigned char bShowCNames; /* True to show column names */
- unsigned char eEscMode; /* How to deal with control characters */
- unsigned char bQuote; /* Quote output values as SQL literals */
+ unsigned char eEscape; /* How to deal with control characters */
+ unsigned char eQuote; /* Quoting style */
unsigned char bWordWrap; /* Try to wrap on word boundaries */
int mxWidth; /* Maximum column width in columnar modes */
const char *zColumnSep; /* Alternative column separator */
#define RESFMT_Off 15 /* No query output shown */
#define RESFMT_ScanExp 16 /* Like RESFMT_Explain, but for ".scanstats vm" */
#define RESFMT_Www 17 /* Full web-page output */
+
+/*
+** Quoting styles.
+** Allowed values for sqlite3_resfmt_spec.eQuote
+*/
+#define RESFMT_Q_Off 0 /* Literal text */
+#define RESFMT_Q_Sql 1 /* Quote as an SQL literal */
+#define RESFMT_Q_Csv 2 /* CSV-style quoting */
+#define RESFMT_Q_Html 3 /* HTML-style quoting */
+#define RESFMT_Q_C 4 /* C/Tcl quoting */
+#define RESFMT_Q_Json 5 /* JSON quoting */
+
+/*
+** Control-character escape modes.
+** Allowed values for sqlite3_resfmt_spec.eEscape
+*/
+#define RESFMT_E_Off 0 /* Do not escape control characters */
+#define RESFMT_E_Unix 1 /* Unix-style escapes. Ex: U+0007 shows ^G */
+#define RESFMT_E_Unicode 2 /* Unicode escapes. Ex: U+0007 shows U+2407 */
-C More\scapabilities\sbeing\sadded.\s\sIncremental\scheck-in.
-D 2025-10-20T19:55:26.972
+C Recognize\sthe\svarious\squoting\sstyles\sand\sescape\smodes\sin\sthe\sresfmt-test\nprogram.
+D 2025-10-21T11:00:04.169
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F ext/misc/randomjson.c ef835fc64289e76ac4873b85fe12f9463a036168d7683cf2b773e36e6262c4ed
F ext/misc/regexp.c 548151f3e57506fda678e6a65e85a763f4eece653287e1ad44e167f9485e0c6b
F ext/misc/remember.c add730f0f7e7436cd15ea3fd6a90fd83c3f706ab44169f7f048438b7d6baa69c
-F ext/misc/resfmt-tester.c a657a79ce49ea6b39294d8684a9972c8b5824a7d9d51a08e5166c29e08a2dd70
-F ext/misc/resfmt.c a634719bdc83cbe8f732d6dbbdafd3a73060a8aa45a4fdfe55ecc93530bc2e5a
-F ext/misc/resfmt.h 2cb13016806263897e4aad0689f26f07eb8b5b26619d09f07af5c64be3041f4b
+F ext/misc/resfmt-tester.c 90a13ed2d4b61e147c0aa976c5b7c184c5e782ddbcfd6667a11431f26001cfc0
+F ext/misc/resfmt.c b12901db493acb62beb382f4174d66824f1311148b293f7736d74bfcfed0984d
+F ext/misc/resfmt.h da70079e9b543fbdd5bc2fef525b1d257f8e0e25d2550a0258540a377f42f4f3
F ext/misc/resfmt.md 6f6cefd95fa11ce30e4f34ea84052e7a8291dd48b7e666352bd7cf2e22c22ec4
F ext/misc/rot13.c 51ac5f51e9d5fd811db58a9c23c628ad5f333c173f1fc53c8491a3603d38556c
F ext/misc/scrub.c 2a44b0d44c69584c0580ad2553f6290a307a49df4668941d2812135bfb96a946
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 7aaaeea319c7165284028ff8cf1b3448a818c5029de02e7199614bb45aa304c5
-R 93f18f5de015815076ba558bceea8787
+P 9adaf791f88875c5afeba7e7aa72efb59df42c6052898f8d7e2f83aede00a044
+R 41bf090f4cb07015b0636c2cbe7ec8eb
U drh
-Z db7581bf692ee1510ff2608fd9941892
+Z 6c096d7b8b0de8560d49dc8950bacfdd
# Remove this line to create a well-formed Fossil manifest.