1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2001-03-21 23:22:16 +00:00
|
|
|
* Copyright (C) 1998-2000, International Business Machines
|
1999-12-13 22:28:37 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File util.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 06/10/99 stephen Creation.
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
2000-07-14 20:17:02 +00:00
|
|
|
#include "unicode/putil.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* go from "/usr/local/include/curses.h" to "/usr/local/include" */
|
|
|
|
void
|
|
|
|
get_dirname(char *dirname,
|
|
|
|
const char *filename)
|
|
|
|
{
|
2000-07-14 20:17:02 +00:00
|
|
|
const char *lastSlash = uprv_strrchr(filename, U_FILE_SEP_CHAR) + 1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-13 01:10:24 +00:00
|
|
|
if(lastSlash>filename) {
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_strncpy(dirname, filename, (lastSlash - filename));
|
1999-10-13 01:10:24 +00:00
|
|
|
*(dirname + (lastSlash - filename)) = '\0';
|
|
|
|
} else {
|
|
|
|
*dirname = '\0';
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* go from "/usr/local/include/curses.h" to "curses" */
|
|
|
|
void
|
|
|
|
get_basename(char *basename,
|
|
|
|
const char *filename)
|
|
|
|
{
|
1999-10-13 01:10:24 +00:00
|
|
|
/* strip off any leading directory portions */
|
2000-07-14 20:17:02 +00:00
|
|
|
const char *lastSlash = uprv_strrchr(filename, U_FILE_SEP_CHAR) + 1;
|
1999-08-16 21:50:52 +00:00
|
|
|
char *lastDot;
|
|
|
|
|
1999-10-13 01:10:24 +00:00
|
|
|
if(lastSlash>filename) {
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_strcpy(basename, lastSlash);
|
1999-10-13 01:10:24 +00:00
|
|
|
} else {
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_strcpy(basename, filename);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* strip off any suffix */
|
1999-12-28 23:57:50 +00:00
|
|
|
lastDot = uprv_strrchr(basename, '.');
|
1999-10-13 01:10:24 +00:00
|
|
|
|
|
|
|
if(lastDot != NULL) {
|
|
|
|
*lastDot = '\0';
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|