Browse Source

Modified the console time function to always produce a non-negative and correct value.

MissValeska 10 years ago
parent
commit
e52842f8d8
1 changed files with 38 additions and 4 deletions
  1. 38
    4
      src/Ntk-Console/Netsukuku-Console.c

+ 38
- 4
src/Ntk-Console/Netsukuku-Console.c View File

@@ -155,6 +155,40 @@ void console_uptime(void) {
155 155
     uptime_day1 -= uptime_day;
156 156
     uptime_month1 -= uptime_month;
157 157
     uptime_year1 -= uptime_year;
158
+    /* Checks if the date/time is negative,
159
+     * And makes it positive.
160
+     * e.g -11 is 1 because this is a signed variable
161
+     * at a modulus of 12. Thus after 12, It is -12
162
+     * which is zero, Every number after this is counting up
163
+     * to 12 again, Which is going to be 0 in this instance.
164
+     * -12 to 12 is 24 actual months.
165
+     * So -11 + 12 is 1, As it should be, And -12 + 12 is zero
166
+     * as it should be. The only difference is the modulus number,
167
+     * i.e: 12, 24, etc. */
168
+    if(uptime_month1 < 0)
169
+        uptime_month1 + 12;
170
+    if(uptime_day1 < 0)
171
+        uptime_day1 + 365;
172
+    if(uptime_hour1 < 0)
173
+        uptime_hour1 + 24;
174
+    if(uptime_min1 < 0)
175
+        uptime_min1 + 60;
176
+    if(uptime_sec1 < 0)
177
+        uptime_sec1 + 60;
178
+    /* Checks if the date/time is the modulus, And resets it to zero.
179
+     * e.g: 12 months is a year, Listing 12 months and one year
180
+     * is confusing,
181
+     * And implies that it has been two years. */
182
+    if(uptime_month1 == 12)
183
+        uptime_month1 = 0;
184
+    if(uptime_day1 == 365)
185
+        uptime_day1 = 0;
186
+    if(uptime_hour1 == 24)
187
+        uptime_hour1 = 0;
188
+    if(uptime_min1 == 60)
189
+        uptime_min1 = 0;
190
+    if(uptime_sec1 == 60)
191
+        uptime_sec1 = 0;
158 192
     
159 193
     printf("Total Uptime is: %i Year(s), %i Month(s), %i Day(s), %i Hour(s), %i Minute(s), %i Second(s)\n",uptime_year1, uptime_month1, uptime_day1, uptime_hour1, uptime_min1, uptime_sec1);
160 194
     
@@ -218,11 +252,11 @@ int main(void) {
218 252
     
219 253
     printf("This is the Netsukuku Console, Please type 'help' for more information.\n");
220 254
     
221
-    char * request;
255
+    char request;
222 256
 
223 257
     char request1;
224 258
     
225
-    request = (char *)malloc(BUFFER_LENGTH);
259
+    request = (char)malloc(BUFFER_LENGTH);
226 260
     
227 261
     request1 = (char)malloc(BUFFER_LENGTH);
228 262
     
@@ -230,11 +264,11 @@ int main(void) {
230 264
     
231 265
     printf("\n>");
232 266
         
233
-    fgets(request, 16, stdin);
267
+    fgets(request1, 16, stdin);
234 268
     
235 269
     fflush(stdin);
236 270
     
237
-    request = request1;
271
+    request1 = request;
238 272
     
239 273
     console(request);
240 274
     } while(FALSE);

Loading…
Cancel
Save