Subversion Repositories SvarDOS

Rev

Rev 421 | Rev 426 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 421 Rev 423
Line 493... Line 493...
493
}
493
}
494
 
494
 
495
 
495
 
496
/* computes a formatted integer number based on NLS patterns found in p
496
/* computes a formatted integer number based on NLS patterns found in p
497
 * returns length of result */
497
 * returns length of result */
498
unsigned short nls_format_number(char *s, long num, const struct nls_patterns *p) {
498
unsigned short nls_format_number(char *s, unsigned long num, const struct nls_patterns *p) {
499
  unsigned short sl = 0, res, i;
499
  unsigned short sl = 0, i;
500
  unsigned char thcount = 0;
500
  unsigned char thcount = 0;
501
 
501
 
502
  /* handle negative values */
-
 
503
  if (num < 0) {
-
 
504
    s[sl++] = '-';
-
 
505
    num = 0 - num;
-
 
506
  }
-
 
507
 
-
 
508
  /* write the absolute value now */
502
  /* write the value (reverse) with thousand separators (if any defined) */
509
  do {
503
  do {
510
    if ((thcount == 3) && (p->thousep[0] != 0)) {
504
    if ((thcount == 3) && (p->thousep[0] != 0)) {
511
      s[sl++] = p->thousep[0];
505
      s[sl++] = p->thousep[0];
512
      thcount = 0;
506
      thcount = 0;
513
    }
507
    }
514
    s[sl++] = '0' + num % 10;
508
    s[sl++] = '0' + num % 10;
515
    num /= 10;
509
    num /= 10;
516
    thcount++;
510
    thcount++;
517
  } while (num > 0);
511
  } while (num > 0);
518
 
512
 
519
  /* terminate the string and remember its size */
513
  /* terminate the string */
520
  s[sl] = 0;
514
  s[sl] = 0;
521
  res = sl;
-
 
522
 
515
 
523
  /* reverse the string now (it has been build in reverse) */
516
  /* reverse the string now (has been built in reverse) */
524
  if (s[0] == '-') {
-
 
525
    sl--;
-
 
526
    s++;
-
 
527
  }
-
 
528
  for (i = 0; i <= (sl / 2); i++) {
517
  for (i = sl / 2 + (sl & 1); i < sl; i++) {
529
    thcount = s[i];
518
    thcount = s[i];
530
    s[i] = s[sl - (i + 1)];
519
    s[i] = s[sl - (i + 1)];   /* abc'de  if i=3 then ' <-> c */
531
    s[sl - (i + 1)] = thcount;
520
    s[sl - (i + 1)] = thcount;
532
  }
521
  }
533
 
522
 
534
  return(res);
523
  return(sl);
535
}
524
}