common.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. {****************************************************************************
  2. Common types, and definitions
  3. Copyright (c) 1997 Balazs Scheidler ([email protected])
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free
  14. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. $Id$
  17. ****************************************************************************
  18. Changelog:
  19. Common version 0.2.6
  20. Date Version Who Comments
  21. 07/12/97 0.1 Bazsi Initial implementation (bazsi)
  22. 07/18/97 0.2 Bazsi Linux specific error codes added
  23. 07/18/97 0.2.1 Bazsi Some syntactical errors removed...
  24. 07/28/97 0.2.2 Bazsi Base error code for Video registered
  25. 07/29/97 0.2.3 Bazsi Some basic types added (PByte, PWord etc)
  26. 08/08/97 0.2.4 Bazsi Finalized error handling code (Brad's code added)
  27. 08/27/97 0.2.5 Bazsi BP doesn't like function types as return-values
  28. for functions, returning Pointer instead
  29. 09/06/97 0.2.6 Bazsi Added base error code for Keyboard
  30. 11/06/97 0.2.7 Bazsi Added base error code for FileCtrl
  31. Todo:
  32. * Some types found in the DOS unit should be included here (TextRec maybe
  33. renamed to TTextRec, FileRec etc.)
  34. * Other platform specific error codes.
  35. ****************************************************************************}
  36. unit Common;
  37. interface
  38. {$i platform.inc}
  39. const
  40. { Error codes }
  41. errOk = 0;
  42. errVioBase = 1000;
  43. errKbdBase = 1010;
  44. errFileCtrlBase = 1020;
  45. errMouseBase = 1030;
  46. { The following ranges have been defined for error codes:
  47. 0 - 1000 OS dependent codes
  48. 1000 - 10000 API reserved codes
  49. 10000 - Add-on unit errors
  50. Before anyone adding a unit, contact [email protected] to assign a base
  51. error code, to avoid collisions.
  52. The symbolic names of error codes should be defined in the unit which uses
  53. those error codes, except for OS dependent ones, which should be defined here
  54. enclosed in IFDEFs. (The reason is that not always you can't always decide
  55. which error-code belongs to one unit or the other) }
  56. {$IFDEF OS_Linux}
  57. { for a more complete description of each error check /usr/include/asm/errno.h }
  58. errNotPermitted = 1;
  59. errFileNotFound = 2;
  60. errNoSuchProcess = 3;
  61. errInterruptedCall = 4;
  62. errIOError = 5;
  63. errNoDevAddr = 6;
  64. errTooManyArguments = 7;
  65. errExecError = 8;
  66. errBadFileHandle = 9;
  67. errNoChild = 10;
  68. errTryAgain = 11;
  69. errWouldBlock = errTryAgain;
  70. errOutOfMemory = 12;
  71. errNoPermission = 13;
  72. errInvalidAddress = 14; { Invalid pointer passed to kernel }
  73. errNotBlockDev = 15;
  74. errDeviceBusy = 16;
  75. errFileExists = 17;
  76. errCrossDevice = 18;
  77. errNoSuchDev = 19;
  78. errNotDirectory = 20;
  79. errIsDirectory = 21;
  80. errInvalidArgument = 22;
  81. errFileTableOverflow = 23;
  82. errTooManyOpenFiles = 24;
  83. errNotATTY = 25;
  84. errTextBusy = 26;
  85. errFileTooLarge = 27;
  86. errDiskFull = 28;
  87. errIllegalSeek = 29;
  88. errReadOnlyFS = 30;
  89. errTooManyLinks = 31;
  90. errBrokenPipe = 32;
  91. errMathDomain = 33; { Math domain error, what does this mean? }
  92. errMathRange = 34; { Math result out of range }
  93. errDeadLock = 35;
  94. errFileNameTooLong = 36;
  95. errNoLock = 37; { No record locks available }
  96. errNotImplemented = 38; { Kernel function not implemented }
  97. errDirNotEmpty = 39;
  98. errSymlinkLoop = 40;
  99. errNoMessage = 41; { ??? maybe the IPC getmsg call returns this }
  100. { Here are some errors that are too cryptic for me, I think they are not used
  101. under Linux, only on some mainframes (channel errors etc) }
  102. errBadFont = 59;
  103. errNotStream = 60;
  104. errNoData = 61;
  105. errTimeOut = 62;
  106. errNoMoreStreams = 63;
  107. errNoNetwork = 64;
  108. errPackageNotInstalled = 65; { ??? }
  109. errRemote = 66;
  110. errSevereLink = 67;
  111. errAdvertise = 68; { Advertise error??? }
  112. errSrMount = 69;
  113. errCommunication = 70; { Communication error on send? }
  114. errProtocol = 71; { Protocol error }
  115. errMuiltiHop = 72;
  116. errDotDot = 73; { RFS specific error ???}
  117. errBadMessage = 74; { Not a data message }
  118. errOverflow = 75;
  119. errNotUnique = 76; { Network name not unique }
  120. errBadFileHandleState = 77;
  121. errRemoteChange = 78; { Remote address changed }
  122. errLibAccess = 79; { Cannot access the needed shared lib }
  123. errLibCorrupt = 80; { Shared library corrupted }
  124. errLibScn = 81;
  125. errLibTooMany = 82; { Too many shared libraries }
  126. errLibExec = 83; { Attempting to execute a shared lib }
  127. errIllegalSequence = 84; { Illegal byte sequence ??? }
  128. errRestart = 85; { interrupted system call should be restarted }
  129. errStreamPipe = 86;
  130. errTooManyUsers = 87;
  131. errNotSocket = 88;
  132. errDestAddrRequired = 89;
  133. errMessageTooLong = 90;
  134. errProtocolType = 91;
  135. errNoSuchProtocol = 92;
  136. errProtocolNotSupported = 93;
  137. errSocketTypeNotSupported = 94;
  138. errOperationNotSupported= 95;
  139. errPFamilyNotSupported = 96; { Protocol family not supported }
  140. errAFamilyNotSupported = 97; { Address family not supported }
  141. errAddressInUse = 98;
  142. errAddressNotAvailable = 99;
  143. errNetDown = 100;
  144. errNetUnreachable = 101;
  145. errNetReset = 102;
  146. errConnAborted = 103;
  147. errConnReset = 104;
  148. errNoBufs = 105;
  149. errAlreadyConn = 106;
  150. errNotConn = 107;
  151. errShutdown = 108;
  152. errTooManyRefs = 109;
  153. errConnTimeOut = 110;
  154. errConnRefused = 111;
  155. errHostDown = 112;
  156. errNoRoute = 113; { No route to host }
  157. errOperationProgress = 114; { Operation already in progress }
  158. errStaleNFSHandle = 115;
  159. errStrucClean = 116; { Structure needs cleaning ? }
  160. { Xenix specific codes left out }
  161. errRemoteIO = 121;
  162. errQuotaExceeded = 122;
  163. {$ENDIF}
  164. {$IFDEF OS_DOS}
  165. { DOS specific error-codes to be added }
  166. {$ENDIF}
  167. type
  168. {$IFDEF BIT_32}
  169. CPUWord = Longint;
  170. CPUInt = Longint;
  171. {$ELSE}
  172. CPUWord = Word;
  173. CPUInt = Integer;
  174. {$ENDIF}
  175. PByte = ^Byte;
  176. PWord = ^Word;
  177. PLongint = ^Longint;
  178. { This code is taken from Brad Williams code, with some modifications }
  179. type
  180. TErrorHandlerReturnValue = (errRetry, errAbort, errContinue);
  181. { errRetry = retry the operation,
  182. errAbort = abort, return error code,
  183. errContinue = abort, without returning errorcode }
  184. TErrorHandler = function (Code: Longint; Info: Pointer): TErrorHandlerReturnValue;
  185. { ErrorHandler is the standard procedural interface for all error functions.
  186. Info may contain any data type specific to the error code passed to the
  187. function. }
  188. function GetErrorCode: Longint;
  189. { Returns the last error code, and resets it to 0 (errOK) }
  190. function GetErrorInfo: Pointer;
  191. { Returns the info assigned to the previous error, doesn't reset the value to nil }
  192. {$IFDEF PPC_BP}
  193. function SetErrorHandler(AErrorHandler: TErrorHandler): Pointer;
  194. {$ELSE}
  195. function SetErrorHandler(AErrorHandler: TErrorHandler): TErrorHandler;
  196. {$ENDIF}
  197. { Sets ErrorHandler to AErrorHandler, and returns the old one }
  198. function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
  199. { Default error handler, simply sets error code, and returns errContinue }
  200. const
  201. ErrorCode: Longint = errOk;
  202. ErrorInfo: Pointer = nil;
  203. ErrorHandler: TErrorHandler = DefaultErrorHandler;
  204. implementation
  205. function GetErrorCode: Longint;
  206. begin
  207. GetErrorCode := ErrorCode;
  208. ErrorCode := 0;
  209. end;
  210. function GetErrorInfo: Pointer;
  211. begin
  212. GetErrorInfo := ErrorInfo;
  213. end;
  214. {$IFDEF PPC_BP}
  215. function SetErrorHandler(AErrorHandler: TErrorHandler): Pointer;
  216. begin
  217. SetErrorHandler := @ErrorHandler;
  218. ErrorHandler := AErrorHandler;
  219. end;
  220. {$ELSE}
  221. function SetErrorHandler(AErrorHandler: TErrorHandler): TErrorHandler;
  222. begin
  223. SetErrorHandler := ErrorHandler;
  224. ErrorHandler := AErrorHandler;
  225. end;
  226. {$ENDIF}
  227. function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
  228. begin
  229. ErrorCode := AErrorCode;
  230. ErrorInfo := AErrorInfo;
  231. DefaultErrorHandler := errAbort; { return error code }
  232. end;
  233. end.
  234. {
  235. $Id$
  236. Common types, and definitions
  237. Copyright (c) 1997 Balazs Scheidler ([email protected])
  238. This library is free software; you can redistribute it and/or
  239. modify it under the terms of the GNU Library General Public
  240. License as published by the Free Software Foundation; either
  241. version 2 of the License, or (at your option) any later version.
  242. This library is distributed in the hope that it will be useful,
  243. but WITHOUT ANY WARRANTY; without even the implied warranty of
  244. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  245. Library General Public License for more details.
  246. You should have received a copy of the GNU Library General Public
  247. License along with this library; if not, write to the Free
  248. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  249. ****************************************************************************
  250. Todo:
  251. * Some types found in the DOS unit should be included here (TextRec maybe
  252. renamed to TTextRec, FileRec etc.)
  253. * Other platform specific error codes.
  254. ****************************************************************************}
  255. unit Common;
  256. interface
  257. {$i platform.inc}
  258. const
  259. { Error codes }
  260. errOk = 0;
  261. errVioBase = 1000;
  262. errKbdBase = 1010;
  263. errFileCtrlBase = 1020;
  264. { The following ranges have been defined for error codes:
  265. 0 - 1000 OS dependent codes
  266. 1000 - 10000 API reserved codes
  267. 10000 - Add-on unit errors
  268. Before anyone adding a unit, contact [email protected] to assign a base
  269. error code, to avoid collisions.
  270. The symbolic names of error codes should be defined in the unit which uses
  271. those error codes, except for OS dependent ones, which should be defined here
  272. enclosed in IFDEFs. (The reason is that not always you can't always decide
  273. which error-code belongs to one unit or the other) }
  274. {$IFDEF OS_Linux}
  275. { for a more complete description of each error check /usr/include/asm/errno.h }
  276. errNotPermitted = 1;
  277. errFileNotFound = 2;
  278. errNoSuchProcess = 3;
  279. errInterruptedCall = 4;
  280. errIOError = 5;
  281. errNoDevAddr = 6;
  282. errTooManyArguments = 7;
  283. errExecError = 8;
  284. errBadFileHandle = 9;
  285. errNoChild = 10;
  286. errTryAgain = 11;
  287. errWouldBlock = errTryAgain;
  288. errOutOfMemory = 12;
  289. errNoPermission = 13;
  290. errInvalidAddress = 14; { Invalid pointer passed to kernel }
  291. errNotBlockDev = 15;
  292. errDeviceBusy = 16;
  293. errFileExists = 17;
  294. errCrossDevice = 18;
  295. errNoSuchDev = 19;
  296. errNotDirectory = 20;
  297. errIsDirectory = 21;
  298. errInvalidArgument = 22;
  299. errFileTableOverflow = 23;
  300. errTooManyOpenFiles = 24;
  301. errNotATTY = 25;
  302. errTextBusy = 26;
  303. errFileTooLarge = 27;
  304. errDiskFull = 28;
  305. errIllegalSeek = 29;
  306. errReadOnlyFS = 30;
  307. errTooManyLinks = 31;
  308. errBrokenPipe = 32;
  309. errMathDomain = 33; { Math domain error, what does this mean? }
  310. errMathRange = 34; { Math result out of range }
  311. errDeadLock = 35;
  312. errFileNameTooLong = 36;
  313. errNoLock = 37; { No record locks available }
  314. errNotImplemented = 38; { Kernel function not implemented }
  315. errDirNotEmpty = 39;
  316. errSymlinkLoop = 40;
  317. errNoMessage = 41; { ??? maybe the IPC getmsg call returns this }
  318. { Here are some errors that are too cryptic for me, I think they are not used
  319. under Linux, only on some mainframes (channel errors etc) }
  320. errBadFont = 59;
  321. errNotStream = 60;
  322. errNoData = 61;
  323. errTimeOut = 62;
  324. errNoMoreStreams = 63;
  325. errNoNetwork = 64;
  326. errPackageNotInstalled = 65; { ??? }
  327. errRemote = 66;
  328. errSevereLink = 67;
  329. errAdvertise = 68; { Advertise error??? }
  330. errSrMount = 69;
  331. errCommunication = 70; { Communication error on send? }
  332. errProtocol = 71; { Protocol error }
  333. errMuiltiHop = 72;
  334. errDotDot = 73; { RFS specific error ???}
  335. errBadMessage = 74; { Not a data message }
  336. errOverflow = 75;
  337. errNotUnique = 76; { Network name not unique }
  338. errBadFileHandleState = 77;
  339. errRemoteChange = 78; { Remote address changed }
  340. errLibAccess = 79; { Cannot access the needed shared lib }
  341. errLibCorrupt = 80; { Shared library corrupted }
  342. errLibScn = 81;
  343. errLibTooMany = 82; { Too many shared libraries }
  344. errLibExec = 83; { Attempting to execute a shared lib }
  345. errIllegalSequence = 84; { Illegal byte sequence ??? }
  346. errRestart = 85; { interrupted system call should be restarted }
  347. errStreamPipe = 86;
  348. errTooManyUsers = 87;
  349. errNotSocket = 88;
  350. errDestAddrRequired = 89;
  351. errMessageTooLong = 90;
  352. errProtocolType = 91;
  353. errNoSuchProtocol = 92;
  354. errProtocolNotSupported = 93;
  355. errSocketTypeNotSupported = 94;
  356. errOperationNotSupported= 95;
  357. errPFamilyNotSupported = 96; { Protocol family not supported }
  358. errAFamilyNotSupported = 97; { Address family not supported }
  359. errAddressInUse = 98;
  360. errAddressNotAvailable = 99;
  361. errNetDown = 100;
  362. errNetUnreachable = 101;
  363. errNetReset = 102;
  364. errConnAborted = 103;
  365. errConnReset = 104;
  366. errNoBufs = 105;
  367. errAlreadyConn = 106;
  368. errNotConn = 107;
  369. errShutdown = 108;
  370. errTooManyRefs = 109;
  371. errConnTimeOut = 110;
  372. errConnRefused = 111;
  373. errHostDown = 112;
  374. errNoRoute = 113; { No route to host }
  375. errOperationProgress = 114; { Operation already in progress }
  376. errStaleNFSHandle = 115;
  377. errStrucClean = 116; { Structure needs cleaning ? }
  378. { Xenix specific codes left out }
  379. errRemoteIO = 121;
  380. errQuotaExceeded = 122;
  381. {$ENDIF}
  382. {$IFDEF OS_DOS}
  383. { DOS specific error-codes to be added }
  384. {$ENDIF}
  385. type
  386. {$IFDEF BIT_32}
  387. CPUWord = Longint;
  388. CPUInt = Longint;
  389. {$ELSE}
  390. CPUWord = Word;
  391. CPUInt = Integer;
  392. {$ENDIF}
  393. PByte = ^Byte;
  394. PWord = ^Word;
  395. PLongint = ^Longint;
  396. { This code is taken from Brad Williams code, with some modifications }
  397. type
  398. TErrorHandlerReturnValue = (errRetry, errAbort, errContinue);
  399. { errRetry = retry the operation,
  400. errAbort = abort, return error code,
  401. errContinue = abort, without returning errorcode }
  402. TErrorHandler = function (Code: Longint; Info: Pointer): TErrorHandlerReturnValue;
  403. { ErrorHandler is the standard procedural interface for all error functions.
  404. Info may contain any data type specific to the error code passed to the
  405. function. }
  406. function GetErrorCode: Longint;
  407. { Returns the last error code, and resets it to 0 (errOK) }
  408. function GetErrorInfo: Pointer;
  409. { Returns the info assigned to the previous error, doesn't reset the value to nil }
  410. {$IFDEF PPC_BP}
  411. function SetErrorHandler(AErrorHandler: TErrorHandler): Pointer;
  412. {$ELSE}
  413. function SetErrorHandler(AErrorHandler: TErrorHandler): TErrorHandler;
  414. {$ENDIF}
  415. { Sets ErrorHandler to AErrorHandler, and returns the old one }
  416. function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
  417. { Default error handler, simply sets error code, and returns errContinue }
  418. const
  419. ErrorCode: Longint = errOk;
  420. ErrorInfo: Pointer = nil;
  421. ErrorHandler: TErrorHandler = DefaultErrorHandler;
  422. implementation
  423. function GetErrorCode: Longint;
  424. begin
  425. GetErrorCode := ErrorCode;
  426. ErrorCode := 0;
  427. end;
  428. function GetErrorInfo: Pointer;
  429. begin
  430. GetErrorInfo := ErrorInfo;
  431. end;
  432. {$IFDEF PPC_BP}
  433. function SetErrorHandler(AErrorHandler: TErrorHandler): Pointer;
  434. begin
  435. SetErrorHandler := @ErrorHandler;
  436. ErrorHandler := AErrorHandler;
  437. end;
  438. {$ELSE}
  439. function SetErrorHandler(AErrorHandler: TErrorHandler): TErrorHandler;
  440. begin
  441. SetErrorHandler := ErrorHandler;
  442. ErrorHandler := AErrorHandler;
  443. end;
  444. {$ENDIF}
  445. function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
  446. begin
  447. ErrorCode := AErrorCode;
  448. ErrorInfo := AErrorInfo;
  449. DefaultErrorHandler := errAbort; { return error code }
  450. end;
  451. end.
  452. {
  453. $Log$
  454. Revision 1.1 2000-01-06 01:20:31 peter
  455. * moved out of packages/ back to topdir
  456. Revision 1.1 1999/12/23 19:36:47 peter
  457. * place unitfiles in target dirs
  458. Revision 1.1 1999/11/24 23:36:37 peter
  459. * moved to packages dir
  460. Revision 1.1 1998/12/04 12:48:24 peter
  461. * moved some dirs
  462. Revision 1.5 1998/10/28 00:02:05 peter
  463. + mouse
  464. + video.clearscreen, video.videobufsize
  465. Revision 1.4 1998/10/26 11:22:48 peter
  466. * updates
  467. Date Version Who Comments
  468. 07/12/97 0.1 Bazsi Initial implementation (bazsi)
  469. 07/18/97 0.2 Bazsi Linux specific error codes added
  470. 07/18/97 0.2.1 Bazsi Some syntactical errors removed...
  471. 07/28/97 0.2.2 Bazsi Base error code for Video registered
  472. 07/29/97 0.2.3 Bazsi Some basic types added (PByte, PWord etc)
  473. 08/08/97 0.2.4 Bazsi Finalized error handling code (Brad's code added)
  474. 08/27/97 0.2.5 Bazsi BP doesn't like function types as return-values
  475. for functions, returning Pointer instead
  476. 09/06/97 0.2.6 Bazsi Added base error code for Keyboard
  477. 11/06/97 0.2.7 Bazsi Added base error code for FileCtrl
  478. }