summaryrefslogtreecommitdiff
path: root/support/word2x/num_unit_probe.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/word2x/num_unit_probe.c
Initial commit
Diffstat (limited to 'support/word2x/num_unit_probe.c')
-rw-r--r--support/word2x/num_unit_probe.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/support/word2x/num_unit_probe.c b/support/word2x/num_unit_probe.c
new file mode 100644
index 0000000000..d1016fb43a
--- /dev/null
+++ b/support/word2x/num_unit_probe.c
@@ -0,0 +1,67 @@
+/* $Id: num_unit_probe.c,v 1.1 1997/04/22 20:32:17 dps Exp $ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif /* HAVE_STRING_H */
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif /* HAVE_STRINGS_H */
+#ifdef HAVE_CTYPE_H
+#include <ctype.h>
+#endif /* HAVE_CTYPE_H */
+#define __EXCLUDE_READER_CLASSES
+#include "lib.h"
+
+struct unit_number n_unit_probe(const char *txt, struct unit_info *dp)
+{
+ int i,j,n,c,l,unit;
+ struct unit_number u_num;
+
+ u_num.unit_num=-1;
+ unit=dp->unit_type-1;
+ l=strlen(txt);
+ i=0;
+ while(1)
+ {
+ n=0;
+ for (c=0; i<l && isdigit(txt[i]); i++, c++)
+ n=n*10+txt[i]-'0';
+ if (c==0)
+ break;
+ unit++;
+ if (unit>=NUNITS)
+ {
+ unit=NUNITS-1;
+ break;
+ }
+ if (dp->unit_number[unit]==-1)
+ {
+ if (n>MAX_START_NUM)
+ return u_num;
+
+ dp->unit_number[unit]=n;
+ for (j=unit+1; j<NUNITS; j++)
+ dp->unit_number[j]=0;
+ }
+ else if (dp->unit_number[unit]+1==n)
+ {
+ dp->unit_number[unit]++;
+ for (j=unit+1; j<NUNITS; j++)
+ dp->unit_number[j]=0;
+ }
+ else if (dp->unit_number[unit]!=n)
+ return u_num;
+
+ if (txt[i]!='.')
+ break;
+ i++;
+ }
+
+ if (unit==dp->unit_type-1)
+ return u_num;
+ u_num.unit_num=unit;
+ u_num.offset=i;
+ return u_num;
+}