File: clexnum.c

package info (click to toggle)
iraf 2.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,000 kB
  • sloc: ansic: 115,890; fortran: 74,576; lisp: 18,888; yacc: 5,642; sh: 961; lex: 596; makefile: 509; asm: 159; csh: 54; xml: 33; sed: 4
file content (55 lines) | stat: -rw-r--r-- 1,448 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
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/

#include <ctype.h>

#define	import_spp
#define import_libc
#define	import_lexnum
#define	import_xnames
#include <iraf.h>


/* LEXNUM -- Lexically analyze a string to determine if it is a legal IRAF
** style number.  Returns one of the following tokens (lexnum.h):
**
**	LEX_OCTAL		octal number (e.g. B suffix)
**	LEX_HEX			hex number (e.g. X suffix)
**	LEX_DECIMAL		decimal number
**	LEX_REAL		real number (incl sexagesimal)
**	LEX_NONNUM		nonnumeric
**
** A numeric token is returned if any (prefix) portion of the field is
** numeric.  The total number of numeric characters is also returned so
** that the application may verify that the entire field was numeric,
** if desired.
*/
int
c_lexnum (
  char	*str,			/* input string			*/
  int	*toklen			/* nchars in token		*/
)
{
	register char *ip;
	register XCHAR *op, ch, ndigits;
	XCHAR	 numbuf[SZ_FNAME];
	XINT	 ip_start = 1, x_toklen = *toklen;
	int      status;


	/* Convert number to XCHAR for lexnum.  In the process check to see
	 * if we have a simple decimal integer constant to save a scan.
	 */
	for (ip=str, op=numbuf, ndigits=0;  (*op++ = ch = *ip++);  )
	    if (isdigit (ch))
		ndigits++;

	if (ndigits == (ip - str - 1)) {
	    *toklen = ndigits;
	    return (LEX_DECIMAL);
	} else {
	    status = LEXNUM (numbuf, &ip_start, &x_toklen);
	    *toklen = (int) x_toklen;
	    return (status);
	}
}