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.

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

mercurial