ArgLook - Look at the contents of a string

Function

Look at the contents of a string and determined if it can be represented as a number.

Description

A common requirement in user interfaces is to convert a string containing a number to the machine representation of that number. This routine determines if this is possible and if so, what type the string can be converted to.

1.
If the string has the format - [+-]nnn, where nnn means any number of decimal digits, this routine beleives it can be be represented as an integer.

2.
If the string has the format - [+-]nnn[.nnn][{e|E}[+/-]nnn], where nnn means nay number of decimal digites, this routine beleives it can be represented as a real.

The actual ability to represent the number in a given machine type is dependent on the size of the number.

If MinFlag is flase and the string has the format of 1, then DstType is set to SDS_INT, except if USFlag is set true, In which case DstType is set to SDS_UINT (unless the number is negative).

If MinFlag is false and the string has the format of 2, then DstType is set to SDS_DOUBLE.

If MinFlag is true, then the routine attempts to determine the smallest size of the required type which can be used to represent the number. If base type (INT or REAL) is determined as per when MinFlag is false. The system then tries to convert the value to a number of that type using ArgCvt. If this is successfull, then it looks at the resulting values and determines the smallest type which can be used to represet the number.

If the string is not a valid number (or when MinFlag is true, cannot be represented in the largest type) then DstType is set to ARG_STRING.

Any precedding white space in the string is ignored, but trailing white space is not allowed.

Language

C

Call

(Void) = ArgLook (SrcAddr, USFlag, MinFlag, DstType , status)

Parameters

(">" input, "!" modified, "W" workspace, "<" output)

>SrcAddrchar *Address of the source data.
>USFlagintIf true, integers are unsigned unless they include a minus sign. If false, integers are always signed.
>MinFlagintIf true, then find the smallest type of the appropiate class which can represent this time. E.g., use float instead of double if possible. This is a more expensive operation as ArgLook must invoke ArgCvt to do a conversion in order to determine this.
<DstTypeSdsCodeType *Type of the destination.
!statusLong int *Modified status.

Include files

Arg.h

External functions used

ErsPushErs Increment error context.
ErsPopErs Decrement error context.
ErsAnnulErs Annull error messages.
ArgCvtArg Convert a value from one type to another.
isspaceCRTL Is a character a which space character.
isdigitCRTL Is a character a digit.

External values used

none

Prior requirements

none

Support

Tony Farrell, AAO

Click here for the DRAMA home page and here for the AAO home page.

 For more information, contact tony.farrell@mq.edu.au