summaryrefslogtreecommitdiff
path: root/src/scan.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scan.c')
-rw-r--r--src/scan.c86
1 files changed, 48 insertions, 38 deletions
diff --git a/src/scan.c b/src/scan.c
index da3d8ad..4d6b918 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -7,24 +7,24 @@
@brief scanning/conversion of strings to different variable types
*/
-static long int fromhex(unsigned char c)
+static long int fromhex(unsigned char c)
{
- if (c>='0' && c<='9')
- return c-'0';
- else if (c>='A' && c<='F')
- return c-'A'+10;
- else if (c>='a' && c<='f')
- return c-'a'+10;
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ else if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+ else if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
return -1;
}
-unsigned int scan_0x(register const char *s,register unsigned int *u)
+unsigned int scan_0x(register const char *s, register unsigned int *u)
{
register unsigned int pos = 0;
register unsigned long result = 0;
register long int c;
- while ((c = fromhex((unsigned char) (s[pos]))) >= 0) {
+ while ((c = fromhex((unsigned char)(s[pos]))) >= 0) {
result = (result << 4) + c;
++pos;
}
@@ -32,89 +32,99 @@ unsigned int scan_0x(register const char *s,register unsigned int *u)
return pos;
}
-unsigned int scan_8long(register const char *s,register unsigned long *u)
+unsigned int scan_8long(register const char *s, register unsigned long *u)
{
register unsigned int pos = 0;
register unsigned long result = 0;
register unsigned long c;
- while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 8) {
+ while ((c = (unsigned long)(unsigned char)(s[pos] - '0')) < 8) {
result = result * 8 + c;
- ++pos;
+ ++pos;
}
*u = result;
return pos;
}
-unsigned int scan_uint(register const char *s,register unsigned int *u)
+unsigned int scan_uint(register const char *s, register unsigned int *u)
{
- register unsigned int pos;
+ register unsigned int pos;
unsigned long result;
- pos = scan_ulong(s,&result);
- *u = result;
+ pos = scan_ulong(s, &result);
+ *u = result;
return pos;
}
-unsigned int scan_plusminus(register const char *s,register int *sign)
+unsigned int scan_plusminus(register const char *s, register int *sign)
{
- if (*s == '+') { *sign = 1; return 1; }
- if (*s == '-') { *sign = -1; return 1; }
- *sign = 1; return 0;
+ if (*s == '+') {
+ *sign = 1;
+ return 1;
+ }
+ if (*s == '-') {
+ *sign = -1;
+ return 1;
+ }
+ *sign = 1;
+ return 0;
}
-unsigned int scan_long(register const char *s,register long *i)
+unsigned int scan_long(register const char *s, register long *i)
{
- int sign;
- unsigned long u;
+ int sign;
+ unsigned long u;
register unsigned int len;
- len = scan_plusminus(s,&sign); s += len;
- len += scan_ulong(s,&u);
- if (sign < 0) *i = -u; else *i = u;
+ len = scan_plusminus(s, &sign);
+ s += len;
+ len += scan_ulong(s, &u);
+ if (sign < 0)
+ *i = -u;
+ else
+ *i = u;
return len;
}
-unsigned int scan_ulong(register const char *s,register unsigned long *u)
+unsigned int scan_ulong(register const char *s, register unsigned long *u)
{
register unsigned int pos = 0;
register unsigned long result = 0;
register unsigned long c;
- while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 10) {
+ while ((c = (unsigned long)(unsigned char)(s[pos] - '0')) < 10) {
result = result * 10 + c;
- ++pos;
+ ++pos;
}
*u = result;
return pos;
}
-unsigned int scan_xlong(const char *s,unsigned long *u)
+unsigned int scan_xlong(const char *s, unsigned long *u)
{
register const char *t = s;
register int l = 0;
register unsigned char c;
while ((c = fromhex(*t)) < 16) {
- l = (l<<4)+c;
+ l = (l << 4) + c;
++t;
}
- *u=l;
- return t-s;
+ *u = l;
+ return t - s;
}
-unsigned int scan_xint(const char *s,unsigned int *i)
+unsigned int scan_xint(const char *s, unsigned int *i)
{
register const char *t = s;
register unsigned int l = 0;
register unsigned char c;
- while ((l >> (sizeof(l)*8 - 4)) == 0
- && (c = (unsigned char)fromhex((unsigned char)*t))<16) {
- l= (l << 4) + c;
+ while ((l >> (sizeof(l) * 8 - 4)) == 0 && (c = (unsigned char)fromhex((unsigned char)*t)) < 16) {
+ l = (l << 4) + c;
++t;
}
*i = l;
- return (unsigned int)(t-s);
+ return (unsigned int)(t - s);
}