| Previous | Up | Next |
|
|
Use this link if you want more information about Open Source project support services. This project's summary page on SourceForge.net. Suggestions on how to improve this project are welcome here. |
Status and Text Reference Coding Programmers' Guide IntroductionThe purpose of this project is to make code maintenance easier. One aspect of code maintenance is reading and checking the code. To that end, this project includes a header and library that makes it easier to read code. The code is the ultimate authority on what the computer will do. As a result, someone, possibly yourself, will need to read the code after it has been written, with the possible (but not probable) exceptions of very small personal projects. One significant problem is that the meaning of return values is not always clear. Usually some kind of expression is need to test the result but the intent of the calculation is usually something less than obvious. The header for this library, and to a much lesser extent the actual code in the library, make it easier to understand your intent if it is used consistently. A second phase of this project, which is not even in the planning stages at this time, will make translating the program's or project's messages, particularly status messages, into other languages easier. Quick ReferenceStatus encodingA common 'C' convention is to return a pointer to a resource or resource
control structure.
Another common convention is to return a negative value when an error occurs
and the normal range of results is positive.
The pointer convention and to lesser extent the negative value convention fail
to provide details about the source or cause of the error.
The 'C' standard calls for a global variable There are two major problems with An alternative design is to pass the address of a pointer or other object to receive the result and return an encoded status value indicating the validity of the operation. This approach is used in VMS and less consistently in Microsoft Windows. It was one of the unifying themes of VMS. (Comments on its use by Microsoft are inappropriate in this context.) Such a design requires the following characteristics:
The type used to contain this information is designated
Types and data structures.Note: The number of integer architectures supported is limited by the ability to test the implementations. Help with this for less common architectures would be very helpful. The
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 | 06 | 05 | 04 | 03 | 02 | 01 | 00 |
| C | Maintainer ID | Facility ID | Context ID | R | |||||||||||||||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 | 06 | 05 | 04 | 03 | 02 | 01 | 00 |
| C | Facility ID | Context ID | R | ||||||||||||
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 | 06 | 05 | 04 | 03 | 02 | 01 | 00 |
| C | implementation defined constant | Count | R | ||||||||||||||||||||||||||||
The purpose of each field is as follows:
signed short int in
bits (16).
The count value extracted by
statusCount.status_t changes.Note that there should not be any need to use the following
_RSE_ constants in normal code.
The main reason for documenting them is so that you can avoid using conflicting
names.
The status_t fields are described by a set of enumerated
or macro defined constants.
In the following description x is one of the words
continue, context, facility,
maintainer, or result.
_RSE_Wx defines the width of the
field.
If the field is missing for a particular architecture, its
value is zero._RSE_Vx indicates the least
significant bit of the field in the
status_t value.
If the field is missing for a particular architecture, this
value should not be used. _RSE_Lx is a value equivalent to(1 << _RSE_Vx).status_t
value or it can divide a masked status_t value to
get the field value.
If the field is missing for a particular architecture, this
value should not be used. _RSE_Mx is a value as a mask to
isolate a particular field in a status_t
value.
The expression(((status) &
_RSE_Mx) / _RSE_Lx)| field | W | V | L | M |
|---|---|---|---|---|
| continue | 1 | 31 | 0x80000000 | 0x80000000 |
| context | 10 | 1 | 0x00000002 | 0x000007FE |
| count | 16 | 1 | 0x00000002 | 0x0001FFFE |
| facility | 5 | 11 | 0x00000800 | 0x0000F800 |
| maintainer | 15 | 16 | 0x00010000 | 0x7FFF0000 |
| msg | 11 | 0 | 0x00000001 | 0x000007FF |
| result | 1 | 0 | 0x00000001 | 0x00000001 |
There are also a number of constants of the form
_RSE_Cy, _RSE_Ry and
_RSE_Sy used, among other things, to convert
macro keyword like parameters to field values.
They are described in more detail in the section on
initialization macros (below).
#include <stdbool.h>#include <stdint.h>#include <status.h>bool canContinue(status_t);canContinue function test the continuation
indicator of the status_t
value for a not done status.canContinue function returns true if the
continuation indicator of the
status_t value
has a not done status and false otherwise.isError,
isSuccess, andstatus_t,
statusDef5,
myStatusDef3,
sysStatusDef3,
statusMessageId,
and mustStop,
isDone,
isFatal,
isOverrun,
isWarning
#include <stdbool.h>#include <stdint.h>#include <status.h>bool isBad(status_t);isBad function test the result indicator
of the status_t value for
an invalid result status.isBad function returns true if the
result indicator of the
status_t value has an
invalid result status and false otherwise.isError,
isFatal,
isOverrun, andstatus_t,
statusDef5,
myStatusDef3,
sysStatusDef3,
statusMessageId,
and isGood,
isDone,
isSuccess,
isWarning, and#include <stdbool.h>#include <stdint.h>#include <status.h>bool isCError(int);isCError function test the int
argument for a negative value which indicates an error.isCError function returns true if the
int value indicates an error and false
otherwise.notCError
#include <stdbool.h>#include <stdint.h>#include <status.h>bool isCount(status_t);isCount function test the
status_t value to see if
it is a valid argument for the
statusCount
function.
status_t values
constructed with either the
statusCountDef2 or
statusCountDef3
macros will have this property.isCount function returns true if the
the status_t value is a
valid argument for the
statusCount function.
statusCount,
statusCountDef2,
statusCountDef3,
status_t
#include <stdbool.h>#include <stdint.h>#include <status.h>bool isDone(status_t);isDone function test the
status_t value for the
done condition.
It is equivalent to the expression(isGood(status_t) &&
mustStop(status_t))status_t argument only
once.
isDone function returns true if the
the status_t condition
indicates done and false otherwise.isWarning,
isGood,
mustStop, andstatus_t,
statusDef4,
myStatusDef2,
sysStatusDef2, and
isError,
isFatal,
isOverrun,
isSuccess
#include <stdbool.h>#include <stdint.h>#include <status.h>bool isError(status_t);isError function test the
status_t value for the
error condition.
It is equivalent to the expression(isBad(status_t) &&
canContinue(status_t))status_t argument only
once.
isError function returns true if the
status_t condition
indicates an error and false otherwise.canContinue,
isBad, andstatus_t,
statusDef4,
myStatusDef2,
sysStatusDef2, and
isDone,
isFatal,
isOverrun,
isSuccess,
isWarning
#include <stdbool.h>#include <stdint.h>#include <status.h>boot isFatal(status_t);isFatal function test the
status_t value for the
sever or fatal error condition.
It should be used in situations where a continuation indication
does not make sense.
It is equivalent to the expression(isBad(status_t) &&
mustStop(status_t))status_t argument only
once.isFatal function returns true if the
status_t condition
indicates a sever or fatal error and false otherwise.isOverrun,
isBad,
mustStop, andstatus_t,
statusDef4,
myStatusDef2,
sysStatusDef2, and
isDone,
isError,
isSuccess,
isWarning
#include <stdbool.h>#include <stdint.h>#include <status.h>bool isGood(status_t);isGood function test the result indicator
of the status_t for a
valid result status.isGood function returns true if the
result indicator of the
status_t value indicates a
valid result status and false otherwise.isDone,
isSuccess,
isWarning, andstatus_t,
statusDef5,
myStatusDef5,
sysStatusDef5,
statusMessageId,
and isBad,
isError,
isFatal,
isOverrun
#include <stddef.h>#include <stdbool.h>#include <stdint.h>#include <status.h>bool isNULL(void *);isNULL function tests its argument's
value for equivalence to the NULL pointer.isNULL function returns true if its
argument's value is equivalent to the NULL pointer and false
otherwise.notNULL#include <stdbool.h>#include <stdint.h>#include <status.h>bool isOverrun(status_t);isOverrun function test the
status_t value for an
overrun error condition.
It is equivalent to the expression(isBad(status_t) &&
mustStop(status_t))status_t argument only
once.isOverrun function returns true if the
status_t condition
indicates an overrun error and false otherwise.isFatal,
isBad,
mustStop, andstatus_t,
statusDef4,
myStatusDef2,
sysStatusDef2,
andisDone,
isError,
isWarning
#include <stdbool.h>#include <stdint.h>#include <status.h>bool isSuccess(status_t);isSuccess function test the
status_t value for the
success condition.
It is equivalent to the expression(isGood(status_t) &&
canContinue(status_t))status_t argument only
once.isSuccess function returns true if the
status_t condition
indicates success and false otherwise.isGood,
canContinue, andstatus_t,
statusDef4,
myStatusDef2,
sysStatusDef2, and
isDone,
isError,
isFatal,
isOverrun,
isWarning
#include <stdbool.h>#include <stdint.h>#include <status.h>bool isWarning(status_t);isWarning function test the
status_t value for the
warning condition.
It should be used in situations where a continuation indication
does not make sense.
It is equivalent to the expression(isGood(status_t) &&
mustStop(status_t))status_t argument only
once.isWarning function returns true if the
status_t condition
indicates warning and false otherwise.isDone,
isGood,
mustStop, andstatus_t,
statusDef4,
myStatusDef2,
sysStatusDef2, and
isError,
isFatal,
isOverrun,
isSuccess
#include <stdbool.h>#include <stdint.h>#include <status.h>bool mustStop(status_t);mustStop function test the continuation
indicator of the
status_t value for a done
status.mustStop function returns true if the
continuation indicator of the
status_t value
indicates a done status and false otherwise.isDone,
isFatal,
isOverrun,
isWarning, andstatus_t,
statusDef5,
myStatusDef3,
sysStatusDef3,
statusMessageId,
andcanContinue,
isError,
isSuccess
#include <stdbool.h>#include <stdint.h>#include <status.h>bool notCError(int);notCError function test the
int value for a positive value which indicates
that the value has its nominal meaning.notCError function returns true if the
int value does not indicates an error and false
otherwise.isCError
#include <stddef.h>#include <stdbool.h>#include <stdint.h>#include <status.h>bool notNULL(void *);notNULL function tests its argument's
value for equivalence to the NULL pointer.notNULL function returns true if its
argument's value is not equivalent to the NULL pointer and
false otherwise.isNULL
#include <stdbool.h>#include <stdint.h>#include <status.h>unsigned int statusContextID(status_t);statusContextID function extracts the value
of the status_t Context ID
field.statusContextID function returns the value
of the status_t Context ID
field.statusMessageId,
andstatus_t,
myStatusDef2,
myStatusDef3,
statusDef4,
statusDef5,
sysStatusDef2,
sysStatusDef3#include <stdbool.h>#include <stdint.h>#include <status.h>short int statusCount(status_t);statusCount function extracts the count
value from a status_t
value constructed using the
statusCountDef2 or
statusCountDef3
macros.
If the function is applied to a
status_t value
for which
isCount returns false,
the result is undefined.statusCount function returns the
value of the last argument passed to the
statusCountDef2 or
statusCountDef3
macro used to construct the
status_t value.
isCount, andstatus_t,
statusCountDef2,
statusCountDef3
#include <stdbool.h>#include <stdint.h>#include <status.h>unsigned int statusFacilityId(status_t);statusFacilityId function extracts the
value of the Facility Id field of the
status_t value.statusFacilityId function returns the
value of the Facility Id field of the
status_t value.status_t,
statusDef2,
statusDef3,
sysStatusDef2,
sysStatusDef3, and
RSE_facility,
myStatusDef2,
myStatusDef3
#include <stdbool.h>#include <stdint.h>#include <status.h>unsigned int statusMaintainerId(status_t);statusMaintainerId function extracts the
value of the Maintainer Id field from the
status_t value.
This function is not implemented on architectures with small
ints.statusMaintainerId function returns the
value of the Maintainer Id field from the
status_t value.status_t,
statusDef2,
statusDef3,
sysStatusDef2,
sysStatusDef3, and
RSE_maintainer,
myStatusDef2,
myStatusDef3
#include <stdbool.h>#include <stdint.h>#include <status.h>unsigned int statusMessageId(status_t);statusMessageId constructs a message
identifier from several fields in the
status_t value.
If this function is implemented as a macro, it may evaluate
its argument more than once.statusMessageId returns the Message Id
constructed from several fields in the
status_t value.statusContextId,
canContinue,
isBad,
isGood,
mustStop, andstatus_t,
statusDef4,
statusDef5,
myStatusDef2,
myStatusDef3,
sysStatusDef2,
sysStatusDef3
The following user defined macros set the values for use by the
myStatusDef3 and
myStatusDef3 macros.
myStatusDef3 and
myStatusDef2
macros.
If not defined, a default value will be set by including the
<status.h> header.status_t,
myStatusDef2,
myStatusDef3,
statusFacilityId
myStatusDef3 and
myStatusDef2
macros.
If not defined, a default value will be set by including the
<status.h> header.status_t,
myStatusDef2,
myStatusDef3,
statusMaintainerId
Initial values for status_t static constants and variables must
be compile-time constant expressions;
they can not be function return values.
The expressions needed are fairly complex and implementation dependent.
To avoid these problems a number of macros are defined in this section.
The return, continuation and combined status indicator coding may change with the platform. Simply passing zero and non-zero values to the macros would not be portable and the meaning of each argument would not be clear. The solution to both these problems is to give these values meaningful names.
Warning
The keyword like arguments used in the following eight (8) macros can not be expressions. Using anything other than the keywords defined below will result in compile or link time errors of some form. The exact form of the error messages may be obscure; they are not under the control of this project.
#include <stdbool.h>#include <stdint.h>#include <status.h>status_t statusDef4({success | warning | error |
fatal | done | overrun}, contextId,
facilityId, maintainerId);statusDef4 macro constructs a
status_t value from all
its components.
{success | warning | error | fatal | done | overrun} is a
keyword like argument specifying the
values of the combined indicators.statusDef4 macro returns the constructed
status_t value.status_t,
myStatusDef2,
sysStatusDef2, and
isDone,
isError,
isFatal,
isOverrun,
isSuccess,
isWarning, and statusDef5,
myStatusDef3,
sysStatusDef3
#include <stdbool.h>#include <stdint.h>#include <status.h>status_t statusDef5({good | bad},
{continue | stop}, contextId,
facilityId, maintainerId);statusDef5 macro constructs a
status_t value from all
its components.
{good | bad} is a keyword like argument
specifying the value of the result indicator.
{continue | stop} is a keyword like
argument specifying
the value of the continuation indicator.statusDef5 macro returns the constructed
status_t value.status_t,
myStatusDef3,
sysStatusDef3, and
canContinue,
isBad,
isGood,
mustStop, and statusDef4,
myStatusDef2,
sysStatusDef2
#include <stdbool.h>#include <stdint.h>#include <status.h>status_t statusCountDef2({success | warning |
error | fatal | done | overrun},
signed short int);
statusCountDef2 macro constructs a
status_t value that can be
used with the
statusCount function
from all its components.
{success | warning | error | fatal | done | overrun} is a
keyword like argument specifying the
values of the combined indicators.
The value of signed short int is the value that
will be extracted by the
statusCount function.
statusCountDef2 macro returns the constructed
status_t value.isCount,
statusCount,
status_t,
statusCountDef3 and
isDone,
isError,
isFatal,
isOverrun,
isSuccess,
isWarning
#include <stdbool.h>#include <stdint.h>#include <status.h>status_t statusCountDef3({good | bad},
{continue | stop}, signed short int);statusCountDef3 macro constructs a
status_t value that can be
used with the
statusCount function
from all its components.
{good | bad} is a keyword like argument
specifying the value of the result indicator.
{continue | stop} is a keyword like
argument specifying the value of the continuation
indicator.
The value of signed short int is the value that
will be extracted by the
statusCount function.
statusCountDef3 macro returns the
constructed status_t
value.isCount,
statusCount,
status_t,
statusCountDef2,
andcanContinue,
isBad,
isGood,
mustStop
#include <stdbool.h>#include <stdint.h>#include <status.h>status_t myStatusDef2({success | warning | error |
fatal | done | overrun},
contextId);myStatusDef2 macro is equivalent tostatusDef4({success | warning | error
| fatal | overrun}, contextId, RSE_facility,
RSE_maintainer).myStatusDef2 macro returns the constructed
status_t value.status_t,
statusDef4,
sysStatusDef2, and
isDone,
isError,
isFatal,
isOverrun,
isSuccess,
isWarning, and statusDef5,
myStatusDef3,
sysStatusDef3
#include <stdbool.h>#include <stdint.h>#include <status.h>myStatusDef3({good | bad},
{continue | stop},
contextId);
myStatusDef3 macro is equivalent tostatusDef5({good | bad},
{continue | stop}, contextId,
RSE_facility, RSE_maintainer).myStatusDef3 macro returns the constructed
status_t value.status_t,
statusDef5,
sysStatusDef3, and
canContinue,
isBad,
isGood,
mustStop, and statusDef5,
myStatusDef3,
sysStatusDef3
#include <stdbool.h>#include <stdint.h>#include <status.h>status_t sysStatusDef2({success | warning | error
| fatal | done | overrun},
contextId);sysStatusDef2 macro is equivalent tostatusDef4({success | warning | error
| fatal | overrun}, contextId, 0, 0).
E... values defined in the
<errno.h> system header.
sysStatusDef2 macro returns the constructed
status_t value.status_t,
statusDef4,
myStatusDef2, and
isDone,
isError,
isFatal,
isOverrun,
isSuccess,
isWarning, and statusDef5,
myStatusDef3,
sysStatusDef3
#include <stdbool.h>#include <stdint.h>#include <status.h>sysStatusDef3({good | bad},
{continue | stop},
contextId);
sysStatusDef3 macro is equivalent tostatusDef5({good | bad},
{continue | stop}, contextId, 0,
0).E... values defined in the
<errno.h> system header.
sysStatusDef3 macro returns the constructed
status_t value.status_t,
statusDef5,
myStatusDef3, and
canContinue,
isBad,
isGood,
mustStop, and statusDef5,
myStatusDef3,
sysStatusDef3
All the 'Def' macros that are used to construct
status_t values take one or two
'keyword like arguments' to specify the state of indicators.
These arguments can not be expressions.
A preprocessor trick is used to associate the words with the values
the indicators are to be set to.
(See the Implementation guide for
details.)
If you must use an expression to select different
status_t values, select between
complete status_t, not keyword like arguments.
In addition to the complete keywords, a number of abbreviations have also been defined:
|
|
|
These words are the 'y's used to construct the
_RSE_Cy, _RSE_Sy and _RSE_Ry
internal constants mentioned in the section on the fields of
status_t values.
Note that these keywords are not reserved; they can be used for other purposes in your code if you want to do so.
The ContextIds and MessageIds used in
status_t values are a global resource that
will be needed in several places in a project.
As with any such global set of definitions it will be difficult to keep track
of all the places the definitions have to be changed unless their values are
defined in only one place,
like in a project level header file similar to the system header
<errno.h>.
The total number of different messages or contexts that a
status_t value can designate is quite large (>109)
but any one project will need only a modest number.
This preliminary implementation allocates a few thousand messages or contexts
to each project.
Simple division shows that about a million projects could be handled by this
implementation.
The facility and maintainer Id fields should combine to uniquely designate the project. However the mapping of this number to the actual project is not a simple problem.
For active groups with multiple projects it makes sense to have the group designate at least part of the mapping. That is why there are separate facility and maintainer fields; the facility Id is nominally designated by the maintainer. Not all groups will have multiple projects and it would be wasteful to give a small group a large, multi-facility, message space if they are only going to use a tiny fraction of it. For these reasons the split between maintainer and facility fields should be considered experimental.
Also note that a large project may need more than the few thousand messages or contexts allocated by this scheme. This should be rare (>85% of all projects should need less than the preallocated number) that a project will overflow one allocation but there will be some that need more. This needs to be taken into account as well when allocating project identifiers.
All the above, while important considerations, do not actually specify how project numbers are to be assigned. Some assignments are required:
EXIT_SUCCESS,
EXIT_FAILURE and EOF must be reserved to the
'C' run time and kernel.The rest of the assignments will be arbitrary with some authority (or possibly a small set of coordinated authorities) specifying the mapping. There are a number of authorities already in existence that perform similar services in different contexts. They are commercial enterprises and charge fees for each assignment and, as a result, are less than ideal for implementing this function. Further, a project is probably not a good candidate for such an authority since failing to maintain the project would make the assignments unusable. That suggests that the Open Source hosting facilities as a group may be the appropriate authorities to perform this task.
Work List:
| Previous | Up | Next |
|
|