bday

changeset 3:dc2f94280b01

new Makefile; removed MinWarn and MaxWarn; adjusted manpage
author meillo@marmaro.de
date Mon, 17 Dec 2007 11:28:40 +0100
parents 9ec037775c38
children 5326c222cd4e
files Makefile bday.1 bdengine.c birthday.c birthday.h
diffstat 5 files changed, 75 insertions(+), 70 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Mon Dec 17 08:02:15 2007 +0100
     1.2 +++ b/Makefile	Mon Dec 17 11:28:40 2007 +0100
     1.3 @@ -1,34 +1,80 @@
     1.4 -######################################################################
     1.5 -# birthday. Reminder of birthdays and other events in the near future.
     1.6 -# $Id: Makefile.in,v 1.3 2000/01/02 19:17:33 andy Exp $
     1.7 +# bday by meillo@marmaro.de
     1.8  
     1.9  
    1.10 +NAME=bday
    1.11 +VERSION = 0.1
    1.12 +NV=${NAME}-${VERSION}
    1.13 +
    1.14 +DOCS=COPYRIGHT ChangeLog TODO
    1.15 +
    1.16 +# paths
    1.17 +PREFIX = /usr
    1.18 +BINDIR = ${PREFIX}/bin
    1.19 +MANDIR = ${PREFIX}/share/man
    1.20 +
    1.21 +SRC=birthday.c bdengine.c
    1.22 +OBJ=$(SRC:.c=.o)
    1.23 +
    1.24  CFLAGS=-O2 -Wall -Wstrict-prototypes
    1.25  
    1.26 +all:
    1.27 +	@echo usage: make [un]install
    1.28  
    1.29 -SRC=birthday.c bdengine.c
    1.30 -OBJ=$(SRC:.c=.o)
    1.31 -EXE=bday
    1.32 +build: ${NAME}
    1.33  
    1.34 -all: ${EXE}
    1.35 -
    1.36 -${EXE}: $(OBJ)
    1.37 +${NAME}: $(OBJ)
    1.38  	$(CC) $(LDFLAGS) $(OBJ) -o $@
    1.39  
    1.40 +dist: build changelog
    1.41 +	@mkdir -p ${NV}
    1.42 +	@cp -f ${NAME} ${NAME}.1 Makefile ${DOCS} ${NV}
    1.43 +	@tar -czhof ${NV}.tar.gz ${NV}
    1.44 +	@rm -rf ${NV}
    1.45  
    1.46 -install: all
    1.47 -	@echo "installing program in $(DESTDIR)/usr/bin"
    1.48 -	mkdir -p $(DESTDIR)/usr/bin
    1.49 -	cp ${EXE} $(DESTDIR)/usr/bin/${EXE}
    1.50 -	chmod 0755 $(DESTDIR)/usr/bin/${EXE}
    1.51 -	@echo "installing manpage in $(DESTDIR)/usr/share/man/man1"
    1.52 -	mkdir -p $(DESTDIR)/usr/share/man/man1
    1.53 -	cp ${EXE}.1 $(DESTDIR)/usr/share/man/man1/${EXE}.1
    1.54 -	chmod 0644 $(DESTDIR)/usr/share/man/man1/${EXE}.1
    1.55 +deb: dist
    1.56 +	@mkdir -p Packages
    1.57 +	@cp ${NV}.tar.gz Packages/
    1.58 +	@( \
    1.59 +		cd Packages/ ;\
    1.60 +		tar -xzf ${NV}.tar.gz ;\
    1.61 +		mv ${NV}.tar.gz ${NAME}_${VERSION}.orig.tar.gz ;\
    1.62 +		cd ${NV}/ ;\
    1.63 +		cp -r ../../debian/ . ;\
    1.64 +		debuild ;\
    1.65 +	 )
    1.66 +
    1.67 +changelog:
    1.68 +	@echo generating changelog from mercurial log
    1.69 +	@hg log -v --style changelog > ChangeLog
    1.70 +
    1.71 +install:
    1.72 +	@echo installing executable file to ${DESTDIR}${BINDIR}
    1.73 +	@mkdir -p ${DESTDIR}${BINDIR}
    1.74 +	@cp ${NAME} ${DESTDIR}${BINDIR}
    1.75 +	@chmod 755 ${DESTDIR}${BINDIR}/${NAME}
    1.76 +	@echo installing manual page to ${DESTDIR}${MANDIR}/man1
    1.77 +	@mkdir -p ${DESTDIR}${MANDIR}/man1
    1.78 +	@sed 's/VERSION/${VERSION}/g' < ${NAME}.1 > ${DESTDIR}${MANDIR}/man1/${NAME}.1
    1.79 +	@chmod 644 ${DESTDIR}${MANDIR}/man1/${NAME}.1
    1.80 +
    1.81 +uninstall:
    1.82 +	@echo removing executable file from ${DESTDIR}${BINDIR}
    1.83 +	@rm -f ${DESTDIR}${BINDIR}/${NAME}
    1.84 +	@echo removing manual page from ${DESTDIR}${MANDIR}/man1
    1.85 +	@rm -f ${DESTDIR}${MANDIR}/man1/${NAME}.1
    1.86  
    1.87  
    1.88  clean:
    1.89  	rm -f *.o
    1.90  
    1.91  realclean: clean
    1.92 -	rm -f ${EXE}
    1.93 +	rm -f ${NAME}
    1.94 +
    1.95 +distclean: realclean
    1.96 +	@rm -f ${NAME}-*.tar.gz ChangeLog
    1.97 +
    1.98 +debclean: distclean
    1.99 +	@cd Packages/${NV}/ ; debuild clean ;
   1.100 +
   1.101 +
   1.102 +.PHONY: all dist deb changelog clean distclean debclean build install uninstall
     2.1 --- a/bday.1	Mon Dec 17 08:02:15 2007 +0100
     2.2 +++ b/bday.1	Mon Dec 17 11:28:40 2007 +0100
     2.3 @@ -6,10 +6,6 @@
     2.4  .IR file ]
     2.5  .RB [ -W
     2.6  .IR defwarn ]
     2.7 -.RB [ -M
     2.8 -.IR maxwarn ]
     2.9 -.RB [ -m
    2.10 -.IR minwarn ]
    2.11  
    2.12  .SH DESCRIPTION
    2.13  The 
    2.14 @@ -33,8 +29,6 @@
    2.15  is a single hyphen, read the events from the standard input (usually
    2.16  the terminal).
    2.17  
    2.18 -.SS List Options
    2.19 -
    2.20  .TP
    2.21  .BI -W\  warn
    2.22  Warn
    2.23 @@ -44,32 +38,13 @@
    2.24  flag (see
    2.25  .BR FILE\ FORMAT ).
    2.26  If this switch is not specified, it defaults to 21 days.
    2.27 -.TP
    2.28 -.BI -M\  max
    2.29 -Warn at most
    2.30 -.I max
    2.31 -days in advance. This overrides any flag given in the file.
    2.32 -.TP
    2.33 -.BI -m\  min
    2.34 -Warn at least
    2.35 -.I min
    2.36 -days in advance. This overrides any flag given in the file.
    2.37  
    2.38  
    2.39  .SH FILE FORMAT
    2.40  
    2.41  Each line beginning with a hash sign, 
    2.42  .RB ` # ',
    2.43 -is a comment and will be ignored. Lines beginning with an ampersand,
    2.44 -.RB ` & ',
    2.45 -are directives. Currently there is only one such directive,
    2.46 -.B &include
    2.47 -.IR file ,
    2.48 -which reads in a seperate file from your
    2.49 -.I .birthdays
    2.50 -file.
    2.51 -.I file
    2.52 -should be given with an absolute path, which should not use the tilde notation to specify your home directory.
    2.53 +is a comment and will be ignored.
    2.54  
    2.55  Any other line specifies the name of a person or event, followed by an equals sign and
    2.56  a date and finally some extra options. The date has to be in ISO 8601 date format (YYYY-MM-DD).
     3.1 --- a/bdengine.c	Mon Dec 17 08:02:15 2007 +0100
     3.2 +++ b/bdengine.c	Mon Dec 17 11:28:40 2007 +0100
     3.3 @@ -82,8 +82,8 @@
     3.4  	$Id: xmalloc.c,v 1.2 1999/01/16 17:08:59 andy Exp $
     3.5  */
     3.6  
     3.7 -void *xmalloc (size_t size) {
     3.8 -	register void *value = malloc (size);
     3.9 +void* xmalloc (size_t size) {
    3.10 +	register void* value = malloc (size);
    3.11  	if (value == 0) {
    3.12  		fprintf(stderr, "virtual memory exhausted\n");
    3.13  		exit(1);
    3.14 @@ -92,8 +92,8 @@
    3.15  }
    3.16  
    3.17  
    3.18 -void *xrealloc (void *ptr, size_t size) {
    3.19 -	register void *value = realloc (ptr, size);
    3.20 +void* xrealloc (void* ptr, size_t size) {
    3.21 +	register void* value = realloc (ptr, size);
    3.22  	if (value == 0) {
    3.23  		fprintf(stderr, "virtual memory exhausted\n");
    3.24  		exit(1);
    3.25 @@ -112,14 +112,11 @@
    3.26  int evcmp(const void *e1, const void *e2);
    3.27  char *deffname(void);
    3.28  
    3.29 -/*struct event *dir_include(char *dir, char *parm);*/
    3.30  
    3.31  /* ========== Global variables */
    3.32  
    3.33  struct date today;
    3.34  int iDWarn   = DEF_WARN;
    3.35 -int iMaxWarn = MAX_WARN;
    3.36 -int iMinWarn = MIN_WARN;
    3.37  
    3.38  const unsigned MLENDAT[]={31,-1,31,30,31,30,31,31,30,31,30,31};
    3.39  
    3.40 @@ -290,7 +287,7 @@
    3.41  		if (evl[i].warn == -1 && delta(&(evl[i].date))==0) {
    3.42  			 append(buf, evl[i].text);
    3.43  		} else if (evl[i].enddate.day == 0) {
    3.44 -			if (delta(&(evl[i].date)) <= warnperiod(evl[i])) {
    3.45 +			if (delta(&(evl[i].date)) <= evl[i].warn) {
    3.46  				append(buf, evl[i].text);
    3.47  				append(buf, " ");
    3.48  				tmp = tdelta(&(evl[i].date));
    3.49 @@ -298,7 +295,7 @@
    3.50  				free(tmp);
    3.51  			}
    3.52  		} else {
    3.53 -			if (delta(&(evl[i].date)) <= warnperiod(evl[i])) {
    3.54 +			if (delta(&(evl[i].date)) <= evl[i].warn) {
    3.55  				append(buf, evl[i].text);
    3.56  				append(buf, " for ");
    3.57  				/* +1 because, if the difference between two dates is one day,
    3.58 @@ -310,7 +307,7 @@
    3.59  				append(buf, " ");
    3.60  				tmp = tdelta(&(evl[i].date));
    3.61  				append(buf, tmp);
    3.62 -			} else if (delta(&(evl[i].enddate)) <= warnperiod(evl[i])) {
    3.63 +			} else if (delta(&(evl[i].enddate)) <= evl[i].warn) {
    3.64  				append(buf, evl[i].text);
    3.65  				append(buf, " ");
    3.66  				j = delta(&(evl[i].enddate));
     4.1 --- a/birthday.c	Mon Dec 17 08:02:15 2007 +0100
     4.2 +++ b/birthday.c	Mon Dec 17 11:28:40 2007 +0100
     4.3 @@ -36,7 +36,6 @@
     4.4  {
     4.5    char* fname = NULL;
     4.6    struct event *evl; /* evl => event list */
     4.7 -  char* opt = NULL;
     4.8  
     4.9    while (--argc > 0 && (*++argv)[0] == '-') {
    4.10      if (strcmp(argv[0], "-f") == 0) {
    4.11 @@ -45,14 +44,8 @@
    4.12  		} else if (strcmp(argv[0], "-W") == 0) {
    4.13  			iDWarn = atoi((++argv)[0]);
    4.14  			argc--;
    4.15 -		} else if (strcmp(argv[0], "-M") == 0) {
    4.16 -			iMaxWarn = atoi((++argv)[0]);
    4.17 -			argc--;
    4.18 -		} else if (strcmp(argv[0], "-m") == 0) {
    4.19 -			iMinWarn = atoi((++argv)[0]);
    4.20 -			argc--;
    4.21  		} else {
    4.22 -			fprintf(stderr, "unknown option %s\n", opt);
    4.23 +			fprintf(stderr, "unknown option %s\n", argv[0]);
    4.24  			exit(1);
    4.25  		}
    4.26  	}
     5.1 --- a/birthday.h	Mon Dec 17 08:02:15 2007 +0100
     5.2 +++ b/birthday.h	Mon Dec 17 11:28:40 2007 +0100
     5.3 @@ -31,10 +31,6 @@
     5.4  
     5.5  /* standard time to warn in advance, when no explicit w flag is given. */
     5.6  #define DEF_WARN 21
     5.7 -/* maximum time to warn in advance when no M flag is given */
     5.8 -#define MAX_WARN 500 /* ie, a year */
     5.9 -/* minimum time to warn in advance when no m flag */
    5.10 -#define MIN_WARN 0
    5.11  
    5.12  /* ========== Required includes */
    5.13  
    5.14 @@ -50,7 +46,7 @@
    5.15  #define mlen(m,y) (MLENDAT[(m)-1] != -1 ? MLENDAT[(m)-1] : (isleapyear((y)) ? 29 : 28))
    5.16  #define before(a,b) ((a).month < (b).month || ((a).month == (b).month && (a).day < (b).day))
    5.17  #define ydelta(a,b) ((int) (b).year - (a).year + before((a),(b)))
    5.18 -#define warnperiod(ev) ((ev).warn<iMinWarn?iMinWarn:((ev).warn>iMaxWarn?iMaxWarn:(ev).warn))
    5.19 +#define warnperiod(ev) ( (ev).warn )
    5.20  
    5.21  /* -------- modifier flags */
    5.22  
    5.23 @@ -99,6 +95,4 @@
    5.24  
    5.25  extern struct date today;
    5.26  extern int iDWarn;
    5.27 -extern int iMaxWarn;
    5.28 -extern int iMinWarn;
    5.29