Browse code

print_q -> q2str and it's interface aligned to other similar functions.

Jan Janak authored on 26/04/2004 19:19:28
Showing 1 changed files
... ...
@@ -102,31 +102,41 @@ static inline size_t len_q(qvalue_t q)
102 102
 
103 103
 
104 104
 /*
105
- * Print the q parameter
105
+ * Convert q value to string
106 106
  */
107
-static inline size_t print_q(char* p, qvalue_t q)
107
+static inline char* q2str(qvalue_t q, unsigned int* len)
108 108
 {
109
+	static char buf[sizeof("0.123")];
110
+	char* p;
111
+
112
+	p = buf;
109 113
 	if (q == Q_UNSPECIFIED) {
110
-		return 0;
114
+		     /* Do nothing */
111 115
 	} else if (q >= MAX_Q) {
112 116
 		memcpy(p, MAX_Q_STR, MAX_Q_STR_LEN);
113
-		return MAX_Q_STR_LEN;
117
+		p += MAX_Q_STR_LEN;
114 118
 	} else if (q <= MIN_Q) {
115 119
 		memcpy(p, MIN_Q_STR, MIN_Q_STR_LEN);
116
-		return MIN_Q_STR_LEN;
120
+		p += MIN_Q_STR_LEN;
121
+	} else {
122
+		memcpy(p, Q_PREFIX, Q_PREFIX_LEN);
123
+		p += Q_PREFIX_LEN;
124
+		
125
+		*p++ = q / 100 + '0';
126
+		q %= 100;
127
+		if (!q) goto end;
128
+
129
+		*p++ = q / 10 + '0';
130
+		q %= 10;
131
+		if (!q) goto end;
132
+
133
+		*p = q + '0';
134
+		*len = Q_PREFIX_LEN + 3;
117 135
 	}
118
-	
119
-	memcpy(p, Q_PREFIX, Q_PREFIX_LEN);
120
-	p += Q_PREFIX_LEN;
121
-
122
-	*p++ = q / 100 + '0';
123
-	q %= 100;
124
-	if (!q) return Q_PREFIX_LEN + 1;
125
-	*p++ = q / 10 + '0';
126
-	q %= 10;
127
-	if (!q) return Q_PREFIX_LEN + 2;
128
-	*p = q + '0';
129
-	return Q_PREFIX_LEN + 3;
136
+ end:
137
+	*p = '\0';
138
+	*len = p - buf;
139
+	return buf;
130 140
 }
131 141
 
132 142