home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / deposit.c < prev    next >
C/C++ Source or Header  |  1989-07-25  |  4KB  |  165 lines

  1.  
  2. /*
  3. I verified that this program will compile with Turbo C 2.0.  I have not
  4. tested it for conformance to copyright law and make no claims about its
  5. performance.   I think it is intended only for use by people in the
  6. USA, but it's small, so I won't worry about restricting distribution.
  7. -- Rahul Dhesi
  8. */
  9.  
  10. /* --cut here to separate program from headers etc. -- */
  11.  
  12. /*
  13. This is a program for generating hexadecimal object code deposits
  14. for copyright registration of computer programs.
  15.  
  16. An object code deposit is the first and last 25 pages of a binary, octal,
  17. or hexadecimal dump of a computer program.  Before using this program,
  18. consult an expert on copyright law, or at least a good book on copyright law.
  19. For example:
  20.  
  21. Remer and Elias, "Legal Care for your Software", 3d. ed., Nolo Press, 1987
  22.  
  23. NOTE:  on IBM PCs this program should be compiled with the TINY memory model.
  24.  
  25. Using the program:
  26.  
  27. By default, the output of this program goes to the computer screen.
  28. The output can be redirected to a file or printer.  For example:
  29.  
  30. deposit junkmail.exe "Junk Mail v. 1.4" > prn:
  31.  
  32. The above command will generate an object code deposit for the program
  33. "junkmail.exe".  Each page will have a header of "Junk Mail v. 1.4  Page XX".
  34.  
  35. deposit c:\sources\junkmail\junkmail.exe "Junk Mail v. 1.4" > deposit.txt
  36.  
  37. The above command will generate an object code deposit and place it in the
  38. file "deposit.txt".
  39.  
  40. This program was written in TURBO C by Eric Bergman-Terrell, and is in
  41. the public domain.
  42. */
  43.  
  44. #include <stdio.h>
  45. #include <sys/stat.h>
  46.  
  47. #define ERROR    -1
  48. #define SUCCESS     0
  49.  
  50. #define COL_WIDTH    80  /* Width of columns - can be changed to 132. */
  51. #define PAGES        25
  52.  
  53. #define TOP_MARGIN    3
  54. #define BOT_MARGIN    3
  55.  
  56. #define TOT_LINES    66
  57. #define PRINT_LINES    (TOT_LINES - (TOP_MARGIN + BOT_MARGIN))
  58.  
  59. #define BYTES_PER_LINE        (COL_WIDTH / 2)
  60. #define PAGE_BUFFER_SIZE    (PRINT_LINES * BYTES_PER_LINE)
  61.  
  62. typedef char BUFFER[PAGE_BUFFER_SIZE];
  63.  
  64.  
  65. void print_page(page, buffer, no_bytes, page_heading)
  66.  
  67. /*
  68. Print the current page of the hexadecimal dump.
  69. */
  70.  
  71. int    page, no_bytes;
  72. BUFFER    buffer;
  73. char    *page_heading;
  74.  
  75. {
  76. int i;
  77.  
  78. if (no_bytes > 0)
  79.   {
  80.   printf("\n%s  Page %5d\n\n", page_heading, page);
  81.  
  82.   for (i = 0; i < no_bytes; i++)
  83.     {
  84.     printf("%X%X", (int) buffer[i] / 16, (int) buffer[i] % 16);
  85.  
  86.     if (((i + 1) % BYTES_PER_LINE) == 0)
  87.       printf("\n");
  88.     }
  89.  
  90.   printf("\n\n\n");
  91.   }
  92. }
  93.  
  94.  
  95. void main(int argc, char *argv[])
  96. {
  97. FILE   *file;
  98. long int    file_size;
  99. int            result, start_last_page, page, max_page;
  100. BUFFER         buffer;
  101. struct stat     stat_buf;
  102.  
  103. if (argc != 3)
  104.   {
  105.   printf("usage: deposit <file name> <page header>\n");
  106.   exit(ERROR);
  107.   }
  108.  
  109. result = stat(argv[1], &stat_buf);
  110.  
  111. if (result != SUCCESS)
  112.   {
  113.   printf("deposit: cannot open file %s\n", argv[1]);
  114.   exit(ERROR);
  115.   }
  116.  
  117. file_size = stat_buf.st_size;
  118.  
  119. file = fopen(argv[1], "rb");
  120.  
  121. if (file == NULL)
  122.   {
  123.   printf("deposit: cannot open file %s\n", argv[1]);
  124.   exit(ERROR);
  125.   }
  126.  
  127. /* Determine the maximum page number. */
  128. max_page = (short) (file_size / PAGE_BUFFER_SIZE) + 1;
  129.  
  130. /* Correct value if last page is exactly full. */
  131. if (file_size % PAGE_BUFFER_SIZE == 0)
  132.   max_page--;
  133.  
  134. /* Determine the page number of the first page of the last 25 pages. */
  135. start_last_page = max_page - PAGES + 1;
  136.  
  137. /* Cope with object files with less than 50 pages. */
  138. if (start_last_page <= PAGES)
  139.   start_last_page = PAGES + 1;
  140.  
  141. /* Print the first 25 pages. */
  142. for (page = 1; page <= PAGES; page++)
  143.   {
  144.   result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
  145.   print_page(page, buffer, result, argv[2]);
  146.   }
  147.  
  148. /* Discard pages before the last 25 pages. */
  149. for (; page < start_last_page; page++)
  150.   result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
  151.  
  152. /* Print the last 25 pages. */
  153. for (; page <= max_page; page++)
  154.   {
  155.   result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
  156.   print_page(page, buffer, result, argv[2]);
  157.   }
  158.  
  159. fclose(file);
  160.  
  161. exit(SUCCESS);
  162. }
  163.  
  164.  
  165.