XINU
xsh_date.c
Go to the documentation of this file.
1 /* xsh_date.c - xsh_date */
2 
3 #include <xinu.h>
4 #include <string.h>
5 #include <stdio.h>
6 
7 /*------------------------------------------------------------------------
8  * xsh_date - obtain and print the current month, day, year, and time
9  *------------------------------------------------------------------------
10  */
11 shellcmd xsh_date(int nargs, char *args[]) {
12 
13  int32 retval; /* return value */
14  uint32 now; /* current local time */
15  char datestr[64]; /* printable date in ascii */
16 
17  /* Output info for '--help' argument */
18 
19  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
20  printf("Usage: %s\n\n", args[0]);
21  printf("Description:\n");
22  printf("\tDisplays the current date and time\n");
23  printf("Options (one per invocation):\n");
24  printf("\t-f\tforce a time server request to be sent\n");
25  printf("\t-d\tset daylight savings time on\n");
26  printf("\t-s\tset standard time (not daylight savings)\n");
27  printf("\t-a\tset daylight savings to automatic\n");
28  printf("\t--help\tdisplay this help and exit\n");
29  return 0;
30  }
31 
32  /* Check argument count */
33 
34  if (nargs > 2) {
35  fprintf(stderr, "%s: too many arguments\n", args[0]);
36  fprintf(stderr, "Try '%s --help' for more information\n",
37  args[0]);
38  return 1;
39  }
40 
41  if (nargs == 2) {
42  if (strncmp(args[1], "-f", 3) == 0) {
44  } else if (strncmp(args[1], "-d", 3) == 0) {
46  } else if (strncmp(args[1], "-s", 3) == 0) {
48  } else if (strncmp(args[1], "-a", 3) == 0) {
50  } else {
51  fprintf(stderr, "%s: invalid argument\n", args[0]);
53  "Try '%s --help' for more information\n",
54  args[0]);
55  return 1;
56  }
57  }
58 
59  retval = gettime(&now);
60  if (retval == SYSERR) {
62  "%s: could not obtain the current date\n",
63  args[0]);
64  return 1;
65  }
66  ascdate(now, datestr);
67  printf("%s\n", datestr);
68  return 0;
69 }
int32 strncmp(const char *, const char *, int32)
bool8 dt_bootvalid
Definition: date.h:30
全てのシステムヘッダファイルをインクルードする。
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
shellcmd xsh_date(int nargs, char *args[])
Definition: xsh_date.c:11
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define DATE_DST_OFF
Definition: date.h:20
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
struct dateinfo Date
Definition: ascdate.c:6
int32 shellcmd
シェルコール関数 返り値の型
Definition: kernel.h:51
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
#define DATE_DST_AUTO
Definition: date.h:22
status ascdate(uint32, char *)
Definition: ascdate.c:16
#define DATE_DST_ON
Definition: date.h:21
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
int32 dt_daylight
Definition: date.h:31
status gettime(uint32 *)
1970年1月1日からの経過時間(秒単位)にロケーション(時差)を反映した時間を返す。
Definition: gettime.c:13