home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume07 / deposit < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  4.7 KB

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