4 * General class implementation for MS-DOS
6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
30 * Revision 1.13 1998/09/24 03:30:50 robertj
31 * Added open software license.
33 * Revision 1.12 1996/01/28 02:55:32 robertj
36 * Revision 1.11 1995/08/24 12:41:00 robertj
37 * Changed PChannel so not a PContainer.
39 * Revision 1.10 1995/06/17 00:59:21 robertj
40 * Moved PPipeChannel::Execute from common dos/windows to individual files.
42 * Revision 1.9 1995/04/01 08:06:03 robertj
43 * Fixed yield for straight DOS and QUICKWIN systems.
45 * Revision 1.8 1995/03/12 05:00:05 robertj
46 * Re-organisation of DOS/WIN16 and WIN32 platforms to maximise common code.
47 * Used built-in equate for WIN32 API (_WIN32).
49 * Revision 1.7 1994/12/13 11:53:44 robertj
50 * Added missing PConfig Construct() function for pure DOS.
52 * Revision 1.6 1994/10/30 11:25:36 robertj
53 * Fixed DOS version of configuration files.
55 * Revision 1.5 1994/08/22 00:18:02 robertj
56 * Added dummy socket function.
58 * Revision 1.4 1994/07/27 06:00:10 robertj
61 * Revision 1.3 1994/07/17 11:01:04 robertj
62 * Ehancements, implementation, bug fixes etc.
64 * Revision 1.2 1994/07/02 03:18:09 robertj
65 * Multi-threading implementation.
67 * Revision 1.1 1994/06/25 12:13:01 robertj
77 ///////////////////////////////////////////////////////////////////////////////
80 PString
PTime::GetTimeSeparator()
86 BOOL
PTime::GetTimeAMPM()
92 PString
PTime::GetTimeAM()
98 PString
PTime::GetTimePM()
104 PString
PTime::GetDayName(Weekdays dayOfWeek
, NameType type
)
106 static const char * const weekdays
[] = {
107 "Sunday", "Monday", "Tuesday", "Wednesday",
108 "Thursday", "Friday", "Saturday"
110 static const char * const abbrev_weekdays
[] = {
111 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
113 return (type
!= FullName
? abbrev_weekdays
: weekdays
)[dayOfWeek
];
117 PString
PTime::GetDateSeparator()
123 PString
PTime::GetMonthName(Months month
, NameType type
)
125 static const char * const months
[] = { "",
126 "January", "February", "March", "April", "May", "June",
127 "July", "August", "September", "October", "November", "December"
129 static const char * const abbrev_months
[] = {
130 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
131 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
133 return (type
!= FullName
? abbrev_months
: months
)[month
];
137 PTime::DateOrder
PTime::GetDateOrder()
143 long PTime::GetTimeZone() const
149 PString
PTime::GetTimeZoneString(TimeZoneType type
) const
156 ///////////////////////////////////////////////////////////////////////////////
159 void PSerialChannel::Construct()
161 biosParm
= 0xe3; // 9600 baud, no parity, 1 stop bit, 8 data bits
165 PString
PSerialChannel::GetName() const
168 return psprintf("COM%i", os_handle
+1);
174 BOOL
PSerialChannel::Read(void * buf
, PINDEX len
)
176 char * b
= (char *)buf
;
188 BOOL
PSerialChannel::Write(const void * buf
, PINDEX len
)
190 const char * b
= (const char *)buf
;
192 if (!WriteChar(*b
++))
199 BOOL
PSerialChannel::Close()
209 BOOL
PSerialChannel::SetCommsParam(DWORD speed
, BYTE data
, Parity parity
,
210 BYTE stop
, FlowControl inputFlow
, FlowControl outputFlow
)
303 if (outputFlow
!= DefaultFlowControl
|| inputFlow
!= DefaultFlowControl
)
306 _bios_serialcom(_COM_INIT
, os_handle
, biosParm
);
310 BOOL
PSerialChannel::Open(const PString
& port
, DWORD speed
, BYTE data
,
311 Parity parity
, BYTE stop
, FlowControl inputFlow
, FlowControl outputFlow
)
316 if (PCaselessString("COM") != port
.Left(3) &&
317 port
[3] >= '1' && port
[3] <= '4')
319 os_handle
= port
[3] - '1';
320 return SetCommsParam(speed
, data
, parity
, stop
, inputFlow
, outputFlow
);
324 BOOL
PSerialChannel::SetSpeed(DWORD speed
)
326 return SetCommsParam(speed
,
327 0, DefaultParity
, 0, DefaultFlowControl
, DefaultFlowControl
);
331 DWORD
PSerialChannel::GetSpeed() const
333 static int speed
[8] = { 110, 150, 300, 600, 1200, 2400, 4800, 9600 };
334 return speed
[biosParm
>>5];
338 BOOL
PSerialChannel::SetDataBits(BYTE data
)
340 return SetCommsParam(0,
341 data
, DefaultParity
, 0, DefaultFlowControl
, DefaultFlowControl
);
345 BYTE
PSerialChannel::GetDataBits() const
347 return (BYTE
)((biosParm
&3)+5);
351 BOOL
PSerialChannel::SetParity(Parity parity
)
353 return SetCommsParam(0,0, parity
, 0, DefaultFlowControl
, DefaultFlowControl
);
357 PSerialChannel::Parity
PSerialChannel::GetParity() const
359 return (biosParm
&8) == 0 ? NoParity
:
360 (biosParm
&0x10) == 0 ? OddParity
: EvenParity
;
364 BOOL
PSerialChannel::SetStopBits(BYTE stop
)
366 return SetCommsParam(0,
367 0, DefaultParity
, stop
, DefaultFlowControl
, DefaultFlowControl
);
371 BYTE
PSerialChannel::GetStopBits() const
373 return (BYTE
)(((biosParm
&4)>>3)+1);
377 BOOL
PSerialChannel::SetInputFlowControl(FlowControl flowControl
)
379 return SetCommsParam(0,0, DefaultParity
, 0, flowControl
, DefaultFlowControl
);
383 PSerialChannel::FlowControl
PSerialChannel::GetInputFlowControl() const
389 BOOL
PSerialChannel::SetOutputFlowControl(FlowControl flowControl
)
391 return SetCommsParam(0,0, DefaultParity
, 0, DefaultFlowControl
, flowControl
);
395 PSerialChannel::FlowControl
PSerialChannel::GetOutputFlowControl() const
401 void PSerialChannel::SetDTR(BOOL state
)
409 void PSerialChannel::SetRTS(BOOL state
)
417 void PSerialChannel::SetBreak(BOOL state
)
426 BOOL
PSerialChannel::GetCTS()
431 return (_bios_serialcom(_COM_STATUS
, os_handle
, 0)&0x8010) == 0x10;
435 BOOL
PSerialChannel::GetDSR()
440 return (_bios_serialcom(_COM_STATUS
, os_handle
, 0)&0x8020) == 0x20;
444 BOOL
PSerialChannel::GetDCD()
449 return (_bios_serialcom(_COM_STATUS
, os_handle
, 0)&0x8080) == 0x80;
453 BOOL
PSerialChannel::GetRing()
458 return (_bios_serialcom(_COM_STATUS
, os_handle
, 0)&0x8040) == 0x40;
462 PStringList
PSerialChannel::GetPortNames()
464 static char buf
[] = "COM ";
466 for (char p
= '1'; p
<= '4'; p
++) {
467 if (*(WORD
*)(0x00400000+p
-'1') != 0) {
469 ports
.Append(new PString(buf
));
476 ///////////////////////////////////////////////////////////////////////////////
479 BOOL
PPipeChannel::Execute()
485 if (os_handle
>= 0) {
490 if (!ConvertOSError(system(subProgName
)))
493 if (!fromChild
.IsEmpty()) {
494 os_handle
= _open(fromChild
, _O_RDONLY
);
495 if (!ConvertOSError(os_handle
))
503 ///////////////////////////////////////////////////////////////////////////////
504 // Configuration files
506 void PConfig::Construct(Source src
)
510 PFilePath appFile
= PProcess::Current()->GetFile();
511 location
= appFile
.GetVolume() +
512 appFile
.GetPath() + appFile
.GetTitle() + ".INI";
517 void PConfig::Construct(const PFilePath
& file
)
523 PStringList
PConfig::GetSections()
525 PStringList sections
;
527 if (!location
.IsEmpty()) {
528 PAssertAlways(PUnimplementedFunction
);
535 PStringList
PConfig::GetKeys(const PString
&) const
539 if (location
.IsEmpty()) {
540 char ** ptr
= _environ
;
541 while (*ptr
!= NULL
) {
542 PString buf
= *ptr
++;
543 keys
.AppendString(buf
.Left(buf
.Find('=')));
547 PAssertAlways(PUnimplementedFunction
);
554 void PConfig::DeleteSection(const PString
&)
556 if (location
.IsEmpty())
559 PAssertAlways(PUnimplementedFunction
);
563 void PConfig::DeleteKey(const PString
&, const PString
& key
)
565 if (location
.IsEmpty()) {
566 PAssert(key
.Find('=') == P_MAX_INDEX
, PInvalidParameter
);
570 PAssertAlways(PUnimplementedFunction
);
574 PString
PConfig::GetString(const PString
&,
575 const PString
& key
, const PString
& dflt
)
579 if (location
.IsEmpty()) {
580 PAssert(key
.Find('=') == P_MAX_INDEX
, PInvalidParameter
);
581 char * env
= getenv(key
);
588 PAssertAlways(PUnimplementedFunction
);
594 void PConfig::SetString(const PString
&, const PString
& key
, const PString
& value
)
596 if (location
.IsEmpty()) {
597 PAssert(key
.Find('=') == P_MAX_INDEX
, PInvalidParameter
);
598 _putenv(key
+ "=" + value
);
601 PAssertAlways(PUnimplementedFunction
);
606 ///////////////////////////////////////////////////////////////////////////////
609 void PThread::SwitchContext(PThread
* from
)
611 if (setjmp(from
->context
) != 0) // Are being reactivated from previous yield
614 if (status
== Starting
) {
615 if (setjmp(context
) != 0) {
618 Terminate(); // Never returns from here
620 context
[7] = (int)stackTop
-16; // Change the stack pointer in jmp_buf
623 longjmp(context
, TRUE
);
624 PAssertAlways("longjmp failed"); // Should never get here
629 ///////////////////////////////////////////////////////////////////////////////
632 PDynaLink::PDynaLink()
634 PAssertAlways(PUnimplementedFunction
);
638 PDynaLink::PDynaLink(const PString
&)
640 PAssertAlways(PUnimplementedFunction
);
644 PDynaLink::~PDynaLink()
649 BOOL
PDynaLink::Open(const PString
& name
)
651 PAssertAlways(PUnimplementedFunction
);
656 void PDynaLink::Close()
661 BOOL
PDynaLink::IsLoaded() const
667 BOOL
PDynaLink::GetFunction(PINDEX index
, Function
& func
)
673 BOOL
PDynaLink::GetFunction(const PString
& name
, Function
& func
)
680 // End Of File ///////////////////////////////////////////////////////////////