2 * FILECOMP.C - handles filename completion.
7 * 30-Jul-1998 (John P Price <linux-guru@gcfl.net>)
8 * moved from command.c file
9 * made second TAB display list of filename matches
10 * made filename be lower case if last character typed is lower case
12 * 25-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
13 * Cleanup. Unicode safe!
16 #define WIN32_LEAN_AND_MEAN
28 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
30 VOID
CompleteFilename (LPTSTR str
, INT charcount
)
38 BOOL found_dot
= FALSE
;
39 BOOL perfectmatch
= TRUE
;
41 TCHAR fname
[MAX_PATH
];
42 TCHAR maxmatch
[MAX_PATH
] = _T("");
43 TCHAR directory
[MAX_PATH
];
45 /* expand current file name */
46 count
= charcount
- 1;
50 /* find front of word */
51 while (count
> 0 && str
[count
] != _T(' '))
54 /* if not at beginning, go forward 1 */
55 if (str
[count
] == _T(' '))
60 /* extract directory from word */
61 _tcscpy (directory
, &str
[start
]);
62 curplace
= _tcslen (directory
) - 1;
63 while (curplace
>= 0 && directory
[curplace
] != _T('\\') &&
64 directory
[curplace
] != _T(':'))
66 directory
[curplace
] = 0;
70 _tcscpy (path
, &str
[start
]);
72 /* look for a '.' in the filename */
73 for (count
= _tcslen (directory
); path
[count
] != 0; count
++)
75 if (path
[count
] == _T('.'))
83 _tcscat (path
, _T("*"));
85 _tcscat (path
, _T("*.*"));
90 hFile
= FindFirstFile (path
, &file
);
91 if (hFile
!= INVALID_HANDLE_VALUE
)
96 /* ignore "." and ".." */
97 if (file
.cFileName
[0] == _T('.'))
100 _tcscpy (fname
, file
.cFileName
);
102 if (file
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
103 _tcscat (fname
, _T("\\"));
105 _tcscat (fname
, _T(" "));
107 if (!maxmatch
[0] && perfectmatch
)
109 _tcscpy(maxmatch
, fname
);
113 for (count
= 0; maxmatch
[count
] && fname
[count
]; count
++)
115 if (tolower(maxmatch
[count
]) != tolower(fname
[count
]))
117 perfectmatch
= FALSE
;
124 while (FindNextFile (hFile
, &file
));
128 _tcscpy (&str
[start
], directory
);
129 _tcscat (&str
[start
], maxmatch
);
143 * returns 1 if at least one match, else returns 0
146 BOOL
ShowCompletionMatches (LPTSTR str
, INT charcount
)
148 WIN32_FIND_DATA file
;
150 BOOL found_dot
= FALSE
;
154 TCHAR path
[MAX_PATH
];
155 TCHAR fname
[MAX_PATH
];
156 TCHAR directory
[MAX_PATH
];
158 /* expand current file name */
159 count
= charcount
- 1;
163 /* find front of word */
164 while (count
> 0 && str
[count
] != _T(' '))
167 /* if not at beginning, go forward 1 */
168 if (str
[count
] == _T(' '))
173 /* extract directory from word */
174 _tcscpy (directory
, &str
[start
]);
175 curplace
= _tcslen (directory
) - 1;
176 while (curplace
>= 0 && directory
[curplace
] != _T('\\') &&
177 directory
[curplace
] != _T(':'))
179 directory
[curplace
] = 0;
183 _tcscpy (path
, &str
[start
]);
185 /* look for a . in the filename */
186 for (count
= _tcslen (directory
); path
[count
] != 0; count
++)
188 if (path
[count
] == _T('.'))
195 _tcscat (path
, _T("*"));
197 _tcscat (path
, _T("*.*"));
202 hFile
= FindFirstFile (path
, &file
);
203 if (hFile
!= INVALID_HANDLE_VALUE
)
206 ConOutChar (_T('\n'));
210 /* ignore . and .. */
211 if (file
.cFileName
[0] == _T('.'))
214 if (file
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
215 wsprintf (fname
,"[%s]", file
.cFileName
);
217 _tcscpy (fname
, file
.cFileName
);
219 ConOutPrintf (_T("%-14s"), fname
);
222 ConOutChar (_T('\n'));
226 while (FindNextFile (hFile
, &file
));
231 ConOutChar (_T('\n'));
244 #ifdef FEATURE_4NT_FILENAME_COMPLETION
246 //static VOID BuildFilenameMatchList (...)
248 // VOID CompleteFilenameNext (LPTSTR, INT)
249 // VOID CompleteFilenamePrev (LPTSTR, INT)
251 // VOID RemoveFilenameMatchList (VOID)