User Tools

Site Tools


haas:spring2016:cprog:projects:cbf0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
haas:spring2016:cprog:projects:cbf0 [2016/03/21 23:11] – [Submission] wedgehaas:spring2016:cprog:projects:cbf0 [2016/03/22 19:56] (current) – [Unthrottled display (512 bytes)] wedge
Line 57: Line 57:
       * error message should be of the form: **Error: Terminal height is less than 20 lines!**       * error message should be of the form: **Error: Terminal height is less than 20 lines!**
       * Unlike the width, the height can impact program output (taller terminals, if not otherwise throttled by a second command-line argument, can auto-expand if there is more room and data to display).       * Unlike the width, the height can impact program output (taller terminals, if not otherwise throttled by a second command-line argument, can auto-expand if there is more room and data to display).
-  * If a second command-line argument exists, assume it is a sizing throttle (controlling the number of lines your program will display). If no argument is given (or that argument is a **0**), assume autosize (use the detected height to be your maximum in your calculations).+  * The second command-line argument is a sizing throttle (controlling the number of lines your program will display). If a  **0** is given, assume autosize (use the detected height to be your maximum in your calculations).
   * Display an ASCII header identifying the various fields (offset, hex, ascii), surrounded by dashed lines, running 79 characters in width. See below for more details.   * Display an ASCII header identifying the various fields (offset, hex, ascii), surrounded by dashed lines, running 79 characters in width. See below for more details.
   * Each row after the header will display:   * Each row after the header will display:
Line 110: Line 110:
  
 <cli> <cli>
-lab46:~/src/cprog$ ./hexview win7.mbr+lab46:~/src/cprog$ ./hexview win7.mbr 0
 ------------------------------------------------------------------------------- -------------------------------------------------------------------------------
 offset      0  1  2  3    5  6  7    9  a  b    d  e  f  ascii offset      0  1  2  3    5  6  7    9  a  b    d  e  f  ascii
Line 205: Line 205:
 lab46:~/src/cprog$  lab46:~/src/cprog$ 
 </cli> </cli>
 +
 +=====Bonus Opportunities=====
 +The following can be considered a bonus point opportunity:
 +
 +  * Enhance the program to accept up to 6 pairs of additional values (offset followed by its length), where each offset through length will be colored using ANSI text escape sequences.
 +  * For any line containing this colorized text, highlight the address in bold white.
 +
 +====Sample output====
 +
 +As an example, running the program with the following arguments could produce results like this:
 +
 +<cli>
 +lab46:~/src/cprog$ ./hexview win7.mbr 0 0x1be 1 0x1c2 1 0x1c6 4 0x1ca 4 0x1fe 2
 +</cli>
 +
 +{{:haas:spring2016:cprog:projects:hexviewer.png?640|}}
 +====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>
 +#define  ANSI_RESET             "\x1b[0m"
 +#define  ANSI_BOLD              "\x1b[1m"
 +#define  ANSI_FG_BLACK          "\x1b[30m"
 +#define  ANSI_FG_RED            "\x1b[31m"
 +#define  ANSI_FG_GREEN          "\x1b[32m"
 +#define  ANSI_FG_YELLOW         "\x1b[33m"
 +#define  ANSI_FG_BLUE           "\x1b[34m"
 +#define  ANSI_FG_MAGENTA        "\x1b[35m"
 +#define  ANSI_FG_CYAN           "\x1b[36m"
 +#define  ANSI_FG_WHITE          "\x1b[37m"
 +#define  ANSI_BG_BLACK          "\x1b[40m"
 +#define  ANSI_BG_RED            "\x1b[41m"
 +#define  ANSI_BG_GREEN          "\x1b[42m"
 +#define  ANSI_BG_YELLOW         "\x1b[43m"
 +#define  ANSI_BG_BLUE           "\x1b[44m"
 +#define  ANSI_BG_MAGENTA        "\x1b[45m"
 +#define  ANSI_BG_CYAN           "\x1b[46m"
 +#define  ANSI_BG_WHITE          "\x1b[47m"
 +</code>
 +
 +To use, you output them:
 +
 +<code>
 +fprintf(stdout, ANSI_FG_GREEN);
 +fprintf(stdout, "This text is green\n");
 +fprintf(stdout, ANSI_RESET);
 +</code>
 +
 +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:
 +
 +<code>
 +fprintf(stdout, ANSI_FG_YELLOW);
 +fprintf(stdout, ANSI_BG_BLUE);
 +fprintf(stdout, ANSI_BOLD);
 +fprintf(stdout, "This text is bold yellow on blue\n");
 +fprintf(stdout, ANSI_RESET);
 +</code>
 +
 +While there are 8 available foreground colors, bolding can double that range to 16.
 =====Submission===== =====Submission=====
 To successfully complete this project, the following criteria must be met: To successfully complete this project, the following criteria must be met:
haas/spring2016/cprog/projects/cbf0.1458601879.txt.gz · Last modified: 2016/03/21 23:11 by wedge