Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language is in C. Given the following files, file descriptions, and starter code. Help clarify and provide simpler instructions as to what the programming assignment

Language is in C.

Given the following files, file descriptions, and starter code. Help clarify and provide simpler instructions as to what the programming assignment wants to be done.

Refer to the //TO DO comments in the starter code provided at the bottom for what I need the most help with. Any attempt at helping clarify will receive a thumbs up :)

image text in transcribedimage text in transcribedimage text in transcribed

Starter Code for globals:

#ifndef _GLOBALS_H

#define _GLOBALS_H

#define MAXFONTSIZE 4*4096

#define MAXFONTLINESIZE 32

#define MAXNUMCGRAMS 200

#define MAXWIDTH 150

#define MAXHEIGHT 16

#define FONTDELIM '#'

#define SPACING 2

#define SMILEY ('~' + 1)

#define FIRSTCHAR ' '

extern int readFontBuffer(const char *);

extern void printCGram(const char);

extern int copyCGram(const char, int);

extern void fillDisplayBuffer(char);

extern void printDisplayBuffer();

extern char fontBuffer[MAXFONTSIZE];

extern char* cGramLookup[MAXNUMCGRAMS];

extern int cGramWidth[MAXNUMCGRAMS];

extern char displayBuffer[MAXHEIGHT][MAXWIDTH];

#endif

Starter Code for fontBuffer:

#include

#include

#include "globals.h"

char fontBuffer[MAXFONTSIZE];

char* cGramLookup[MAXNUMCGRAMS];

int cGramWidth[MAXNUMCGRAMS];

/* Reads the font file and copies the cGram symbols into the fontBuffer

* array, recording the starting location and the max width of each cGram

* in the cGramLookup and cGramWidth arrays. Note that these 2 arrays are

* indexed with an offset of -FIRSTCHAR (i.e. char 'a' data will be in

* cGramLookup['a' - FIRSTCHAR], etc.) */

int readFontBuffer(const char *fontFile) {

FILE *fontFilePtr;

char *fontLine;

char *fontBufferPtr = fontBuffer;

// Variable to index into cGramLookup and cGramWidth as cGrams are read from the font file

int charIdx = 0;

// Variable to keep track of the longest line per cGram, reset to 0 per cGram

int maxWidth = 0;

// This opens the file m and handles file IO errors

if((fontFilePtr = fopen(fontFile, "r")) == NULL) {

return -1;

}

// We found it easier to handle the very first cGram separately; feel free to change!

cGramLookup[charIdx] = fontBufferPtr;

while((fontLine = fgets(fontBufferPtr, MAXFONTLINESIZE, fontFilePtr)) != NULL) {

// TODO:

// - here fontLine is one line of the font file, ending in a ' ' char

// - fgets copies fontLine to fontBufferPtr, so fontBufferPtr should be

// updated by the length of the copied line so the next line will not

// overwrite the current one

// - for every line, update the current cGram's maxWidth

// - when seeing a FONTDELIM char, you should:

// - store the *current* char's cGram's maxWidth into cGramWidth

// - store the *next* char's cGram's location into cGramLookup

// - reset maxWidth for the next char

}

// The file is closed after use

fclose(fontFilePtr);

return 0;

}

/* Looks up the specified char's cGram and prints it to stdout. */

void printCGram(const char c) {

// TODO

}

Starter code for displayBuffer:

#include

#include

#include "globals.h"

char displayBuffer[MAXHEIGHT][MAXWIDTH];

/* Looks up the specified char's cGram in fontBuffer, then copies the

* cGram into the displayBuffer starting at column xPos. Returns the

* column where the next cGram should start. */

int copyCGram(const char c, int xPos) {

// TODO:

// - how can you get char c's cGram?

// - how can you copy the cGram into the displayBuffer?

// - is there anything to be careful about when copying?

// - this should return the xPos (column) of the next cGram;

// what are the inter-cGram spacing rules?

return -1;

}

/* Fills every byte of displayBuffer with the specified char */

void fillDisplayBuffer(const char c) {

// TODO

}

/* Prints the entire displayBuffer to stdout */

void printDisplayBuffer() {

// TODO

}

Source Files The following files are required to compile and run, but globals.h must not be edited. Filename Description globals.h Defines global constants, and externs variable and function declarations to interlink all of the other .c files (so that they can use each other's variables). MAXFONTSIZE - max size of fontBuffer MAXFONTLINESIZE - max size of one line in font file - number of distinct cGrams MAXNUMCGRAMS MAXWIDTH - max width of the 2D displayBuffer do NOT edit MAXHEIGHT - max height of the 2D displayBuffer FONTDELIM - char used to indicate end of cGram SPACING -# of cols between cGrams in displayBuffer SMILEY - represents emoji :) as ascii value 127 FIRSTCHAR - char of first cGram in font file continued on the next page Externed globals from other files: char fontBuffer[MAXFONTSIZE] - holds all of the cGrams in flattened 1D form char cGramLookup [MAXNUMCGRAMS] - maps a char to its cGram's location in fontBuffer int cGramWidth [MAXNUMCGRAMS] - maps a char to its cGram's width char displayBuffer[MAXHEIGHT] [MAXWIDTH] - a 2D array for displaying cGrams fontBuffer.c int readFontBuffer (const char *fontFileName) - reads font file; updates cGramLookup, cGramWidth void printCGram (const char c) - looks up and prints out appropriate cGram int copyCGram (const char c, int xPos) - starting at column xPos, looks up and copies the appropriate cGram displayBuffer. char by char into displayBuffer (not exceeding MAXWIDTH) - returns where *the next cGram* should start (i.e. the next PO5) void fillDisplayBuffer (const char c) - fills the display buffer with the given symbol void printDisplayBuffer () - prints the entire display buffer to stdout main.c void printHelp () - prints the help message; called with the -h flag int main (int argc, char** argv) - processes options, reads in the font file, reads in the input string, and prints out the message ASCII cGrams We have implemented a font file in fonts/cse30.font. This file contains ASCII art of all the printable ASCII characters, which we call cGrams. Our cse30.font cGrams are separated by a single line containing the "#' delimiter character (no delim at the start of the file), which is not considered part of the cGram. Here is a subset of the file with two cGrams shown, where represents the ' character: "Yebape Global Buffers (Arrays) fontBuffer: A big char array defined in fontBuffer.c that is populated with the constituent symbols of all cGrams by the readFontBuffer () function, given some font file. The 2D cGrams are flattened in the fontBuffer, stored as sequences of concatenated rows. Note: cGrams are of varying sizes and occupy different amounts of storage in fontBuffer. cGramLookup: An array of char pointers defined in fontBuffer.c. Each pointer points to the start of a cGram in fontBuffer. This is effectively a char-to-cGram map. Indexing: Our font file contains ASCII values 32 - 126 ('' - -), so the location of the cGram for'' is stored in cGramLookup [0]. We thus define FIRSTCHAR to be' ' and subtract its ASCII value (32) when indexing into cGramLookup. For some char c, its cGram data will be at the address given by cGramLookup[c - FIRSTCHAR]. cGramWidth: An array of ints defined in fontBuffer.c that specify the width of each cGram. Indexing: The indexing scheme here is identical to that of cGramLookup. displayBuffer: A 2D char array defined in displayBuffer.c used as a canvas to store the individual symbols that make up a series of cGrams. To print a message "ab", the symbols that make up the cGrams for 'a' and 'b' are copied into displayBuffer, with additional SPACING between them. Then displayBuffer is printed to stdout. Source Files The following files are required to compile and run, but globals.h must not be edited. Filename Description globals.h Defines global constants, and externs variable and function declarations to interlink all of the other .c files (so that they can use each other's variables). MAXFONTSIZE - max size of fontBuffer MAXFONTLINESIZE - max size of one line in font file - number of distinct cGrams MAXNUMCGRAMS MAXWIDTH - max width of the 2D displayBuffer do NOT edit MAXHEIGHT - max height of the 2D displayBuffer FONTDELIM - char used to indicate end of cGram SPACING -# of cols between cGrams in displayBuffer SMILEY - represents emoji :) as ascii value 127 FIRSTCHAR - char of first cGram in font file continued on the next page Externed globals from other files: char fontBuffer[MAXFONTSIZE] - holds all of the cGrams in flattened 1D form char cGramLookup [MAXNUMCGRAMS] - maps a char to its cGram's location in fontBuffer int cGramWidth [MAXNUMCGRAMS] - maps a char to its cGram's width char displayBuffer[MAXHEIGHT] [MAXWIDTH] - a 2D array for displaying cGrams fontBuffer.c int readFontBuffer (const char *fontFileName) - reads font file; updates cGramLookup, cGramWidth void printCGram (const char c) - looks up and prints out appropriate cGram int copyCGram (const char c, int xPos) - starting at column xPos, looks up and copies the appropriate cGram displayBuffer. char by char into displayBuffer (not exceeding MAXWIDTH) - returns where *the next cGram* should start (i.e. the next PO5) void fillDisplayBuffer (const char c) - fills the display buffer with the given symbol void printDisplayBuffer () - prints the entire display buffer to stdout main.c void printHelp () - prints the help message; called with the -h flag int main (int argc, char** argv) - processes options, reads in the font file, reads in the input string, and prints out the message ASCII cGrams We have implemented a font file in fonts/cse30.font. This file contains ASCII art of all the printable ASCII characters, which we call cGrams. Our cse30.font cGrams are separated by a single line containing the "#' delimiter character (no delim at the start of the file), which is not considered part of the cGram. Here is a subset of the file with two cGrams shown, where represents the ' character: "Yebape Global Buffers (Arrays) fontBuffer: A big char array defined in fontBuffer.c that is populated with the constituent symbols of all cGrams by the readFontBuffer () function, given some font file. The 2D cGrams are flattened in the fontBuffer, stored as sequences of concatenated rows. Note: cGrams are of varying sizes and occupy different amounts of storage in fontBuffer. cGramLookup: An array of char pointers defined in fontBuffer.c. Each pointer points to the start of a cGram in fontBuffer. This is effectively a char-to-cGram map. Indexing: Our font file contains ASCII values 32 - 126 ('' - -), so the location of the cGram for'' is stored in cGramLookup [0]. We thus define FIRSTCHAR to be' ' and subtract its ASCII value (32) when indexing into cGramLookup. For some char c, its cGram data will be at the address given by cGramLookup[c - FIRSTCHAR]. cGramWidth: An array of ints defined in fontBuffer.c that specify the width of each cGram. Indexing: The indexing scheme here is identical to that of cGramLookup. displayBuffer: A 2D char array defined in displayBuffer.c used as a canvas to store the individual symbols that make up a series of cGrams. To print a message "ab", the symbols that make up the cGrams for 'a' and 'b' are copied into displayBuffer, with additional SPACING between them. Then displayBuffer is printed to stdout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

How do the two components of this theory work together?

Answered: 1 week ago