rs - a personal reminder system
Don Joslyn
don at novavax.UUCP
Wed Jul 17 06:53:38 AEST 1985
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
More information about the Comp.sources.unix
mailing list