File: io.c

package info (click to toggle)
zh-autoconvert 0.3.16-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 3,612 kB
  • sloc: ansic: 28,053; perl: 264; makefile: 84; python: 9
file content (58 lines) | stat: -rw-r--r-- 1,795 bytes parent folder | download | duplicates (2)
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
/*
AutoConvert, a Chinese HZ/GB/Big5 encodings auto-converter
Copyright (C) 1999  于广辉  Yu Guanghui <ygh@dlut.edu.cn>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or any
later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA  02111-1307, USA.
*/
/*
 *hack from hztty-2.0(Yongguang ZHANG,1992 COPYRIGHT)
 *by Yu Guanghui <ygh@dlut.edu.cn>
 *1999.10
 */       
//$Header: /home/prog/autoconvert/hzconvert/io.c,v 1.1.1.1 2000/04/19 05:43:32 ygh Exp $
#include "hz.h"

char *hzconvert (s, plen, psaved, dbcvrt)
     char *s;
     int *plen;
     char *psaved;		/* unprocessed char buffer pointer */
     void (*dbcvrt)();		/* 2-byte conversion func for a hanzi */
{
  char *p, *pend;

	if (*plen == 0)
		return (s);
        if (*psaved) {			/* previous buffered char */
                *(--s) = *psaved;	/* put the unprocessed char down */
		(*plen) ++;
		*psaved = 0;		/* clean this char buffer */
        }
	p = s;  pend = s + (*plen);	/* begin/end of the buffer string */
	while (p < pend) {
		if ((*p) & 0x80)	/* hi-bit on: hanzi */
			if (p < pend-1) 	/* not the last one */
				dbcvrt (p++);
			else {			/* the end of string */
				*psaved = *p;	/* save the unprocessed char */
				(*plen) --;
				break;
			}
		p++;
        }
        return (s);
}