ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

filecomp.c
Go to the documentation of this file.
00001 /*
00002  *  FILECOMP.C - handles filename completion.
00003  *
00004  *
00005  *  Comments:
00006  *
00007  *    30-Jul-1998 (John P Price <linux-guru@gcfl.net>)
00008  *       moved from command.c file
00009  *       made second TAB display list of filename matches
00010  *       made filename be lower case if last character typed is lower case
00011  *
00012  *    25-Jan-1999 (Eric Kohl)
00013  *       Cleanup. Unicode safe!
00014  *
00015  *    30-Apr-2004 (Filip Navara <xnavara@volny.cz>)
00016  *       Make the file listing readable when there is a lot of long names.
00017  *
00018 
00019  *    05-Jul-2004 (Jens Collin <jens.collin@lakhei.com>)
00020  *       Now expands lfn even when trailing " is omitted.
00021  */
00022 
00023 #include <precomp.h>
00024 
00025 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
00026 
00027 VOID CompleteFilename (LPTSTR str, UINT charcount)
00028 {
00029     WIN32_FIND_DATA file;
00030     HANDLE hFile;
00031     INT   curplace = 0;
00032     INT   start;
00033     INT   count;
00034     INT step;
00035     INT c = 0;
00036     BOOL  found_dot = FALSE;
00037     BOOL  perfectmatch = TRUE;
00038     TCHAR path[MAX_PATH];
00039     TCHAR fname[MAX_PATH];
00040     TCHAR maxmatch[MAX_PATH] = _T("");
00041     TCHAR directory[MAX_PATH];
00042     LPCOMMAND cmds_ptr;
00043 
00044     /* expand current file name */
00045         count = charcount - 1;
00046     if (count < 0)
00047         count = 0;
00048 
00049     /* find how many '"'s there is typed already.*/
00050     step = count;
00051     while (step > 0)
00052     {
00053         if (str[step] == _T('"'))
00054             c++;
00055         step--;
00056     }
00057     /* if c is odd, then user typed " before name, else not.*/
00058 
00059     /* find front of word */
00060     if (str[count] == _T('"') || (c % 2))
00061     {
00062         count--;
00063         while (count > 0 && str[count] != _T('"'))
00064             count--;
00065     }
00066     else
00067     {
00068         while (count > 0 && str[count] != _T(' '))
00069             count--;
00070     }
00071 
00072     /* if not at beginning, go forward 1 */
00073     if (str[count] == _T(' '))
00074         count++;
00075 
00076     start = count;
00077 
00078     if (str[count] == _T('"'))
00079         count++;    /* don't increment start */
00080 
00081     /* extract directory from word */
00082     _tcscpy (directory, &str[count]);
00083     curplace = _tcslen (directory) - 1;
00084 
00085     if (curplace >= 0 && directory[curplace] == _T('"'))
00086         directory[curplace--] = _T('\0');
00087 
00088     _tcscpy (path, directory);
00089 
00090     while (curplace >= 0 && directory[curplace] != _T('\\') &&
00091                    directory[curplace] != _T('/') &&
00092            directory[curplace] != _T(':'))
00093     {
00094         directory[curplace] = 0;
00095         curplace--;
00096     }
00097 
00098     /* look for a '.' in the filename */
00099     for (count = _tcslen (directory); path[count] != _T('\0'); count++)
00100     {
00101         if (path[count] == _T('.'))
00102         {
00103             found_dot = TRUE;
00104             break;
00105         }
00106     }
00107 
00108     if (found_dot)
00109         _tcscat (path, _T("*"));
00110     else
00111         _tcscat (path, _T("*.*"));
00112 
00113     /* current fname */
00114     curplace = 0;
00115 
00116     hFile = FindFirstFile (path, &file);
00117     if (hFile != INVALID_HANDLE_VALUE)
00118     {
00119         /* find anything */
00120         do
00121         {
00122             /* ignore "." and ".." */
00123             if (!_tcscmp (file.cFileName, _T(".")) ||
00124                 !_tcscmp (file.cFileName, _T("..")))
00125                 continue;
00126 
00127             _tcscpy (fname, file.cFileName);
00128 
00129             if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00130                 _tcscat (fname, _T("\\"));
00131 
00132             if (!maxmatch[0] && perfectmatch)
00133             {
00134                 _tcscpy(maxmatch, fname);
00135             }
00136             else
00137             {
00138                 for (count = 0; maxmatch[count] && fname[count]; count++)
00139                 {
00140                     if (tolower(maxmatch[count]) != tolower(fname[count]))
00141                     {
00142                         perfectmatch = FALSE;
00143                         maxmatch[count] = 0;
00144                         break;
00145                     }
00146                 }
00147 
00148                 if (maxmatch[count] == _T('\0') &&
00149                     fname[count] != _T('\0'))
00150                     perfectmatch = FALSE;
00151             }
00152         }
00153         while (FindNextFile (hFile, &file));
00154 
00155         FindClose (hFile);
00156 
00157         /* only quote if the filename contains spaces */
00158         if (_tcschr(directory, _T(' ')) ||
00159             _tcschr(maxmatch, _T(' ')))
00160         {
00161             str[start] = _T('\"');
00162             _tcscpy (&str[start+1], directory);
00163             _tcscat (&str[start], maxmatch);
00164             _tcscat (&str[start], _T("\"") );
00165         }
00166         else
00167         {
00168             _tcscpy (&str[start], directory);
00169             _tcscat (&str[start], maxmatch);
00170         }
00171 
00172         if(!perfectmatch)
00173         {
00174             MessageBeep (-1);
00175         }
00176     }
00177     else
00178     {
00179         /* no match found - search for internal command */
00180         for (cmds_ptr = cmds; cmds_ptr->name; cmds_ptr++)
00181         {
00182             if (!_tcsnicmp (&str[start], cmds_ptr->name,
00183                 _tcslen (&str[start])))
00184             {
00185                 /* return the mach only if it is unique */
00186                 if (_tcsnicmp (&str[start], (cmds_ptr+1)->name, _tcslen (&str[start])))
00187                     _tcscpy (&str[start], cmds_ptr->name);
00188                 break;
00189             }
00190         }
00191 
00192         MessageBeep (-1);
00193     }
00194 }
00195 
00196 
00197 /*
00198  * returns 1 if at least one match, else returns 0
00199  */
00200 
00201 BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
00202 {
00203     WIN32_FIND_DATA file;
00204     HANDLE hFile;
00205     BOOL  found_dot = FALSE;
00206     INT   curplace = 0;
00207     INT   start;
00208     INT   count;
00209     TCHAR path[MAX_PATH];
00210     TCHAR fname[MAX_PATH];
00211     TCHAR directory[MAX_PATH];
00212     SHORT screenwidth;
00213 
00214     /* expand current file name */
00215     count = charcount - 1;
00216     if (count < 0)
00217         count = 0;
00218 
00219     /* find front of word */
00220     if (str[count] == _T('"'))
00221     {
00222         count--;
00223         while (count > 0 && str[count] != _T('"'))
00224             count--;
00225     }
00226     else
00227     {
00228         while (count > 0 && str[count] != _T(' '))
00229             count--;
00230     }
00231 
00232     /* if not at beginning, go forward 1 */
00233     if (str[count] == _T(' '))
00234         count++;
00235 
00236     start = count;
00237 
00238     if (str[count] == _T('"'))
00239         count++;    /* don't increment start */
00240 
00241     /* extract directory from word */
00242     _tcscpy (directory, &str[count]);
00243     curplace = _tcslen (directory) - 1;
00244 
00245     if (curplace >= 0 && directory[curplace] == _T('"'))
00246         directory[curplace--] = _T('\0');
00247 
00248     _tcscpy (path, directory);
00249 
00250     while (curplace >= 0 &&
00251            directory[curplace] != _T('\\') &&
00252            directory[curplace] != _T(':'))
00253     {
00254         directory[curplace] = 0;
00255         curplace--;
00256     }
00257 
00258     /* look for a . in the filename */
00259     for (count = _tcslen (directory); path[count] != _T('\0'); count++)
00260     {
00261         if (path[count] == _T('.'))
00262         {
00263             found_dot = TRUE;
00264             break;
00265         }
00266     }
00267 
00268     if (found_dot)
00269         _tcscat (path, _T("*"));
00270     else
00271         _tcscat (path, _T("*.*"));
00272 
00273     /* current fname */
00274     curplace = 0;
00275 
00276     hFile = FindFirstFile (path, &file);
00277     if (hFile != INVALID_HANDLE_VALUE)
00278     {
00279         UINT longestfname = 0;
00280         /* Get the size of longest filename first. */
00281         do
00282         {
00283             if (_tcslen(file.cFileName) > longestfname)
00284             {
00285                 longestfname = _tcslen(file.cFileName);
00286                 /* Directories get extra brackets around them. */
00287                 if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00288                     longestfname += 2;
00289             }
00290         }
00291         while (FindNextFile (hFile, &file));
00292         FindClose (hFile);
00293 
00294         hFile = FindFirstFile (path, &file);
00295 
00296         /* Count the highest number of columns */
00297         GetScreenSize(&screenwidth, 0);
00298 
00299         /* For counting columns of output */
00300         count = 0;
00301 
00302         /* Increase by the number of spaces behind file name */
00303         longestfname += 3;
00304 
00305         /* find anything */
00306         ConOutChar (_T('\n'));
00307         do
00308         {
00309             /* ignore . and .. */
00310             if (!_tcscmp (file.cFileName, _T(".")) ||
00311                 !_tcscmp (file.cFileName, _T("..")))
00312                 continue;
00313 
00314             if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00315                 _stprintf (fname, _T("[%s]"), file.cFileName);
00316             else
00317                 _tcscpy (fname, file.cFileName);
00318 
00319             ConOutPrintf (_T("%*s"), - longestfname, fname);
00320             count++;
00321             /* output as much columns as fits on the screen */
00322             if (count >= (screenwidth / longestfname))
00323             {
00324                 /* print the new line only if we aren't on the
00325                  * last column, in this case it wraps anyway */
00326                 if (count * longestfname != (UINT)screenwidth)
00327                     ConOutPrintf (_T("\n"));
00328                 count = 0;
00329             }
00330         }
00331         while (FindNextFile (hFile, &file));
00332 
00333         FindClose (hFile);
00334 
00335         if (count)
00336             ConOutChar (_T('\n'));
00337     }
00338     else
00339     {
00340         /* no match found */
00341         MessageBeep (-1);
00342         return FALSE;
00343     }
00344 
00345     return TRUE;
00346 }
00347 #endif
00348 
00349 #ifdef FEATURE_4NT_FILENAME_COMPLETION
00350 
00351 typedef struct _FileName
00352 {
00353     TCHAR Name[MAX_PATH];
00354 } FileName;
00355 
00356 VOID FindPrefixAndSuffix(LPTSTR strIN, LPTSTR szPrefix, LPTSTR szSuffix)
00357 {
00358     /* String that is to be examined */
00359     TCHAR str[MAX_PATH];
00360     /* temp pointers to used to find needed parts */
00361     TCHAR * szSearch;
00362     TCHAR * szSearch1;
00363     TCHAR * szSearch2;
00364     TCHAR * szSearch3;
00365     /* number of quotes in the string */
00366     INT nQuotes = 0;
00367     /* used in for loops */
00368     UINT i;
00369     /* Char number to break the string at */
00370     INT PBreak = 0;
00371     INT SBreak = 0;
00372     /* when phrasing a string, this tells weather
00373        you are inside quotes ot not. */
00374     BOOL bInside = FALSE;
00375 
00376   szPrefix[0] = _T('\0');
00377   szSuffix[0] = _T('\0');
00378 
00379     /* Copy over the string to later be edited */
00380     _tcscpy(str,strIN);
00381 
00382     /* Count number of " */
00383     for(i = 0; i < _tcslen(str); i++)
00384         if(str[i] == _T('\"'))
00385             nQuotes++;
00386 
00387     /* Find the prefix and suffix */
00388     if(nQuotes % 2 && nQuotes >= 1)
00389     {
00390         /* Odd number of quotes.  Just start from the last " */
00391         /* THis is the way MS does it, and is an easy way out */
00392         szSearch = _tcsrchr(str, _T('\"'));
00393         /* Move to the next char past the " */
00394         szSearch++;
00395         _tcscpy(szSuffix,szSearch);
00396         /* Find the one closest to end */
00397         szSearch1 = _tcsrchr(str, _T('\"'));
00398         szSearch2 = _tcsrchr(str, _T('\\'));
00399         szSearch3 = _tcsrchr(str, _T('.'));
00400         if(szSearch2 != NULL && _tcslen(szSearch1) > _tcslen(szSearch2))
00401             szSearch = szSearch2;
00402         else if(szSearch3 != NULL && _tcslen(szSearch1) > _tcslen(szSearch3))
00403             szSearch = szSearch3;
00404         else
00405             szSearch = szSearch1;
00406         /* Move one char past */
00407         szSearch++;
00408     szSearch[0] = _T('\0');
00409         _tcscpy(szPrefix,str);
00410         return;
00411 
00412     }
00413 
00414     if(!_tcschr(str, _T(' ')))
00415     {
00416         /* No spaces, everything goes to Suffix */
00417         _tcscpy(szSuffix,str);
00418         /* look for a slash just in case */
00419         szSearch = _tcsrchr(str, _T('\\'));
00420         if(szSearch)
00421         {
00422             szSearch++;
00423       szSearch[0] = _T('\0');
00424             _tcscpy(szPrefix,str);
00425         }
00426         else
00427         {
00428             szPrefix[0] = _T('\0');
00429         }
00430         return;
00431     }
00432 
00433     if(!nQuotes)
00434     {
00435         /* No quotes, and there is a space*/
00436         /* Take it after the last space */
00437         szSearch = _tcsrchr(str, _T(' '));
00438         szSearch++;
00439         _tcscpy(szSuffix,szSearch);
00440         /* Find the closest to the end space or \ */
00441         _tcscpy(str,strIN);
00442         szSearch1 = _tcsrchr(str, _T(' '));
00443         szSearch2 = _tcsrchr(str, _T('\\'));
00444         szSearch3 = _tcsrchr(str, _T('/'));
00445         if(szSearch2 != NULL && _tcslen(szSearch1) > _tcslen(szSearch2))
00446             szSearch = szSearch2;
00447         else if(szSearch3 != NULL && _tcslen(szSearch1) > _tcslen(szSearch3))
00448             szSearch = szSearch3;
00449         else
00450             szSearch = szSearch1;
00451         szSearch++;
00452     szSearch[0] = _T('\0');
00453         _tcscpy(szPrefix,str);
00454         return;
00455     }
00456 
00457     /* All else fails and there is a lot of quotes, spaces and |
00458        Then we search through and find the last space or \ that is
00459         not inside a quotes */
00460     for(i = 0; i < _tcslen(str); i++)
00461     {
00462         if(str[i] == _T('\"'))
00463             bInside = !bInside;
00464         if(str[i] == _T(' ') && !bInside)
00465             SBreak = i;
00466         if((str[i] == _T(' ') || str[i] == _T('\\')) && !bInside)
00467             PBreak = i;
00468 
00469     }
00470     SBreak++;
00471     PBreak++;
00472     _tcscpy(szSuffix,&strIN[SBreak]);
00473   strIN[PBreak] = _T('\0');
00474     _tcscpy(szPrefix,strIN);
00475     if (szPrefix[_tcslen(szPrefix) - 2] == _T('\"') &&
00476         szPrefix[_tcslen(szPrefix) - 1] != _T(' '))
00477     {
00478         /* need to remove the " right before a \ at the end to
00479            allow the next stuff to stay inside one set of quotes
00480             otherwise you would have multiple sets of quotes*/
00481         _tcscpy(&szPrefix[_tcslen(szPrefix) - 2],_T("\\"));
00482 
00483     }
00484 
00485 }
00486 
00487 int __cdecl compare(const void *arg1,const void *arg2)
00488 {
00489     FileName * File1;
00490     FileName * File2;
00491     INT ret;
00492 
00493     File1 = cmd_alloc(sizeof(FileName));
00494     File2 = cmd_alloc(sizeof(FileName));
00495     if(!File1 || !File2)
00496         return 0;
00497 
00498     memcpy(File1,arg1,sizeof(FileName));
00499     memcpy(File2,arg2,sizeof(FileName));
00500 
00501      /* ret = _tcsicmp(File1->Name, File2->Name); */
00502      ret = lstrcmpi(File1->Name, File2->Name);
00503 
00504     cmd_free(File1);
00505     cmd_free(File2);
00506     return ret;
00507 }
00508 
00509 BOOL
00510 FileNameContainsSpecialCharacters(LPTSTR pszFileName)
00511 {
00512     TCHAR chr;
00513 
00514     while ((chr = *pszFileName++) != _T('\0'))
00515     {
00516         if ((chr == _T(' ')) ||
00517             (chr == _T('!')) ||
00518             (chr == _T('%')) ||
00519             (chr == _T('&')) ||
00520             (chr == _T('(')) ||
00521             (chr == _T(')')) ||
00522             (chr == _T('{')) ||
00523             (chr == _T('}')) ||
00524             (chr == _T('[')) ||
00525             (chr == _T(']')) ||
00526             (chr == _T('=')) ||
00527             (chr == _T('\'')) ||
00528             (chr == _T('`')) ||
00529             (chr == _T(',')) ||
00530             (chr == _T(';')) ||
00531             (chr == _T('^')) ||
00532             (chr == _T('~')) ||
00533             (chr == _T('+')) ||
00534             (chr == 0xB4)) // '´'
00535         {
00536             return TRUE;
00537         }
00538     }
00539 
00540     return FALSE;
00541 }
00542 
00543 
00544 VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor)
00545 {
00546     /* Length of string before we complete it */
00547     INT_PTR StartLength;
00548     /* Length of string after completed */
00549     //INT EndLength;
00550     /* The number of chars added too it */
00551     //static INT DiffLength = 0;
00552     /* Used to find and assemble the string that is returned */
00553     TCHAR szBaseWord[MAX_PATH];
00554     TCHAR szPrefix[MAX_PATH];
00555     TCHAR szOrginal[MAX_PATH];
00556     TCHAR szSearchPath[MAX_PATH];
00557     /* Save the strings used last time, so if they hit tab again */
00558     static TCHAR LastReturned[MAX_PATH];
00559     static TCHAR LastSearch[MAX_PATH];
00560     static TCHAR LastPrefix[MAX_PATH];
00561     /* Used to search for files */
00562     HANDLE hFile;
00563     WIN32_FIND_DATA file;
00564     /* List of all the files */
00565     FileName * FileList = NULL;
00566     /* Number of files */
00567     INT FileListSize = 0;
00568     /* Used for loops */
00569     UINT i;
00570     /* Editable string of what was passed in */
00571     TCHAR str[MAX_PATH];
00572     /* Keeps track of what element was last selected */
00573     static INT Sel;
00574     BOOL NeededQuote = FALSE;
00575     BOOL ShowAll = TRUE;
00576     TCHAR * line = strIN;
00577 
00578     strOut[0] = _T('\0');
00579 
00580     while (_istspace (*line))
00581             line++;
00582     if(!_tcsnicmp (line, _T("rd "), 3) || !_tcsnicmp (line, _T("cd "), 3))
00583         ShowAll = FALSE;
00584 
00585     /* Copy the string, str can be edited and orginal should not be */
00586     _tcscpy(str,strIN);
00587     _tcscpy(szOrginal,strIN);
00588 
00589     /* Look to see if the cusor is not at the end of the string */
00590     if((cusor + 1) < _tcslen(str))
00591         str[cusor] = _T('\0');
00592 
00593     /* Look to see if they hit tab again, if so cut off the diff length */
00594     if(_tcscmp(str,LastReturned) || !_tcslen(str))
00595     {
00596         /* We need to know how many chars we added from the start */
00597         StartLength = _tcslen(str);
00598 
00599         /* no string, we need all files in that directory */
00600         if(!StartLength)
00601         {
00602             _tcscat(str,_T("*"));
00603         }
00604 
00605         /* Zero it out first */
00606         szBaseWord[0] = _T('\0');
00607         szPrefix[0] = _T('\0');
00608 
00609         /*What comes out of this needs to be:
00610             szBaseWord =  path no quotes to the object
00611             szPrefix = what leads up to the filename
00612             no quote at the END of the full name */
00613         FindPrefixAndSuffix(str,szPrefix,szBaseWord);
00614         /* Strip quotes */
00615         for(i = 0; i < _tcslen(szBaseWord); )
00616         {
00617             if(szBaseWord[i] == _T('\"'))
00618                 memmove(&szBaseWord[i],&szBaseWord[i + 1], _tcslen(&szBaseWord[i]) * sizeof(TCHAR));
00619             else
00620                 i++;
00621         }
00622 
00623         /* clear it out */
00624         memset(szSearchPath, 0, sizeof(szSearchPath));
00625 
00626         /* Start the search for all the files */
00627         GetFullPathName(szBaseWord, MAX_PATH, szSearchPath, NULL);
00628 
00629         /* Got a device path? Fallback to the the current dir plus the short path */
00630         if (szSearchPath[0] == _T('\\') && szSearchPath[1] == _T('\\') &&
00631             szSearchPath[2] == _T('.') && szSearchPath[3] == _T('\\'))
00632         {
00633             GetCurrentDirectory(MAX_PATH, szSearchPath);
00634             _tcscat(szSearchPath, _T("\\"));
00635             _tcscat(szSearchPath, szBaseWord);
00636         }
00637 
00638         if(StartLength > 0)
00639         {
00640             _tcscat(szSearchPath,_T("*"));
00641         }
00642         _tcscpy(LastSearch,szSearchPath);
00643         _tcscpy(LastPrefix,szPrefix);
00644     }
00645     else
00646     {
00647         _tcscpy(szSearchPath, LastSearch);
00648         _tcscpy(szPrefix, LastPrefix);
00649         StartLength = 0;
00650     }
00651     /* search for the files it might be */
00652     hFile = FindFirstFile (szSearchPath, &file);
00653     if(hFile == INVALID_HANDLE_VALUE)
00654     {
00655         /* Assemble the orginal string and return */
00656         _tcscpy(strOut,szOrginal);
00657         return;
00658     }
00659 
00660     /* aseemble a list of all files names */
00661     do
00662     {
00663         if(!_tcscmp (file.cFileName, _T(".")) ||
00664             !_tcscmp (file.cFileName, _T("..")))
00665             continue;
00666 
00667         /* Don't show files when they are doing 'cd' or 'rd' */
00668         if(!ShowAll &&
00669        file.dwFileAttributes != 0xFFFFFFFF &&
00670        !(file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
00671         {
00672                 continue;
00673         }
00674 
00675         /* Add the file to the list of files */
00676         FileList = cmd_realloc(FileList, ++FileListSize * sizeof(FileName));
00677 
00678         if(FileList == NULL)
00679         {
00680             /* Assemble the orginal string and return */
00681             _tcscpy(strOut,szOrginal);
00682             FindClose(hFile);
00683             ConOutFormatMessage (GetLastError());
00684             return;
00685         }
00686         /* Copies the file name into the struct */
00687         _tcscpy(FileList[FileListSize-1].Name,file.cFileName);
00688 
00689     } while(FindNextFile(hFile,&file));
00690 
00691     FindClose(hFile);
00692 
00693     /* Check the size of the list to see if we
00694        found any matches */
00695     if(FileListSize == 0)
00696     {
00697         _tcscpy(strOut,szOrginal);
00698         if(FileList != NULL)
00699             cmd_free(FileList);
00700         return;
00701 
00702     }
00703     /* Sort the files */
00704     qsort(FileList,FileListSize,sizeof(FileName), compare);
00705 
00706     /* Find the next/previous */
00707     if(!_tcscmp(szOrginal,LastReturned))
00708     {
00709         if(bNext)
00710         {
00711             if(FileListSize - 1 == Sel)
00712                 Sel = 0;
00713             else
00714                 Sel++;
00715         }
00716         else
00717         {
00718             if(!Sel)
00719                 Sel = FileListSize - 1;
00720             else
00721                 Sel--;
00722         }
00723     }
00724     else
00725     {
00726         Sel = 0;
00727     }
00728 
00729     /* nothing found that matched last time
00730        so return the first thing in the list */
00731     strOut[0] = _T('\0');
00732 
00733     /* Special character in the name */
00734     if (FileNameContainsSpecialCharacters(FileList[Sel].Name))
00735     {
00736         INT LastSpace;
00737         BOOL bInside;
00738         /* It needs a " at the end */
00739         NeededQuote = TRUE;
00740         LastSpace = -1;
00741         bInside = FALSE;
00742         /* Find the place to put the " at the start */
00743         for(i = 0; i < _tcslen(szPrefix); i++)
00744         {
00745             if(szPrefix[i] == _T('\"'))
00746                 bInside = !bInside;
00747             if(szPrefix[i] == _T(' ') && !bInside)
00748                 LastSpace = i;
00749 
00750         }
00751         /* insert the quotation and move things around */
00752         if(szPrefix[LastSpace + 1] != _T('\"') && LastSpace != -1)
00753         {
00754             memmove ( &szPrefix[LastSpace+1], &szPrefix[LastSpace], (_tcslen(szPrefix)-LastSpace+1) * sizeof(TCHAR) );
00755 
00756             if((UINT)(LastSpace + 1) == _tcslen(szPrefix))
00757             {
00758                 _tcscat(szPrefix,_T("\""));
00759             }
00760             szPrefix[LastSpace + 1] = _T('\"');
00761         }
00762         else if(LastSpace == -1)
00763         {
00764             /* Add quotation only if none exists already */
00765             if (szPrefix[0] != _T('\"'))
00766             {
00767                 _tcscpy(szBaseWord,_T("\""));
00768                 _tcscat(szBaseWord,szPrefix);
00769                 _tcscpy(szPrefix,szBaseWord);
00770             }
00771         }
00772     }
00773 
00774     _tcscpy(strOut,szPrefix);
00775     _tcscat(strOut,FileList[Sel].Name);
00776 
00777     /* check for odd number of quotes means we need to close them */
00778     if(!NeededQuote)
00779     {
00780         for(i = 0; i < _tcslen(strOut); i++)
00781             if(strOut[i] == _T('\"'))
00782                 NeededQuote = !NeededQuote;
00783     }
00784 
00785     if(szPrefix[_tcslen(szPrefix) - 1] == _T('\"') || NeededQuote)
00786         _tcscat(strOut,_T("\""));
00787 
00788     _tcscpy(LastReturned,strOut);
00789     //EndLength = _tcslen(strOut);
00790     //DiffLength = EndLength - StartLength;
00791     if(FileList != NULL)
00792         cmd_free(FileList);
00793 
00794 }
00795 #endif

Generated on Sat May 26 2012 04:17:03 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.