@@ -591,30 +591,30 @@ static void initValue(long lng_val) {
591
591
int i ,div ,dig ;
592
592
char tmp [2 ]= " " ;
593
593
594
- // set some obvious things
594
+ /* set some obvious things */
595
595
value .val = lng_val >=0 ?lng_val :lng_val * (-1 );
596
596
value .sign = lng_val >=0 ?'+' :'-' ;
597
597
value .maxdigits = log10 (2 )* (8 * sizeof (long )-1 );
598
598
599
- // determine the number of digits
599
+ /* determine the number of digits */
600
600
for (i = 1 ;i <=value .maxdigits ;i ++ ) {
601
601
if ((int )(value .val /pow (10 ,i ))!= 0 ) {
602
602
value .digits = i + 1 ;
603
603
}
604
604
}
605
605
value .remaining = value .digits ;
606
606
607
- // convert the long to string
607
+ /* convert the long to string */
608
608
value .val_string = (char * )malloc (value .digits + 1 );
609
609
for (i = value .digits ;i > 0 ;i -- ) {
610
610
div = pow (10 ,i );
611
611
dig = (value .val %div ) / (div /10 );
612
612
tmp [0 ]= (char )(dig + 48 );
613
613
strcat (value .val_string ,tmp );
614
614
}
615
- // safety-net
615
+ /* safety-net */
616
616
value .val_string [value .digits ]= '\0' ;
617
- // clean up
617
+ /* clean up */
618
618
free (tmp );
619
619
}
620
620
@@ -641,34 +641,38 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
641
641
int i ,j ,k ,dotpos ;
642
642
int leftalign = 0 ,blank = 0 ,sign = 0 ,entity = 0 ,
643
643
entitydone = 0 ,signdone = 0 ,brackets_ok = 0 ;
644
- char temp [fmt_len + 1 ],tmp [2 ]= " " ,lastfmt = ' ' ,fmtchar = ' ' ;
644
+ char * temp ;
645
+ char tmp [2 ]= " " ;
646
+ char lastfmt = ' ' ,fmtchar = ' ' ;
647
+
648
+ temp = (char * )malloc (fmt_len + 1 );
645
649
646
- // put all info about the long in a struct
650
+ /* put all info about the long in a struct */
647
651
initValue (lng_val );
648
652
649
- // '<' is the only format, where we have to align left
653
+ /* '<' is the only format, where we have to align left */
650
654
if (strchr (fmt , (int )'<' )) {
651
655
leftalign = 1 ;
652
656
}
653
657
654
- // '(' requires ')'
658
+ /* '(' requires ')' */
655
659
if (strchr (fmt , (int )'(' )&& strchr (fmt , (int )')' )) {
656
660
brackets_ok = 1 ;
657
661
}
658
662
659
- // get position of the right-most dot in the format-string
660
- // and fill the temp-string wit '0's up to there.
663
+ /* get position of the right-most dot in the format-string */
664
+ /* and fill the temp-string wit '0's up to there. */
661
665
dotpos = getRightMostDot (fmt );
662
666
663
- // start to parse the formatstring
667
+ /* start to parse the formatstring */
664
668
temp [0 ]= '\0' ;
665
- j = 0 ;// position in temp
666
- k = value .digits - 1 ;// position in the value_string
669
+ j = 0 ;/* position in temp */
670
+ k = value .digits - 1 ;/* position in the value_string */
667
671
for (i = fmt_len - 1 ,j = 0 ;i >=0 ;i -- ,j ++ ) {
668
- // qualify, where we are in the value_string
672
+ /* qualify, where we are in the value_string */
669
673
if (k < 0 ) {
670
674
if (leftalign ) {
671
- // can't use strncat(,,0) here, Solaris would freek out
675
+ /* can't use strncat(,,0) here, Solaris would freek out */
672
676
temp [j ]= '\0' ;
673
677
break ;
674
678
}
@@ -680,7 +684,7 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
680
684
sign = 1 ;
681
685
}
682
686
}
683
- // if we're right side of the right-most dot, print '0'
687
+ /* if we're right side of the right-most dot, print '0' */
684
688
if (dotpos >=0 && dotpos <=i ) {
685
689
if (dotpos < i ) {
686
690
if (fmt [i ]== ')' )tmp [0 ]= value .sign == '-' ?')' :' ' ;
@@ -692,10 +696,10 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
692
696
strcat (temp ,tmp );
693
697
continue ;
694
698
}
695
- // the ',' needs special attention, if it is in the blank area
699
+ /* the ',' needs special attention, if it is in the blank area */
696
700
if (blank && fmt [i ]== ',' )fmtchar = lastfmt ;
697
701
else fmtchar = fmt [i ];
698
- // analyse this format-char
702
+ /* analyse this format-char */
699
703
switch (fmtchar ) {
700
704
case ',' :
701
705
tmp [0 ]= ',' ;
@@ -755,10 +759,10 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
755
759
lastfmt = fmt [i ];
756
760
k -- ;
757
761
}
758
- // safety-net
762
+ /* safety-net */
759
763
temp [fmt_len ]= '\0' ;
760
764
761
- // reverse the temp-string and put it into the outbuf
765
+ /* reverse the temp-string and put it into the outbuf */
762
766
temp_len = strlen (temp );
763
767
outbuf [0 ]= '\0' ;
764
768
for (i = temp_len - 1 ;i >=0 ;i -- ) {
@@ -767,8 +771,8 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
767
771
}
768
772
outbuf [temp_len ]= '\0' ;
769
773
770
- // cleaning up
771
- free (tmp );
774
+ /* cleaning up */
775
+ free (temp );
772
776
free (value .val_string );
773
777
774
778
return 0 ;