Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/pax/convert.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1987-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Bell Laboratories
24
*
25
* pax conversion support
26
*/
27
28
#include "pax.h"
29
30
/*
31
* set char code conversion for section
32
*/
33
34
void
35
convert(Archive_t* ap, int section, int from, int to)
36
{
37
if (ap->convert[section].on = (ap->convert[section].f2t = ccmap(from, to)) != 0)
38
{
39
ap->convert[section].t2f = ccmap(to, from);
40
ap->convert[section].f2a = ccmap(from, CC_ASCII);
41
ap->convert[section].t2a = ccmap(to, CC_ASCII);
42
}
43
}
44
45
/*
46
* convert string to lower case in place
47
*/
48
49
char*
50
strlower(register char* s)
51
{
52
register int c;
53
register char* t;
54
55
for (t = s; c = *t; t++)
56
if (isupper(c))
57
*t = tolower(c);
58
return s;
59
}
60
61
/*
62
* convert string to upper case in place
63
*/
64
65
char*
66
strupper(register char* s)
67
{
68
register int c;
69
register char* t;
70
71
for (t = s; c = *t; t++)
72
if (islower(c))
73
*t = toupper(c);
74
return s;
75
}
76
77
/*
78
* return 1 if s is a portable string
79
*/
80
81
int
82
portable(Archive_t* ap, const char* s)
83
{
84
register unsigned char* u = (unsigned char*)s;
85
register unsigned char* m;
86
register int c;
87
88
if (!ap->convert[SECTION_CONTROL].on)
89
{
90
while (c = *u++)
91
if (c > 0177)
92
return 0;
93
}
94
else
95
{
96
m = ap->convert[SECTION_CONTROL].f2t;
97
while (c = m[*u++])
98
if (c > 0177)
99
return 0;
100
}
101
return 1;
102
}
103
104
/*
105
* this is an obsolete version of the ast library implementation
106
*/
107
108
#undef OHASHPART
109
#define OHASHPART(b,h,c,l,r) (h = ((h = ((unsigned)h << (l)) ^ (h >> (r)) ^ (c)) & ((unsigned)1 << (b)) ? ~h : h) & (((((unsigned)1 << ((b) - 1)) - 1) << 2) | 3))
110
111
#undef OHASHLPART
112
#define OHASHLPART(h,c) OHASHPART(31, h, c, 3, 2)
113
114
unsigned long
115
omemsum(const void* b, int n, register unsigned long c)
116
{
117
register unsigned char* p;
118
register unsigned char* e;
119
120
p = (unsigned char*)b;
121
e = p + n;
122
while (p < e) OHASHLPART(c, *p++ + 1);
123
return c;
124
}
125
126