home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
utilities
/
utilss
/
support
/
Source
/
Splitf_c
< prev
next >
Wrap
Text File
|
1995-02-04
|
19KB
|
391 lines
/********************************************************************************/
/* */
/* Splitf.c */
/* Part of Splitf and Joinf distribution */
/* version 1.13, © 1993-1995 Adam Hamilton */
/* See the README file for copyright information */
/* */
/********************************************************************************/
/*********************************/
/* Include required header files */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
/**********************************/
/* Program macros and definitions */
#ifndef Bool
# define Bool char
#endif
#define False 0
#define True !False
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#ifndef LEAFNAME_MAX
# define LEAFNAME_MAX FILENAME_MAX
#endif
/********************************************************************************/
/* */
/* Function : usage */
/* Description : Displays program usage to standard error, and exits. */
/* Arguments : progname - pointer to character string containing the program */
/* name. */
/* Returns : None. */
/* */
/********************************************************************************/
void usage (char *progname)
{
fprintf (stderr, "File splitter. Version 1.13 - 4th Feburary 1995 by A.Hamilton\n\n");
fprintf (stderr, "Usage : %s [options] <filename>\n\n", progname);
fprintf (stderr, "Options (can be abbreviated) :\n");
fprintf (stderr, " -filesize [filesize in K] default = 1423\n");
#ifndef PC
fprintf (stderr, " -buffersize [buffersize in K] default = 32\n");
#endif
fprintf (stderr, " -path [new path]\n");
fprintf (stderr, " -interactive\n");
exit (EXIT_FAILURE);
}
/********************************************************************************/
/* */
/* Function : examine_filename */
/* Description : Splits filename into component parts. */
/* Arguments : original_name - character array, filename to be examined. */
/* name - pointer to a character array in which to store */
/* file leafname (excluding extention). */
/* ext - pointer to a character array in which to store */
/* the source files extention (if any). */
/* Returns : If the source file has an extention, then return ".spt", */
/* otherwise return "". */
/* */
/********************************************************************************/
char *examine_filename (char original_name[], char *name, char *ext)
{
char main_name[256]; /* Temporary store for leafname. */
char *original; /* Pointer to start of leafname. */
char *pointer; /* Pointer to any ':' characters found. */
register int i = -1, n; /* Pointer & counter. */
if (COLON) /* If our system uses ':' in */
pointer = strrchr (original_name, ':'); /* the file path, then remember */
else /* where it is. */
pointer = NULL;
original = strrchr (original_name, SEPARATOR_SEARCH); /* Find the address where the */
if ((original = MAX (original, pointer)) == NULL) /* leafname starts. */
original = original_name;
else {
original++;
}
do {
i++;
main_name[i] = original[i]; /* Get files leafname */
} while (main_name[i] != '.' && main_name[i] != '\0'); /* (excluding any extention). */
for (n = 0; (ext[n] = original[i]) != '\0'; n++, i++) ; /* Now copy any extention. */
if (main_name[i - n] == '\0') { /* If the file doesn't have an */
strcpy (name, main_name); /* extention, copy the leafname */
return (""); /* and return an empty string. */
}
main_name[i - n] = '\0'; /* Otherwise, terminate the */
strcpy (name, main_name); /* leafname, copy it, and */
return (".spt"); /* the output extention to use. */
}
/********************************************************************************/
/* */
/* Function : numtostr */
/* Description : Converts a number into a 2 didget character string. */
/* Arguments : number - number to be converted. */
/* name - pointer to a character array to store the number. */
/* Returns : None. */
/* */
/********************************************************************************/
void numtostr (short number, char *name)
{
name[0] = (short) (number / 10) + '0';
name[1] = (number % 10) + '0';
name[2] = '\0';
}
/********************************************************************************/
/* */
/* Function : main */
/* Description : Main control function. */
/* Arguments : Command line parameters. */
/* Returns : Exit status. */
/* */
/********************************************************************************/
int main (int argc, char **argv)
{
char source_filename[256]; /* Source filename. */
char out_filename[256]; /* Output leafname. */
char out_path[256]; /* Output path. */
char file_ext[32]; /* Output extention. */
char out_name[256]; /* Full output filename. */
char header[50]; /* Output file header. */
char fnum[3]; /* Output part number. */
char *progname; /* Program name. */
char string[256]; /* Input string. */
char type[5]; /* Filetype (Acorn systems only). */
char interactive = 0; /* Interactive status flag. */
char orig_ext[20]; /* Original filename extention. */
short file_number = 0; /* Current part number. */
long disk_size = 1423 * 1024; /* Output part size (default 1423K). */
long read_size = 32 * 1024; /* B