2
#include <LYGlobalDefs.h>
7
#include <LYTraversal.h>
12
/* routines to handle special traversal feature */
14
PRIVATE void final_perror ARGS2(CONST char *,msg, BOOLEAN, clean_flag)
16
int saved_errno = errno;
23
set_errno(saved_errno);
27
PRIVATE void exit_with_perror ARGS1(CONST char *,msg)
29
final_perror(msg, TRUE);
30
exit_immediately(EXIT_FAILURE);
33
PUBLIC BOOLEAN lookup ARGS1(char *,target)
40
if ((ifp = fopen(TRAVERSE_FILE, TXT_R)) == NULL) {
41
if ((ifp = LYNewTxtFile(TRAVERSE_FILE)) == NULL) {
42
exit_with_perror(CANNOT_OPEN_TRAV_FILE);
49
HTSprintf0(&line, "%s\n", target);
51
while (LYSafeGets(&buffer, ifp) != NULL) {
52
if (STREQ(line,buffer)) {
61
return (BOOL) (result);
64
PUBLIC void add_to_table ARGS1(char *,target)
69
if ((ifp = LYAppendToTxtFile(TRAVERSE_FILE)) == NULL) {
70
exit_with_perror(CANNOT_OPEN_TRAV_FILE);
73
fprintf(ifp,"%s\n",target);
78
PUBLIC void add_to_traverse_list ARGS2(char *,fname, char *,prev_link_name)
83
if ((ifp = LYAppendToTxtFile(TRAVERSE_FOUND_FILE)) == NULL) {
84
exit_with_perror(CANNOT_OPEN_TRAF_FILE);
87
fprintf(ifp,"%s\t%s\n",fname, prev_link_name);
92
PUBLIC void dump_traversal_history NOARGS
100
if ((ifp = LYAppendToTxtFile(TRAVERSE_FILE)) == NULL) {
101
final_perror(CANNOT_OPEN_TRAV_FILE, FALSE);
105
fprintf(ifp, "\n\n%s\n\n\t %s\n\n",
106
TRAV_WAS_INTERRUPTED,
107
gettext("here is a list of the history stack so that you may rebuild"));
109
for (x = nhist-1; x >= 0; x--) {
110
fprintf(ifp, "%s\t%s\n", HDOC(x).title, HDOC(x).address);
116
PUBLIC void add_to_reject_list ARGS1(char *,target)
121
if ((ifp = LYAppendToTxtFile(TRAVERSE_REJECT_FILE)) == NULL) {
122
exit_with_perror(CANNOT_OPEN_REJ_FILE);
125
fprintf(ifp,"%s\n",target);
130
/* there need not be a reject file, so if it doesn't open, just return
131
FALSE, meaning "target not in reject file" If the last character in
132
a line in a reject file is "*", then also reject if target matches up to
133
that point in the string
134
Blank lines are ignored
135
Lines that contain just a * are allowed, but since they mean "reject
136
everything" it shouldn't come up much!
139
PUBLIC BOOLEAN lookup_reject ARGS1(char *,target)
147
if ((ifp = fopen(TRAVERSE_REJECT_FILE, TXT_R)) == NULL){
151
HTSprintf0(&line, "%s\n", target);
153
while (LYSafeGets(&buffer, ifp) != NULL && !result) {
154
LYTrimTrailing(buffer);
155
len = strlen(buffer);
156
if (len > 0) { /* if not an empty line */
157
if (buffer[len-1] == '*') {
158
/* if last char is * and the rest of the chars match */
159
if ((len == 1) || (strncmp(line,buffer,len - 1) == 0)) {
163
if (STREQ(line,buffer)) {
168
} /* end while loop over the file */
173
return (BOOL) (result);