1295d917880de7187627b0a82357432a014b5784
[feisty_meow.git] / nucleus / tools / clam_tools / cygwin_fixer.cpp
1 //need header here.
2
3 // make ms be quiet about strncat.
4 #define _CRT_SECURE_NO_WARNINGS
5
6 #ifdef _MSC_VER
7 #include <io.h>
8 #else
9 #include <unistd.h>
10 #endif
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 // turns the cygwin name format into a usable windos filename.
16 char *translate_cygwin(char *fname)
17 {
18   int oldlen = strlen(fname);
19   if (!strncmp(fname, "/cygdrive/", 10) && (oldlen > 10) ) {
20     // in the first case the filename has /cygdrive in it, right at the front.
21     char *newprefix = (char *)malloc(oldlen);
22     // build the drive letter first.
23     newprefix[0] = fname[10];
24     newprefix[1] = ':';
25     newprefix[2] = '\0';
26     // concatenate the filename without cygdrive in it.
27     strncat(newprefix, fname + 11, oldlen - 11 + 1);  // one extra for null char.
28     return newprefix;  // mem leak here; cannot be helped for quick fix using functional style.
29   } else if ( (fname[0] == '-') && (oldlen > 12)
30       && (!strncmp(fname + 2, "/cygdrive/", 10)) ) {
31     // in the second case we are looking for command line options.  this code handles a parameter
32     // that starts with a single dash and has a single flag character after that.
33     char *newprefix = (char *)malloc(oldlen);
34     newprefix[0] = fname[0];
35     newprefix[1] = fname[1];
36     newprefix[2] = fname[12];
37     newprefix[3] = ':';
38     newprefix[4] = '\0';
39     // now concatenate the useful filename portion, offset by the flag found.
40     strncat(newprefix, fname + 13, oldlen - 13 + 1);  // one extra for null char.
41     return newprefix;
42   } else {
43     return fname;
44   }
45 }
46
47
48 /*
49
50 function dossify_and_run_commands()
51 {
52
53
54   declare -a darc_commands=()
55   for i in "$@"; do
56     // we only mess with the command line on windows.
57     if [ "$OS" == "Windows_NT" ]; then
58       if [[ "$i" =~ ^-[a-zA-z][/\"].* ]]; then
59 #echo matched on our pattern for parameters
60         flag="${i:0:2}"
61         filename="$(unix_to_dos_path ${i:2})"
62
63 #echo "first two chars are $flag"
64 #echo "last after that are $filename"
65 #combined="$flag$filename"
66 #echo combined is $combined
67       
68         darc_commands+=("$flag$filename")
69       else 
70         darc_commands+=($(unix_to_dos_path $i))
71       fi
72     else
73       darc_commands+=("$i")
74     fi
75   done
76
77 }
78
79 */
80
81 int main(int argc, char *argv[])
82 {
83   for (int i = 1; i < argc; i++) {
84     printf("%s", translate_cygwin(argv[i]));
85   }
86   return 0;
87 }
88