psp-fixup-imports: remove one gratuitous level of indentation

there's so many indented blocks, it's hardly possible to read the code even
on a terminal that's been resized to 160 chars wide.
This commit is contained in:
rofl0r
2022-03-23 16:37:20 +00:00
parent cc887d731f
commit a797442dd9

View File

@@ -499,116 +499,114 @@ int load_mapfile(const char *mapfile)
struct ImportMap *currmap = NULL; struct ImportMap *currmap = NULL;
int line = 0; int line = 0;
if(mapfile != NULL) if(mapfile == NULL) return ret;
do
{ {
do FILE *fp;
fp = fopen(mapfile, "r");
if(fp != NULL)
{ {
FILE *fp; while(fgets(buf, sizeof(buf), fp))
fp = fopen(mapfile, "r");
if(fp != NULL)
{ {
while(fgets(buf, sizeof(buf), fp)) line++;
strip_wsp(buf);
if((buf[0]) && (buf[0] != '#'))
{ {
line++; if(buf[0] == '@')
strip_wsp(buf);
if((buf[0]) && (buf[0] != '#'))
{ {
if(buf[0] == '@') struct ImportMap *temp;
temp = (struct ImportMap *) malloc(sizeof(struct ImportMap));
if(temp == NULL)
{ {
struct ImportMap *temp; printf("Error allocating memory for import map\n");
ret = 0;
break;
}
temp = (struct ImportMap *) malloc(sizeof(struct ImportMap)); memset(temp, 0, sizeof(struct ImportMap));
if(temp == NULL) if(currmap == NULL)
{ {
printf("Error allocating memory for import map\n"); g_map = temp;
ret = 0; }
break; else
} {
temp->next = currmap;
g_map = temp;
}
memset(temp, 0, sizeof(struct ImportMap)); currmap = temp;
if(currmap == NULL) if(buf[1])
{ {
g_map = temp; strncpy(currmap->name, &buf[1], 32);
} currmap->name[31] = 0;
else }
{ else
temp->next = currmap; {
g_map = temp; printf("Invalid library name at line %d\n", line);
} break;
}
currmap = temp; if(g_verbose)
if(buf[1]) {
{ printf("Mapping library %s\n", currmap->name);
strncpy(currmap->name, &buf[1], 32); }
currmap->name[31] = 0; }
} else
else {
{ unsigned int oldnid;
printf("Invalid library name at line %d\n", line); unsigned int newnid;
break; char *endp;
}
if(g_verbose) if(currmap->count == MAX_MAPNIDS)
{
printf("Error, number of defined nids exceed maximum\n");
break;
}
/* Hex data should be prefixed with 0 */
if(buf[0] == '0')
{
errno = 0;
oldnid = strtoul(buf, &endp, 16);
if((errno != 0) || (*endp != ':'))
{ {
printf("Mapping library %s\n", currmap->name); printf("Invalid NID entry on line %d\n", line);
continue;
} }
} }
else else
{ {
unsigned int oldnid; unsigned char hash[SHA1_DIGEST_SIZE];
unsigned int newnid;
char *endp;
if(currmap->count == MAX_MAPNIDS) endp = strchr(buf, ':');
if(endp == NULL)
{ {
printf("Error, number of defined nids exceed maximum\n"); printf("Invalid NID entry on line %d\n", line);
break; continue;
} }
/* Hex data should be prefixed with 0 */ sha1(hash, (unsigned char *) buf, endp-buf);
if(buf[0] == '0') oldnid = hash[0] | (hash[1] << 8) | (hash[2] << 16) | (hash[3] << 24);
{
errno = 0;
oldnid = strtoul(buf, &endp, 16);
if((errno != 0) || (*endp != ':'))
{
printf("Invalid NID entry on line %d\n", line);
continue;
}
}
else
{
unsigned char hash[SHA1_DIGEST_SIZE];
endp = strchr(buf, ':');
if(endp == NULL)
{
printf("Invalid NID entry on line %d\n", line);
continue;
}
sha1(hash, (unsigned char *) buf, endp-buf);
oldnid = hash[0] | (hash[1] << 8) | (hash[2] << 16) | (hash[3] << 24);
}
newnid = strtoul(endp+1, &endp, 16);
if(g_verbose)
{
fprintf(stderr, "NID Mapping 0x%08X to 0x%08X\n", oldnid, newnid);
}
currmap->nids[currmap->count].oldnid = oldnid;
currmap->nids[currmap->count].newnid = newnid;
currmap->count++;
} }
newnid = strtoul(endp+1, &endp, 16);
if(g_verbose)
{
fprintf(stderr, "NID Mapping 0x%08X to 0x%08X\n", oldnid, newnid);
}
currmap->nids[currmap->count].oldnid = oldnid;
currmap->nids[currmap->count].newnid = newnid;
currmap->count++;
} }
} }
fclose(fp);
} }
fclose(fp);
} }
while(0);
} }
while(0);
return ret; return ret;
} }