[net.sources] rs - a personal reminder system

don@novavax.UUCP (Don Joslyn) (07/16/85)

rs makes it easy to remember! (At least for me :-)

If you like it, use it.  If you don't like it loose it!  :-)

What else do you do with a rainy weekend?

--- cut here ---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	Makefile
#	README
#	rs.1
#	rs.c
# This archive created: Tue Jul 16 16:41:26 1985
# By:	Don Joslyn (Nova University, Fort Lauderdale, Florida)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'Makefile'" '(838 characters)'
if test -f 'Makefile'
then
	echo shar: will not over-write existing file "'Makefile'"
else
sed 's/^	X//' << \SHAR_EOF > 'Makefile'
	XDEST	      = /usr/local
	X
	XMDEST	      = /usr/man/manl/rs.l
	X
	XEXTHDRS	      = /usr/include/ctype.h \
	X		/usr/include/stdio.h \
	X		/usr/include/strings.h
	X
	XLDFLAGS	      = -O -w
	X
	XLINKER	      = cc
	X
	XMAKEFILE      = Makefile
	X
	XMANUAL	      = rs.1
	X
	XPRINT	      = pr
	X
	XPROGRAM	      = rs
	X
	XSRCS	      = rs.c
	X
	Xall:		$(PROGRAM)
	X
	X$(PROGRAM):     
	X		@echo -n "Loading $(PROGRAM) ... "
	X		@$(LINKER) $(LDFLAGS) $(SRCS) -o $(PROGRAM)
	X		@echo "done"
	X
	Xinstall:	$(PROGRAM)
	X		@echo Installing $(PROGRAM) in $(DEST)
	X		@install -s $(PROGRAM) $(DEST)
	X		@echo Installing manual in $(MDEST)
	X		@cp $(MANUAL) $(MDEST)
	X
	Xprint:;		@$(PRINT) $(SRCS)
	X
	Xprogram:        $(PROGRAM)
	X
	Xupdate:		$(DEST)/$(PROGRAM)
	X
	X$(DEST)/$(PROGRAM): $(SRCS) $(LIBS) $(EXTHDRS)
	X		@make -f $(MAKEFILE) DEST=$(DEST) install
	X###
	Xrs.o: /usr/include/stdio.h /usr/include/ctype.h /usr/include/strings.h
SHAR_EOF
if test 838 -ne "`wc -c < 'Makefile'`"
then
	echo shar: error transmitting "'Makefile'" '(should have been 838 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'README'" '(1623 characters)'
if test -f 'README'
then
	echo shar: will not over-write existing file "'README'"
else
sed 's/^	X//' << \SHAR_EOF > 'README'
	Xrs - a reminder system, by:
	X
	X	Don Joslyn
	X	Nova University Computer Center
	X	3301 College Avenue
	X	Fort Lauderdale, Florida 33314
	X	(305) 475-7630
	X	...{ucf-cs, neoucom, allegra}!novavax!don
	X	Copyright (C) 1985 by Nova University, Don Joslyn
	X
	XThis directory contains the source and manual entry for the rs program.
	XSee the manual entry for more information on the use of rs.
	XThe rs program was written under and for BSD 4.2
	X
	XTo Install:
	X
	X1)	Look at rs.c and change any #defines needed.
	X	Defaults:
	X
	X		CALENDAR  "/calendar"		users calendar file.
	X		RSFILE	  "/.reminders"		users reminder file.
	X		RSNOTES	  "/.rsnotes"		users notes    file.
	X
	X		All of the above files are looked for in the users HOME dir.
	X
	X		LPR		"/usr/ucb/lpr"	location of lpr command.
	X		VI		"/usr/ucb/vi"	location and def. of editor.
	X
	X		MAXLINES	500		Max. number of lines (reminders)
	X		MAXLEN		256		Max. len of a single line.
	X
	X	If your /tmp directory is somewhere else, change rstmp.
	X	Default:	char rstmp[] = "/tmp/rsXXXXX"
	X
	X2)	Look at the Makefile and change target directory for the rs executable 
	X	and the manual entry if you wish.
	X
	X	Defaults:
	X
	X		DEST  = /usr/local		rs program >> /usr/local
	X		MDEST = /usr/man/manl		rs manual  >> /usr/man/manl
	X
	X3)	Run 'make install' which will make and install the executables and the
	X	manual entries.
	X	If you want to compile the rs program in the current directory,
	X	run 'make program'.
	X
	X------------------
	XMail questions to:
	X
	X	...{ucf-cs, neoucom, allegra}!novavax!don
	X
	XIf you would like to receive new revisions of the rs program, please inform
	Xnovavax!don
	X
	XThe main purpose of the rs command, is to make remembering easy!
SHAR_EOF
if test 1623 -ne "`wc -c < 'README'`"
then
	echo shar: error transmitting "'README'" '(should have been 1623 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'rs.1'" '(4316 characters)'
if test -f 'rs.1'
then
	echo shar: will not over-write existing file "'rs.1'"
else
sed 's/^	X//' << \SHAR_EOF > 'rs.1'
	X.TH RS 1 "30 January 1985"
	X.SH NAME
	Xrs \ - reminder system
	X.SH SYNOPSIS
	X.B rs
	X[ \-Aacknpv ] [ \-s
	X.I string
	X] [ -d # ] [ -d #-# ]
	X.SH DESCRIPTION
	X.I rs
	Xis a personal reminder system.  Reminders that you have added can be displayed
	Xevery time you log into the system By placing the
	X.I rs
	Xcommand in your
	X.I .login
	Xfile.  The reminder system includes two reminder files,
	Xone for reminders and one for notes, plus an alternate reminder file that is
	Xuser defined by the environment variable
	X.I RSALT.
	X.TP
	X.I Options:
	X.TP
	X.I rs
	Xwith no options will output reminder list to terminal.
	X.TP
	X.B \-A
	Xwork with
	X.I alternate
	Xreminder file.  The name of the alternate file is user
	Xdefined in the
	X.I RSALT
	Xenvironment variable.
	X.TP
	X.B \-a
	Xadd reminder(s)/note(s)/alternate(s).  User is prompted to add reminder(s)/note(s)/alternate(s).
	X.TP
	X.B \-c
	Xadd reminder(s) to calendar system.  User is prompted to add calendar reminder(s).
	Xsee
	X.I calendar(1).
	X.TP
	X.B \-d
	Xdelete reminder(s)/note(s)/alternate(s).  Followed by a number or numbers, 
	X.I rs
	Xwill delete
	Xthe specified reminder(s)/note(s)/alternate(s).  More than 1 number may be placed on the same
	Xcommand line separated by blanks.  A range of numbers may also be specified
	Xwith the format #-#.
	X.TP
	X.B \-k
	Xkill all reminders/notes/alternates.
	X.TP
	X.B \-n
	Xwork on
	X.I notes
	Xreminder file.
	X.TP
	X.B \-p
	Xprint reminders/notes/alternates. (Does an
	X.I lpr
	Xof reminder file.)
	X.TP
	X.B \-s
	Xsearch for reminders/notes/alternates that match the given string.
	X.TP
	X.B \-v
	Xedit reminders/notes/alternates with
	X.I vi.
	X.PP
	XMore than one option may follow a single '-'.
	X.br
	XExample:
	X
	X.br
	X	rs -na		The command for "add note".
	X
	X.PP
	X.I rs
	Xlooks in the environment variable
	X.I RSINIT
	Xto determine what to do after additions/deletions to a reminder/note/alternate
	Xfile.  For example, if you prefer to view your reminders/notes/alternates after
	Xadditions/deletions, the
	X.I csh
	Xcommand
	X.I "setenv RSINIT 'aAdD'"
	Xwould cause
	X.I rs
	Xto display your reminders/notes/alternates after additions/deletions.  The
	Xabove command sequence may be placed in your
	X.I .login
	Xfile.
	X.br
	Xa & d = display reminders after additions/deletions.
	X.br
	XA & D = display notes/alternates/calendar after additions/deletions.
	X.PP
	XReminders/notes/alternates may be from 1 to 255 characters long.  If a reminder is longer than
	X80 characters (1 line),
	X.I rs
	Xwill do automatic word wrapping.  To add a reminder/note/alternate longer than
	X80 characters, type in the entire reminder/note/alternate and end with a single
	Xcarriage return. Do
	X.I not
	Xinsert carriage returns before the end of a
	Xreminder/note/alternate.  A single carriage return
	X.I always
	Xindicates the
	X.I end
	Xof a reminder.
	X.SH EXAMPLES
	Xrs -d 1 5 8	delete reminders 1, 5, 8.
	X.TP
	Xrs -n -d 1-5 8	delete notes 1, 2, 3, 4, 5, 8.
	X.TP
	Xrs -k		kill all reminders.
	X
	X.SH EXAMPLE USE OF ALTERNATE REMINDER FILE
	X.PP
	X
	XIf you would like to have a list of phone numbers that can be accessed by the
	Xreminder system, you could do the following:
	X.PP
	XSet the
	X.I RSALT
	Xenvironment variable to
	X.I phone-numbers
	Xby including the following command line in your
	X.I .login
	Xfile:
	X.TP
	X.I "     setenv RSALT 'phone-numbers'"
	X.TP
	XUse the reminder system command:
	X.TP
	X.I "     rs -A [options]"
	X.TP
	Xto work on the phone-numbers reminder file.
	X.SH EXAMPLE COMMANDS FOR PHONE-NUMBERS REMINDER FILE
	X.TP
	Xrs \-A \-a
	XAdd phone numbers to the phone-numbers reminder file.
	X.TP
	Xrs \-A \-s Joslyn   Search for Joslyn's phone number.
	X.TP
	Xrs \-A \-v          Edit phone-numbers with vi.
	X.TP
	Xrs \-A \-p          Print phone-numbers on the line printer.
	X.TP
	Xrs \-A \-d 1        Delete the first line from phone-numbers.
	X.SH FILES
	X~.reminders     users reminders.
	X.br
	X~.rsnotes       users notes.
	X.br
	X/tmp/.rs*       used during reminder deletion.
	X.br
	X~.?             other reminder file(s) defined by
	X.I RSALT.
	X.SH "SEE ALSO"
	Xcalendar(1),
	Xcsh(1),
	Xenviron(7),
	Xlpr(1),
	Xvi(1)
	X.SH AUTHOR
	XDon Joslyn
	X.br
	XNova University Computer Center
	X.br
	X3301 College Avenue
	X.br
	XFort Lauderdale, Florida 33314
	X.br
	X(305) 475-7630
	X.br
	X{ucf-cs, neoucom, allegra}!novavax!don
	X.br
	XCopyright (C) 1985 by Nova University, Don Joslyn
	X.SH BUGS
	XThe
	X.I auto-wrap
	Xfeature can be fooled since
	X.I rs
	Xlooks for blanks between words to split lines.  If a word is longer than 75
	Xcharacters,
	X.I rs
	Xwill NOT break the line up properly.  Strange things will occur!
SHAR_EOF
if test 4316 -ne "`wc -c < 'rs.1'`"
then
	echo shar: error transmitting "'rs.1'" '(should have been 4316 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'rs.c'" '(9852 characters)'
if test -f 'rs.c'
then
	echo shar: will not over-write existing file "'rs.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'rs.c'
	Xstatic char rcsid[] = "$Header: rs.c,v 2.2 85/02/25 10:35:48 don Exp $";
	X
	X/* $Log:	rs.c,v $
	X * Revision 2.2  85/02/25  10:35:48  don
	X * 1.  Optimized kill and line wrap routines.
	X * 2.  Added defines for LPR & VI.
	X * 3.  Added more RSINIT options. (A & D)
	X * 4.  Deleted add_calendar routine, now uses add_reminders.
	X * 5.  Added comments.
	X * 
	X * Revision 2.1  85/01/28  17:03:56  don
	X * 1. Added new notes file - .rsnotes | command rs -n
	X * 2. Added new alternate file - user defined via setenv RSALT | command rs -A
	X * 3. Added environment variable RSINIT.
	X *    setenv RSINIT 'ad' | a = display after add | d = display after delete.
	X * 4. Lines may now be 256 char. long.
	X * 5. Long lines will automatically wrap like 'vi'.
	X * 6. Added search command. | rs -s 'search string'
	X * 7. Help deleted, replaced with 'usage' message.
	X * 8. Misc. optimizations.
	X * 
	X * Revision 1.3  85/01/15  09:17:57  don
	X * 1. Added $Log line for RCS.
	X * 2. Fixed help message.
	X * 3. Coded in range deletion.
	X *  */
	X
	X/*	Program	written by:	Don Joslyn
	X *				Nova University Computer Center
	X *				3301 College Avenue
	X *				Fort Lauderdale, Florida 33314
	X *				(305) 475-7630 (novavax!don)
	X *
	X *	Copyright (C) 1985 by	Nova University, Don Joslyn
	X *
	X *	The rs program was written under and for BSD 4.2
	X*/
	X
	X#include	<stdio.h>
	X#include	<ctype.h>
	X#include	<strings.h>
	X
	X#define		MAXLEN   256	/* Max. Length of a single line     */
	X#define		MAXLINES 500	/* Max. number of lines (reminders) */
	X
	X#define		CALENDAR "/calendar"	/* calendar file */
	X#define		RSFILE	 "/.reminders"	/* reminder file */
	X#define		RSNOTES  "/.rsnotes"	/* notes    file */
	X
	X#define		LPR	"/usr/ucb/lpr"	/* location of lpr */
	X#define		VI	"/usr/ucb/vi"	/* location of vi  */
	X
	XFILE	*fp,
	X	*fptmp;
	X
	Xchar	fname[128],
	X	line[MAXLEN],
	X	s[MAXLEN],
	X	sstr[80],
	X	cmd[128],
	X	entity[128],
	X	*fun;
	X
	Xchar	*getenv(),
	X	*mktemp();
	X
	Xchar	rstmp[]= "/tmp/rsXXXXXX";	/* name of temp. file during delete */
	X
	Xint	adisplay = 0,	/* display reminders after additions (default = no) */
	X	ddisplay = 0,	/* display reminders after deletions (default = no) */
	X	Adisplay = 0,	/* display notes/alt after additions (default = no) */
	X	Ddisplay = 0,	/* display notes/alt after deletions (default = no) */
	X	rem_work = 1,	/* working on reminder file by default */
	X	search = 0,	/* search option seen on command line */
	X	status;		/* Hold status returned by sys calls and such */
	X
	Xmain(argc, argv)
	Xint	argc;
	Xchar	*argv[];
	X
	X{ 
	X
	Xchar	*env;		/* Hold for RSINIT environment variable */
	X
	X/* Get RSINIT environment variable to find options desired */
	X
	Xenv = getenv("RSINIT");
	X
	Xif (index(env, 'd'))
	X	ddisplay++;	/* user wants reminders displayed after deletions */
	Xif (index(env, 'a'))
	X	adisplay++;	/* user wants reminders displayed after additions */
	Xif (index(env, 'D'))
	X	Ddisplay++;	/* user wants notes/alt displayed after deletions */
	Xif (index(env, 'A'))
	X	Adisplay++;	/* user wants notes/alt displayed after additions */
	X
	X/* Get users HOME directory and construct default name for reminder file */
	X
	Xsprintf(fname, "%s%s", getenv("HOME"), RSFILE);
	Xstrcpy(entity, "Reminders");
	X
	X/* Find out what the user wants to do */
	X
	Xwhile ( --argc > 0 && (*++argv)[0] == '-')
	X	for (fun = argv[0]+1; *fun != '\0'; fun++)
	X		switch(*fun) {
	X		case 'A' :	/* Work on Alternate reminder file */
	X			env = getenv("RSALT");
	X			if (!env)
	X			{
	X				printf("RSALT not defined\n");
	X				exit(1);
	X			}
	X			else
	X			{
	X			sprintf(fname, "%s/.%s", getenv("HOME"), env);
	X			strcpy(entity, env);
	X			if (islower(entity[0]))
	X				entity[0] = toupper(entity[0]);
	X			rem_work = 0;
	X			break;
	X			}
	X
	X		case 'a' :	/* Add reminder(s)/note(s)/alternate(s) */
	X			add_reminder();
	X			exit(0);
	X
	X		case 'c' :	/* Add entries to calendar file */
	X			sprintf(fname, "%s%s", getenv("HOME"), CALENDAR);
	X			strcpy(entity, "Calendar commands");
	X			rem_work = 0;
	X			add_reminder();
	X			exit(0);
	X
	X		case 'd' :	/* Delete reminder(s)/note(s)/alternate(s) */
	X			delete_reminder(argc, argv);
	X			exit(0);
	X
	X		case 'k' :	/* Kill all reminders/notes/alternates */
	X			if ( unlink(fname) == 0)
	X			{
	X				printf("%s killed.\n", entity);
	X			}
	X			exit(0);
	X
	X		case 'n' :	/* Work on notes file */
	X			sprintf(fname, "%s%s", getenv("HOME"), RSNOTES);
	X			strcpy(entity, "Notes");
	X			rem_work = 0;
	X			break;
	X
	X		case 'p' :	/* print reminders/notes/alternates */
	X			sprintf(cmd, "%s %s", LPR, fname);
	X			status = system(cmd);
	X
	X			if (status == 0)
	X			{
	X				printf("%s will be printed.\n", entity);
	X				exit(0);
	X			}
	X			else
	X			{
	X				printf("%s can't be printed, sorry\n", entity);
	X				exit(1);
	X			}
	X
	X		case 's' :	/* search for string in reminders/notes/alts */
	X			argc--;
	X			argv++;
	X			sprintf(sstr, "%s", argv[0]);
	X			search++;
	X			break;
	X		case 'v' :	/* Edit reminders/notes/alternates with vi */
	X			sprintf(cmd, "%s %s",VI,fname);
	X			system(cmd);
	X			exit(0);
	X		default:	/* Give em some help */
	X			printf("Usage: rs [ -Aacknpv ] [ -s search_string ] [ -d # ] [ -d #-# ]\n");
	X			printf("For additional information type:  man rs\n");
	X
	X		/* You can enable this stuff if you want! */
	X		/*	printf("Reminder Service commands:\n\n");
	X			printf("-A	Work on Alternate reminder file.\n");
	X			printf("-a	Add reminder(s)/note(s)/Alt(s).\n");
	X			printf("-c	Add line(s) to the calendar file.\n");
	X			printf("-d	Delete reminder(s)/note(s)/Alt(s).\n");
	X			printf("-k	Kill all reminders/notes/Alternate.\n");
	X			printf("-n	Work on notes.\n");
	X			printf("-p	Print reminders/notes/Alternates.\n");
	X			printf("-s	Search for string.\n");
	X			printf("-v	Edit reminders/notes/Alt with Vi.\n\n");
	X			printf("rs with no option will display reminders.\n");
	X			printf("SEE ALSO rs(1)\n");
	X		*/
	X			exit(0);
	X		}
	X
	Xprint_reminders();
	X
	X}
	X
	X
	X/* ADD REMINDERS */
	X/* This routine uses cat to add lines to the reminder/note/alternate file */
	X/* If you don't like it, add your own getline routine! */
	X
	Xadd_reminder()
	X{
	X
	X	printf("Enter %s then ^d to exit:\n", entity);
	X
	X	sprintf(cmd, "%s %s","/bin/cat >>",fname);
	X	system(cmd);
	X	if ( (adisplay && rem_work) || (Adisplay && !rem_work) )
	X		print_reminders();
	X}
	X
	X
	X/* DELETE REMINDERS/NOTES/ALTERNATES */
	X
	Xdelete_reminder(argc, argv)
	X	int	argc;
	X	char	*argv[];
	X{
	X
	X
	X	int	begin,
	X		end,
	X		delete_line[MAXLINES];
	X
	X	char	a[4], b[4];
	X
	X	register int	i	    = 0,
	X			j	    = 0,
	X			deleted     = 0,
	X			line_number = 0,
	X			printed     = 0;
	X
	X
	X	argc--, argv++;
	X	for (;argc > 0; argc--, argv++)
	X	{
	X		if (alldigits(*argv))
	X		{
	X			delete_line[atoi(*argv)] = 1;
	X		}
	X
	X
	X		else
	X		{
	X			i = rindex(*argv, '-');
	X			sscanf(i+1, "%s", b );
	X			j = ( strlen(*argv) - strlen(b) ) - 1;
	X			strncpy(a, *argv, j);
	X			a[j]='\0';
	X			begin = atoi(a);
	X			end   = atoi(b);
	X
	X			if (begin < end)
	X			{
	X				for (j = begin ; j < end+1 ; j++)
	X					delete_line[j] = 1;
	X			}
	X			else
	X			{
	X				printf("Illegal range specified.\n");
	X				exit(1);
	X			}
	X		}
	X	}
	X
	X
	X	mktemp(rstmp);
	X	if ((fptmp = fopen(rstmp,"w")) == NULL)
	X	{
	X		print_open_error_exit(rstmp);
	X	}
	X
	X
	X	if ((fp = fopen(fname,"r")) == NULL)
	X	{
	X		print_open_error_exit(fname);
	X	}
	X
	X
	X	while (getline(s, MAXLEN) > 0)
	X	{
	X		if (delete_line[++line_number] != 1)
	X		{
	X			fprintf(fptmp,"%s",s);
	X			printed++;
	X		}
	X
	X
	X		else
	X		{
	X			deleted++;
	X		}
	X	}
	X
	X
	X	fclose(fp);
	X	fclose(fptmp);
	X
	X	status = unlink(fname);
	X	if (status != 0)
	X	{
	X		printf("Can't remove file - %s", fname);
	X		exit(1);
	X	}
	X
	X	if (printed)
	X	{
	X		if ((fp = fopen(fname,"w")) == NULL)
	X		{
	X			print_open_error_exit(fname);
	X		}
	X
	X		if ((fptmp = fopen(rstmp,"r")) == NULL)
	X		{
	X			print_open_error_exit(rstmp);
	X		}
	X
	X		while (fgets(line, MAXLEN, fptmp) != NULL)
	X		{
	X			fputs(line, fp);
	X		}
	X
	X	}
	X
	X	fclose(fp);
	X	fclose(fptmp);
	X	status = unlink(rstmp);
	X
	X
	X	if (deleted)
	X	{
	X
	X		printf("%d %s deleted.\n",
	X			deleted, entity );
	X	}
	X	if ( (ddisplay && rem_work) || (Ddisplay && !rem_work) )
	X		print_reminders();
	X}
	X
	X
	X/* PRINT REMINDERS/NOTES/ALTERNATES */
	X/* This routine will print reminders/notes/alternates */
	X/* If a line is longer than 75 characters, print_line is called which does */
	X/* auto wrap.  If a search argument was given, only lines that contain the */
	X/* search string will be printed. */
	X
	Xprint_reminders()
	X{
	X
	X	register int line_number = 0;
	X
	X	if ((fp = fopen(fname,"r")) == NULL)
	X	{
	X		exit(0);
	X	}
	X
	X
	X	printf("\n%s:\n", entity);
	X
	X	while (getline(s, MAXLEN) > 0)
	X	{
	X		if (search)
	X		{
	X			if (instr(s, sstr) != -1)
	X			{
	X				if ( strlen(s) > 75 )
	X				{
	X					printf("%3d. ", ++line_number);
	X					print_line(s);
	X				}
	X				else
	X					printf("%3d. %s",++line_number,s);
	X			}
	X			else
	X				line_number++;
	X		}
	X		else
	X		if ( strlen(s) > 75 )
	X		{
	X			printf("%3d. ", ++line_number);
	X			print_line(s);
	X		}
	X		else
	X			printf("%3d. %s",++line_number,s);
	X	}
	X
	X
	X	printf("\n");
	X
	X
	X	fclose(fp);
	X
	X}
	X
	X
	Xgetline(s, lim)
	Xchar s[];
	Xint  lim;
	X{
	X
	X	register int i = 0;
	X	register int c;
	X
	X
	X	while (--lim > 0 && (c=getc(fp)) != EOF && c != '\n')
	X	{
	X		s[i++] = c;
	X	}
	X
	X	if (c == '\n')
	X	{
	X		s[i++] = c;
	X	}
	X
	X	s[i] = '\0';
	X
	X	return(i);
	X}
	X
	X
	Xalldigits(s)
	X	register char *s;
	X{
	Xregister c = *s++;
	X
	X	do
	X	{
	X	if (!isdigit(c))
	X		return(0);
	X	 }
	X	 while (c = *s++);
	X		return(1);
	X}
	X
	Xinstr(s, t)
	Xchar s[], t[];
	X{
	X	register int i, j, k;
	X
	X	for (i = 0; s[i] != '\0' ; i++)
	X	{
	X		for (j=i, k=0 ; t[k] != '\0' && s[j]==t[k] ; j++ , k++)
	X			;
	X		if (t[k] == '\0')
	X			return(i);
	X	}
	X	return(-1);
	X}
	X
	Xprint_open_error_exit(file_name)
	Xchar	file_name[];
	X{
	X	printf("Can't open file - %s\n",file_name);
	X	exit(1);
	X}
	X
	X/* This routine will wrap lines greater than 75 characters long.      */
	X/* An attempt is made to break the line up after a word.  If a "word" */
	X/* is greater than 75 characters, the line does not look so hot.      */
	X/* There must be a better way to do this.  If you have time to play   */
	X/* and find a better way, please let me know. */
	X
	Xprint_line(long_line)
	Xchar	long_line[];
	X{
	X
	Xregister int	a,z,x,m;
	X
	Xm = strlen(long_line);
	Xz = -1;
	Xwhile ( z < m )
	X{
	X	x = ++z;
	X	z += 74;
	X	if ( z < m)
	X		for ( ; long_line[z] != ' ' && (z != x) ; z--) ;
	X	else
	X		z = m;
	X	for (a=x ; a < z ; a++)
	X		putchar(long_line[a]);
	X	if ( z < m )
	X		printf("\n     ");
	X}
	X}
SHAR_EOF
if test 9852 -ne "`wc -c < 'rs.c'`"
then
	echo shar: error transmitting "'rs.c'" '(should have been 9852 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0

don@novavax.UUCP (Don Joslyn) (07/03/86)

rs is a personal reminder system.

Enjoy,
-------------------
Don Joslyn, Manager
Nova University, Computer Center, Fort Lauderdale, FL
UUCP: ...{codas|ucf-cs|allegra|usfvax2}!novavax!don
-----Cut Here-----
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	rs.man
#	README
#	Makefile
#	rs.c
#	rs.1
# This archive created: Thu Jul  3 15:58:03 1986
# By:	Don Joslyn (Nova University, Fort Lauderdale, Florida)
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "extracting 'rs.man'" '(6439 characters)'
if test -f 'rs.man'
then
	echo shar: "will not over-write existing file 'rs.man'"
else
sed 's/^XX//' << \SHAR_EOF > 'rs.man'
XX
XX
XX
XXRS(1)               UNIX Programmer's Manual                RS(1)
XX
XX
XX
XXNAME
XX     rs - reminder system
XX
XXSYNOPSIS
XX     rs [ -Aacknpv ] [ -s string ] [ -d # #-# ]
XX
XXDESCRIPTION
XX     rs  is  a  personal  reminder  system.   Reminders  can   be
XX     displayed  every time you log into the system by placing the
XX     rs command in your .login or .profile  file.   The  reminder
XX     system includes three reminder files:
XX
XX
XX          1.   Reminders  ($HOME/.reminders)
XX          2.   Notes      ($HOME/.rsnotes)
XX          3.   User defined by setting the RSALT environment variable.
XX               (Defaults to $HOME/.phone_numbers)
XX
XX     Options:
XX
XX     rs   With no options, print reminder list to terminal.
XX
XX     -A   Work with alternate reminder file.   The  name  of  the
XX          alternate  file  is  user  defined by setting the RSALT
XX          environment variable.  (If RSALT is not set, the alter-
XX          nate file defaults to 'phone_numbers'.)
XX
XX     -a   Add reminders/notes/alternates.  You  are  prompted  to
XX          add   reminders/notes/alternates.    Appending   a   ^G
XX          (Control-G) at the end of a reminder will cause  rs  to
XX          mark   it  (Highlight)  during  display.   (See  RSINIT
XX          below.)
XX
XX     -c   Add entries to calendar system.  You  are  prompted  to
XX          add calendar entries.  See calendar(1).
XX
XX     -d   Delete reminders/notes/alternates.  This  option,  fol-
XX          lowed  by  a number or numbers, causes rs to delete the
XX          specified reminders/notes/alternates.   More  than  one
XX          number may be placed on the same command line separated
XX          by blanks.  A range of numbers may also be specified.
XX
XX     -e   Edit reminders/notes/alternates file.   If  the  EDITOR
XX          environment  variable  is  set, the specified EDITOR is
XX          used.  If not, vi is used by default. (-v may  be  used
XX          in place of -e)
XX
XX     -k   Kill (delete) all reminders/notes/alternates.
XX
XX     -n   Work on notes file.
XX
XX     -p   Print reminders/notes/alternates.  (By default, does an
XX
XX
XX
XXPrinted 7/3/86            3 July 1986                        1
XX
XX
XX
XX
XX
XX
XXRS(1)               UNIX Programmer's Manual                RS(1)
XX
XX
XX
XX          lpr of reminder file.)
XX
XX     -s   Search for reminders/notes/alternates  that  match  the
XX          given string.
XX
XX     More than one option may follow a single "-", for example:
XX
XX          rs -na    The command for "add note."
XX
XXNOTES
XX     To mark a reminder (Highlight), append a ^G  (Control-G)  to
XX     the  reminder.   rs  will  mark  the reminder during display
XX     using one of the following:
XX
XX
XX          Standout
XX          Underscore.
XX          Bold
XX          Asterisk
XX
XX     as defined in RSINIT.
XX
XX     rs looks in the environment variable RSINIT  for  additional
XX     configuration options.  Options are:
XX
XX
XX     A    Display notes/alternates/calendar after additions.
XX     D    Display notes/alternates/calendar after deletions.
XX     a    Display reminders after additions.
XX     d    Display reminders after deletions.
XX     I    Ignore TERMCAP info during startup.
XX          (Default number of columns is 80, no mark capability)
XX
XX     Default mark is standout mode.
XX          ('so' and 'se' must be defined in termcap entry.)
XX
XX     U    Use underscore (underline) to mark reminders.
XX          ('us' and 'ue' must be defined in termcap entry.)
XX     B    Use Bold to mark reminders.
XX          ('bo' and 'be' must be defined in termcap entry.)
XX     S    Use '*' to mark reminders.
XX          (Terminal must have 'bs'.)
XX
XX     For    example,    if    you    prefer    to    view    your
XX     reminders/notes/alternates  after  additions/deletions,  the
XX     csh command:
XX
XX
XX               setenv RSINIT 'aAdD'
XX
XX     causes rs to display your  reminders/notes/alternates  after
XX     additions/deletions.   The  above  command  sequence  may be
XX
XX
XX
XXPrinted 7/3/86           3 July 1986                        2
XX
XX
XX
XX
XX
XX
XXRS(1)               UNIX Programmer's Manual                RS(1)
XX
XX
XX
XX     placed in your .login file.
XX
XX     Reminders/notes/alternates may be from one to 255 characters
XX     long.   If a reminder is longer than one line (As defined in
XX     termcap 'co'), rs  does  automatic  word  wrap.   To  add  a
XX     reminder/note/alternate  longer  than  one line, type in the
XX     entire reminder/note/alternate and end with  a  single  car-
XX     riage return.  Do not insert carriage returns before the end
XX     of a  reminder/note/alternate.   A  single  carriage  return
XX     always indicates the end of a reminder.
XX
XXEXAMPLES
XX     rs -d 1 5 8
XX          Delete reminders 1, 5, 8.
XX
XX     rs -n -d 1-5 8
XX          Delete notes 1, 2, 3, 4, 5, 8.
XX
XX     rs -k
XX          Kill all reminders.
XX
XXEXAMPLE USE OF ALTERNATE REMINDER FILE
XX     If you would like to have a list of phone numbers  that  can
XX     be  accessed  by the reminder system, you can do the follow-
XX     ing:
XX
XX     Set the  RSALT  environment  variable  to  phone-numbers  by
XX     including the following command line in your .login file:
XX
XX          setenv RSALT 'phone-numbers'
XX
XX     Use the reminder system command:
XX
XX          rs -A [options]
XX
XX     to work on the phone-numbers reminder file.
XX
XXEXAMPLE COMMANDS FOR PHONE-NUMBERS REMINDER FILE
XX     rs -A -a
XX          Add phone numbers to the phone-numbers reminder file.
XX
XX     rs -A -s Joslyn
XX          Search for Joslyn's phone number.
XX
XX     rs -A -e
XX          Edit phone-numbers.
XX
XX     rs -A -p
XX          Print phone-numbers on the line printer.
XX
XX     rs -A -d 1
XX          Delete the first line from phone-numbers.
XX
XX
XX
XXPrinted 7/3/86           3 July 1986                        3
XX
XX
XX
XX
XX
XX
XXRS(1)               UNIX Programmer's Manual                RS(1)
XX
XX
XX
XXTIPS
XX     To make use  of  the  notes/alternates  easier,  the  author
XX     defines two aliases:
XX
XX     alias rsn 'rs -n'     Use rsn to work with notes file.
XX     alias rsa 'rs -A'     Use rsa to work with alternate file.
XX
XXFILES
XX     $HOME/.reminders    User's reminders.
XX     $HOME/.rsnotes      User's notes.
XX     /tmp/.rs*           Used during reminder deletion.
XX     $HOME/.?            Other reminder file(s) defined by RSALT.
XX
XXSEE ALSO
XX     calendar(1), csh(1), environ(7), lpr(1), vi(1)
XX
XXAUTHOR
XX     Don Joslyn, Manager
XX     Nova University Computer Center
XX     3301 College Avenue
XX     Fort Lauderdale, Florida 33314
XX     (305) 475-7678
XX     {codas, allegra, ucf-cs}!novavax!don
XX
XXPrinted 7/3/86            3 July 1986                        4
SHAR_EOF
if test 6439 -ne "`wc -c < 'rs.man'`"
then
	echo shar: "error transmitting 'rs.man'" '(should have been 6439 characters)'
fi
fi
echo shar: "extracting 'README'" '(1568 characters)'
if test -f 'README'
then
	echo shar: "will not over-write existing file 'README'"
else
sed 's/^XX//' << \SHAR_EOF > 'README'
XXrs - a reminder system, by:
XX
XX	Don Joslyn, Manager
XX	Nova University Computer Center
XX	3301 College Avenue
XX	Fort Lauderdale, Florida 33314
XX	(305) 475-7678
XX	...{codas, allegra, ucf-cs}!novavax!don
XX
XXThis directory contains the source and manual entry for the rs program.
XXSee the manual entry for more information on the use of rs.
XX
XXTo Install:
XX
XX1)	Look at rs.c and change any #defines needed.
XX	Defaults:
XX
XX		CALENDAR  "/calendar"		users calendar file.
XX		RSFILE	  "/.reminders"		users reminder file.
XX		RSNOTES	  "/.rsnotes"		users notes    file.
XX
XX		LPR		"/usr/ucb/lpr"	location of lpr command.
XX		EDITOR		"/usr/ucb/vi"	default editor.
XX
XX		MAXLINES	500		Max. number of lines (reminders)
XX		MAXLEN		256		Max. len of a single line.
XX
XX	If your /tmp directory is somewhere else, change rstmp.
XX	Default:	char rstmp[] = "/tmp/rsXXXXX"
XX
XX2)	Edit the Makefile.
XX
XX	Change target directory for the rs executable and manual entry
XX	if you wish.
XX
XX	Defaults:
XX
XX		DEST  = /usr/local		rs program >> /usr/local
XX		MDEST = /usr/man/manl		rs manual  >> /usr/man/manl
XX
XX	If you have something other than termcap, make the change to LIBS.
XX
XX	If you are not a BSD site, take '-DBSD' out of the Makefile so that
XX	strnchr and <string.h> will be used in place of rindex and <strings.h>
XX
XX3)	Run 'make install' which will make and install the executables and the
XX	manual entries.
XX	If you want to compile the rs program in the current directory,
XX	run 'make program'.
XX
XX------------------
XXMail questions to:
XX
XX	...{codas, allegra, ucf-cs}!novavax!don
XX
XXThe main purpose of the rs command, is to make remembering easy!
SHAR_EOF
if test 1568 -ne "`wc -c < 'README'`"
then
	echo shar: "error transmitting 'README'" '(should have been 1568 characters)'
fi
fi
echo shar: "extracting 'Makefile'" '(513 characters)'
if test -f 'Makefile'
then
	echo shar: "will not over-write existing file 'Makefile'"
else
sed 's/^XX//' << \SHAR_EOF > 'Makefile'
XXDEST	      = /usr/local
XX
XXMDEST	      = /usr/man/manl/rs.l
XX
XXLDFLAGS	      = -DBSD -O -w
XX
XXLIBS          = -ltermcap
XX
XXLINKER	      = cc
XX
XXMANUAL	      = rs.1
XX
XXPROGRAM	      = rs
XX
XXSRCS	      = rs.c
XX
XXall:		$(PROGRAM)
XX
XX$(PROGRAM):     
XX		@echo -n "Loading rs ..."
XX		@$(LINKER) $(LDFLAGS) $(SRCS) $(LIBS) -o $(PROGRAM)
XX		@echo "done."
XX
XXinstall:	$(PROGRAM)
XX		@echo Installing $(PROGRAM) in $(DEST)
XX		@install -s $(PROGRAM) $(DEST)
XX		@echo Installing manual in $(MDEST)
XX		@cp $(MANUAL) $(MDEST)
XX
XXprogram:        $(PROGRAM)
SHAR_EOF
if test 513 -ne "`wc -c < 'Makefile'`"
then
	echo shar: "error transmitting 'Makefile'" '(should have been 513 characters)'
fi
fi
echo shar: "extracting 'rs.c'" '(13652 characters)'
if test -f 'rs.c'
then
	echo shar: "will not over-write existing file 'rs.c'"
else
sed 's/^XX//' << \SHAR_EOF > 'rs.c'
XXstatic char rcsid[] = "$Header: rs.c,v 3.3 86/07/03 14:24:34 don Exp $";
XX
XX/* $Log:	rs.c,v $
XX * Revision 3.3  86/07/03  14:24:34  don
XX * 1.  MAX_LINE (# columns on a line) now defined by termcap entry for TERM.
XX * 2.  Misc. Optimizations.
XX * 3.  Reminders can now be "marked", by appending ^G to reminder, to have
XX *     reminder highlighted during display.  "Highlight" options can be defined
XX *     in the RSINIT environment variable.
XX *     U - Underscore,  B - Bold,  S - Asterisk. (Default is standout)
XX *     I - Ignore termcap entry.
XX * 
XX * Revision 3.2  85/08/26  14:55:42  don
XX * Adding Mike's enhancements.  Thanks Mike! :-)
XX * Revision 3.2 & 3.3 by Mike Spitzer @ (pur-ee!mjs)
XX * 
XX * Revision 3.2  85/08/05  13:10:52  mjs
XX * -added new print_line which doesn't barf on long words
XX * -added #define for place to break up lines(MAX_LINE)
XX * -print_line is always called now, test for strlen(line) < MAX_LINE
XX *  is now made there.
XX * 
XX * 	MIke Spitzer
XX * 	pur-ee!mjs
XX * 
XX * Revision 3.1  85/07/26  20:48:06  mjs
XX * "rs" now recognizes the $EDITOR variable.  "vi" will be used if 
XX * $EDITOR is undefined.
XX * 
XX * added "-e" flag... does the same thing as "-v"
XX * 
XX * -mjs
XX * 
XX * Revision 2.2  85/02/25  10:35:48  don
XX * 1.  Optimized kill and line wrap routines.
XX * 2.  Added defines for LPR & VI.
XX * 3.  Added more RSINIT options. (A & D)
XX * 4.  Deleted add_calendar routine, now uses add_reminders.
XX * 5.  Added comments.
XX * 
XX * Revision 2.1  85/01/28  17:03:56  don
XX * 1. Added new notes file - .rsnotes | command rs -n
XX * 2. Added new alternate file - user defined via setenv RSALT | command rs -A
XX * 3. Added environment variable RSINIT.
XX *    setenv RSINIT 'ad' | a = display after add | d = display after delete.
XX * 4. Lines may now be 256 char. long.
XX * 5. Long lines will automatically wrap like 'vi'.
XX * 6. Added search command. | rs -s 'search string'
XX * 7. Help deleted, replaced with 'usage' message.
XX * 8. Misc. optimizations.
XX * 
XX * Revision 1.3  85/01/15  09:17:57  don
XX * 1. Added $Log line for RCS.
XX * 2. Fixed help message.
XX * 3. Coded in range deletion.
XX *  */
XX
XX/*	Program	written by:	Don Joslyn
XX *				Nova University Computer Center
XX *				3301 College Avenue
XX *				Fort Lauderdale, Florida 33314
XX *				(305) 475-7630 (novavax!don)
XX *
XX *	Notice:  No Copyright. 
XX *
XX*/
XX
XX#include	<stdio.h>
XX#include	<ctype.h>
XX#ifdef	BSD
XX#include	<strings.h>
XX#else
XX#include	<string.h>
XX#define		rindex	strnchr
XX#endif	BSD
XX
XX#define		MAXLEN   256	/* Max. Length of a single line     */
XX#define		MAXLINES 500	/* Max. number of lines (reminders) */
XX
XX#define		CALENDAR "/calendar"	/* calendar file */
XX#define		RSFILE	 "/.reminders"	/* reminder file */
XX#define		RSNOTES  "/.rsnotes"	/* notes    file */
XX
XX#define		LPR	"/usr/ucb/lpr"	/* location of lpr */
XX#define		EDITOR	"/usr/ucb/vi" 	/* default editor  */
XX
XX/*#define		BIGHELP	/* Define if you want verbose help message */
XX
XXFILE	*fp,
XX	*fptmp;
XX
XXchar	fname[128],		/* Filename tmp */
XX	on[32],			/* string used to turn "mark" on  */
XX	off[32],		/* string used to turn "mark" off */
XX	buff[1024],		/* Holds termcap entry for TERM */
XX	s[MAXLEN],		/* Tmp string and line storage */
XX	sstr[80],		/* Search string */
XX	cmd[256];		/* cmd for system call */
XX
XXchar	*a,
XX	*editor,		/* Hold for EDITOR environment variable */
XX	*entity = "Reminders",	/* Entity working on */
XX	*env,			/* Hold for RSINIT environment variable */
XX	*fun,			/* Used in arg processing */
XX	*mark_on  = "so",	/* Default mark is Standout mode */
XX	*mark_off = "se";	/* Standout end */
XX	
XX
XXchar	*getenv(),
XX	*malloc(),
XX	*mktemp();
XX
XXchar	rstmp[]= "/tmp/rsXXXXXX";	/* name of temp. file during delete */
XX
XXint	adisplay = 0,	/* display reminders after additions (default = no) */
XX	ddisplay = 0,	/* display reminders after deletions (default = no) */
XX	Adisplay = 0,	/* display notes/alt after additions (default = no) */
XX	Ddisplay = 0,	/* display notes/alt after deletions (default = no) */
XX	columns = 80,	/* Number of columns in a line. */
XX	len      = 0,	/* Length of line */
XX	mark     = 0,	/* Mark the line (High Priority) */
XX	tcap     = 1,	/* Read Termcap stuff. */
XX	tcapok   = 0,	/* TERM found in Termcap file. */
XX	rem_work = 1,	/* working on reminder file by default */
XX	search   = 0,	/* search option seen on command line */
XX	status;		/* Hold status returned by sys calls and such */
XX
XXmain(argc, argv)
XXint	argc;
XXchar	*argv[];
XX{ 
XX
XX/* Get RSINIT environment variable to find options desired */
XX
XXenv = getenv("RSINIT");
XX
XXwhile (*env) {
XX	switch(*env++) {
XX		case 'a' : adisplay++; break;
XX		case 'd' : ddisplay++; break;
XX		case 'A' : Adisplay++; break;
XX		case 'D' : Ddisplay++; break;
XX		case 'I' : tcap = 0;   break;
XX		case 'U' :
XX			mark_on  = "us";
XX			mark_off = "ue";
XX			break;
XX		case 'B' :
XX			mark_on  = "bo";
XX			mark_off = "be";
XX			break;
XX		case 'S' :
XX			mark_on  = "ss";
XX			mark_off = "ss";
XX			break;
XX	}
XX}
XX
XX
XX/* Get users HOME directory and construct default name for reminder file */
XX
XXsprintf(fname, "%s%s", getenv("HOME"), RSFILE);
XX
XX/* Find out what the user wants to do */
XX
XXwhile ( --argc > 0 && (*++argv)[0] == '-')
XX	for (fun = argv[0]+1; *fun != '\0'; fun++)
XX		switch(*fun) {
XX		case 'A' :	/* Work on Alternate reminder file */
XX			env = getenv("RSALT");
XX			if (!env)
XX				env = "phone_numbers";
XX
XX			sprintf(fname, "%s/.%s", getenv("HOME"), env);
XX			entity = env;
XX			if (islower(entity[0]))
XX				entity[0] = toupper(entity[0]);
XX			rem_work = 0;
XX			break;
XX
XX		case 'a' :	/* Add reminder(s)/note(s)/alternate(s) */
XX			add_reminder();
XX			exit(0);
XX
XX		case 'c' :	/* Add entries to calendar file */
XX			sprintf(fname, "%s%s", getenv("HOME"), CALENDAR);
XX			entity = "Calendar commands";
XX			rem_work = 0;
XX			add_reminder();
XX			exit(0);
XX
XX		case 'd' :	/* Delete reminder(s)/note(s)/alternate(s) */
XX			delete_reminder(argc, argv);
XX			exit(0);
XX
XX		case 'k' :	/* Kill all reminders/notes/alternates */
XX			if ( unlink(fname) == 0) {
XX				printf("%s killed.\n", entity);
XX			}
XX			exit(0);
XX
XX		case 'n' :	/* Work on notes file */
XX			sprintf(fname, "%s%s", getenv("HOME"), RSNOTES);
XX			entity = "Notes";
XX			rem_work = 0;
XX			break;
XX
XX		case 'p' :	/* print reminders/notes/alternates */
XX			sprintf(cmd, "%s %s", LPR, fname);
XX			status = system(cmd);
XX
XX			if (status == 0) {
XX				printf("%s will be printed.\n", entity);
XX				exit(0);
XX			}
XX			else {
XX				printf("%s can't be printed, sorry\n", entity);
XX				exit(1);
XX			}
XX
XX		case 's' :	/* search for string in reminders/notes/alts */
XX			argc--;
XX			argv++;
XX			sprintf(sstr, "%s", argv[0]);
XX			search++;
XX			break;
XX		case 'e' : /* -e and -v are equivilent */
XX		case 'v' : /* Edit reminders/notes/alternates with editor */
XX			editor = getenv("EDITOR");
XX			if (!editor)
XX				editor = EDITOR;
XX			sprintf(cmd, "%s %s",editor,fname);
XX			system(cmd);
XX			exit(0);
XX		default:	/* Give em some help */
XX#ifndef	BIGHELP
XX			printf("Usage: rs [ -Aaceknpv ] [ -s search_string ] [ -d # ] [ -d #-# ]\n");
XX			printf("For additional information type:  man rs\n");
XX#else
XX			/* You can enable this stuff if you want! */
XX			printf("Reminder Service commands:\n\n");
XX			printf("-A\tWork on Alternate reminder file.\n");
XX			printf("-a\tAdd reminder(s)/note(s)/Alt(s).\n");
XX			printf("-c\tAdd line(s) to the calendar file.\n");
XX			printf("-d\tDelete reminder(s)/note(s)/Alt(s).\n");
XX			printf("-k\tKill all reminders/notes/Alternate.\n");
XX			printf("-n\tWork on notes.\n");
XX			printf("-p\tPrint reminders/notes/Alternates.\n");
XX			printf("-s\tSearch for string.\n");
XX			printf("-e\tEdit reminders/notes/Alt.\n\n");
XX			printf("rs with no option will display reminders.\n");
XX			printf("SEE ALSO rs(1)\n");
XX#endif	BIGHELP
XX			exit(0);
XX		}
XX
XXprint_reminders();
XX
XX}
XX
XX
XX/* ADD REMINDERS */
XX/* This routine uses cat to add lines to the reminder/note/alternate file */
XX/* If you don't like it, add your own getline routine! */
XX
XXadd_reminder()
XX{
XX	printf("Enter %s then ^d to exit:\n", entity);
XX
XX	sprintf(cmd, "%s %s","/bin/cat >>",fname);
XX	system(cmd);
XX	if ( (adisplay && rem_work) || (Adisplay && !rem_work) )
XX		print_reminders();
XX}
XX
XX
XX/* DELETE REMINDERS/NOTES/ALTERNATES */
XX
XXdelete_reminder(argc, argv)
XX	int	argc;
XX	char	*argv[];
XX{
XX	int	begin,
XX		end,
XX		delete_line[MAXLINES];
XX
XX	char	a[4], b[4];
XX
XX	register int	i	    = 0,
XX			j	    = 0,
XX			deleted     = 0,
XX			line_number = 0,
XX			printed     = 0;
XX
XX	argc--, argv++;
XX	for (;argc > 0; argc--, argv++) {
XX		if (alldigits(*argv)) {
XX			delete_line[atoi(*argv)] = 1;
XX		}
XX		else {
XX			i = rindex(*argv, '-');
XX			sscanf(i+1, "%s", b );
XX			j = ( strlen(*argv) - strlen(b) ) - 1;
XX			strncpy(a, *argv, j);
XX			a[j]='\0';
XX			begin = atoi(a);
XX			end   = atoi(b);
XX
XX			if (begin < end) {
XX				for (j = begin ; j < end+1 ; j++)
XX					delete_line[j] = 1;
XX			}
XX			else {
XX				printf("Illegal range specified.\n");
XX				exit(1);
XX			}
XX		}
XX	}
XX
XX	mktemp(rstmp);
XX	if ((fptmp = fopen(rstmp,"w")) == NULL) {
XX		print_open_error_exit(rstmp);
XX	}
XX
XX	if ((fp = fopen(fname,"r")) == NULL) {
XX		print_open_error_exit(fname);
XX	}
XX
XX	while (getline(s, MAXLEN) > 0) {
XX		if (delete_line[++line_number] != 1) {
XX			fprintf(fptmp,"%s",s);
XX			printed++;
XX		}
XX		else {
XX			deleted++;
XX		}
XX	}
XX
XX	fclose(fp);
XX	fclose(fptmp);
XX
XX	status = unlink(fname);
XX	if (status != 0) {
XX		printf("Can't remove file - %s", fname);
XX		exit(1);
XX	}
XX
XX	if (printed) {
XX		if ((fp = fopen(fname,"w")) == NULL) {
XX			print_open_error_exit(fname);
XX		}
XX
XX		if ((fptmp = fopen(rstmp,"r")) == NULL) {
XX			print_open_error_exit(rstmp);
XX		}
XX
XX		while (fgets(s, MAXLEN, fptmp) != NULL) {
XX			fputs(s, fp);
XX		}
XX	}
XX
XX	fclose(fp);
XX	fclose(fptmp);
XX	status = unlink(rstmp);
XX
XX	if (deleted)
XX		printf("%d %s deleted.\n", deleted, entity );
XX
XX	if ( (ddisplay && rem_work) || (Ddisplay && !rem_work) )
XX		print_reminders();
XX}
XX
XX
XX/* PRINT REMINDERS/NOTES/ALTERNATES */
XX/* This routine will print reminders/notes/alternates */
XX/* print_line is called to do the printing with */
XX/* auto wrap.  If a search argument was given, only lines that contain the */
XX/* search string will be printed. */
XX
XXprint_reminders()
XX{
XX	register int line_number = 0;
XX
XX	if ((fp = fopen(fname,"r")) == NULL) {
XX		exit(0);
XX	}
XX
XX	if (tcap) {
XX		if (tgetent(buff, getenv("TERM")) == 1) {
XX			tcapok++;
XX			columns = tgetnum("co");
XX			if (columns <= 0)
XX				columns = 80;
XX			columns -= 6;
XX			a = on;
XX			tgetstr(mark_on,  &a);
XX			a = off;
XX			tgetstr(mark_off, &a);
XX			if (!strlen(on)) {
XX				if (tgetflag("bs"))
XX					strcpy(on, "\010*");
XX				else {
XX					a = on;
XX					tgetstr("bc", &a);
XX				}
XX			}
XX		}
XX	}
XX		
XX	printf("\n%s:\n", entity);
XX
XX	while ((len = getline(s, MAXLEN)) > 0) {
XX		if (search) {
XX			if (instr(s, sstr) != -1) {
XX				printf("%3d. ", ++line_number);
XX				if (tcapok)
XX					find_mark();
XX				if (mark)
XX					printf("%s", on);
XX				print_line(s, columns);
XX				if (mark) {
XX					printf("%s", off);
XX					mark = 0;
XX				}
XX			}
XX			else
XX				line_number++;
XX		}
XX		else {
XX			printf("%3d. ", ++line_number);
XX			if (tcapok)
XX				find_mark();
XX			if (mark)
XX				printf("%s", on);
XX			print_line(s, columns);
XX			if (mark) {
XX				printf("%s", off);
XX				mark = 0;
XX			}
XX		}
XX	}
XX
XX	printf("\n");
XX
XX	fclose(fp);
XX}
XX
XXgetline(s, lim)
XXchar s[];
XXint  lim;
XX{
XX	register int i = 0;
XX	register int c;
XX
XX	while (--lim > 0 && (c=getc(fp)) != EOF && c != '\n')
XX		s[i++] = c;
XX
XX	if (c == '\n')
XX		s[i++] = c;
XX
XX	s[i] = '\0';
XX
XX	return(i);
XX}
XX
XXalldigits(s)
XXregister char *s;
XX{
XX	register c = *s++;
XX
XX	do {
XX	if (!isdigit(c))
XX		return(0);
XX	}
XX	while (c = *s++);
XX
XX	return(1);
XX}
XX
XXinstr(s, t)
XXchar s[], t[];
XX{
XX	register int i, j, k;
XX
XX	for (i = 0; s[i] != '\0' ; i++) {
XX		for (j=i, k=0 ; t[k] != '\0' && s[j]==t[k] ; j++ , k++)
XX			;
XX		if (t[k] == '\0')
XX			return(i);
XX	}
XX	return(-1);
XX}
XX
XXprint_open_error_exit(file_name)
XXchar	file_name[];
XX{
XX	printf("Can't open file - %s\n",file_name);
XX	exit(1);
XX}
XX
XX/* This routine will wrap lines greater than 75 characters long.      */
XX/* An attempt is made to break the line up after a word.  If a "word" */
XX/* is greater than 75 characters, the word will be split.             */ 
XX/* 	pur-ee!mjs						      */
XX
XX#define SPACE	' '
XXint print_line (line, maxlen)
XXchar    line[];			/* string to be printed */
XXunsigned int    maxlen;		/* longest line permitted for output */
XX{
XX    register int    index,	/* used in for loops */
XX                    breaking_pt,/* index in line[] at point to break line 
XX				*/
XX                    nospace = 0,/* set to TRUE if no space is found */
XX                    last_br_pt = 0,/* last breaking point */
XX                    line_len,	/* number of characters in line[] */
XX                    done = 0;	/* set to TRUE if finished */
XX
XX /* if line[] isn't longer than the longest line permitted, we can just
XX    print it, and return. */
XX
XX    line_len = strlen (line);
XX
XX    if (strlen (line) <= maxlen) {
XX	printf ("%s", line);
XX	return;
XX    }
XX
XX    do {
XX    /* set breaking_pt at point in line[] where we should break the line.
XX       Do this by start looking backwards from maxlen until a space is
XX       found. */
XX
XX	for (index = (maxlen + last_br_pt); line[index] != SPACE; --index) {
XX	    if (index == last_br_pt) {
XX		nospace = 1;
XX		break;
XX	    }
XX	    if (index >= line_len) {
XX		index = line_len - 1;   /* 1 gets added to it below */
XX		done = 1;
XX		break;
XX	    }
XX	}
XX	breaking_pt = index + 1;
XX
XX    /* if there is no space found, set breaking point to MAXLEN */
XX
XX	if (nospace == 1) {
XX	    breaking_pt = maxlen + last_br_pt;
XX	    nospace = 0;	/* reset flag */
XX	}
XX    /* print line[] up to breaking point */
XX
XX	for (index = last_br_pt; index < breaking_pt; ++index) 
XX	    putchar (line[index]);
XX
XX
XX    	if (last_br_pt == 0) /* this is our first time through */
XX    		maxlen -= 5; /* for indenting */
XX    	if (!done) {
XX		if (mark)
XX			printf("%s", off);
XX
XX    		printf("\n     "); /* indent */
XX
XX		if (mark)
XX			printf("%s", on);
XX	}
XX
XX	last_br_pt = breaking_pt;
XX    } while (!done);
XX}
XXfind_mark()
XX{
XX	if (s[len-2] == '\07') {
XX		mark = 1;
XX		s[len-2] = '\n';
XX		s[len-1] = '\0';
XX	}
XX}
SHAR_EOF
if test 13652 -ne "`wc -c < 'rs.c'`"
then
	echo shar: "error transmitting 'rs.c'" '(should have been 13652 characters)'
fi
fi
echo shar: "extracting 'rs.1'" '(5288 characters)'
if test -f 'rs.1'
then
	echo shar: "will not over-write existing file 'rs.1'"
else
sed 's/^XX//' << \SHAR_EOF > 'rs.1'
XX.TH RS 1 "3 July 1986"
XX.ad b
XX.SH NAME
XXrs \- reminder system
XX.SH SYNOPSIS
XX.B rs
XX[
XX.B \-Aacknpv
XX] [
XX.B \-s
XX.I string
XX] [
XX.BI \-d \0# \0#-#
XX]
XX.SH DESCRIPTION
XX.I rs
XXis a personal reminder system.
XXReminders can be displayed every time you log into the system
XXby placing the
XX.I rs
XXcommand in your
XX.I .login
XXor
XX.I .profile
XXfile.
XXThe reminder system includes three reminder files:
XX.nf
XX
XX
XX	1.	Reminders  ($HOME/.reminders)
XX	2.	Notes      ($HOME/.rsnotes)
XX	3.	User defined by setting the RSALT environment variable.
XX		(Defaults to $HOME/.phone_numbers)
XX.fi
XX.PP
XX.I Options:
XX.TP
XX.I rs
XXWith no options, print reminder list to terminal.
XX.TP
XX.B \-A
XXWork with
XX.I alternate
XXreminder file.
XXThe name of the alternate file is user defined by setting the
XX.I RSALT
XXenvironment variable.  (If
XX.I RSALT
XXis not set, the alternate file defaults to 'phone_numbers'.)
XX.TP
XX.B \-a
XXAdd reminders/notes/alternates.
XXYou are prompted to add reminders/notes/alternates.  Appending a ^G (Control-G)
XXat the end of a reminder will cause rs to mark it (Highlight) during display.  (See
XX.I RSINIT
XXbelow.)
XX.TP
XX.B \-c
XXAdd entries to calendar system.  You are prompted to add calendar entries.
XXSee
XX.I calendar(1).
XX.TP
XX.B \-d
XXDelete reminders/notes/alternates.  This option, followed by a number or
XXnumbers, causes
XX.I rs
XXto delete the specified reminders/notes/alternates.
XXMore than one number may be placed on the same command line separated by
XXblanks.
XXA range of numbers may also be specified.
XX.TP
XX.B \-e
XXEdit reminders/notes/alternates file.  If the EDITOR environment variable is
XXset, the specified EDITOR is used.  If not, vi is used by default. (-v may be
XXused in place of -e)
XX.TP
XX.B \-k
XXKill (delete) all reminders/notes/alternates.
XX.TP
XX.B \-n
XXWork on
XX.I notes
XXfile.
XX.TP
XX.B \-p
XXPrint reminders/notes/alternates.
XX(By default, does an
XX.I lpr
XXof reminder file.)
XX.TP
XX.B \-s
XXSearch for reminders/notes/alternates that match the given string.
XX.PP
XXMore than one option may follow a single "\-", for example:
XX.nf
XX.RS
XX
XXrs -na    The command for "add note."
XX.RE
XX.fi
XX.PP
XX.SH NOTES
XXTo mark a reminder (Highlight), append a ^G (Control-G) to the reminder.
XX.I rs
XXwill mark the reminder during display using one of the following:
XX.nf
XX
XX
XX	Standout
XX	Underscore.
XX	Bold
XX	Asterisk
XX
XX.fi
XXas defined in
XX.I RSINIT.
XX.PP
XX.I rs
XXlooks in the environment variable
XX.I RSINIT
XXfor additional configuration options.  Options are:
XX.nf
XX
XX
XXA	Display notes/alternates/calendar after additions.
XXD	Display notes/alternates/calendar after deletions.
XXa	Display reminders after additions.
XXd	Display reminders after deletions.
XXI	Ignore TERMCAP info during startup.
XX	(Default number of columns is 80, no mark capability)
XX
XXDefault mark is standout mode.
XX	('so' and 'se' must be defined in termcap entry.)
XX
XXU	Use underscore (underline) to mark reminders.
XX	('us' and 'ue' must be defined in termcap entry.)
XXB	Use Bold to mark reminders.
XX	('bo' and 'be' must be defined in termcap entry.)
XXS	Use '*' to mark reminders.
XX	(Terminal must have 'bs'.)
XX.fi
XX.PP
XXFor example,
XXif you prefer to view your reminders/notes/alternates after
XXadditions/deletions, the
XX.I csh
XXcommand:
XX.nf
XX
XX
XX          setenv RSINIT 'aAdD'
XX
XX.fi
XXcauses
XX.I rs
XXto display your reminders/notes/alternates after additions/deletions.
XXThe above command sequence may be placed in your
XX.I .login
XXfile.
XX.PP
XXReminders/notes/alternates may be from one to 255 characters long.
XXIf a reminder is longer than one line (As defined in termcap 'co'),
XX.I rs
XXdoes automatic word wrap.
XXTo add a reminder/note/alternate longer than one line,
XXtype in the entire reminder/note/alternate and end with a single carriage
XXreturn.
XXDo
XX.B not
XXinsert carriage returns before the end of a reminder/note/alternate.
XXA single carriage return
XX.B always
XXindicates the
XX.B end
XXof a reminder.
XX.SH EXAMPLES
XX.TP
XXrs -d 1 5 8
XXDelete reminders 1, 5, 8.
XX.TP
XXrs -n -d 1-5 8
XXDelete notes 1, 2, 3, 4, 5, 8.
XX.TP
XXrs -k
XXKill all reminders.
XX.SH EXAMPLE USE OF ALTERNATE REMINDER FILE
XX.PP
XXIf you would like to have a list of phone numbers that can be accessed by the
XXreminder system, you can do the following:
XX.PP
XXSet the
XX.I RSALT
XXenvironment variable to
XX.I phone-numbers
XXby including the following command line in your
XX.I .login
XXfile:
XX.TP
XX.I "     setenv RSALT 'phone-numbers'"
XX.TP
XXUse the reminder system command:
XX.TP
XX.I "     rs -A [options]"
XX.TP
XXto work on the phone-numbers reminder file.
XX.SH EXAMPLE COMMANDS FOR PHONE-NUMBERS REMINDER FILE
XX.TP
XXrs \-A \-a
XXAdd phone numbers to the phone-numbers reminder file.
XX.TP
XXrs \-A \-s Joslyn
XXSearch for Joslyn's phone number.
XX.TP
XXrs \-A \-e
XXEdit phone-numbers.
XX.TP
XXrs \-A \-p
XXPrint phone-numbers on the line printer.
XX.TP
XXrs \-A \-d 1
XXDelete the first line from phone-numbers.
XX.SH TIPS
XXTo make use of the notes/alternates easier, the author defines two aliases:
XX.nf
XX
XXalias rsn 'rs -n'     Use rsn to work with notes file.
XXalias rsa 'rs -A'     Use rsa to work with alternate file.
XX.fi
XX.SH FILES
XX.nf
XX
XX$HOME/.reminders    User's reminders.
XX$HOME/.rsnotes      User's notes.
XX/tmp/.rs*           Used during reminder deletion.
XX$HOME/.?            Other reminder file(s) defined by RSALT.
XX.fi
XX.SH SEE ALSO
XXcalendar(1), csh(1), environ(7), lpr(1), vi(1)
XX.SH AUTHOR
XX.nf
XXDon Joslyn, Manager
XXNova University Computer Center
XX3301 College Avenue
XXFort Lauderdale, Florida 33314
XX(305) 475-7678
XX{codas, allegra, ucf-cs}!novavax!don
XX.fi
SHAR_EOF
if test 5288 -ne "`wc -c < 'rs.1'`"
then
	echo shar: "error transmitting 'rs.1'" '(should have been 5288 characters)'
fi
fi
exit 0
#	End of shell archive