Leaked source code of windows server 2003
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.

100 lines
2.4 KiB

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Include files */
  2. #include "windows.h"
  3. #include "stdio.h"
  4. #include "stdlib.h"
  5. #include "string.h"
  6. #define MAX_NAME_SIZE (8)
  7. #define MAX_EXT_SIZE (3)
  8. char CharRemoveList[] = "AEIOUaeiou_";
  9. int ConvertFileName(char *NameToConvert);
  10. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::: Main entry point */
  11. __cdecl main(int argc, char *argv[])
  12. {
  13. int index;
  14. /*......................................... Validate input parameters */
  15. if(argc < 2)
  16. {
  17. printf("Invalid usage : rename <filenames>\n");
  18. return(1);
  19. }
  20. for(index = 1; index < argc; index++)
  21. ConvertFileName(argv[index]);
  22. return(0);
  23. }
  24. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
  25. int ConvertFileName(char *NameToConvert)
  26. {
  27. char *Name, *Ext, *ExtStart;
  28. int NameSize, ExtSize;
  29. char NewName[MAX_NAME_SIZE+1], NewFileName[1000];
  30. char *NewNamePtr;
  31. /*....................... Get the size of the file name and extension */
  32. for(Name = NameToConvert, NameSize = 0;
  33. *Name && *Name != '.'; Name++, NameSize++);
  34. for(ExtStart = Name, Ext = *Name == '.' ? Name+1 : Name, ExtSize = 0;
  35. *Ext ; Ext++, ExtSize++);
  36. /*................................ Validate name and extension sizes */
  37. if(ExtSize > MAX_EXT_SIZE)
  38. {
  39. printf("Unable to convert '%s' to 8.3 filename\n", NameToConvert);
  40. return(1);
  41. }
  42. if(NameSize <= MAX_NAME_SIZE)
  43. {
  44. /* Name does not need conversion */
  45. return(0);
  46. }
  47. /*................................................ Convert file name */
  48. NewNamePtr = &NewName[MAX_NAME_SIZE];
  49. *NewNamePtr-- = 0;
  50. do
  51. {
  52. Name--;
  53. if(NameSize > MAX_NAME_SIZE && strchr(CharRemoveList, *Name))
  54. NameSize--; /* Remove character */
  55. else
  56. *NewNamePtr-- = *Name;
  57. }
  58. while(NewNamePtr >= NewName && Name != NameToConvert);
  59. /*............................................. Validate conversion */
  60. if(NameSize > MAX_NAME_SIZE)
  61. {
  62. printf("Unable to convert '%s' to 8.3 filename\n", NameToConvert);
  63. return(1);
  64. }
  65. sprintf(NewFileName,"%s%s", NewNamePtr+1, ExtStart);
  66. printf("REN '%s' to '%s'\n", NameToConvert, NewFileName);
  67. rename(NameToConvert, NewFileName);
  68. return(0);
  69. }