summaryrefslogtreecommitdiff
path: root/Build/source/texk/seetexk/strtol.c
blob: 5cb6662fbb6ec9edd6cd08c3a427b6d6f618f094 (plain)
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
#include <stdio.h>
#include <ctype.h>

/*
 * This is for people who don't have strtol defined on their systems.
 * -- Compliments of Daniel.Stodolsky@cs.cmu.edu
 */

long strtol(nptr,base,eptr)
char *nptr;
int base;
char **eptr;
{
  long l;
  
  if (base==10)
    {
      if (sscanf(nptr,"%ld",&l)!=1)
	{
	  *eptr = nptr;
	  return 0;
	}
      else
	{
	  while(!isdigit(*nptr))
	    nptr++;
	  while (isdigit(*nptr))
	    nptr++;
	  *eptr = nptr;
	  return l;
	}
    }
  else
    if (base==16)
      {
	if (sscanf(nptr,"%lx",&l)!=1)
	{
	  *eptr = nptr;
	  return 0;
	}
      else
	{
	  while(!isxdigit(*nptr))
	    nptr++;
	  while (isxdigit(*nptr))
	    nptr++;
	  *eptr = nptr;
	  return l;
	}
      }
    else
      { /* a base we don't understand. Puke */
	*eptr = nptr;
	return 0;
      }
}