[comp.binaries.ibm.pc] Thanks, I'd rather do it myself

clark@ttidca.TTI.COM (Ralph Clark) (04/06/88)

Here is a simple program to convert a self-extracting archive back into
a regular you-can-run-arc--t-on-it-before-you-spend-an-hour-downloading-it
archive. Inquiry to three local gurus failed to produce a simple one-line
shell command alternative. It will undoubtedly fail if you ask it to delete
a googolplex of bytes from the head of a file.

9758 has been posted as the length of the extraction program - no doubt
future or previous versions will vary. It is correct for skyplot.exe.

Usage : lobotomy -9758 <skyplot.exe >skyplot.arc  (uudecoded first!)

(not tested with any other example.)

--------------------------cut here------------------------------------------
/*      lobotomy.c
*
*       a tool to strip a specified number of bytes from the front of a file
*       while copying stdin to stdout.
*/
#include <stdio.h>

main(argc,argv)
int argc;
char *argv[];
{
    int c,i,nbytes;

    if ((argc != 2)
    || (*argv[1] != '-')
    || ((nbytes = atoi(&argv[1][1])) <= 0))
	printf(
    "Usage : %s -n, where n bytes are to be skipped from stdin to stdout",
	argv[0]);

    for (i = 0; i < nbytes; i++)
	if ((c == getchar()) == EOF)
	    exit(0);

    while ((c = getchar()) != EOF)
	putchar(c);

    exit (0);
}
----------------------------cut here--------------------------------------

Disclaimer: not responsible for damage caused by using this program to
remove any useful bytes from your files.
-- 
R. Clark (clark@TTI.COM)
Citicorp(+)TTI
3100 Ocean Park Blvd.   (213) 452-9191, x2965
Santa Monica, CA  90405 {csun|philabs|psivax|trwrb}!ttidca!clark

clark@ttidca.TTI.COM (Ralph Clark) (04/06/88)

Oops! I seem to have left out an exit call after displaying the usage. (I
told you I only tested the one example (-:) In keeping with the title,
I'll leave the insertion of the fix to the user.
-- 
R. Clark (clark@TTI.COM)
Citicorp(+)TTI
3100 Ocean Park Blvd.   (213) 452-9191, x2965
Santa Monica, CA  90405 {csun|philabs|psivax|trwrb}!ttidca!clark

marms@sandia.UUCP (Mike Arms) (04/08/88)

In article <2237@ttidca.TTI.COM> clark@ttidca.TTI.COM (Ralph Clark) writes:
>Here is a simple program to convert a self-extracting archive back into
>a regular you-can-run-arc--t-on-it-before-you-spend-an-hour-downloading-it
>archive. Inquiry to three local gurus failed to produce a simple one-line
>shell command alternative. It will undoubtedly fail if you ask it to delete
>a googolplex of bytes from the head of a file.


There is indeed a fairly simple one-line Unix command to do exactly this
using "dd", but it is VERY slow compared to your C-program. You must
specify the block size and the skip option to "dd":

      dd bs=1 skip=9758 <sky.exe >sky.arc

On my Sun 3/60, I ran a time comparison just for grins. The "dd" took
4.5 minutes, while "lobotomy" only took 1 second. They produced exactly
the same output. Most likely "dd" would move a hell of a lot faster if
it wasn't bogged down with a 1 byte block size specifier. Thanks for
a simple, but useful solution to the self-extracting arcs problem.

-- 
Mike Arms
uucp:  ...{ucbvax | gatech}!unmvax!sandia!marms

davidsen@steinmetz.ge.com (William E. Davidsen Jr) (04/08/88)

Although the C program works, on a UNIX system it can be done using
system tools:
	dd bs=1 skip=9758 if=self.extract of=real.arc

It can be done less conveniently with DEBUG under DOS as well, for those
who lack a C compiler. How about posting the compiler version, since
this is a binary newsgroup...
-- 
	bill davidsen		(wedu@ge-crd.arpa)
  {uunet | philabs | seismo}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me

rns@se-sd.sandiego.NCR.COM (Rick Schubert) (04/08/88)

In article <2237@ttidca.TTI.COM> clark@ttidca.TTI.COM (Ralph Clark) writes:
>Here is a simple program to convert a self-extracting archive back into
>a regular you-can-run-arc--t-on-it-before-you-spend-an-hour-downloading-it
>archive. Inquiry to three local gurus failed to produce a simple one-line
>shell command alternative. It will undoubtedly fail if you ask it to delete
>a googolplex of bytes from the head of a file.
>
>9758 has been posted as the length of the extraction program - no doubt
>future or previous versions will vary. It is correct for skyplot.exe.
>
>Usage : lobotomy -9758 <skyplot.exe >skyplot.arc  (uudecoded first!)

Two points:

1. I assume lobotomy must be run on UNIX(tm), or at least not DOS(no tm?).
   The DOS C libraries I am familiar with (Lattice and Turbo) will do
   CR-LF -> LF conversion for stdin and LF -> CR-LF conversion for stdout,
   which is not very useful for non-text files.  To make this work with
   these libraries, you would have to open the input and output files as
   binary files.

2. You have just reinvented tail +9758c.

merlin@hqda-ai.UUCP (David S. Hayes) (04/08/88)

In article <2237@ttidca.TTI.COM> clark@ttidca.TTI.COM (Ralph Clark) writes:
>archive. Inquiry to three local gurus failed to produce a simple one-line
>shell command alternative. It will undoubtedly fail if you ask it to delete
>
>9758 has been posted as the length of the extraction program - no doubt
>
>Usage : lobotomy -9758 <skyplot.exe >skyplot.arc  (uudecoded first!)

A simple way to delete 9758 bytes from a file:

     dd if=infile of=outfile bs=1 skip=9758

-- 
David S. Hayes, The Merlin of Avalon	PhoneNet:  (202) 694-6900
UUCP:  *!uunet!cos!hqda-ai!merlin	ARPA:  ai01@hios-pent.arpa

cuddy@convex.UUCP (04/09/88)

> ...Inquiry to three local gurus failed to produce a simple one-line
> shell command alternative.... 
> ... 9758 has been posted as the length of the extraction program...

> Usage : lobotomy -9758 <skyplot.exe >skyplot.arc  (uudecoded first!)

try tail +7959c skyplot.exe > skyplot.arc

or as a shell script:
---lobot.sh---<snip>--
#!/bin/csh -f
if ( $#argv != "3" ) then
   echo "Usage: lobotomy [bytes] [infile] [outfile]"
   exit 1
endif
@ argv[1]++
tail +$1c $2 > $3
----------------------
chmod 775 lobot.sh
Usage: lobot.sh [bytes] [infile] [outfile]

This works in 4.3BSD.  Check to make sure that your tail can do n characters.
(ours does n characters words or lines--I don't think it's a local enhancement
although our company is prone to doing such things).

Mike Cuddy,
CONVEX Computer Corp
{ihnp4,sun,allegra,uiucdcs}!convex!cuddy

doug@sys1.TANDY.COM (04/15/88)

{munch}
>Although the C program works, on a UNIX system it can be done using
>system tools:
>	dd bs=1 skip=9758 if=self.extract of=real.arc

that's a tad slow, try
	dd bs=9758 skip=1 if=self.extract of=real.arc


doug@sys1.tandy.com

            \ T /  \ T /
            / C \  / C \
            -------------
USnail  :   400 Atrium 
            One Tandy Center
            Fort Worth, Tx, 76102.  
AT&T    :   (817)-390-3001 
UUCP    :   { ihnp4 || trsvax || soma || uiucuxc || ico }!sys1!doug
LOGICAL :   1110011 1111001 1110011 0110001 0100001 
            1100100 1101111 1110101 1110101 1100111

#include <standard.h>
#include <disclamer.h>
extern short int *employers();
disclamer(this_message)
char **this_message
{
	register out;
	if (*this_message == employers(opinon)) exit();
	if (*this_message == reality) abort();
	if (flames)  {
		out=open("/dev/null", O_WRONLY);
		write(out, flames, sizeof(flames));
		close(out);
	}
}