home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
-
- uucat(tm) v0.0
-
- COPYRIGHT: This program is the sole property of Thomas D. Haynes.
- Copyright 1991.
-
- DISCLAIMER: While it was compilied with Turbo C++, it will work
- in Turbo C, and if you change the findfirst and
- findnext functions to the corresponding MSC functions,
- it ought to work with MSC.
-
- Use of this product waives the author of any responsibilty
- of damage. Face it, I've tested this software on my
- system, and if it wiped out my hard disk, I'd be sure
- to rewrite the code so that I could use it safely.
-
- AUTHOR: Thomas D. Haynes
-
- FILE: uucat TYPE: int PROTOTYPE FILE: N/A
-
- PURPOSE: To concatonate uudecoded parts into one file.
-
- DATE: 03/31/91
-
- LANGUAGE: Borland C++ v2.00
-
- FUNCTIONS CALLED:
- uuError
- uuClError
- uuGetParts
-
- LIBRARY FUNCTIONS CALLED:
- fclose <stdio.h>
- findfirst <dir.h>
- findnext <dir.h>
- fgets <stdio.h>
- fopen <stdio.h>
- fprintf <stdio.h>
- fputs <stdio.h>
- memset <string.h>
- strcat <string.h>
- strcmp <string.h>
- strcpy <string.h>
- strncmp <string.h>
-
- RETURN CODES:
- -1 if the input file can not be opened
- -2 if the output file can not be opened
- -3 if not enough command line arguements
-
- OTHER:
- uucat <output_file> <input_file>(s)
-
- Where output_file is the destination file, and input_file
- is either a list of files to concatonate or a list of
- wildcarded filename of files to concatonate.
-
- Borland C++ is a Copyright of Borland International.
-
- *******************************************************************************/
- #include <dir.h>
- #include <stdio.h>
- #include <string.h>
-
- #define UUCAT_MAX_FILE 13
- #define UUCAT_MAX_LINE 257
- #define UUCAT_MAX_PARTS 512
-
- static char *mine[] =
- {
- "COPYRIGHT: This program is the sole property of Thomas D. Haynes.",
- " ALL RIGHTS RESERVED ",
- " Copyright 1991. "
- };
-
- void uuError(char *msg, char *file_name, int code)
- {
- if (file_name[0] == '\0')
- fprintf(stderr, "\nUUCAT ERROR: %s.\n", msg);
- else
- fprintf(stderr, "\nUUCAT ERROR: %s: %s \n", msg, file_name);
-
- exit(code);
- }
-
- void uuClError(void)
- {
- fprintf(stderr, "\nUUCAT ERROR: Incorrect arguements.");
- fprintf(stderr, "\n uucat <output> <input>(s)\n");
-
- exit(-3);
- }
-
- void uuGetParts(char **parts, char **argv, int argc, int *num_parts)
- {
- int j; /* loop variable */
- int i; /* loop variable */
- int done; /* flag if all files found */
- struct ffblk ffblk_st; /* structure containing found info */
-
- *num_parts = 0;
-
- /* If wildcard, get all the files to open */
- for (i = 2; i < argc; i++)
- {
- if (strchr(argv[i], '*') || strchr(argv[i], '?'))
- {
- done = findfirst(argv[i], &ffblk_st, 0);
- while (!done)
- {
- strcpy(parts[(*num_parts)++], ffblk_st.ff_name);
- done = findnext(&ffblk_st);
- }
- }
- else
- strcpy(parts[(*num_parts)++], argv[i]);
- }
- }
-
- int main(int argc, char *argv[])
- {
- FILE *in_fp; /* Input File pointer */
- FILE *out_fp; /* Output File pointer */
- char buf[UUCAT_MAX_LINE]; /* Buffer */
- char in_file[UUCAT_MAX_FILE]; /* Input File name */
- char out_file[UUCAT_MAX_FILE]; /* Output File name */
- char begin_text[] = "BEGIN--cut here--cut here"; /* Beginning Text Marker */
- char end_text[] = "END--cut here--cut here"; /* Ending Text Marker */
- char part_list[UUCAT_MAX_PARTS][UUCAT_MAX_FILE]; /* List of parts to ccat */
- char *part_ptrs[UUCAT_MAX_PARTS]; /* Pointer to list parts */
- int j; /* loop variable */
- int j_end; /* loop variable end */
-
- /* Check number of cmmand line arguements */
- if (argc < 3)
- uuClError();
-
- /* Open output file */
- if ((out_fp = fopen(argv[1], "wb")) == NULL)
- uuError("Cannot open output file", argv[1], -2);
-
- /* Get pointers to the Parts List */
- for (j = 0; j < UUCAT_MAX_PARTS; j++)
- {
- memset(part_list[j], '\0', UUCAT_MAX_FILE);
- part_ptrs[j] = &part_list[j][0];
- }
-
- /* Get the Parts List */
- uuGetParts(part_ptrs, argv, argc, &j_end);
-
- /* Loop through, reading in each Part */
- for (j = 0; j < j_end; j++)
- {
- /* Open up each Part for scanning */
- if ((in_fp = fopen(part_list[j], "rb")) == NULL)
- uuError("Cannot open input file", part_list[j], -1);
-
- /* First scan for the start of the UUENCODED text */
- /* Do not ouput anything */
- memset(buf, '\0', UUCAT_MAX_LINE);
- while(fgets(buf, UUCAT_MAX_LINE, in_fp))
- if (!strncmp(buf, begin_text, strlen(begin_text)))
- break;
- else
- memset(buf, '\0', UUCAT_MAX_LINE);
-
- /* Now scan for the end of the UUENCODED text */
- /* Output everything until end */
- memset(buf, '\0', UUCAT_MAX_LINE);
- while(fgets(buf, UUCAT_MAX_LINE, in_fp))
- if (!strncmp(buf, end_text, strlen(end_text)))
- break;
- else
- {
- fputs(buf, out_fp);
- memset(buf, '\0', UUCAT_MAX_LINE);
- }
-
- fclose(in_fp);
- }
-
- fclose(out_fp);
-
- return(0);
- }