Use for loops for recursion in the Windows build, cutting down on the
[krb5.git] / src / config / ren2long.awk
1 #
2 # Awk script to convert filenames shortened down to 8.3 
3 # back to their larger size. 
4 #
5 # Works by looking at every filename and seeing if it's shortened
6 # 8.3 version exists, and if so then mv the short name to the long
7 # name.
8 #
9 # Usage: find . -type f -print | gawk -f ren2long.awk | sh -x [ 2> /dev/null ]
10 #
11
12
13 # Parse_path
14 #
15 # Takes the whole path and converts the basename part to 8.3. If it
16 # changed in the process we emit a sh command to mv it if the shortened
17 # name exists.
18
19 function parse_path(p,P2,N,NEW) {
20
21      P2 = tolower(p)
22
23      NEW = ""
24      while(1) {
25           N = index(P2,"/")                     # Go until all / are parsed
26           if (N == 0) break
27
28           NEW = NEW name83(substr(P2,1,N-1)) "/"; # More of the path
29           P2 = substr(P2,N+1)
30      }
31
32      if (bad[P2] == 1) {
33           print "echo skipping " p
34           return
35      }
36      NEW = NEW name83(P2)                       # Append path and 8.3 name
37
38      if (bad[P2] == 2) {
39           print "if [ -f " NEW " ]; then echo ::rm " NEW " ; rm " NEW " ; fi"
40           return
41      }
42      if (NEW != p) 
43           print "if [ -f " NEW " ]; then echo ::mv " NEW " " p " ; mv " NEW " " p " ; fi"
44 }
45 #
46 # Name83
47
48 # Converts the a single component part of a file name into 8.3 format
49 #
50 function name83(fname,P,B,E) {
51      P = index(fname,".");                      # Find the extension
52
53      if (P == 0) {                              # No extension
54           B = substr(fname,1,8);                # Just truncate at 8 chars
55           return B;
56     }
57
58     B = substr(fname, 1, P <= 8 ? P-1 : 8);     # At most 8 chars in name
59     E = substr(fname, P+1, 3)                   # And 3 in extension
60     P = index(E, ".")                           # 2 dot problem
61     if (P)
62          E = substr(E, 1, P-1)
63
64      B = B "." E                                # Put name together
65      return B
66 }
67 BEGIN {
68      bad["krb5-types-aux.h"] = 1
69      bad["autoconf.h.in"] = 1
70      bad["conv_tkt_skey.c"] = 1
71      ##bad["makefile"] = 2 -- windows have legitimate files with this name
72 }
73 {
74      parse_path($1)                             # Do it
75 }