source: git/ntl/src/tools.c @ de6a29

spielwiese
Last change on this file since de6a29 was de6a29, checked in by Hans Schönemann <hannes@…>, 19 years ago
* hannes: NTL-5.4 git-svn-id: file:///usr/local/Singular/svn/trunk@8693 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.0 KB
Line 
1
2#include <NTL/tools.h>
3
4#include <ctype.h>
5
6#include <stdio.h>
7
8#include <NTL/new.h>
9
10NTL_START_IMPL
11
12
13void Error(const char *s)
14{
15   printf("%s\n", s );
16   abort();
17}
18
19
20// The following implementation of CharToIntVal is completely portable.
21
22long CharToIntVal(long a)
23{
24   switch (a) {
25      case '0': return 0;
26      case '1': return 1;
27      case '2': return 2;
28      case '3': return 3;
29      case '4': return 4;
30      case '5': return 5;
31      case '6': return 6;
32      case '7': return 7;
33      case '8': return 8;
34      case '9': return 9;
35
36      case 'A': return 10;
37      case 'B': return 11;
38      case 'C': return 12;
39      case 'D': return 13;
40      case 'E': return 14;
41      case 'F': return 15;
42
43      case 'a': return 10;
44      case 'b': return 11;
45      case 'c': return 12;
46      case 'd': return 13;
47      case 'e': return 14;
48      case 'f': return 15;
49
50      default:  return -1;
51   }
52}
53
54// The following implementation of IntValToChar is completely portable.
55
56char IntValToChar(long a)
57{
58   switch (a) {
59      case 0: return '0';
60      case 1: return '1';
61      case 2: return '2';
62      case 3: return '3';
63      case 4: return '4';
64      case 5: return '5';
65      case 6: return '6';
66      case 7: return '7';
67      case 8: return '8';
68      case 9: return '9';
69
70      case 10: return 'a';
71      case 11: return 'b';
72      case 12: return 'c';
73      case 13: return 'd';
74      case 14: return 'e';
75      case 15: return 'f';
76
77      default: Error("IntValToChar: bad arg");
78   }
79
80   return 0;  // to supress warnings
81}
82
83
84long IsWhiteSpace(long a)
85{
86   if (a > NTL_MAX_INT || a < NTL_MIN_INT)
87      return 0;
88
89   int b = (int) a;
90
91   if (isspace(b))
92      return 1;
93   else 
94      return 0;
95}
96
97void PrintTime(double t)
98{
99   long hh, mm, ss;
100
101   ss = long(t + 0.5);
102
103   hh = ss/3600;
104   ss = ss - hh*3600;
105   mm = ss/60;
106   ss = ss - mm*60;
107
108   if (hh > 0)
109      printf("%d:",hh);
110
111   if (hh > 0 || mm > 0) {
112      if (hh > 0 && mm < 10) printf("0");
113      printf("%d:",mm);
114   }
115
116   if ((hh > 0 || mm > 0) && ss < 10) printf("0");
117   printf("%d:",ss);
118}
119
120NTL_END_IMPL
Note: See TracBrowser for help on using the repository browser.