/[pg_recode]/recode.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /recode.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (vendor branch)
Sat Mar 18 21:47:50 2000 UTC (19 years, 5 months ago) by dpavlin
Branch: DbP, MAIN
CVS Tags: beta, HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/plain
početni import

1 dpavlin 1.1 /*****************************************************************************
2     * recode.c
3     * 2000-03-04 Dobrica Pavlinusic <dpavlin@rot13.org>
4     * first really working version which doesn't overwrite chars which are
5     * in PostgreSQL buffer (I should really read examples more carefully!)
6     * 2000-03-17 dpavlin added to88592 function
7     * 2000-03-18 dpavlin added initcap2 function
8     *****************************************************************************/
9    
10     #include <string.h>
11     #include <stdio.h>
12     #include "postgres.h" /* for char16, etc. */
13     #include "utils/palloc.h" /* for palloc */
14     #include "libpq-fe.h" /* for TUPLE */
15     #include <stdio.h>
16     #include <ctype.h>
17    
18     /* to1250 -- convert iso8859-2 chars to cp1250 */
19    
20     text *
21     to1250(text *t)
22     {
23     int32 i;
24     char c;
25     text *new_t = (text *) palloc(VARSIZE(t));
26     memset(new_t, 0, VARSIZE(t));
27     VARSIZE(new_t) = VARSIZE(t);
28    
29     for(i=0; i<=VARSIZE(t)-VARHDRSZ; i++) {
30     c=VARDATA(t)[i];
31     switch (c) {
32     case (char)0xa9: c=(char)0x8a; break;
33     case (char)0xb9: c=(char)0x9a; break;
34     case (char)0xae: c=(char)0x8e; break;
35     case (char)0xbe: c=(char)0x9e; break;
36     }
37     VARDATA(new_t)[i]=c;
38     }
39    
40     return (new_t);
41     }
42    
43     /* to88592 -- convert cp1250 to iso8859-2 chars */
44    
45     text *
46     to88592(text *t)
47     {
48     int32 i;
49     char c;
50     text *new_t = (text *) palloc(VARSIZE(t));
51     memset(new_t, 0, VARSIZE(t));
52     VARSIZE(new_t) = VARSIZE(t);
53    
54     for(i=0; i<=VARSIZE(t)-VARHDRSZ; i++) {
55     c=VARDATA(t)[i];
56     switch (c) {
57     case (char)0x8a: c=(char)0xa9; break;
58     case (char)0x9a: c=(char)0xb9; break;
59     case (char)0x8e: c=(char)0xae; break;
60     case (char)0x9e: c=(char)0xbe; break;
61     }
62     VARDATA(new_t)[i]=c;
63     }
64    
65     return (new_t);
66     }
67    
68     /* tocsz -- convert iso8859-2 or cp1250 to czs */
69    
70     text *
71     toczs(text *t)
72     {
73     int32 i;
74     char c;
75     text *new_t = (text *) palloc(VARSIZE(t));
76     memset(new_t, 0, VARSIZE(t));
77     VARSIZE(new_t) = VARSIZE(t);
78    
79     for(i=0; i<=VARSIZE(t)-VARHDRSZ; i++) {
80     c=VARDATA(t)[i];
81     switch (c) {
82     /* iso8859-2 */
83     case (char)0xa9: c=(char)'S'; break;
84     case (char)0xb9: c=(char)'s'; break;
85     case (char)0xd0: c=(char)'D'; break;
86     case (char)0xf0: c=(char)'d'; break;
87     case (char)0xc8: c=(char)'C'; break;
88     case (char)0xe8: c=(char)'c'; break;
89     case (char)0xc6: c=(char)'C'; break;
90     case (char)0xe6: c=(char)'c'; break;
91     case (char)0xae: c=(char)'Z'; break;
92     case (char)0xbe: c=(char)'z'; break;
93     /* cp1250 */
94     case (char)0x8a: c=(char)'S'; break;
95     case (char)0x9a: c=(char)'s'; break;
96     case (char)0x8e: c=(char)'Z'; break;
97     case (char)0x9e: c=(char)'z'; break;
98     }
99     VARDATA(new_t)[i]=c;
100     }
101    
102     return (new_t);
103     }
104    
105     /* initcap2 -- initcap whith support for iso8859-2 or cp1250 */
106    
107     text *
108     initcap2(text *t)
109     {
110     int32 i;
111     char c;
112     int first = 1; /* is this a first letter? */
113     text *new_t = (text *) palloc(VARSIZE(t));
114     memset(new_t, 0, VARSIZE(t));
115     VARSIZE(new_t) = VARSIZE(t);
116    
117     for(i=0; i<=VARSIZE(t)-VARHDRSZ; i++) {
118     c=VARDATA(t)[i];
119     if (first) {
120     if (c >=(char)'a' && c <= (char)'z') { c-=32; }
121     switch (c) {
122     /* iso8859-2 */
123     case (char)0xb9: c-=16; break;
124     case (char)0xf0: c-=32; break;
125     case (char)0xe8: c-=32; break;
126     case (char)0xe6: c-=32; break;
127     case (char)0xbe: c-=16; break;
128     /* cp1250 */
129     case (char)0x9a: c-=16; break;
130     case (char)0x9e: c-=16; break;
131     }
132     }
133     if (!first) {
134     if (c >='A' && c <= 'Z') { c+=32; }
135     switch (c) {
136     /* iso8859-2 */
137     case (char)0xa9: c+=16; break;
138     case (char)0xd0: c+=32; break;
139     case (char)0xc8: c+=32; break;
140     case (char)0xc6: c+=32; break;
141     case (char)0xae: c+=16; break;
142     /* cp1250 */
143     case (char)0x8a: c+=16; break;
144     case (char)0x8e: c+=16; break;
145     }
146     }
147     if (c == ' ' || c == '-' || c =='.') first = 1; else first = 0;
148     VARDATA(new_t)[i]=c;
149     }
150    
151     return (new_t);
152     }
153    

  ViewVC Help
Powered by ViewVC 1.1.26