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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2 *******************************************************************************
     3 *
     4 *   Copyright (C) 1998-2008, International Business Machines
     5 *   Corporation and others.  All Rights Reserved.
     6 *
     7 *******************************************************************************
     8 *
     9 * File util.c
    10 *
    11 * Modification History:
    12 *
    13 *   Date        Name        Description
    14 *   06/10/99    stephen     Creation.
    15 *   02/07/08    Spieth      Correct XLIFF generation on EBCDIC platform
    16 *   
    17 *******************************************************************************
    18 */
    20 #include "unicode/putil.h"
    21 #include "rbutil.h"
    22 #include "cmemory.h"
    23 #include "cstring.h"
    26 /* go from "/usr/local/include/curses.h" to "/usr/local/include" */
    27 void
    28 get_dirname(char *dirname,
    29             const char *filename)
    30 {
    31   const char *lastSlash = uprv_strrchr(filename, U_FILE_SEP_CHAR) + 1;
    33   if(lastSlash>filename) {
    34     uprv_strncpy(dirname, filename, (lastSlash - filename));
    35     *(dirname + (lastSlash - filename)) = '\0';
    36   } else {
    37     *dirname = '\0';
    38   }
    39 }
    41 /* go from "/usr/local/include/curses.h" to "curses" */
    42 void
    43 get_basename(char *basename,
    44              const char *filename)
    45 {
    46   /* strip off any leading directory portions */
    47   const char *lastSlash = uprv_strrchr(filename, U_FILE_SEP_CHAR) + 1;
    48   char *lastDot;
    50   if(lastSlash>filename) {
    51     uprv_strcpy(basename, lastSlash);
    52   } else {
    53     uprv_strcpy(basename, filename);
    54   }
    56   /* strip off any suffix */
    57   lastDot = uprv_strrchr(basename, '.');
    59   if(lastDot != NULL) {
    60     *lastDot = '\0';
    61   }
    62 }
    64 #define MAX_DIGITS 10
    65 int32_t 
    66 itostr(char * buffer, int32_t i, uint32_t radix, int32_t pad)
    67 {
    68     const char digits[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
    69     int32_t length = 0;
    70     int32_t num = 0;
    71     int32_t save = i;
    72     int digit;
    73     int32_t j;
    74     char temp;
    76     /* if i is negative make it positive */
    77     if(i<0){
    78         i=-i;
    79     }
    81     do{
    82         digit = (int)(i % radix);
    83         buffer[length++]= digits[digit];
    84         i=i/radix;
    85     } while(i);
    87     while (length < pad){
    88         buffer[length++] = '0';/*zero padding */
    89     }
    91     /* if i is negative add the negative sign */
    92     if(save < 0){
    93         buffer[length++]='-';
    94     }
    96     /* null terminate the buffer */
    97     if(length<MAX_DIGITS){
    98         buffer[length] =  0x0000;
    99     }
   101     num= (pad>=length) ? pad :length;
   104     /* Reverses the string */
   105     for (j = 0; j < (num / 2); j++){
   106         temp = buffer[(length-1) - j];
   107         buffer[(length-1) - j] = buffer[j];
   108         buffer[j] = temp;
   109     }
   110     return length;
   111 }

mercurial