~jonathank89/burg/burg-percise

« back to all changes in this revision

Viewing changes to commands/time.c

  • Committer: Bean
  • Date: 2010-06-23 15:25:02 UTC
  • Revision ID: bean123ch@gmail.com-20100623152502-9h370uiaoryb2r3v
New command time, misc fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  BURG - Brand-new Universal loadeR from GRUB
 
3
 *  Copyright 2010 Bean Lee - All Rights Reserved
 
4
 *
 
5
 *  BURG is free software: you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation, either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  BURG is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with BURG.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include <grub/dl.h>
 
20
#include <grub/err.h>
 
21
#include <grub/misc.h>
 
22
#include <grub/datetime.h>
 
23
#include <grub/command.h>
 
24
#include <grub/i18n.h>
 
25
 
 
26
static grub_err_t
 
27
grub_cmd_time (grub_command_t cmd __attribute__ ((unused)),
 
28
               int argc, char **args)
 
29
{
 
30
  struct grub_datetime t1, t2;
 
31
  int delta;
 
32
  grub_err_t err;
 
33
 
 
34
  if (argc < 1)
 
35
    grub_error (GRUB_ERR_BAD_ARGUMENT, "no command");
 
36
 
 
37
  if (grub_get_datetime (&t1))
 
38
    return grub_errno;
 
39
 
 
40
  err = grub_command_execute (args[0], argc - 1, args + 1);
 
41
 
 
42
  if (grub_get_datetime (&t2))
 
43
    return grub_errno;
 
44
 
 
45
  delta = (int) t2.year - (int) t1.year;
 
46
  delta = delta * 365 + (int) t2.day - (int) t1.day;
 
47
  delta = delta * 24 + (int) t2.hour - (int) t1.hour;
 
48
  delta = delta * 60 + (int) t2.minute - (int) t1.minute;
 
49
  delta = delta * 60 + (int) t2.second - (int) t1.second;
 
50
 
 
51
  grub_printf ("%d seconds\n", delta);
 
52
 
 
53
  return err;
 
54
}
 
55
 
 
56
static grub_command_t cmd;
 
57
 
 
58
GRUB_MOD_INIT(time)
 
59
{
 
60
  cmd =
 
61
    grub_register_command ("time", grub_cmd_time,
 
62
                           N_("COMMAND"),
 
63
                           N_("Execute COMMAND and print run time."));
 
64
}
 
65
 
 
66
GRUB_MOD_FINI(time)
 
67
{
 
68
  grub_unregister_command (cmd);
 
69
}