Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

34
external/bdwgc/cord/cord.am vendored Normal file
View File

@@ -0,0 +1,34 @@
## This file is processed with automake.
# Info (current:revision:age) for the Libtool versioning system.
# These numbers should be updated at most once just before the release,
# and, optionally, at most once during the development (after the release).
LIBCORD_VER_INFO = 4:0:3
noinst_LTLIBRARIES += libcord.la
libcord_la_LIBADD = $(top_builddir)/libgc.la
libcord_la_LDFLAGS = -version-info $(LIBCORD_VER_INFO) -no-undefined
libcord_la_CPPFLAGS = $(AM_CPPFLAGS)
libcord_la_SOURCES = \
cord/cordbscs.c \
cord/cordprnt.c \
cord/cordxtra.c
TESTS += cordtest$(EXEEXT)
check_PROGRAMS += cordtest
cordtest_SOURCES = cord/tests/cordtest.c
cordtest_LDADD = $(top_builddir)/libgc.la $(top_builddir)/libcord.la
EXTRA_DIST += \
cord/tests/de.c \
cord/tests/de_cmds.h \
cord/tests/de_win.c \
cord/tests/de_win.h \
cord/tests/de_win.rc
pkginclude_HEADERS += \
include/cord.h \
include/cord_pos.h \
include/ec.h

923
external/bdwgc/cord/cordbscs.c vendored Normal file

File diff suppressed because it is too large Load Diff

438
external/bdwgc/cord/cordprnt.c vendored Normal file
View File

@@ -0,0 +1,438 @@
/*
* Copyright (c) 1993-1994 by Xerox Corporation. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* An sprintf implementation that understands cords. This is probably */
/* not terribly portable. It assumes an ANSI stdarg.h. It further */
/* assumes that I can make copies of va_list variables, and read */
/* arguments repeatedly by applying va_arg to the copies. This */
/* could be avoided at some performance cost. */
/* We also assume that unsigned and signed integers of various kinds */
/* have the same sizes, and can be cast back and forth. */
/* We assume that void * and char * have the same size. */
/* All this cruft is needed because we want to rely on the underlying */
/* sprintf implementation whenever possible. */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef CORD_BUILD
# define CORD_BUILD
#endif
#include "cord.h"
#include "ec.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gc.h"
#define CONV_SPEC_LEN 50 /* Maximum length of a single */
/* conversion specification. */
#define CONV_RESULT_LEN 50 /* Maximum length of any */
/* conversion with default */
/* width and prec. */
#define OUT_OF_MEMORY do { \
if (CORD_oom_fn != 0) (*CORD_oom_fn)(); \
fprintf(stderr, "Out of memory\n"); \
abort(); \
} while (0)
static int ec_len(CORD_ec x)
{
return(CORD_len(x[0].ec_cord) + (x[0].ec_bufptr - x[0].ec_buf));
}
/* Possible nonumeric precision values. */
# define NONE -1
# define VARIABLE -2
/* Copy the conversion specification from CORD_pos into the buffer buf */
/* Return negative on error. */
/* Source initially points one past the leading %. */
/* It is left pointing at the conversion type. */
/* Assign field width and precision to *width and *prec. */
/* If width or prec is *, VARIABLE is assigned. */
/* Set *left to 1 if left adjustment flag is present. */
/* Set *long_arg to 1 if long flag ('l' or 'L') is present, or to */
/* -1 if 'h' is present. */
static int extract_conv_spec(CORD_pos source, char *buf,
int * width, int *prec, int *left, int * long_arg)
{
int result = 0;
int current_number = 0;
int saw_period = 0;
int saw_number = 0;
int chars_so_far = 0;
char current;
*width = NONE;
buf[chars_so_far++] = '%';
while(CORD_pos_valid(source)) {
if (chars_so_far >= CONV_SPEC_LEN) return(-1);
current = CORD_pos_fetch(source);
buf[chars_so_far++] = current;
switch(current) {
case '*':
saw_number = 1;
current_number = VARIABLE;
break;
case '0':
if (!saw_number) {
/* Zero fill flag; ignore */
break;
}
current_number *= 10;
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
saw_number = 1;
current_number *= 10;
current_number += current - '0';
break;
case '.':
saw_period = 1;
if(saw_number) {
*width = current_number;
saw_number = 0;
}
current_number = 0;
break;
case 'l':
case 'L':
*long_arg = 1;
current_number = 0;
break;
case 'h':
*long_arg = -1;
current_number = 0;
break;
case ' ':
case '+':
case '#':
current_number = 0;
break;
case '-':
*left = 1;
current_number = 0;
break;
case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
case 'c':
case 'C':
case 's':
case 'S':
case 'p':
case 'n':
case 'r':
goto done;
default:
return(-1);
}
CORD_next(source);
}
return(-1);
done:
if (saw_number) {
if (saw_period) {
*prec = current_number;
} else {
*prec = NONE;
*width = current_number;
}
} else {
*prec = NONE;
}
buf[chars_so_far] = '\0';
return(result);
}
#if defined(DJGPP) || defined(__STRICT_ANSI__)
/* vsnprintf is missing in DJGPP (v2.0.3) */
# define GC_VSNPRINTF(buf, bufsz, format, args) vsprintf(buf, format, args)
#elif defined(_MSC_VER)
# ifdef MSWINCE
/* _vsnprintf is deprecated in WinCE */
# define GC_VSNPRINTF StringCchVPrintfA
# else
# define GC_VSNPRINTF _vsnprintf
# endif
#else
# define GC_VSNPRINTF vsnprintf
#endif
int CORD_vsprintf(CORD * out, CORD format, va_list args)
{
CORD_ec result;
int count;
char current;
CORD_pos pos;
char conv_spec[CONV_SPEC_LEN + 1];
CORD_ec_init(result);
for (CORD_set_pos(pos, format, 0); CORD_pos_valid(pos); CORD_next(pos)) {
current = CORD_pos_fetch(pos);
if (current == '%') {
CORD_next(pos);
if (!CORD_pos_valid(pos)) return(-1);
current = CORD_pos_fetch(pos);
if (current == '%') {
CORD_ec_append(result, current);
} else {
int width, prec;
int left_adj = 0;
int long_arg = 0;
CORD arg;
size_t len;
if (extract_conv_spec(pos, conv_spec,
&width, &prec,
&left_adj, &long_arg) < 0) {
return(-1);
}
current = CORD_pos_fetch(pos);
switch(current) {
case 'n':
/* Assign length to next arg */
if (long_arg == 0) {
int * pos_ptr;
pos_ptr = va_arg(args, int *);
*pos_ptr = ec_len(result);
} else if (long_arg > 0) {
long * pos_ptr;
pos_ptr = va_arg(args, long *);
*pos_ptr = ec_len(result);
} else {
short * pos_ptr;
pos_ptr = va_arg(args, short *);
*pos_ptr = ec_len(result);
}
goto done;
case 'r':
/* Append cord and any padding */
if (width == VARIABLE) width = va_arg(args, int);
if (prec == VARIABLE) prec = va_arg(args, int);
arg = va_arg(args, CORD);
len = CORD_len(arg);
if (prec != NONE && len > (size_t)prec) {
if (prec < 0) return(-1);
arg = CORD_substr(arg, 0, prec);
len = (unsigned)prec;
}
if (width != NONE && len < (size_t)width) {
char * blanks =
(char *)GC_MALLOC_ATOMIC(width - len + 1);
if (NULL == blanks) OUT_OF_MEMORY;
memset(blanks, ' ', width-len);
blanks[width-len] = '\0';
if (left_adj) {
arg = CORD_cat(arg, blanks);
} else {
arg = CORD_cat(blanks, arg);
}
}
CORD_ec_append_cord(result, arg);
goto done;
case 'c':
if (width == NONE && prec == NONE) {
char c;
c = (char)va_arg(args, int);
CORD_ec_append(result, c);
goto done;
}
break;
case 's':
if (width == NONE && prec == NONE) {
char * str = va_arg(args, char *);
char c;
while ((c = *str++)) {
CORD_ec_append(result, c);
}
goto done;
}
break;
default:
break;
}
/* Use standard sprintf to perform conversion */
{
char * buf;
va_list vsprintf_args;
int max_size = 0;
int res = 0;
# if defined(CPPCHECK)
va_copy(vsprintf_args, args);
# elif defined(__va_copy)
__va_copy(vsprintf_args, args);
# elif defined(__GNUC__) && !defined(__DJGPP__) \
&& !defined(__EMX__) /* and probably in other cases */
va_copy(vsprintf_args, args);
# else
vsprintf_args = args;
# endif
if (width == VARIABLE) width = va_arg(args, int);
if (prec == VARIABLE) prec = va_arg(args, int);
if (width != NONE) max_size = width;
if (prec != NONE && prec > max_size) max_size = prec;
max_size += CONV_RESULT_LEN;
if (max_size >= CORD_BUFSZ) {
buf = (char *)GC_MALLOC_ATOMIC(max_size + 1);
if (NULL == buf) OUT_OF_MEMORY;
} else {
if (CORD_BUFSZ - (result[0].ec_bufptr-result[0].ec_buf)
< max_size) {
CORD_ec_flush_buf(result);
}
buf = result[0].ec_bufptr;
}
switch(current) {
case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
case 'c':
if (long_arg <= 0) {
(void) va_arg(args, int);
} else /* long_arg > 0 */ {
(void) va_arg(args, long);
}
break;
case 's':
case 'p':
(void) va_arg(args, char *);
break;
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
(void) va_arg(args, double);
break;
default:
res = -1;
}
if (0 == res)
res = GC_VSNPRINTF(buf, max_size + 1, conv_spec,
vsprintf_args);
# if defined(CPPCHECK) || defined(__va_copy) \
|| (defined(__GNUC__) && !defined(__DJGPP__) \
&& !defined(__EMX__))
va_end(vsprintf_args);
# endif
len = (size_t)res;
if ((char *)(GC_word)res == buf) {
/* old style vsprintf */
len = strlen(buf);
} else if (res < 0) {
return(-1);
}
if (buf != result[0].ec_bufptr) {
char c;
while ((c = *buf++)) {
CORD_ec_append(result, c);
}
} else {
result[0].ec_bufptr = buf + len;
}
}
done:;
}
} else {
CORD_ec_append(result, current);
}
}
count = ec_len(result);
*out = CORD_balance(CORD_ec_to_cord(result));
return(count);
}
int CORD_sprintf(CORD * out, CORD format, ...)
{
va_list args;
int result;
va_start(args, format);
result = CORD_vsprintf(out, format, args);
va_end(args);
return(result);
}
int CORD_fprintf(FILE * f, CORD format, ...)
{
va_list args;
int result;
CORD out = CORD_EMPTY; /* initialized to prevent compiler warning */
va_start(args, format);
result = CORD_vsprintf(&out, format, args);
va_end(args);
if (result > 0) CORD_put(out, f);
return(result);
}
int CORD_vfprintf(FILE * f, CORD format, va_list args)
{
int result;
CORD out = CORD_EMPTY;
result = CORD_vsprintf(&out, format, args);
if (result > 0) CORD_put(out, f);
return(result);
}
int CORD_printf(CORD format, ...)
{
va_list args;
int result;
CORD out = CORD_EMPTY;
va_start(args, format);
result = CORD_vsprintf(&out, format, args);
va_end(args);
if (result > 0) CORD_put(out, stdout);
return(result);
}
int CORD_vprintf(CORD format, va_list args)
{
int result;
CORD out = CORD_EMPTY;
result = CORD_vsprintf(&out, format, args);
if (result > 0) CORD_put(out, stdout);
return(result);
}

638
external/bdwgc/cord/cordxtra.c vendored Normal file

File diff suppressed because it is too large Load Diff

316
external/bdwgc/cord/tests/cordtest.c vendored Normal file
View File

@@ -0,0 +1,316 @@
/*
* Copyright (c) 1993-1994 by Xerox Corporation. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
# include "gc.h" /* For GC_INIT() only */
# include "cord.h"
# include <stdarg.h>
# include <string.h>
# include <stdio.h>
# include <stdlib.h>
/* This is a very incomplete test of the cord package. It knows about */
/* a few internals of the package (e.g. when C strings are returned) */
/* that real clients shouldn't rely on. */
# define ABORT(string) \
{ fprintf(stderr, "FAILED: %s\n", string); abort(); }
#if defined(CPPCHECK)
# undef CORD_iter
# undef CORD_next
# undef CORD_pos_fetch
# undef CORD_pos_to_cord
# undef CORD_pos_to_index
# undef CORD_pos_valid
# undef CORD_prev
#endif
int count;
int test_fn(char c, void * client_data)
{
if (client_data != (void *)13) ABORT("bad client data");
if (count < 64*1024+1) {
if ((count & 1) == 0) {
if (c != 'b') ABORT("bad char");
} else {
if (c != 'a') ABORT("bad char");
}
count++;
return(0);
} else {
if (c != 'c') ABORT("bad char");
count++;
return(1);
}
}
char id_cord_fn(size_t i, void * client_data)
{
if (client_data != 0) ABORT("id_cord_fn: bad client data");
return((char)i);
}
void test_basics(void)
{
CORD x = CORD_from_char_star("ab");
int i;
CORD y;
CORD_pos p;
x = CORD_cat(x,x);
if (x == CORD_EMPTY) ABORT("CORD_cat(x,x) returned empty cord");
if (!CORD_IS_STRING(x)) ABORT("short cord should usually be a string");
if (strcmp(x, "abab") != 0) ABORT("bad CORD_cat result");
for (i = 1; i < 16; i++) {
x = CORD_cat(x,x);
}
x = CORD_cat(x,"c");
if (CORD_len(x) != 128*1024+1) ABORT("bad length");
count = 0;
if (CORD_iter5(x, 64*1024-1, test_fn, CORD_NO_FN, (void *)13) == 0) {
ABORT("CORD_iter5 failed");
}
if (count != 64*1024 + 2) ABORT("CORD_iter5 failed");
count = 0;
CORD_set_pos(p, x, 64*1024-1);
while(CORD_pos_valid(p)) {
(void) test_fn(CORD_pos_fetch(p), (void *)13);
CORD_next(p);
}
if (count != 64*1024 + 2) ABORT("Position based iteration failed");
y = CORD_substr(x, 1023, 5);
if (!y) ABORT("CORD_substr returned NULL");
if (!CORD_IS_STRING(y)) ABORT("short cord should usually be a string");
if (strcmp(y, "babab") != 0) ABORT("bad CORD_substr result");
y = CORD_substr(x, 1024, 8);
if (!y) ABORT("CORD_substr returned NULL");
if (!CORD_IS_STRING(y)) ABORT("short cord should usually be a string");
if (strcmp(y, "abababab") != 0) ABORT("bad CORD_substr result");
y = CORD_substr(x, 128*1024-1, 8);
if (!y) ABORT("CORD_substr returned NULL");
if (!CORD_IS_STRING(y)) ABORT("short cord should usually be a string");
if (strcmp(y, "bc") != 0) ABORT("bad CORD_substr result");
x = CORD_balance(x);
if (CORD_len(x) != 128*1024+1) ABORT("bad length");
count = 0;
if (CORD_iter5(x, 64*1024-1, test_fn, CORD_NO_FN, (void *)13) == 0) {
ABORT("CORD_iter5 failed");
}
if (count != 64*1024 + 2) ABORT("CORD_iter5 failed");
y = CORD_substr(x, 1023, 5);
if (!y) ABORT("CORD_substr returned NULL");
if (!CORD_IS_STRING(y)) ABORT("short cord should usually be a string");
if (strcmp(y, "babab") != 0) ABORT("bad CORD_substr result");
y = CORD_from_fn(id_cord_fn, 0, 13);
i = 0;
CORD_set_pos(p, y, i);
while(CORD_pos_valid(p)) {
char c = CORD_pos_fetch(p);
if(c != i) ABORT("Traversal of function node failed");
CORD_next(p);
i++;
}
if (i != 13) ABORT("Bad apparent length for function node");
# if defined(CPPCHECK)
/* TODO: Actually test these functions. */
CORD_prev(p);
(void)CORD_pos_to_cord(p);
(void)CORD_pos_to_index(p);
(void)CORD_iter(CORD_EMPTY, test_fn, NULL);
(void)CORD_riter(CORD_EMPTY, test_fn, NULL);
CORD_dump(y);
# endif
}
void test_extras(void)
{
# define FNAME1 "cordtst1.tmp" /* short name (8+3) for portability */
# define FNAME2 "cordtst2.tmp"
int i;
CORD y = "abcdefghijklmnopqrstuvwxyz0123456789";
CORD x = "{}";
CORD u, w, z;
FILE *f;
FILE *f1a, *f1b, *f2;
w = CORD_cat(CORD_cat(y,y),y);
z = CORD_catn(3,y,y,y);
if (CORD_cmp(w,z) != 0) ABORT("CORD_catn comparison wrong");
for (i = 1; i < 100; i++) {
x = CORD_cat(x, y);
}
z = CORD_balance(x);
if (CORD_cmp(x,z) != 0) ABORT("balanced string comparison wrong");
if (CORD_cmp(x,CORD_cat(z, CORD_nul(13))) >= 0) ABORT("comparison 2");
if (CORD_cmp(CORD_cat(x, CORD_nul(13)), z) <= 0) ABORT("comparison 3");
if (CORD_cmp(x,CORD_cat(z, "13")) >= 0) ABORT("comparison 4");
if ((f = fopen(FNAME1, "w")) == 0) ABORT("open failed");
if (CORD_put(z,f) == EOF) ABORT("CORD_put failed");
if (fclose(f) == EOF) ABORT("fclose failed");
f1a = fopen(FNAME1, "rb");
if (!f1a) ABORT("Unable to open " FNAME1);
w = CORD_from_file(f1a);
if (CORD_len(w) != CORD_len(z)) ABORT("file length wrong");
if (CORD_cmp(w,z) != 0) ABORT("file comparison wrong");
if (CORD_cmp(CORD_substr(w, 50*36+2, 36), y) != 0)
ABORT("file substr wrong");
f1b = fopen(FNAME1, "rb");
if (!f1b) ABORT("2nd open failed: " FNAME1);
z = CORD_from_file_lazy(f1b);
if (CORD_cmp(w,z) != 0) ABORT("File conversions differ");
if (CORD_chr(w, 0, '9') != 37) ABORT("CORD_chr failed 1");
if (CORD_chr(w, 3, 'a') != 38) ABORT("CORD_chr failed 2");
if (CORD_rchr(w, CORD_len(w) - 1, '}') != 1) ABORT("CORD_rchr failed");
x = y;
for (i = 1; i < 14; i++) {
x = CORD_cat(x,x);
}
if ((f = fopen(FNAME2, "w")) == 0) ABORT("2nd open failed");
# ifdef __DJGPP__
/* FIXME: DJGPP workaround. Why does this help? */
if (fflush(f) != 0) ABORT("fflush failed");
# endif
if (CORD_put(x,f) == EOF) ABORT("CORD_put failed");
if (fclose(f) == EOF) ABORT("fclose failed");
f2 = fopen(FNAME2, "rb");
if (!f2) ABORT("Unable to open " FNAME2);
w = CORD_from_file(f2);
if (CORD_len(w) != CORD_len(x)) ABORT("file length wrong");
if (CORD_cmp(w,x) != 0) ABORT("file comparison wrong");
if (CORD_cmp(CORD_substr(w, 1000*36, 36), y) != 0)
ABORT("file substr wrong");
if (strcmp(CORD_to_char_star(CORD_substr(w, 1000*36, 36)), y) != 0)
ABORT("char * file substr wrong");
u = CORD_substr(w, 1000*36, 2);
if (!u) ABORT("CORD_substr returned NULL");
if (strcmp(u, "ab") != 0)
ABORT("short file substr wrong");
if (CORD_str(x,1,"9a") != 35) ABORT("CORD_str failed 1");
if (CORD_str(x,0,"9abcdefghijk") != 35) ABORT("CORD_str failed 2");
if (CORD_str(x,0,"9abcdefghijx") != CORD_NOT_FOUND)
ABORT("CORD_str failed 3");
if (CORD_str(x,0,"9>") != CORD_NOT_FOUND) ABORT("CORD_str failed 4");
/* Note: f1a, f1b, f2 handles are closed lazily by CORD library. */
/* TODO: Propose and use CORD_fclose. */
*(CORD volatile *)&w = CORD_EMPTY;
*(CORD volatile *)&z = CORD_EMPTY;
GC_gcollect();
GC_invoke_finalizers();
/* Of course, this does not guarantee the files are closed. */
if (remove(FNAME1) != 0) {
/* On some systems, e.g. OS2, this may fail if f1 is still open. */
/* But we cannot call fclose as it might lead to double close. */
fprintf(stderr, "WARNING: remove failed: " FNAME1 "\n");
}
if (remove(FNAME2) != 0) {
fprintf(stderr, "WARNING: remove failed: " FNAME2 "\n");
}
}
int wrap_vprintf(CORD format, ...)
{
va_list args;
int result;
va_start(args, format);
result = CORD_vprintf(format, args);
va_end(args);
return result;
}
int wrap_vfprintf(FILE * f, CORD format, ...)
{
va_list args;
int result;
va_start(args, format);
result = CORD_vfprintf(f, format, args);
va_end(args);
return result;
}
#if defined(__DJGPP__) || defined(__STRICT_ANSI__)
/* snprintf is missing in DJGPP (v2.0.3) */
#else
# if defined(_MSC_VER)
# if defined(_WIN32_WCE)
/* _snprintf is deprecated in WinCE */
# define GC_SNPRINTF StringCchPrintfA
# else
# define GC_SNPRINTF _snprintf
# endif
# else
# define GC_SNPRINTF snprintf
# endif
#endif
void test_printf(void)
{
CORD result;
char result2[200];
long l = -1;
short s = (short)-1;
CORD x;
if (CORD_sprintf(&result, "%7.2f%ln", 3.14159F, &l) != 7)
ABORT("CORD_sprintf failed 1");
if (CORD_cmp(result, " 3.14") != 0)ABORT("CORD_sprintf goofed 1");
if (l != 7) ABORT("CORD_sprintf goofed 2");
if (CORD_sprintf(&result, "%-7.2s%hn%c%s", "abcd", &s, 'x', "yz") != 10)
ABORT("CORD_sprintf failed 2");
if (CORD_cmp(result, "ab xyz") != 0)ABORT("CORD_sprintf goofed 3");
if (s != 7) ABORT("CORD_sprintf goofed 4");
x = "abcdefghij";
x = CORD_cat(x,x);
x = CORD_cat(x,x);
x = CORD_cat(x,x);
if (CORD_sprintf(&result, "->%-120.78r!\n", x) != 124)
ABORT("CORD_sprintf failed 3");
# ifdef GC_SNPRINTF
(void)GC_SNPRINTF(result2, sizeof(result2), "->%-120.78s!\n",
CORD_to_char_star(x));
# else
(void)sprintf(result2, "->%-120.78s!\n", CORD_to_char_star(x));
# endif
result2[sizeof(result2) - 1] = '\0';
if (CORD_cmp(result, result2) != 0)ABORT("CORD_sprintf goofed 5");
/* TODO: Better test CORD_[v][f]printf. */
(void)CORD_printf(CORD_EMPTY);
(void)wrap_vfprintf(stdout, CORD_EMPTY);
(void)wrap_vprintf(CORD_EMPTY);
}
int main(void)
{
# ifdef THINK_C
printf("cordtest:\n");
# endif
GC_INIT();
test_basics();
test_extras();
test_printf();
CORD_fprintf(stdout, "SUCCEEDED\n");
return(0);
}

615
external/bdwgc/cord/tests/de.c vendored Normal file

File diff suppressed because it is too large Load Diff

31
external/bdwgc/cord/tests/de_cmds.h vendored Normal file
View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 1994 by Xerox Corporation. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
#ifndef DE_CMDS_H
# define DE_CMDS_H
# define UP 16 /* ^P */
# define DOWN 14 /* ^N */
# define LEFT 2 /* ^B */
# define RIGHT 6 /* ^F */
# define DEL 127 /* ^? */
# define BS 8 /* ^H */
# define UNDO 21 /* ^U */
# define WRITE 23 /* ^W */
# define QUIT 4 /* ^D */
# define REPEAT 18 /* ^R */
# define LOCATE 12 /* ^L */
# define TOP 20 /* ^T */
#endif

368
external/bdwgc/cord/tests/de_win.c vendored Normal file
View File

@@ -0,0 +1,368 @@
/*
* Copyright (c) 1994 by Xerox Corporation. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/*
* The MS Windows specific part of de.
* This started as the generic Windows application template
* but significant parts didn't survive to the final version.
*
* This was written by a nonexpert windows programmer.
*/
#include "windows.h"
#include "gc.h"
#include "cord.h"
#include "de_cmds.h"
#include "de_win.h"
int LINES = 0;
int COLS = 0;
#define szAppName TEXT("DE")
HWND hwnd;
void de_error(const char *s)
{
(void)MessageBoxA(hwnd, s, "Demonstration Editor",
MB_ICONINFORMATION | MB_OK);
InvalidateRect(hwnd, NULL, TRUE);
}
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR command_line, int nCmdShow)
{
MSG msg;
WNDCLASS wndclass;
HACCEL hAccel;
GC_INIT();
# if defined(CPPCHECK)
GC_noop1((GC_word)&WinMain);
# endif
if (!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = DLGWINDOWEXTRA;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, szAppName);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = TEXT("DE");
wndclass.lpszClassName = szAppName;
if (RegisterClass (&wndclass) == 0) {
de_error("RegisterClass error");
return(0);
}
}
/* Empirically, the command line does not include the command name ...
if (command_line != 0) {
while (isspace(*command_line)) command_line++;
while (*command_line != 0 && !isspace(*command_line)) command_line++;
while (isspace(*command_line)) command_line++;
} */
if (command_line == 0 || *command_line == 0) {
de_error("File name argument required");
return( 0 );
} else {
char *p = command_line;
while (*p != 0 && !isspace(*(unsigned char *)p))
p++;
arg_file_name = CORD_to_char_star(
CORD_substr(command_line, 0, p - command_line));
}
hwnd = CreateWindow (szAppName,
TEXT("Demonstration Editor"),
WS_OVERLAPPEDWINDOW | WS_CAPTION, /* Window style */
CW_USEDEFAULT, 0, /* default pos. */
CW_USEDEFAULT, 0, /* default width, height */
NULL, /* No parent */
NULL, /* Window class menu */
hInstance, NULL);
if (hwnd == NULL) {
de_error("CreateWindow error");
return(0);
}
ShowWindow (hwnd, nCmdShow);
hAccel = LoadAccelerators( hInstance, szAppName );
while (GetMessage (&msg, NULL, 0, 0))
{
if( !TranslateAccelerator( hwnd, hAccel, &msg ) )
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
return (int)msg.wParam;
}
/* Return the argument with all control characters replaced by blanks. */
char * plain_chars(char * text, size_t len)
{
char * result = (char *)GC_MALLOC_ATOMIC(len + 1);
size_t i;
if (NULL == result) return NULL;
for (i = 0; i < len; i++) {
if (iscntrl(((unsigned char *)text)[i])) {
result[i] = ' ';
} else {
result[i] = text[i];
}
}
result[len] = '\0';
return(result);
}
/* Return the argument with all non-control-characters replaced by */
/* blank, and all control characters c replaced by c + 32. */
char * control_chars(char * text, size_t len)
{
char * result = (char *)GC_MALLOC_ATOMIC(len + 1);
size_t i;
if (NULL == result) return NULL;
for (i = 0; i < len; i++) {
if (iscntrl(((unsigned char *)text)[i])) {
result[i] = text[i] + 0x40;
} else {
result[i] = ' ';
}
}
result[len] = '\0';
return(result);
}
int char_width;
int char_height;
void get_line_rect(int line, int win_width, RECT * rectp)
{
rectp -> top = line * (LONG)char_height;
rectp -> bottom = rectp->top + char_height;
rectp -> left = 0;
rectp -> right = win_width;
}
int caret_visible = 0; /* Caret is currently visible. */
int screen_was_painted = 0;/* Screen has been painted at least once. */
void update_cursor(void);
INT_PTR CALLBACK AboutBoxCallback( HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam )
{
(void)lParam;
switch( message )
{
case WM_INITDIALOG:
SetFocus( GetDlgItem( hDlg, IDOK ) );
break;
case WM_COMMAND:
switch( wParam )
{
case IDOK:
EndDialog( hDlg, TRUE );
break;
}
break;
case WM_CLOSE:
EndDialog( hDlg, TRUE );
return TRUE;
}
return FALSE;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance;
HDC dc;
PAINTSTRUCT ps;
RECT client_area;
RECT this_line;
RECT dummy;
TEXTMETRIC tm;
int i;
int id;
switch (message)
{
case WM_CREATE:
hInstance = ( (LPCREATESTRUCT) lParam)->hInstance;
dc = GetDC(hwnd);
SelectObject(dc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextMetrics(dc, &tm);
ReleaseDC(hwnd, dc);
char_width = tm.tmAveCharWidth;
char_height = tm.tmHeight + tm.tmExternalLeading;
GetClientRect(hwnd, &client_area);
COLS = (client_area.right - client_area.left)/char_width;
LINES = (client_area.bottom - client_area.top)/char_height;
generic_init();
return(0);
case WM_CHAR:
if (wParam == QUIT) {
SendMessage( hwnd, WM_CLOSE, 0, 0L );
} else {
do_command((int)wParam);
}
return(0);
case WM_SETFOCUS:
CreateCaret(hwnd, NULL, char_width, char_height);
ShowCaret(hwnd);
caret_visible = 1;
update_cursor();
return(0);
case WM_KILLFOCUS:
HideCaret(hwnd);
DestroyCaret();
caret_visible = 0;
return(0);
case WM_LBUTTONUP:
{
unsigned xpos = LOWORD(lParam); /* From left */
unsigned ypos = HIWORD(lParam); /* from top */
set_position(xpos / (unsigned)char_width,
ypos / (unsigned)char_height);
return(0);
}
case WM_COMMAND:
id = LOWORD(wParam);
if (id & EDIT_CMD_FLAG) {
if (id & REPEAT_FLAG) do_command(REPEAT);
do_command(CHAR_CMD(id));
return( 0 );
} else {
switch(id) {
case IDM_FILEEXIT:
SendMessage( hwnd, WM_CLOSE, 0, 0L );
return( 0 );
case IDM_HELPABOUT:
if( DialogBox( hInstance, TEXT("ABOUTBOX"),
hwnd, AboutBoxCallback ) )
InvalidateRect( hwnd, NULL, TRUE );
return( 0 );
case IDM_HELPCONTENTS:
de_error(
"Cursor keys: ^B(left) ^F(right) ^P(up) ^N(down)\n"
"Undo: ^U Write: ^W Quit:^D Repeat count: ^R[n]\n"
"Top: ^T Locate (search, find): ^L text ^L\n");
return( 0 );
}
}
break;
case WM_CLOSE:
DestroyWindow( hwnd );
return 0;
case WM_DESTROY:
PostQuitMessage (0);
GC_win32_free_heap();
return 0;
case WM_PAINT:
dc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &client_area);
COLS = (client_area.right - client_area.left)/char_width;
LINES = (client_area.bottom - client_area.top)/char_height;
SelectObject(dc, GetStockObject(SYSTEM_FIXED_FONT));
for (i = 0; i < LINES; i++) {
get_line_rect(i, client_area.right, &this_line);
if (IntersectRect(&dummy, &this_line, &ps.rcPaint)) {
CORD raw_line = retrieve_screen_line(i);
size_t len = CORD_len(raw_line);
char * text = CORD_to_char_star(raw_line);
/* May contain embedded NULLs */
char * plain = plain_chars(text, len);
char * blanks = CORD_to_char_star(CORD_chars(' ',
COLS - len));
char * control = control_chars(text, len);
if (NULL == plain || NULL == control)
de_error("Out of memory!");
# define RED RGB(255,0,0)
SetBkMode(dc, OPAQUE);
SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT));
if (plain != NULL)
TextOutA(dc, this_line.left, this_line.top,
plain, (int)len);
TextOutA(dc, this_line.left + (int)len * char_width,
this_line.top,
blanks, (int)(COLS - len));
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, RED);
if (control != NULL)
TextOutA(dc, this_line.left, this_line.top,
control, (int)strlen(control));
}
}
EndPaint(hwnd, &ps);
screen_was_painted = 1;
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
int last_col;
int last_line;
void move_cursor(int c, int l)
{
last_col = c;
last_line = l;
if (caret_visible) update_cursor();
}
void update_cursor(void)
{
SetCaretPos(last_col * char_width, last_line * char_height);
ShowCaret(hwnd);
}
void invalidate_line(int i)
{
RECT line;
if (!screen_was_painted) return;
/* Invalidating a rectangle before painting seems result in a */
/* major performance problem. */
get_line_rect(i, COLS*char_width, &line);
InvalidateRect(hwnd, &line, FALSE);
}

97
external/bdwgc/cord/tests/de_win.h vendored Normal file
View File

@@ -0,0 +1,97 @@
/*
* Copyright (c) 1994 by Xerox Corporation. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* cord.h, de_cmds.h, and windows.h should be included before this. */
# define OTHER_FLAG 0x100
# define EDIT_CMD_FLAG 0x200
# define REPEAT_FLAG 0x400
# define CHAR_CMD(i) ((i) & 0xff)
/* MENU: DE */
#define IDM_FILESAVE (EDIT_CMD_FLAG + WRITE)
#define IDM_FILEEXIT (OTHER_FLAG + 1)
#define IDM_HELPABOUT (OTHER_FLAG + 2)
#define IDM_HELPCONTENTS (OTHER_FLAG + 3)
#define IDM_EDITPDOWN (REPEAT_FLAG + EDIT_CMD_FLAG + DOWN)
#define IDM_EDITPUP (REPEAT_FLAG + EDIT_CMD_FLAG + UP)
#define IDM_EDITUNDO (EDIT_CMD_FLAG + UNDO)
#define IDM_EDITLOCATE (EDIT_CMD_FLAG + LOCATE)
#define IDM_EDITDOWN (EDIT_CMD_FLAG + DOWN)
#define IDM_EDITUP (EDIT_CMD_FLAG + UP)
#define IDM_EDITLEFT (EDIT_CMD_FLAG + LEFT)
#define IDM_EDITRIGHT (EDIT_CMD_FLAG + RIGHT)
#define IDM_EDITBS (EDIT_CMD_FLAG + BS)
#define IDM_EDITDEL (EDIT_CMD_FLAG + DEL)
#define IDM_EDITREPEAT (EDIT_CMD_FLAG + REPEAT)
#define IDM_EDITTOP (EDIT_CMD_FLAG + TOP)
/* Windows UI stuff */
LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam);
/* Screen dimensions. Maintained by de_win.c. */
extern int LINES;
extern int COLS;
/* File being edited. */
extern char * arg_file_name;
/* Current display position in file. Maintained by de.c */
extern int dis_line;
extern int dis_col;
/* Current cursor position in file. */
extern int line;
extern int col;
/*
* Calls from de_win.c to de.c
*/
CORD retrieve_screen_line(int i);
/* Get the contents of i'th screen line. */
/* Relies on COLS. */
void set_position(int x, int y);
/* Set column, row. Upper left of window = (0,0). */
void do_command(int);
/* Execute an editor command. */
/* Agument is a command character or one */
/* of the IDM_ commands. */
void generic_init(void);
/* OS independent initialization */
/*
* Calls from de.c to de_win.c
*/
void move_cursor(int column, int line);
/* Physically move the cursor on the display, */
/* so that it appears at */
/* (column, line). */
void invalidate_line(int line);
/* Invalidate line i on the screen. */
void de_error(const char *s);
/* Display error message. */

67
external/bdwgc/cord/tests/de_win.rc vendored Normal file
View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to copy this garbage collector for any purpose,
* provided the above notices are retained on all copies.
*/
#include "windows.h"
#include "de_cmds.h"
#include "de_win.h"
ABOUTBOX DIALOG 19, 21, 163, 47
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Demonstration Text Editor"
BEGIN
LTEXT "Demonstration Text Editor", -1, 44, 8, 118, 8, WS_CHILD | WS_VISIBLE | WS_GROUP
PUSHBUTTON "OK", IDOK, 118, 27, 24, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
END
DE MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Save\t^W", IDM_FILESAVE
MENUITEM "E&xit\t^D", IDM_FILEEXIT
END
POPUP "&Edit"
BEGIN
MENUITEM "Page &Down\t^R^N", IDM_EDITPDOWN
MENUITEM "Page &Up\t^R^P", IDM_EDITPUP
MENUITEM "U&ndo\t^U", IDM_EDITUNDO
MENUITEM "&Locate\t^L ... ^L", IDM_EDITLOCATE
MENUITEM "D&own\t^N", IDM_EDITDOWN
MENUITEM "U&p\t^P", IDM_EDITUP
MENUITEM "Le&ft\t^B", IDM_EDITLEFT
MENUITEM "&Right\t^F", IDM_EDITRIGHT
MENUITEM "Delete &Backward\tBS", IDM_EDITBS
MENUITEM "Delete F&orward\tDEL", IDM_EDITDEL
MENUITEM "&Top\t^T", IDM_EDITTOP
END
POPUP "&Help"
BEGIN
MENUITEM "&Contents", IDM_HELPCONTENTS
MENUITEM "&About...", IDM_HELPABOUT
END
MENUITEM "Page_&Down", IDM_EDITPDOWN
MENUITEM "Page_&Up", IDM_EDITPUP
END
DE ACCELERATORS
BEGIN
"^R", IDM_EDITREPEAT
"^N", IDM_EDITDOWN
"^P", IDM_EDITUP
"^L", IDM_EDITLOCATE
"^B", IDM_EDITLEFT
"^F", IDM_EDITRIGHT
"^T", IDM_EDITTOP
VK_DELETE, IDM_EDITDEL, VIRTKEY
VK_BACK, IDM_EDITBS, VIRTKEY
END