home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / tools / genrb / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-13  |  2.0 KB  |  72 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998, 1999     *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  9. *                                                                             *
  10. *******************************************************************************
  11. *
  12. * File util.c
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *   06/10/99    stephen     Creation.
  18. *******************************************************************************
  19. */
  20.  
  21. #include "util.h"
  22. #include "cmemory.h"
  23. #include "cstring.h"
  24.  
  25.  
  26. /* Platform-specific directory separator */
  27. #if defined(WIN32) ||  defined(_WIN32) || defined(OS2) || defined(__OS2__)
  28. # define DIR_SEP '\\'
  29. # define CUR_DIR ".\\"
  30. #else
  31. # define DIR_SEP '/'
  32. # define CUR_DIR "./"
  33. #endif /* WIN32 */
  34.  
  35. /* go from "/usr/local/include/curses.h" to "/usr/local/include" */
  36. void
  37. get_dirname(char *dirname,
  38.         const char *filename)
  39. {
  40.   const char *lastSlash = icu_strrchr(filename, DIR_SEP) + 1;
  41.  
  42.   if(lastSlash>filename) {
  43.     icu_strncpy(dirname, filename, (lastSlash - filename));
  44.     *(dirname + (lastSlash - filename)) = '\0';
  45.   } else {
  46.     *dirname = '\0';
  47.   }
  48. }
  49.  
  50. /* go from "/usr/local/include/curses.h" to "curses" */
  51. void
  52. get_basename(char *basename,
  53.          const char *filename)
  54. {
  55.   /* strip off any leading directory portions */
  56.   const char *lastSlash = icu_strrchr(filename, DIR_SEP) + 1;
  57.   char *lastDot;
  58.  
  59.   if(lastSlash>filename) {
  60.     icu_strcpy(basename, lastSlash);
  61.   } else {
  62.     icu_strcpy(basename, filename);
  63.   }
  64.  
  65.   /* strip off any suffix */
  66.   lastDot = icu_strrchr(basename, '.');
  67.  
  68.   if(lastDot != NULL) {
  69.     *lastDot = '\0';
  70.   }
  71. }
  72.