ReactOS 0.4.15-dev-8434-g155a7c7
filecomp.c File Reference
#include "precomp.h"
Include dependency graph for filecomp.c:

Go to the source code of this file.

Classes

struct  _FileName
 

Typedefs

typedef struct _FileName FileName
 

Functions

VOID FindPrefixAndSuffix (LPTSTR strIN, LPTSTR szPrefix, LPTSTR szSuffix)
 
int __cdecl compare (const void *arg1, const void *arg2)
 
BOOL FileNameContainsSpecialCharacters (LPTSTR pszFileName)
 
VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor)
 

Typedef Documentation

◆ FileName

Definition at line 896 of file fatprocs.h.

Function Documentation

◆ compare()

int __cdecl compare ( const void arg1,
const void arg2 
)

Definition at line 482 of file filecomp.c.

483{
484 FileName * File1;
485 FileName * File2;
486 INT ret;
487
488 File1 = cmd_alloc(sizeof(FileName));
489 if (!File1)
490 return 0;
491
492 File2 = cmd_alloc(sizeof(FileName));
493 if (!File2)
494 {
495 cmd_free(File1);
496 return 0;
497 }
498
499 memcpy(File1,arg1,sizeof(FileName));
500 memcpy(File2,arg2,sizeof(FileName));
501
502 /* ret = _tcsicmp(File1->Name, File2->Name); */
503 ret = lstrcmpi(File1->Name, File2->Name);
504
505 cmd_free(File1);
506 cmd_free(File2);
507 return ret;
508}
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define cmd_alloc(size)
Definition: cmddbg.h:29
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
TCHAR Name[MAX_PATH]
Definition: filecomp.c:349
int32_t INT
Definition: typedefs.h:58
int ret
#define lstrcmpi
Definition: winbase.h:3873

◆ CompleteFilename()

VOID CompleteFilename ( LPTSTR  strIN,
BOOL  bNext,
LPTSTR  strOut,
UINT  cusor 
)

Definition at line 545 of file filecomp.c.

546{
547 /* Length of string before we complete it */
548 INT_PTR StartLength;
549 /* Length of string after completed */
550 //INT EndLength;
551 /* The number of chars added too it */
552 //static INT DiffLength = 0;
553 /* Used to find and assemble the string that is returned */
554 TCHAR szBaseWord[MAX_PATH];
555 TCHAR szPrefix[MAX_PATH];
556 TCHAR szOriginal[MAX_PATH];
557 TCHAR szSearchPath[MAX_PATH];
558 /* Save the strings used last time, so if they hit tab again */
559 static TCHAR LastReturned[MAX_PATH];
560 static TCHAR LastSearch[MAX_PATH];
561 static TCHAR LastPrefix[MAX_PATH];
562 /* Used to search for files */
565 /* List of all the files */
567 /* Number of files */
568 INT FileListSize = 0;
569 /* Used for loops */
570 UINT i;
571 /* Editable string of what was passed in */
573 /* Keeps track of what element was last selected */
574 static INT Sel;
575 BOOL NeededQuote = FALSE;
576 BOOL ShowAll = TRUE;
577 TCHAR * line = strIN;
578
579 strOut[0] = _T('\0');
580
581 while (_istspace (*line))
582 line++;
583 if (!_tcsnicmp (line, _T("rd "), 3) || !_tcsnicmp (line, _T("cd "), 3))
584 ShowAll = FALSE;
585
586 /* Copy the string, str can be edited and original should not be */
587 _tcscpy(str,strIN);
588 _tcscpy(szOriginal,strIN);
589
590 /* Look to see if the cusor is not at the end of the string */
591 if ((cusor + 1) < _tcslen(str))
592 str[cusor] = _T('\0');
593
594 /* Look to see if they hit tab again, if so cut off the diff length */
595 if (_tcscmp(str,LastReturned) || !_tcslen(str))
596 {
597 /* We need to know how many chars we added from the start */
598 StartLength = _tcslen(str);
599
600 /* no string, we need all files in that directory */
601 if (!StartLength)
602 {
603 _tcscat(str,_T("*"));
604 }
605
606 /* Zero it out first */
607 szBaseWord[0] = _T('\0');
608 szPrefix[0] = _T('\0');
609
610 /*What comes out of this needs to be:
611 szBaseWord = path no quotes to the object
612 szPrefix = what leads up to the filename
613 no quote at the END of the full name */
614 FindPrefixAndSuffix(str,szPrefix,szBaseWord);
615 /* Strip quotes */
616 for(i = 0; i < _tcslen(szBaseWord); )
617 {
618 if (szBaseWord[i] == _T('\"'))
619 memmove(&szBaseWord[i],&szBaseWord[i + 1], _tcslen(&szBaseWord[i]) * sizeof(TCHAR));
620 else
621 i++;
622 }
623
624 /* clear it out */
625 memset(szSearchPath, 0, sizeof(szSearchPath));
626
627 /* Start the search for all the files */
628 GetFullPathName(szBaseWord, MAX_PATH, szSearchPath, NULL);
629
630 /* Got a device path? Fallback to the the current dir plus the short path */
631 if (szSearchPath[0] == _T('\\') && szSearchPath[1] == _T('\\') &&
632 szSearchPath[2] == _T('.') && szSearchPath[3] == _T('\\'))
633 {
634 GetCurrentDirectory(MAX_PATH, szSearchPath);
635 _tcscat(szSearchPath, _T("\\"));
636 _tcscat(szSearchPath, szBaseWord);
637 }
638
639 if (StartLength > 0)
640 {
641 _tcscat(szSearchPath,_T("*"));
642 }
643 _tcscpy(LastSearch,szSearchPath);
644 _tcscpy(LastPrefix,szPrefix);
645 }
646 else
647 {
648 _tcscpy(szSearchPath, LastSearch);
649 _tcscpy(szPrefix, LastPrefix);
650 StartLength = 0;
651 }
652 /* search for the files it might be */
653 hFile = FindFirstFile (szSearchPath, &file);
655 {
656 /* Assemble the original string and return */
657 _tcscpy(strOut,szOriginal);
658 return;
659 }
660
661 /* assemble a list of all files names */
662 do
663 {
664 FileName * oldFileList = FileList;
665
666 if (!_tcscmp (file.cFileName, _T(".")) ||
667 !_tcscmp (file.cFileName, _T("..")))
668 continue;
669
670 /* Don't show files when they are doing 'cd' or 'rd' */
671 if (!ShowAll &&
672 file.dwFileAttributes != INVALID_FILE_ATTRIBUTES &&
673 !(file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
674 {
675 continue;
676 }
677
678 /* Add the file to the list of files */
679 FileList = cmd_realloc(FileList, ++FileListSize * sizeof(FileName));
680
681 if (FileList == NULL)
682 {
683 /* Don't leak old buffer */
684 cmd_free(oldFileList);
685 /* Assemble the original string and return */
686 _tcscpy(strOut,szOriginal);
689 return;
690 }
691 /* Copies the file name into the struct */
692 _tcscpy(FileList[FileListSize-1].Name,file.cFileName);
693
694 } while(FindNextFile(hFile,&file));
695
697
698 /* Check the size of the list to see if we found any matches */
699 if (FileListSize == 0)
700 {
701 _tcscpy(strOut,szOriginal);
702 if (FileList != NULL)
704 return;
705
706 }
707 /* Sort the files */
708 qsort(FileList,FileListSize,sizeof(FileName), compare);
709
710 /* Find the next/previous */
711 if (_tcslen(szOriginal) && !_tcscmp(szOriginal,LastReturned))
712 {
713 if (bNext)
714 {
715 if (FileListSize - 1 == Sel)
716 Sel = 0;
717 else
718 Sel++;
719 }
720 else
721 {
722 if (!Sel)
723 Sel = FileListSize - 1;
724 else
725 Sel--;
726 }
727 }
728 else
729 {
730 Sel = 0;
731 }
732
733 /* nothing found that matched last time so return the first thing in the list */
734 strOut[0] = _T('\0');
735
736 /* Special character in the name */
738 {
739 INT LastSpace;
740 BOOL bInside;
741 /* It needs a " at the end */
742 NeededQuote = TRUE;
743 LastSpace = -1;
744 bInside = FALSE;
745 /* Find the place to put the " at the start */
746 for(i = 0; i < _tcslen(szPrefix); i++)
747 {
748 if (szPrefix[i] == _T('\"'))
749 bInside = !bInside;
750 if (szPrefix[i] == _T(' ') && !bInside)
751 LastSpace = i;
752 }
753
754 /* insert the quotation and move things around */
755 if (szPrefix[LastSpace + 1] != _T('\"') && LastSpace != -1)
756 {
757 memmove ( &szPrefix[LastSpace+1], &szPrefix[LastSpace], (_tcslen(szPrefix)-LastSpace+1) * sizeof(TCHAR) );
758
759 if ((UINT)(LastSpace + 1) == _tcslen(szPrefix))
760 {
761 _tcscat(szPrefix,_T("\""));
762 }
763 szPrefix[LastSpace + 1] = _T('\"');
764 }
765 else if (LastSpace == -1)
766 {
767 /* Add quotation only if none exists already */
768 if (szPrefix[0] != _T('\"'))
769 {
770 _tcscpy(szBaseWord,_T("\""));
771 _tcscat(szBaseWord,szPrefix);
772 _tcscpy(szPrefix,szBaseWord);
773 }
774 }
775 }
776
777 _tcscpy(strOut,szPrefix);
778 _tcscat(strOut,FileList[Sel].Name);
779
780 /* check for odd number of quotes means we need to close them */
781 if (!NeededQuote)
782 {
783 for(i = 0; i < _tcslen(strOut); i++)
784 {
785 if (strOut[i] == _T('\"'))
786 NeededQuote = !NeededQuote;
787 }
788 }
789
790 if (NeededQuote || (_tcslen(szPrefix) && szPrefix[_tcslen(szPrefix) - 1] == _T('\"')))
791 _tcscat(strOut,_T("\""));
792
793 _tcscpy(LastReturned,strOut);
794 //EndLength = _tcslen(strOut);
795 //DiffLength = EndLength - StartLength;
796 if (FileList != NULL)
798}
vector< FileInfo > FileList
Definition: DriveVolume.h:63
#define cmd_realloc(ptr, size)
Definition: cmddbg.h:30
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL FileNameContainsSpecialCharacters(LPTSTR pszFileName)
Definition: filecomp.c:511
VOID FindPrefixAndSuffix(LPTSTR strIN, LPTSTR szPrefix, LPTSTR szSuffix)
Definition: filecomp.c:352
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _istspace
Definition: tchar.h:1504
#define _tcscmp
Definition: tchar.h:1424
#define _tcscat
Definition: tchar.h:622
#define _tcscpy
Definition: tchar.h:623
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned int UINT
Definition: ndis.h:50
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define ConOutFormatMessage(MessageId,...)
Definition: replace.h:34
const WCHAR * str
#define memset(x, y, z)
Definition: compat.h:39
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))
Definition: bug.cpp:8
Definition: fci.c:127
Definition: parser.c:49
int32_t INT_PTR
Definition: typedefs.h:64
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FindNextFile
Definition: winbase.h:3788
#define FindFirstFile
Definition: winbase.h:3782
#define GetCurrentDirectory
Definition: winbase.h:3805
#define GetFullPathName
Definition: winbase.h:3821
char TCHAR
Definition: xmlstorage.h:189
#define _tcsnicmp
Definition: xmlstorage.h:207
#define _tcslen
Definition: xmlstorage.h:198

Referenced by ReadCommand().

◆ FileNameContainsSpecialCharacters()

BOOL FileNameContainsSpecialCharacters ( LPTSTR  pszFileName)

Definition at line 511 of file filecomp.c.

512{
513 TCHAR chr;
514
515 while ((chr = *pszFileName++) != _T('\0'))
516 {
517 if ((chr == _T(' ')) ||
518 (chr == _T('!')) ||
519 (chr == _T('%')) ||
520 (chr == _T('&')) ||
521 (chr == _T('(')) ||
522 (chr == _T(')')) ||
523 (chr == _T('{')) ||
524 (chr == _T('}')) ||
525 (chr == _T('[')) ||
526 (chr == _T(']')) ||
527 (chr == _T('=')) ||
528 (chr == _T('\'')) ||
529 (chr == _T('`')) ||
530 (chr == _T(',')) ||
531 (chr == _T(';')) ||
532 (chr == _T('^')) ||
533 (chr == _T('~')) ||
534 (chr == _T('+')) ||
535 (chr == 0xB4)) // '´'
536 {
537 return TRUE;
538 }
539 }
540
541 return FALSE;
542}
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:44

Referenced by CompleteFilename().

◆ FindPrefixAndSuffix()

VOID FindPrefixAndSuffix ( LPTSTR  strIN,
LPTSTR  szPrefix,
LPTSTR  szSuffix 
)

Definition at line 352 of file filecomp.c.

353{
354 /* String that is to be examined */
356 /* temp pointers to used to find needed parts */
357 TCHAR * szSearch;
358 TCHAR * szSearch1;
359 TCHAR * szSearch2;
360 TCHAR * szSearch3;
361 /* number of quotes in the string */
362 INT nQuotes = 0;
363 /* used in for loops */
364 UINT i;
365 /* Char number to break the string at */
366 INT PBreak = 0;
367 INT SBreak = 0;
368 /* when phrasing a string, this tells weather
369 you are inside quotes ot not. */
370 BOOL bInside = FALSE;
371
372 szPrefix[0] = _T('\0');
373 szSuffix[0] = _T('\0');
374
375 /* Copy over the string to later be edited */
376 _tcscpy(str,strIN);
377
378 /* Count number of " */
379 for(i = 0; i < _tcslen(str); i++)
380 {
381 if (str[i] == _T('\"'))
382 nQuotes++;
383 }
384
385 /* Find the prefix and suffix */
386 if (nQuotes % 2 && nQuotes >= 1)
387 {
388 /* Odd number of quotes. Just start from the last " */
389 /* THis is the way MS does it, and is an easy way out */
390 szSearch = _tcsrchr(str, _T('\"'));
391 /* Move to the next char past the " */
392 szSearch++;
393 _tcscpy(szSuffix,szSearch);
394 /* Find the one closest to end */
395 szSearch1 = _tcsrchr(str, _T('\"'));
396 szSearch2 = _tcsrchr(str, _T('\\'));
397 szSearch3 = _tcsrchr(str, _T('/'));
398 if ((szSearch2 != NULL) && (szSearch1 < szSearch2))
399 szSearch = szSearch2;
400 else if ((szSearch3 != NULL) && (szSearch1 < szSearch3))
401 szSearch = szSearch3;
402 else
403 szSearch = szSearch1;
404 /* Move one char past */
405 szSearch++;
406 szSearch[0] = _T('\0');
407 _tcscpy(szPrefix,str);
408 return;
409
410 }
411
412 if (!_tcschr(str, _T(' ')))
413 {
414 /* No spaces, everything goes to Suffix */
415 _tcscpy(szSuffix,str);
416 /* look for a slash just in case */
417 szSearch = _tcsrchr(str, _T('\\'));
418 if (szSearch)
419 {
420 szSearch++;
421 szSearch[0] = _T('\0');
422 _tcscpy(szPrefix,str);
423 }
424 else
425 {
426 szPrefix[0] = _T('\0');
427 }
428 return;
429 }
430
431 if (!nQuotes)
432 {
433 /* No quotes, and there is a space*/
434 /* Take it after the last space */
435 szSearch = _tcsrchr(str, _T(' '));
436 szSearch++;
437 _tcscpy(szSuffix,szSearch);
438 /* Find the closest to the end space or \ */
439 _tcscpy(str,strIN);
440 szSearch1 = _tcsrchr(str, _T(' '));
441 szSearch2 = _tcsrchr(str, _T('\\'));
442 szSearch3 = _tcsrchr(str, _T('/'));
443 if ((szSearch2 != NULL) && (szSearch1 < szSearch2))
444 szSearch = szSearch2;
445 else if ((szSearch3 != NULL) && (szSearch1 < szSearch3))
446 szSearch = szSearch3;
447 else
448 szSearch = szSearch1;
449 szSearch++;
450 szSearch[0] = _T('\0');
451 _tcscpy(szPrefix,str);
452 return;
453 }
454
455 /* All else fails and there is a lot of quotes, spaces and |
456 Then we search through and find the last space or \ that is
457 not inside a quotes */
458 for(i = 0; i < _tcslen(str); i++)
459 {
460 if (str[i] == _T('\"'))
461 bInside = !bInside;
462 if (str[i] == _T(' ') && !bInside)
463 SBreak = i;
464 if ((str[i] == _T(' ') || str[i] == _T('\\')) && !bInside)
465 PBreak = i;
466 }
467 SBreak++;
468 PBreak++;
469 _tcscpy(szSuffix,&strIN[SBreak]);
470 strIN[PBreak] = _T('\0');
471 _tcscpy(szPrefix,strIN);
472 if (szPrefix[_tcslen(szPrefix) - 2] == _T('\"') &&
473 szPrefix[_tcslen(szPrefix) - 1] != _T(' '))
474 {
475 /* need to remove the " right before a \ at the end to
476 allow the next stuff to stay inside one set of quotes
477 otherwise you would have multiple sets of quotes*/
478 _tcscpy(&szPrefix[_tcslen(szPrefix) - 2],_T("\\"));
479 }
480}
#define _tcschr
Definition: tchar.h:1406
#define _tcsrchr
Definition: utility.h:116

Referenced by CompleteFilename().