From cc043d750d5bc5f80f47b7fd30f9fb379d078819 Mon Sep 17 00:00:00 2001 From: Angel Ortega Date: Sun, 26 Apr 2009 10:53:53 +0200 Subject: [PATCH] Delete all traces of scanf(), as it won't be part of 1.0.7. --- RELEASE_NOTES | 1 - TODO | 2 +- mpdm.h | 1 - mpdm_s.c | 188 ---------------------------------------------------------- stress.c | 63 -------------------- 5 files changed, 1 insertion(+), 254 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 92fad88..ad793c4 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -4,7 +4,6 @@ MPDM Release Notes 1.0.7 ----- - * New function mpdm_scanf(). * Fixed a bug when processing backslashes in the substitution string in sregex(), that made them dissappear if they were not escaping an ampersand. diff --git a/TODO b/TODO index 4c9e779..9577783 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,7 @@ Minimum Profit Data Manager (MPDM) TODO / Bug List Release Critical Bugs --------------------- - * 1111: Document mpdm_scanf(). +None! Open Bugs --------- diff --git a/mpdm.h b/mpdm.h index e19348a..67c95f9 100644 --- a/mpdm.h +++ b/mpdm.h @@ -121,7 +121,6 @@ mpdm_t mpdm_new_r(double rval); int mpdm_wcwidth(wchar_t c); mpdm_t mpdm_sprintf(const mpdm_t fmt, const mpdm_t args); mpdm_t mpdm_ulc(const mpdm_t s, int u); -mpdm_t mpdm_scanf(const mpdm_t fmt, const mpdm_t str, int offset); wchar_t *mpdm_string(const mpdm_t v); mpdm_t mpdm_splice(const mpdm_t v, const mpdm_t i, int offset, int del); diff --git a/mpdm_s.c b/mpdm_s.c index 4f99eb3..54ec0b1 100644 --- a/mpdm_s.c +++ b/mpdm_s.c @@ -960,191 +960,3 @@ mpdm_t mpdm_ulc(const mpdm_t s, int u) return r; } - - -/* working buffers */ -#define SCANF_BUF_SIZE 1024 -static wchar_t scanf_yset[SCANF_BUF_SIZE]; -static wchar_t scanf_nset[SCANF_BUF_SIZE]; -static wchar_t scanf_mark[SCANF_BUF_SIZE]; - -mpdm_t mpdm_scanf(const mpdm_t fmt, const mpdm_t str, int offset) -{ - wchar_t *i = (wchar_t *)str->data; - wchar_t *f = (wchar_t *)fmt->data; - mpdm_t r; - - i += offset; - r = MPDM_A(0); - - while (*f) { - if (*f == L'%') { - wchar_t *ptr = NULL; - int size = 0; - wchar_t cmd; - int vsize = 0; - int ignore = 0; - int msize = 0; - - /* empty all buffers */ - scanf_yset[0] = scanf_nset[0] = scanf_mark[0] = L'\0'; - - f++; - - /* an asterisk? don't return next value */ - if (*f == L'*') { - ignore = 1; - f++; - } - - /* does it have a size? */ - while (wcschr(L"0123456789", *f)) { - vsize *= 10; - vsize += *f - L'0'; - f++; - } - - /* if no size, set it to an arbitrary big limit */ - if (!vsize) - vsize = 0xfffffff; - - /* now *f should contain a command */ - cmd = *f; - f++; - - /* is it a number? */ - if (wcschr(L"udixf", cmd)) { - wcscpy(scanf_yset, L"0123456789"); - - if (cmd != 'u') - wcscat(scanf_yset, L"-"); - if (cmd == 'x') - wcscat(scanf_yset, L"xabcdefABCDEF"); - if (cmd == 'f') - wcscat(scanf_yset, L"."); - } - else - /* non-space string */ - if (cmd == L's') - wcscpy(scanf_nset, L" \t"); - else - /* verbatim percent sign */ - if (cmd == L'%') { - vsize = 1; - ignore = 1; - wcscpy(scanf_yset, L"%"); - } - else - /* position */ - if (cmd == L'n') { - vsize = 0; - ignore = 1; - mpdm_push(r, MPDM_I(i - (wchar_t *)str->data)); - } - else - /* string upto a mark */ - if (cmd == L'S') { - wchar_t *tmp = f; - - /* fill the mark upto another command */ - while (*tmp) { - if (*tmp == L'%') { - tmp++; - - /* is it an 'n'? ignore and go on */ - if (*tmp == L'n') { - tmp++; - continue; - } - else - if (*tmp == L'%') - scanf_mark[msize++] = *tmp; - else - break; - } - else - scanf_mark[msize++] = *tmp; - - tmp++; - } - - scanf_mark[msize] = L'\0'; - } - else - /* raw set */ - if (cmd == L'[') { - int n = 0; - wchar_t *set = scanf_yset; - - /* is it an inverse set? */ - if (*f == L'^') { - set = scanf_nset; - f++; - } - - /* first one is a ]? add it */ - if (*f == L']') { - set[n++] = *f; - f++; - } - - /* now build the set */ - for (; n < SCANF_BUF_SIZE - 1 && *f && *f != L']'; f++) { - /* is it a range? */ - if (*f == L'-') { - f++; - - /* start or end? hyphen itself */ - if (n == 0 || *f == L']') - set[n++] = L'-'; - else { - /* pick previous char */ - wchar_t c = set[n - 1]; - - /* fill */ - while (n < SCANF_BUF_SIZE - 1 && c < *f) - set[n++] = ++c; - } - } - else - set[n++] = *f; - } - - /* skip the ] */ - f++; - - set[n] = L'\0'; - } - - /* now fill the dynamic string */ - while (vsize && - !wcschr(scanf_nset, *i) && - (scanf_yset[0] == L'\0' || wcschr(scanf_yset, *i)) && - (msize == 0 || wcsncmp(i, scanf_mark, msize) != 0)) { - - /* only add if not being ignored */ - if (!ignore) - ptr = mpdm_poke(ptr, &size, i, 1, sizeof(wchar_t)); - - i++; - vsize--; - } - - if (!ignore && size) { - /* null terminate and push */ - ptr = mpdm_poke(ptr, &size, L"", 1, sizeof(wchar_t)); - mpdm_push(r, MPDM_ENS(ptr, size)); - } - } - else - /* test for literals in the format string */ - if (*i == *f) { - i++; - f++; - } - else - break; - } - - return r; -} diff --git a/stress.c b/stress.c index c56fcf0..f34d5fa 100644 --- a/stress.c +++ b/stress.c @@ -1177,68 +1177,6 @@ void test_ulc(void) } -void test_scanf(void) -{ - mpdm_t v; - - v = mpdm_scanf(MPDM_LS(L"%d %d"), MPDM_LS(L"1234 5678"), 0); - do_test("mpdm_scanf_1.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"1234")) == 0); - do_test("mpdm_scanf_1.2", mpdm_cmp(mpdm_aget(v, 1), MPDM_LS(L"5678")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%s %f %d"), MPDM_LS(L"this 12.34 5678"), 0); - do_test("mpdm_scanf_2.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"this")) == 0); - do_test("mpdm_scanf_2.2", mpdm_cmp(mpdm_aget(v, 1), MPDM_LS(L"12.34")) == 0); - do_test("mpdm_scanf_2.3", mpdm_cmp(mpdm_aget(v, 2), MPDM_LS(L"5678")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%s %*f %d"), MPDM_LS(L"this 12.34 5678"), 0); - do_test("mpdm_scanf_3.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"this")) == 0); - do_test("mpdm_scanf_3.2", mpdm_cmp(mpdm_aget(v, 1), MPDM_LS(L"5678")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%4d%4d%2d%10d"), MPDM_LS(L"12341234121234567890"), 0); - do_test("mpdm_scanf_4.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"1234")) == 0); - do_test("mpdm_scanf_4.2", mpdm_cmp(mpdm_aget(v, 1), MPDM_LS(L"1234")) == 0); - do_test("mpdm_scanf_4.3", mpdm_cmp(mpdm_aget(v, 2), MPDM_LS(L"12")) == 0); - do_test("mpdm_scanf_4.4", mpdm_cmp(mpdm_aget(v, 3), MPDM_LS(L"1234567890")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%[abc]%s"), MPDM_LS(L"ccbaabcxaaae and more"), 0); - do_test("mpdm_scanf_5.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"ccbaabc")) == 0); - do_test("mpdm_scanf_5.2", mpdm_cmp(mpdm_aget(v, 1), MPDM_LS(L"xaaae")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%[a-d]%s"), MPDM_LS(L"ccbaabcxaaae and more"), 0); - do_test("mpdm_scanf_6.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"ccbaabc")) == 0); - do_test("mpdm_scanf_6.2", mpdm_cmp(mpdm_aget(v, 1), MPDM_LS(L"xaaae")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%[^x]%s"), MPDM_LS(L"ccbaabcxaaae and more"), 0); - do_test("mpdm_scanf_7.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"ccbaabc")) == 0); - do_test("mpdm_scanf_7.2", mpdm_cmp(mpdm_aget(v, 1), MPDM_LS(L"xaaae")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%[^:]: %s"), MPDM_LS(L"key: value"), 0); - do_test("mpdm_scanf_8.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"key")) == 0); - do_test("mpdm_scanf_8.2", mpdm_cmp(mpdm_aget(v, 1), MPDM_LS(L"value")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%*[^/]/* %s */"), MPDM_LS(L"this is code /* comment */ more code"), 0); - do_test("mpdm_scanf_9.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"comment")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%d%%%d"), MPDM_LS(L"1234%5678"), 0); - do_test("mpdm_scanf_10.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"1234")) == 0); - do_test("mpdm_scanf_10.2", mpdm_cmp(mpdm_aget(v, 1), MPDM_LS(L"5678")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%*[abc]%n%*[^ ]%n"), MPDM_LS(L"ccbaabcxaaae and more"), 0); - do_test("mpdm_scanf_11.1", mpdm_ival(mpdm_aget(v, 0)) == 7); - do_test("mpdm_scanf_11.2", mpdm_ival(mpdm_aget(v, 1)) == 12); - - v = mpdm_scanf(MPDM_LS(L"/* %S */"), MPDM_LS(L"/* inside the comment */"), 0); - do_test("mpdm_scanf_12.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"inside the comment")) == 0); - - v = mpdm_scanf(MPDM_LS(L"/* %S */%s"), MPDM_LS(L"/* inside the comment */outside"), 0); - do_test("mpdm_scanf_13.1", mpdm_cmp(mpdm_aget(v, 0), MPDM_LS(L"inside the comment")) == 0); - do_test("mpdm_scanf_13.2", mpdm_cmp(mpdm_aget(v, 1), MPDM_LS(L"outside")) == 0); - - v = mpdm_scanf(MPDM_LS(L"%n"), MPDM_LS(L""), 0); - do_test("mpdm_scanf_14.1", mpdm_size(v) == 1 && mpdm_ival(mpdm_aget(v, 0)) == 0); -} - - int main(int argc, char *argv[]) { if (argc > 1) { @@ -1268,7 +1206,6 @@ int main(int argc, char *argv[]) test_misc(); test_sprintf(); test_ulc(); - test_scanf(); benchmark(); -- 2.11.4.GIT