]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/test_and_benchmark/libshared/src/libshared_ansi/libshared_ansi_strcat_number.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / test_and_benchmark / libshared / src / libshared_ansi / libshared_ansi_strcat_number.c
1 /***** includes *****/
2 #include "libshared_ansi_internal.h"
3
4
5
6
7
8 /****************************************************************************/
9 void libshared_ansi_strcat_number( char *destination, lfds710_pal_uint_t number )
10 {
11   lfds710_pal_uint_t
12     digit,
13     length = 0,
14     original_number;
15
16   LFDS710_PAL_ASSERT( destination != NULL );
17   // TRD : number can be any value in its range
18
19   // TRD : point destination at the end of the string
20   while( *destination++ != '\0' );
21
22   destination--;
23
24   // TRD : figure out length of the number
25
26   original_number = number;
27
28   do
29   {
30     digit = number % 10;
31     length++;
32     number -= digit;
33     number /= 10;
34   }
35   while( number > 0 );
36
37   destination[length] = '\0';
38
39   // TRD : copy over the number digits - note we get them the right way around
40
41   number = original_number;
42
43   do
44   {
45     digit = number % 10;
46     destination[--length] = (char) ( digit + '0' );
47     number -= digit;
48     number /= 10;
49   }
50   while( number > 0 );
51
52   return;
53 }
54
55
56
57
58
59 /****************************************************************************/
60 void libshared_ansi_strcat_number_with_leading_zeros( char *destination, lfds710_pal_uint_t number, lfds710_pal_uint_t minimum_width )
61 {
62   lfds710_pal_uint_t
63     digit,
64     length = 0,
65     loop,
66     original_number;
67
68   LFDS710_PAL_ASSERT( destination != NULL );
69   // TRD : number can be any value in its range
70   // TRD : minimum_width can be any value in its range
71
72   // TRD : point destination at the end of the string
73   while( *destination++ != '\0' );
74
75   destination--;
76
77   // TRD : figure out length of the number
78
79   original_number = number;
80
81   do
82   {
83     digit = number % 10;
84     length++;
85     number -= digit;
86     number /= 10;
87   }
88   while( number > 0 );
89
90   if( length < minimum_width )
91     for( loop = 0 ; loop < minimum_width - length ; loop++ )
92       *destination++ = '0';
93
94   destination[length] = '\0';
95
96   // TRD : copy over the number digits - note we get them the right way around
97
98   number = original_number;
99
100   do
101   {
102     digit = number % 10;
103     destination[--length] = (char) ( digit + '0' );
104     number -= digit;
105     number /= 10;
106   }
107   while( number > 0 );
108
109   return;
110 }
111