source: git/ntl/src/tools.c @ 6ce030f

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