Debian Codegraph @

texk/xdvik/gui/sfPath.c

raw
1 /*
2 * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
3 *
4 * Permission to use, copy, modify, and distribute this software and its
5 * documentation for any purpose and without fee is hereby granted, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Software Research Associates not be used
9 * in advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. Software Research Associates
11 * makes no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
16 * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
17 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
19 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 * Author: Erik M. van der Poel
23 * Software Research Associates, Inc., Tokyo, Japan
24 * [email protected]
25 */
26
27 #include "xdvi-config.h"
28
29 #include "kpathsea/c-auto.h"
30 #include "kpathsea/config.h"
31 #include "kpathsea/c-stat.h"
32
33 #include "xdvi.h"
34 #include "sfDir.h"
35 #include "sfDraw.h"
36 #include "sfPath.h"
37 #include "sfSelFile.h"
38
39 #if !defined(MOTIF) /* entire file */
40
41 #include <stdio.h>
42
43 #include <X11/Intrinsic.h>
44 #include <X11/StringDefs.h>
45 #include <X11/Xos.h>
46 #include <X11/Xaw/Text.h>
47 #include <X11/Xaw/AsciiText.h>
48 #include <X11/Xaw/Scrollbar.h>
49 #include <X11/Xaw/Cardinals.h>
50
51
52 #ifdef SEL_FILE_IGNORE_CASE
53 #include <ctype.h>
54 #endif /* def SEL_FILE_IGNORE_CASE */
55
56 #ifndef S_IXUSR
57 #define S_IXUSR 0100
58 #endif
59 #ifndef S_IXGRP
60 #define S_IXGRP 0010
61 #endif
62 #ifndef S_IXOTH
63 #define S_IXOTH 0001
64 #endif
65
66 #define S_ISXXX(m) ((m) & (S_IXUSR | S_IXGRP | S_IXOTH))
67
68 #include <X11/Xos.h>
69 #include <pwd.h>
70 #include <X11/Xaw/Scrollbar.h>
71
72 typedef struct {
73 const char *name;
74 const char *dir;
75 } SFLogin;
76
77 SFDir *SFdirs = NULL;
78
79 int SFdirEnd;
80
81 int SFdirPtr;
82
83 int SFbuttonPressed = 0;
84
85 static int SFdoNotTouchDirPtr = 0;
86
87 static int SFdoNotTouchVorigin = 0;
88
89 static SFDir SFrootDir, SFhomeDir;
90
91 static SFLogin *SFlogins;
92
93 static int SFtwiddle = 0;
94
95 int
96 SFchdir(const char *path)
97 {
98 int result;
99
100 result = 0;
101
102 if (strcmp(path, SFcurrentDir)) {
103 result = chdir(path);
104 if (!result) {
105 (void)strcpy(SFcurrentDir, path);
106 }
107 }
108
109 return result;
110 }
111
112 static void
113 SFfree(int i)
114 {
115 SFDir *dir;
116 int j;
117
118 dir = &(SFdirs[i]);
119
120 for (j = dir->nEntries - 1; j >= 0; j--) {
121 if (dir->entries[j].shown != dir->entries[j].real) {
122 XtFree(dir->entries[j].shown);
123 }
124 XtFree(dir->entries[j].real);
125 }
126
127 XtFree((char *)dir->entries);
128
129 XtFree(dir->dir);
130
131 dir->dir = NULL;
132 }
133
134 static char *
135 SFstrdup(const char *s2)
136 {
137 char *s1 = strcpy(XtMalloc((unsigned)(strlen(s2) + 1)), s2);
138 return s1;
139 }
140
141 static void
142 SFunreadableDir(SFDir *dir)
143 {
144 const char *cannotOpen = "<cannot open> ";
145
146 dir->entries = (SFEntry *) XtMalloc(sizeof(SFEntry));
147 dir->entries[0].statDone = 1;
148 dir->entries[0].real = SFstrdup(cannotOpen);
149 dir->entries[0].shown = dir->entries[0].real;
150 dir->nEntries = 1;
151 dir->nChars = strlen(cannotOpen);
152 }
153
154 #ifdef SEL_FILE_IGNORE_CASE
155 static
156 SFstrncmp(char *p, char *q, int n)
157 {
158 char c1, c2;
159 char *psave, *qsave;
160 int nsave;
161
162 psave = p;
163 qsave = q;
164 nsave = n;
165
166 c1 = *p++;
167 if (islower(c1)) {
168 c1 = toupper(c1);
169 }
170 c2 = *q++;
171 if (islower(c2)) {
172 c2 = toupper(c2);
173 }
174
175 while ((--n >= 0) && (c1 == c2)) {
176 if (!c1) {
177 return strncmp(psave, qsave, nsave);
178 }
179 c1 = *p++;
180 if (islower(c1)) {
181 c1 = toupper(c1);
182 }
183 c2 = *q++;
184 if (islower(c2)) {
185 c2 = toupper(c2);
186 }
187 }
188
189 if (n < 0) {
190 return strncmp(psave, qsave, nsave);
191 }
192
193 return c1 - c2;
194 }
195 #endif /* def SEL_FILE_IGNORE_CASE */
196
197 static void
198 SFreplaceText(SFDir *dir, char *str)
199 {
200 int len;
201
202 *(dir->path) = '\0';
203 len = strlen(str);
204
205 if (str[len - 1] == '/') {
206 (void)strcat(SFcurrentPath, str);
207 }
208 else {
209 char *p = SFcurrentPath + strlen(SFcurrentPath);
210
211 (void)memcpy(p, str, len - 1);
212 p[len - 1] = '\0';
213 }
214 /* if (strncmp(SFcurrentPath, SFstartDir, strlen(SFstartDir))) { */
215 /* SFsetText(SFcurrentPath); */
216 /* } */
217 /* else { */
218 /* SFsetText(&(SFcurrentPath[strlen(SFstartDir)])); */
219 /* } */
220 SFsetText(SFcurrentPath);
221
222 SFtextChanged();
223 }
224
225 static void
226 SFexpand(char *str)
227 {
228 int len;
229 int cmp;
230 char *name, *growing;
231 SFDir *dir;
232 SFEntry *entry, *max;
233
234 len = strlen(str);
235
236 dir = &(SFdirs[SFdirEnd - 1]);
237
238 if (dir->beginSelection == -1) {
239 str = SFstrdup(str);
240 SFreplaceText(dir, str);
241 XtFree(str);
242 return;
243 }
244 else if (dir->beginSelection == dir->endSelection) {
245 SFreplaceText(dir, dir->entries[dir->beginSelection].shown);
246 return;
247 }
248
249 max = &(dir->entries[dir->endSelection + 1]);
250
251 name = dir->entries[dir->beginSelection].shown;
252 growing = SFstrdup(name);
253
254 cmp = 0;
255 while (!cmp) {
256 entry = &(dir->entries[dir->beginSelection]);
257 while (entry < max) {
258 if ((cmp = strncmp(growing, entry->shown, len))) {
259 break;
260 }
261 entry++;
262 }
263 len++;
264 }
265
266 /*
267 * SFreplaceText() expects filename
268 */
269 growing[len - 2] = ' ';
270
271 growing[len - 1] = 0;
272 SFreplaceText(dir, growing);
273 XtFree(growing);
274 }
275
276 static int
277 SFfindFile(SFDir *dir, char *str)
278 {
279 int i, last, max;
280 char *name, save;
281 SFEntry *entries;
282 int len;
283 int begin, end;
284 int result;
285
286 len = strlen(str);
287
288 if (str[len - 1] == ' ') {
289 SFexpand(str);
290 return 1;
291 }
292 else if (str[len - 1] == '/') {
293 len--;
294 }
295
296 max = dir->nEntries;
297
298 entries = dir->entries;
299
300 i = 0;
301 while (i < max) {
302 name = entries[i].shown;
303 last = strlen(name) - 1;
304 save = name[last];
305 name[last] = 0;
306
307 #ifdef SEL_FILE_IGNORE_CASE
308 result = SFstrncmp(str, name, len);
309 #else /* def SEL_FILE_IGNORE_CASE */
310 result = strncmp(str, name, len);
311 #endif /* def SEL_FILE_IGNORE_CASE */
312
313 name[last] = save;
314 if (result <= 0) {
315 break;
316 }
317 i++;
318 }
319 begin = i;
320 while (i < max) {
321 name = entries[i].shown;
322 last = strlen(name) - 1;
323 save = name[last];
324 name[last] = 0;
325
326 #ifdef SEL_FILE_IGNORE_CASE
327 result = SFstrncmp(str, name, len);
328 #else /* def SEL_FILE_IGNORE_CASE */
329 result = strncmp(str, name, len);
330 #endif /* def SEL_FILE_IGNORE_CASE */
331
332 name[last] = save;
333 if (result) {
334 break;
335 }
336 i++;
337 }
338 end = i;
339
340 if (begin != end) {
341 if ((dir->beginSelection != begin) || (dir->endSelection != end - 1)
342 ) {
343 dir->changed = 1;
344 dir->beginSelection = begin;
345 if (str[strlen(str) - 1] == '/') {
346 dir->endSelection = begin;
347 }
348 else {
349 dir->endSelection = end - 1;
350 }
351 }
352 }
353 else {
354 if (dir->beginSelection != -1) {
355 dir->changed = 1;
356 dir->beginSelection = -1;
357 dir->endSelection = -1;
358 }
359 }
360
361 if (SFdoNotTouchVorigin ||
362 ((begin > dir->vOrigin) && (end < dir->vOrigin + SFlistSize))) {
363 SFdoNotTouchVorigin = 0;
364 return 0;
365 }
366
367 i = begin - 1;
368 if (i > max - SFlistSize) {
369 i = max - SFlistSize;
370 }
371 if (i < 0) {
372 i = 0;
373 }
374
375 if (dir->vOrigin != i) {
376 dir->vOrigin = i;
377 dir->changed = 1;
378 }
379
380 return 0;
381 }
382
383 static void
384 SFunselect(void)
385 {
386 SFDir *dir;
387
388 dir = &(SFdirs[SFdirEnd - 1]);
389 if (dir->beginSelection != -1) {
390 dir->changed = 1;
391 }
392 dir->beginSelection = -1;
393 dir->endSelection = -1;
394 }
395
396 static int
397 SFcompareLogins(const void *vp, const void *vq)
398 {
399 const SFLogin *p = vp;
400 const SFLogin *q = vq;
401 return strcmp(p->name, q->name);
402 }
403
404 static void
405 SFgetHomeDirs(void)
406 {
407 struct passwd *pw;
408 int alloc;
409 int i;
410 SFEntry *entries = NULL;
411 int len;
412 int maxChars;
413
414 {
415 alloc = 1;
416 i = 1;
417 entries = (SFEntry *) XtMalloc(sizeof(SFEntry));
418 SFlogins = (SFLogin *) XtMalloc(sizeof(SFLogin));
419 entries[0].real = XtMalloc(3);
420 (void)strcpy(entries[0].real, "~");
421 entries[0].shown = entries[0].real;
422 entries[0].statDone = 1;
423 SFlogins[0].name = "";
424 pw = getpwuid((int)getuid());
425 SFlogins[0].dir = SFstrdup(pw ? pw->pw_dir : "/");
426 maxChars = 0;
427 }
428
429 (void)setpwent();
430
431 while ((pw = (struct passwd *)getpwent()) && (*(pw->pw_name))) {
432 if (i >= alloc) {
433 alloc *= 2;
434 entries = (SFEntry *) XtRealloc(
435 (char *)entries,
436 (unsigned)(alloc *
437 sizeof(SFEntry)));
438 SFlogins =
439 (SFLogin *) XtRealloc((char *)SFlogins,
440 (unsigned)(alloc * sizeof(SFLogin))
441 );
442 }
443 len = strlen(pw->pw_name);
444 entries[i].real = XtMalloc((unsigned)(len + 3));
445 (void)strcat(strcpy(entries[i].real, "~"), pw->pw_name);
446 entries[i].shown = entries[i].real;
447 entries[i].statDone = 1;
448 if (len > maxChars) {
449 maxChars = len;
450 }
451 SFlogins[i].name = SFstrdup(pw->pw_name);
452 SFlogins[i].dir = SFstrdup(pw->pw_dir);
453 i++;
454 }
455
456 SFhomeDir.dir = XtMalloc(1);
457 SFhomeDir.dir[0] = 0;
458 SFhomeDir.path = SFcurrentPath;
459 SFhomeDir.entries = entries;
460 SFhomeDir.nEntries = i;
461 SFhomeDir.vOrigin = 0; /* :-) */
462 SFhomeDir.nChars = maxChars + 2;
463 SFhomeDir.hOrigin = 0;
464 SFhomeDir.changed = 1;
465 SFhomeDir.beginSelection = -1;
466 SFhomeDir.endSelection = -1;
467
468 #if defined(SVR4) || defined(SYSV) || defined(USG)
469 qsort((char *)entries, (unsigned)i, sizeof(SFEntry), SFcompareEntries);
470 qsort((char *)SFlogins, (unsigned)i, sizeof(SFLogin), SFcompareLogins);
471 #else /* defined(SVR4) || defined(SYSV) || defined(USG) */
472 qsort((char *)entries, i, sizeof(SFEntry), SFcompareEntries);
473 qsort((char *)SFlogins, i, sizeof(SFLogin), SFcompareLogins);
474 #endif /* defined(SVR4) || defined(SYSV) || defined(USG) */
475
476 for (i--; i >= 0; i--) {
477 (void)strcat(entries[i].real, "/");
478 }
479 }
480
481 static int
482 SFfindHomeDir(char *begin, char *end)
483 {
484 char save;
485 char *theRest;
486 int i;
487
488 save = *end;
489 *end = 0;
490
491 for (i = SFhomeDir.nEntries - 1; i >= 0; i--) {
492 if (!strcmp(SFhomeDir.entries[i].real, begin)) {
493 *end = save;
494 theRest = SFstrdup(end);
495 (void)strcat(strcat(strcpy(SFcurrentPath,
496 SFlogins[i].dir), "/"), theRest);
497 XtFree(theRest);
498 SFsetText(SFcurrentPath);
499 SFtextChanged();
500 return 1;
501 }
502 }
503
504 *end = save;
505
506 return 0;
507 }
508
509 void
510 SFupdatePath(void)
511 {
512 static int alloc;
513 static int wasTwiddle = 0;
514 char *begin, *end;
515 int i, j;
516 int prevChange;
517 int SFdirPtrSave, SFdirEndSave;
518 SFDir *dir;
519
520 if (!SFdirs) {
521 SFdirs = (SFDir *) XtMalloc((alloc = 10) * sizeof(SFDir));
522 dir = &(SFdirs[0]);
523 dir->dir = SFstrdup("/");
524 (void)SFchdir("/");
525 (void)SFgetDir(dir);
526 for (j = 1; j < alloc; j++) {
527 SFdirs[j].dir = NULL;
528 }
529 dir->path = SFcurrentPath + 1;
530 dir->vOrigin = 0;
531 dir->hOrigin = 0;
532 dir->changed = 1;
533 dir->beginSelection = -1;
534 dir->endSelection = -1;
535 SFhomeDir.dir = NULL;
536 }
537
538 SFdirEndSave = SFdirEnd;
539 SFdirEnd = 1;
540
541 SFdirPtrSave = SFdirPtr;
542 SFdirPtr = 0;
543
544 begin = NULL;
545
546 if (SFcurrentPath[0] == '~') {
547 if (!SFtwiddle) {
548 SFtwiddle = 1;
549 dir = &(SFdirs[0]);
550 SFrootDir = *dir;
551 if (!SFhomeDir.dir) {
552 SFgetHomeDirs();
553 }
554 *dir = SFhomeDir;
555 dir->changed = 1;
556 }
557 end = SFcurrentPath;
558 SFdoNotTouchDirPtr = 1;
559 wasTwiddle = 1;
560 }
561 else {
562 if (SFtwiddle) {
563 SFtwiddle = 0;
564 dir = &(SFdirs[0]);
565 *dir = SFrootDir;
566 dir->changed = 1;
567 }
568 end = SFcurrentPath + 1;
569 }
570
571 i = 0;
572
573 prevChange = 0;
574
575 while (*end) {
576 while (*end++ == '/') {
577 ;
578 }
579 end--;
580 begin = end;
581 while ((*end) && (*end++ != '/')) {
582 ;
583 }
584 if ((end - SFcurrentPath <= SFtextPos) && (*(end - 1) == '/')) {
585 SFdirPtr = i - 1;
586 if (SFdirPtr < 0) {
587 SFdirPtr = 0;
588 }
589 }
590 if (*begin) {
591 if (*(end - 1) == '/') {
592 char save = *end;
593
594 if (SFtwiddle) {
595 if (SFfindHomeDir(begin, end)) {
596 return;
597 }
598 }
599 *end = 0;
600 i++;
601 SFdirEnd++;
602 if (i >= alloc) {
603 SFdirs = (SFDir *) XtRealloc(
604 (char *)SFdirs,
605 (unsigned)((alloc *= 2) *
606 sizeof(SFDir))
607 );
608 for (j = alloc / 2; j < alloc; j++) {
609 SFdirs[j].dir = NULL;
610 }
611 }
612 dir = &(SFdirs[i]);
613 if ((!(dir->dir)) || prevChange || strcmp(dir->dir, begin)
614 ) {
615 if (dir->dir) {
616 SFfree(i);
617 }
618 prevChange = 1;
619 dir->dir = SFstrdup(begin);
620 dir->path = end;
621 dir->vOrigin = 0;
622 dir->hOrigin = 0;
623 dir->changed = 1;
624 dir->beginSelection = -1;
625 dir->endSelection = -1;
626 (void)SFfindFile(dir - 1, begin);
627 if (SFchdir(SFcurrentPath) || SFgetDir(dir)
628 ) {
629 SFunreadableDir(dir);
630 break;
631 }
632 }
633 *end = save;
634 if (!save) {
635 SFunselect();
636 }
637 }
638 else {
639 if (SFfindFile(&(SFdirs[SFdirEnd - 1]), begin)) {
640 return;
641 }
642 }
643 }
644 else {
645 SFunselect();
646 }
647 }
648
649 if ((end == SFcurrentPath + 1) && (!SFtwiddle)) {
650 SFunselect();
651 }
652
653 for (i = SFdirEnd; i < alloc; i++) {
654 if (SFdirs[i].dir) {
655 SFfree(i);
656 }
657 }
658
659 if (SFdoNotTouchDirPtr) {
660 if (wasTwiddle) {
661 wasTwiddle = 0;
662 SFdirPtr = SFdirEnd - 2;
663 if (SFdirPtr < 0) {
664 SFdirPtr = 0;
665 }
666 }
667 else {
668 SFdirPtr = SFdirPtrSave;
669 }
670 SFdoNotTouchDirPtr = 0;
671 }
672
673 if ((SFdirPtr != SFdirPtrSave) || (SFdirEnd != SFdirEndSave)) {
674 XawScrollbarSetThumb(selFileHScroll,
675 (double)(SFdirPtr) / SFdirEnd,
676 (double)(SFdirEnd < 3 ? SFdirEnd : 3) / SFdirEnd);
677 }
678
679 if (SFdirPtr != SFdirPtrSave) {
680 SFdrawLists(SF_DO_SCROLL);
681 }
682 else {
683 for (i = 0; i < 3; i++) {
684 if (SFdirPtr + i < SFdirEnd) {
685 if (SFdirs[SFdirPtr + i].changed) {
686 SFdirs[SFdirPtr + i].changed = 0;
687 SFdrawList(i, SF_DO_SCROLL);
688 }
689 }
690 else {
691 SFclearList(i, SF_DO_SCROLL);
692 }
693 }
694 }
695 }
696
697 void
698 SFsetText(char *path)
699 {
700 XawTextBlock text;
701
702 text.firstPos = 0;
703 text.length = strlen(path);
704 text.ptr = path;
705 text.format = FMT8BIT;
706
707 XawTextReplace(selFileField, 0, strlen(SFtextBuffer), &text);
708 XawTextSetInsertionPoint(selFileField, strlen(SFtextBuffer));
709 }
710
711 void
712 SFbuttonPressList(Widget w, int n, XButtonPressedEvent *event)
713 {
714 UNUSED(w);
715 UNUSED(n);
716 UNUSED(event);
717
718 SFbuttonPressed = 1;
719 }
720
721 void
722 SFbuttonReleaseList(Widget w, int n, XButtonReleasedEvent *event)
723 {
724 SFDir *dir;
725
726 SFbuttonPressed = 0;
727
728 if (SFcurrentInvert[n] != -1) {
729 if (n < 2) {
730 SFdoNotTouchDirPtr = 1;
731 }
732 SFdoNotTouchVorigin = 1;
733 dir = &(SFdirs[SFdirPtr + n]);
734 SFreplaceText(dir,
735 dir->entries[dir->vOrigin + SFcurrentInvert[n]].shown);
736 SFmotionList(w, n, (XMotionEvent *)event);
737 }
738 }
739
740 static int
741 SFcheckDir(int n, SFDir *dir)
742 {
743 struct stat statBuf;
744 int i;
745
746 if ((!stat(".", &statBuf)) && (statBuf.st_mtime != dir->mtime)
747 ) {
748
749 /*
750 * If the pointer is currently in the window that we are about
751 * to update, we must warp it to prevent the user from
752 * accidentally selecting the wrong file.
753 */
754 if (SFcurrentInvert[n] != -1) {
755 XWarpPointer(SFdisplay,
756 None, XtWindow(selFileLists[n]), 0, 0, 0, 0, 0, 0);
757 }
758
759 for (i = dir->nEntries - 1; i >= 0; i--) {
760 if (dir->entries[i].shown != dir->entries[i].real) {
761 XtFree(dir->entries[i].shown);
762 }
763 XtFree(dir->entries[i].real);
764 }
765 XtFree((char *)dir->entries);
766 if (SFgetDir(dir)) {
767 SFunreadableDir(dir);
768 }
769 if (dir->vOrigin > dir->nEntries - SFlistSize) {
770 dir->vOrigin = dir->nEntries - SFlistSize;
771 }
772 if (dir->vOrigin < 0) {
773 dir->vOrigin = 0;
774 }
775 if (dir->hOrigin > dir->nChars - SFcharsPerEntry) {
776 dir->hOrigin = dir->nChars - SFcharsPerEntry;
777 }
778 if (dir->hOrigin < 0) {
779 dir->hOrigin = 0;
780 }
781 dir->beginSelection = -1;
782 dir->endSelection = -1;
783 SFdoNotTouchVorigin = 1;
784 if ((dir + 1)->dir) {
785 (void)SFfindFile(dir, (dir + 1)->dir);
786 }
787 else {
788 (void)SFfindFile(dir, dir->path);
789 }
790
791 if (!SFworkProcAdded) {
792 (void)XtAppAddWorkProc(SFapp, (XtWorkProc)SFworkProc, NULL);
793 SFworkProcAdded = 1;
794 }
795
796 return 1;
797 }
798
799 return 0;
800 }
801
802 static int
803 SFcheckFiles(SFDir *dir)
804 {
805 int from, to;
806 int result;
807 char old, new;
808 int i;
809 char *str;
810 int last;
811 struct stat statBuf;
812
813 result = 0;
814
815 from = dir->vOrigin;
816 to = dir->vOrigin + SFlistSize;
817 if (to > dir->nEntries) {
818 to = dir->nEntries;
819 }
820
821 for (i = from; i < to; i++) {
822 str = dir->entries[i].real;
823 last = strlen(str) - 1;
824 old = str[last];
825 str[last] = 0;
826 if (stat(str, &statBuf)) {
827 new = ' ';
828 }
829 else {
830 new = SFstatChar(&statBuf);
831 }
832 str[last] = new;
833 if (new != old) {
834 result = 1;
835 }
836 }
837
838 return result;
839 }
840
841 void
842 SFdirModTimer(XtPointer cl, XtIntervalId *id)
843 {
844 static int n = -1;
845 static int f = 0;
846 char save;
847 SFDir *dir;
848
849 UNUSED(cl);
850 UNUSED(id);
851
852 if ((!SFtwiddle) && (SFdirPtr < SFdirEnd)) {
853 n++;
854 if ((n > 2) || (SFdirPtr + n >= SFdirEnd)) {
855 n = 0;
856 f++;
857 if ((f > 2) || (SFdirPtr + f >= SFdirEnd)) {
858 f = 0;
859 }
860 }
861 dir = &(SFdirs[SFdirPtr + n]);
862 save = *(dir->path);
863 *(dir->path) = 0;
864 if (SFchdir(SFcurrentPath)) {
865 *(dir->path) = save;
866
867 /*
868 * force a re-read
869 */
870 *(dir->dir) = 0;
871
872 SFupdatePath();
873 }
874 else {
875 *(dir->path) = save;
876 if (SFcheckDir(n, dir) || ((f == n) && SFcheckFiles(dir))
877 ) {
878 SFdrawList(n, SF_DO_SCROLL);
879 }
880 }
881 }
882
883 SFdirModTimerId = XtAppAddTimeOut(SFapp, 1500UL,
884 SFdirModTimer, (XtPointer) NULL);
885 }
886
887 /* Return a single character describing what kind of file STATBUF is. */
888
889 char
890 SFstatChar(struct stat *statBuf)
891 {
892 if (S_ISDIR(statBuf->st_mode)) {
893 return '/';
894 }
895 else if (S_ISREG(statBuf->st_mode)) {
896 return S_ISXXX(statBuf->st_mode) ? '*' : ' ';
897 #ifdef S_ISSOCK
898 }
899 else if (S_ISSOCK(statBuf->st_mode)) {
900 return '=';
901 #endif /* S_ISSOCK */
902 }
903 else {
904 return ' ';
905 }
906 }
907
908 #else
909 /* silence `empty compilation unit' warnings */
910 static void bar(void); static void foo(void) { bar(); } static void bar(void) { foo(); }
911 #endif /* !defined(MOTIF) */