home *** CD-ROM | disk | FTP | other *** search
- From decwrl!purdue!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!allbery Thu Aug 3 08:50:19 PDT 1989
- Article 979 of comp.sources.misc:
- Path: decwrl!purdue!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!allbery
- From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
- Newsgroups: comp.sources.misc
- Subject: v07i087: Quick 'n Dirty Object Deposit Generator
- Message-ID: <61149@uunet.UU.NET>
- Date: 22 Jul 89 00:46:49 GMT
- Sender: allbery@uunet.UU.NET
- Reply-To: terrell@druhi.ATT.COM (TerrellE)
- Organization: AT&T, Denver, CO
- Lines: 171
- Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 7, Issue 87
- Submitted-by: terrell@druhi.ATT.COM (TerrellE)
- Archive-name: deposit
-
- #! /bin/sh
- # This file was wrapped with "dummyshar". "sh" this file to extract.
- # Contents: deposit.c
- echo extracting 'deposit.c'
- if test -f 'deposit.c' -a -z "$1"; then echo Not overwriting 'deposit.c'; else
- sed 's/^X//' << \EOF > 'deposit.c'
- X/*
- XThis is a program for generating hexadecimal object code deposits
- Xfor copyright registration of computer programs.
- X
- XAn object code deposit is the first and last 25 pages of a binary, octal,
- Xor hexadecimal dump of a computer program. Before using this program,
- Xconsult an expert on copyright law, or at least a good book on copyright law.
- XFor example:
- X
- XRemer and Elias, "Legal Care for your Software", 3d. ed., Nolo Press, 1987
- X
- XNOTE: on IBM PCs this program should be compiled with the TINY memory model.
- X
- XUsing the program:
- X
- XBy default, the output of this program goes to the computer screen.
- XThe output can be redirected to a file or printer. For example:
- X
- Xdeposit junkmail.exe "Junk Mail v. 1.4" > prn:
- X
- XThe above command will generate an object code deposit for the program
- X"junkmail.exe". Each page will have a header of "Junk Mail v. 1.4 Page XX".
- X
- Xdeposit c:\sources\junkmail\junkmail.exe "Junk Mail v. 1.4" > deposit.txt
- X
- XThe above command will generate an object code deposit and place it in the
- Xfile "deposit.txt".
- X
- XThis program was written by Eric Bergman-Terrell, and is in the public domain.
- X*/
- X
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X
- X#define ERROR -1
- X#define SUCCESS 0
- X
- X#define COL_WIDTH 80 /* Width of columns - can be changed to 132. */
- X#define PAGES 25
- X
- X#define TOP_MARGIN 3
- X#define BOT_MARGIN 3
- X
- X#define TOT_LINES 66
- X#define PRINT_LINES (TOT_LINES - (TOP_MARGIN + BOT_MARGIN))
- X
- X#define BYTES_PER_LINE (COL_WIDTH / 2)
- X#define PAGE_BUFFER_SIZE (PRINT_LINES * BYTES_PER_LINE)
- X
- Xtypedef char BUFFER[PAGE_BUFFER_SIZE];
- X
- X
- Xvoid print_page(page, buffer, no_bytes, page_heading)
- X
- X/*
- XPrint the current page of the hexadecimal dump.
- X*/
- X
- Xint page, no_bytes;
- XBUFFER buffer;
- Xchar *page_heading;
- X
- X{
- Xint i;
- X
- Xif (no_bytes > 0)
- X {
- X printf("\n%s Page %5d\n\n", page_heading, page);
- X
- X for (i = 0; i < no_bytes; i++)
- X {
- X printf("%X%X", (int) buffer[i] / 16, (int) buffer[i] % 16);
- X
- X if (((i + 1) % BYTES_PER_LINE) == 0)
- X printf("\n");
- X }
- X
- X printf("\n\n\n");
- X }
- X}
- X
- X
- Xvoid main(argc, argv)
- X
- Xint argc;
- Xchar *argv[];
- X
- X{
- XFILE *file;
- Xlong int file_size;
- Xint result, start_last_page, page, max_page;
- XBUFFER buffer;
- Xstruct stat stat_buf;
- X
- Xif (argc != 3)
- X {
- X printf("usage: deposit <file name> <page header>\n");
- X exit(ERROR);
- X }
- X
- Xresult = stat(argv[1], &stat_buf);
- X
- Xif (result != SUCCESS)
- X {
- X printf("deposit: cannot open file %s\n", argv[1]);
- X exit(ERROR);
- X }
- X
- Xfile_size = stat_buf.st_size;
- X
- Xfile = fopen(argv[1], "rb");
- X
- Xif (file == NULL)
- X {
- X printf("deposit: cannot open file %s\n", argv[1]);
- X exit(ERROR);
- X }
- X
- X/* Determine the maximum page number. */
- Xmax_page = (short) (file_size / PAGE_BUFFER_SIZE) + 1;
- X
- X/* Correct value if last page is exactly full. */
- Xif (file_size % PAGE_BUFFER_SIZE == 0)
- X max_page--;
- X
- X/* Determine the page number of the first page of the last 25 pages. */
- Xstart_last_page = max_page - PAGES + 1;
- X
- X/* Cope with object files with less than 50 pages. */
- Xif (start_last_page <= PAGES)
- X start_last_page = PAGES + 1;
- X
- X/* Print the first 25 pages. */
- Xfor (page = 1; page <= PAGES; page++)
- X {
- X result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
- X print_page(page, buffer, result, argv[2]);
- X }
- X
- X/* Discard pages before the last 25 pages. */
- Xfor (; page < start_last_page; page++)
- X result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
- X
- X/* Print the last 25 pages. */
- Xfor (; page <= max_page; page++)
- X {
- X result = fread(buffer, 1, PAGE_BUFFER_SIZE, file);
- X print_page(page, buffer, result, argv[2]);
- X }
- X
- Xfclose(file);
- X
- Xexit(SUCCESS);
- X}
- X
- EOF
- chars=`wc -c < 'deposit.c'`
- if test $chars != 3534; then echo 'deposit.c' is $chars characters, should be 3534 characters!; fi
- fi
- exit 0
-
-
-