1 /*
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Michael Fischbein.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $Id$
37 */
38
39 /*
40 * written by shige <shige@kuis.kyoto-u.ac.jp>
41 */
42
43 #include <stdio.h>
44
samba_cap(char * s)45 int samba_cap(char *s)
46 {
47 char *sp;
48 int i = 0;
49 char tmpnum;
50 char tmp[FILENAME_MAX];
51
52 sp = s;
53
54 while(*s != '\0') {
55 if (*s == ':') {
56 if ('9' >= *(s+1) && *(s+1) >= '0')
57 tmpnum = (*(s+1) - 0x30) * 16;
58 else if ('f' >= *(s+1) && *(s+1) >= 'a')
59 tmpnum = (*(s+1) - 0x60 + 9) * 16;
60 else {
61 tmp[i] = *s;
62 tmp[i+1] = *(s+1);
63 *s = '\0';
64 *(s+1) = '\0';
65 i += 2;
66 s += 2;
67 continue;
68 }
69
70 if ('9' >= *(s+2) && *(s+2) >= '0')
71 tmpnum = (*(s+2) - 0x30) + tmpnum;
72 else if ('f' >= *(s+2) && *(s+2) >= 'a')
73 tmpnum = (*(s+2) - 0x60 + 9) + tmpnum;
74 else {
75 tmp[i] = *s;
76 tmp[i+1] = *(s+1);
77 tmp[i+2] = *(s+2);
78 *s = '\0';
79 *(s+1) = '\0';
80 *(s+2) = '\0';
81 i += 3;
82 s += 3;
83 continue;
84 }
85
86 tmp[i] = tmpnum;
87 *s = '\0';
88 *(s+1) = '\0';
89 *(s+2) = '\0';
90 i++;
91 s += 3;
92 } else {
93 tmp[i] = *s;
94 *s = '\0';
95 i++;
96 s++;
97 }
98 }
99
100 tmp[i] = '\0';
101 strcpy(sp, tmp);
102
103 return 0;
104 }
105
106 #ifdef DEBUG_TEST
main()107 int main()
108 {
109 char *name = ":90V:82:b5:82:a2:83t:83H:83:8b:83_";
110 char new[1024];
111
112 strcpy(new, name);
113 samba_cap(new);
114
115 printf("converted: %s\n", new);
116 return 0;
117 }
118 #endif
119