This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:fall2017:discrete:projects:bdt1 [2017/10/02 15:24] – [Experiencing xxd] wedge | haas:fall2017:discrete:projects:bdt1 [2017/10/19 14:28] (current) – wedge | ||
---|---|---|---|
Line 3: | Line 3: | ||
< | < | ||
</ | </ | ||
- | |||
- | ~~TOC~~ | ||
======Project: | ======Project: | ||
Line 56: | Line 54: | ||
So these **bdt#** projects are a specific foray into this special case study of writing our own custom tool that can get a certain job done, faster. Reducing OUR particular need to keep tabs on something the computer is very much better at doing. | So these **bdt#** projects are a specific foray into this special case study of writing our own custom tool that can get a certain job done, faster. Reducing OUR particular need to keep tabs on something the computer is very much better at doing. | ||
- | =====Detecting Terminal Size===== | + | =====Implementation Restrictions===== |
- | To detect the current size of your terminal, you may make use of the following code, provided in the form of a complete program for you to test, and then adapt into your code as appropriate. | + | |
- | It makes use of a pre-existing **structure**, | + | As our goal is not only to explore the more subtle concepts |
- | <code c> | + | As such, the following implementation restrictions are also in place: |
- | #include < | + | |
- | #include < | + | |
- | #include < | + | |
- | int main (void) | + | * use any **break** or **continue** statements sparingly. I am not forbidding their use, but I also don't want this to turn into a lazy solution free-for-all. I am letting you use them, but with **justification**. |
- | { | + | * absolutely **NO** infinite loops (**while(1)**). |
- | | + | * no forced redirection of the flow of the process (no seeking to the end of the file to grab a max size only to zip back somewhere else: deal with the data in as you are naturally encountering it). |
- | | + | * All " |
+ | | ||
- | printf (" | + | Basically, I am going loosen my implementation restriction grip for this project: I would like you NOT to disappoint me. Write clean, effective |
- | printf (" | + | |
- | return (0); | + | |
- | } | + | |
- | </code> | + | |
- | An **ioctl(2)** is a method (and system/ | + | =====Program Specifications===== |
+ | For this project, I am looking for a minimum subset | ||
- | Here we are accessing the information on our terminal file, retrieving the width and height so that we can make use of them productively in our programs. | + | ====Basic functionality==== |
+ | Your program should: | ||
- | Compile and run the above code to see how it works. Try it in different size terminals. Then incorporate | + | * accept two files as command-line arguments (these would be the files you'd like to compare) |
+ | * display | ||
+ | * display the row preceding the first identified byte of difference | ||
+ | * display the row containing (and coloring/ | ||
+ | * display the row following the identified byte of difference for the first, then second file | ||
- | =====Selection highlighting===== | + | The focus is the FIRST byte of difference. The algorithm could get considerably trickier when dealing with additional differences (especially if extra bytes are involved in the difference). |
- | The following adds a nice visual twist to things: | + | |
- | * Enhance the program | + | ====Bonus opportunities==== |
- | * For any line containing this colorized text, highlight the address in bold white. | + | Some ideas to enhance your program |
- | ====Sample output==== | + | * accept some sort of mode argument, a number, that would alter the behavior of your tool. Such as: |
+ | * 0: display as project specifies | ||
+ | * 1: display on separate lines, vs. the same line of difference (first file, newline, second file). | ||
+ | * additional modes as justified | ||
+ | * accept numeric offset arguments, 1 for each file, to instruct your tool where they should start reading/ | ||
+ | * this would be a way for your tool to natively support " | ||
+ | * this would likely require displaying the pertinent offsets for each file. | ||
+ | * you could endeavor to explore some algorithmic enhancements to automatically detect additional points of difference. Note that this could be rather fragile, depending on the identified differences. | ||
- | As an example, running the program with the following arguments could produce results like this: | + | =====Output===== |
- | + | A basic mockup | |
- | {{: | + | |
- | + | ||
- | ====ANSI escape sequences for color==== | + | |
- | This probably isn't very portable, and depending on the terminal, it may not work for some people. | + | |
- | + | ||
- | It may be most convenient to set up preprocessor #define statements near the top of your code, as follows: | + | |
- | + | ||
- | <code c> | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | </ | + | |
- | + | ||
- | To use, you output them: | + | |
- | + | ||
- | < | + | |
- | fprintf(stdout, | + | |
- | fprintf(stdout, | + | |
- | fprintf(stdout, | + | |
- | </ | + | |
- | + | ||
- | You have to remember to turn the color or setting off (resetting it) to revert back to the original color. | + | |
- | + | ||
- | You can mix and match as well: | + | |
- | + | ||
- | < | + | |
- | fprintf(stdout, | + | |
- | fprintf(stdout, | + | |
- | fprintf(stdout, | + | |
- | fprintf(stdout, | + | |
- | fprintf(stdout, | + | |
- | </ | + | |
- | + | ||
- | While there are 8 available foreground colors, bolding can double that range to 16. | + | |
- | + | ||
- | =====Implementation Restrictions===== | + | |
- | + | ||
- | As our goal is not only to explore the more subtle concepts of computing but to promote different methods of thinking | + | |
- | + | ||
- | As such, the following implementation restrictions are also in place: | + | |
- | + | ||
- | * absolutely **NO** switch/ | + | |
- | * absolutely **NO** infinite loops (**while(1)**, | + | |
- | * no forced redirection of the flow of the process (no seeking to the end of the file to grab a max size only to zip back somewhere else: deal with the data in as you are naturally encountering it). | + | |
- | * With the exception of any negative values, all numbers should be transacted in hexadecimal (as in the values you assign and compare and manipulate in your code). | + | |
- | * No line must exceed 80 characters in width. | + | |
- | * All " | + | |
- | * For the highlighted address and lengths, store them in an array of structs (containing the //address// and //length// members). | + | |
- | * **NO** logic shunts (ie having an if statement nested inside a loop to bypass an undesirable iteration)- this should be handled by the loop condition! | + | |
+ | <cli> | ||
+ | lab46: | ||
+ | 0000090: 0011 2233 4455 6677 8899 aabb ccdd eeff | 0011 2233 4455 6677 8899 aabb ccdd eeff | ||
+ | 00000a0: 55aa 66bb 0401 77cc 88dd 99ee aaff 89af | 55aa 66bb 0501 77cc 88dd 99ee aaff 89af | ||
+ | 00000b0: 9988 7766 5544 3322 1100 ffee ddcc bbaa | 9988 7766 5544 3322 1100 ffee ddcc bbaa | ||
+ | lab46: | ||
+ | </ | ||
=====Submission===== | =====Submission===== | ||
To successfully complete this project, the following criteria must be met: | To successfully complete this project, the following criteria must be met: |