2 * $Id: adv1tov2.c,v 1.3 2001-06-29 14:14:46 rufustfirefly Exp $
3 * v1tov2: given a root directory, run down and convert all the
4 * files/directories into appledouble v2.
9 #endif /* HAVE_CONFIG_H */
16 #endif /* HAVE_FCNTL_H */
19 #endif /* HAVE_UNISTD_H */
21 #include <sys/types.h>
23 #include <sys/param.h>
25 #include <atalk/adouble.h>
27 #if AD_VERSION == AD_VERSION2
28 /* translate characters */
29 static int xlate(char *name, int flags) {
30 static const char hexdig[] = "0123456789abcdef";
31 char upath[MAXPATHLEN + 1];
38 if (isascii(*m) && !isprint(*m)) {
41 *u++ = hexdig[(*m & 0xf0) >> 4];
42 *u++ = hexdig[*m & 0x0f];
51 if ((flags & ADFLAGS_DIR) == 0)
52 rename(ad_path(name, flags), ad_path(upath, flags)); /* rename rfork */
57 #define MAXDESCEND 0xFFFF
58 /* recursively descend subdirectories.
59 * oh the stack space we use up! */
70 if (count++ > MAXDESCEND) {
71 fprintf(stderr, "FAILURE: too many subdirectories! possible infinite recursion.");
76 for (de = readdir(dp); de; de = readdir(dp)) {
77 if (de->d_name[0] == '.')
80 if (stat(de->d_name, &st) < 0) {
81 fprintf(stderr, "FAILURE: can't stat %s\n", de->d_name);
85 /* go down subdirectory */
87 if (S_ISDIR(st.st_mode) && (dpnew = opendir(de->d_name))) {
95 if (ad_open(de->d_name, flags, O_RDWR, 0, &ad) < 0) {
96 fprintf(stderr, "FAILURE: can't convert %s\n", de->d_name);
99 ad_close(&ad, ADFLAGS_HF);
100 xlate(de->d_name, flags);
107 int main(int argc, char **argv)
113 fprintf(stderr, "%s <directory>\n", *argv);
117 /* convert main directory */
118 if (ad_open(argv[1], ADFLAGS_HF | ADFLAGS_DIR, O_RDWR, 0,
120 fprintf(stderr, "FAILURE: can't convert %s\n", argv[1]);
124 ad_close(&ad, ADFLAGS_HF);
125 if ((dp = opendir(argv[1])) == NULL) {
126 fprintf(stderr, "%s: unable to open %s\n", *argv, argv[1]);
135 xlate(argv[1], ADFLAGS_HF | ADFLAGS_DIR);
140 #else /* AD_VERSION == AD_VERSION2 */
141 int main(int argc, char **argv)
143 fprintf(stderr, "%s not built for v2 AppleDouble files.\n", *argv);
146 #endif /* AD_VERSION == AD_VERSION2 */