Subversion Repositories SvarDOS

Rev

Rev 2223 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2223 Rev 2245
Line 737... Line 737...
737
 
737
 
738
  return(res);
738
  return(res);
739
}
739
}
740
 
740
 
741
 
741
 
-
 
742
/* divides an unsigned long by 10 using 16bit division */
-
 
743
static unsigned short divulong10(unsigned long *n) {
-
 
744
  unsigned short a, b;
-
 
745
  unsigned short rem;
-
 
746
  const long adj[10] = {-1, 6553, 13107, 19660, 26214, 32767, 39321, 45875, 52428, 58982};
-
 
747
 
-
 
748
  b = *n;
-
 
749
  *n >>= 16;
-
 
750
  a = *n;
-
 
751
 
-
 
752
  rem = ((a % 10) << 4) + (b % 10);
-
 
753
  rem %= 10;
-
 
754
 
-
 
755
  /* AB / 10 = (((A / 10) + ((A % 10) / 10)) << 16) + (B / 10) */
-
 
756
 
-
 
757
  *n = (a / 10);
-
 
758
  *n <<= 16;
-
 
759
  *n += b / 10;
-
 
760
 
-
 
761
  /* I have no clue about the math behind this, found out the cyclic relation
-
 
762
   * using brute force */
-
 
763
  *n += adj[a % 10];
-
 
764
  if ((b % 10) >= (((a % 10) * 4) % 10)) *n += 1;
-
 
765
 
-
 
766
  return(rem);
-
 
767
}
-
 
768
 
-
 
769
 
742
/* computes a formatted integer number based on NLS patterns found in p
770
/* computes a formatted integer number based on NLS patterns found in p
743
 * returns length of result */
771
 * returns length of result */
744
unsigned short nls_format_number(char *s, unsigned long num, const struct nls_patterns *p) {
772
unsigned short nls_format_number(char *s, unsigned long num, const struct nls_patterns *p) {
745
  unsigned short sl = 0, i;
773
  unsigned short sl = 0, i;
746
  unsigned char thcount = 0;
774
  unsigned char thcount = 0;
747
 
775
 
748
  /* write the value (reverse) with thousand separators (if any defined) */
776
  /* write the value (reverse) with thousand separators (if any defined) */
749
  do {
777
  do {
-
 
778
    unsigned short rem;
750
    if ((thcount == 3) && (p->thousep[0] != 0)) {
779
    if ((thcount == 3) && (p->thousep[0] != 0)) {
751
      s[sl++] = p->thousep[0];
780
      s[sl++] = p->thousep[0];
752
      thcount = 0;
781
      thcount = 0;
753
    }
782
    }
754
    s[sl++] = '0' + num % 10;
783
    rem = divulong10(&num);
755
    num /= 10;
784
    s[sl++] = '0' + rem;
756
    thcount++;
785
    thcount++;
757
  } while (num > 0);
786
  } while (num > 0);
758
 
787
 
759
  /* terminate the string */
788
  /* terminate the string */
760
  s[sl] = 0;
789
  s[sl] = 0;