CMPS-4350 Advanced Software Engineering
Lab-5

Overview:

Step 1:
Copy files to your /4350/5 folder.

Get the lab files from Odin at:

/home/fac/gordon/p/4350/code/lab5/*

Name your source file lab5.cpp

Step 2:
Write your LZ77 decoder.

Use the knowledge you learned in our Monday lecture to write a decoder
for a compressed LZ77 file.

Use the following main function...
int main(void) { char str[1000]; printf("\n\nCMPS-4350 Lab-5 decompression\n"); decode("banana.cmp", str); if (strcmp(str, "banana") != 0) printf("ERROR: decoding banana.cmp"); else printf("banana.cmp decoded correctly."); decode("apple.cmp", str); if (strcmp(str, "apple") != 0) printf("ERROR: decoding banana.cmp"); else printf("apple.cmp decoded correctly."); printf("\n"); // return 0; }

Step 3:
Homework.

Decode the following file.

/home/fac/gordon/p/4350/lab5/aart.cmp

 1. The length of the uncompressed text is at the beginning of the file.

 2. It is a number coded as ascii characters, followed by a null terminator.

 3. The null terminator is the first zero of the first compressed code triplet.

 4. All 3-character compression codes follow.

3-character compression code: onc
                              |||
                              ||+---one additional character of text
                              |+----how many repeated characters are there
                              +-----offset into existing previous text

Get your decoder working.

Use the following main function for the homework...

int main(void)
{
    char *str = new char[1000000];
    printf("\n\nCMPS-4350 Lab-5 decompression\n\n");
    decode("banana2.cmp", str);
    if (strcmp(str, "banana") != 0) {
        printf("ERROR: decoding banana. <-----\n");
    } else {
        printf("banana decoded correctly.\n");
    }
    decode("apple2.cmp", str);
    if (strcmp(str, "apple") != 0) {
        printf("ERROR: decoding apple. <-----\n");
    } else {
        printf("apple decoded correctly.\n");
    }
    printf("\n");
    decode("aart.cmp", str);
    printf("%s", str);
    printf("\n");
    delete [] str;
    return 0;
}

//function prototype
void decode(const char *fname, char *str);