home *** CD-ROM | disk | FTP | other *** search
-
- /*
- I verified that this program will compile with Turbo C 2.0. I have not
- tested it for conformance to copyright law and make no claims about its
- performance. I think it is intended only for use by people in the
- USA, but it's small, so I won't worry about restricting distribution.
- -- Rahul Dhesi
- */
-
- /* --cut here to separate program from headers etc. -- */
-
- /*
- This is a program for generating hexadecimal object code deposits
- for copyright registration of computer programs.
-
- An object code deposit is the first and last 25 pages of a binary, octal,
- or hexadecimal dump of a computer program. Before using this program,
- consult an expert on copyright law, or at least a good book on copyright law.
- For example:
-
- Remer and Elias, "Legal Care for your Software", 3d. ed., Nolo Press, 1987
-
- NOTE: on IBM PCs this program should be compiled with the TINY memory model.
-
- Using the program:
-
- By default, the output of this program goes to the computer screen.
- The output can be redirected to a file or printer. For example:
-
- deposit junkmail.exe "Junk Mail v. 1.4" > prn:
-
- The above command will generate an object code deposit for the program
- "junkmail.exe". Each page will have a header of "Junk Mail v. 1.4 Page XX".
-
- deposit c:\sources\junkmail\junkmail.exe "Junk Mail v. 1.4" > deposit.txt
-
- The above command will generate an object code deposit and place it in the
- file "deposit.txt".
-
- This program was written in TURBO C by Eric Bergman-Terrell, and is in
- the public domain.
- */
-
- #include <stdio.h>
- #include <sys/stat.h>
-
- #define ERROR -1
- #define SUCCESS 0
-
- #define COL_WIDTH 80 /* Width of columns - can be changed to 132. */
- #define PAGES 25
-
- #define TOP_MARGIN 3
- #define BOT_MARGIN 3
-
- #define TOT_LINES 66
- #define PRINT_LINES (TOT_LINES - (TOP_MARGIN + BOT_MARGIN))
-
- #define BYTES_PER_LINE (COL_WIDTH / 2)
- #define PAGE_BUFFER_SIZE (PRINT_LINES * BYTES_PER_LINE)
-
- typedef char BUFFER[PAGE_BUFFER_SIZE];
-
-
- void print_page(page, buffer, no_bytes, page_heading)
-
- /*
- Print the current page of the hexadecimal dump.
- */
-
- int page, no_bytes;
- BUFFER buffer;
- char *page_heading;
-
- {
- int i;
-
- if (no_bytes > 0)
- {
- printf("\n%s Page %5d\n\n", page_heading, page);
-
- for (i = 0; i < no_bytes; i++)
- {
- printf("%X%X", (int) buffer[i] / 16, (int) buffer[i] % 16);
-
- if (((i + 1) % BYTES_PER_LINE) == 0)
- printf("\n");
- }
-
- printf("\n\n\n");
- }
- }
-
-
- void main(int argc, char *argv[])
- {
- FILE *file;
- long int file_size;
- int result, start_last_page, page, max_page;
- BUFFER buffer;
- struct stat stat_buf;
-
- if (argc != 3)
- {
- printf("usage: deposit <file name> <page header>\n");
- exit(ERROR);
- }
-
- result = stat(argv[1], &stat_buf);
-
- if (result != SUCCESS)
- {
- printf("deposit: cannot open file %s\n", argv[1]);
- exit(ERROR);
- }
-
- file_size = stat_buf.st_size;
-
- file = fopen(argv[1], "rb");
-
- if (file == NULL)
- {
- printf("deposit: cannot open file %s\n", argv[1]);
- exit(ERROR);
- }
-
- /* Determine the maximum page number. */
- max_page = (short) (file_size / PAGE_BUFFER_SIZE) + 1;
-
- /* Correct value if last page is exactly full. */
- if (file_size % PAGE_BUFFER_SIZE == 0)
- max_page--;
-
- /* Determine the page number of the first page of the last 25 pages. */
- start_last_page = max_page - PAGES + 1;
-
- /* Cope with object files with less than 50 pages. */
- if (start_last_page <= PAGES)
- start_last_page = PAGES + 1;
-
- /* Print the first 25 pages. */
- for (page = 1; page <= PAGES; page++)
- {
- result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
- print_page(page, buffer, result, argv[2]);
- }
-
- /* Discard pages before the last 25 pages. */
- for (; page < start_last_page; page++)
- result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
-
- /* Print the last 25 pages. */
- for (; page <= max_page; page++)
- {
- result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
- print_page(page, buffer, result, argv[2]);
- }
-
- fclose(file);
-
- exit(SUCCESS);
- }
-
-
-