home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 62 < prev    next >
Encoding:
Internet Message Format  |  1991-05-03  |  7.1 KB

  1. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  2. Newsgroups: comp.sources.apple2
  3. Subject: v001SRC043:  more -- More For Orca (GS)
  4. Message-ID: <May.2.17.09.11.1991.311@yoko.rutgers.edu>
  5. Date: 2 May 91 21:09:12 GMT
  6. Approved: jac@paul.rutgers.edu
  7.  
  8.  
  9. Submitted-by: Jawaid Bazyar (bazyar@cs.uiuc.edu)
  10. Posting-number: Volume 1, Source:43
  11. Archive-name: util/gs/shell/orca/more
  12. Architecture: ONLY_2gs
  13. Version-number: 1.2
  14.  
  15.  
  16. View a file one page at a time.
  17.  
  18. Requires ORCA shell.
  19.  
  20. Enjoy.
  21.  
  22. ###################################
  23.  
  24. =more.doc
  25. -============
  26. -    MORE
  27. -============
  28. -
  29. -Version 1.2
  30. -
  31. -The first tool I wanted was a text file pager.  TYPE worked ok, but
  32. -having to hit the space bar at just the right time got on my nerves.
  33. -So I first created PAGE (RIP), then MORE.  As it exists, MORE looks like
  34. -Unix 'more'.  It doesn't support searching with regular expressions
  35. -and silliness like that (that's what uEmacs is for).  But it's a good
  36. -pager.
  37. -
  38. -MORE is invoked with the following format:
  39. -
  40. -   MORE <filespec>...
  41. -
  42. -When the - <filename> (xx%) - prompt appears at the bottom of the screen,
  43. -pressing Q will quit the current file and MORE the next one (if present).
  44. -Hitting ESC at this prompt will stop the program completely (whether more
  45. -files were specified or not).  Pressing SPACE will scroll through another page
  46. -of the file.  RETURN will move forward in the file one line.
  47. -
  48. -MORE supports redirection and pipes.  If the output is redirected away
  49. -from the console, more won't pause for each page.  In this way it can be
  50. -used as a simple text file converter.
  51. -
  52. -The most useful aspect of MORE is it's versatility- it can read regular Apple
  53. -(CR-delimited) TXT and SRC files, Unix text files (LF-delimited), and IBM CRLF
  54. -text files.  All automatically.
  55. -By redirecting output to a file, MORE can convert from Unix or IBM to Apple
  56. -text format.  Neat, eh? (But using MORE is slower than using CONV- see below).
  57. -
  58. -MORE has no option switches- it's too simple.
  59. -
  60. -Change Log:
  61. -
  62. -v1.1 - MORE can now abort either an individual file or all files. Also,
  63. -       changed return from 'advance page' to 'advance line', like the
  64. -       Unix version.
  65. -
  66. -Note:
  67. -
  68. -A filespec is a method of identifying files on a disk.  In the ORCA
  69. -shell, a filespec can contain the = and ? wildcards, in addition to
  70. -plain filenames.  MORE supports multiple filespecs, e.g.
  71. -    more a.c b.c c.c d=.c
  72. -etc.  Any combination of wildcarded and/or vanilla filespecs is allowed.
  73. -This functionality, however, comes at a price.  MORE works only under
  74. -the ORCA shell or a compatible.  At this time, there are no shells truly
  75. -compatible with ORCA.
  76. -
  77. ------
  78. -
  79. -Jawaid Bazyar
  80. -Derek Taubert
  81. -
  82. -Copyright 1990 by Procyon Software
  83. -Freeware - distribute but don't sell!
  84. -
  85. -This utility is FreeWare.  Distribute them as much as you like, just
  86. -don't sell them or distribute modified versions.  Send me your comments -
  87. -I'm eager to hear from you for suggestions and improvements.
  88. -
  89. -Also, if you make any modifications to the code please do not redistribute
  90. -them. Instead, send me the changed source along with an explanation and
  91. -I will consider including your change in the next version.
  92. -
  93. -    Jawaid Bazyar
  94. -    1120 Maple Street
  95. -    Mt. Vernon, IL 62864
  96. -
  97. -    Internet/ARPAnet     bazyar@cs.uiuc.edu
  98. -    GEnie                J.BAZYAR
  99. -
  100. =more.c
  101. -#pragma optimize -1
  102. -
  103. -#pragma keep "6/more"
  104. -
  105. -#include <stdio.h>
  106. -#include <stdlib.h>
  107. -#include <shell.h>
  108. -#include <gsos.h>
  109. -#include <string.h>
  110. -#include <orca.h>
  111. -
  112. -#pragma lint -1
  113. -
  114. -#define MAX_LINE 24
  115. -#define MAX_COL 80
  116. -
  117. -int main(int argc,char *argv[])
  118. -{
  119. -FILE *file;
  120. -int line,col;
  121. -int i;
  122. -int c,quit,abort;
  123. -int pipeFlag; /* 1 means input is piped in or redirected */
  124. -int standardOut;
  125. -DirectionPB checkIO;
  126. -EOFRecGS eofs;
  127. -char expanded[65];
  128. -char *truncated;
  129. -Init_WildcardPB iwpb;
  130. -Next_WildcardPB nwpb;
  131. -
  132. -    checkIO.device = 1;
  133. -    DIRECTION(&checkIO);
  134. -    standardOut = (checkIO.direct != 0) ? 0 : 1;
  135. -
  136. -    pipeFlag = (argc == 1) ? 1 : 0;
  137. -    if (argc == 1) argc = 2;
  138. -    quit = 0;
  139. -    abort = 0;
  140. -
  141. -    for (i = 1; (i < argc && !abort); i++)
  142. -    {
  143. -      if (!pipeFlag) {
  144. -          strcpy(expanded+1,argv[i]);
  145. -          expanded[0] = strlen(argv[i]);
  146. -          iwpb.w_file = expanded;
  147. -          iwpb.flags = 0x8000;
  148. -          INIT_WILDCARD(&iwpb);
  149. -          nwpb.nextfile = expanded;
  150. -          NEXT_WILDCARD(&nwpb);
  151. -          expanded[expanded[0]+1] = 0;
  152. -      }
  153. -      while ((strlen(expanded) != 0) || (pipeFlag && !quit)) {
  154. -          quit = 0;
  155. -
  156. -          if (pipeFlag) {
  157. -              file = stdin;
  158. -           /*   rewind(file);   */
  159. -          }
  160. -          else {
  161. -              truncated = strrchr(expanded+1,'/');
  162. -              if (truncated == NULL) truncated = expanded+1;
  163. -                  else truncated++;
  164. -              file = fopen(expanded+1,"rb");
  165. -              eofs.pCount = 2;
  166. -              eofs.refNum = file->_file;
  167. -              GetEOFGS(&eofs);
  168. -              if (toolerror()) {
  169. -                  printf("GS/OS Error %d\n",toolerror());
  170. -                  exit(-1);
  171. -              }
  172. -          }
  173. -          line = 1; col = 1;
  174. -
  175. -          c = getc(file);
  176. -          if ((c == EOF) || (c == 0x04)) quit = 1;
  177. -
  178. -          while (!quit && !abort)
  179. -
  180. -          {
  181. -          int k;
  182. -
  183. -              if (c == '\r') {
  184. -                  if ((k = getc(file)) == '\n') /*  IBM silly CR & LF EOL */
  185. -                      putchar('\n');
  186. -                  else { ungetc(k,file); putchar('\n'); }
  187. -                  col = 1; line++;
  188. -              }
  189. -              else
  190. -              if (c == '\n')
  191. -              {
  192. -                  putchar('\n');
  193. -                  col = 1; line++;
  194. -              }
  195. -              else
  196. -              {
  197. -                  putchar(c);
  198. -                  col++;
  199. -                  if (col > MAX_COL)
  200. -                  {
  201. -                      col = 1; line++;
  202. -                  }
  203. -              }
  204. -              if ((line == MAX_LINE) && standardOut)
  205. -              {  long percent;
  206. -                  putchar(15);
  207. -                  if (!pipeFlag)
  208. -                  {
  209. -                      percent = (ftell(file) * 100) / eofs.eof;
  210. -                      printf(" - %s (%2ld%%) -",truncated,percent);
  211. -                  }
  212. -                  else
  213. -                      printf(" - (pipe) -");
  214. -                  putchar(14);
  215. -                  asm {
  216. -                  again: lda 0xE0C000
  217. -                         bpl again
  218. -                         sta c
  219. -                         lda 0xE0C010
  220. -                  }
  221. -                  c = c & 0x7f;
  222. -
  223. -                  if (c == 'q') quit = 1;
  224. -                  if (c == 27) abort = 1;
  225. -                  if (c == 13) line--;
  226. -                  else line = 1;
  227. -                  for (c = 0; c < (11 + (pipeFlag ? 0 : strlen(truncated))); c++)
  228. -                  {
  229. -                      putchar(8);
  230. -                      putchar(' ');
  231. -                      putchar(8);
  232. -                  }
  233. -              }
  234. -              c = getc(file);
  235. -              if ((c == EOF) || (c == 0x04)) quit = 1;
  236. -          }
  237. -        /*  if (!pipeFlag)*/ fclose(file);
  238. -       if (!pipeFlag)
  239. -       {   NEXT_WILDCARD(&nwpb);
  240. -          expanded[expanded[0]+1] = 0; }
  241. -       }
  242. -    }
  243. -}
  244. -
  245. + END OF ARCHIVE
  246.