home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Console.c
- **
- ** High-level terminal console routines
- **
- ** Copyright © 1990-1996 by Olaf `Olsen' Barthel
- ** All Rights Reserved
- */
-
- #ifndef _GLOBAL_H
- #include "Global.h"
- #endif
-
- /* Character set modes. */
-
- enum { MODE_STANDARD,MODE_GFX };
-
- /* Hints for the data flow scanner. */
-
- STATIC WORD ScanStart,
- ScanEnd;
-
- STATIC WORD AttentionCount[SCAN_COUNT],
- AttentionLength[SCAN_COUNT],
- FlowCount;
-
- /* Temporary console working buffer. */
-
- STATIC UBYTE ConTempBuffer[512];
-
- /* ConTranslateSetup():
- *
- * Set up for buffer translation.
- */
-
- STATIC VOID
- ConTranslateSetup(struct TranslationHandle *Handle,STRPTR SourceBuffer,LONG SourceLen,STRPTR DestinationBuffer,LONG DestinationLen,struct TranslationEntry **Table)
- {
- Handle -> LocalBuffer = NULL;
- Handle -> LocalLen = 0;
-
- Handle -> SourceBuffer = SourceBuffer;
- Handle -> SourceLen = SourceLen;
-
- Handle -> DestinationBuffer = DestinationBuffer;
- Handle -> DestinationLen = DestinationLen;
-
- Handle -> Table = Table;
- }
-
- /* ConTranslateBuffer(struct TranslationHandle *Handle):
- *
- * Translate buffer contents according to
- * translation table contents.
- */
-
- STATIC LONG
- ConTranslateBuffer(struct TranslationHandle *Handle)
- {
- register STRPTR Data = Handle -> DestinationBuffer;
- register LONG BytesWritten = 0;
- register struct TranslationEntry *Entry;
-
- /* Are we to return any translated data? */
-
- while(Handle -> LocalLen && BytesWritten < Handle -> DestinationLen)
- {
- /* Decrement number of bytes in buffer. */
-
- Handle -> LocalLen--;
-
- /* Return next character. */
-
- *Data++ = *Handle -> LocalBuffer++;
-
- /* Add another byte. */
-
- BytesWritten++;
- }
-
- /* Loop until done. */
-
- while(Handle -> SourceLen && BytesWritten < Handle -> DestinationLen)
- {
- /* Another byte eaten. */
-
- Handle -> SourceLen--;
-
- /* Get table entry. */
-
- if(Entry = Handle -> Table[*Handle -> SourceBuffer++])
- {
- /* Copy to local data area. */
-
- Handle -> LocalBuffer = Entry -> String;
- Handle -> LocalLen = Entry -> Len;
-
- /* Translate the data. */
-
- while(Handle -> LocalLen && BytesWritten < Handle -> DestinationLen)
- {
- /* Decrement number of bytes in buffer. */
-
- Handle -> LocalLen--;
-
- /* Return next character. */
-
- *Data++ = *Handle -> LocalBuffer++;
-
- /* Add another byte. */
-
- BytesWritten++;
- }
- }
- }
-
- return(BytesWritten);
- }
-
- /* TrapFilter(register STRPTR Data,register LONG Size):
- *
- * Handle the trap list, similar to FlowFilter().
- */
-
- STATIC VOID
- TrapFilter(register STRPTR Data,register LONG Size)
- {
- if(Size)
- {
- STATIC LONG WaitCount = 0;
-
- struct List *List = (struct List *)&GenericListTable[GLIST_TRAP] -> ListHeader;
- struct TrapNode *Node;
-
- register LONG c,Mask;
-
- ObtainSemaphore(&GenericListTable[GLIST_TRAP] -> ListSemaphore);
-
- if(Config -> SerialConfig -> StripBit8)
- Mask = 0x7F;
- else
- Mask = 0xFF;
-
- do
- {
- register BOOL MatchMade;
-
- c = (*Data++) & Mask;
-
- do
- {
- MatchMade = FALSE;
-
- for(Node = (struct TrapNode *)List -> lh_Head ; Node -> Node . ln_Succ ; Node = (struct TrapNode *)Node -> Node . ln_Succ)
- {
- if(Node -> Count == WaitCount)
- {
- if(c == (Node -> Sequence[WaitCount] & Mask))
- {
- MatchMade = TRUE;
-
- if(++Node -> Count == Node -> SequenceLen)
- {
- struct DataMsg *Msg;
-
- Node -> Count = 0;
-
- if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg) + strlen(Node -> Command) + 1))
- {
- Msg -> Type = DATAMSGTYPE_SERIALCOMMAND;
- Msg -> Data = (STRPTR)(Msg + 1);
-
- strcpy(Msg -> Data,Node -> Command);
-
- PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
- }
- }
- }
- }
- }
-
- if(MatchMade)
- WaitCount++;
- else
- {
- if(WaitCount)
- {
- WaitCount = 0;
-
- for(Node = (struct TrapNode *)List -> lh_Head ; Node -> Node . ln_Succ ; Node = (struct TrapNode *)Node -> Node . ln_Succ)
- Node -> Count = 0;
- }
- else
- break;
- }
- }
- while(!WaitCount);
- }
- while(--Size);
-
- ReleaseSemaphore(&GenericListTable[GLIST_TRAP] -> ListSemaphore);
- }
- }
-
- /* FlowFilter(register STRPTR Data,register LONG Size,UBYTE Mask):
- *
- * Data flow filter.
- */
-
- STATIC VOID
- FlowFilter(register STRPTR Data,register LONG Size,register UBYTE Mask)
- {
- register LONG c;
-
- /* Run until done. */
-
- do
- {
- if(c = (*Data++ & Mask))
- {
-
- /* We already got a `CONNECT',
- * Continue scanning the serial output
- * data for the actual baud rate.
- */
-
- if(BaudPending)
- {
- if(c < ' ')
- {
- while(BaudCount > 0 && BaudBuffer[BaudCount - 1] == ' ')
- BaudCount--;
-
- BaudBuffer[BaudCount] = 0;
-
- FlowInfo . Connect = TRUE;
- FlowInfo . Changed = TRUE;
-
- BaudPending = FALSE;
-
- DTERate = GetBaudRate(BaudBuffer);
-
- if(Quiet && Size > 1)
- {
- DataHold = Data;
- DataSize = Size - 1;
- }
- }
- else
- {
- if(BaudCount || c != ' ')
- {
- BaudBuffer[BaudCount++] = c;
-
- if(BaudCount == 79)
- {
- while(BaudCount > 0 && BaudBuffer[BaudCount - 1] == ' ')
- BaudCount--;
-
- BaudBuffer[BaudCount] = 0;
-
- FlowInfo . Connect = TRUE;
- FlowInfo . Changed = TRUE;
-
- BaudPending = FALSE;
-
- DTERate = GetBaudRate(BaudBuffer);
-
- if(Quiet && Size > 1)
- {
- DataHold = Data;
- DataSize = Size - 1;
- }
- }
- }
- }
- }
- else
- {
- register BOOL MatchMade;
- register LONG i;
-
- do
- {
- MatchMade = FALSE;
-
- /* Scan all ID strings for matches. */
-
- for(i = ScanStart ; i <= ScanEnd ; i++)
- {
- /* This sequence is a likely
- * match.
- */
-
- if(AttentionCount[i] == FlowCount)
- {
- /* Does the character
- * fit into the sequence?
- */
-
- if(c == AttentionBuffers[i][FlowCount] & Mask)
- {
- MatchMade = TRUE;
-
- /* Did we hit the
- * last character
- * in the sequence?
- */
-
- if(++AttentionCount[i] == AttentionLength[i])
- {
- /* We've got a valid
- * sequence, now look
- * which flags to change.
- */
-
- switch(i)
- {
- /* We got a `no carrier' message. */
-
- case SCAN_NOCARRIER:
-
- if(!FlowInfo . NoCarrier)
- {
- FlowInfo . NoCarrier = TRUE;
- FlowInfo . Changed = TRUE;
- }
-
- break;
-
- /* Got another call. */
-
- case SCAN_RING:
-
- if(!FlowInfo . Ring)
- {
- FlowInfo . Ring = TRUE;
- FlowInfo . Changed = TRUE;
- }
-
- break;
-
- /* Got a voice call. */
-
- case SCAN_VOICE:
-
- if(!FlowInfo . Voice)
- {
- FlowInfo . Voice = TRUE;
- FlowInfo . Changed = TRUE;
- }
-
- break;
-
- /* Modem reported an error. */
-
- case SCAN_ERROR:
-
- if(!FlowInfo . Error)
- {
- FlowInfo . Error = TRUE;
- FlowInfo . Changed = TRUE;
- }
-
- break;
-
- /* Got a connect message. */
-
- case SCAN_CONNECT:
-
- if(!Online)
- {
- BaudBuffer[0] = 0;
-
- BaudPending = TRUE;
- BaudCount = 0;
- }
-
- break;
-
- /* Line is busy. */
-
- case SCAN_BUSY:
-
- if(!FlowInfo . Busy)
- {
- FlowInfo . Busy = TRUE;
- FlowInfo . Changed = TRUE;
- }
-
- break;
-
- case SCAN_NODIALTONE:
-
- if(!FlowInfo . NoDialTone)
- {
- FlowInfo . NoDialTone = TRUE;
- FlowInfo . Changed = TRUE;
- }
-
- break;
-
- /* Modem accepted a command. */
-
- case SCAN_OK:
-
- if(!FlowInfo . Ok)
- {
- FlowInfo . Ok = TRUE;
- FlowInfo . Changed = TRUE;
- }
-
- break;
-
- default:
-
- if(!FlowInfo . Signature)
- {
- FlowInfo . Signature = i;
- FlowInfo . Changed = TRUE;
- }
-
- break;
- }
- }
- }
- }
- }
-
- if(MatchMade)
- FlowCount++;
- else
- {
- if(FlowCount)
- {
- FlowCount = 0;
-
- memset(AttentionCount,0,sizeof(AttentionCount));
- }
- else
- break;
- }
- }
- while(!FlowCount);
- }
- }
- }
- while(--Size);
- }
-
- /* ConOutputPrinter(STRPTR Buffer,LONG Size):
- *
- * Raw text output routine, printer capture flavour.
- */
-
- STATIC VOID
- ConOutputPrinter(STRPTR Buffer,LONG Size)
- {
- if(Write(PrinterCapture,Buffer,Size) != Size)
- {
- BlockWindows();
-
- if(!ShowRequest(NULL,LocaleString(MSG_CONSOLE_ERROR_WRITING_TO_PRINTER_TXT),LocaleString(MSG_CONSOLE_IGNORE_CLOSE_PRINTER_TXT)))
- ClosePrinterCapture(TRUE);
-
- ReleaseWindows();
- }
- }
-
- /* ConOutputGFX(STRPTR Buffer,LONG Size):
- *
- * Raw text output routine, GFX text flavour.
- */
-
- STATIC VOID
- ConOutputGFX(STRPTR Buffer,LONG Size)
- {
- register LONG Offset;
-
- /* Do we still have a character in the
- * magnificient buffer?
- */
-
- while(Size)
- {
- /* Cursor is positioned at
- * the right hand side of the
- * display. If auto-wrap is
- * enabled, perform some
- * kind of CR/LF, else leave
- * the cursor where it is and
- * quit the show.
- */
-
- if(CursorX > LastPrintableColumn)
- {
- /* Wrap cursor. */
-
- if(Config -> EmulationConfig -> LineWrap)
- {
- /* Move to beginning of next line. */
-
- CursorX = 0;
-
- DownLine();
-
- /* Reposition cursor, don't redraw it. */
-
- RepositionCursor();
- }
- else
- {
- /* Stop the cursor. */
-
- CursorX = LastPrintableColumn;
-
- /* Make it reappear. */
-
- RepositionCursor();
-
- return;
- }
- }
-
- if((Offset = LastPrintableColumn + 1 - CursorX) > Size)
- Offset = Size;
-
- if(Config -> EmulationConfig -> InsertMode)
- {
- RasterShiftChar(Offset);
-
- ScrollLineShiftChar(Offset);
-
- ShiftChar(Offset);
- }
-
- RasterPutString(Buffer,Offset);
-
- ScrollLinePutString(Offset);
-
- if(FontScalingRequired)
- PrintScaled(Buffer,Offset,CurrentFontScale);
- else
- GfxText(RPort,Buffer,Offset);
-
- Buffer += Offset;
-
- Size -= Offset;
-
- CursorX += Offset;
- }
-
- RepositionCursor();
- }
-
- /* ConOutputNormal(STRPTR Buffer,LONG Size):
- *
- * Raw text output routine, normal text flavour.
- */
-
- STATIC VOID
- ConOutputNormal(STRPTR Buffer,LONG Size)
- {
- register LONG Offset;
-
- while(Size)
- {
- if(CursorX > LastPrintableColumn)
- {
- if(Config -> EmulationConfig -> LineWrap)
- {
- CursorX = 0;
-
- DownLine();
-
- RepositionCursor();
- }
- else
- {
- CursorX = LastPrintableColumn;
-
- RepositionCursor();
-
- return;
- }
- }
-
- if((Offset = LastPrintableColumn + 1 - CursorX) > Size)
- Offset = Size;
-
- if(Config -> EmulationConfig -> InsertMode)
- {
- RasterShiftChar(Offset);
-
- ScrollLineShiftChar(Offset);
-
- ShiftChar(Offset);
- }
-
- RasterPutString(Buffer,Offset);
-
- ScrollLinePutString(Offset);
-
- if(FontScalingRequired)
- PrintScaled(Buffer,Offset,CurrentFontScale);
- else
- Text(RPort,Buffer,Offset);
-
- Buffer += Offset;
-
- Size -= Offset;
-
- CursorX += Offset;
- }
-
- RepositionCursor();
- }
-
- /* ConProcessUpdate():
- *
- * Choose the right console data processing routine.
- */
-
- VOID
- ConProcessUpdate()
- {
- Forbid();
-
- if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
- {
- if(ReceiveTable)
- ConProcessData = ConProcessDataTransExternal;
- else
- ConProcessData = ConProcessDataExternal;
- }
- else
- {
- if(Config -> SerialConfig -> StripBit8)
- {
- if(Config -> TerminalConfig -> EmulationMode == EMULATION_HEX)
- ConProcessData = ConProcessDataHex7;
- else
- ConProcessData = ConProcessData7;
- }
- else
- {
- if(Config -> TerminalConfig -> EmulationMode == EMULATION_HEX)
- ConProcessData = ConProcessDataHex8;
- else
- ConProcessData = ConProcessData8;
- }
- }
-
- Permit();
- }
-
- /* ConOutputUpdate():
- *
- * Choose the right raw text output routine for the job.
- */
-
- VOID
- ConOutputUpdate()
- {
- Forbid();
-
- if(Config -> CaptureConfig -> BufferMode == BUFFERMODE_FLOW)
- SaveRaster = SaveRasterDummy;
- else
- SaveRaster = SaveRasterReal;
-
- if(BufferFrozen || Config -> CaptureConfig -> BufferMode != BUFFERMODE_FLOW)
- {
- if(FileCapture)
- {
- if(PrinterCapture)
- {
- if(Config -> CaptureConfig -> CaptureFilterMode && !RawCapture)
- CaptureData = CaptureFilteredTo_File_Printer;
- else
- CaptureData = CaptureRawTo_File_Printer;
- }
- else
- {
- if(Config -> CaptureConfig -> CaptureFilterMode && !RawCapture)
- CaptureData = CaptureFilteredTo_File;
- else
- CaptureData = CaptureRawTo_File;
- }
- }
- else
- {
- if(PrinterCapture)
- {
- if(Config -> CaptureConfig -> CaptureFilterMode && !RawCapture)
- CaptureData = CaptureFilteredTo_Printer;
- else
- CaptureData = CaptureRawTo_Printer;
- }
- else
- CaptureData = NULL;
- }
- }
- else
- {
- if(FileCapture)
- {
- if(PrinterCapture)
- {
- if(Config -> CaptureConfig -> CaptureFilterMode && !RawCapture)
- CaptureData = CaptureFilteredTo_Buffer_File_Printer;
- else
- CaptureData = CaptureRawTo_Buffer_File_Printer;
- }
- else
- {
- if(Config -> CaptureConfig -> CaptureFilterMode && !RawCapture)
- CaptureData = CaptureFilteredTo_Buffer_File;
- else
- CaptureData = CaptureRawTo_Buffer_File;
- }
- }
- else
- {
- if(PrinterCapture)
- {
- if(Config -> CaptureConfig -> CaptureFilterMode && !RawCapture)
- CaptureData = CaptureFilteredTo_Buffer_Printer;
- else
- CaptureData = CaptureRawTo_Buffer_Printer;
- }
- else
- {
- if(Config -> CaptureConfig -> CaptureFilterMode && !RawCapture)
- CaptureData = CaptureFilteredTo_Buffer;
- else
- CaptureData = CaptureRawTo_Buffer;
- }
- }
- }
-
- if(ControllerActive)
- ConOutput = ConOutputPrinter;
- else
- {
- if(CurrentFont == GFX)
- ConOutput = ConOutputGFX;
- else
- ConOutput = ConOutputNormal;
- }
-
- if(ReceiveTable)
- ConDump = ConTransWrite;
- else
- ConDump = ConOutput;
-
- Permit();
- }
-
- /* ConFontScaleUpdate():
- *
- * Choose the right font scale for the job.
- */
-
- VOID
- ConFontScaleUpdate()
- {
- CurrentFontScale = RasterAttr[CursorY];
- FontScalingRequired = FALSE;
- CharCellNominator = 1;
-
- if(CurrentCharWidth == SCALE_HALF)
- CharCellDenominator = 2;
- else
- CharCellDenominator = 1;
-
- if(CurrentFontScale == SCALE_ATTR_NORMAL)
- {
- if(CurrentCharWidth == SCALE_HALF)
- {
- // Half of normal width
-
- LastPrintableColumn = (LastColumn + 1) * 2 - 1;
- LastPrintablePixel = (LastPixel + 1) * 2 - 1;
- FontScalingRequired = TRUE;
- }
- else
- {
- // Normal width
-
- LastPrintableColumn = LastColumn;
- LastPrintablePixel = LastPixel;
- }
- }
- else
- {
- if(CurrentCharWidth == SCALE_HALF)
- {
- // Half of double width
-
- LastPrintableColumn = LastColumn;
- LastPrintablePixel = LastPixel;
- }
- else
- {
- // Double width
-
- LastPrintableColumn = ((LastColumn + 1) / 2) - 1;
- LastPrintablePixel = ((LastPixel + 1) / 2) - 1;
- FontScalingRequired = TRUE;
- }
- }
- }
-
- /* ConTransWrite(STRPTR Buffer,LONG Size):
- *
- * Frontend for ConWrite(), including character translation.
- */
-
- VOID
- ConTransWrite(STRPTR Buffer,LONG Size)
- {
- struct TranslationHandle Handle;
- UBYTE LocalBuffer[256];
-
- /* Set up for translation. */
-
- ConTranslateSetup(&Handle,Buffer,Size,LocalBuffer,256,ReceiveTable);
-
- /* Process and output the data. */
-
- while(Size = ConTranslateBuffer(&Handle))
- (* ConOutput)(LocalBuffer,Size);
- }
-
- /* ConProcessDataTransExternal(register STRPTR String,register LONG Size):
- *
- * Process data, external emulation including translation flavour.
- */
-
- VOID
- ConProcessDataTransExternal(register STRPTR String,register LONG Size)
- {
- struct TranslationHandle Handle;
-
- /* Set up for translation. */
-
- ConTranslateSetup(&Handle,String,Size,ConTempBuffer,256,ReceiveTable);
-
- if(StripBuffer)
- {
- register LONG Len;
-
- /* Process and output the data. */
-
- while(Size = ConTranslateBuffer(&Handle))
- {
- XEmulatorWrite(XEM_IO,ConTempBuffer,Size);
-
- XEM_HostData . Source = ConTempBuffer;
- XEM_HostData . Destination = StripBuffer;
-
- if(Len = XEmulatorHostMon(XEM_IO,&XEM_HostData,Size))
- {
- if(CaptureData)
- (*CaptureData)(StripBuffer,Len);
- }
- }
- }
- else
- {
- /* Process and output the data. */
-
- while(Size = ConTranslateBuffer(&Handle))
- XEmulatorWrite(XEM_IO,ConTempBuffer,Size);
- }
- }
-
- /* ConProcessDataExternal(register STRPTR String,register LONG Size):
- *
- * Process data, external emulation flavour.
- */
-
- VOID
- ConProcessDataExternal(register STRPTR String,register LONG Size)
- {
- XEmulatorWrite(XEM_IO,String,Size);
-
- /* Build another string to contain
- * the pure ASCII contents, i.e.
- * not including any ESC control
- * sequences.
- */
-
- if(StripBuffer)
- {
- register LONG Len;
-
- XEM_HostData . Source = String;
- XEM_HostData . Destination = StripBuffer;
-
- if(Len = XEmulatorHostMon(XEM_IO,&XEM_HostData,Size))
- {
- if(CaptureData)
- (*CaptureData)(StripBuffer,Len);
- }
- }
- }
-
- /* ConProcessData7(register STRPTR String,register LONG Size):
- *
- * Process data, 7 bit flavour.
- */
-
- VOID
- ConProcessData7(register STRPTR String,register LONG Size)
- {
- register LONG Len = 0;
- register UBYTE c;
-
- /* If still parsing a sequence,
- * continue with it.
- */
-
- if(InSequence)
- {
- while(Size--)
- {
- c = *String++ & 0x7F;
-
- if(!(*AbortTable[c])(c))
- {
- InSequence = FALSE;
-
- break;
- }
- }
- }
-
- /* Check which font we are in, if other than Topaz
- * the only invalid char is a Null (0) which will
- * display as a space if let to continue.
- */
-
- if(Config -> TerminalConfig -> FontMode == FONT_STANDARD)
- {
- while(Size-- > 0)
- {
- if(IsPrintable[c = *String++ & 0x7F])
- {
- /* This character is associated with a
- * special function (bell, xon, xoff, etc.).
- */
-
- if(SpecialTable[c])
- {
- if(Len)
- {
- (*ConDump)(ConTempBuffer,Len);
-
- Len = 0;
- }
-
- /* Does this character start
- * a control sequence?
- */
-
- if(InSequence = (*SpecialTable[c])(c))
- {
- while(Size-- > 0)
- {
- c = *String++ & 0x7F;
-
- if(!(*AbortTable[c])(c))
- {
- InSequence = FALSE;
-
- break;
- }
- }
- }
- }
- else
- {
- /* Put the character into the buffer
- * and flush it if necessary.
- */
-
- ConTempBuffer[Len] = c;
-
- if(Len++ == 512)
- {
- (*ConDump)(ConTempBuffer,Len);
-
- Len = 0;
- }
- }
- }
- }
- }
- else
- {
- while(Size-- > 0)
- {
- if(c = (*String++ & 0x7F))
- {
- /* This character is associated with a
- * special function (bell, xon, xoff, etc.).
- */
-
- if(SpecialTable[c])
- {
- if(Len)
- {
- (*ConDump)(ConTempBuffer,Len);
-
- Len = 0;
- }
-
- if(InSequence = (*SpecialTable[c])(c))
- {
- while(Size-- > 0)
- {
- c = *String++ & 0x7F;
-
- if(!(*AbortTable[c])(c))
- {
- InSequence = FALSE;
-
- break;
- }
- }
- }
- }
- else
- {
- /* Put the character into the buffer
- * and flush it if necessary.
- */
-
- ConTempBuffer[Len] = c;
-
- if(Len++ == 512)
- {
- (*ConDump)(ConTempBuffer,Len);
-
- Len = 0;
- }
- }
- }
- }
- }
-
- if(Len)
- (*ConDump)(ConTempBuffer,Len);
- }
-
- /* ConProcessData8(register STRPTR String,register LONG Size):
- *
- * Process data, 8 bit flavour.
- */
-
- VOID
- ConProcessData8(register STRPTR String,register LONG Size)
- {
- register LONG Len = 0;
- register UBYTE c;
-
- if(InSequence)
- {
- while(Size--)
- {
- c = *String++;
-
- if(!(*AbortTable[c])(c))
- {
- InSequence = FALSE;
-
- break;
- }
- }
- }
-
- if(Config -> TerminalConfig -> FontMode == FONT_STANDARD)
- {
- while(Size-- > 0)
- {
- if(IsPrintable[c = *String++])
- {
- if(SpecialTable[c])
- {
- if(Len)
- {
- (*ConDump)(ConTempBuffer,Len);
-
- Len = 0;
- }
-
- if(InSequence = (*SpecialTable[c])(c))
- {
- while(Size-- > 0)
- {
- c = *String++;
-
- if(!(*AbortTable[c])(c))
- {
- InSequence = FALSE;
-
- break;
- }
- }
- }
- }
- else
- {
- ConTempBuffer[Len] = c;
-
- if(Len++ == 512)
- {
- (*ConDump)(ConTempBuffer,Len);
-
- Len = 0;
- }
- }
- }
- }
- }
- else
- {
- while(Size-- > 0)
- {
- if(c = *String++)
- {
- if(SpecialTable[c])
- {
- if(Len)
- {
- (*ConDump)(ConTempBuffer,Len);
-
- Len = 0;
- }
-
- if(InSequence = (*SpecialTable[c])(c))
- {
- while(Size-- > 0)
- {
- c = *String++;
-
- if(!(*AbortTable[c])(c))
- {
- InSequence = FALSE;
-
- break;
- }
- }
- }
- }
- else
- {
- ConTempBuffer[Len] = c;
-
- if(Len++ == 512)
- {
- (*ConDump)(ConTempBuffer,Len);
-
- Len = 0;
- }
- }
- }
- }
- }
-
- if(Len)
- (*ConDump)(ConTempBuffer,Len);
- }
-
- /* ConProcessDataHex7(register STRPTR String,register LONG Size):
- *
- * Process data, hex mode flavour, seven bits.
- */
-
- VOID
- ConProcessDataHex7(register STRPTR String,register LONG Size)
- {
- UBYTE DummyBuffer[40],c;
- LONG Fit,Spaces,Current;
-
- /* How many characters will fit into the line? */
-
- Fit = (LastColumn + 1) / 4;
-
- /* Which position are we currently in? */
-
- Current = CursorX / 3;
-
- /* Weird cursor position? */
-
- if(Current >= Fit || (CursorX % 3))
- {
- ConProcessData7("\r\n",2);
-
- Current = 0;
- }
-
- /* Check the font type. */
-
- if(Config -> TerminalConfig -> FontMode == FONT_STANDARD)
- {
- while(Size-- > 0)
- {
- c = (*String++) & 0x7F;
-
- Spaces = (Fit - Current) * 3 + Current - 3;
-
- if(c > ' ' && c < 127)
- SPrintf(DummyBuffer,"%02lx \33[%ldC%lc\33[%ldD",c,Spaces,c,Spaces + 1);
- else
- SPrintf(DummyBuffer,"%02lx \33[%ldC.\33[%ldD",c,Spaces,Spaces + 1);
-
- ConProcessData7(DummyBuffer,strlen(DummyBuffer));
-
- if(Current++ == Fit - 1)
- {
- Current = 0;
-
- ConProcessData7("\r\n",2);
- }
- }
- }
- else
- {
- while(Size-- > 0)
- {
- c = (*String++) & 0x7F;
-
- Spaces = (Fit - Current) * 3 + Current - 3;
-
- if(c && c != ' ')
- SPrintf(DummyBuffer,"%02lx \33[%ldC%lc\33[%ldD",c,Spaces,c,Spaces + 1);
- else
- SPrintf(DummyBuffer,"%02lx \33[%ldC.\33[%ldD",c,Spaces,Spaces + 1);
-
- ConProcessData7(DummyBuffer,strlen(DummyBuffer));
-
- if(Current++ == Fit - 1)
- {
- Current = 0;
-
- ConProcessData7("\r\n",2);
- }
- }
- }
- }
-
- /* ConProcessDataHex8(register STRPTR String,register LONG Size):
- *
- * Process data, hex mode flavour, eight bits.
- */
-
- VOID
- ConProcessDataHex8(register STRPTR String,register LONG Size)
- {
- UBYTE DummyBuffer[40],c;
- LONG Fit,Spaces,Current;
-
- /* How many characters will fit into the line? */
-
- Fit = (LastColumn + 1) / 4;
-
- /* Which position are we currently in? */
-
- Current = CursorX / 3;
-
- /* Weird cursor position? */
-
- if(Current >= Fit || (CursorX % 3))
- {
- ConProcessData8("\r\n",2);
-
- Current = 0;
- }
-
- /* Check the font type. */
-
- if(Config -> TerminalConfig -> FontMode == FONT_STANDARD)
- {
- while(Size-- > 0)
- {
- c = *String++;
-
- Spaces = (Fit - Current) * 3 + Current - 3;
-
- if((c > ' ' && c < 127) || c > 160)
- SPrintf(DummyBuffer,"%02lx \33[%ldC%lc\33[%ldD",c,Spaces,c,Spaces + 1);
- else
- SPrintf(DummyBuffer,"%02lx \33[%ldC.\33[%ldD",c,Spaces,Spaces + 1);
-
- ConProcessData8(DummyBuffer,strlen(DummyBuffer));
-
- if(Current++ == Fit - 1)
- {
- Current = 0;
-
- ConProcessData8("\r\n",2);
- }
- }
- }
- else
- {
- while(Size-- > 0)
- {
- c = *String++;
-
- Spaces = (Fit - Current) * 3 + Current - 3;
-
- if(c && c != ' ')
- SPrintf(DummyBuffer,"%02lx \33[%ldC%lc\33[%ldD",c,Spaces,c,Spaces + 1);
- else
- SPrintf(DummyBuffer,"%02lx \33[%ldC.\33[%ldD",c,Spaces,Spaces + 1);
-
- ConProcessData8(DummyBuffer,strlen(DummyBuffer));
-
- if(Current++ == Fit - 1)
- {
- Current = 0;
-
- ConProcessData8("\r\n",2);
- }
- }
- }
- }
-
- /* ConTransferHost(STRPTR Buffer,LONG Len):
- *
- * Process data read from the serial line,
- * special XPR flavour.
- */
-
- VOID
- ConTransferHost(STRPTR Buffer,LONG Len)
- {
- LONG MaxSize;
-
- if(Buffer != ReadBuffer)
- MaxSize = SerialBufferSize - ((LONG)Buffer - (LONG)ReadBuffer);
- else
- MaxSize = SerialBufferSize;
-
- Len = XProtocolHostMon(XprIO,Buffer,Len,MaxSize);
-
- if(TransferWindow)
- TransferCleanup();
-
- if(Len)
- ConProcess(Buffer,Len);
- }
-
- /* ConsoleCommand(STRPTR String):
- *
- * Just like SerialCommand(), but addresses the local
- * terminal side.
- */
-
- VOID
- ConsoleCommand(STRPTR String)
- {
- STATIC UBYTE LocalBuffer[256];
-
- LONG Count = 0,i,Len = strlen(String);
-
- BOOL GotControl = FALSE,
- GotEscape = FALSE;
-
- /* Scan the string. */
-
- for(i = 0 ; i < Len ; i++)
- {
- /* We are looking for plain characters
- * and the control ('\') and escape
- * ('^') characters.
- */
-
- if(!GotControl && !GotEscape)
- {
- /* Got a control character,
- * the next byte will probably be
- * a command sequence.
- */
-
- if(String[i] == '\\')
- {
- GotControl = TRUE;
-
- continue;
- }
-
- /* Got an escape character,
- * the next byte will be some
- * kind of control character
- * (such as XON, XOF, bell, etc.).
- */
-
- if(String[i] == '^')
- {
- GotEscape = TRUE;
-
- continue;
- }
-
- /* This tells us to wait another
- * second before continuing with
- * the scanning.
- */
-
- if(String[i] == '~')
- continue;
-
- /* Stuff the character into the
- * buffer.
- */
-
- LocalBuffer[Count++] = String[i];
- }
- else
- {
- /* Convert the character to a control
- * style character (^C, etc.).
- */
-
- if(GotEscape)
- {
- if(ToUpper(String[i]) >= 'A' && ToUpper(String[i]) <= '_')
- LocalBuffer[Count++] = ToUpper(String[i]) - '@';
- else
- LocalBuffer[Count++] = String[i];
-
- GotEscape = FALSE;
- }
-
- /* The next character represents a command. */
-
- if(GotControl)
- {
- switch(ToUpper(String[i]))
- {
- /* Translate code. */
-
- case '*':
-
- i++;
-
- while(i < Len && String[i] == ' ')
- i++;
-
- if(i < Len)
- {
- UBYTE DummyBuffer[5],j = 0,Char;
-
- if(String[i] >= '0' && String[i] <= '9')
- {
- while(j < 3 && i < Len)
- {
- Char = String[i++];
-
- if(Char >= '0' && Char <= '9')
- DummyBuffer[j++] = Char;
- else
- {
- i--;
-
- break;
- }
- }
- }
- else
- {
- while(j < 4 && i < Len)
- {
- Char = ToLower(String[i++]);
-
- if((Char >= '0' && Char <= '9') || (Char >= 'a' && Char <= 'z'))
- DummyBuffer[j++] = Char;
- else
- {
- i--;
-
- break;
- }
- }
- }
-
- DummyBuffer[j] = 0;
-
- LocalBuffer[Count++] = NameToCode(DummyBuffer);
- }
-
- i--;
-
- break;
-
- /* Execute an AmigaDOS command. */
-
- case 'D':
-
- return;
-
- /* Execute an ARexx command. */
-
- case 'A':
-
- return;
-
- /* Add the control character ('\'). */
-
- case '\\':
-
- LocalBuffer[Count++] = '\\';
- break;
-
- /* This is a backspace. */
-
- case 'B':
-
- LocalBuffer[Count++] = '\b';
- break;
-
- /* This is a form feed. */
-
- case 'F':
-
- LocalBuffer[Count++] = '\f';
- break;
-
- /* This is a line feed. */
-
- case 'N':
-
- LocalBuffer[Count++] = '\n';
- break;
-
- /* Send the current password. */
-
- case 'P':
-
- break;
-
- /* This is a carriage return. */
-
- case 'R':
-
- LocalBuffer[Count++] = '\r';
- break;
-
- /* This is a tab. */
-
- case 'T':
-
- LocalBuffer[Count++] = '\t';
- break;
-
- /* Send the current user name. */
-
- case 'U':
-
- break;
-
- /* Send a break across the serial line. */
-
- case 'X':
-
- break;
-
- /* Feed the contents of the
- * clipboard into the input
- * stream.
- */
-
- case 'I':
-
- if(Count)
- ConProcess(LocalBuffer,Count);
-
- Count = LoadClip(LocalBuffer,256);
-
- break;
-
- /* Send a string to the clipboard. */
-
- case 'G':
-
- if(String[i + 1])
- SaveClip(&String[i + 1],strlen(&String[i + 1]));
-
- return;
-
- /* Produce the escape character. */
-
- case 'E':
-
- LocalBuffer[Count++] = ESC;
- break;
-
- /* Call a menu item. */
-
- case 'C':
-
- break;
-
- /* Stuff the character into the buffer. */
-
- default:
-
- LocalBuffer[Count++] = String[i];
- break;
- }
-
- GotControl = FALSE;
- }
- }
-
- /* If the buffer is full, release it. */
-
- if(Count == 256)
- {
- ConProcess(LocalBuffer,Count);
-
- Count = 0;
- }
- }
-
- if(Count)
- ConProcess(LocalBuffer,Count);
- }
-
- /* ConBypass(STRPTR String,LONG Size):
- *
- * Bypass the `normal' ConOutput() data processing.
- */
-
- VOID
- ConBypass(STRPTR String,LONG Size)
- {
- if(Size < 0)
- Size = strlen(String);
-
- if(Size > 0)
- {
- VOID (* ProcessData)(STRPTR,LONG);
-
- if(Config -> SerialConfig -> StripBit8)
- ProcessData = ConProcessData7;
- else
- ProcessData = ConProcessData8;
-
- ObtainSemaphore(&TerminalSemaphore);
-
- if(Marking)
- DropMarker();
-
- ClearCursor();
-
- (*ProcessData)(String,Size);
-
- DrawCursor();
-
- ReleaseSemaphore(&TerminalSemaphore);
- }
- }
-
- /* ConProcess(STRPTR String,LONG Size):
- *
- * Process the contents of a string to be sent to the
- * console window.
- */
-
- VOID
- ConProcess(register STRPTR String,register LONG Size)
- {
- if(Size > 0)
- {
- /* Feed the flow filter. */
-
- if(UseFlow)
- {
- if(Config -> SerialConfig -> StripBit8)
- FlowFilter(String,Size,0x7F);
- else
- FlowFilter(String,Size,0xFF);
- }
-
- /* In quiet mode no characters are echoed to the
- * console window, they are just passed through
- * the data flow filter. Usually, this mode is
- * enabled by the dial panel.
- */
-
- if(!Quiet)
- {
- /* Capture the data. */
-
- if(CaptureData)
- {
- if(Config -> CaptureConfig -> ConvertChars && Config -> TerminalConfig -> FontMode != FONT_STANDARD)
- {
- UBYTE LocalBuffer[BUFFER_LINE_MAX];
-
- UBYTE *Src = String,
- *Dst,
- c;
-
- ULONG Count,Len = Size;
-
- while(Len > 0)
- {
- Count = MIN(BUFFER_LINE_MAX,Len);
-
- Len -= Count;
-
- Dst = LocalBuffer;
-
- do
- {
- if(c = ISOConversion[*Src++])
- *Dst++ = c;
- else
- *Dst++ = (UBYTE)'·';
- }
- while(--Count > 0);
-
- if((Count = (ULONG)Dst - (ULONG)&LocalBuffer[0]) > 0)
- (*CaptureData)(LocalBuffer,Count);
- }
- }
- else
- (*CaptureData)(String,Size);
- }
-
- /* Remember the data. */
-
- if(RememberOutput)
- RememberOutputText(String,Size);
-
- /* Check the traps if necessary. */
-
- if(WatchTraps)
- {
- TrapFilter(String,Size);
- /*
- #ifdef FILTER_TRAPS
- CaptureParser(TrapStuff,String,Size,TrapFilter);
- #else
- TrapFilter(String,Size);
- #endif // FILTER_TRAPS
- */
- }
-
- if(Marking)
- DropMarker();
-
- if(TerminalQueue)
- {
- struct DataMsg *Msg;
-
- if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg) + Size))
- {
- Msg -> Data = (APTR)(Msg + 1);
- Msg -> Size = Size;
-
- CopyMem(String,Msg -> Data,Msg -> Size);
-
- PutMsgItem(TerminalQueue,Msg);
-
- return;
- }
- }
-
- ClearCursor();
-
- (*ConProcessData)(String,Size);
-
- DrawCursor();
- }
- }
- }
-
- /* ConWrites(STRPTR String,...):
- *
- * Output a string to the console.
- */
-
- VOID __stdargs
- ConWrites(STRPTR String,...)
- {
- va_list VarArgs;
-
- if(Marking)
- DropMarker();
-
- va_start(VarArgs,String);
- VSPrintf(SharedBuffer,String,VarArgs);
- va_end(VarArgs);
-
- ConProcess(SharedBuffer,strlen(SharedBuffer));
- }
-
- /* FlowInit():
- *
- * Set up the data flow parser. The parser scans the serial
- * output data for more or less interesting modem output
- * (carrier lost, connect, etc.).
- */
-
- VOID
- FlowInit(BOOL FullReset)
- {
- LONG i;
-
- for(i = 0 ; i < SCAN_COUNT ; i++)
- AttentionBuffers[i][0] = 0;
-
- /* Set up `NO CARRIER' message. */
-
- if(Config -> ModemConfig -> NoCarrier[0])
- SPrintf(AttentionBuffers[SCAN_NOCARRIER],"%s\r",Config -> ModemConfig -> NoCarrier);
-
- /* Set up `CONNECT' message. */
-
- strcpy(AttentionBuffers[SCAN_CONNECT],Config -> ModemConfig -> Connect);
-
- /* Set up `VOICE' message. */
-
- if(Config -> ModemConfig -> Voice[0])
- SPrintf(AttentionBuffers[SCAN_VOICE],"%s\r",Config -> ModemConfig -> Voice);
-
- /* Set up `RING' message. */
-
- if(Config -> ModemConfig -> Ring[0])
- SPrintf(AttentionBuffers[SCAN_RING],"%s\r",Config -> ModemConfig -> Ring);
-
- /* Set up `BUSY' message. */
-
- if(Config -> ModemConfig -> Busy[0])
- SPrintf(AttentionBuffers[SCAN_BUSY],"%s\r",Config -> ModemConfig -> Busy);
-
- /* Set up `NO DIALTONE' message. */
-
- if(Config -> ModemConfig -> NoDialTone[0])
- SPrintf(AttentionBuffers[SCAN_NODIALTONE],"%s\r",Config -> ModemConfig -> NoDialTone);
-
- /* Set up `OK' message. */
-
- if(Config -> ModemConfig -> Ok[0])
- SPrintf(AttentionBuffers[SCAN_OK],"%s\r",Config -> ModemConfig -> Ok);
-
- /* Set up `ERROR' message. */
-
- if(Config -> ModemConfig -> Error[0])
- SPrintf(AttentionBuffers[SCAN_ERROR],"%s\r",Config -> ModemConfig -> Error);
-
- /* Reset match counter. */
-
- FlowCount = 0;
-
- /* Reset indices. */
-
- memset(AttentionCount,0,sizeof(AttentionCount));
-
- /* Determine lengths. */
-
- for(i = 0 ; i < SCAN_COUNT ; i++)
- AttentionLength[i] = strlen(AttentionBuffers[i]);
-
- for(i = SCAN_SIGDEFAULTUPLOAD ; i <= SCAN_SIGBINARYDOWNLOAD ; i++)
- {
- if(AttentionLength[i] = Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD + i - SCAN_SIGDEFAULTUPLOAD] . Length)
- CopyMem(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD + i - SCAN_SIGDEFAULTUPLOAD] . Signature,AttentionBuffers[i],Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD + i - SCAN_SIGDEFAULTUPLOAD] . Length);
- }
-
- if(Config -> TransferConfig -> ASCIIUploadType != XFER_XPR && Config -> TransferConfig -> ASCIIUploadType != XFER_EXTERNALPROGRAM)
- AttentionLength[SCAN_SIGASCIIUPLOAD] = 0;
-
- if(Config -> TransferConfig -> ASCIIDownloadType != XFER_XPR && Config -> TransferConfig -> ASCIIUploadType != XFER_EXTERNALPROGRAM)
- AttentionLength[SCAN_SIGASCIIDOWNLOAD] = 0;
-
- if(Config -> TransferConfig -> TextUploadType != XFER_XPR && Config -> TransferConfig -> TextUploadType != XFER_EXTERNALPROGRAM)
- AttentionLength[SCAN_SIGTEXTUPLOAD] = 0;
-
- if(Config -> TransferConfig -> TextDownloadType != XFER_XPR && Config -> TransferConfig -> TextUploadType != XFER_EXTERNALPROGRAM)
- AttentionLength[SCAN_SIGTEXTDOWNLOAD] = 0;
-
- if(Config -> TransferConfig -> BinaryUploadType != XFER_XPR && Config -> TransferConfig -> BinaryUploadType != XFER_EXTERNALPROGRAM)
- AttentionLength[SCAN_SIGBINARYUPLOAD] = 0;
-
- if(Config -> TransferConfig -> BinaryDownloadType != XFER_XPR && Config -> TransferConfig -> BinaryUploadType != XFER_EXTERNALPROGRAM)
- AttentionLength[SCAN_SIGBINARYDOWNLOAD] = 0;
-
- if(FullReset)
- {
- /* No, we are not yet looking for a baud rate. */
-
- BaudPending = FALSE;
-
- /* Reset the flags. */
-
- memset(&FlowInfo,FALSE,sizeof(struct FlowInfo));
- }
-
- /* Full data check is a lot slower than looking for
- * just a single sequence (such as the `CONNECT'
- * below). This mode is reserved for the dial panel.
- */
-
- ScanStart = 0;
- ScanEnd = SCAN_COUNT - 1;
- UseFlow = TRUE;
- }
-
- /* GfxText(struct RastPort *RPort,STRPTR Buffer,LONG Length):
- *
- * Text output, if necessary switching from gfx font
- * to current default font.
- */
-
- VOID
- GfxText(struct RastPort *RPort,STRPTR Buffer,LONG Length)
- {
- LONG TextMode;
- LONG SameMode;
-
- /* Determine current text rendering mode. */
-
- if(GfxTable[Buffer[0]] == MODE_GFX)
- TextMode = MODE_GFX;
- else
- {
- TextMode = MODE_STANDARD;
-
- SetFont(RPort,TextFont);
- }
-
- /* Reset number of characters in common mode. */
-
- SameMode = 0;
-
- /* Scan until all input is processed. */
-
- FOREVER
- {
- /* Scan for characters in the current mode. */
-
- while(GfxTable[Buffer[SameMode]] == TextMode && SameMode < Length)
- SameMode++;
-
- /* Output the text found. */
-
- Text(RPort,Buffer,SameMode);
-
- /* Decrement number of remaining bytes. */
-
- Length -= SameMode;
-
- /* Anything left? */
-
- if(Length)
- {
- /* Skip to next character. */
-
- Buffer += SameMode;
- SameMode = 0;
-
- /* Change text output mode. */
-
- if(TextMode == MODE_GFX)
- {
- SetFont(RPort,TextFont);
-
- TextMode = MODE_STANDARD;
- }
- else
- {
- SetFont(RPort,GFX);
-
- TextMode = MODE_GFX;
- }
- }
- else
- break;
- }
-
- /* Reset font type. */
-
- if(TextMode == MODE_STANDARD)
- SetFont(RPort,GFX);
- }
-
- /* ConvertKey():
- *
- * The actual key conversion routine.
- */
-
- STATIC LONG
- ConvertKey(ULONG Qualifier,UWORD Code,ULONG Prev,STRPTR Buffer,LONG Len)
- {
- LONG Actual;
-
- /* Fill in the defaults. */
-
- FakeInputEvent -> ie_Code = Code;
- FakeInputEvent -> ie_Qualifier = Qualifier;
- FakeInputEvent -> ie_position . ie_addr = (APTR)Prev;
-
- /* Clear the buffer (sortof). */
-
- Buffer[0] = 0;
-
- /* Convert the codes. */
-
- if((Actual = RawKeyConvert(FakeInputEvent,Buffer,Len,KeyMap)) > 0)
- return(Actual);
- else
- return(0);
- }
-
- /* ConvertTheKey(STRPTR Buffer,LONG *Len,UWORD Code,UWORD Qualifier,ULONG Prev):
- *
- * Much more simplified raw key conversion routine.
- */
-
- LONG
- ConvertTheKey(STRPTR Buffer,LONG *Len,UWORD Code,UWORD Qualifier,ULONG Prev)
- {
- if(Buffer)
- Buffer[0] = 0;
-
- if(Len)
- *Len = 0;
-
- /* Key was pressed, not released. */
-
- if(!(Code & IECODE_UP_PREFIX))
- {
- /* These are the sequences mapped to special
- * control keys (cursor keys, function keys,
- * the help key).
- */
-
- STATIC struct { STRPTR RawCode; UBYTE Result; } ConversionTable[15] =
- {
- (STRPTR)"A", CUP,
- (STRPTR)"B", CDN,
- (STRPTR)"C", CFW,
- (STRPTR)"D", CBK,
-
- (STRPTR)"?~", HLP,
-
- (STRPTR)"0~", FN1,
- (STRPTR)"1~", FN2,
- (STRPTR)"2~", FN3,
- (STRPTR)"3~", FN4,
- (STRPTR)"4~", FN5,
- (STRPTR)"5~", FN6,
- (STRPTR)"6~", FN7,
- (STRPTR)"7~", FN8,
- (STRPTR)"8~", FN9,
- (STRPTR)"9~", F10
- };
-
- STATIC UBYTE SeqLens[15] = { 1,1,1,1,2,2,2,2,2,2,2,2,2,2,2 };
-
- UBYTE ConvertBuffer[257];
- LONG Actual;
-
- /* If it's a function or cursor key, clear the qualifier. */
-
- if(Code >= CURSOR_UP_CODE && Code <= F10_CODE)
- Qualifier = NULL;
- else
- {
- /* Does it have a numeric keypad qualifier set? */
-
- if((Qualifier & (IEQUALIFIER_NUMERICPAD | IEQUALIFIER_CONTROL)) == (IEQUALIFIER_NUMERICPAD | IEQUALIFIER_CONTROL))
- {
- STRPTR String = NULL;
-
- /* Look at the vanilla result. */
-
- if(ConvertKey(Qualifier & ~(IEQUALIFIER_CONTROL | IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT | IEQUALIFIER_LALT | IEQUALIFIER_RALT),Code,Prev,ConvertBuffer,1))
- {
- /* Take a look at the results. */
-
- switch(ConvertBuffer[0])
- {
- case '(':
- case '[':
- case '{':
-
- String = "\033OP";
- break;
-
- case ')':
- case ']':
- case '}':
-
- String = "\033OQ";
- break;
-
- case '/':
-
- String = "\033OR";
- break;
-
- case '*':
-
- String = "\033OS";
- break;
-
- default:
-
- String = NULL;
- break;
- }
- }
-
- if(!String)
- {
- switch(Code)
- {
- case 0x5A:
-
- String = "\033OP";
- break;
-
- case 0x5B:
-
- String = "\033OQ";
- break;
-
- case 0x5C:
-
- String = "\033OR";
- break;
-
- case 0x5D:
-
- String = "\033OS";
- break;
- }
- }
-
- /* Return the PFx key code. */
-
- if(String)
- {
- if(Buffer)
- CopyMem(String,Buffer,3);
-
- if(Len)
- *Len = 3;
-
- return('\033');
- }
- }
-
- /* Does it have a shift qualifier set? */
-
- if(Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
- {
- /* Do the conversion... */
-
- if(ConvertKey(Qualifier & ~(IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT),Code,Prev,ConvertBuffer,1))
- {
- /* Did it produce a tab key? If so, transfer
- * Esc tab instead.
- */
-
- if(ConvertBuffer[0] == '\t')
- {
- if(Len)
- *Len = 2;
-
- if(Buffer)
- CopyMem("\033\t",Buffer,2);
-
- return('\033');
- }
- }
- }
-
- /* Does it have the control qualifier set? */
-
- if(Qualifier & IEQUALIFIER_CONTROL)
- {
- /* Do the conversion... */
-
- if(ConvertKey(Qualifier & ~IEQUALIFIER_CONTROL,Code,Prev,ConvertBuffer,1))
- {
- /* Did it produce a space or an `at' sign? */
-
- switch(ConvertBuffer[0])
- {
- /* NUL */
-
- case ' ':
- case '@':
- case '2':
-
- if(Len)
- *Len = 1;
-
- if(Buffer)
- Buffer[0] = 0;
-
- return(0);
-
- /* Escape */
-
- case '3':
- case '[':
-
- if(Len)
- *Len = 1;
-
- if(Buffer)
- Buffer[0] = 0x1B;
-
- return(0x1B);
-
- /* FS */
-
- case '4':
- case '/':
-
- if(Len)
- *Len = 1;
-
- if(Buffer)
- Buffer[0] = 0x1C;
-
- return(0x1C);
-
- /* GS */
-
- case '5':
- case ']':
-
- if(Len)
- *Len = 1;
-
- if(Buffer)
- Buffer[0] = 0x1D;
-
- return(0x1D);
-
- /* RS */
-
- case '6':
- case '~':
-
- if(Len)
- *Len = 1;
-
- if(Buffer)
- Buffer[0] = 0x1E;
-
- return(0x1E);
-
-
- /* US */
-
- case '7':
- case '?':
-
- if(Len)
- *Len = 1;
-
- if(Buffer)
- Buffer[0] = 0x1F;
-
- return(0x1F);
- }
- }
- }
- }
-
- /* Do the final conversion... */
-
- if(Actual = ConvertKey(Qualifier,Code,Prev,ConvertBuffer,256))
- {
- /* Are we to swap the backspace and
- * delete keys?
- */
-
- if(Config -> EmulationConfig -> SwapBSDelete)
- {
- register LONG i;
-
- for(i = 0 ; i < Actual ; i++)
- {
- if(ConvertBuffer[i] == BKS)
- ConvertBuffer[i] = DEL;
- else
- {
- if(ConvertBuffer[i] == DEL)
- ConvertBuffer[i] = BKS;
- }
- }
- }
-
- /* Translated sequence starts
- * with a CSI, let's have a look
- * at the associated control
- * key.
- */
-
- if(ConvertBuffer[0] == CSI)
- {
- register LONG i;
-
- for(i = 0 ; i < sizeof(SeqLens) ; i++)
- {
- /* Does it match? */
-
- if(!memcmp(&ConvertBuffer[1],ConversionTable[i] . RawCode,SeqLens[i]))
- {
- /* Store the length. */
-
- if(Len)
- *Len = 1;
-
- /* Store the result. */
-
- if(Buffer)
- {
- Buffer[0] = ConversionTable[i] . Result;
- Buffer[1] = 0;
- }
-
- return(ConversionTable[i] . Result);
- }
- }
- }
-
- /* Store the number of characters converted. */
-
- if(Len)
- *Len = Actual;
-
- /* Store the converted characters. */
-
- if(Buffer)
- CopyMem(ConvertBuffer,Buffer,Actual);
-
- return(ConvertBuffer[0]);
- }
- }
-
- return(0);
- }
-
- /* KeyConvert(struct IntuiMessage *Massage,STRPTR Buffer):
- *
- * Convert a raw key information according to the
- * current keymap settings.
- */
-
- LONG
- KeyConvert(struct IntuiMessage *Massage,STRPTR Buffer,LONG *Len)
- {
- /* Is this really a keyboard event? */
-
- if(Massage -> Class == IDCMP_RAWKEY)
- return(ConvertTheKey(Buffer,Len,Massage -> Code,Massage -> Qualifier,*(ULONG *)Massage -> IAddress));
- else
- {
- if(Buffer)
- Buffer[0] = 0;
-
- if(Len)
- *Len = 0;
-
- return(0);
- }
- }
-
- /* DoBackspace():
- *
- * Special function: perform backspace.
- */
-
- BOOL
- DoBackspace()
- {
- if(CursorX)
- {
- LONG DeltaX,MinX;
-
- CursorX--;
-
- // What backspace mode are we in?
-
- switch(Config -> EmulationConfig -> DestructiveBackspace)
- {
- // Do nothing
-
- case 0:
-
- RepositionCursor();
- break;
-
- // Shift the line to the left
-
- case 2:
-
- BackupRender();
-
- RasterEraseCharacters(1);
-
- if(FontScalingRequired)
- {
- if(CurrentCharWidth == SCALE_NORMAL)
- {
- DeltaX = TextFontWidth * 2;
- MinX = MUL_X(CursorX) * 2;
- }
- else
- {
- DeltaX = TextFontWidth / 2;
- MinX = MUL_X(CursorX) / 2;
- }
- }
- else
- {
- DeltaX = TextFontWidth;
- MinX = MUL_X(CursorX);
- }
-
- ScrollLineEraseCharacters(1);
-
- ScrollLineRaster(RPort,DeltaX,0,MinX,MUL_Y(CursorY),LastPixel,MUL_Y(CursorY + 1) - 1,FALSE);
-
- BackupRender();
-
- RepositionCursor();
-
- break;
-
- // Clear the character below the cursor
-
- default:
-
- RepositionCursor();
-
- ObtainSemaphore(RasterSemaphore);
-
- Raster[CursorY * RasterWidth + CursorX] = ' ';
-
- ReleaseSemaphore(RasterSemaphore);
-
- BackupRender();
-
- if(FontScalingRequired)
- PrintScaled(" ",1,CurrentFontScale);
- else
- Text(RPort," ",1);
-
- BackupRender();
-
- break;
- }
- }
-
- return(FALSE);
- }
-
- /* DoBeep():
- *
- * The real interface to the beep routine.
- */
-
- BOOL
- DoBeep()
- {
- BellSignal();
-
- return(FALSE);
- }
-
- /* DoxON():
- *
- * Perform XON (stop data flow).
- */
-
- BOOL
- DoxON()
- {
- return(FALSE);
- }
-
- /* DoLF():
- *
- * Special function: perform line feed.
- */
-
- BOOL
- DoLF()
- {
- // This takes care of regular jump scrolling
-
- if(CursorY == Bottom && Bottom > 0 && Config -> EmulationConfig -> MaxJump > 1)
- {
- LONG Scroll,TotalLines,OldBack = BackgroundPen;
-
- Scroll = Config -> EmulationConfig -> MaxJump;
-
- // How tall is the current scroll region?
-
- TotalLines = Bottom - Top + 1;
-
- // Don't scroll more than the entire screenful
-
- if(Scroll > TotalLines)
- Scroll = TotalLines;
-
- if(OldBack)
- {
- BackgroundPen = 0;
-
- UpdatePens();
- }
-
- // Scroll the region...
-
- ScrollRegion(Scroll);
-
- // Reposition the cursor
-
- if(CursorY > Scroll)
- CursorY -= Scroll;
- else
- CursorY = 0;
-
- if(OldBack)
- {
- BackgroundPen = OldBack;
-
- UpdatePens();
- }
- }
-
- DownLine();
-
- RepositionCursor();
-
- return(FALSE);
- }
-
- /* DoShiftIn():
- *
- * Special function: Shift into graphics mode
- */
-
- BOOL
- DoShiftIn()
- {
- if(CharMode[1] == TABLE_GFX && GFX)
- CurrentFont = GFX;
-
- if(CharMode[1] == TABLE_ASCII)
- CurrentFont = TextFont;
-
- SetFont(RPort,CurrentFont);
-
- ConOutputUpdate();
-
- Charset = 1;
-
- return(FALSE);
- }
-
- /* DoShiftOut():
- *
- * Special function: Shift out of graphics mode
- */
-
- BOOL
- DoShiftOut()
- {
- if(CharMode[0] == TABLE_GFX && GFX)
- CurrentFont = GFX;
-
- if(CharMode[0] == TABLE_ASCII)
- CurrentFont = TextFont;
-
- SetFont(RPort,CurrentFont);
-
- ConOutputUpdate();
-
- Charset = 0;
-
- return(FALSE);
- }
-
- /* DoCR_LF():
- *
- * Special function: perform carriage return and line feed.
- */
-
- BOOL
- DoCR_LF()
- {
- CursorX = 0;
-
- DownLine();
-
- RepositionCursor();
-
- return(FALSE);
- }
-
- /* DoFF():
- *
- * Special function: perform form feed.
- */
-
- BOOL
- DoFF()
- {
- if(Config -> EmulationConfig -> NewLineMode)
- {
- CursorX = 0;
-
- DoCR_LF();
- }
- else
- {
- EraseScreen("2");
-
- CursorX = CursorY = 0;
-
- RepositionCursor();
-
- ConFontScaleUpdate();
- }
-
- return(FALSE);
- }
-
- /* DoLF_FF_VT():
- *
- * Special function: handle line feed, form feed and vertical
- * tab.
- */
-
- BOOL
- DoLF_FF_VT()
- {
- if(Config -> EmulationConfig -> NewLineMode)
- DoCR_LF();
- else
- DoLF();
-
- return(FALSE);
- }
-
- /* DoCR():
- *
- * Special function: handle carriage return.
- */
-
- BOOL
- DoCR()
- {
- if(Config -> EmulationConfig -> NewLineMode)
- DoCR_LF();
- else
- {
- CursorX = 0;
-
- RepositionCursor();
- }
-
- return(FALSE);
- }
-
- /* DoTab():
- *
- * Special function: handle tab, move cursor to next
- * tab stop.
- */
-
- BOOL
- DoTab()
- {
- LONG Column;
-
- if(RasterAttr[CursorY] == SCALE_ATTR_NORMAL)
- Column = LastColumn;
- else
- Column = ((LastColumn + 1) / 2) - 1;
-
- if(Config -> EmulationConfig -> LineWrap)
- {
- if(CursorX >= LastColumn)
- {
- CursorX = 0;
-
- DownLine();
- }
- else
- {
- while(CursorX < Column)
- {
- CursorX++;
-
- if(TabStops[CursorX])
- break;
- }
- }
- }
- else
- {
- while(CursorX < Column)
- {
- CursorX++;
-
- if(TabStops[CursorX])
- break;
- }
- }
-
- RepositionCursor();
-
- return(FALSE);
- }
-
- /* DoEnq():
- *
- * Special function: send answerback message.
- */
-
- BOOL
- DoEnq()
- {
- if(Config -> EmulationConfig -> AnswerBack[0])
- SerialCommand(Config -> EmulationConfig -> AnswerBack);
-
- return(FALSE);
- }
-
- /* DoEsc():
- *
- * Start new control sequence.
- */
-
- BOOL
- DoEsc()
- {
- if(Config -> TerminalConfig -> EmulationMode == EMULATION_TTY)
- (* ConDump)("^",1);
-
- return(TRUE);
- }
-
- /* DoCsi():
- *
- * Start new control sequence.
- */
-
- BOOL
- DoCsi()
- {
- if(Config -> TerminalConfig -> EmulationMode == EMULATION_TTY)
- (* ConDump)("^[",2);
-
- ParseCode('[');
-
- return(TRUE);
- }
-
- /* DoNewEsc(LONG Char):
- *
- * Start new control sequence.
- */
-
- BOOL
- DoNewEsc(LONG Char)
- {
- if(Config -> TerminalConfig -> EmulationMode == EMULATION_TTY)
- (* ConDump)("^",1);
-
- DoCancel();
-
- InSequence = TRUE;
-
- return(TRUE);
- }
-
- /* DoNewCsi(LONG Char):
- *
- * Start new control sequence.
- */
-
- BOOL
- DoNewCsi(LONG Char)
- {
- if(Config -> TerminalConfig -> EmulationMode == EMULATION_TTY)
- (* ConDump)("^[",2);
-
- DoCancel();
-
- InSequence = TRUE;
-
- return(ParseCode('['));
- }
-
- STATIC STRPTR CR_Translation,
- LF_Translation;
- STATIC WORD CR_Trans_Len,
- LF_Trans_Len;
-
- STATIC LONG
- Translate_CR_LF_1(register STRPTR Data,register LONG Size)
- {
- register STRPTR String = Data;
- register LONG Count = 0;
- register LONG c;
-
- while(Size--)
- {
- switch(c = *Data++)
- {
- case '\r':
-
- if(CR_Trans_Len)
- {
- *String++ = *CR_Translation;
-
- Count++;
- }
-
- break;
-
- case '\n':
-
- if(LF_Trans_Len)
- {
- *String++ = *LF_Translation;
-
- Count++;
- }
-
- break;
-
- default:
-
- *String++ = c;
-
- Count++;
-
- break;
- }
- }
-
- return(Count);
- }
-
- STATIC LONG
- Translate_CR_LF_2x2(register STRPTR Data,register LONG Size)
- {
- register STRPTR String = Data;
- register LONG Count = 0;
- register LONG c;
-
- /* ALWAYS */
- {
- register BOOL GotIt = FALSE;
- register LONG i;
-
- for(i = 0 ; i < Size ; i++)
- {
- if(String[i] == '\r' || String[i] == '\n')
- {
- GotIt = TRUE;
-
- break;
- }
- }
-
- if(GotIt)
- {
- CopyMem(Data,StripBuffer,Size);
-
- String = Data;
- Data = StripBuffer;
- }
- else
- return(Size);
- }
-
- while(Size--)
- {
- switch(c = *Data++)
- {
- case '\r':
-
- if(CR_Trans_Len)
- {
- register LONG i;
-
- for(i = 0 ; i < CR_Trans_Len ; i++)
- {
- *String++ = CR_Translation[i];
-
- Count++;
- }
- }
-
- break;
-
- case '\n':
-
- if(LF_Trans_Len)
- {
- register LONG i;
-
- for(i = 0 ; i < LF_Trans_Len ; i++)
- {
- *String++ = LF_Translation[i];
-
- Count++;
- }
- }
-
- break;
-
- default:
-
- *String++ = c;
-
- Count++;
-
- break;
- }
- }
-
- return(Count);
- }
-
- STATIC LONG
- Translate_CR_LF_2LF(register STRPTR Data,register LONG Size)
- {
- register STRPTR String = Data;
- register LONG Count = 0;
- register LONG c;
-
- /* ALWAYS */
- {
- register BOOL GotIt = FALSE;
- register LONG i;
-
- for(i = 0 ; i < Size ; i++)
- {
- if(String[i] == '\n')
- {
- GotIt = TRUE;
-
- break;
- }
- }
-
- if(GotIt)
- {
- CopyMem(Data,StripBuffer,Size);
-
- String = Data;
- Data = StripBuffer;
- }
- else
- return(Size);
- }
-
- while(Size--)
- {
- switch(c = *Data++)
- {
- case '\r':
-
- if(CR_Trans_Len)
- {
- register LONG i;
-
- for(i = 0 ; i < CR_Trans_Len ; i++)
- {
- *String++ = CR_Translation[i];
-
- Count++;
- }
- }
-
- break;
-
- case '\n':
-
- if(LF_Trans_Len)
- {
- register LONG i;
-
- for(i = 0 ; i < LF_Trans_Len ; i++)
- {
- *String++ = LF_Translation[i];
-
- Count++;
- }
- }
-
- break;
-
- default:
-
- *String++ = c;
-
- Count++;
-
- break;
- }
- }
-
- return(Count);
- }
-
- STATIC LONG
- Translate_CR_LF_2CR(register STRPTR Data,register LONG Size)
- {
- register STRPTR String = Data;
- register LONG Count = 0;
- register LONG c;
-
- /* ALWAYS */
- {
- register BOOL GotIt = FALSE;
- register LONG i;
-
- for(i = 0 ; i < Size ; i++)
- {
- if(String[i] == '\r')
- {
- GotIt = TRUE;
-
- break;
- }
- }
-
- if(GotIt)
- {
- CopyMem(Data,StripBuffer,Size);
-
- String = Data;
- Data = StripBuffer;
- }
- else
- return(Size);
- }
-
- while(Size--)
- {
- switch(c = *Data++)
- {
- case '\r':
-
- if(CR_Trans_Len)
- {
- register LONG i;
-
- for(i = 0 ; i < CR_Trans_Len ; i++)
- {
- *String++ = CR_Translation[i];
-
- Count++;
- }
- }
-
- break;
-
- case '\n':
-
- if(LF_Trans_Len)
- {
- register LONG i;
-
- for(i = 0 ; i < LF_Trans_Len ; i++)
- {
- *String++ = LF_Translation[i];
-
- Count++;
- }
- }
-
- break;
-
- default:
-
- *String++ = c;
-
- Count++;
-
- break;
- }
- }
-
- return(Count);
- }
-
- VOID
- Update_CR_LF_Translation()
- {
- Forbid();
-
- if(Config -> TerminalConfig -> ReceiveCR == EOL_CRLF || Config -> TerminalConfig -> ReceiveCR == EOL_LFCR || Config -> TerminalConfig -> ReceiveLF == EOL_LFCR || Config -> TerminalConfig -> ReceiveLF == EOL_CRLF)
- SerialBufferSize = Config -> SerialConfig -> SerialBufferSize / 2;
- else
- SerialBufferSize = Config -> SerialConfig -> SerialBufferSize;
-
- switch(Config -> TerminalConfig -> ReceiveCR)
- {
- case EOL_IGNORE:
-
- CR_Trans_Len = 0;
- break;
-
- case EOL_CR:
-
- CR_Trans_Len = 1;
- CR_Translation = "\r";
- break;
-
- case EOL_LF:
-
- CR_Trans_Len = 1;
- CR_Translation = "\n";
- break;
-
- case EOL_CRLF:
-
- CR_Trans_Len = 2;
- CR_Translation = "\r\n";
- break;
-
- case EOL_LFCR:
-
- CR_Trans_Len = 2;
- CR_Translation = "\n\r";
- break;
- }
-
- switch(Config -> TerminalConfig -> ReceiveLF)
- {
- case EOL_IGNORE:
-
- LF_Trans_Len = 0;
- break;
-
- case EOL_LF:
-
- LF_Trans_Len = 1;
- LF_Translation = "\n";
- break;
-
- case EOL_CR:
-
- LF_Trans_Len = 1;
- LF_Translation = "\r";
- break;
-
- case EOL_LFCR:
-
- LF_Trans_Len = 2;
- LF_Translation = "\n\r";
- break;
-
- case EOL_CRLF:
-
- LF_Trans_Len = 2;
- LF_Translation = "\r\n";
- break;
- }
-
- if(Config -> TerminalConfig -> ReceiveCR == EOL_CR && Config -> TerminalConfig -> ReceiveLF == EOL_LF)
- Translate_CR_LF = NULL;
- else
- {
- if(LF_Trans_Len <= 1 && CR_Trans_Len <= 1)
- Translate_CR_LF = Translate_CR_LF_1;
- else
- {
- if(LF_Trans_Len == 2 && CR_Trans_Len == 2)
- Translate_CR_LF = Translate_CR_LF_2x2;
- else
- {
- if(LF_Trans_Len == 2)
- Translate_CR_LF = Translate_CR_LF_2LF;
- else
- {
- if(CR_Trans_Len == 2)
- Translate_CR_LF = Translate_CR_LF_2CR;
- else
- Translate_CR_LF = Translate_CR_LF_1;
- }
- }
- }
- }
-
- Permit();
- }
-