#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void usage(char *prog)
{
  printf("Usage: %s <seconds>[s|m|h|d]\n", prog);
  printf("\tSleep until the given time has elapsed. Unlike the regular\n");
  printf("\t'sleep', do not terminate due to suspending the process.\n\n");
  printf("\tHacked up 2000 by Marcel Waldvogel\n");
  exit(1);
}

int main(int argc, char **argv)
{
  unsigned int seconds;

  if (argc != 2 || argv[1][0] < '0' || argv[1][0] > '9') usage(argv[0]);
  seconds = atoi(argv[1]);
  if (strchr(argv[1], 'm')) {
    seconds *= 60;
  }
  if (strchr(argv[1], 'h')) {
    seconds *= 60*60;
  }
  if (strchr(argv[1], 'd')) {
    seconds *= 60*60*24;
  }

  while (seconds > 0) {
    seconds = sleep(seconds);
  }
  if (seconds < 0) {
    perror("sleep");
  }
  return 0;
}
