=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/ifile.c,v retrieving revision 1.7 retrieving revision 1.8 diff -c -r1.7 -r1.8 *** src/usr.bin/less/ifile.c 2014/04/25 13:38:21 1.7 --- src/usr.bin/less/ifile.c 2015/11/05 22:08:44 1.8 *************** *** 6,19 **** * * For more information, see the README file. */ - /* * An IFILE represents an input file. * * It is actually a pointer to an ifile structure, * but is opaque outside this module. ! * Ifile structures are kept in a linked list in the order they * appear on the command line. * Any new file which does not already appear in the list is * inserted after the current file. --- 6,22 ---- * * For more information, see the README file. */ + /* + * Modified for use with illumos. + * Copyright 2014 Garrett D'Amore + */ /* * An IFILE represents an input file. * * It is actually a pointer to an ifile structure, * but is opaque outside this module. ! * Ifile structures are kept in a linked list in the order they * appear on the command line. * Any new file which does not already appear in the list is * inserted after the current file. *************** *** 38,69 **** * Convert an IFILE (external representation) * to a struct file (internal representation), and vice versa. */ ! #define int_ifile(h) ((struct ifile *)(h)) ! #define ext_ifile(h) ((IFILE)(h)) /* * Anchor for linked list. */ static struct ifile anchor = { &anchor, &anchor, NULL, NULL, 0, 0, '\0', ! { NULL_POSITION, 0 } }; static int ifiles = 0; ! static void ! incr_index(p, incr) ! register struct ifile *p; ! int incr; { ! for (; p != &anchor; p = p->h_next) p->h_index += incr; } /* * Link an ifile into the ifile list. */ ! static void ! link_ifile(p, prev) ! struct ifile *p; ! struct ifile *prev; { /* * Link into list. --- 41,68 ---- * Convert an IFILE (external representation) * to a struct file (internal representation), and vice versa. */ ! #define int_ifile(h) ((struct ifile *)(h)) ! #define ext_ifile(h) ((IFILE)(h)) /* * Anchor for linked list. */ static struct ifile anchor = { &anchor, &anchor, NULL, NULL, 0, 0, '\0', ! { -1, 0 } }; static int ifiles = 0; ! static void ! incr_index(struct ifile *p, int incr) { ! for (; p != &anchor; p = p->h_next) p->h_index += incr; } /* * Link an ifile into the ifile list. */ ! static void ! link_ifile(struct ifile *p, struct ifile *prev) { /* * Link into list. *************** *** 82,94 **** incr_index(p->h_next, 1); ifiles++; } ! /* * Unlink an ifile from the ifile list. */ ! static void ! unlink_ifile(p) ! struct ifile *p; { p->h_next->h_prev = p->h_prev; p->h_prev->h_next = p->h_next; --- 81,92 ---- incr_index(p->h_next, 1); ifiles++; } ! /* * Unlink an ifile from the ifile list. */ ! static void ! unlink_ifile(struct ifile *p) { p->h_next->h_prev = p->h_prev; p->h_prev->h_next = p->h_next; *************** *** 102,120 **** * (or at the beginning of the list if "prev" is NULL). * Return a pointer to the new ifile structure. */ ! static struct ifile * ! new_ifile(filename, prev) ! char *filename; ! struct ifile *prev; { ! register struct ifile *p; /* * Allocate and initialize structure. */ ! p = (struct ifile *) ecalloc(1, sizeof(struct ifile)); p->h_filename = save(filename); ! p->h_scrpos.pos = NULL_POSITION; p->h_opened = 0; p->h_hold = 0; p->h_filestate = NULL; --- 100,116 ---- * (or at the beginning of the list if "prev" is NULL). * Return a pointer to the new ifile structure. */ ! static struct ifile * ! new_ifile(char *filename, struct ifile *prev) { ! struct ifile *p; /* * Allocate and initialize structure. */ ! p = ecalloc(1, sizeof (struct ifile)); p->h_filename = save(filename); ! p->h_scrpos.pos = -1; p->h_opened = 0; p->h_hold = 0; p->h_filestate = NULL; *************** *** 125,135 **** /* * Delete an existing ifile structure. */ ! public void ! del_ifile(h) ! IFILE h; { ! register struct ifile *p; if (h == NULL_IFILE) return; --- 121,130 ---- /* * Delete an existing ifile structure. */ ! void ! del_ifile(IFILE h) { ! struct ifile *p; if (h == NULL_IFILE) return; *************** *** 149,159 **** /* * Get the ifile after a given one in the list. */ ! public IFILE ! next_ifile(h) ! IFILE h; { ! register struct ifile *p; p = (h == NULL_IFILE) ? &anchor : int_ifile(h); if (p->h_next == &anchor) --- 144,153 ---- /* * Get the ifile after a given one in the list. */ ! IFILE ! next_ifile(IFILE h) { ! struct ifile *p; p = (h == NULL_IFILE) ? &anchor : int_ifile(h); if (p->h_next == &anchor) *************** *** 164,174 **** /* * Get the ifile before a given one in the list. */ ! public IFILE ! prev_ifile(h) ! IFILE h; { ! register struct ifile *p; p = (h == NULL_IFILE) ? &anchor : int_ifile(h); if (p->h_prev == &anchor) --- 158,167 ---- /* * Get the ifile before a given one in the list. */ ! IFILE ! prev_ifile(IFILE h) { ! struct ifile *p; p = (h == NULL_IFILE) ? &anchor : int_ifile(h); if (p->h_prev == &anchor) *************** *** 179,190 **** /* * Return a different ifile from the given one. */ ! public IFILE ! getoff_ifile(ifile) ! IFILE ifile; { IFILE newifile; ! if ((newifile = prev_ifile(ifile)) != NULL_IFILE) return (newifile); if ((newifile = next_ifile(ifile)) != NULL_IFILE) --- 172,182 ---- /* * Return a different ifile from the given one. */ ! IFILE ! getoff_ifile(IFILE ifile) { IFILE newifile; ! if ((newifile = prev_ifile(ifile)) != NULL_IFILE) return (newifile); if ((newifile = next_ifile(ifile)) != NULL_IFILE) *************** *** 195,202 **** /* * Return the number of ifiles. */ ! public int ! nifile() { return (ifiles); } --- 187,194 ---- /* * Return the number of ifiles. */ ! int ! nifile(void) { return (ifiles); } *************** *** 204,214 **** /* * Find an ifile structure, given a filename. */ ! static struct ifile * ! find_ifile(filename) ! char *filename; { ! register struct ifile *p; for (p = anchor.h_next; p != &anchor; p = p->h_next) if (strcmp(filename, p->h_filename) == 0) --- 196,205 ---- /* * Find an ifile structure, given a filename. */ ! static struct ifile * ! find_ifile(const char *filename) { ! struct ifile *p; for (p = anchor.h_next; p != &anchor; p = p->h_next) if (strcmp(filename, p->h_filename) == 0) *************** *** 221,232 **** * If the filename has not been seen before, * insert the new ifile after "prev" in the list. */ ! public IFILE ! get_ifile(filename, prev) ! char *filename; ! IFILE prev; { ! register struct ifile *p; if ((p = find_ifile(filename)) == NULL) p = new_ifile(filename, int_ifile(prev)); --- 212,221 ---- * If the filename has not been seen before, * insert the new ifile after "prev" in the list. */ ! IFILE ! get_ifile(char *filename, IFILE prev) { ! struct ifile *p; if ((p = find_ifile(filename)) == NULL) p = new_ifile(filename, int_ifile(prev)); *************** *** 236,244 **** /* * Get the filename associated with a ifile. */ ! public char * ! get_filename(ifile) ! IFILE ifile; { if (ifile == NULL) return (NULL); --- 225,232 ---- /* * Get the filename associated with a ifile. */ ! char * ! get_filename(IFILE ifile) { if (ifile == NULL) return (NULL); *************** *** 248,279 **** /* * Get the index of the file associated with a ifile. */ ! public int ! get_index(ifile) ! IFILE ifile; { ! return (int_ifile(ifile)->h_index); } /* * Save the file position to be associated with a given file. */ ! public void ! store_pos(ifile, scrpos) ! IFILE ifile; ! struct scrpos *scrpos; { int_ifile(ifile)->h_scrpos = *scrpos; } /* * Recall the file position associated with a file. ! * If no position has been associated with the file, return NULL_POSITION. */ ! public void ! get_pos(ifile, scrpos) ! IFILE ifile; ! struct scrpos *scrpos; { *scrpos = int_ifile(ifile)->h_scrpos; } --- 236,262 ---- /* * Get the index of the file associated with a ifile. */ ! int ! get_index(IFILE ifile) { ! return (int_ifile(ifile)->h_index); } /* * Save the file position to be associated with a given file. */ ! void ! store_pos(IFILE ifile, struct scrpos *scrpos) { int_ifile(ifile)->h_scrpos = *scrpos; } /* * Recall the file position associated with a file. ! * If no position has been associated with the file, return -1. */ ! void ! get_pos(IFILE ifile, struct scrpos *scrpos) { *scrpos = int_ifile(ifile)->h_scrpos; } *************** *** 281,289 **** /* * Mark the ifile as "opened". */ ! public void ! set_open(ifile) ! IFILE ifile; { int_ifile(ifile)->h_opened = 1; } --- 264,271 ---- /* * Mark the ifile as "opened". */ ! void ! set_open(IFILE ifile) { int_ifile(ifile)->h_opened = 1; } *************** *** 291,347 **** /* * Return whether the ifile has been opened previously. */ ! public int ! opened(ifile) ! IFILE ifile; { return (int_ifile(ifile)->h_opened); } ! public void ! hold_ifile(ifile, incr) ! IFILE ifile; ! int incr; { int_ifile(ifile)->h_hold += incr; } ! #if !SMALL ! public int ! held_ifile(ifile) ! IFILE ifile; { return (int_ifile(ifile)->h_hold); } - #endif /* !SMALL */ ! public void * ! get_filestate(ifile) ! IFILE ifile; { return (int_ifile(ifile)->h_filestate); } ! public void ! set_filestate(ifile, filestate) ! IFILE ifile; ! void *filestate; { int_ifile(ifile)->h_filestate = filestate; } - - #if 0 - public void - if_dump() - { - register struct ifile *p; - - for (p = anchor.h_next; p != &anchor; p = p->h_next) - { - printf("%x: %d. <%s> pos %d,%x\n", - p, p->h_index, p->h_filename, - p->h_scrpos.ln, p->h_scrpos.pos); - ch_dump(p->h_filestate); - } - } - #endif --- 273,304 ---- /* * Return whether the ifile has been opened previously. */ ! int ! opened(IFILE ifile) { return (int_ifile(ifile)->h_opened); } ! void ! hold_ifile(IFILE ifile, int incr) { int_ifile(ifile)->h_hold += incr; } ! int ! held_ifile(IFILE ifile) { return (int_ifile(ifile)->h_hold); } ! void * ! get_filestate(IFILE ifile) { return (int_ifile(ifile)->h_filestate); } ! void ! set_filestate(IFILE ifile, void *filestate) { int_ifile(ifile)->h_filestate = filestate; }