Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.3 KiB

  1. /********************************************************************************
  2. * Description:
  3. * Functions that do what _dos_findfirst and _dos_findnext SHOULD do
  4. *******************************************************************************/
  5. #include <io.h>
  6. #include <string.h>
  7. #include <malloc.h>
  8. #include "filefind.h"
  9. static char * StringTable;
  10. static long offset = 0 ;
  11. static long MaxOffset;
  12. int InitStringTable(long size)
  13. {
  14. StringTable=(char *) malloc(size);
  15. ResetStringTable();
  16. return StringTable != 0;
  17. }
  18. void EndStringTable()
  19. {
  20. if (StringTable)
  21. free (StringTable);
  22. }
  23. void AddString (char * StringToAdd, finddata * s)
  24. {
  25. int len;
  26. len=strlen(StringToAdd);
  27. strcpy(StringTable+offset, StringToAdd);
  28. s->name=StringTable+offset;
  29. offset+=len+1;
  30. if (len>12) {
  31. strcpy(StringTable+offset, StringToAdd);
  32. StringTable[offset+11]='~';
  33. StringTable[offset+12]='\0';
  34. s->ShortName=StringTable+offset;
  35. offset+=13;
  36. }
  37. else
  38. s->ShortName=s->name;
  39. MaxOffset= (offset > MaxOffset) ? offset : MaxOffset;
  40. }
  41. long GetStringTableSize()
  42. {
  43. return MaxOffset;
  44. }
  45. void ResetStringTable()
  46. {
  47. offset=0;
  48. }
  49. int
  50. FindFirst(char * ss, unsigned attr, long * hFile, finddata * s)
  51. {
  52. int found;
  53. SysFindData s2;
  54. *hFile=_findfirst(ss, &s2);
  55. found = (*hFile != -1L);
  56. if (found) {
  57. if ( attr == ALL_FILES ) {
  58. while(found && s2.name[0] == '.')
  59. found=(_findnext(*hFile, &s2) == 0);
  60. }
  61. else if ( attr & _A_SUBDIR ) {
  62. while(found && (((s2.attrib & _A_SUBDIR) == 0) || s2.name[0] == '.'))
  63. found=(_findnext(*hFile, &s2) == 0);
  64. }
  65. else {
  66. while(found && (s2.attrib & _A_SUBDIR))
  67. found=(_findnext(*hFile, &s2) == 0);
  68. }
  69. if (!found)
  70. _findclose(*hFile);
  71. else {
  72. memcpy(s, &s2, sizeof(finddata));
  73. AddString(s2.name, s);
  74. }
  75. }
  76. return(found);
  77. } /* FindFirst() */
  78. int
  79. FindNext(int attr, long hFile, finddata * s)
  80. {
  81. int found;
  82. SysFindData s2;
  83. found=(_findnext(hFile, &s2) == 0);
  84. if (found && attr != ALL_FILES) {
  85. if ( attr & _A_SUBDIR ) {
  86. while(found && (((s2.attrib & _A_SUBDIR) == 0) || s2.name[0] == '.'))
  87. found=(_findnext(hFile, &s2) == 0);
  88. }
  89. else {
  90. while(found && (s2.attrib & _A_SUBDIR))
  91. found=(_findnext(hFile, &s2) == 0);
  92. }
  93. }
  94. if (!found)
  95. _findclose(hFile);
  96. else {
  97. memcpy(s, &s2, sizeof(finddata));
  98. AddString(s2.name, s);
  99. }
  100. return(found);
  101. } /* FindNext() */