Cident.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //---------------------------------------------------------------------------
  2. //
  3. // cident.cpp - This file contains some misc string classes
  4. //
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. //---------------------------------------------------------------------------
  9. // Include files
  10. #ifndef CIDENT_H
  11. #include "cident.h"
  12. #endif
  13. #include "heap.h"
  14. #include <ctype.h>
  15. #include "windows.h"
  16. #ifndef _MBCS
  17. #include <gameos.hpp>
  18. #else
  19. #include <assert.h>
  20. #define gosASSERT assert
  21. #define gos_Malloc malloc
  22. #define gos_Free free
  23. #endif
  24. //---------------------------------------------------------------------------
  25. //---------------------------------------------------------------------------
  26. // FullPathFileName
  27. //---------------------------------------------------------------------------
  28. FullPathFileName::~FullPathFileName (void)
  29. {
  30. destroy();
  31. }
  32. //---------------------------------------------------------------------------
  33. void FullPathFileName::destroy (void)
  34. {
  35. if (fullName)
  36. systemHeap->Free(fullName);
  37. fullName = NULL;
  38. }
  39. //---------------------------------------------------------------------------
  40. void FullPathFileName::init (char * dir_path, const char * name, char * ext)
  41. {
  42. destroy();
  43. long total_length = strlen(dir_path);
  44. total_length += strlen(name);
  45. total_length += strlen(ext);
  46. total_length++;
  47. fullName = (char *)systemHeap->Malloc(total_length);
  48. gosASSERT(fullName != NULL);
  49. fullName[0] = 0;
  50. if ( strstr( name, dir_path ) != name )
  51. strcpy(fullName,dir_path);
  52. strcat(fullName,name);
  53. // don't append if its already there
  54. if (ext && stricmp( fullName + strlen( fullName ) - strlen( ext ), ext ) != 0)
  55. strcat(fullName,ext);
  56. CharLower(fullName);
  57. }
  58. void FullPathFileName::changeExt (char *from, char *to)
  59. {
  60. if (strlen(from) != strlen(to))
  61. return;
  62. char *ext = strstr(fullName,from);
  63. if (ext)
  64. {
  65. for (unsigned long i=0;i<strlen(to);i++)
  66. ext[i] = to[i];
  67. }
  68. }
  69. //---------------------------------------------------------------------------
  70. //
  71. // Edit Log
  72. //
  73. // $Log$
  74. //
  75. //---------------------------------------------------------------------------