forked from shattered/macro11
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add varrec, a little tool to convert files with variable records to b…
…yte streams.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* A little tool to convert files with variable records to byte streams. | ||
* | ||
* Each record consist of 2 bytes of length (little endian) followed by | ||
* that number of data bytes. | ||
* | ||
* If the length is odd, there is a padding byte. This byte does not have | ||
* to be 0. | ||
*/ | ||
#include <stdio.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
while (!feof(stdin)) { | ||
int count, savecount; | ||
unsigned char ch; | ||
|
||
ch = getchar(); | ||
count = ch; | ||
ch = getchar(); | ||
count += ch << 8; | ||
|
||
savecount = count; | ||
|
||
while (count-- > 0) { | ||
ch = getchar(); | ||
putchar(ch); | ||
} | ||
|
||
if (savecount & 1) { | ||
getchar(); | ||
} | ||
} | ||
} |