home *** CD-ROM | disk | FTP | other *** search
/ 1st Multimedia Mac Shareware / Multimedia Shareware CD-ROM - BetaCorp.iso / ControlPanelDev / EnToutesLettres / ETL.DevDoc / English.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-04  |  3.0 KB  |  147 lines  |  [TEXT/KAHL]

  1. #include <SetUpA4.h>
  2.  
  3. static    char unites[10][8] = { "zero ","one ","two ","three ","four ","five ","six ","seven ","eight ","nine " }    ;
  4. static    char dizaines[10][14] = { "","ten ","twenty ","thirty ","forty ","fifty ","sixty ","seventy ","eighty ","ninety " }    ;
  5. static     char multiples[4][9] = { "hundred","thousand","million" ,"billion"}    ;
  6. static     char special[10][11] = { "and ","eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "}    ;
  7.  
  8. char    *strcpy(char *s1,char *s2)    ;
  9. char    *strcat(char *s1,char *s2)    ;
  10. void    reverse(char *s)    ;
  11. short    strlen(char *s)    ;
  12. short    english(char *temp,char *tmpresult,short n)    ;
  13.  
  14. pascal void main(char *text,char *result)
  15. {
  16.     char    thestring[20],temp[4],tmpresult[256];
  17.     short    i,j,l,res        ;
  18.     short    plurial            ;
  19.     
  20.         RememberA0()        ;
  21.         SetUpA4()            ;
  22.         text[12] = 0        ;    /* max =  999 999 999 999 */
  23.         result[0] = '\0'    ;    
  24.         strcpy(thestring,text)    ;
  25.         if( strlen(thestring) != 0 )
  26.         {
  27.             while (thestring[0] == '0')
  28.                 for (i=0;thestring[i]!=0;thestring[i]=thestring[i+1],i++)    ;
  29.             plurial = 0 ;
  30.             if ( (l = strlen(thestring)) )
  31.             {
  32.                 reverse(thestring)    ;
  33.                 if (l < 12)
  34.                 {
  35.                     for ( i=l ; i<12 ; i++ )
  36.                         thestring[i] = '0'    ;
  37.                     thestring[12] = 0    ;
  38.                 }
  39.                 for ( i=3 ; i>=0 ; i--)
  40.                 {
  41.                     for ( j=3*i ; j<3*(i+1) ; j++)
  42.                         temp[j-3*i] = thestring[j]    ;
  43.                     temp[3] = 0         ;
  44.                     tmpresult[0] = 0    ;
  45.                     res = english(temp,tmpresult,i)    ;
  46.                     if ( (res > 1) || ((res == 1) && (i != 0)) )
  47.                         plurial = 1    ;
  48.                     strcat(result,tmpresult)        ;
  49.                 }
  50.             }
  51.             else
  52.                 strcpy(result,unites[0])    ;
  53.         }
  54.         RestoreA4()    ;
  55. }    
  56.  
  57. short english(char *temp,char *tmpresult,short n)
  58. {
  59.     register int res,x,y,z;
  60.  
  61.         reverse(temp);
  62.         x = temp[0]-'0'    ;
  63.         y = temp[1]-'0'    ;
  64.         z = temp[2]-'0'    ;
  65.         res = ((x*10)+y)*10+z;
  66.         if(res!=0)
  67.         {
  68.             if(x)
  69.             {
  70.                 strcpy(tmpresult,unites[x]);
  71.                 strcat(tmpresult,multiples[0]);
  72.                 strcat(tmpresult," ");
  73.             }
  74.             if(y>1)
  75.             {
  76.                 strcat(tmpresult,dizaines[y]);
  77.             }
  78.             if(z)
  79.                 if(y==1)
  80.                     strcat(tmpresult,special[z]);
  81.                 else
  82.                 {
  83.                     if ( (z != 1) || (x != 0) || (y != 0) || (res == 1) )
  84.                         strcat(tmpresult,unites[z]);
  85.                 }
  86.             else
  87.                 if(y==1)
  88.                     strcat(tmpresult,dizaines[1]);
  89.             if (res && n)
  90.                 strcat(tmpresult,multiples[n])    ;
  91.             if ((res>1) &&(n>1))
  92.                 strcat(tmpresult,"s");
  93.             if (res &&(n>0))
  94.                 strcat(tmpresult," ");
  95.         }
  96. }
  97.  
  98. char * strcpy(char *s1,char *s2)
  99. {
  100.     asm {
  101.         movea.l    s1,a0        ;  A0 = s1
  102.         movea.l    s2,a1        ;  A1 = s2
  103.         move.l    a0,d0            ;  D0.L = result
  104. @1        move.b    (a1)+,(a0)+
  105.         bne.s    @1
  106.     }
  107. }
  108.  
  109.  
  110. char *strcat(char *s1,char *s2)
  111. {
  112.     asm {
  113.         movea.l    s1,a0        ;  A0 = s1
  114.         movea.l    s2,a1        ;  A1 = s2
  115.         move.l    a0,d0            ;  D0.L = result
  116. @1        tst.b    (a0)+
  117.         bne.s    @1
  118.         subq.l    #1,a0
  119. @2        move.b    (a1)+,(a0)+
  120.         bne.s    @2
  121.     }
  122. }
  123.  
  124. short strlen(char *s)
  125. {
  126.     asm {
  127.         moveq    #-1,d0            ;  D0.L = result
  128.         movea.l    s,a0        ;  A0 = s
  129. @1        addq.l    #1,d0
  130.         tst.b    (a0)+
  131.         bne.s    @1
  132.     }
  133. }
  134.  
  135. void reverse(char *s)
  136. {
  137.     register short        i,j        ;
  138.     register char        c        ;
  139.         
  140.         for(i=0,j=strlen(s)-1;i<j;i++,j--)
  141.         {
  142.             c = s[j]            ;
  143.             s[j] = s[i]            ;
  144.             s[i] = c            ;
  145.         }
  146. }
  147.