home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume7 / deposit < prev    next >
Encoding:
Text File  |  1989-07-21  |  4.3 KB  |  178 lines

  1. Newsgroups: comp.sources.misc
  2. organization: AT&T, Denver, CO
  3. subject: v07i087: Quick 'n Dirty Object Deposit Generator
  4. from: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Reply-To: terrell@druhi.ATT.COM (TerrellE)
  6.  
  7. Posting-number: Volume 7, Issue 87
  8. Submitted-by: terrell@druhi.ATT.COM (TerrellE)
  9. Archive-name: deposit
  10.  
  11. #! /bin/sh
  12. # This file was wrapped with "dummyshar".  "sh" this file to extract.
  13. # Contents:  deposit.c
  14. echo extracting 'deposit.c'
  15. if test -f 'deposit.c' -a -z "$1"; then echo Not overwriting 'deposit.c'; else
  16. sed 's/^X//' << \EOF > 'deposit.c'
  17. X/*
  18. XThis is a program for generating hexadecimal object code deposits
  19. Xfor copyright registration of computer programs.
  20. X
  21. XAn object code deposit is the first and last 25 pages of a binary, octal,
  22. Xor hexadecimal dump of a computer program.  Before using this program,
  23. Xconsult an expert on copyright law, or at least a good book on copyright law.
  24. XFor example:
  25. X
  26. XRemer and Elias, "Legal Care for your Software", 3d. ed., Nolo Press, 1987
  27. X
  28. XNOTE:  on IBM PCs this program should be compiled with the TINY memory model.
  29. X
  30. XUsing the program:
  31. X
  32. XBy default, the output of this program goes to the computer screen.
  33. XThe output can be redirected to a file or printer.  For example:
  34. X
  35. Xdeposit junkmail.exe "Junk Mail v. 1.4" > prn:
  36. X
  37. XThe above command will generate an object code deposit for the program
  38. X"junkmail.exe".  Each page will have a header of "Junk Mail v. 1.4  Page XX".
  39. X
  40. Xdeposit c:\sources\junkmail\junkmail.exe "Junk Mail v. 1.4" > deposit.txt
  41. X
  42. XThe above command will generate an object code deposit and place it in the
  43. Xfile "deposit.txt".
  44. X
  45. XThis program was written by Eric Bergman-Terrell, and is in the public domain.
  46. X*/
  47. X
  48. X#include <stdio.h>
  49. X#include <sys/types.h>
  50. X#include <sys/stat.h>
  51. X
  52. X#define ERROR    -1
  53. X#define SUCCESS     0
  54. X
  55. X#define COL_WIDTH    80  /* Width of columns - can be changed to 132. */
  56. X#define PAGES        25
  57. X
  58. X#define TOP_MARGIN    3
  59. X#define BOT_MARGIN    3
  60. X
  61. X#define TOT_LINES    66
  62. X#define PRINT_LINES    (TOT_LINES - (TOP_MARGIN + BOT_MARGIN))
  63. X
  64. X#define BYTES_PER_LINE        (COL_WIDTH / 2)
  65. X#define PAGE_BUFFER_SIZE    (PRINT_LINES * BYTES_PER_LINE)
  66. X
  67. Xtypedef char BUFFER[PAGE_BUFFER_SIZE];
  68. X
  69. X
  70. Xvoid print_page(page, buffer, no_bytes, page_heading)
  71. X
  72. X/*
  73. XPrint the current page of the hexadecimal dump.
  74. X*/
  75. X
  76. Xint    page, no_bytes;
  77. XBUFFER    buffer;
  78. Xchar    *page_heading;
  79. X
  80. X{
  81. Xint i;
  82. X
  83. Xif (no_bytes > 0)
  84. X  {
  85. X  printf("\n%s  Page %5d\n\n", page_heading, page);
  86. X
  87. X  for (i = 0; i < no_bytes; i++)
  88. X    {
  89. X    printf("%X%X", (int) buffer[i] / 16, (int) buffer[i] % 16);
  90. X
  91. X    if (((i + 1) % BYTES_PER_LINE) == 0)
  92. X      printf("\n");
  93. X    }
  94. X
  95. X  printf("\n\n\n");
  96. X  }
  97. X}
  98. X
  99. X
  100. Xvoid main(argc, argv)
  101. X
  102. Xint    argc;
  103. Xchar    *argv[];
  104. X
  105. X{
  106. XFILE   *file;
  107. Xlong int    file_size;
  108. Xint            result, start_last_page, page, max_page;
  109. XBUFFER         buffer;
  110. Xstruct stat     stat_buf;
  111. X
  112. Xif (argc != 3)
  113. X  {
  114. X  printf("usage: deposit <file name> <page header>\n");
  115. X  exit(ERROR);
  116. X  }
  117. X
  118. Xresult = stat(argv[1], &stat_buf);
  119. X
  120. Xif (result != SUCCESS)
  121. X  {
  122. X  printf("deposit: cannot open file %s\n", argv[1]);
  123. X  exit(ERROR);
  124. X  }
  125. X
  126. Xfile_size = stat_buf.st_size;
  127. X
  128. Xfile = fopen(argv[1], "rb");
  129. X
  130. Xif (file == NULL)
  131. X  {
  132. X  printf("deposit: cannot open file %s\n", argv[1]);
  133. X  exit(ERROR);
  134. X  }
  135. X
  136. X/* Determine the maximum page number. */
  137. Xmax_page = (short) (file_size / PAGE_BUFFER_SIZE) + 1;
  138. X
  139. X/* Correct value if last page is exactly full. */
  140. Xif (file_size % PAGE_BUFFER_SIZE == 0)
  141. X  max_page--;
  142. X
  143. X/* Determine the page number of the first page of the last 25 pages. */
  144. Xstart_last_page = max_page - PAGES + 1;
  145. X
  146. X/* Cope with object files with less than 50 pages. */
  147. Xif (start_last_page <= PAGES)
  148. X  start_last_page = PAGES + 1;
  149. X
  150. X/* Print the first 25 pages. */
  151. Xfor (page = 1; page <= PAGES; page++)
  152. X  {
  153. X  result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
  154. X  print_page(page, buffer, result, argv[2]);
  155. X  }
  156. X
  157. X/* Discard pages before the last 25 pages. */
  158. Xfor (; page < start_last_page; page++)
  159. X  result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
  160. X
  161. X/* Print the last 25 pages. */
  162. Xfor (; page <= max_page; page++)
  163. X  {
  164. X  result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
  165. X  print_page(page, buffer, result, argv[2]);
  166. X  }
  167. X
  168. Xfclose(file);
  169. X
  170. Xexit(SUCCESS);
  171. X}
  172. X
  173. EOF
  174. chars=`wc -c < 'deposit.c'`
  175. if test $chars !=     3534; then echo 'deposit.c' is $chars characters, should be     3534 characters!; fi
  176. fi
  177. exit 0
  178.