sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 474ee643edc05791771b9bf0308295b39da784e2
parent 8e26716a5a33fc4a7c6f5f0a72356523a8ca9119
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Mon, 23 May 2011 19:00:31 +0100

add sleep & date, thanks kamil
Diffstat:
MLICENSE | 1+
MMakefile | 2+-
Mcat.1 | 2+-
Mconfig.mk | 4++--
Adate.1 | 20++++++++++++++++++++
Adate.c | 32++++++++++++++++++++++++++++++++
Asleep.1 | 9+++++++++
Asleep.c | 18++++++++++++++++++
Mtouch.c | 1-
9 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -1,6 +1,7 @@ MIT/X Consortium License © 2011 Connor Lane Smith <cls@lubutu.com> +© 2011 Kamil Cholewiński <harry666t@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ include config.mk -SRC = basename.c cat.c echo.c false.c grep.c tee.c touch.c true.c wc.c +SRC = basename.c cat.c date.c echo.c false.c grep.c sleep.c tee.c touch.c true.c wc.c OBJ = $(SRC:.c=.o) util.o BIN = $(SRC:.c=) MAN = $(SRC:.c=.1) diff --git a/cat.1 b/cat.1 @@ -3,7 +3,7 @@ cat \- concatenate files .SH SYNOPSIS .B cat -.RI [ files ...] +.RI [ file ...] .SH DESCRIPTION .B cat reads each file in sequence and writes it to stdout. If no file is given, cat diff --git a/config.mk b/config.mk @@ -1,8 +1,8 @@ # sbase version VERSION = 0.0 -CC = cc -#CC = musl-gcc +#CC = cc +CC = musl-gcc CPPFLAGS = -D_BSD_SOURCE CFLAGS = -Os -ansi -Wall -pedantic $(CPPFLAGS) diff --git a/date.1 b/date.1 @@ -0,0 +1,20 @@ +.TH DATE 1 sbase\-VERSION +.SH NAME +date \- print date and time +.SH SYNOPSIS +.B date +.RB [ \-d +.IR time ] +.RI [+ format ] +.SH DESCRIPTION +.B date +prints the date and time. If a +.I format +is given it is used to format the date as per +.BR strftime (3). +.SH OPTIONS +.TP +.BI \-d " time" +prints +.I time +instead of the system time, given as the number of seconds since the Unix epoch. diff --git a/date.c b/date.c @@ -0,0 +1,32 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include "util.h" + +int +main(int argc, char *argv[]) +{ + char buf[BUFSIZ]; + char *fmt = "%c"; + int i; + struct tm *now = NULL; + time_t t; + + t = time(NULL); + for(i = 1; i < argc; i++) + if(!strncmp("+", argv[i], 1)) + fmt = &argv[i][1]; + else if(!strcmp("-d", argv[i]) && i+1 < argc) + t = strtol(argv[++i], NULL, 0); + else + eprintf("usage: %s [-d time] [+format]\n", argv[0]); + now = localtime(&t); + if(!now) + eprintf("localtime failed\n"); + + strftime(buf, sizeof buf, fmt, now); + puts(buf); + return EXIT_SUCCESS; +} diff --git a/sleep.1 b/sleep.1 @@ -0,0 +1,9 @@ +.TH SLEEP 1 sbase\-VERSION +.SH NAME +sleep \- wait for a number of seconds +.SH SYNOPSIS +.B sleep +.I seconds +.SH DESCRIPTION +.B sleep +waits until the given number of seconds have elapsed. diff --git a/sleep.c b/sleep.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdlib.h> +#include <unistd.h> +#include "util.h" + +int +main(int argc, char *argv[]) +{ + unsigned int seconds; + + if(argc != 2) + eprintf("usage: %s seconds\n", argv[0]); + + seconds = atoi(argv[1]); + while((seconds = sleep(seconds)) > 0) + ; + return EXIT_SUCCESS; +} diff --git a/touch.c b/touch.c @@ -21,7 +21,6 @@ main(int argc, char *argv[]) int i; t = time(NULL); - for(i = 1; i < argc; i++) if(!strcmp(argv[i], "-c")) cflag = true;