source: buchla-68k/orig/GP/GETINT.C

Last change on this file was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 1.1 KB
Line 
1/*
2 =============================================================================
3 getint.c -- convert a string to a 16 bit integer
4 Version 2 -- 1988-09-21 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "ctype.h"
9#include "stddefs.h"
10
11extern long atol();
12
13/*
14 =============================================================================
15 get_int(str, ap) -- convert 'str' to a 16 bit integer at 'ap'
16 =============================================================================
17*/
18
19int
20get_int(str, ap)
21register char *str;
22int *ap;
23{
24 register int i, sign, c;
25 long arg;
26 char *s;
27
28 s = str;
29
30 while (*str EQ ' ')
31 ++str;
32
33 while ('\0' NE (c = 0x00FF & *str++)) {
34
35 if (c EQ '+') {
36
37 if (++sign > 1)
38 return(FAILURE);
39
40 } else if (c EQ '-') {
41
42 if (++sign > 1)
43 return(FAILURE);
44
45 } else {
46
47 if (NOT isascii(c))
48 return(FAILURE);
49
50 if (NOT isdigit(c))
51 return(FAILURE);
52 }
53 }
54
55 if ((arg = atol(s)) > 65535L)
56 return(FAILURE);
57
58 *ap = arg;
59
60 return(SUCCESS);
61}
Note: See TracBrowser for help on using the repository browser.