Rev 9763 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9763 | vitalkrilo | 1 | #include "func.h" |
9778 | vitalkrilo | 2 | #include |
9763 | vitalkrilo | 3 | |
4 | char debuf[50] = ""; |
||
5 | |||
6 | double textwidth(const char* s, int len) { |
||
7 | int i; |
||
8 | for (i = 0; i < len; i++) |
||
9 | if (s[i] == 0) |
||
10 | break; |
||
11 | return i * 6; |
||
12 | } |
||
13 | |||
14 | double textheight(const char* s, int len) { |
||
15 | return 8.0; |
||
16 | } |
||
17 | |||
18 | int isalpha(char c) { |
||
19 | return (c==' ' || c=='\n' || c=='\t' || c=='\r'); |
||
20 | } |
||
21 | |||
22 | // эта функция - велосипед. но проще было написать чем найти. |
||
23 | double convert(const char* s, int* len) { |
||
24 | int i; |
||
25 | double sign, res, tail, div; |
||
26 | res = 0.0; |
||
27 | i = 0; |
||
28 | while (s[i] && isalpha(s[i])) i++; |
||
29 | if (len) *len=i; |
||
30 | if (s[i] == '\0') |
||
31 | return ERROR_END; |
||
32 | |||
33 | sign=1.0; |
||
34 | if (s[i] == '-') { |
||
35 | sign=-1.0; |
||
36 | i++; |
||
37 | } |
||
38 | while (s[i] && s[i] >= '0' && s[i] <= '9') { |
||
39 | res *= 10.0; |
||
40 | res += s[i] - '0'; |
||
41 | i++; |
||
42 | } |
||
43 | if (len) *len=i; |
||
44 | if (!s[i] || isalpha(s[i])) |
||
45 | return sign*res; |
||
46 | if (s[i] != '.' && s[i] != ',') |
||
47 | return ERROR; |
||
48 | i++; |
||
49 | if (len) *len=i; |
||
50 | if (!s[i]) |
||
51 | return sign*res; |
||
52 | |||
53 | div = 1.0; |
||
54 | tail = 0.0; |
||
55 | while (s[i] && s[i] >= '0' && s[i] <= '9') { |
||
56 | tail *= 10.0; |
||
57 | tail += s[i] - '0'; |
||
58 | div *= 10.0; |
||
59 | i++; |
||
60 | } |
||
61 | res += tail/div; |
||
62 | if (len) *len=i; |
||
63 | return sign*res; |
||
9778 | vitalkrilo | 64 | } |
65 | |||
66 | int isequal(double a, double b) { |
||
67 | return fabs(a-b) < EQUALITY_VAL; |
||
9763 | vitalkrilo | 68 | }>=>=>> |