From 640a08101fb4c5d09502bc17dca933a3a6a76d68 Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Mon, 8 Apr 2024 01:59:14 +0000 Subject: Sun, Apr 7, 2024, 6:59 PM -07:00 --- wk4/pset/recover/recover.c | 59 ++++++---------------------------------------- 1 file changed, 7 insertions(+), 52 deletions(-) (limited to 'wk4/pset/recover/recover.c') diff --git a/wk4/pset/recover/recover.c b/wk4/pset/recover/recover.c index 1f96528..c10d032 100644 --- a/wk4/pset/recover/recover.c +++ b/wk4/pset/recover/recover.c @@ -1,14 +1,15 @@ #include #include +#include #include #include #include #include -#include int main(int argc, char *argv[]) { - if (argc != 2) { + if (argc != 2) + { printf("Usage: ./recover infile\n"); return 1; } @@ -27,16 +28,11 @@ int main(int argc, char *argv[]) char name[8]; // restoring jpegs - while(fread(buffer, 1, 512, card) == 512) + while (fread(buffer, 1, 512, card) == 512) { // check if this is a new picture - if ( - buffer[0] == 0xff && - buffer[1] == 0xd8 && - buffer[2] == 0xff && - buffer[3] >= 0xe0 && - buffer[3] <= 0xef - ) + if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && buffer[3] >= 0xe0 && + buffer[3] <= 0xef) { // this is a jpeg, make a new file from it files++; @@ -45,7 +41,7 @@ int main(int argc, char *argv[]) fwrite(buffer, 1, 512, point); fclose(point); } - else if(files >= 0) // if it is part of a previous picture, add to it + else if (files >= 0) // if it is part of a previous picture, add to it { FILE *point = fopen(name, "a"); fwrite(buffer, 1, 512, point); @@ -53,45 +49,4 @@ int main(int argc, char *argv[]) } } fclose(card); - - /* - files = 0 - for (file length) - { - if (first 3 bytes are 0xff 0xd8 0xff AND 4th byte is 0xe* (* denotes anything)) - fread(ptr, ) - { - this is a photo; remember the pointer (call it point) - int photolength = 0; - // look through the blocks ahead of this one for a new photo - for (file length left) - { - photolength++; - if (first 3 bytes are 0xff 0xd8 0xff AND 4th byte is 0xe* (* denotes anything)) - { - // this is the photo length - break - } - } - filename = files.jpg - files++ - Open output file with name (filename) - - // make buffer space to store the data - uint32_t data[photolength][16]; - // read the photo to data in blocks of 32 bits - fread(&data, sizeof(uint8_t), 16 * photolength, card); - // write the photo from data - fwrite(&data, sizeof(uint8_t), 16 * photolength, point); - // Close the photo file - // repeat this process for other photos - } - } - - - - - - */ - } -- cgit v1.2.3