home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 613a.lha / SplitP / SplitP.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-16  |  5.4 KB  |  165 lines

  1. ;/* SplitP.c
  2. lc -j73 -L SplitP.c
  3. quit
  4. ; *************************************************************************
  5. ; * SplitP                          Created: Feb 15, 1992 6:37 pm         *
  6. ; * ©1992  John Bianchi             Bianchi Computer Systems              *
  7. ; *************************************************************************
  8. ; *              Execute me to compile under SAS/C 5.10b                  *
  9. ; *************************************************************************
  10. ; * SplitP - SplitPrint - will split a document file into opposite sides  *
  11. ; * for printing page 1,3,5,7.... on one side of your printer paper, then *
  12. ; * re-feeding the paper and printing page 2,4,6,8...                     *
  13. ; * This program only splits the file, it does not do the printing.       *
  14. ; *************************************************************************
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <exec/types.h>
  20. #include <exec/memory.h>
  21. #include <libraries/dos.h>
  22. #include <libraries/dosextens.h>
  23. #include <proto/exec.h>
  24. #include <proto/dos.h>
  25.  
  26. /* 2.0 compatable Version Tag String                                    */
  27.  #define PROGRAM    "SplitP" 
  28.  #define VERS       "0.8"
  29.  #define RELEASE    "02.15.1992"
  30.  #define COPYRIGHT  "©1992 John Bianchi  All Rights Reserved." 
  31.  UBYTE *version      = "\0$VER: " PROGRAM "  " VERS "   (" RELEASE ") ";
  32.  
  33. #define SIDE_ONE "_1"
  34. #define SIDE_TWO "_2"
  35. /* #define DEBUG */
  36.  
  37. int page_len=66, line_len=256;
  38.  
  39. void usage(void)
  40. {
  41.     printf("SplitP   Version: " VERS "   " COPYRIGHT "\n\n");
  42.     printf("Usage:\n   " PROGRAM "  <file> [-options]\n");
  43.     printf("With:\n");
  44.     printf("  <file> = The AmigaDOS filename you want to Split\n");
  45.     printf("Options:\n");
  46.     printf("   -p#   = Set Page length (default=%d)\n",page_len);
  47.     /* printf("   -l#   = Set Line length (default=%d)\n",line_len); 
  48.        ### NOT IMPLEMENTED YET ###
  49.     */
  50.     printf("\n");
  51. }
  52.  
  53. main (argc, argv)
  54. int argc;
  55. char *argv[];
  56. {
  57.     BOOL side=FALSE;
  58.     int k=0,page=0,line=0;
  59.     char c,page_one[256],page_two[256];
  60.     FILE *infile,*out_1,*out_2,*fopen();
  61.     struct  Process *proc;
  62.     struct  CommandLineInterface *cli;
  63.  
  64.     proc = (struct Process *)FindTask(NULL);
  65.     cli =  (struct CommandLineInterface *)(proc->pr_CLI << 2);
  66.     if(!cli  || argc == 0) exit(RETURN_ERROR);
  67.  
  68.     if(argv[1][0]=='?' || argv[1][0]=='\0') 
  69.        {
  70.         usage();
  71.         exit(RETURN_WARN);
  72.     }
  73.     else
  74.     {
  75.         if((infile = fopen(argv[1],"r")))
  76.         {
  77.             #ifdef DEBUG
  78.              printf("DE-BUGGING!\n\n");
  79.              printf("Opening file: %s.\n",argv[1]);
  80.             #endif
  81.             for(k=2; k<argc; k++)
  82.             {
  83.                 /* this is to find the '-' commands */
  84.                 if(argv[k][0] == '-')
  85.                 {
  86.                     switch( argv[k][1] )
  87.                     {
  88.                         case 'P':
  89.                         case 'p':
  90.                             page_len=atoi(argv[k]+2);
  91.                             #ifdef DEBUG
  92.                               printf("Page Length: %d.\n",page_len);
  93.                             #endif
  94.                             break;
  95.                         case 'L':
  96.                         case 'l':
  97.                             line_len=atoi(argv[k]+2);
  98.                             #ifdef DEBUG
  99.                               printf("Line Length: %d.\n",line_len);
  100.                             #endif
  101.                             break;
  102.                         default:
  103.                             printf("Unknown option (%d): %s\n",k,argv[k]);
  104.                             fclose(infile);
  105.                             exit(RETURN_ERROR);
  106.                             break;
  107.                      }
  108.                 }
  109.             }
  110.             strcpy(page_one,argv[1]);
  111.             strcat(page_one,SIDE_ONE);
  112.             strcpy(page_two,argv[1]);
  113.             strcat(page_two,SIDE_TWO);
  114.             #ifdef DEBUG
  115.              printf("Side 1: '%s'\n",page_one);
  116.             #endif
  117.             #ifdef DEBUG
  118.              printf("Side 2: '%s'\n",page_two);
  119.             #endif
  120.             if((out_1=fopen(page_one,"w")))
  121.             {
  122.                 if((out_2=fopen(page_two,"w")))
  123.                 {
  124.                     page=1;
  125.                     line=1;
  126.                     side=FALSE;
  127.                     while((c=getc(infile)) != EOF)
  128.                     {
  129.                         if(!side)
  130.                             putc(c,out_1);
  131.                         else
  132.                             putc(c,out_2);
  133.  
  134.                         if(c=='\n')
  135.                             line++;
  136.  
  137.                         if(c=='\f' || line>page_len)
  138.                         {
  139.                             #ifdef DEBUG
  140.                              printf("P:%d  S:%d  L:%d \n",page,side,line);  
  141.                             #endif
  142.                             side=!side;
  143.                             line=1;
  144.                             page++;
  145.                         }
  146.                     }
  147.                     fclose(out_2);
  148.                     printf("%d pages processed.\n",(line>1) ? page : page-1);
  149.                 }
  150.                 else
  151.                     printf("Can't open output file (2)!\n");
  152.                 fclose(out_1);
  153.             }
  154.             else
  155.                 printf("Can't open output file (1)!\n");    
  156.             fclose(infile);
  157.         }
  158.         else
  159.         {
  160.             printf("Can't open input file: '%s'\n",argv[1]);
  161.             exit(RETURN_ERROR);
  162.         }
  163.     }
  164. }
  165.