home *** CD-ROM | disk | FTP | other *** search
- ;/* SplitP.c
- lc -j73 -L SplitP.c
- quit
- ; *************************************************************************
- ; * SplitP Created: Feb 15, 1992 6:37 pm *
- ; * ©1992 John Bianchi Bianchi Computer Systems *
- ; *************************************************************************
- ; * Execute me to compile under SAS/C 5.10b *
- ; *************************************************************************
- ; * SplitP - SplitPrint - will split a document file into opposite sides *
- ; * for printing page 1,3,5,7.... on one side of your printer paper, then *
- ; * re-feeding the paper and printing page 2,4,6,8... *
- ; * This program only splits the file, it does not do the printing. *
- ; *************************************************************************
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <libraries/dos.h>
- #include <libraries/dosextens.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
-
- /* 2.0 compatable Version Tag String */
- #define PROGRAM "SplitP"
- #define VERS "0.8"
- #define RELEASE "02.15.1992"
- #define COPYRIGHT "©1992 John Bianchi All Rights Reserved."
- UBYTE *version = "\0$VER: " PROGRAM " " VERS " (" RELEASE ") ";
-
- #define SIDE_ONE "_1"
- #define SIDE_TWO "_2"
- /* #define DEBUG */
-
- int page_len=66, line_len=256;
-
- void usage(void)
- {
- printf("SplitP Version: " VERS " " COPYRIGHT "\n\n");
- printf("Usage:\n " PROGRAM " <file> [-options]\n");
- printf("With:\n");
- printf(" <file> = The AmigaDOS filename you want to Split\n");
- printf("Options:\n");
- printf(" -p# = Set Page length (default=%d)\n",page_len);
- /* printf(" -l# = Set Line length (default=%d)\n",line_len);
- ### NOT IMPLEMENTED YET ###
- */
- printf("\n");
- }
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- BOOL side=FALSE;
- int k=0,page=0,line=0;
- char c,page_one[256],page_two[256];
- FILE *infile,*out_1,*out_2,*fopen();
- struct Process *proc;
- struct CommandLineInterface *cli;
-
- proc = (struct Process *)FindTask(NULL);
- cli = (struct CommandLineInterface *)(proc->pr_CLI << 2);
- if(!cli || argc == 0) exit(RETURN_ERROR);
-
- if(argv[1][0]=='?' || argv[1][0]=='\0')
- {
- usage();
- exit(RETURN_WARN);
- }
- else
- {
- if((infile = fopen(argv[1],"r")))
- {
- #ifdef DEBUG
- printf("DE-BUGGING!\n\n");
- printf("Opening file: %s.\n",argv[1]);
- #endif
- for(k=2; k<argc; k++)
- {
- /* this is to find the '-' commands */
- if(argv[k][0] == '-')
- {
- switch( argv[k][1] )
- {
- case 'P':
- case 'p':
- page_len=atoi(argv[k]+2);
- #ifdef DEBUG
- printf("Page Length: %d.\n",page_len);
- #endif
- break;
- case 'L':
- case 'l':
- line_len=atoi(argv[k]+2);
- #ifdef DEBUG
- printf("Line Length: %d.\n",line_len);
- #endif
- break;
- default:
- printf("Unknown option (%d): %s\n",k,argv[k]);
- fclose(infile);
- exit(RETURN_ERROR);
- break;
- }
- }
- }
- strcpy(page_one,argv[1]);
- strcat(page_one,SIDE_ONE);
- strcpy(page_two,argv[1]);
- strcat(page_two,SIDE_TWO);
- #ifdef DEBUG
- printf("Side 1: '%s'\n",page_one);
- #endif
- #ifdef DEBUG
- printf("Side 2: '%s'\n",page_two);
- #endif
- if((out_1=fopen(page_one,"w")))
- {
- if((out_2=fopen(page_two,"w")))
- {
- page=1;
- line=1;
- side=FALSE;
- while((c=getc(infile)) != EOF)
- {
- if(!side)
- putc(c,out_1);
- else
- putc(c,out_2);
-
- if(c=='\n')
- line++;
-
- if(c=='\f' || line>page_len)
- {
- #ifdef DEBUG
- printf("P:%d S:%d L:%d \n",page,side,line);
- #endif
- side=!side;
- line=1;
- page++;
- }
- }
- fclose(out_2);
- printf("%d pages processed.\n",(line>1) ? page : page-1);
- }
- else
- printf("Can't open output file (2)!\n");
- fclose(out_1);
- }
- else
- printf("Can't open output file (1)!\n");
- fclose(infile);
- }
- else
- {
- printf("Can't open input file: '%s'\n",argv[1]);
- exit(RETURN_ERROR);
- }
- }
- }
-