home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / more.zip / more.c next >
C/C++ Source or Header  |  1994-01-15  |  3KB  |  114 lines

  1. /*    More by L Kuru 4.1.1994 */
  2.  
  3. /* IBM OS/2 more works, but through pipes only + gives an */
  4. /*    extra blank line on top of screen which is very confusing + */
  5. /* changes your text window size */
  6. /* 'fast' more ( by S. Lacy) can't handle colors + sends too long "tab'ed" */
  7. /* lines off screen, normal too long lines -> last char of line is not used */
  8.  
  9. /* Redirection to a file not ok; ibm more even worse here; 'fast' more */
  10. /* writes directly to screen, no redirection possible */
  11. /* > -redirection doesn't work very well, type is recommended instead */
  12.  
  13. /* compiled with BC++ 1.0 for OS/2 */
  14. /* wildcard support by linking WILDARGS.OBJ (by Borland) with source */
  15.  
  16. #include<stdio.h>
  17. #include<conio.h>
  18. #include<stdlib.h>
  19. #include<io.h>
  20. #include<string.h>
  21.  
  22. int main(int argc, char *argv[])
  23. {
  24. struct text_info ti;
  25. int x,y;
  26. unsigned int lines;
  27. int i,j,k;
  28. FILE *rp;
  29. char curline[134];
  30. char blank[134]="";
  31.  
  32. gettextinfo(&ti);
  33. x=ti.screenwidth+1;
  34. y=ti.screenheight;
  35. for(i=1;i<x-1;i++)strcat(blank," ");
  36.  
  37. /* my clrscr */
  38. gotoxy(1,1);
  39. for(i=1;i<y;i++)printf("%s ",blank);printf("%s",blank);
  40. gotoxy(1,1);
  41.  
  42. /* open input stream */
  43. for( k=0;k<argc;k++)
  44.     {
  45.     if(argc==1) {rp=stdin;}
  46.         else if((rp=fopen(argv[k+1],"rt"))==NULL)
  47.             {fprintf(stderr,"Error opening file %s.\n",argv[k+1]);exit(1);}
  48.  
  49.     /* count # of lines for % information */
  50.     lines=0;
  51.     if(argc!=1)
  52.         {
  53.         while (!feof(rp)){fgets(curline,x,rp);++lines;};
  54.         rewind(rp);
  55.         }
  56.  
  57.     /* my more; i used for %-info */
  58.     i=0;
  59.     while(!feof(rp))
  60.         {
  61.         fgets(curline,x,rp);
  62.         printf("%s",curline);
  63.         strcpy(curline,"");
  64.         i++;
  65.         if(wherey()==y)
  66.             {
  67.             printf("\r -- more --");
  68.             if(argc!=1)printf("\b %s - %2d % --",argv[k+1],100*i/lines);
  69.  
  70.             j=getch();
  71.             switch (j)
  72.                 {
  73.                 case 'q' :  /* 113 */
  74.                     fclose(rp);
  75.                     return(0);
  76.                     break;
  77.                 case 13 : /* enter */
  78.                     printf("\r%s\n\n\n\n",blank);
  79.                     gotoxy(1,y-4);
  80.                     break;
  81.                 case 'v' :/* version info */
  82.                     printf("\r%s\r -- more v 1.0 by qru --",blank);
  83.                     /* repeat this section to make enter and q work after v */
  84.                     j=getch();
  85.                     switch (j)
  86.                         {
  87.                         case 'q' :  /* 113 */
  88.                             fclose(rp);
  89.                             return(0);
  90.                             break;
  91.                         case 13 : /* enter */
  92.                             printf("\r%s\n\n\n\n",blank);
  93.                             gotoxy(1,y-4);
  94.                             break;
  95.                         default:
  96.                         ;
  97.                         }                default:
  98.                 ;
  99.                 }
  100.             if(j!=13)   /* "default", clrscr */
  101.                 {
  102.                 gotoxy(1,1);
  103.                 for(j=1;j<y;j++)printf("%s ",blank);printf("\r%s",blank);
  104.                 gotoxy(1,1);
  105.                 }
  106.             }
  107.         }
  108.  
  109.     fclose(rp);
  110.     if(argc==(k+2)||argc==1) return (0);
  111.     }
  112. return (0);
  113. }
  114.