clang-format

This commit is contained in:
2024-09-10 13:03:02 -04:00
parent 53c617d779
commit d66450e427
381 changed files with 28864 additions and 34170 deletions

View File

@@ -46,56 +46,53 @@
* really report syntax errors or overflow in any useful way.
*/
int
atoi(const char *s)
{
static const char digits[] = "0123456789"; /* legal digits in order */
unsigned val=0; /* value we're accumulating */
int neg=0; /* set to true if we see a minus sign */
int atoi(const char *s) {
static const char digits[] = "0123456789"; /* legal digits in order */
unsigned val = 0; /* value we're accumulating */
int neg = 0; /* set to true if we see a minus sign */
/* skip whitespace */
while (*s==' ' || *s=='\t') {
s++;
}
/* skip whitespace */
while (*s == ' ' || *s == '\t') {
s++;
}
/* check for sign */
if (*s=='-') {
neg=1;
s++;
}
else if (*s=='+') {
s++;
}
/* check for sign */
if (*s == '-') {
neg = 1;
s++;
} else if (*s == '+') {
s++;
}
/* process each digit */
while (*s) {
const char *where;
unsigned digit;
/* process each digit */
while (*s) {
const char *where;
unsigned digit;
/* look for the digit in the list of digits */
where = strchr(digits, *s);
if (where==NULL) {
/* not found; not a digit, so stop */
break;
}
/* look for the digit in the list of digits */
where = strchr(digits, *s);
if (where == NULL) {
/* not found; not a digit, so stop */
break;
}
/* get the index into the digit list, which is the value */
digit = (where - digits);
/* get the index into the digit list, which is the value */
digit = (where - digits);
/* could (should?) check for overflow here */
/* could (should?) check for overflow here */
/* shift the number over and add in the new digit */
val = val*10 + digit;
/* shift the number over and add in the new digit */
val = val * 10 + digit;
/* look at the next character */
s++;
}
/* look at the next character */
s++;
}
/* handle negative numbers */
if (neg) {
return -val;
}
/* handle negative numbers */
if (neg) {
return -val;
}
/* done */
return val;
/* done */
return val;
}