AminetAminet
Search:
84782 packages online
About
Recent
Browse
Search
Upload
Setup
Services

util/misc/LSFileCut.lha

Mirror:Random
Showing: i386-aros icongeneric icon
No screenshot available
Short:Cut data from FILE with position, and length (with source)
Author:LouiSe
Uploader:LouiSe <louise mail ahiv hu>
Type:util/misc
Architecture:m68k-amigaos
Date:1999-07-20
Download:util/misc/LSFileCut.lha - View contents
Readme:util/misc/LSFileCut.readme
Downloads:728

Simple file cutter by LouiSe

Usage:  LSFileCut <sourcefile> <targetfile> <position> <bytes>

---------------------------------------------------------

check out our projects @
- http://AMIGAonly.ahol.com   			AMIGAonly, the hungarian Amiga magazin
- http://AMIGAonly.ahol.com/louise/		LouiSe's home
- http://AMIGAonly.ahol.com/amilinux/	Amiga Linux page

--- CUT HERE for THE SOURCE ! ---------------------------

#include	<stdio.h>
#include	<string.h>
#include	<stdlib.h>
#include	<clib/dos_protos.h>

#define	BUFFSIZE 200000UL

void	main(int argc, char *argv[])
{
	BPTR	fhi, fho;
	long	pos,bytes;
	char	buffer[BUFFSIZE];
	long	allbytes=0;
	long	fr=0;
	
	if(argc<5)
	{
		printf("usage:\n");
		printf("      LSFileCut <source filename> <target filename> <position> <bytes>\n");
		exit(0);
	}
	

	if(strchr(argv[3],'x')!=NULL) sscanf(argv[3],"%x",&pos);
	else						      pos=atol(argv[3]);
	if(strchr(argv[4],'x')!=NULL) sscanf(argv[4],"%x",&bytes);
	else						      bytes=atol(argv[4]);

	printf("FileCut v1.05 by LouiSe 1999\n\n");
	printf("Input file   : %s\n",argv[1]);
	printf("Output file  : %s\n",argv[2]);
	printf("Cut position : %lu\n",pos);
	printf("Bytes to Cut : %lu\n",bytes);

	if((fhi=Open(argv[1],MODE_OLDFILE))==NULL)
	{
		printf("*** couldn't open input file: []\n",argv[1]);
		exit(-1);
	}
	else
		{
			if((fho=Open(argv[2],MODE_NEWFILE))==NULL)
			{
				printf("*** couldn't open output file: []\n",argv[2]);
				exit(-2);
			}
			else
				{
					allbytes=0;
					Seek(fhi,pos,OFFSET_BEGINNING);
					while(1)
					{
						fr=Read(fhi,buffer,sizeof(buffer));
						if(fr<=0) break;
						allbytes=allbytes+fr;
						// printf("fr=%lu, allbytes=%lu\n",fr,allbytes);

						if(allbytes<bytes)
						{
							Write(fho,buffer,fr);
						}
						else
							{
								if(fr>bytes)
								{
									Write(fho,buffer,bytes);
								}
								else
									{
										Write(fho,buffer,allbytes-bytes);
									}
									break;
							}
					}
					
					Close(fhi);
					Close(fho);
				}
	
		}

}


Contents of util/misc/LSFileCut.lha
 PERMSSN    UID  GID    PACKED    SIZE  RATIO     CRC       STAMP          NAME
---------- ----------- ------- ------- ------ ---------- ------------ -------------
[generic]                 6416   10180  63.0% -lh5- 0fce Jul 18  1999 LSFileCut
[generic]                  927    2165  42.8% -lh5- 3f7e Jul 19  1999 LSFileCut.readme
---------- ----------- ------- ------- ------ ---------- ------------ -------------
 Total         2 files    7343   12345  59.5%            Jul 19  1999
Page generated in 0.02 seconds
Aminet © 1992-2024 Urban Müller and the Aminet team. Aminet contact address: <aminetaminet net>