CC=gcc CFLAGS=-g -Wall -ansi -pedantic
Two programs need to be built, atobm and bmtoa.
atobm will ask the user for
In the above, default means that the user is allowed to press return rather than enter a single character. In that case, the default character is used.
To be valid, <name> may only contain characters in the range 'a'-'z', 'A'-'Z', and '0'-'9'.
After the user has supplied the above required information, the program accepts a number of lines consisting of only the characters denoting a 0 bit and a 1 bit. The only other valid input is an empty line, denoting the end of the input. All entered lines must be of equal length.
Invalid input results in an appropriate error message (depending on the type of error) to the standard output (not to file) and program termination with an exit status 1.
The number of lines entered is used as the bitmap height. The number of characters entered per line is used as the bitmap width.
#--#-###---#--#-## #--#-###---#--#-## #--#-###---#--#-##should produce the file example1.xbm containing
#define example1_width 18 #define example1_height 3 static unsigned char example1_bits[] = { 0xe9, 0x48, 0x03, 0xe9, 0x48, 0x03, 0xe9, 0x48, 0x03 };
The same output would be produced (on stdout) when using the UNIX atobm -name example1 -chars -# with the above input.
100101110001001011 100101110001001011 100101110001001011should produce exactly the same output as in Example 1.
The same output would be produced (on stdout) when using the UNIX atobm -name example1 -chars 01 with the above input.
If the name is ``example3'' and the characters denoting a 0 and a 1 bit are the defaults, the input
#--#-###---#--#-## #--#-#-#--#------#should produce the file example3.xbm containing
#define example3_width 18 #define example3_height 2 static unsigned char example3_bits[] = { 0xe9, 0x48, 0x03, 0xa9, 0x04, 0x02 };
Let's take a closer look at how the output is generated. If the name is ``example4'' and the characters denoting a 0 and a 1 bit are the defaults, the input
#--##---#--##---# #-------------###should produce the file example4.xbm containing
#define example4_width 17 #define example4_height 2 static unsigned char example4_bits[] = { 0x19, 0x19, 0x01, 0x01, 0xc0, 0x01 };This is the example presented in class.
All (both) input lines have length 17, so example4_width needs to be # defined as 17. As there are two lines, example4_height needs to be # defined as 2.
The content of the character vector is obtained as follows (we are using the first input line as an example):
Similarly, the second line will lead to 0x01, 0xc0, 0x01.
In the program, processing can be done byte by byte ! Also, the reversing need not be done explicitly, but can be done ``on the fly''.
bmtoa will be constructed by compiling and linking bmtoa.c as well as bitmap.c. bitmap.c is produced by using ``bitmap'' as the name input in atobm, renaming or copying (manually) the file bitmap.xbm created by atobm to bitmap.c and removing the static in that file. The program in bmtoa.c must use the definitions in bitmap.c (via an external reference) to print the bitmap to standard output. To access bitmap height and width information, a file bitmap.h must be included which is constructed from the first two lines of bitmap.xbm. The program bmtoa must ask the user for
As before, default means that the user is allowed to press return rather than enter a single character. In that case, the default character is used.
Invalid input results in an appropriate error message (depending on the type of error) to the standard output (not to file) and program termination with an exit status 1.
You may assume that the total number of bits (rows x columns) input will never be more than 10000.
# indent (GNU C beautifier) # # -ts1: tab stop width = 1 # -bli0: block indent ({}) 0 # -c28: try to start code-line comments in column 28 # -cd28: try to start declaration-line comments in column 28 # -npcs: no space after function call names # -l72: maximum non-comment-line length # -lc72: maximum comment-line length # alias indent 'indent -ts1 -bli0 -c28 -cd28 -npcs -l72 -lc72'Beware of TABs. TAB expansion (as a number of blank spaces) on one machine may be different from TAB expansion on another. This may result in code which looks properly indented on one platform and chaotic on another. To avoid this: