Page 1 of 1

Subset 0 To complete subset 0, you need to implement code that can • print a list of the contents of an egg, and • print

Posted: Sat Nov 27, 2021 2:33 pm
by answerhappygod
Subset 0 To Complete Subset 0 You Need To Implement Code That Can Print A List Of The Contents Of An Egg And Print 1
Subset 0 To Complete Subset 0 You Need To Implement Code That Can Print A List Of The Contents Of An Egg And Print 1 (86.45 KiB) Viewed 78 times
Subset 0 To Complete Subset 0 You Need To Implement Code That Can Print A List Of The Contents Of An Egg And Print 2
Subset 0 To Complete Subset 0 You Need To Implement Code That Can Print A List Of The Contents Of An Egg And Print 2 (64.06 KiB) Viewed 78 times
Subset 0 To complete subset 0, you need to implement code that can • print a list of the contents of an egg, and • print a detailed list of the contents of an egg. Subset 0: Print a list of the contents of an egg Given the -1 command-line argument, chicken should print the path names of the files/directories in an egg. For example: # List each item in the egg called text_file.egg, which is in the examples directory $ ./chicken -1 examples/text_file.egg hello.txt # List each item in the egg called 4_files.egg, which is in the examples directory $ ./chicken -1 examples/4_files.egg 256.bin hello.txt last_goodbye.txt these_days.txt # List each item in the egg called hello world.egg, which is in the examples directory $ ./chicken -l examples/hello world.egg hello.c hello.cpp hello.d hello.go hello.hs hello.java hello.js hello.pl hello.py hello.rs hello.s hello.sh hello.sql Subset 0: Print a detailed list of the contents of an egg Given the -L command-line argument chicken should for each file in the specified egg print: 1. the file/directory permissions, 2. the egglet format which will be one of 6, 7 or 8 (the default), 3. the file/directory size in bytes, and 4. the file/directory path name. $ ./chicken -L examples/text_file.egg -rw-r--r-- 8 56 hello.txt # List the details of each item in the egg called 4_files.egg, which is in the examples directory $ ./chicken -L examples/4_files.egg -rw-r--r- 8 256 256.bin -rw-r--r- 8 56 hello.txt -r--r--r- 8 166 last_goodbye.txt -r--rw-r-- 8 148 these_days.txt # List the details of each item in the egg called hello_world, egg, which is in the examples directory $ ./chicken -L examples/hello_world.egg -rw-r--r-- 8 93 hello.c -rw-r--r-- 8 8 82 hello.cpp -rw-r--r-- 8 65 hello.d -rw-r--r-- 8 8 77 hello.go -rw-r--r-- 8 32 hello.hs -rw-r--r- 8 117 hello.java -rw-r--r-- 8 30 hello.js -rwxr-xr-x 8 47 hello.pl -rwxr-xr-x 8 103 hello.py -rw-r--r-- 8 8 45 hello.rs -rw-r--r-- 8 r 8 123 hello.s -rwxr-xr-x 8 41 hello.sh -rw-r--r-- -r8 8 24 hello.sol

HINT: chicken_main.c calls the function list_egg in chicken.c when either of the - 1 or-L options are specified on the command line Add code to list_egg in chicken.c. Use fopen to open the egg file. Use fgetc to read bytes Make sure you understand the egglet format specification below Use C bitwise operations such as <<& and to combine bytes into integers. Think carefully about the functions you can construct to avoid repeated code. Review print_borts_file.c from our week 8 tutorial and print_bytes.c from our week 8 lab. fseek can be used to skip over parts of the egg file, but you can also use a loop and fgetc NOTE: The order you list files is the order they appear in the egg. egg files do not necessarily end with egg. This has been done with the provided example files purely as a convenience Hint: use a format like "slu" to print the file size.

name The egg and egglet format eggs must follow exactly the format produced by the reference implementation An egg consists of a sequence of one or more egglets. Each egglet contains the information about one file or directory. The first byte of an egg file is the first byte of the first egglet. That egglet is immediately followed by either another egglet, or by the end of the egg file. length type description magic 1.B unsigned, 8-bit. byte 0 in every egglet must be 0x63 (ASCII C") number little-endian egglet format 18 unsigned, 8-bit byte 1 in every egglet must be one of Ox36, 0x37, 0x38 little-endian (ASCII '6', '7', '8') permissions 10B characters bytes 2–11 are the type and permissions as a 's-like character array; eg. "-rwxr-xr-x" pathname unsigned, 16-bit, bytes 12—13 are an unsigned 2-byte (16-bit) little- length little-endian endian integer, giving the length of pathname pathname-length characters the filename of the object in this egglet. content unsigned, 48-bit, the next bytes are an unsigned 6-byte (48-bit) little length little-endian endian integer giving the length of the file that was encoded to give content content-length for 8-bit bytes the data of the object in this egglet. format, see below for other formats hash 1B unsigned, 8-bit, the last byte of an egglet is an egglet-hash of all bytes little-endian of this egglet except this byte. 2 100 6B

9 10 11 12 13 #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <assert.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> 14 15 16 17 #include "chicken.h" 18 19 20 // ADD ANY extra #defines HERE 21 22 23 24 25 // ADD YOUR FUNCTION PROTOTYPES HERE 26 27 28 29 30 // print the files & directories stored in egg pathname (subset o) // // if long_listing is non-zero then file/directory permissions, formats & sizes are also prin // // if long_listing is non-zero then egglet hashes should also be checked (subset 1) 31 void list_egg(char *egg_pathname, int long_listing) { 32 33 34 // REPLACE THIS CODE WITH YOUR CODE 35 printf("list_egg called to list egg: %s'\n", egg_pathname); 36 37 38 39 if (long_listing) { printf("long listing with permissions & sizes specified\n"); } 40 41 }