intl/icu/source/tools/genrb/rbutil.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/tools/genrb/rbutil.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 1998-2008, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +*******************************************************************************
    1.11 +*
    1.12 +* File util.c
    1.13 +*
    1.14 +* Modification History:
    1.15 +*
    1.16 +*   Date        Name        Description
    1.17 +*   06/10/99    stephen     Creation.
    1.18 +*   02/07/08    Spieth      Correct XLIFF generation on EBCDIC platform
    1.19 +*   
    1.20 +*******************************************************************************
    1.21 +*/
    1.22 +
    1.23 +#include "unicode/putil.h"
    1.24 +#include "rbutil.h"
    1.25 +#include "cmemory.h"
    1.26 +#include "cstring.h"
    1.27 +
    1.28 +
    1.29 +/* go from "/usr/local/include/curses.h" to "/usr/local/include" */
    1.30 +void
    1.31 +get_dirname(char *dirname,
    1.32 +            const char *filename)
    1.33 +{
    1.34 +  const char *lastSlash = uprv_strrchr(filename, U_FILE_SEP_CHAR) + 1;
    1.35 +
    1.36 +  if(lastSlash>filename) {
    1.37 +    uprv_strncpy(dirname, filename, (lastSlash - filename));
    1.38 +    *(dirname + (lastSlash - filename)) = '\0';
    1.39 +  } else {
    1.40 +    *dirname = '\0';
    1.41 +  }
    1.42 +}
    1.43 +
    1.44 +/* go from "/usr/local/include/curses.h" to "curses" */
    1.45 +void
    1.46 +get_basename(char *basename,
    1.47 +             const char *filename)
    1.48 +{
    1.49 +  /* strip off any leading directory portions */
    1.50 +  const char *lastSlash = uprv_strrchr(filename, U_FILE_SEP_CHAR) + 1;
    1.51 +  char *lastDot;
    1.52 +
    1.53 +  if(lastSlash>filename) {
    1.54 +    uprv_strcpy(basename, lastSlash);
    1.55 +  } else {
    1.56 +    uprv_strcpy(basename, filename);
    1.57 +  }
    1.58 +
    1.59 +  /* strip off any suffix */
    1.60 +  lastDot = uprv_strrchr(basename, '.');
    1.61 +
    1.62 +  if(lastDot != NULL) {
    1.63 +    *lastDot = '\0';
    1.64 +  }
    1.65 +}
    1.66 +
    1.67 +#define MAX_DIGITS 10
    1.68 +int32_t 
    1.69 +itostr(char * buffer, int32_t i, uint32_t radix, int32_t pad)
    1.70 +{
    1.71 +    const char digits[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
    1.72 +    int32_t length = 0;
    1.73 +    int32_t num = 0;
    1.74 +    int32_t save = i;
    1.75 +    int digit;
    1.76 +    int32_t j;
    1.77 +    char temp;
    1.78 +    
    1.79 +    /* if i is negative make it positive */
    1.80 +    if(i<0){
    1.81 +        i=-i;
    1.82 +    }
    1.83 +    
    1.84 +    do{
    1.85 +        digit = (int)(i % radix);
    1.86 +        buffer[length++]= digits[digit];
    1.87 +        i=i/radix;
    1.88 +    } while(i);
    1.89 +
    1.90 +    while (length < pad){
    1.91 +        buffer[length++] = '0';/*zero padding */
    1.92 +    }
    1.93 +    
    1.94 +    /* if i is negative add the negative sign */
    1.95 +    if(save < 0){
    1.96 +        buffer[length++]='-';
    1.97 +    }
    1.98 +
    1.99 +    /* null terminate the buffer */
   1.100 +    if(length<MAX_DIGITS){
   1.101 +        buffer[length] =  0x0000;
   1.102 +    }
   1.103 +
   1.104 +    num= (pad>=length) ? pad :length;
   1.105 + 
   1.106 +
   1.107 +    /* Reverses the string */
   1.108 +    for (j = 0; j < (num / 2); j++){
   1.109 +        temp = buffer[(length-1) - j];
   1.110 +        buffer[(length-1) - j] = buffer[j];
   1.111 +        buffer[j] = temp;
   1.112 +    }
   1.113 +    return length;
   1.114 +}

mercurial