source: trunk/gsdl/packages/wv-0.5.44-gs/src/ordinal.c@ 1468

Last change on this file since 1468 was 1468, checked in by paynter, 24 years ago

The wv Packages from www.wvware.com is used to convert Word documents into
HTML. This is an adaptation of wv version 0.5.44 for greenstone; it is
called by the gsConvert.pl script.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include "wv.h"
4#include <string.h>
5
6/*
7http://216.46.233.38/code/functions/convert_numbers_to_words/index.htm
8
9wvOrdinal numbers to words with this easy to use set of functions.
10Now, 5675 becomes Five Thousand Six Hundred Seventy Five.
11
12'-- Sean Kelly - [email protected]
13'-- Windows CE Tools
14
15'-- Sean works for Microsoft in the CE tools division.
16'-- The views and opinions expressed in the code are Sean's and
17'-- do not necessarily represent those of his employer.
18*/
19
20/*
21I did a quick hack job to convert this to C, from the original VB.
22[email protected]
23*/
24
25char *cvtText[31];
26void cvtInit(void);
27char *convert100(U32 x);
28char *wvOrdinal(U32 x);
29
30#if 0
31int main(void)
32 {
33 char *temp;
34 temp = wvOrdinal(500);
35 if (temp)
36 {
37 printf("%s\n",temp);
38 wvFree(temp);
39 return(0);
40 }
41 fprintf(stderr,"Memory Allocation Problems\n");
42 return(1);
43 }
44#endif
45
46void cvtInit(void)
47 {
48 cvtText[0] = "--";
49 cvtText[1] = "One";
50 cvtText[2] = "Two";
51 cvtText[3] = "Three";
52 cvtText[4] = "Four";
53 cvtText[5] = "Five";
54 cvtText[6] = "Six";
55 cvtText[7] = "Seven";
56 cvtText[8] = "Eight";
57 cvtText[9] = "Nine";
58 cvtText[10] = "Ten";
59 cvtText[11] = "Eleven";
60 cvtText[12] = "Twelve";
61 cvtText[13] = "Thirteen";
62 cvtText[14] = "Fourteen";
63 cvtText[15] = "Fifteen";
64 cvtText[16] = "Sixteen";
65 cvtText[17] = "Seventeen";
66 cvtText[18] = "Eighteen";
67 cvtText[19] = "Ninteen";
68 cvtText[20] = "Twenty";
69 cvtText[21] = "Thirty";
70 cvtText[22] = "Forty";
71 cvtText[23] = "Fifty";
72 cvtText[24] = "Sixty";
73 cvtText[25] = "Seventy";
74 cvtText[26] = "Eigthty";
75 cvtText[27] = "Ninty";
76 cvtText[28] = "Hundred";
77 cvtText[29] = "Thousand";
78 cvtText[30] = "Million";
79 }
80
81char *convert100(U32 x)
82 {
83 U16 t;
84 char *cvt100;
85
86 cvt100=(char *)malloc(4096);
87 if (cvt100 == NULL)
88 return(NULL);
89
90 if (x > 999)
91 {
92 strcpy(cvt100,"Error 100");
93 return(cvt100);
94 }
95
96 if (x > 99)
97 {
98 t = x / 100;
99 sprintf(cvt100,"%s %s ",cvtText[t],cvtText[28]);
100 x = x - (t * 100);
101 }
102
103 if (x > 20)
104 {
105 t = x / 10;
106 wvStrcat(cvt100,cvtText[t + 18]);
107 wvStrcat(cvt100," ");
108 x = x - (t * 10);
109 }
110
111 if (x > 0)
112 {
113 wvStrcat(cvt100,cvtText[x]);
114 wvStrcat(cvt100," ");
115 }
116 return(cvt100);
117 }
118
119char *wvOrdinal(U32 x)
120 {
121 U32 t;
122 char *Cvt;
123 char *temp;
124
125 Cvt=(char *)malloc(4096);
126 if (Cvt == NULL)
127 return(NULL);
128 cvtInit();
129
130 if (x > 999999999)
131 {
132 strcpy(Cvt,"Number too large");
133 return(Cvt);
134 }
135
136 if (x > 999999)
137 {
138 t = x / 1000000;
139 temp = convert100(t);
140 if (temp)
141 {
142 sprintf(Cvt,"%s%s ",temp,cvtText[30]);
143 wvFree(temp);
144 }
145 else
146 {
147 wvFree(Cvt);
148 return(NULL);
149 }
150 x = x - (t * 1000000);
151 }
152
153 if (x > 999)
154 {
155 t = x / 1000;
156 temp = convert100(t);
157 if (temp)
158 {
159 wvStrcat(Cvt,temp);
160 wvFree(temp);
161 }
162 else
163 {
164 wvFree(Cvt);
165 return(NULL);
166 }
167 wvStrcat(Cvt,cvtText[29]);
168 wvStrcat(Cvt," ");
169 x = x - (t * 1000);
170 }
171
172 if (x > 0)
173 {
174 temp = convert100(x);
175 if (temp)
176 {
177 wvStrcat(Cvt,temp);
178 wvFree(temp);
179 }
180 else
181 {
182 wvFree(Cvt);
183 return(NULL);
184 }
185 }
186 return(Cvt);
187 }
Note: See TracBrowser for help on using the repository browser.