home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 143_01 / 2up.c < prev    next >
Text File  |  1985-11-14  |  5KB  |  187 lines

  1. /*
  2. %CC1 $1.C -X -E5000
  3. %CLINK $1 DIO 
  4. %DELETE $1.CRL 
  5. */
  6. /*********************************************************************
  7. *                               2UP                                  *
  8. **********************************************************************
  9. *                  COPYRIGHT 1983 EUGENE H. MALLORY                  *
  10. *    MODIFIED FOR EITHER C80 OR BDS/C COMPILER BY H. ECKERSON    *
  11. *            4/27/85                         *
  12. *********************************************************************/
  13.  
  14. #include "BDSCIO.H"
  15. #INCLUDE "DIO.H"
  16.  
  17. #define MAXW 132
  18.  
  19. char doneflag,string[MAXLINE];
  20. char array[90][MAXW+2];
  21. int ncol,col,len,hold,margin,space,width;
  22. int bm,tm;
  23.  
  24. main(argc,argv)
  25.  
  26. int argc;
  27. char **argv;
  28.  
  29.   BEGIN
  30.     int i,j,k,firstflag;
  31.     dioinit(&argc,argv);      /* INITIALIZE DIO BUFFERS AND FLAGS */
  32.  
  33. /*********************************************************************
  34. ***               ARGUMENT PROCESSING                              ***
  35. *********************************************************************/
  36.  
  37.     int ii,jj,optionerr;
  38.     char *ss;
  39.     hold = ncol = space = margin = col = len = optionerr = 0;
  40.     bm = tm = 0;
  41.     for (ii=argc-1;ii>0;ii--)
  42.     if (argv[ii][0] == '-')
  43.       THEN
  44.     for (ss = &argv[ii][1]; *ss != '\0';)
  45.       LOOP
  46.         switch (toupper(*ss++))
  47.           BEGIN
  48.           case 'L':
  49.         len = atoi(ss);
  50.         break;
  51.           case 'C':
  52.         col= atoi(ss);
  53.         break;
  54.           case 'M':
  55.         margin = atoi(ss);
  56.         break;
  57.           case 'T':
  58.         tm = atoi(ss);
  59.         break;
  60.           case 'B':
  61.         bm = atoi(ss);
  62.         break;
  63.           case 'S':
  64.         space = atoi(ss);
  65.         break;
  66.           case 'N':
  67.         ncol= atoi(ss);
  68.         break;
  69.           case 'W':
  70.         hold = TRUE;
  71.         break;
  72.           case 'H':
  73.         optionerr = TRUE;
  74.         break;
  75.           default:
  76.         typef("2UP: Illegal option %c.\n", *--ss);
  77.         ss++;
  78.         optionerr = TRUE;
  79.         break;
  80.           END
  81.         while (isdigit(*ss)) ss++;
  82.       ENDLOOP
  83.     for (jj=ii;jj<(argc-1);jj++) argv[jj] = argv[jj+1];
  84.     argc--;
  85.       ENDIF
  86.     if (optionerr) 
  87.       THEN
  88.     typef("2UP:   Legal options are:\n");
  89.     typef("-Ln    Page length.\n");
  90.     typef("-Cn    Column width .\n");
  91.     typef("-Mn    Margin.\n");
  92.     typef("-Tn    Top margin.\n");
  93.     typef("-Bn    Bottom margin.\n");
  94.     typef("-W     Wait at the bottom of each page.\n");
  95.     typef("-Sn    Space between columns.\n");
  96.     typef("-Nn    Number of columns.\n");
  97.     exit(0);
  98.       ENDIF
  99.     if (ncol == 0) ncol = 2;
  100.     if (space == 0) space = 0;
  101.     if (len == 0) len = 66;
  102.     if (col == 0) col = (80-margin-space*(ncol-1))/ncol;
  103.     if (len > 88) error("2UP: Too long a page, 88 lines is maximum.");
  104.     if ((margin+ncol*col+(ncol-1)*space) > MAXW) 
  105.     error("2UP: Total width exceeds 132.");
  106.     len = len-tm-bm;
  107.     if (len < 1)
  108.     error("2UP: Insufficient length.");
  109.  
  110. /*********************************************************************
  111. ***                  END OF ARGUMENT PROCESSING                    ***
  112. *********************************************************************/
  113. /*********************************/
  114. /*    MAIN LOOP                */
  115. /*********************************/
  116.     firstflag = TRUE;
  117.     doneflag = FALSE;
  118.     width = margin + ncol*col + (ncol-1)*space;
  119.     do
  120.       LOOP
  121.     for (i=1;i<=len;i++)
  122.       LOOP
  123.         for (j=1;j<=MAXW+1;j++)
  124.         array[i][j] = ' ';
  125.       ENDLOOP
  126.     for (k=0;k<ncol;k++)
  127.       LOOP
  128.         for (i=1;i<=len;i++)
  129.           LOOP
  130.         if (!doneflag) 
  131.           THEN
  132.             doneflag = getstring(string);
  133.             if (k == 0 
  134.             && i == 1&& doneflag) goto done;
  135.             if (k == 0 
  136.             && i == 1 && hold && !firstflag)THEN
  137.             typef("Hit return to continue.\n");
  138.             while (!bdos(6,0xff));
  139.               ENDIF
  140.             firstflag = FALSE;
  141.             if (!doneflag) 
  142.               THEN
  143.             strmov(&array[i][margin+k*col+k*space+1],
  144.             string,col);
  145.               ENDIF
  146.           ENDIF
  147.           ENDLOOP
  148.       ENDLOOP
  149.     for (i=1;i<=tm;i++) puts("\n");
  150.     for (i=1;i<=len;i++)
  151.       LOOP
  152.         for (j=MAXW+1;j>0;j--)
  153.         if (array[i][j] != ' ' || j == 1)
  154.           THEN
  155.         array[i][j+1] = 0;
  156.         break;
  157.           ENDIF
  158.         puts(&array[i][1]);
  159.         puts("\n");
  160.       ENDLOOP
  161.     for (i=1;i<=bm;i++) puts("\n");
  162.       ENDLOOP
  163.     while (doneflag == FALSE);
  164.     done:;
  165.     dioflush();
  166.   END
  167.  
  168. strmov(s1,s2,n)
  169. char *s1,*s2;
  170. int n;
  171.   BEGIN
  172.     int i;
  173.     char c;
  174.     for (i=1;i<=n;i++)
  175.       LOOP
  176.     c = *s2;
  177.     s2++;
  178.     if ((c == 0) || (c == '\n')) 
  179.       THEN
  180.         for (i;i<=n;i++) s1++;
  181.         return(0);
  182.       ENDIF
  183.     *s1 = c;
  184.     s1++;
  185.       ENDLOOP
  186.   END
  187.