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!
27 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
29 VOID
CompleteFilename (LPTSTR str
, INT charcount
)
36 BOOL found_dot
= FALSE
;
37 BOOL perfectmatch
= TRUE
;
39 TCHAR fname
[MAX_PATH
];
40 TCHAR maxmatch
[MAX_PATH
] = _T("");
41 TCHAR directory
[MAX_PATH
];
43 /* expand current file name */
44 count
= charcount
- 1;
48 /* find front of word */
49 while (count
> 0 && str
[count
] != _T(' '))
52 /* if not at beginning, go forward 1 */
53 if (str
[count
] == _T(' '))
58 /* extract directory from word */
59 _tcscpy (directory
, &str
[start
]);
60 curplace
= _tcslen (directory
) - 1;
61 while (curplace
>= 0 && directory
[curplace
] != _T('\\') &&
62 directory
[curplace
] != _T(':'))
64 directory
[curplace
] = 0;
68 _tcscpy (path
, &str
[start
]);
70 /* look for a '.' in the filename */
71 for (count
= _tcslen (directory
); path
[count
] != _T('\0'); count
++)
73 if (path
[count
] == _T('.'))
81 _tcscat (path
, _T("*"));
83 _tcscat (path
, _T("*.*"));
88 hFile
= FindFirstFile (path
, &file
);
89 if (hFile
!= INVALID_HANDLE_VALUE
)
94 /* ignore "." and ".." */
95 if (!_tcscmp (file
.cFileName
, _T(".")) ||
96 !_tcscmp (file
.cFileName
, _T("..")))
99 _tcscpy (fname
, file
.cFileName
);
101 if (file
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
102 _tcscat (fname
, _T("\\"));
104 _tcscat (fname
, _T(" "));
106 if (!maxmatch
[0] && perfectmatch
)
108 _tcscpy(maxmatch
, fname
);
112 for (count
= 0; maxmatch
[count
] && fname
[count
]; count
++)
114 if (tolower(maxmatch
[count
]) != tolower(fname
[count
]))
116 perfectmatch
= FALSE
;
123 while (FindNextFile (hFile
, &file
));
127 _tcscpy (&str
[start
], directory
);
128 _tcscat (&str
[start
], maxmatch
);
150 * returns 1 if at least one match, else returns 0
153 BOOL
ShowCompletionMatches (LPTSTR str
, INT charcount
)
155 WIN32_FIND_DATA file
;
157 BOOL found_dot
= FALSE
;
161 TCHAR path
[MAX_PATH
];
162 TCHAR fname
[MAX_PATH
];
163 TCHAR directory
[MAX_PATH
];
165 /* expand current file name */
166 count
= charcount
- 1;
170 /* find front of word */
171 while (count
> 0 && str
[count
] != _T(' '))
174 /* if not at beginning, go forward 1 */
175 if (str
[count
] == _T(' '))
180 /* extract directory from word */
181 _tcscpy (directory
, &str
[start
]);
182 curplace
= _tcslen (directory
) - 1;
183 while (curplace
>= 0 &&
184 directory
[curplace
] != _T('\\') &&
185 directory
[curplace
] != _T(':'))
187 directory
[curplace
] = 0;
191 _tcscpy (path
, &str
[start
]);
193 /* look for a . in the filename */
194 for (count
= _tcslen (directory
); path
[count
] != _T('\0'); count
++)
196 if (path
[count
] == _T('.'))
204 _tcscat (path
, _T("*"));
206 _tcscat (path
, _T("*.*"));
211 hFile
= FindFirstFile (path
, &file
);
212 if (hFile
!= INVALID_HANDLE_VALUE
)
215 ConOutChar (_T('\n'));
219 /* ignore . and .. */
220 if (!_tcscmp (file
.cFileName
, _T(".")) ||
221 !_tcscmp (file
.cFileName
, _T("..")))
224 if (file
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
225 wsprintf (fname
,"[%s]", file
.cFileName
);
227 _tcscpy (fname
, file
.cFileName
);
229 ConOutPrintf (_T("%-14s"), fname
);
232 ConOutChar (_T('\n'));
236 while (FindNextFile (hFile
, &file
));
241 ConOutChar (_T('\n'));
258 #ifdef FEATURE_4NT_FILENAME_COMPLETION
260 //static VOID BuildFilenameMatchList (...)
262 // VOID CompleteFilenameNext (LPTSTR, INT)
263 // VOID CompleteFilenamePrev (LPTSTR, INT)
265 // VOID RemoveFilenameMatchList (VOID)