Rev 1085 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * (see the web pages for full authors list) |
||
13 | * |
||
14 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
15 | * |
||
16 | * http://www.sssup.it |
||
17 | * http://retis.sssup.it |
||
18 | * http://shark.sssup.it |
||
19 | */ |
||
20 | |||
21 | |||
22 | /** |
||
23 | ------------ |
||
24 | CVS : $Id: utils.c,v 1.1.1.1 2002-09-02 09:37:42 pj Exp $ |
||
25 | |||
26 | File: $File$ |
||
27 | Revision: $Revision: 1.1.1.1 $ |
||
28 | Last update: $Date: 2002-09-02 09:37:42 $ |
||
29 | ------------ |
||
30 | **/ |
||
31 | |||
32 | /* |
||
33 | * Copyright (C) 2000 Marco Dallera and Marco Fiocca |
||
34 | * |
||
35 | * This program is free software; you can redistribute it and/or modify |
||
36 | * it under the terms of the GNU General Public License as published by |
||
37 | * the Free Software Foundation; either version 2 of the License, or |
||
38 | * (at your option) any later version. |
||
39 | * |
||
40 | * This program is distributed in the hope that it will be useful, |
||
41 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
42 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
43 | * GNU General Public License for more details. |
||
44 | * |
||
45 | * You should have received a copy of the GNU General Public License |
||
46 | * along with this program; if not, write to the Free Software |
||
47 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
48 | * |
||
49 | */ |
||
50 | |||
51 | /* |
||
52 | * AUTO |
||
53 | * |
||
54 | * Another Unuseful Track simulatOr |
||
55 | * |
||
56 | * Authors: Marco Dallera |
||
57 | * Marco Fiocca |
||
58 | * |
||
59 | */ |
||
60 | |||
61 | #include "include/auto.h" |
||
62 | #include "include/utils.h" |
||
63 | #include <string.h> |
||
64 | #include <stdlib.h> |
||
65 | |||
66 | float rand_01() |
||
67 | { |
||
68 | return (((float)(rand()%20) / 100.0) + 0.8); |
||
69 | } |
||
70 | |||
71 | int rand_color() |
||
72 | { |
||
73 | return (rand()%16); |
||
74 | } |
||
75 | |||
76 | int round(float value) |
||
77 | { |
||
78 | return ((int)(value + 0.5)); |
||
79 | } |
||
80 | |||
81 | void reverse(char s[]) { |
||
82 | int c, i, j; |
||
83 | |||
84 | for (i = 0, j = strlen(s)-1; i<j; i++, j--) { |
||
85 | c = s[i]; |
||
86 | s[i] = s[j]; |
||
87 | s[j] = c; |
||
88 | } |
||
89 | } |
||
90 | |||
91 | char * itoa(int n, char *s) { |
||
92 | int i, sign; |
||
93 | |||
94 | if ((sign = n) < 0) |
||
95 | n = -n; |
||
96 | i = 0; |
||
97 | |||
98 | do { |
||
99 | s[i++] = n % 10 + '0'; |
||
100 | } while ((n /= 10) > 0); |
||
101 | |||
102 | if (sign < 0) |
||
103 | s[i++] = '-'; |
||
104 | s[i] = 0; |
||
105 | |||
106 | reverse(s); |
||
107 | |||
108 | return s; |
||
109 | } |
||
110 | |||
111 | time int2time(int t) |
||
112 | { |
||
113 | time ts; |
||
114 | |||
115 | ts.dec = t % 10; |
||
116 | ts.sec = (t/10) % 60; |
||
117 | ts.min = (int)(t / 600); |
||
118 | |||
119 | return ts; |
||
120 | } |
||
121 | |||
122 | |||
123 | |||
124 | |||
125 | |||
126 | |||
127 | |||
128 | |||
129 | |||
130 | |||
131 |