At long, panful last, a functional version of exercise 1-17. The code has contracted considerably since the intiially architected version, with replicate() and its functionality having been eliminated as unnecessary, saving numerous cycles and ~64kB of memory, advance() has been eliminated due to creating needless complexity, hindering readability, and decreasing efficiency, and recall has been eliminated because it depended on replicate, and was also unnecessary as enumerate() now contains three lines of code that completely eliminate the need for replicate() or enumerate().
This commit is contained in:
parent
848898ff11
commit
8665f996e5
1 changed files with 21 additions and 28 deletions
|
|
@ -4,12 +4,15 @@
|
|||
#define maxOutputSize 32100
|
||||
|
||||
char buffer[maxInputSize] = { 0 };
|
||||
char output[maxOutputSize] = { 0 };
|
||||
|
||||
void store(char to[]); // Complete
|
||||
void enumerate(char data[], char output[]); // Complete, pending testing. Needs replicate() before testing.
|
||||
void enumerateAdvance(int extDataCrsr, char accessedData, char externalBuffer[]);// Complete, pending testing.
|
||||
void replicate(char to[], char from[]);// Not Started
|
||||
void enumerate(char data[]); // Complete, pending testing.
|
||||
|
||||
int main(){
|
||||
store(buffer);
|
||||
enumerate(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Status: Complete & Tested
|
||||
void store(char to[]){
|
||||
|
|
@ -20,21 +23,11 @@ void store(char to[]){
|
|||
}
|
||||
}
|
||||
|
||||
//Status: Complete, pending testing. Not to be used unil enumerate() has been
|
||||
//validated, at which point the for loop of enumerate can be modified to use
|
||||
//enumerateAdvance() as its completion action rather than calling an increment
|
||||
//and char fetch at the end of each loop independently. This function exists
|
||||
//purely for readability and style.
|
||||
void enumerateAdvance(int extDataCrsr, char accessedData, char externalBuffer[]){
|
||||
++extDataCrsr;
|
||||
accessedData = externalBuffer[extDataCrsr];
|
||||
}
|
||||
|
||||
//Status: Complete, pending testing. Not testable until replicate is complete.
|
||||
void enumerate(char data[], char output[]){
|
||||
void enumerate(char data[]){
|
||||
|
||||
int dataCrsr = 0; // Stores currently accessed position in data[]
|
||||
int wscursor = 0; //Stores the cursor position in workingStorage
|
||||
int wscursor = 0; //Stores the cursor position in ekorkingStorage
|
||||
int lineLen = 0; // Stores the length of the current line being enumerated.
|
||||
char workingStorage[maxOutputSize] = { 0 }; // Stores processed data until
|
||||
// replicated to output.
|
||||
|
|
@ -45,14 +38,16 @@ void enumerate(char data[], char output[]){
|
|||
if(current == '\n' && lineLen >= 80){
|
||||
//Reset line length in preparation for next dataset.
|
||||
lineLen = 0;
|
||||
//Increment wscursor and add a null byte at the end of valid data
|
||||
// Increment wscursor and add a null ek yte at the end of valid data
|
||||
// for replicate to break on.
|
||||
++wscursor;
|
||||
workingStorage[wscursor] = 0;
|
||||
//Copy workingStorage into output.
|
||||
replicate(output, workingStorage);
|
||||
//Reset wscuror. Existing data in workingStorage will be ovrwritten
|
||||
//by next dataset.
|
||||
// Print line to stdout
|
||||
for(wscursor = 0; workingStorage[wscursor] != 0;++wscursor){
|
||||
putchar(workingStorage[wscursor]);
|
||||
}
|
||||
putchar('\n');
|
||||
// Reset wscursor
|
||||
wscursor = 0;
|
||||
// Begin case: newline with unacceptable line length.
|
||||
} else if (current == '\n' && lineLen < 80){
|
||||
|
|
@ -72,5 +67,3 @@ void enumerate(char data[], char output[]){
|
|||
current = data[dataCrsr];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue