1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2005-03-08 22:49:59 +00:00
|
|
|
* Copyright (C) 1998-2005, 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.
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2001-09-25 19:28:25 +00:00
|
|
|
#include "unicode/putil.h"
|
2005-03-08 07:05:49 +00:00
|
|
|
#include "rbutil.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* go from "/usr/local/include/curses.h" to "/usr/local/include" */
|
|
|
|
void
|
|
|
|
get_dirname(char *dirname,
|
2002-04-02 02:55:31 +00:00
|
|
|
const char *filename)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
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,
|
2002-04-02 02:55:31 +00:00
|
|
|
const char *filename)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
2002-10-10 01:05:51 +00:00
|
|
|
|
|
|
|
#define MAX_DIGITS 10
|
|
|
|
int32_t
|
|
|
|
itostr(char * buffer, int32_t i, uint32_t radix, int32_t pad)
|
|
|
|
{
|
|
|
|
int32_t length = 0;
|
|
|
|
int32_t num = 0;
|
|
|
|
int32_t save = i;
|
|
|
|
int digit;
|
|
|
|
int32_t j;
|
|
|
|
char temp;
|
|
|
|
|
|
|
|
/* if i is negative make it positive */
|
|
|
|
if(i<0){
|
|
|
|
i=-i;
|
|
|
|
}
|
|
|
|
|
|
|
|
do{
|
|
|
|
digit = (int)(i % radix);
|
|
|
|
buffer[length++]=(char)(digit<=9?(0x0030+digit):(0x0030+digit+7));
|
|
|
|
i=i/radix;
|
|
|
|
} while(i);
|
|
|
|
|
|
|
|
while (length < pad){
|
|
|
|
buffer[length++] = 0x0030;/*zero padding */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if i is negative add the negative sign */
|
|
|
|
if(save < 0){
|
|
|
|
buffer[length++]='-';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* null terminate the buffer */
|
|
|
|
if(length<MAX_DIGITS){
|
|
|
|
buffer[length] = 0x0000;
|
|
|
|
}
|
|
|
|
|
|
|
|
num= (pad>=length) ? pad :length;
|
|
|
|
|
|
|
|
|
|
|
|
/* Reverses the string */
|
|
|
|
for (j = 0; j < (num / 2); j++){
|
|
|
|
temp = buffer[(length-1) - j];
|
|
|
|
buffer[(length-1) - j] = buffer[j];
|
|
|
|
buffer[j] = temp;
|
|
|
|
}
|
|
|
|
return length;
|
2002-11-12 00:43:02 +00:00
|
|
|
}
|