Fossil

Check-in [8133501e]
Login

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

Overview
Comment:Modify linenoise.c so that it can build with -std=c89. Baseline linenoise.c relied on snprintf(), strdup(), and strcasecmp() which are technically not in C89. Since linenoise.c's only purpose (at present) is to implement the SQLite shell, make use of the SQLite compatibility functions. Following this change, "fossil clean -f && CFLAGS='-std=c89 -Wall' ./configure && make" builds without warnings or errors on gcc 4.4.7 20120313 (Red Hat 4.4.7-3) on CentOS release 6.4 (Final). Unrelated note: discovered during testing that "CFLAGS=-Werror ./configure" fails to add -lm to link step due to conflicting types for built-in function "sin" being regarded as an error.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8133501ecbf7810ad5da386db3b1f2a642de9c66
User & Date: andygoth 2016-11-04 17:25:27
Context
2016-11-04
17:28
Further magic _WIN32_WINNT changes to fix the build for mingw. check-in: 45b76344 user: drh tags: trunk
17:25
Modify linenoise.c so that it can build with -std=c89. Baseline linenoise.c relied on snprintf(), strdup(), and strcasecmp() which are technically not in C89. Since linenoise.c's only purpose (at present) is to implement the SQLite shell, make use of the SQLite compatibility functions. Following this change, "fossil clean -f && CFLAGS='-std=c89 -Wall' ./configure && make" builds without warnings or errors on gcc 4.4.7 20120313 (Red Hat 4.4.7-3) on CentOS release 6.4 (Final). Unrelated note: discovered during testing that "CFLAGS=-Werror ./configure" fails to add -lm to link step due to conflicting types for built-in function "sin" being regarded as an error. check-in: 8133501e user: andygoth tags: trunk
12:03
typo check-in: e826eadd user: jan.nijtmans tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/linenoise.c.

103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
...
189
190
191
192
193
194
195
































196
197
198
199
200
201
202
 *    Sequence: ESC [ 2 J
 *    Effect: clear the whole screen
 *
 */

#include <termios.h>
#include <unistd.h>

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "linenoise.h"


#define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100
#define LINENOISE_MAX_LINE 4096
static const char *unsupported_term[] = {"dumb","cons25","emacs",NULL};
static linenoiseCompletionCallback *completionCallback = NULL;

static struct termios orig_termios; /* In order to restore at exit.*/
................................................................................
        } \
        fprintf(lndebug_fp, ", " fmt, arg1); \
        fflush(lndebug_fp); \
    } while (0)
#else
#define lndebug(fmt, arg1)
#endif

































/* ======================= Low level terminal handling ====================== */

/* Set if to use or not the multi line mode. */
void linenoiseSetMultiLine(int ml) {
    mlmode = ml;
}







>










>







 







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







103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
 *    Sequence: ESC [ 2 J
 *    Effect: clear the whole screen
 *
 */

#include <termios.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "linenoise.h"
#include "sqlite3.h"

#define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100
#define LINENOISE_MAX_LINE 4096
static const char *unsupported_term[] = {"dumb","cons25","emacs",NULL};
static linenoiseCompletionCallback *completionCallback = NULL;

static struct termios orig_termios; /* In order to restore at exit.*/
................................................................................
        } \
        fprintf(lndebug_fp, ", " fmt, arg1); \
        fflush(lndebug_fp); \
    } while (0)
#else
#define lndebug(fmt, arg1)
#endif

/* =========================== C89 compatibility ============================ */

/* snprintf() is not C89, but sqlite3_vsnprintf() can be adapted. */
static int linenoiseSnprintf(char *str, size_t size, const char *format, ...) {
    va_list ap;
    int result;

    va_start(ap,format);
    result = strlen(sqlite3_vsnprintf((int)size,str,format,ap));
    va_end(ap);

    return result;
}
#undef snprintf
#define snprintf linenoiseSnprintf

/* strdup() is technically not standard C89 despite being in POSIX. */
static char *linenoiseStrdup(const char *s) {
    int size = strlen(s)+1;
    char *result = malloc(size);

    if (result) memcpy(result,s,size);

    return result;
}
#undef strdup
#define strdup linenoiseStrdup

/* strcasecmp() is not standard C89.  SQLite offers a direct replacement. */
#undef strcasecmp
#define strcasecmp sqlite3_stricmp

/* ======================= Low level terminal handling ====================== */

/* Set if to use or not the multi line mode. */
void linenoiseSetMultiLine(int ml) {
    mlmode = ml;
}