usenet@cps3xx.UUCP (Usenet file owner) (12/11/89)
Enclosed are the diffs to make index work on System V 3.2 along with the recently posted bug fix. ==larry diff -c ./WORK/Makefile ./Makefile *** ./WORK/Makefile Sun Dec 10 19:43:34 1989 --- ./Makefile Fri Nov 17 20:58:16 1989 *************** *** 16,22 **** # # CFLAGS= -O ! LIBS= -lcurses -ltermcap SRCS= createdb.c dbfunc.c dbio.c main.c printdb.c screen.c \ searchdb.c selectdb.c util.c --- 16,22 ---- # # CFLAGS= -O ! LIBS= -lcurses SRCS= createdb.c dbfunc.c dbio.c main.c printdb.c screen.c \ searchdb.c selectdb.c util.c Only in .: WORK diff -c ./WORK/createdb.c ./createdb.c *** ./WORK/createdb.c Sun Dec 10 19:43:36 1989 --- ./createdb.c Sun Dec 10 20:06:42 1989 *************** *** 19,24 **** --- 19,25 ---- #include <sys/param.h> #include <curses.h> #include <stdio.h> + #include <unistd.h> #include "defs.h" /* *************** *** 84,90 **** char *editor; char *getenv(); register int row; ! char buf[BUFSIZ], fname[MAXPATHLEN]; /* * Clear the screen and move to the top. --- 85,91 ---- char *editor; char *getenv(); register int row; ! char buf[BUFSIZ], fname[_POSIX_PATH_MAX]; /* * Clear the screen and move to the top. *************** *** 102,108 **** * Give the user a chance to read it. Wait till they * type a carriage return before proceeding. */ ! prompt_char(++row, 0, "Type RETURN to continue: ", "\n"); /* * Use the editor the user prefers, or EDITOR if --- 103,109 ---- * Give the user a chance to read it. Wait till they * type a carriage return before proceeding. */ ! prompt_char(++row, 0, "Type RETURN to continue: ", "\n\r"); /* * Use the editor the user prefers, or EDITOR if *************** *** 110,116 **** */ if ((editor = getenv("EDITOR")) == NULL) editor = EDITOR; ! /* * Construct the file name. */ --- 111,122 ---- */ if ((editor = getenv("EDITOR")) == NULL) editor = EDITOR; ! /* X_OK == 01 */ ! if (access(editor, X_OK) == -1) ! { ! error("%s: cannot execute.\n", editor, 0, 0); ! exit(1); ! } /* * Construct the file name. */ Only in .: createdb.o diff -c ./WORK/dbfunc.c ./dbfunc.c *** ./WORK/dbfunc.c Sun Dec 10 19:43:36 1989 --- ./dbfunc.c Sun Dec 10 19:49:29 1989 *************** *** 18,23 **** --- 18,24 ---- */ #include <curses.h> #include <stdio.h> + #include <memory.h> #include "defs.h" /* *************** *** 39,45 **** /* * Clear out any old junk. */ ! bzero(&db[i], sizeof(struct dbfile)); /* * Let the user edit the entry. --- 40,46 ---- /* * Clear out any old junk. */ ! memset(&db[i], 0, sizeof(struct dbfile)); /* * Let the user edit the entry. *************** *** 77,83 **** exit(1); } ! bzero(&db[dbentries], sizeof(struct dbfile)); /* * Let the user edit the new entry. --- 78,84 ---- exit(1); } ! memset(&db[dbentries], 0, sizeof(struct dbfile)); /* * Let the user edit the new entry. *************** *** 161,167 **** */ prompt_char(LINES/2, 0, "No entries match pattern, type RETURN to continue: ", ! "\n"); } } --- 162,168 ---- */ prompt_char(LINES/2, 0, "No entries match pattern, type RETURN to continue: ", ! "\n\r"); } } Only in .: dbfunc.o diff -c ./WORK/dbio.c ./dbio.c *** ./WORK/dbio.c Sun Dec 10 19:43:37 1989 --- ./dbio.c Sun Dec 10 19:37:56 1989 *************** *** 16,25 **** --- 16,27 ---- * Initial revision * */ + #include <sys/types.h> #include <sys/param.h> #include <sys/stat.h> #include <curses.h> #include <stdio.h> + #include <memory.h> #include "defs.h" struct dbfile *db; /* array of database entries */ *************** *** 27,32 **** --- 29,35 ---- int dbmodified = 0; /* non-zero if database needs saving */ int dbentries, dbsize; /* number of entries, size of db array */ + FILE *fopen(); /* * read_idxfile - read the database description file. *************** *** 36,42 **** { FILE *fp; register int len; ! char buf[BUFSIZ], idxfile[MAXPATHLEN]; /* * Construct the file name. --- 39,45 ---- { FILE *fp; register int len; ! char buf[BUFSIZ], idxfile[_POSIX_PATH_MAX]; /* * Construct the file name. *************** *** 54,60 **** /* * Zero out the structure. */ ! bzero(&idx, sizeof(struct idxfile)); /* * Read lines from the file. --- 57,63 ---- /* * Zero out the structure. */ ! memset(&idx, 0, sizeof(struct idxfile)); /* * Read lines from the file. *************** *** 114,121 **** { FILE *fp; register int i; struct dbfile *malloc(), *realloc(); ! char buf[BUFSIZ], dbfile[MAXPATHLEN]; /* * Allocate some entries in the array. 16 is just an --- 117,125 ---- { FILE *fp; register int i; + int j; struct dbfile *malloc(), *realloc(); ! char buf[BUFSIZ], dbfile[_POSIX_PATH_MAX]; /* * Allocate some entries in the array. 16 is just an *************** *** 128,134 **** error("%s: out of memory.\n", pname, 0, 0); exit(1); } ! /* * Construct the name of the file. */ --- 132,141 ---- error("%s: out of memory.\n", pname, 0, 0); exit(1); } ! for (j = 0; j < dbsize; j++) ! { ! db[j].db_flag = 0; ! } /* * Construct the name of the file. */ *************** *** 157,162 **** --- 164,174 ---- } } + for (j = dbentries; j < dbsize; j++) + { + db[j].db_flag = 0; + } + /* * Read in one entry at a time. */ *************** *** 204,210 **** FILE *fp; struct stat st; register int i, j; ! char realfile[MAXPATHLEN], bakfile[MAXPATHLEN]; /* * If it doesn't need saving, never mind. --- 216,222 ---- FILE *fp; struct stat st; register int i, j; ! char realfile[_POSIX_PATH_MAX], bakfile[_POSIX_PATH_MAX]; /* * If it doesn't need saving, never mind. *************** *** 258,264 **** * Set the file mode to the mode of the original * file. Mark the database as unmodified. */ ! fchmod(fileno(fp), st.st_mode & 0777); dbmodified = 0; fclose(fp); --- 270,276 ---- * Set the file mode to the mode of the original * file. Mark the database as unmodified. */ ! chmod(realfile, st.st_mode & 0777); dbmodified = 0; fclose(fp); Only in .: dbio.o diff -c ./WORK/defs.h ./defs.h *** ./WORK/defs.h Sun Dec 10 19:43:37 1989 --- ./defs.h Fri Nov 17 21:13:27 1989 *************** *** 20,26 **** #define MAXDBFILES 64 /* max. no. of database files */ #define MAXDBLINES 16 /* max. no. of fields in dbase */ ! #define EDITOR "/usr/ucb/vi" /* editor to use when creating */ #define INDEXDIR ".index" /* directory where stuff is */ #define DBFILE_SUFFIX ".db" /* database file suffix */ --- 20,26 ---- #define MAXDBFILES 64 /* max. no. of database files */ #define MAXDBLINES 16 /* max. no. of fields in dbase */ ! #define EDITOR "/usr/bin/vi" /* editor to use when creating */ #define INDEXDIR ".index" /* directory where stuff is */ #define DBFILE_SUFFIX ".db" /* database file suffix */ *************** *** 47,53 **** * Usually defined in ttychars.h. */ #ifndef CTRL ! #define CTRL(c) ('c' & 037) #endif /* --- 47,53 ---- * Usually defined in ttychars.h. */ #ifndef CTRL ! #define CTRL(c) (c & 037) #endif /* Only in .: index.diff diff -c ./WORK/main.c ./main.c *** ./WORK/main.c Sun Dec 10 19:43:39 1989 --- ./main.c Sun Dec 10 19:42:59 1989 *************** *** 14,19 **** --- 14,23 ---- * $Log: main.c,v $ * Revision 1.1 89/08/09 11:06:42 davy * Initial revision + * + * Ported to System V on SCO UNIX 3.2 {mailrus, uunet}!frith!lunapark!larry + * 12/10/89 + * also added fixes by ray@physics.purdue.edu from 12/9/89 * */ #include <sys/param.h> *************** *** 25,31 **** int verbose = 0; /* non-zero if -v flag given */ char *pname; /* program name */ ! char dbasedir[MAXPATHLEN]; /* path to database directory */ main(argc, argv) char **argv; --- 29,35 ---- int verbose = 0; /* non-zero if -v flag given */ char *pname; /* program name */ ! char dbasedir[_POSIX_PATH_MAX]; /* path to database directory */ main(argc, argv) char **argv; Only in .: main.o diff -c ./WORK/printdb.c ./printdb.c *** ./WORK/printdb.c Sun Dec 10 19:43:39 1989 --- ./printdb.c Fri Nov 17 21:09:00 1989 *************** *** 16,23 **** * Initial revision * */ ! #include <sys/file.h> #include <stdio.h> #include "defs.h" /* --- 16,24 ---- * Initial revision * */ ! #include <fcntl.h> #include <stdio.h> + #include <unistd.h> #include "defs.h" /* Only in .: printdb.o Common subdirectories: ./WORK/samples and ./samples diff -c ./WORK/screen.c ./screen.c *** ./WORK/screen.c Sun Dec 10 19:43:47 1989 --- ./screen.c Sun Dec 10 19:53:12 1989 *************** *** 20,25 **** --- 20,26 ---- #include <signal.h> #include <curses.h> #include <stdio.h> + #include <memory.h> #include "defs.h" static int screen_inited = 0; /* for use with set/reset modes */ *************** *** 66,79 **** */ while ((c = getchar()) != EOF) { switch (c) { ! case CTRL(a): /* beginning of line */ col = col0; break; ! case CTRL(b): /* back character */ if (col > col0) col--; break; ! case CTRL(d): /* delete character */ /* * If there's stuff in the string, * delete this character. --- 67,80 ---- */ while ((c = getchar()) != EOF) { switch (c) { ! case CTRL('a'): /* beginning of line */ col = col0; break; ! case CTRL('b'): /* back character */ if (col > col0) col--; break; ! case CTRL('d'): /* delete character */ /* * If there's stuff in the string, * delete this character. *************** *** 102,115 **** } break; ! case CTRL(e): /* end of line */ col = col0 + len; break; ! case CTRL(f): /* forward character */ if ((col - col0) < len) col++; break; ! case CTRL(h): /* backspace delete */ case '\177': /* * If there's stuff in the string, --- 103,116 ---- } break; ! case CTRL('e'): /* end of line */ col = col0 + len; break; ! case CTRL('f'): /* forward character */ if ((col - col0) < len) col++; break; ! case CTRL('h'): /* backspace delete */ case '\177': /* * If there's stuff in the string, *************** *** 139,145 **** delch(); } break; ! case CTRL(k): /* kill line */ /* * Clear the string. */ --- 140,146 ---- delch(); } break; ! case CTRL('k'): /* kill line */ /* * Clear the string. */ *************** *** 152,160 **** clrtoeol(); } break; ! case CTRL(l): /* redraw screen */ wrefresh(curscr); break; case '\n': /* return the string */ line[len] = '\0'; return; --- 153,162 ---- clrtoeol(); } break; ! case CTRL('l'): /* redraw screen */ wrefresh(curscr); break; + case '\r': case '\n': /* return the string */ line[len] = '\0'; return; *************** *** 163,169 **** * If it's the user's line-kill character, * we'll accept that to kill the line too. */ ! if (c == _tty.sg_kill) { move(row, col0); clrtoeol(); col = col0; --- 165,171 ---- * If it's the user's line-kill character, * we'll accept that to kill the line too. */ ! if (c == killchar()) { move(row, col0); clrtoeol(); col = col0; *************** *** 170,211 **** *line = '\0'; len = 0; ! } ! else { /* ! * If it's a printable character, ! * insert it into the string. */ ! if ((c >= ' ') && (c < '\177')) { ! /* ! * Calculate position of character ! * in string. ! */ ! i = col - col0; ! ! /* ! * If we have to, move the ! * string "right" one place ! * to insert the character. ! */ ! if (i < len) { ! for (j = len; j >= i; j--) ! line[j+1] = line[j]; ! } ! ! line[i] = c; ! len += 1; ! col++; ! ! /* ! * Insert the character on the ! * screen. ! */ ! insch(c); ! ! } ! } ! break; } /* --- 172,212 ---- *line = '\0'; len = 0; ! } ! /* ! * If it's a printable character, ! * insert it into the string. ! */ ! if ((c >= ' ') && (c < '\177')) { /* ! * Calculate position of character ! * in string. */ ! i = col - col0; ! ! /* ! * If we have to, move the ! * string "right" one place ! * to insert the character. ! */ ! if (i < len) { ! for (j = len; j >= i; j--) ! line[j+1] = line[j]; ! } ! ! line[i] = c; ! len += 1; ! col++; ! ! /* ! * Insert the character on the ! * screen. ! */ ! insch(c); ! ! } ! ! break; } /* *************** *** 224,230 **** char *promptstr, *valid; int row, col; { ! char *index(); register int c; /* --- 225,231 ---- char *promptstr, *valid; int row, col; { ! char *strchr(); register int c; /* *************** *** 242,248 **** * If it's not a valid one, beep * and get another one. */ ! if (index(valid, c) == NULL) { putc('\007', stdout); fflush(stdout); continue; --- 243,249 ---- * If it's not a valid one, beep * and get another one. */ ! if (strchr(valid, c) == NULL) { putc('\007', stdout); fflush(stdout); continue; *************** *** 332,338 **** case 'x': byebye(); break; ! case CTRL(l): /* redraw screen */ wrefresh(curscr); break; } --- 333,339 ---- case 'x': byebye(); break; ! case CTRL('l'): /* redraw screen */ wrefresh(curscr); break; } *************** *** 408,419 **** * See what they want to do with this entry. */ c = prompt_char(idx.idx_nlines+6, 0, "Command: ", ! "-deq\n\014"); /* * Dispatch the command... */ switch (c) { case '\n': /* go to next entry */ /* * Save this one. --- 409,421 ---- * See what they want to do with this entry. */ c = prompt_char(idx.idx_nlines+6, 0, "Command: ", ! "-deq\n\r\014"); /* * Dispatch the command... */ switch (c) { + case '\r': case '\n': /* go to next entry */ /* * Save this one. *************** *** 538,544 **** * memory. */ tmp.db_lens[i] = entry->db_lens[i]; ! bzero(tmp.db_lines[i], BUFSIZ); /* * Copy and print the line from the entry. --- 540,546 ---- * memory. */ tmp.db_lens[i] = entry->db_lens[i]; ! memset(tmp.db_lines[i], 0, BUFSIZ); /* * Copy and print the line from the entry. *************** *** 567,580 **** len = &tmp.db_lens[row]; switch (c) { ! case CTRL(a): /* beginning of line */ col = col0; break; ! case CTRL(b): /* back character */ if (col > col0) col--; break; ! case CTRL(d): /* delete character */ if (*len) { /* * Calculate position of character --- 569,582 ---- len = &tmp.db_lens[row]; switch (c) { ! case CTRL('a'): /* beginning of line */ col = col0; break; ! case CTRL('b'): /* back character */ if (col > col0) col--; break; ! case CTRL('d'): /* delete character */ if (*len) { /* * Calculate position of character *************** *** 599,612 **** } break; ! case CTRL(e): /* end of line */ col = col0 + *len; break; ! case CTRL(f): /* forward character */ if ((col - col0) < *len) col++; break; ! case CTRL(h): /* backspace delete */ case '\177': if (*len) { /* --- 601,614 ---- } break; ! case CTRL('e'): /* end of line */ col = col0 + *len; break; ! case CTRL('f'): /* forward character */ if ((col - col0) < *len) col++; break; ! case CTRL('h'): /* backspace delete */ case '\177': if (*len) { /* *************** *** 632,638 **** delch(); } break; ! case CTRL(k): /* kill line */ /* * Kill the line. */ --- 634,640 ---- delch(); } break; ! case CTRL('k'): /* kill line */ /* * Kill the line. */ *************** *** 645,654 **** clrtoeol(); } break; ! case CTRL(l): /* redraw screen */ wrefresh(curscr); break; ! case CTRL(n): /* next line */ /* * Wrap around to the top if necessary. */ --- 647,656 ---- clrtoeol(); } break; ! case CTRL('l'): /* redraw screen */ wrefresh(curscr); break; ! case CTRL('n'): /* next line */ /* * Wrap around to the top if necessary. */ *************** *** 662,668 **** if ((col - col0) > tmp.db_lens[row]) col = col0 + tmp.db_lens[row]; break; ! case CTRL(p): /* previous line */ /* * Wrap around if necessary. */ --- 664,670 ---- if ((col - col0) > tmp.db_lens[row]) col = col0 + tmp.db_lens[row]; break; ! case CTRL('p'): /* previous line */ /* * Wrap around if necessary. */ *************** *** 676,692 **** if ((col - col0) > tmp.db_lens[row]) col = col0 + tmp.db_lens[row]; break; ! case CTRL([): /* save entry */ /* * Prompt for whether to save the entry. */ sprintf(tbuf, "Save %s entry in database? ", word); ! c = prompt_char(idx.idx_nlines+2, 0, tbuf, "YyNn\n"); /* * See what they said. */ switch (c) { case '\n': /* never mind */ move(idx.idx_nlines+2, 0); clrtoeol(); --- 678,695 ---- if ((col - col0) > tmp.db_lens[row]) col = col0 + tmp.db_lens[row]; break; ! case CTRL('['): /* save entry */ /* * Prompt for whether to save the entry. */ sprintf(tbuf, "Save %s entry in database? ", word); ! c = prompt_char(idx.idx_nlines+2, 0, tbuf, "YyNn\r\n"); /* * See what they said. */ switch (c) { + case '\r': case '\n': /* never mind */ move(idx.idx_nlines+2, 0); clrtoeol(); *************** *** 717,722 **** --- 720,726 ---- return(0); } break; + case '\r': case '\n': /* go to next line */ /* * Wrap around if necessary. *************** *** 730,736 **** * If it's the user's kill character, we'll * accept that to delete the line too. */ ! if (c == _tty.sg_kill) { move(row, col0); clrtoeol(); col = col0; --- 734,741 ---- * If it's the user's kill character, we'll * accept that to delete the line too. */ ! ! if (c == killchar()) { move(row, col0); clrtoeol(); col = col0; *************** *** 738,775 **** *line = '\0'; *len = 0; } ! else { /* ! * If it's a printable character, insert ! * it into the string. */ ! if ((c >= ' ') && (c < '\177')) { ! /* ! * Calculate character position. ! */ ! i = col - col0; ! ! /* ! * If necessary, move the string ! * to the "right" to insert the ! * character. ! */ ! if (i < *len) { ! for (j = *len; j >= i; j--) ! line[j+1] = line[j]; ! } ! ! line[i] = c; ! *len += 1; ! col++; ! ! /* ! * Insert the character on the ! * screen. ! */ ! insch(c); } ! } break; } --- 743,779 ---- *line = '\0'; *len = 0; } ! ! /* ! * If it's a printable character, insert ! * it into the string. ! */ ! if ((c >= ' ') && (c < '\177')) { ! /* ! * Calculate character position. ! */ ! i = col - col0; ! /* ! * If necessary, move the string ! * to the "right" to insert the ! * character. */ ! if (i < *len) { ! for (j = *len; j >= i; j--) ! line[j+1] = line[j]; } ! ! line[i] = c; ! *len += 1; ! col++; ! ! /* ! * Insert the character on the ! * screen. ! */ ! insch(c); ! } break; } Only in .: screen.o diff -c ./WORK/searchdb.c ./searchdb.c *** ./WORK/searchdb.c Sun Dec 10 19:43:44 1989 --- ./searchdb.c Sun Dec 10 19:58:36 1989 *************** *** 28,37 **** char *pattern; { int code = 0; ! char *re_comp(); char buf[BUFSIZ]; register int i, j; ! register char *p, *q; /* * If we're ignoring case, convert the pattern --- 28,37 ---- char *pattern; { int code = 0; ! char *regcmp(), *regex(); char buf[BUFSIZ]; register int i, j; ! register char *p, *q, *ptr; /* * If we're ignoring case, convert the pattern *************** *** 47,54 **** /* * Compile the regular expression. */ ! if (re_comp(pattern) != NULL) return(0); /* * For all entries... --- 47,56 ---- /* * Compile the regular expression. */ ! if ((ptr = regcmp(pattern, (char *)0)) == NULL) ! { return(0); + } /* * For all entries... *************** *** 85,91 **** * If we get a match, mark this entry as * printable. */ ! if (re_exec(buf)) { db[i].db_flag |= DB_PRINT; code = 1; } --- 87,93 ---- * If we get a match, mark this entry as * printable. */ ! if (regex(ptr, buf)) { db[i].db_flag |= DB_PRINT; code = 1; } *************** *** 95,101 **** * If we get a match, mark this entry * as printable. */ ! if (re_exec(db[i].db_lines[j])) { db[i].db_flag |= DB_PRINT; code = 1; } --- 97,103 ---- * If we get a match, mark this entry * as printable. */ ! if (regex(ptr, db[i].db_lines[j])) { db[i].db_flag |= DB_PRINT; code = 1; } Only in .: searchdb.o diff -c ./WORK/selectdb.c ./selectdb.c *** ./WORK/selectdb.c Sun Dec 10 19:43:45 1989 --- ./selectdb.c Sun Dec 10 17:18:03 1989 *************** *** 16,23 **** * Initial revision * */ #include <sys/param.h> ! #include <sys/dir.h> #include <curses.h> #include <stdio.h> #include "defs.h" --- 16,24 ---- * Initial revision * */ + #include <sys/types.h> #include <sys/param.h> ! #include <dirent.h> #include <curses.h> #include <stdio.h> #include "defs.h" *************** *** 29,35 **** char * select_db() { ! char dbname[MAXPATHLEN]; char *dblist[MAXDBFILES]; register int ndbs, i, row, col, spread; --- 30,36 ---- char * select_db() { ! char dbname[_POSIX_PATH_MAX]; char *dblist[MAXDBFILES]; register int ndbs, i, row, col, spread; *************** *** 52,58 **** for (col = 0; col < 4; col++) { i = col * spread + row; ! if (dblist[i]) mvaddstr(row, col * COLS/4, dblist[i]); } } --- 53,60 ---- for (col = 0; col < 4; col++) { i = col * spread + row; ! /* if (dblist[i]) */ ! if (i < ndbs) mvaddstr(row, col * COLS/4, dblist[i]); } } *************** *** 88,97 **** { DIR *dp; int ndbs; ! char *rindex(); register char *s; extern int compare(); ! register struct direct *d; ndbs = 0; --- 90,99 ---- { DIR *dp; int ndbs; ! char *strrchr(); register char *s; extern int compare(); ! register struct dirent *d; ndbs = 0; *************** *** 111,117 **** * Search for a "." in the name, which marks * the suffix. */ ! if ((s = rindex(d->d_name, '.')) == NULL) continue; /* --- 113,119 ---- * Search for a "." in the name, which marks * the suffix. */ ! if ((s = strrchr(d->d_name, '.')) == NULL) continue; /* Only in .: selectdb.o Only in .: util.o LARRY SHIELDS USENET: ...!frith!lunapark!larry P.O. Box 6159 BIX: lshields E. Lansing, MI 48826 Compuserve: 70277,3677 ************lunapark bbs 2400/1200 8-1-N 24hrs (517) 487-3356************