home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 33 < prev    next >
Encoding:
Internet Message Format  |  1990-12-02  |  3.1 KB

  1. Path: wuarchive!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!jac
  2. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  3. Newsgroups: comp.sources.apple2
  4. Subject: v001SRC010:  View A File 1 Page At A Time
  5. Message-ID: <Dec.1.16.37.43.1990.24383@yoko.rutgers.edu>
  6. Date: 1 Dec 90 21:37:44 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 155
  9. Approved: jac@paul.rutgers.edu
  10.  
  11.  
  12. Submitted-by: NONE
  13. Posting-number: Volume 1, Source:10
  14. Archive-name: util/page
  15. Architecture: ANY_2
  16. Version-number: 1.00
  17.  
  18. Enclosed is page.c.  It allows you to view a file one page at a
  19. time.
  20.  
  21. Enjoy.
  22.  
  23.  
  24. =page.c
  25. -
  26. -/*
  27. - *
  28. - * page.c
  29. - *
  30. - * Examine a file one screenful at a time.
  31. - *
  32. - * Developed for the AZTEC C system for the Apple ][+, Apple //e computer.
  33. - * Based on a more.c by aluxe!ira.
  34. - *
  35. - * Bob Cunningham
  36. - * bob@kahala.soest.hawaii.edu
  37. - * November 19, 1983
  38. - *
  39. - * Version 1.00
  40. - *
  41. - * This code is offered without any warranty or support.
  42. - *
  43. - */
  44. -#include "kbctl.h"
  45. -#include "stdio.h"
  46. -#define SCRNSIZE 24
  47. -#define MAXLINE 1000
  48. -#define NEWPAGE ioctl( 1, KB_CLEAR)
  49. -char    str_e[] = "  End of  ";
  50. -char    str_m[] = "--More--  ";
  51. -char    str_more[] = "  [Hit 'space' to continue, 'q' to quit] ";
  52. -int    file_len;
  53. -main(argc, argv)
  54. -    int    argc;
  55. -    char    *argv[];
  56. -    {
  57. -    char    line[MAXLINE], *s;
  58. -    long    lineno;
  59. -    int    flag, srnsize, len;
  60. -    FILE * fp, *fopen();
  61. -    flag = lineno = 0;
  62. -    srnsize = SCRNSIZE - 2;
  63. -    while (--argc > 0 && (*++argv)[0] == '-' )
  64. -        for (s = argv[0] + 1; *s != '\0'; s++)
  65. -            switch (*s)
  66. -                {
  67. -                default:
  68. -                    printf("page: illegal option %c\n",
  69. -                           *s );
  70. -                    argc = 0;
  71. -                    break;
  72. -                }
  73. -    if ( argc < 1 ) 
  74. -        {
  75. -        printf("Usage: page file1 [ file2 file3 .. ]\n");
  76. -        exit(1);
  77. -        }
  78. -     else
  79. -        *--argv;
  80. -    if ( argc >= 2 )
  81. -        flag = 1;
  82. -    while ( --argc >= 0 )
  83. -        {
  84. -        if ((fp = fopen(*++argv, "r")) == NULL)
  85. -            {
  86. -            printf("page: can't open %s\n", *argv);
  87. -            exit(1);
  88. -            }
  89. -        NEWPAGE;
  90. -        if (flag)
  91. -            {
  92. -            printf(":::::::::::::::::::\n");
  93. -            printf("%s\n",*argv);
  94. -            printf(":::::::::::::::::::\n");
  95. -            lineno = 2;
  96. -            }
  97. -        fp->bufsiz = 2048;
  98. -        file_len = strlen (*argv);
  99. -        while ( (len = getline(line, MAXLINE, fp)) > 0)
  100. -            {
  101. -            lineno++;
  102. -            write( 1, line, len );
  103. -            if ( lineno % srnsize == 0 )
  104. -                {
  105. -                if ( more(str_m,*argv) == -1 )
  106. -                    exit(0);
  107. -                lineno = 0;
  108. -                }
  109. -            }
  110. -            fclose(fp);
  111. -            if ( (argc >= 1) )
  112. -                {
  113. -                fflush(stdout);
  114. -                if ( more(str_e,*argv) == -1 )
  115. -                    exit(0);
  116. -                }
  117. -            lineno = 0;
  118. -        }
  119. -    }
  120. -getline(s, lim, fp)
  121. -char    *s;
  122. -int    lim;
  123. -FILE *fp;
  124. -{
  125. -    char    c, *pc;
  126. -    pc = s;
  127. -    while (--lim > 0 && (c = agetc(fp) ) != EOF && c != '\n' )
  128. -        *pc++ = c;
  129. -    if (c == '\n' )
  130. -        *pc++ = c;
  131. -    *pc = '\0';
  132. -    return((int)(pc - s));
  133. -}
  134. -more(msg,file)
  135. -    char   *msg;
  136. -    char    *file;
  137. -    {
  138. -    int    c;
  139. -    ioctl ( 1, KB_INV, 1 );
  140. -    write ( 1, msg, 11);
  141. -    write ( 1, file, file_len);
  142. -    write ( 1, str_more, 42 );
  143. -    ioctl ( 1, KB_INV, 0 );
  144. -    c = getchar();
  145. -    ioctl ( 1, KB_CURS, ( 23 << 8 ) | 0 );
  146. -    ioctl ( 1, KB_CLEOL );
  147. -    if ( c != ' ' && c != 'q' )
  148. -        more(file);
  149. -    if ( c == 'q' )
  150. -        return(-1);
  151. -    NEWPAGE;
  152. -    }
  153. + END OF ARCHIVE
  154.