Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6520c66

Browse files
committed
Fix a few of the more blatantly unportable constructs in this file.
1 parent 3a1ed87 commit 6520c66

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -591,30 +591,30 @@ static void initValue(long lng_val) {
591591
int i, div, dig;
592592
char tmp[2] = " ";
593593

594-
// set some obvious things
594+
/* set some obvious things */
595595
value.val = lng_val >= 0 ? lng_val : lng_val * (-1);
596596
value.sign = lng_val >= 0 ? '+' : '-';
597597
value.maxdigits = log10(2)*(8*sizeof(long)-1);
598598

599-
// determine the number of digits
599+
/* determine the number of digits */
600600
for(i=1; i <= value.maxdigits; i++) {
601601
if ((int)(value.val / pow(10, i)) != 0) {
602602
value.digits = i+1;
603603
}
604604
}
605605
value.remaining = value.digits;
606606

607-
// convert the long to string
607+
/* convert the long to string */
608608
value.val_string = (char *)malloc(value.digits + 1);
609609
for(i=value.digits; i > 0; i--) {
610610
div = pow(10,i);
611611
dig = (value.val % div) / (div / 10);
612612
tmp[0] = (char)(dig + 48);
613613
strcat(value.val_string, tmp);
614614
}
615-
// safety-net
615+
/* safety-net */
616616
value.val_string[value.digits] = '\0';
617-
// clean up
617+
/* clean up */
618618
free(tmp);
619619
}
620620

@@ -641,34 +641,38 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
641641
int i, j, k, dotpos;
642642
int leftalign = 0, blank = 0, sign = 0, entity = 0,
643643
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);
645649

646-
// put all info about the long in a struct
650+
/* put all info about the long in a struct */
647651
initValue(lng_val);
648652

649-
// '<' is the only format, where we have to align left
653+
/* '<' is the only format, where we have to align left */
650654
if (strchr(fmt, (int)'<')) {
651655
leftalign = 1;
652656
}
653657

654-
// '(' requires ')'
658+
/* '(' requires ')' */
655659
if (strchr(fmt, (int)'(') && strchr(fmt, (int)')')) {
656660
brackets_ok = 1;
657661
}
658662

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. */
661665
dotpos = getRightMostDot(fmt);
662666

663-
// start to parse the formatstring
667+
/* start to parse the formatstring */
664668
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 */
667671
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 */
669673
if (k < 0) {
670674
if (leftalign) {
671-
// can't use strncat(,,0) here, Solaris would freek out
675+
/* can't use strncat(,,0) here, Solaris would freek out */
672676
temp[j] = '\0';
673677
break;
674678
}
@@ -680,7 +684,7 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
680684
sign = 1;
681685
}
682686
}
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' */
684688
if (dotpos >= 0 && dotpos <= i) {
685689
if (dotpos < i) {
686690
if (fmt[i] == ')') tmp[0] = value.sign == '-' ? ')' : ' ';
@@ -692,10 +696,10 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
692696
strcat(temp, tmp);
693697
continue;
694698
}
695-
// the ',' needs special attention, if it is in the blank area
699+
/* the ',' needs special attention, if it is in the blank area */
696700
if (blank && fmt[i] == ',') fmtchar = lastfmt;
697701
else fmtchar = fmt[i];
698-
// analyse this format-char
702+
/* analyse this format-char */
699703
switch(fmtchar) {
700704
case ',':
701705
tmp[0] = ',';
@@ -755,10 +759,10 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
755759
lastfmt = fmt[i];
756760
k--;
757761
}
758-
// safety-net
762+
/* safety-net */
759763
temp[fmt_len] = '\0';
760764

761-
// reverse the temp-string and put it into the outbuf
765+
/* reverse the temp-string and put it into the outbuf */
762766
temp_len = strlen(temp);
763767
outbuf[0] = '\0';
764768
for(i=temp_len-1; i>=0; i--) {
@@ -767,8 +771,8 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
767771
}
768772
outbuf[temp_len] = '\0';
769773

770-
// cleaning up
771-
free(tmp);
774+
/* cleaning up */
775+
free(temp);
772776
free(value.val_string);
773777

774778
return 0;

0 commit comments

Comments
 (0)