[flexi-streams-devel] koi8-r

Igor Plekhov penguin at ocean.vvo.ru
Tue Oct 31 04:17:51 UTC 2006


Attached is a patch that implements KOI8-R codepage support in
flexi-streams 0.6.6.  KOI8-R codepage is traditionally used in
russian unix environment.

It is described at
http://unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT


--
Registered Linux User #124759
-------------- next part --------------
diff -Nur flexi-streams-0.6.6/external-format.lisp flexi-streams-0.6.6-koi8-r/external-format.lisp
--- flexi-streams-0.6.6/external-format.lisp	2006-09-24 07:47:06.000000000 +1100
+++ flexi-streams-0.6.6-koi8-r/external-format.lisp	2006-10-31 13:35:50.000000000 +1000
@@ -64,6 +64,7 @@
   (let* ((real-name (normalize-external-format-name name))
          (initargs
           (cond ((or (iso-8859-name-p real-name)
+		     (koi8-r-name-p real-name)
                      (ascii-name-p real-name))
                  (list :eol-style (or eol-style *default-eol-style*)))
                 ((code-page-name-p real-name)
@@ -109,6 +110,7 @@
          ;; for non-8-bit encodings the endianess must be the same
          (or code-page-name-p
              (ascii-name-p name1)
+	     (koi8-r-name-p name1)
              (iso-8859-name-p name1)
              (eq name1 :utf-8)
              (eq (not (external-format-little-endian ef1))
@@ -126,6 +128,7 @@
           (eol-style (external-format-eol-style object)))
       (prin1
        (cond ((or (ascii-name-p name)
+		  (koi8-r-name-p name)
                   (iso-8859-name-p name)
                   (eq name :utf-8))
               (list name :eol-style eol-style))
diff -Nur flexi-streams-0.6.6/flexi-streams.asd flexi-streams-0.6.6-koi8-r/flexi-streams.asd
--- flexi-streams-0.6.6/flexi-streams.asd	2006-10-06 22:55:22.000000000 +1100
+++ flexi-streams-0.6.6-koi8-r/flexi-streams.asd	2006-10-31 13:37:39.000000000 +1000
@@ -32,6 +32,7 @@
   :serial t
   :components ((:file "packages")
                (:file "ascii")
+	       (:file "koi8-r")
                (:file "iso-8859")
                (:file "code-pages")
                (:file "specials")
diff -Nur flexi-streams-0.6.6/input.lisp flexi-streams-0.6.6-koi8-r/input.lisp
--- flexi-streams-0.6.6/input.lisp	2006-10-06 22:49:27.000000000 +1100
+++ flexi-streams-0.6.6-koi8-r/input.lisp	2006-10-31 13:40:54.000000000 +1000
@@ -235,6 +235,8 @@
 handle line endings."
              (cond ((ascii-name-p external-format-name)
                     (read-char-8-bit stream +ascii-table+))
+		   ((koi8-r-name-p external-format-name)
+                    (read-char-8-bit stream +koi8-r-table+))
                    ((iso-8859-name-p external-format-name)
                     (read-char-8-bit stream
                                      (cdr (assoc external-format-name +iso-8859-tables+
diff -Nur flexi-streams-0.6.6/koi8-r.lisp flexi-streams-0.6.6-koi8-r/koi8-r.lisp
--- flexi-streams-0.6.6/koi8-r.lisp	1970-01-01 10:00:00.000000000 +1000
+++ flexi-streams-0.6.6-koi8-r/koi8-r.lisp	2006-10-31 13:25:43.000000000 +1000
@@ -0,0 +1,6 @@
+(in-package :flexi-streams)
+
+;; http://unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT
+(defvar +koi8-r-table+
+  #(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 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 9472 9474 9484 9488 9492 9496 9500 9508 9516 9524 9532 9600 9604 9608 9612 9616 9617 9618 9619 8992 9632 8729 8730 8776 8804 8805 160 8993 176 178 183 247 9552 9553 9554 1105 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 1025 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 169 1102 1072 1073 1094 1076 1077 1092 1075 1093 1080 1081 1082 1083 1084 1085 1086 1087 1103 1088 1089 1090 1091 1078 1074 1100 1099 1079 1096 1101 1097 1095 1098 1070 1040 1041 1062 1044 1045 1060 1043 1061 1048 1049 1050 1051 1052 1053 1054 1055 1071 1056 1057 1058 1059 1046 1042 1068 1067 1047 1064 1069 1065 1063 1066)
+    "An array enumerating the character codes for the KOI8-R encoding.")
diff -Nur flexi-streams-0.6.6/output.lisp flexi-streams-0.6.6-koi8-r/output.lisp
--- flexi-streams-0.6.6/output.lisp	2006-10-06 18:07:57.000000000 +1100
+++ flexi-streams-0.6.6-koi8-r/output.lisp	2006-10-31 13:42:53.000000000 +1000
@@ -45,6 +45,10 @@
   "A hash table which maps US-ASCII character codes to the
 corresponding octets.")
 
+(defvar +koi8-r-hash+ (invert-table +koi8-r-table+)
+  "A hash table which maps KOI8-R character codes to the
+corresponding octets.")
+
 #-:lispworks
 (defun write-byte* (byte flexi-output-stream)
   "Writes one byte \(octet) to the underlying stream of
@@ -143,6 +147,8 @@
 #\Newline handling."
              (cond ((ascii-name-p external-format-name)
                     (translate-char-8-bit flexi-stream char-code +ascii-hash+))
+		   ((koi8-r-name-p external-format-name)
+                    (translate-char-8-bit flexi-stream char-code +koi8-r-hash+))
                    ((iso-8859-name-p external-format-name)
                     (translate-char-8-bit flexi-stream char-code
                                           (cdr (assoc external-format-name
diff -Nur flexi-streams-0.6.6/specials.lisp flexi-streams-0.6.6-koi8-r/specials.lisp
--- flexi-streams-0.6.6/specials.lisp	2006-08-11 01:47:03.000000000 +1100
+++ flexi-streams-0.6.6-koi8-r/specials.lisp	2006-10-31 13:46:08.000000000 +1000
@@ -43,6 +43,7 @@
     (:ucs4 . :utf-32)
     (:ucs-4 . :utf-32)
     (:ascii . :us-ascii)
+    (:koi8r . :koi8-r)
     (:latin-1 . :iso-8859-1)
     (:latin1 . :iso-8859-1)
     (:latin-2 . :iso-8859-2)
diff -Nur flexi-streams-0.6.6/util.lisp flexi-streams-0.6.6-koi8-r/util.lisp
--- flexi-streams-0.6.6/util.lisp	2006-06-30 00:34:00.000000000 +1100
+++ flexi-streams-0.6.6-koi8-r/util.lisp	2006-10-31 13:31:36.000000000 +1000
@@ -115,6 +115,10 @@
   "Checks whether NAME is the keyword :ASCII."
   (eq name :us-ascii))
 
+(defun koi8-r-name-p (name)
+  "Checks whether NAME is the keyword :KOI8-R."
+  (eq name :koi8-r))
+
 (defun code-page-name-p (name)
   "Checks whether NAME is the keyword :CODE-PAGE."
   (eq name :code-page))


More information about the Flexi-streams-devel mailing list