summaryrefslogtreecommitdiff
path: root/src/fmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fmt.c')
-rw-r--r--src/fmt.c79
1 files changed, 53 insertions, 26 deletions
diff --git a/src/fmt.c b/src/fmt.c
index 52ab5dc..eaf98fb 100644
--- a/src/fmt.c
+++ b/src/fmt.c
@@ -7,65 +7,91 @@
@brief formating differnt inputs format for output printing
*/
-unsigned int fmt_str(register char *s,register char *t)
+unsigned int fmt_str(register char *s, register char *t)
{
register unsigned int len;
char ch;
len = 0;
- if (s) { while ((ch = t[len])) s[len++] = ch; }
- else while (t[len]) len++;
+ if (s) {
+ while ((ch = t[len])) s[len++] = ch;
+ } else
+ while (t[len]) len++;
return len;
}
-unsigned int fmt_strn(register char *s,register char *t,register unsigned int n)
+unsigned int fmt_strn(register char *s, register char *t, register unsigned int n)
{
register unsigned int len;
char ch;
len = 0;
- if (s) { while (n-- && (ch = t[len])) s[len++] = ch; }
- else while (n-- && t[len]) len++;
+ if (s) {
+ while (n-- && (ch = t[len])) s[len++] = ch;
+ } else
+ while (n-- && t[len]) len++;
return len;
}
-unsigned int fmt_uint(register char *s,register unsigned int u)
+unsigned int fmt_uint(register char *s, register unsigned int u)
{
- register unsigned long l; l = u; return fmt_ulong(s,l);
+ register unsigned long l;
+ l = u;
+ return fmt_ulong(s, l);
}
-unsigned int fmt_uint0(char *s,unsigned int u,unsigned int n)
+unsigned int fmt_uint0(char *s, unsigned int u, unsigned int n)
{
unsigned int len;
- len = fmt_uint(FMT_LEN,u);
- while (len < n) { if (s) *s++ = '0'; ++len; }
- if (s) fmt_uint(s,u);
+ len = fmt_uint(FMT_LEN, u);
+ while (len < n) {
+ if (s) *s++ = '0';
+ ++len;
+ }
+ if (s) fmt_uint(s, u);
return len;
}
-unsigned int fmt_ulong(register char *s,register unsigned long u)
+unsigned int fmt_ulong(register char *s, register unsigned long u)
{
- register unsigned int len; register unsigned long q;
- len = 1; q = u;
- while (q > 9) { ++len; q /= 10; }
+ register unsigned int len;
+ register unsigned long q;
+ len = 1;
+ q = u;
+ while (q > 9) {
+ ++len;
+ q /= 10;
+ }
if (s) {
s += len;
- do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */
+ do {
+ *--s = '0' + (u % 10);
+ u /= 10;
+ } while (u); /* handles u == 0 */
}
return len;
}
-unsigned int fmt_xlong(register char *s,register unsigned long u)
+unsigned int fmt_xlong(register char *s, register unsigned long u)
{
- register unsigned int len; register unsigned long q;
- len = 1; q = u;
- while (q > 15) { ++len; q /= 16; }
+ register unsigned int len;
+ register unsigned long q;
+ len = 1;
+ q = u;
+ while (q > 15) {
+ ++len;
+ q /= 16;
+ }
if (s) {
s += len;
- do { *--s = tohex(u % 16); u /= 16; } while(u); /* handles u == 0 */
+ do {
+ *--s = tohex(u % 16);
+ u /= 16;
+ } while (u); /* handles u == 0 */
}
return len;
}
-char tohex(char num) {
+char tohex(char num)
+{
if (num < 10)
return num + '0';
else if (num < 16)
@@ -74,11 +100,12 @@ char tohex(char num) {
return -1;
}
-int fromhex(unsigned char c) {
+int fromhex(unsigned char c)
+{
if (c >= '0' && c <= '9')
- return c-'0';
+ return c - '0';
else if (c >= 'A' && c <= 'F')
- return c -'A' + 10;
+ return c - 'A' + 10;
else if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
return -1;