CS 3113: Project 1

Objectives

The objectives of this project are for you to:

Overview

Proper Academic Conduct

The code solution to this project must be done individually. Do not copy solutions to this problem from the network and do not look at or copy solutions from others. However, you may use the net for inspiration and you may discuss your general approach with others.

Specification

Storage API

You are to implement a Storage API that provides the functions for opening/closing a file, as well as reading/writing a specified number of bytes from/to a specified location within the file. Your implementation must follow this specification exactly.

The STORAGE structure for now stores just the file descriptor of the open file:

typedef struct 
{
  int fd;
} STORAGE;
init_storage()

STORAGE * init_storage(char * name);

close_storage()

int close_storage(STORAGE *storage);

get_bytes()

int get_bytes(STORAGE *storage, unsigned char *buf, int location, int len);

put_bytes()

int put_bytes(STORAGE *storage, unsigned char *buf, int location, int len);


Main Program

Your main program maintains a 128-byte buffer in memory. The user can interact with this buffer by placing integer, floating point, character, string and hexadecimal values at a specified location in the buffer. In addition, the user may request that the values in the buffer be placed in a specified location in the storage file, or that the buffer values can be read from a specific location in the file.

The command-line interface to your program is as follows (note that you must respect the casing):

./project1
This program does the following:

Parsing Lines

There are lots of ways to parse a string into the individual tokens (tokens are symbols that are separated by white space). Here, we will use the string tokenizer provided in the string library in C.

The local data structures that you need are:

const char SEPARATORS[] = " \t\n";         // Declare as a global constant

char in_buffer[INBUFSIZE];                 // Input buffer from STDIN
char * args[MAX_ARGS];                     // pointers to arg strings
char ** arg;                               // working pointer that steps through the args
After receiving an input line into in_buffer (e.g., using fgets()), you can split the characters in the buffer into distinct tokens as follows:

    arg = args;
    *arg++ = strtok(in_buffer,SEPARATORS);   // tokenize input
    while ((*arg++ = strtok(NULL,SEPARATORS)));
Here, SEPARATORS is a string that contains all of the characters that are valid indicators for splitting the input string up. At the end, of the loop, arg will be an array of strings (technically, it is an array of pointers to characters). The arg in the array after the last argument will be set to NULL.

Commands

There will be exactly one command per line of input from STDIN.

Notes

Examples

Program Invocation (for all examples)
./project1

Input Text

z
l
Output Text
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
Input Text
z
b 42 67
l
B 42
H 42
Output Text
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 43 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
67
43
C


Input Text

z
s 10 HelloWorld
S 10
S 15
C 15
H 15
l
Output Text
HelloWorld
World
W
57
00 00 00 00 00 00 00 00 00 00 48 65 6c 6c 6f 57 
6f 72 6c 64 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
Input Text
z
i 32 1138
I 32
I 33
I 34
H 32
H 33
H 34
l
Output Text
1138
4
0
72
4
0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
72 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
Input Text
z
s 16 Hello
h 21 20
s 22 World!
S 16
S 20
l
Output Text
Hello World!
o World!
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
48 65 6c 6c 6f 20 57 6f 72 6c 64 21 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
Input Text
z
w 0 128
w 128 128
w 256 128
i 30 1138
s 40 HelloWorld!
l
w 0 128
z
r 128 128
H 0
l
r 0 128
H 0
l
S 40
Output Text
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 72 04 
00 00 00 00 00 00 00 00 48 65 6c 6c 6f 57 6f 72 
6c 64 21 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 72 04 
00 00 00 00 00 00 00 00 48 65 6c 6c 6f 57 6f 72 
6c 64 21 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
HelloWorld!


Submitting Your Program


Grading Criteria


Downloads

The following file contains storage.h and a number of example tests: project1_dist.tar

Testing

The testing procedure is the same as in Project 0.


Hints


Addenda


andrewhfagg at gmail.com

Last modified: Fri Sep 20 14:48:10 2019