XINU
Functions
xsh_sleep.c File Reference
#include <xinu.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for xsh_sleep.c:

Go to the source code of this file.

Functions

shellcmd xsh_sleep (int nargs, char *args[])
 

Function Documentation

◆ xsh_sleep()

shellcmd xsh_sleep ( int  nargs,
char *  args[] 
)

Definition at line 11 of file xsh_sleep.c.

References delay(), fprintf(), NULLCH, printf(), sleep(), stderr, and strncmp().

12 {
13  int32 delay; /* Delay in seconds */
14  char *chptr; /* Walks through argument */
15  char ch; /* Next character of argument */
16 
17  /* For argument '--help', emit help about the 'sleep' command */
18 
19  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
20  printf("Use: %s\n\n", args[0]);
21  printf("Description:\n");
22  printf("\tDelay for a specified number of seconds\n");
23  printf("Options:\n");
24  printf("\t--help\t display this help and exit\n");
25  return 0;
26  }
27 
28  /* Check for valid number of arguments */
29 
30  if (nargs > 2) {
31  fprintf(stderr, "%s: too many arguments\n", args[0]);
32  fprintf(stderr, "Try '%s --help' for more information\n",
33  args[0]);
34  return 1;
35  }
36 
37  if (nargs != 2) {
38  fprintf(stderr, "%s: argument in error\n", args[0]);
39  fprintf(stderr, "Try '%s --help' for more information\n",
40  args[0]);
41  return 1;
42  }
43 
44  chptr = args[1];
45  ch = *chptr++;
46  delay = 0;
47  while (ch != NULLCH) {
48  if ( (ch < '0') || (ch > '9') ) {
49  fprintf(stderr, "%s: nondigit in argument\n",
50  args[0]);
51  return 1;
52  }
53  delay = 10*delay + (ch - '0');
54  ch = *chptr++;
55  }
56  sleep(delay);
57  return 0;
58 }
int32 strncmp(const char *, const char *, int32)
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 delay(int n)
マイクロ秒単位で処理を遅らせる。
Definition: initialize.c:262
syscall sleep(int32)
Definition: sleep.c:11
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function: