File: common.pas

package info (click to toggle)
fpc 0.99.13-19991013-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 23,104 kB
  • ctags: 9,760
  • sloc: pascal: 253,711; ansic: 5,236; makefile: 3,855; yacc: 2,016; lex: 707; asm: 526; xml: 443; sh: 200; perl: 87; sed: 21; csh: 12; cpp: 1
file content (538 lines) | stat: -rw-r--r-- 19,382 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
{****************************************************************************

   Common types, and definitions

   Copyright (c) 1997 Balazs Scheidler (bazsi@balabit.hu)

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
   
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
   
   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 ****************************************************************************
   $Id: common.pas,v 1.1 1998/12/04 12:48:24 peter Exp $
 ****************************************************************************

 Changelog:
   
   Common version 0.2.6

   Date       Version  Who     Comments
   07/12/97   0.1      Bazsi   Initial implementation (bazsi)
   07/18/97   0.2      Bazsi   Linux specific error codes added
   07/18/97   0.2.1    Bazsi   Some syntactical errors removed...
   07/28/97   0.2.2    Bazsi   Base error code for Video registered
   07/29/97   0.2.3    Bazsi   Some basic types added (PByte, PWord etc)
   08/08/97   0.2.4    Bazsi   Finalized error handling code (Brad's code added)
   08/27/97   0.2.5    Bazsi   BP doesn't like function types as return-values
                               for functions, returning Pointer instead
   09/06/97   0.2.6    Bazsi   Added base error code for Keyboard
   11/06/97   0.2.7    Bazsi   Added base error code for FileCtrl
   
 Todo:
 
 *  Some types found in the DOS unit should be included here (TextRec maybe 
    renamed to TTextRec, FileRec etc.)
 *  Other platform specific error codes.

 ****************************************************************************}
unit Common;

interface

{$i platform.inc}

const
  { Error codes }
  errOk                 = 0;
  errVioBase            = 1000;
  errKbdBase            = 1010;
  errFileCtrlBase	= 1020;
  errMouseBase          = 1030;
  { The following ranges have been defined for error codes:
     0      - 1000           OS dependent codes
     1000   - 10000          API reserved codes
     10000  -                Add-on unit errors 
    Before anyone adding a unit, contact bazsi@tas.vein.hu to assign a base
    error code, to avoid collisions. 
    
    The symbolic names of error codes should be defined in the unit which uses
    those error codes, except for OS dependent ones, which should be defined here
    enclosed in IFDEFs. (The reason is that not always you can't always decide
    which error-code belongs to one unit or the other) }

{$IFDEF OS_Linux}
  { for a more complete description of each error check /usr/include/asm/errno.h }
  errNotPermitted         =   1;
  errFileNotFound         =   2;
  errNoSuchProcess        =   3;
  errInterruptedCall      =   4;
  errIOError              =   5;
  errNoDevAddr            =   6;
  errTooManyArguments     =   7;
  errExecError            =   8;
  errBadFileHandle        =   9;
  errNoChild              =  10;
  errTryAgain             =  11;
  errWouldBlock           =  errTryAgain;
  errOutOfMemory          =  12;
  errNoPermission         =  13;
  errInvalidAddress       =  14;  { Invalid pointer passed to kernel }
  errNotBlockDev          =  15;
  errDeviceBusy           =  16;
  errFileExists           =  17;
  errCrossDevice          =  18;  
  errNoSuchDev            =  19;
  errNotDirectory         =  20;
  errIsDirectory          =  21;
  errInvalidArgument      =  22;
  errFileTableOverflow    =  23;
  errTooManyOpenFiles     =  24;
  errNotATTY              =  25;
  errTextBusy             =  26;
  errFileTooLarge         =  27;
  errDiskFull             =  28;
  errIllegalSeek          =  29;
  errReadOnlyFS           =  30;
  errTooManyLinks         =  31;
  errBrokenPipe		  =  32;
  errMathDomain           =  33;  { Math domain error, what does this mean? }
  errMathRange            =  34;  { Math result out of range }
  errDeadLock             =  35;
  errFileNameTooLong      =  36;
  errNoLock               =  37;  { No record locks available }
  errNotImplemented       =  38;  { Kernel function not implemented }
  errDirNotEmpty          =  39;
  errSymlinkLoop          =  40;
  errNoMessage            =  41;  { ??? maybe the IPC getmsg call returns this }
  { Here are some errors that are too cryptic for me, I think they are not used
    under Linux, only on some mainframes (channel errors etc) }
  errBadFont              =  59;
  errNotStream            =  60;
  errNoData               =  61;
  errTimeOut              =  62;
  errNoMoreStreams        =  63;
  errNoNetwork            =  64;
  errPackageNotInstalled  =  65; { ??? }
  errRemote               =  66;
  errSevereLink           =  67;
  errAdvertise            =  68; { Advertise error??? }
  errSrMount              =  69;
  errCommunication        =  70; { Communication error on send? }
  errProtocol             =  71; { Protocol error }
  errMuiltiHop            =  72; 
  errDotDot               =  73; { RFS specific error ???}
  errBadMessage           =  74; { Not a data message }
  errOverflow             =  75;
  errNotUnique            =  76; { Network name not unique }
  errBadFileHandleState   =  77;
  errRemoteChange         =  78; { Remote address changed }
  errLibAccess            =  79; { Cannot access the needed shared lib }
  errLibCorrupt           =  80; { Shared library corrupted }
  errLibScn               =  81;
  errLibTooMany           =  82; { Too many shared libraries }
  errLibExec              =  83; { Attempting to execute a shared lib }
  errIllegalSequence      =  84; { Illegal byte sequence ??? }
  errRestart              =  85; { interrupted system call should be restarted }
  errStreamPipe           =  86;
  errTooManyUsers         =  87;
  errNotSocket            =  88;
  errDestAddrRequired     =  89;
  errMessageTooLong       =  90;
  errProtocolType         =  91;
  errNoSuchProtocol       =  92;
  errProtocolNotSupported =  93;
  errSocketTypeNotSupported = 94;
  errOperationNotSupported=  95;
  errPFamilyNotSupported  =  96; { Protocol family not supported }
  errAFamilyNotSupported  =  97; { Address family not supported }
  errAddressInUse         =  98;
  errAddressNotAvailable  =  99;
  errNetDown              = 100;
  errNetUnreachable       = 101;
  errNetReset             = 102;
  errConnAborted          = 103;
  errConnReset            = 104;
  errNoBufs               = 105;
  errAlreadyConn          = 106;
  errNotConn              = 107;
  errShutdown             = 108;
  errTooManyRefs          = 109;
  errConnTimeOut          = 110;
  errConnRefused          = 111;
  errHostDown             = 112;
  errNoRoute              = 113; { No route to host }
  errOperationProgress    = 114; { Operation already in progress }
  errStaleNFSHandle       = 115;
  errStrucClean           = 116; { Structure needs cleaning ? }
  { Xenix specific codes left out }
  errRemoteIO             = 121;
  errQuotaExceeded        = 122; 
{$ENDIF}
{$IFDEF OS_DOS}
  { DOS specific error-codes to be added }
{$ENDIF}



type
{$IFDEF BIT_32}
  CPUWord = Longint;
  CPUInt = Longint;
{$ELSE}
  CPUWord = Word;
  CPUInt = Integer;
{$ENDIF}

  PByte = ^Byte;
  PWord = ^Word;
  PLongint = ^Longint;

{ This code is taken from Brad Williams code, with some modifications }
type
  TErrorHandlerReturnValue = (errRetry, errAbort, errContinue);
  { errRetry = retry the operation,
    errAbort = abort, return error code,
    errContinue = abort, without returning errorcode }

  TErrorHandler = function (Code: Longint; Info: Pointer): TErrorHandlerReturnValue;
    { ErrorHandler is the standard procedural interface for all error functions.
      Info may contain any data type specific to the error code passed to the
      function. }

function GetErrorCode: Longint;
{ Returns the last error code, and resets it to 0 (errOK) }
function GetErrorInfo: Pointer;
{ Returns the info assigned to the previous error, doesn't reset the value to nil }
{$IFDEF PPC_BP}
function SetErrorHandler(AErrorHandler: TErrorHandler): Pointer;
{$ELSE}
function SetErrorHandler(AErrorHandler: TErrorHandler): TErrorHandler;
{$ENDIF}
{ Sets ErrorHandler to AErrorHandler, and returns the old one }
function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
{ Default error handler, simply sets error code, and returns errContinue }

const
  ErrorCode: Longint = errOk;
  ErrorInfo: Pointer = nil;
  ErrorHandler: TErrorHandler = DefaultErrorHandler;

implementation

function GetErrorCode: Longint;
begin
  GetErrorCode := ErrorCode;
  ErrorCode := 0;
end;

function GetErrorInfo: Pointer;
begin
  GetErrorInfo := ErrorInfo;
end;

{$IFDEF PPC_BP}
function SetErrorHandler(AErrorHandler: TErrorHandler): Pointer;
begin
  SetErrorHandler := @ErrorHandler;
  ErrorHandler := AErrorHandler;
end;
{$ELSE}
function SetErrorHandler(AErrorHandler: TErrorHandler): TErrorHandler;
begin
  SetErrorHandler := ErrorHandler;
  ErrorHandler := AErrorHandler;
end;
{$ENDIF}

function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
begin
  ErrorCode := AErrorCode;
  ErrorInfo := AErrorInfo;
  DefaultErrorHandler := errAbort; { return error code }
end;

end.
{
   $Id: common.pas,v 1.1 1998/12/04 12:48:24 peter Exp $

   Common types, and definitions

   Copyright (c) 1997 Balazs Scheidler (bazsi@balabit.hu)

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.


   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 ****************************************************************************

 Todo:

 *  Some types found in the DOS unit should be included here (TextRec maybe
    renamed to TTextRec, FileRec etc.)
 *  Other platform specific error codes.

 ****************************************************************************}
unit Common;

interface

{$i platform.inc}

const
  { Error codes }
  errOk                 = 0;
  errVioBase            = 1000;
  errKbdBase            = 1010;
  errFileCtrlBase       = 1020;
  { The following ranges have been defined for error codes:
     0      - 1000           OS dependent codes
     1000   - 10000          API reserved codes
     10000  -                Add-on unit errors
    Before anyone adding a unit, contact bazsi@tas.vein.hu to assign a base
    error code, to avoid collisions.

    The symbolic names of error codes should be defined in the unit which uses
    those error codes, except for OS dependent ones, which should be defined here
    enclosed in IFDEFs. (The reason is that not always you can't always decide
    which error-code belongs to one unit or the other) }

{$IFDEF OS_Linux}
  { for a more complete description of each error check /usr/include/asm/errno.h }
  errNotPermitted         =   1;
  errFileNotFound         =   2;
  errNoSuchProcess        =   3;
  errInterruptedCall      =   4;
  errIOError              =   5;
  errNoDevAddr            =   6;
  errTooManyArguments     =   7;
  errExecError            =   8;
  errBadFileHandle        =   9;
  errNoChild              =  10;
  errTryAgain             =  11;
  errWouldBlock           =  errTryAgain;
  errOutOfMemory          =  12;
  errNoPermission         =  13;
  errInvalidAddress       =  14;  { Invalid pointer passed to kernel }
  errNotBlockDev          =  15;
  errDeviceBusy           =  16;
  errFileExists           =  17;
  errCrossDevice          =  18;
  errNoSuchDev            =  19;
  errNotDirectory         =  20;
  errIsDirectory          =  21;
  errInvalidArgument      =  22;
  errFileTableOverflow    =  23;
  errTooManyOpenFiles     =  24;
  errNotATTY              =  25;
  errTextBusy             =  26;
  errFileTooLarge         =  27;
  errDiskFull             =  28;
  errIllegalSeek          =  29;
  errReadOnlyFS           =  30;
  errTooManyLinks         =  31;
  errBrokenPipe           =  32;
  errMathDomain           =  33;  { Math domain error, what does this mean? }
  errMathRange            =  34;  { Math result out of range }
  errDeadLock             =  35;
  errFileNameTooLong      =  36;
  errNoLock               =  37;  { No record locks available }
  errNotImplemented       =  38;  { Kernel function not implemented }
  errDirNotEmpty          =  39;
  errSymlinkLoop          =  40;
  errNoMessage            =  41;  { ??? maybe the IPC getmsg call returns this }
  { Here are some errors that are too cryptic for me, I think they are not used
    under Linux, only on some mainframes (channel errors etc) }
  errBadFont              =  59;
  errNotStream            =  60;
  errNoData               =  61;
  errTimeOut              =  62;
  errNoMoreStreams        =  63;
  errNoNetwork            =  64;
  errPackageNotInstalled  =  65; { ??? }
  errRemote               =  66;
  errSevereLink           =  67;
  errAdvertise            =  68; { Advertise error??? }
  errSrMount              =  69;
  errCommunication        =  70; { Communication error on send? }
  errProtocol             =  71; { Protocol error }
  errMuiltiHop            =  72;
  errDotDot               =  73; { RFS specific error ???}
  errBadMessage           =  74; { Not a data message }
  errOverflow             =  75;
  errNotUnique            =  76; { Network name not unique }
  errBadFileHandleState   =  77;
  errRemoteChange         =  78; { Remote address changed }
  errLibAccess            =  79; { Cannot access the needed shared lib }
  errLibCorrupt           =  80; { Shared library corrupted }
  errLibScn               =  81;
  errLibTooMany           =  82; { Too many shared libraries }
  errLibExec              =  83; { Attempting to execute a shared lib }
  errIllegalSequence      =  84; { Illegal byte sequence ??? }
  errRestart              =  85; { interrupted system call should be restarted }
  errStreamPipe           =  86;
  errTooManyUsers         =  87;
  errNotSocket            =  88;
  errDestAddrRequired     =  89;
  errMessageTooLong       =  90;
  errProtocolType         =  91;
  errNoSuchProtocol       =  92;
  errProtocolNotSupported =  93;
  errSocketTypeNotSupported = 94;
  errOperationNotSupported=  95;
  errPFamilyNotSupported  =  96; { Protocol family not supported }
  errAFamilyNotSupported  =  97; { Address family not supported }
  errAddressInUse         =  98;
  errAddressNotAvailable  =  99;
  errNetDown              = 100;
  errNetUnreachable       = 101;
  errNetReset             = 102;
  errConnAborted          = 103;
  errConnReset            = 104;
  errNoBufs               = 105;
  errAlreadyConn          = 106;
  errNotConn              = 107;
  errShutdown             = 108;
  errTooManyRefs          = 109;
  errConnTimeOut          = 110;
  errConnRefused          = 111;
  errHostDown             = 112;
  errNoRoute              = 113; { No route to host }
  errOperationProgress    = 114; { Operation already in progress }
  errStaleNFSHandle       = 115;
  errStrucClean           = 116; { Structure needs cleaning ? }
  { Xenix specific codes left out }
  errRemoteIO             = 121;
  errQuotaExceeded        = 122;
{$ENDIF}
{$IFDEF OS_DOS}
  { DOS specific error-codes to be added }
{$ENDIF}



type
{$IFDEF BIT_32}
  CPUWord = Longint;
  CPUInt = Longint;
{$ELSE}
  CPUWord = Word;
  CPUInt = Integer;
{$ENDIF}

  PByte = ^Byte;
  PWord = ^Word;
  PLongint = ^Longint;

{ This code is taken from Brad Williams code, with some modifications }
type
  TErrorHandlerReturnValue = (errRetry, errAbort, errContinue);
  { errRetry = retry the operation,
    errAbort = abort, return error code,
    errContinue = abort, without returning errorcode }

  TErrorHandler = function (Code: Longint; Info: Pointer): TErrorHandlerReturnValue;
    { ErrorHandler is the standard procedural interface for all error functions.
      Info may contain any data type specific to the error code passed to the
      function. }

function GetErrorCode: Longint;
{ Returns the last error code, and resets it to 0 (errOK) }
function GetErrorInfo: Pointer;
{ Returns the info assigned to the previous error, doesn't reset the value to nil }
{$IFDEF PPC_BP}
function SetErrorHandler(AErrorHandler: TErrorHandler): Pointer;
{$ELSE}
function SetErrorHandler(AErrorHandler: TErrorHandler): TErrorHandler;
{$ENDIF}
{ Sets ErrorHandler to AErrorHandler, and returns the old one }
function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
{ Default error handler, simply sets error code, and returns errContinue }

const
  ErrorCode: Longint = errOk;
  ErrorInfo: Pointer = nil;
  ErrorHandler: TErrorHandler = DefaultErrorHandler;

implementation

function GetErrorCode: Longint;
begin
  GetErrorCode := ErrorCode;
  ErrorCode := 0;
end;

function GetErrorInfo: Pointer;
begin
  GetErrorInfo := ErrorInfo;
end;

{$IFDEF PPC_BP}
function SetErrorHandler(AErrorHandler: TErrorHandler): Pointer;
begin
  SetErrorHandler := @ErrorHandler;
  ErrorHandler := AErrorHandler;
end;
{$ELSE}
function SetErrorHandler(AErrorHandler: TErrorHandler): TErrorHandler;
begin
  SetErrorHandler := ErrorHandler;
  ErrorHandler := AErrorHandler;
end;
{$ENDIF}

function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
begin
  ErrorCode := AErrorCode;
  ErrorInfo := AErrorInfo;
  DefaultErrorHandler := errAbort; { return error code }
end;

end.

{
  $Log: common.pas,v $
  Revision 1.1  1998/12/04 12:48:24  peter
    * moved some dirs

  Revision 1.5  1998/10/28 00:02:05  peter
    + mouse
    + video.clearscreen, video.videobufsize

  Revision 1.4  1998/10/26 11:22:48  peter
    * updates

  
   Date       Version  Who     Comments
   07/12/97   0.1      Bazsi   Initial implementation (bazsi)
   07/18/97   0.2      Bazsi   Linux specific error codes added
   07/18/97   0.2.1    Bazsi   Some syntactical errors removed...
   07/28/97   0.2.2    Bazsi   Base error code for Video registered
   07/29/97   0.2.3    Bazsi   Some basic types added (PByte, PWord etc)
   08/08/97   0.2.4    Bazsi   Finalized error handling code (Brad's code added)
   08/27/97   0.2.5    Bazsi   BP doesn't like function types as return-values
                               for functions, returning Pointer instead
   09/06/97   0.2.6    Bazsi   Added base error code for Keyboard
   11/06/97   0.2.7    Bazsi   Added base error code for FileCtrl
}