cake
/
libg1m
Archived
1
0
Fork 0

Tried to clean a bit

This commit is contained in:
Thomas Touhey 2016-12-30 19:51:39 +01:00
parent 2c6b760fc9
commit a33d7e8871
1 changed files with 33 additions and 22 deletions

View File

@ -12,6 +12,30 @@
case storage_entrytype_##TYPE:; \
struct storage_##TYPE *V = (struct storage_##TYPE*)&entry.raw_subheader;
/**
* rawfctombs:
* Temporary function, from raw FONTCHARACTER to multi-byte using buffers.
*
* @arg raw the raw buffer
* @arg count the number of fontcharacters in the count
* @arg final the final multi-byte buffer
*/
static void rawfctombs(FONTCHARACTER *raw, int count, char *final)
{
/* copy the raw data into a null-terminated buffer */
FONTCHARACTER traw[count + 1]; traw[count] = 0;
memcpy(traw, raw, count * sizeof(FONTCHARACTER));
/* big endian to host the raw buffer, and null terminate it */
int i;
for (i = 0; traw[i] != 0xffff && i < count; i++)
traw[i] = be16toh(traw[i]);
traw[i] = 0;
g1m_fcstombs(final, traw, 0);
}
/**
* g1m_parse_storage:
* Parse storage files.
@ -60,44 +84,30 @@ int g1m_parse_storage(g1m_t *handle, FILE *stream,
be32toh(sh->logical_sector_number));
#endif
break;
SUB(dh, directory)
log_info("[%02d,%02" PRIu16 "] Is a %s directory.", id, entry.uuid,
(special == 0x05) ? "deleted" : "active");
#if LOGLEVEL <= ll_info
FONTCHARACTER rawdir[13]; rawdir[12] = 0;
memcpy(rawdir, dh->name, 12 * sizeof(FONTCHARACTER));
{
int i;
for (i = 0; rawdir[i] != 0xffff && i < 12; i++)
rawdir[i] = be16toh(rawdir[i]);
rawdir[i] = 0;
}
char dirname[25]; g1m_fcstombs(dirname, rawdir, 0);
char dirname[25]; rawfctombs(dh->name, 12, dirname);
log_info("- Directory name: %s", dirname);
#endif
break;
SUB(fh, file)
log_info("[%02d,%02" PRIu16 "] Is a %s file.", id, entry.uuid,
(special == 0x05) ? "deleted" : "active");
#if LOGLEVEL <= ll_info
FONTCHARACTER rawname[13]; rawname[12] = 0;
memcpy(rawname, fh->name, 12 * sizeof(FONTCHARACTER));
{
int i;
for (i = 0; rawname[i] != 0xffff && i < 12; i++)
rawname[i] = be16toh(rawname[i]);
rawname[i] = 0;
}
char name[25]; g1m_fcstombs(name, rawname, 0);
log_info("- File name: %s", name);
char filename[25]; rawfctombs(fh->name, 12, filename);
log_info("- File name: %s", filename);
if (be16toh(fh->directory_reference) == storage_entrytype_directory)
log_info("- Is in directory #%" PRIu16,
be16toh(fh->directory_number));
else
log_info("- Is in root.");
else log_info("- Is in root.");
#endif
break;
SUB(fgh, fragment)
log_info("[%02d,%02" PRIu16 "] Is a fragment.", id, entry.uuid);
log_info("- Points at sector #%" PRIu16,
@ -107,7 +117,8 @@ int g1m_parse_storage(g1m_t *handle, FILE *stream,
be16toh(fgh->fragment_id), be16toh(fgh->fragment_count),
be16toh(fgh->used_bytes), be16toh(fgh->used_bytes_offset));
break;
default:
default: /* we should know all of the types, but we never know */
log_info("[%02d,%02" PRIu16 "] Is unknown.", id, entry.uuid);
}
}