root/trunk/txlib/txstrnum.c

Revision 1, 4.4 kB (checked in by jvw, 3 years ago)

Initial check-in for TxWin? version 1.02 sources

Line 
1//
2//                     TxWin, Textmode Windowing Library
3//
4//   Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk
5//
6// ==========================================================================
7//
8// This file contains Original Code and/or Modifications of Original Code as
9// defined in and that are subject to the GNU Lesser General Public License.
10// You may not use this file except in compliance with the License.
11// BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE.
12// A copy of the License is provided with the Original Code and Modifications,
13// and is also available at http://www.dfsee.com/txwin/lgpl.htm
14//
15// This library is free software; you can redistribute it and/or modify
16// it under the terms of the GNU Lesser General Public License as published
17// by the Free Software Foundation; either version 2.1 of the License,
18// or (at your option) any later version.
19//
20// This library is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23// See the GNU Lesser General Public License for more details.
24//
25// You should have received a copy of the GNU Lesser General Public License
26// along with this library; (lgpl.htm) if not, write to the Free Software
27// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28//
29// Questions on TxWin licensing can be directed to: txwin@fsys.nl
30//
31// ==========================================================================
32//
33// TX string number handling functions
34//
35// Author: J. van Wijk
36//
37// JvW  24-07-2005 Initial version, split off from TXUTIL
38
39#include <txlib.h>
40
41
42/*****************************************************************************/
43// Test if string represents a valid hex number, allow 0x prefix and ,unit
44/*****************************************************************************/
45BOOL txIsValidHex                               // RET   string is valid hex
46(
47   char               *num                      // IN    candidate string
48)
49{
50   BOOL                rc = TRUE;               // function return
51   char               *= num;
52
53   if (strnicmp( s, "0x", 2) == 0)
54   {
55      s += 2;
56   }
57   while ((*s) && (*s != ','))                  // until end or unit separator
58   {
59      if (isxdigit(*s))
60      {
61         s++;
62      }
63      else
64      {
65         rc = FALSE;
66         break;
67      }
68   }
69   return (rc);
70}                                               // end 'txIsValidHex'
71/*---------------------------------------------------------------------------*/
72
73
74/*****************************************************************************/
75// Test if string represents a valid decimal nr, allow 0t/0n prefix and ,unit
76/*****************************************************************************/
77BOOL txIsValidDec                               // RET   string is not decimal
78(
79   char               *num                      // IN    candidate string
80)
81{
82   BOOL                rc = TRUE;               // function return
83   char               *= num;
84
85   if ((strnicmp( s, "0t", 2) == 0) ||
86       (strnicmp( s, "0n", 2) == 0)  )
87   {
88      s += 2;
89   }
90   while ((*s) && (*s != ','))                  // until end or unit separator
91   {
92      if (isdigit(*s))
93      {
94         s++;
95      }
96      else
97      {
98         rc = FALSE;
99         break;
100      }
101   }
102   return (rc);
103}                                               // end 'txIsValidDec'
104/*---------------------------------------------------------------------------*/
105
106
107/*****************************************************************************/
108// Test if string starts with a valid MCS prefix 0x 0n 0t 0x (case insensitive)
109/*****************************************************************************/
110BOOL txHasMcsPrefix                             // RET   string has MCS prefix
111(
112   char               *num                      // IN    candidate string
113)
114{
115   BOOL                rc = FALSE;              // function return
116
117   ENTER();
118   TRACES(("num string: '%s'\n", num));
119
120   if (num[0] == '0')
121   {
122      if (strchr("NnOoTtXx", num[1]) != NULL)
123      {
124         rc = TRUE;
125      }
126   }
127   BRETURN (rc);
128}                                               // end 'txHasMcsPrefix'
129/*---------------------------------------------------------------------------*/
Note: See TracBrowser for help on using the browser.