home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 007.lha / xicon / ticon.c < prev    next >
C/C++ Source or Header  |  1986-11-09  |  3KB  |  109 lines

  1.  
  2. /****************************************************************
  3.  *                                                              *
  4.  *    TICON                                                     *
  5.  *                                                              *
  6.  *   Types (displays) Text Files from an Icon                   *
  7.  *                                                              *
  8.  *   copyright 1986 by Pete Goodeve -- All Rights Reserved      *
  9.  *                                                              *
  10.  *    This is a quick hack, sparsely commented -- Sorry.        *
  11.  *                                                              *
  12.  *    Compile with pass 2 -v option (Lattice)                   *
  13.  *    Link with lstartup.obj, amiga.lib, lc.lib                 *
  14.  *                                                              *
  15.  * vers 86:7:15                                                 *
  16.  ****************************************************************/
  17.  
  18. #include "exec/types.h"
  19. #include "workbench/startup.h"
  20.  
  21.  
  22. extern struct WBStartup *WBenchMsg;
  23.  
  24. struct WBArg *argptr;
  25. int nargs;
  26.  
  27. LONG infile, outfile;
  28.  
  29. _main()
  30. {
  31.  
  32.    if (!WBenchMsg)
  33.       return 0;
  34.  
  35.    if (!(outfile = Open("CON:0/10/640/185/TICON 1.00", MODE_OLDFILE)))
  36.       return 0;
  37.  
  38.    argptr = WBenchMsg->sm_ArgList;
  39.    nargs = WBenchMsg->sm_NumArgs;
  40.    for(argptr++, nargs--; nargs; argptr++, nargs--)
  41.       doito(argptr);
  42.  
  43.    display("\n\n<<type ctrl-C to close window>>");
  44.    Wait(SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D);
  45.    Close(outfile);
  46. }
  47. /*** end main ***/
  48.  
  49.  
  50. doito(argp) struct WBArg *argp;
  51. {
  52.    LONG oldir;
  53.  
  54.    oldir = CurrentDir(argp->wa_Lock);
  55.    infile = Open(argp->wa_Name, MODE_OLDFILE);
  56.    dispfile();
  57.    Close(infile);
  58.    CurrentDir(oldir);
  59. }
  60.  
  61. display(msg) char *msg;
  62. {
  63.    Write(outfile, msg, strlen(msg));
  64. }
  65.  
  66. #define BUFSIZE 200
  67.  
  68. dispfile()
  69. {
  70.    char inbuf[BUFSIZE], outbuf[BUFSIZE], ansbuf[2];
  71.    int inpos = 0, lcount = 20;
  72.    while (copyline(inbuf, &inpos, outbuf)) {
  73.       if (!lcount-- || *outbuf == '\014' /*Formfeed*/) {
  74.          display("<<Type return to continue>>");
  75.          Read(outfile,ansbuf,1);
  76.          display("\x1b\x9bF\x1b\x9bM"); /* backup one line & delete */
  77.          display(outbuf);
  78.          lcount = 15; /* leave some overlap with previous page */
  79.       }
  80.       else display(outbuf);
  81.       if (SetSignal(0,SIGBREAKF_CTRL_C)) break;
  82.    }
  83. }
  84.  
  85. copyline(in, pos, out) char *in, *out; int *pos;
  86. {
  87.    char ch, copych();
  88.    int trunc=BUFSIZE-1;
  89.    while ((*out++ = ch = copych(in, pos)) && ch != '\n' && --trunc)
  90.        /*loop*/;
  91.    *out = '\0';
  92.    return (int) ch /* FALSE if EOF */;
  93. }
  94.  
  95.  static int curmax=0;
  96.  
  97. char copych(in, pos) char *in; int *pos;
  98. {
  99.    if (*pos >= curmax) {
  100.       curmax = Read(infile,in,BUFSIZE);
  101.       *pos = 0;
  102.       if (!curmax) return '\0';
  103.    }
  104.    return in[(*pos)++];
  105. }
  106.  
  107. /**************************************/
  108.  
  109.