ze-filter  (ze-filter-0.8.0-develop-180218)
ze-convert-8to7.c
Go to the documentation of this file.
1 /*
2  *
3  * ze-filter - Mail Server Filter for sendmail
4  *
5  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
6  *
7  * Auteur : Jose Marcio Martins da Cruz
8  * jose.marcio.mc@gmail.org
9  *
10  * Historique :
11  * Creation : Mon Sep 25 10:15:07 CEST 2006
12  *
13  * This program is free software, but with restricted license :
14  *
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  * More details about ze-filter license can be found at ze-filter
21  * web site : http://foss.jose-marcio.org
22  */
23 
24 
25 #include <ze-sys.h>
26 #include <ze-filter.h>
27 #include <ze-convert-8to7.h>
28 
29 /* ****************************************************************************
30  * *
31  * *
32  **************************************************************************** */
33 void
34 convert_8to7(buf, convert_blanks)
35  char *buf;
36  bool convert_blanks;
37 {
38  char *p, *q;
39  int nUnderscore = 0;
40 
41  int pc = '\0', nc = 0;
42 
43  for (p = q = buf; *p != '\0'; p++)
44  {
45  int c = *((unsigned char *) p);
46 
47  /* This is general... */
48  if (c == pc)
49  {
50  nc++;
51  if (nc > 10 && !isdigit(c))
52  continue;
53  } else
54  {
55  nc = 0;
56  pc = c;
57  }
58 
59  /* this is only for _ (underscore) */
60  if (c == '_')
61  nUnderscore++;
62  else
63  nUnderscore = 0;
64 
65  if (nUnderscore > 3)
66  continue;
67 
68  if (*p == 0x1B)
69  {
70  continue;
71  }
72 
73  if (c < 0x20)
74  {
75  if (*p == '\n' || *p == '\r' || *p == '\t')
76  {
77  if (convert_blanks)
78  *q++ = ' ';
79  else
80  *q++ = *p;
81  continue;
82  }
83 
84  if (1)
85  *q++ = ' ';
86  continue;
87  }
88 
89  if (c > 0x7F)
90  {
91 #define CHR_128_159 "________________________________"
92 #define CHR_160_191 "________________________________"
93 #define CHR_192_223 "AAAAAAACEEEEIIIIGNOOOOOxOUUUUYPB"
94 #define CHR_224_255 "aaaaaaaceeeeiiiionooooo-ouuuuyby";
95 
97 
98  c -= 0x80;
99  if (c > 0 && c < sizeof (s))
100  *q++ = s[c];
101  continue;
102  }
103 
104  *q++ = *p;
105  }
106  *q = '\0';
107 }
108 
109 
110 /* ****************************************************************************
111  * *
112  * *
113  **************************************************************************** */
114 void
116  char *buf;
117 {
118  char *p, *q;
119 
120  ASSERT(buf != NULL);
121 
122  for (p = q = buf; *p != '\0'; p++)
123  {
124  int c = *((unsigned char *) p);
125 
126  if (*p == 0x1B)
127  continue;
128 
129  if (c < 0x20)
130  {
131  *q++ = '_';
132  continue;
133  }
134 
135  if (c > 0x7F)
136  {
137 #define CHR_128_159 "________________________________"
138 #define CHR_160_191 "________________________________"
139 #define CHR_192_223 "AAAAAAACEEEEIIIIGNOOOOOxOUUUUYPB"
140 #define CHR_224_255 "aaaaaaaceeeeiiiionooooo-ouuuuyby";
141 
143 
144  c -= 0x80;
145  if (c > 0 && c < sizeof (s))
146  *q++ = s[c];
147  continue;
148  }
149 
150  *q++ = *p;
151  }
152  *q = '\0';
153 }
#define ASSERT(a)
Definition: macros.h:27
#define CHR_192_223
void convert_8to7(char *buf, bool convert_blanks)
#define CHR_128_159
#define CHR_224_255
void convert_filename_8to7(char *buf)
#define CHR_160_191