home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / MM1 / SOUNDUTILS / mm1_tracker.lzh / TRACKER4.6 / Amiga / info.c < prev    next >
Text File  |  1994-11-24  |  2KB  |  95 lines

  1. /* amiga/info.c
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: info.c 1.1 1994/06/22 21:54:12 Espie Exp Espie $
  6.  * $Log: info.c $
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #include <proto/exec.h>
  14.  
  15. #include "defs.h"
  16. #include "extern.h"
  17. #include "amiga/amiga.h"
  18.  
  19. ID("$Id")
  20.  
  21.  
  22. /***
  23.  ***
  24.  ***        Info window handling
  25.  ***
  26.  ***/
  27.  
  28. /* We chose the easy way: outputting everything in a console window
  29.  * on the fly. An interesting improvement would be to buffer everything
  30.  * and open the window with the right size afterwards
  31.  */
  32. struct handle
  33.    {
  34.    FILE *file;
  35.    int linecount;
  36.    int maxlength;
  37.    int currentlength;
  38.    };
  39.  
  40. #define H(h, field)  ( ((struct handle *)h)->field )
  41.  
  42. void *begin_info(char *title)
  43.    {
  44.    struct handle *new;
  45.    
  46.    char buffer[50];
  47.    
  48.    new = malloc(sizeof(struct handle));
  49.    if (!new)
  50.       return 0;
  51.    sprintf(buffer, "CON:////%s/auto/close/wait", title);
  52.    new->file=fopen(buffer, "w");
  53.    if (!new->file)
  54.       {
  55.       free(new);
  56.       return 0;
  57.       }
  58.    new->linecount = 0;
  59.    new->maxlength = 0;
  60.    new->currentlength = 0;
  61.    return new;
  62.    }
  63.  
  64. void infos(void *handle, char *s)
  65.    {
  66.    if (handle)
  67.       {
  68.       fprintf( H(handle,file), s);
  69.       H(handle, currentlength) += strlen(s);
  70.       }
  71.    }
  72.  
  73. void info(void *handle, char *line)
  74.    {
  75.    infos(handle, line);
  76.    if (handle)
  77.       {
  78.       fputc('\n', H(handle, file));
  79.       if ( H(handle, currentlength) > H(handle, maxlength) )
  80.          H(handle, maxlength) = H(handle, currentlength);
  81.       H(handle, linecount)++;
  82.       }
  83.    }
  84.  
  85. void end_info(void *handle)
  86.    {
  87.    if (handle)
  88.       {
  89.       
  90.       fclose(H(handle, file));
  91.       free(handle);
  92.       }
  93.    }
  94.  
  95.