Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
Done #7 (and more, see details)
Browse files Browse the repository at this point in the history
- Changed #E to E: to make a little more sense
- Now using an _fwprintf_p function to print to stderr
- Some code factoring
  • Loading branch information
dd86k committed Mar 30, 2018
1 parent 6464106 commit 38de9a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 42 deletions.
45 changes: 14 additions & 31 deletions src/ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
void scan() {
uint32_t s;
if (_ddread(&s, 4)) {
puts("#E Could not read file.");
puts("E: Could not read file.");
return;
}

Expand Down Expand Up @@ -117,17 +117,12 @@ void scan() {
report("Kodak Cineon image (DPX)");
return;

case 0x01434E52:
case 0x02434E52: // RNC\x01 or \x02
case 0x01434E52: case 0x02434E52: // RNC\x01 or \x02
reportn("Rob Northen Compressed archive v");
switch (s) { // Very lazy
case 0x01000000: puts("2"); return;
case 0x02000000: puts("1"); return;
}
printf("%d\n", s >> 24);
return;

case 0x58504453: // "SDPX", "XPDS"
case 0x53445058:
case 0x58504453: case 0x53445058: // "SDPX", "XPDS"
report("SMPTE DPX image");
return;

Expand All @@ -139,9 +134,7 @@ void scan() {
scan_bpg();
return;

case 0xDBFFD8FF:
case 0xE0FFD8FF:
case 0xE1FFD8FF:
case 0xDBFFD8FF: case 0xE0FFD8FF: case 0xE1FFD8FF:
report("Joint Photographic Experts Group image");
return;

Expand Down Expand Up @@ -182,10 +175,8 @@ void scan() {
scan_rpf(s);
return;

case 0x14000000:
case 0x18000000:
case 0x1C000000:
case 0x20000000: {
case 0x14000000: case 0x18000000:
case 0x1C000000: case 0x20000000: {
uint32_t b[2];
_ddread(&b, sizeof(b));
switch (*b) {
Expand Down Expand Up @@ -265,10 +256,9 @@ void scan() {
return;

// Only the last signature is within the documentation.
case 0x04034B42: // PKZIP, which includes
case 0x06054B42: // JAR, ODF, OOXML, EPUB (PKware ZIP format)
case 0x08074B42:
case 0x04034B50:
// PKWare ZIP format: JAR, ODF, OOXML, EPUB
case 0x04034B42: case 0x06054B42:
case 0x08074B42: case 0x04034B50:
scan_zip();
return;

Expand Down Expand Up @@ -456,8 +446,7 @@ void scan() {
scan_rpm();
return;

case 0x44415749: // "IWAD"
case 0x44415750: { // "PWAD"
case 0x44415749: case 0x44415750: { // "IWAD", "PWAD"
int b[2]; // Reads as ints.
_ddread(&b, sizeof(b));
reportn(s == 0x44415750 ? "PWAD" : "IWAD");
Expand Down Expand Up @@ -519,9 +508,7 @@ void scan() {
return;

// Apple DMG disk image
case 0x0D730178:
case 0x6B6F6C79: // "koly"
case 0x6d697368: // "mish"
case 0x0D730178: case 0x6B6F6C79: case 0x6d697368: // ?, "koly", "mish"
report("Apple disk (dmg)");
return;

Expand Down Expand Up @@ -550,11 +537,11 @@ void scan() {
// ...
*/
return;

case 0x0c0901fe:
report("MySQL FORM");
return;

case 0xff743064: // '\377t0c'
scan_idx();
return;
Expand Down Expand Up @@ -640,10 +627,6 @@ void scan() {
} // 4 Byte signatures
} // scan

/*
* For Windows platforms, it used to be _wprintf_p
*/

/**
* Report to stdout the filetype with a newline
* Params: s = Type
Expand Down
20 changes: 9 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void sa(char *a) {
case 'c': ++Continue; break;
case '-': --_args; return;
default:
fprintf(stderr, "#E -%c: Unknown argument\n", *a);
fprintf(stderr, "E: -%c: Unknown argument\n", *a);
exit(1);
}
}
Expand All @@ -73,7 +73,7 @@ void sb(wchar_t *a) {
help();
if (_strcmpw_l(a, O_VERSION, 6) == 0)
version();
_fwprintf_p(stderr, L"#E --%s: Unknown argument\n", a);
_fwprintf_p(stderr, L"E: --%s: Unknown argument\n", a);
#else
#define O_HELP "help"
#define O_VERSION "version"
Expand All @@ -82,7 +82,7 @@ void sb(char *a) {
help();
if (_strcmp_l(a, O_VERSION, 6) == 0)
version();
fprintf(stderr, "#E --%s: Unknown argument\n", a);
fprintf(stderr, "E: --%s: Unknown argument\n", a);
#endif
exit(1);
}
Expand All @@ -105,7 +105,7 @@ MAIN {
uint32_t a = GetFileAttributesW(_currf);
if (a == 0xFFFFFFFF) { // INVALID_FILE_ATTRIBUTES
EWFO: _fwprintf_p(stderr, //TODO: GetLastError (Windows)
L"#E Could not open file: %s\n",
L"E: Could not open file: %s\n",
_currf
);
return 1;
Expand All @@ -119,12 +119,10 @@ EWFO: _fwprintf_p(stderr, //TODO: GetLastError (Windows)
_fo: f = CreateFileW(_currf,
GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (!f)
goto EWFO;
if (!f) goto EWFO;
switch (GetFileType(f)) {
case 0x0001: // FILE_TYPE_DISK
report("Disk/block device");
return 0;
//case 0x0001: // FILE_TYPE_DISK
// return 0; // Normal files fall here, because they're on disk
case 0x0002: // FILE_TYPE_CHAR
report("Character device");
return 0;
Expand Down Expand Up @@ -153,7 +151,7 @@ _fo: f = CreateFileW(_currf,
case S_IFREG:
_fo: f = fopen(_currf, "rb"); // maybe use _s?
if (!f) {
fprintf(stderr, "#E Could not open file: %s\n", _currf);
fprintf(stderr, "E: Could not open file: %s\n", _currf);
return 2;
}
scan();
Expand All @@ -163,7 +161,7 @@ _fo: f = fopen(_currf, "rb"); // maybe use _s?
default: report_unknown(); break;
}
} else {
perror("#E");
perror("E:");
}
#endif
} // while
Expand Down

0 comments on commit 38de9a2

Please # to comment.