home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d832 / term.lha / Term / term-3.1-Source.lha / termCapture.c < prev    next >
C/C++ Source or Header  |  1993-02-18  |  5KB  |  308 lines

  1. /*
  2. **    termCapture.c
  3. **
  4. **    File and printer capture support routines
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Capture(APTR Buffer,LONG Size):
  13.      *
  14.      *    Send the buffer contents to the display/disk capture.
  15.      */
  16.  
  17. VOID __regargs
  18. Capture(APTR Buffer,LONG Size)
  19. {
  20.         /* Send the filtered data to the capture file. */
  21.  
  22.     if(Config -> CaptureConfig -> CaptureFilterMode)
  23.         CaptureToFile(Buffer,Size);
  24.  
  25.         /* Store data in the log book. */
  26.  
  27.     if(!BufferFrozen)
  28.         StoreBuffer(Buffer,Size);
  29.  
  30.         /* Send the buffer to the printer. */
  31.  
  32.     if(PrinterCapture && Size)
  33.     {
  34.         if(FWrite(PrinterCapture,Buffer,Size,1) != 1)
  35.         {
  36.             BlockWindows();
  37.  
  38.             if(!MyEasyRequest(Window,LocaleString(MSG_CONSOLE_ERROR_WRITING_TO_PRINTER_TXT),LocaleString(MSG_CONSOLE_IGNORE_CLOSE_PRINTER_TXT)))
  39.             {
  40.                 Close(PrinterCapture);
  41.  
  42.                 CheckItem(MEN_CAPTURE_TO_PRINTER,FALSE);
  43.  
  44.                 PrinterCapture = NULL;
  45.  
  46.                 ConOutputUpdate();
  47.             }
  48.  
  49.             ReleaseWindows();
  50.         }
  51.     }
  52. }
  53.  
  54.     /* ClosePrinterCapture(BYTE Force):
  55.      *
  56.      *    Closes printer capture file.
  57.      */
  58.  
  59. VOID
  60. ClosePrinterCapture(BYTE Force)
  61. {
  62.     if(PrinterCapture)
  63.     {
  64.         if(ControllerActive && StandardPrinterCapture && !Force)
  65.             FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_TERMINAL_TRANSCRIPT_ENDING_TXT));
  66.  
  67.         if(Force)
  68.         {
  69.             Close(PrinterCapture);
  70.  
  71.             CheckItem(MEN_CAPTURE_TO_PRINTER,FALSE);
  72.  
  73.             PrinterCapture = NULL;
  74.  
  75.             ConOutputUpdate();
  76.  
  77.             StandardPrinterCapture = FALSE;
  78.         }
  79.     }
  80.  
  81.     ControllerActive = FALSE;
  82.  
  83.     ConOutputUpdate();
  84. }
  85.  
  86.     /* OpenPrinterCapture(BYTE Controller):
  87.      *
  88.      *    Opens printer capture file.
  89.      */
  90.  
  91. BYTE
  92. OpenPrinterCapture(BYTE Controller)
  93. {
  94.     if(PrinterCapture)
  95.     {
  96.         if(Controller && !ControllerActive)
  97.         {
  98.             ControllerActive = TRUE;
  99.  
  100.             ConOutputUpdate();
  101.  
  102.             FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_TERMINAL_TRANSCRIPT_FOLLOWS_TXT));
  103.         }
  104.  
  105.         return(TRUE);
  106.     }
  107.     else
  108.     {
  109.         if(PrinterCapture = Open("PRT:",MODE_NEWFILE))
  110.             CheckItem(MEN_CAPTURE_TO_PRINTER,TRUE);
  111.         else
  112.         {
  113.             CheckItem(MEN_CAPTURE_TO_PRINTER,FALSE);
  114.  
  115.             BlockWindows();
  116.  
  117.             MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_ERROR_OPENING_PRINTER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),"PRT:");
  118.  
  119.             ReleaseWindows();
  120.         }
  121.  
  122.         if(Controller)
  123.         {
  124.             ControllerActive    = TRUE;
  125.             StandardPrinterCapture    = FALSE;
  126.         }
  127.         else
  128.         {
  129.             StandardPrinterCapture = FALSE;
  130.  
  131.             if(ControllerActive)
  132.                 FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_USER_TERMINAL_TRANSCRIPT_FOLLOWS_TXT));
  133.         }
  134.  
  135.         ConOutputUpdate();
  136.  
  137.         if(PrinterCapture)
  138.             return(TRUE);
  139.         else
  140.             return(FALSE);
  141.     }
  142. }
  143.  
  144.     /* CloseFileCapture():
  145.      *
  146.      *    Close the capture file.
  147.      */
  148.  
  149. VOID
  150. CloseFileCapture()
  151. {
  152.     if(FileCapture)
  153.     {
  154.         BufferClose(FileCapture);
  155.  
  156.         FileCapture = NULL;
  157.  
  158.         if(!GetFileSize(CaptureName))
  159.             DeleteFile(CaptureName);
  160.         else
  161.             SetProtection(CaptureName,FIBF_EXECUTE);
  162.     }
  163.  
  164.     CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  165.  
  166.     ConOutputUpdate();
  167. }
  168.  
  169.     /* OpenFileCapture():
  170.      *
  171.      *    Open a capture file.
  172.      */
  173.  
  174. BYTE
  175. OpenFileCapture()
  176. {
  177.     struct FileRequester    *FileRequest;
  178.     UBYTE             DummyBuffer[MAX_FILENAME_LENGTH],
  179.                 *DummyChar;
  180.     BYTE             Aborted = FALSE;
  181.  
  182.     CloseFileCapture();
  183.  
  184.     BlockWindows();
  185.  
  186.     if(!CaptureName[0])
  187.     {
  188.         strcpy(CaptureName,Config -> CaptureConfig -> CapturePath);
  189.  
  190.         if(!AddPart(CaptureName,LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT),MAX_FILENAME_LENGTH))
  191.             CaptureName[0] = 0;
  192.     }
  193.  
  194.     strcpy(DummyBuffer,CaptureName);
  195.  
  196.     DummyChar = PathPart(DummyBuffer);
  197.  
  198.     *DummyChar = 0;
  199.  
  200.     if(FileRequest = GetFile(LocaleString(MSG_TERMMAIN_CAPTURE_TO_DISK_TXT),DummyBuffer,FilePart(CaptureName),DummyBuffer,NULL,TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_OPEN_TXT)))
  201.     {
  202.         if(GetFileSize(DummyBuffer))
  203.         {
  204.             switch(MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FILE_ALREADY_EXISTS_TXT),LocaleString(MSG_GLOBAL_CREATE_APPEND_CANCEL_TXT),DummyBuffer))
  205.             {
  206.                 case 1:
  207.  
  208.                     FileCapture = BufferOpen(DummyBuffer,"w");
  209.                     break;
  210.  
  211.                 case 2:
  212.  
  213.                     FileCapture = BufferOpen(DummyBuffer,"a");
  214.                     break;
  215.  
  216.                 case 0:
  217.  
  218.                     FileCapture = NULL;
  219.  
  220.                     Aborted = TRUE;
  221.  
  222.                     break;
  223.             }
  224.         }
  225.         else
  226.             FileCapture = BufferOpen(DummyBuffer,"w");
  227.  
  228.         if(!Aborted)
  229.         {
  230.             if(!FileCapture)
  231.                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_ERROR_OPENING_FILE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  232.             else
  233.                 strcpy(CaptureName,DummyBuffer);
  234.         }
  235.  
  236.         FreeAslRequest(FileRequest);
  237.     }
  238.  
  239.     if(FileCapture)
  240.         CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  241.     else
  242.         CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  243.  
  244.     ConOutputUpdate();
  245.  
  246.     ReleaseWindows();
  247.  
  248.     if(FileCapture)
  249.         return(TRUE);
  250.     else
  251.         return(FALSE);
  252. }
  253.  
  254.     /* CaptureToFile(APTR Buffer,LONG Size):
  255.      *
  256.      *    Send data to the capture file.
  257.      */
  258.  
  259. VOID __regargs
  260. CaptureToFile(APTR Buffer,LONG Size)
  261. {
  262.     if(FileCapture && Size)
  263.     {
  264.         if(BufferWrite(FileCapture,Buffer,Size) != Size)
  265.         {
  266.             BlockWindows();
  267.  
  268.                 /* We had an error writing to the file. */
  269.  
  270.             switch(MyEasyRequest(NULL,LocaleString(MSG_CONSOLE_ERROR_WRITING_TO_CAPTURE_FILE_TXT),LocaleString(MSG_CONSOLE_IGNORE_DISCARD_CLOSE_TXT),CaptureName))
  271.             {
  272.                 case 1:
  273.  
  274.                     BufferClose(FileCapture);
  275.  
  276.                     DeleteFile(CaptureName);
  277.  
  278.                     CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  279.  
  280.                     FileCapture = NULL;
  281.  
  282.                     ConOutputUpdate();
  283.  
  284.                     break;
  285.  
  286.                 case 2:
  287.  
  288.                     BufferClose(FileCapture);
  289.  
  290.                     CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  291.  
  292.                     FileCapture = NULL;
  293.  
  294.                     if(!GetFileSize(CaptureName))
  295.                         DeleteFile(CaptureName);
  296.                     else
  297.                         SetProtection(CaptureName,FIBF_EXECUTE);
  298.  
  299.                     ConOutputUpdate();
  300.  
  301.                     break;
  302.             }
  303.  
  304.             ReleaseWindows();
  305.         }
  306.     }
  307. }
  308.