summaryrefslogtreecommitdiffstats
path: root/src/backend/utils/mb/win1251.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
commit46651ce6fe013220ed397add242004d764fc0153 (patch)
tree6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/backend/utils/mb/win1251.c
parentInitial commit. (diff)
downloadpostgresql-14-46651ce6fe013220ed397add242004d764fc0153.tar.xz
postgresql-14-46651ce6fe013220ed397add242004d764fc0153.zip
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/backend/utils/mb/win1251.c')
-rw-r--r--src/backend/utils/mb/win1251.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/backend/utils/mb/win1251.c b/src/backend/utils/mb/win1251.c
new file mode 100644
index 0000000..75129e6
--- /dev/null
+++ b/src/backend/utils/mb/win1251.c
@@ -0,0 +1,74 @@
+/*
+ * make KOI8->CP1251(win-1251) and CP1251(win-1251)->KOI8 translation table
+ * from koi-win.tab.
+ *
+ * Tatsuo Ishii
+ *
+ * src/backend/utils/mb/win1251.c
+ */
+
+#include <stdio.h>
+
+
+main()
+{
+ int i;
+ char koitab[128],
+ wintab[128];
+ char buf[4096];
+ int koi,
+ win;
+
+ for (i = 0; i < 128; i++)
+ koitab[i] = wintab[i] = 0;
+
+ while (fgets(buf, sizeof(buf), stdin) != NULL)
+ {
+ if (*buf == '#')
+ continue;
+ sscanf(buf, "%d %d", &koi, &win);
+ if (koi < 128 || koi > 255 || win < 128 || win > 255)
+ {
+ fprintf(stderr, "invalid value %d\n", koi);
+ exit(1);
+ }
+ koitab[koi - 128] = win;
+ wintab[win - 128] = koi;
+ }
+
+ i = 0;
+ printf("static char koi2win[] = {\n");
+ while (i < 128)
+ {
+ int j = 0;
+
+ while (j < 8)
+ {
+ printf("0x%02x", koitab[i++]);
+ j++;
+ if (i >= 128)
+ break;
+ printf(", ");
+ }
+ printf("\n");
+ }
+ printf("};\n");
+
+ i = 0;
+ printf("static char win2koi[] = {\n");
+ while (i < 128)
+ {
+ int j = 0;
+
+ while (j < 8)
+ {
+ printf("0x%02x", wintab[i++]);
+ j++;
+ if (i >= 128)
+ break;
+ printf(", ");
+ }
+ printf("\n");
+ }
+ printf("};\n");
+}