wdvi

network DVI viewer
Log | Files | Refs

commit 12bdb0a6a593ac86969618cd7e0d4f713e89e09c
parent 4978d40cd54e64fc2fd402bae1ce94c9ed3beb39
Author: Kyle Milz <krwmilz@gmail.com>
Date:   Mon,  6 Sep 2021 16:08:59 +0000

Remove dvi file opening code

We are not going to support opening on disk dvi files, so remove the code
that does that.

Diffstat:
Mdvi-draw.c | 6------
Mdvi-init.c | 86++++---------------------------------------------------------------------------
Mevents.c | 1-
Mpopups.c | 1354-------------------------------------------------------------------------------
Mxdvi.c | 34----------------------------------
Mxdvi.h | 3---
6 files changed, 4 insertions(+), 1480 deletions(-)

diff --git a/dvi-draw.c b/dvi-draw.c @@ -2282,12 +2282,6 @@ src_spawn_editor(parsed) if (fstat(fileno(f), &buf) == -1) { perror(parsed->filename); } - else { - if (buf.st_mtime > dvi_time) - WARN1(XmDIALOG_ERROR, - "Source file\n%s\nis newer than dvi file", - parsed->filename); - } Fclose(f); ++n_files_left; diff --git a/dvi-init.c b/dvi-init.c @@ -29,15 +29,10 @@ NOTE: #include "xdvi.h" #include "dvi.h" -#include <sys/stat.h> # include <ft2build.h> # include FT_SIZES_H -#if !defined(S_ISDIR) && defined(S_IFDIR) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif - # include <X11/Shell.h> /* defines XtNtitle and XtNiconName */ #define PK_PRE 247 @@ -781,43 +776,6 @@ set_titles() titles_are_stale = False; } - - -/** - ** open_dvi_file opens the dvi file (if present), checks that it's not - ** a directory, saves its time stamp, and forms its dvi property. - ** Returns True if the operation succeeds. Upon failure, returns False - ** and dvi_file == NULL. - **/ - -Boolean -open_dvi_file(path) - const char *path; -{ - struct stat buf; - ino_t old_inode; - - dvi_file = fopen(path, "r"); - if (dvi_file == NULL) - return False; - - if (fstat(fileno(dvi_file), &buf) != 0 - || S_ISDIR(buf.st_mode)) { /* if it's a directory */ - fclose(dvi_file); - dvi_file = NULL; - return False; - } - - dvi_time = buf.st_mtime; - - old_inode = dvi_inode; - form_dvi_property(buf.st_ino); - if (dvi_inode != old_inode && mane.win != (Window) 0) - set_dvi_property(); - - return True; -} - /* * internal_init_dvi is the main subroutine for reading the startup * information from the dvi file. @@ -871,21 +829,6 @@ set_dvi_property() static Widget dvi_popup = NULL; /* warning popup for corrupt dvi file */ -/* ARGSUSED */ -static void -dvi_callback(w, client_data, call_data) - Widget w; - XtPointer client_data; - XtPointer call_data; -{ - ev_flags |= EV_NEWDOC; - if (dvi_popup != NULL) { - XtDestroyWidget(dvi_popup); - dvi_popup = NULL; - } -} - - /** ** Check for changes in dvi file. Return True if it's OK. **/ @@ -937,30 +880,9 @@ reload_dvi_file() for (fontp = font_head; fontp != NULL; fontp = fontp->next) fontp->flags &= ~FONT_IN_USE; - if (!setjmp(dvi_env)) { - if (dvi_file == NULL) { - if (!open_dvi_file(dvi_name)) - dvi_oops("Cannot reopen dvi file."); - } - else { - struct stat buf; - - if (fstat(fileno(dvi_file), &buf) == 0) - dvi_time = buf.st_mtime; - Fseek(dvi_file, (long) 0, 0); - } - if (!internal_init_dvi()) + Fseek(dvi_file, (long) 0, 0); + if (!internal_init_dvi()) return; - if (list_fonts) Putchar('\n'); - } - else { /* if error */ - XClearWindow(DISP, mane.win); - dvi_popup = warning_popup_long( - "Xdvi cannot read the DVI file\n%s\nReason: %s", - "Reload", dvi_callback, dvi_name, dvi_oops_msg); - if (dvi_file != NULL) { - Fclose(dvi_file); - dvi_file = NULL; - } - } + if (list_fonts) + Putchar('\n'); } diff --git a/events.c b/events.c @@ -166,7 +166,6 @@ XtActionsRec Actions[] = { {"shrink-to-dpi", Act_shrink_to_dpi}, {"set-density", Act_set_density}, {"print", Act_print}, - {"open-dvi-file", Act_open_dvi_file}, {"set-greyscaling", Act_set_greyscaling}, {"set-color", Act_set_color}, {"reread-dvi-file", Act_reread_dvi_file}, diff --git a/popups.c b/popups.c @@ -46,14 +46,6 @@ IN THE SOFTWARE. # include <X11/Xaw/AsciiText.h> # include <X11/Xaw/Viewport.h> -#if !defined(S_ISDIR) && defined(S_IFDIR) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif - -#if !defined(S_ISLNK) && defined(S_IFLNK) -#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -#endif - #include <stdarg.h> #include <sys/wait.h> @@ -475,1352 +467,6 @@ confirm_popup(message, button_name, callback, yes_answer, no_answer) return shell; } - - -/* - * File popup - pop up a window to allow the user to switch dvi files. - */ - -/* Common data for XAW and MOTIF */ - -static Boolean file_active = False; /* if file window is showing */ -static Widget file_shell = NULL; /* shell widget of popup */ -static Boolean reposition = False; /* we want to reposition it */ - -/* Common routines */ - -/* ARGSUSED */ -static void -cb_file_cancel(w, client_data, call_data) - Widget w; - XtPointer client_data; - XtPointer call_data; -{ - XtPopdown(file_shell); - file_active = False; - - if (mane.win == (Window) 0) - exit(1); -} - - -static Widget f1text, f2vport, f2clip, f2form, f3text, f4text; -static Widget *widget_list; /* list of file entries */ -static size_t wl_num = 0; /* actual number of widgets */ -static Widget file_highlit = NULL; /* highlighted widget */ -static int file_hl_seq = -1; /* sequence # of the above */ -static char *dirbuf = NULL; /* buffer containing dir name */ -static size_t dirlen = 0; /* length of above buffer */ -static XtTranslations file_xlats; /* for use in file entries */ -static int file_entry_height = 0; /* line height in viewport */ -static Position f2ddist; /* size of list border */ - -struct suffix { - const char *str; - size_t len; -}; -static struct suffix *suffixes = NULL; -static struct suffix *suff_end = NULL; -static size_t suff_max = 0; /* size of array allocated */ - -/* Icon bitmap of directory */ - -#define filedir_width 16 -#define filedir_height 13 -static unsigned char filedir_bits[] = { - 0xf0, 0x00, 0x08, 0x01, 0x06, 0x7e, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, - 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0xfe, 0x7f, 0x00, 0x00, - 0x00, 0x00}; - -static char fileblank_bits[sizeof filedir_bits]; -static Pixmap filedir_pm = (Pixmap) 0; -static Pixmap fileblank_pm = (Pixmap) 0; - -/* Bitmap of check mark */ -#define filechk_width 13 -#define filechk_height 13 -static unsigned char filechk_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x03, - 0x86, 0x01, 0xcc, 0x00, 0x78, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00}; - -static char fileunchk_bits[sizeof filechk_bits]; -static Pixmap filechk_pm = (Pixmap) 0; -static Pixmap fileunchk_pm = (Pixmap) 0; -static char filehide = '.'; - -/* If the file widget is used before the dvi window goes up, then we destroy - * it because it might not have the right colormap and visual. We want to save - * the settings between these two incarnations, though. For the directory and - * the hidden-file checkbox, these are OK, but we need to do the same for the - * suffixes. */ - -static const char *file_save_suff = ".dvi"; - -static void act_file_go(Widget, XEvent *, String *, Cardinal *); -static void act_file_click(Widget, XEvent *, String *, Cardinal *); -static void act_file_suffixes(Widget, XEvent *, String *, Cardinal *); -static void act_file_scroll(Widget, XEvent *, String *, Cardinal *); -static void act_file_arrow(Widget, XEvent *, String *, Cardinal *); -static void act_file_home(Widget, XEvent *, String *, Cardinal *); -static void act_file_end(Widget, XEvent *, String *, Cardinal *); - -static XtActionsRec file_actions[] = { - {"file-go", act_file_go}, - {"file-click", act_file_click}, - {"file-suff", act_file_suffixes}, - {"file-scroll", act_file_scroll}, - {"file-arrow", act_file_arrow}, - {"file-home", act_file_home}, - {"file-end", act_file_end}, -}; - -#ifndef FILEINDENT -# define FILEINDENT 25 -#endif - -#ifndef DIR_SIZE_INCR -# define DIR_SIZE_INCR 64 -#endif - - -/* - * Refresh list of files in the chosen directory. - */ - -struct dirnode { - struct dirnode *next; - const char *name; -}; - -static struct dirnode * -ll_sort(np) - struct dirnode *np; -{ - struct dirnode *np1, *np2; - struct dirnode **npp; - struct dirnode *np0; - - if (np == NULL || (np2 = np->next) == NULL) - return np; - - np1 = np; - for (;;) { - np2 = np2->next; - if (np2 == NULL) break; - np2 = np2->next; - if (np2 == NULL) break; - np1 = np1->next; - } - - np2 = ll_sort(np1->next); - np1->next = NULL; - np1 = ll_sort(np); - - npp = &np0; - for (;;) - if (strcmp(np1->name, np2->name) < 0) { - *npp = np1; - npp = &np1->next; - np1 = np1->next; - if (np1 == NULL) { - *npp = np2; - break; - } - } - else { - *npp = np2; - npp = &np2->next; - np2 = np2->next; - if (np2 == NULL) { - *npp = np1; - break; - } - } - - return np0; -} - -static Boolean -suffix_check(s, len) - const char *s; - size_t len; -{ - struct suffix *sp; - - if (suffixes == suff_end) - return True; - - for (sp = suffixes; sp < suff_end; ++sp) - if (len >= sp->len - && memcmp(s + len - sp->len, sp->str, sp->len) == 0) - return True; - - return False; -} - -static void -file_refresh() -{ - struct dirnode *head; - struct dirnode *np; - struct dirnode **npp; - DIR *dirp; - size_t count; - Widget prev; - int i; - static Widget *icon_list; - static unsigned wl_max = 0; /* allocated space in list */ - - if (f3text != NULL) - XtVaSetValues(f3text, XtNstring, "", NULL); - else - wl_num = 0; - - dirp = xopendir(dirbuf); - npp = &head; - count = 0; - if (dirp != NULL) { - char *dirbuf2; - size_t dirlen2; - size_t len; - - dirbuf2 = xmemdup(dirbuf, dirlen); - dirlen2 = dirlen; - len = strlen(dirbuf2); - dirbuf2[len++] = '/'; - - for (;;) { - struct dirent *dp; - struct stat buf; - size_t len2; - char dirchar; - char *s; - - dp = readdir(dirp); - if (dp == NULL) break; - len2 = NAMLEN(dp); - if (dp->d_name[0] == '.' && (len2 == 1 - || (len2 == 2 && dp->d_name[1] == '.'))) /* if . or .. */ - continue; - if (dp->d_name[0] == filehide) /* if hidden */ - continue; - - if (dirlen2 <= len + len2) { - dirlen2 = ((len + len2) / DIR_SIZE_INCR + 1) - * DIR_SIZE_INCR; - dirbuf2 = xrealloc(dirbuf2, dirlen2); - } - s = dirbuf2 + len; - memcpy(s, dp->d_name, len2); - s[len2] = '\0'; - dirchar = '0'; - if (stat(dirbuf2, &buf) != 0 || !S_ISDIR(buf.st_mode)) { - dirchar = '1'; - if (!suffix_check(s, len2)) - continue; - } - ++len2; - s = xmalloc(len2 + 1); - *s = dirchar; - memcpy(s + 1, dirbuf2 + len, len2); - - np = xmalloc(sizeof *np); - np->name = s; - *npp = np; - npp = &np->next; - ++count; - } - closedir(dirp); - } - *npp = NULL; - - head = ll_sort(head); - - if (count > wl_max) { - if (wl_max == 0) { - widget_list = xmalloc(count * sizeof(Widget)); - icon_list = xmalloc(count * sizeof(Widget)); - } - else { - widget_list = xrealloc(widget_list, count * sizeof(Widget)); - icon_list = xrealloc(icon_list, count * sizeof(Widget)); - } - wl_max = count; - } - - if (XtIsManaged(f2form)) { - XtUnmanageChild(f2form); - if (file_highlit != NULL) { - XtCallActionProc(file_highlit, "reset", NULL, NULL, 0); - file_highlit = NULL; - file_hl_seq = -1; - } - } - - if (head != NULL) { - if (filedir_pm == (Pixmap) 0) - filedir_pm = XCreateBitmapFromData(DISP, - mane.win != (Window) 0 ? mane.win - : RootWindowOfScreen(SCRN), - (const char *) filedir_bits, - filedir_width, filedir_height); - if (*head->name != '0' && fileblank_pm == (Pixmap) 0) - fileblank_pm = XCreateBitmapFromData(DISP, - mane.win != (Window) 0 ? mane.win - : RootWindowOfScreen(SCRN), - fileblank_bits, filedir_width, filedir_height); - } - - i = 0; - if (count > 0 && wl_num > 0) { - XtVaSetValues(*icon_list, - XtNbitmap, *head->name == '0' ? filedir_pm : fileblank_pm, - NULL); - for (;;) { - XtVaSetValues(widget_list[i], XtNlabel, head->name + 1, NULL); - np = head->next; - free((char *) head->name); - free(head); - head = np; - ++i; - if (i >= count || i >= wl_num) - break; - if (*head->name == '0') { - if (icon_list[i] == NULL) { - char s[3 * sizeof(int) + 1]; - - (void) snprintf(s, sizeof s, "i%u", i); - icon_list[i] = XtVaCreateManagedWidget(s, - labelWidgetClass, f2form, - XtNbitmap, filedir_pm, - XtNborderWidth, 0, - XtNfromVert, widget_list[i - 1], - XtNvertDistance, 0, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - XtNtop, XawChainTop, - XtNbottom, XawChainTop, - NULL); - } - } - else if (icon_list[i] != NULL) { - XtDestroyWidget(icon_list[i]); - icon_list[i] = NULL; - } - } - } - if (head != NULL) { - if (i == 0) { - Dimension h, bw; - - prev = *icon_list = XtVaCreateManagedWidget("i0", - labelWidgetClass, f2form, - XtNbitmap, *head->name == '0' ? filedir_pm : fileblank_pm, - XtNborderWidth, 0, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - XtNtop, XawChainTop, - XtNbottom, XawChainTop, - NULL); - prev = *widget_list = XtVaCreateManagedWidget("0", - commandWidgetClass, f2form, - XtNlabel, head->name + 1, - XtNtranslations, file_xlats, - XtNborderWidth, 0, - XtNresizable, True, - XtNfromHoriz, prev, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - XtNtop, XawChainTop, - XtNbottom, XawChainTop, - NULL); - np = head->next; - free((char *) head->name); - free(head); - head = np; - ++i; - XtVaGetValues(prev, - XtNy, &f2ddist, - XtNheight, &h, - XtNborderWidth, &bw, - NULL); - file_entry_height = h + 2 * bw; - } - else prev = widget_list[i - 1]; - while (head != NULL) { - char s[3 * sizeof(int) + 1]; - - (void) snprintf(s, sizeof s, "i%u", i); - icon_list[i] = *head->name != '0' ? NULL - : XtVaCreateManagedWidget(s, labelWidgetClass, f2form, - XtNbitmap, filedir_pm, - XtNborderWidth, 0, - XtNfromVert, prev, - XtNvertDistance, 0, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - XtNtop, XawChainTop, - XtNbottom, XawChainTop, - NULL); - prev = widget_list[i] = XtVaCreateManagedWidget(s + 1, - commandWidgetClass, f2form, - XtNlabel, head->name + 1, - XtNtranslations, file_xlats, - XtNborderWidth, 0, - XtNresizable, True, - XtNfromHoriz, *icon_list, - XtNfromVert, prev, - XtNvertDistance, 0, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - XtNtop, XawChainTop, - XtNbottom, XawChainTop, - NULL); - np = head->next; - free((char *) head->name); - free(head); - head = np; - ++i; - } - } - - while (wl_num > count) { - XtDestroyWidget(widget_list[--wl_num]); - if (icon_list[wl_num] != NULL) - XtDestroyWidget(icon_list[wl_num]); - } - - wl_num = count; - - XtManageChild(f2form); -} - -/* ARGSUSED */ -static void -cb_file_up(w, client_data, call_data) - Widget w; - XtPointer client_data; - XtPointer call_data; -{ - char *p; - - p = rindex(dirbuf, '/'); - if (p == NULL) - return; - - if (p == dirbuf) { - if (dirbuf[1] == '\0') - return; - ++p; - } - - *p = '\0'; - XtVaSetValues(f1text, XtNstring, dirbuf, NULL); - file_refresh(); -} - -/* ARGSUSED */ -static void -cb_file_home(w, client_data, call_data) - Widget w; - XtPointer client_data; - XtPointer call_data; -{ - const char *d; - size_t l; - - d = getenv("HOME"); - if (d == NULL) - return; - - l = strlen(d) + 1; - if (l > dirlen) { - dirlen = ((l - 1) / DIR_SIZE_INCR + 1) * DIR_SIZE_INCR; - free(dirbuf); - dirbuf = xmalloc(dirlen); - } - - memcpy(dirbuf, d, l); - XtVaSetValues(f1text, XtNstring, dirbuf, NULL); - file_refresh(); -} - -/* ARGSUSED */ -static void -cb_file_hidechk(w, client_data, call_data) - Widget w; - XtPointer client_data; - XtPointer call_data; -{ - if (filehide == '.') { - filehide = '\0'; - XtVaSetValues(w, XtNbitmap, filechk_pm, NULL); - } - else { - filehide = '.'; - XtVaSetValues(w, XtNbitmap, fileunchk_pm, NULL); - } - - file_refresh(); -} - -static Boolean -xdvi_get_cwd() -{ - if (dirbuf == NULL) - dirbuf = xmalloc(dirlen = DIR_SIZE_INCR); - - for (;;) { - if (getcwd(dirbuf, dirlen) != NULL) - return True; - if (errno != ERANGE) - break; - free(dirbuf); - dirbuf = xmalloc(dirlen += DIR_SIZE_INCR); - } - dirbuf[0] = '.'; - dirbuf[1] = '\0'; - return False; -} - -static Boolean -get_dir_name(str, len) - const char *str; - size_t len; -{ - int fd; - Boolean val; - - if (dirbuf == NULL) - dirbuf = xmalloc(dirlen = DIR_SIZE_INCR); - - /* Normalize directory name */ - while (len > 0 && str[len - 1] == '/') --len; - if (len == 0) { - dirbuf[0] = '/'; - dirbuf[1] = '\0'; - return True; - } - - /* Save current directory */ - fd = xopen(".", O_RDONLY); - if (fd == -1) - return False; - - /* Change to new directory */ - if (str[len] == '\0') { - if (chdir(str) != 0) { - close(fd); - return False; - } - } - else { - char *str2; - - str2 = xmemdup(str, len + 1); - str2[len] = '\0'; - if (chdir(str2) != 0) { - free(str2); - fchdir(fd); - close(fd); - return False; - } - free(str2); - } - - val = xdvi_get_cwd(); - fchdir(fd); - close(fd); - return val; -} - -static Boolean -path_is_clean(str, p1) - char *str; - char *p1; -{ - char *p_end = p1 + strlen(p1); - char *p; - char c; - struct stat buf; - int val; - - for (;;) { - ++p1; - p = memchr(p1, '/', p_end - p1); - if (p == NULL) - p = p_end; - - /* check for double slash or slash at end or "." or ".." */ - if (p == p1 || (*p1 == '.' && (p == p1 + 1 || - (p1[1] == '.' && p == p1 + 2)))) - break; - - c = *p; - *p = '\0'; - val = lstat(str, &buf); - *p = c; - - if (val != 0 || S_ISLNK(buf.st_mode)) - break; - - p1 = p; - if (p1 == p_end) - return True; - } - - return False; -} - -/* ARGSUSED */ -static void -cb_file_go(w, client_data, call_data) - Widget w; - XtPointer client_data; - XtPointer call_data; -{ - char *s, *str; - char *p1; - struct stat buf; - - XtVaGetValues(f3text, XtNstring, &s, NULL); - - if (*s == '\0') { /* if no string */ - file_refresh(); - return; - } - - if (*s == '/') /* if ignoring the chosen directory */ - p1 = str = s; - else { - size_t l1, l2; - - l1 = strlen(dirbuf); - l2 = strlen(s) + 1; - str = xmalloc(l1 + l2 + 1); - memcpy(str, dirbuf, l1); - p1 = str + l1; - *p1 = '/'; - memcpy(p1 + 1, s, l2); - } - - if (stat(str, &buf) != 0) { /* if file does not exist (or error) */ - warning_popup_long("Error opening file: %s\n%s.", "OK", NULL, str, - strerror(errno)); - } - else if (S_ISDIR(buf.st_mode)) { /* if directory */ - if (path_is_clean(str, p1) || !get_dir_name(str, strlen(str))) { - size_t l; - - l = strlen(str) + 1; - if (l > dirlen) { - dirlen = ((l - 1) / DIR_SIZE_INCR + 1) * DIR_SIZE_INCR; - free(dirbuf); - dirbuf = xmalloc(dirlen); - } - - memcpy(dirbuf, str, l); - } - XtVaSetValues(f1text, XtNstring, dirbuf, NULL); - file_refresh(); - } - else { /* if not directory (file, we hope) */ - FILE *f; - - /* Normally, dvi files are are not part of the fd-counting - provided by xfopen(), since there is only one of them. - However, in this case we're opening one before closing the - old one, so we have to use xfopen() in this case. */ - f = xfopen(str, "r"); - if (f == NULL) - warning_popup_long("Error opening file: %s\n%s.", "OK", NULL, - str, strerror(errno)); - else { - ino_t old_inode; - - ++n_files_left; - if (dvi_file != NULL) - fclose(dvi_file); - dvi_file = f; - - if (dvi_name != NULL) - free(dvi_name); - - if (str != s) { - dvi_name = str; - str = s; - } - else - dvi_name = xstrdup(str); - - dvi_time = buf.st_mtime; - - old_inode = dvi_inode; - form_dvi_property(buf.st_ino); - titles_are_stale = True; - - if (mane.win != (Window) 0) { /* if not in startup code */ - if (dvi_inode != old_inode) - set_dvi_property(); - - goto_page(0, home); - } - else - reposition = True; - - XtPopdown(file_shell); - file_active = False; - - ev_flags |= EV_NEWDOC; - } - } - - if (str != s) - free(str); -} - -/* ARGSUSED */ -static void -act_file_go(Widget w, XEvent *event, String *params, Cardinal *num_params) -{ - cb_file_go(NULL, NULL, NULL); -} - -static void -select_file_entry(w) - Widget w; -{ - char *s; - Position fy; /* (minus) position of list in vport */ - Dimension ch; /* height of clip widget */ - Position ey; /* position of entry */ - Dimension eh, eb; /* dimensions of entry */ - ptrdiff_t dist; - Widget sbar; - - if (file_highlit != NULL && file_highlit != w) { - XtCallActionProc(file_highlit, "reset", NULL, NULL, 0); - file_hl_seq = -1; - } - file_highlit = w; - - XtVaGetValues(w, XtNlabel, &s, NULL); - XtVaSetValues(f3text, XtNstring, s, NULL); - XawTextSetInsertionPoint(f3text, strlen(s)); - - /* Make sure the entry is fully viewable */ - XtVaGetValues(f2form, XtNy, &fy, NULL); - XtVaGetValues(f2clip, XtNheight, &ch, NULL); - XtVaGetValues(file_highlit, - XtNy, &ey, - XtNheight, &eh, - XtNborderWidth, &eb, - NULL); - eh += 2 * eb; /* real height of entry */ - dist = ey + fy; /* position relative to viewable area */ - if (dist < 0) { - sbar = XtNameToWidget(f2vport, "vertical"); - if (sbar != NULL) - XtCallCallbacks(sbar, XtNscrollProc, (XtPointer) dist); - } - else { - dist += eh - ch; - if (dist > 0) { - sbar = XtNameToWidget(f2vport, "vertical"); - if (sbar != NULL) - XtCallCallbacks(sbar, XtNscrollProc, (XtPointer) dist); - } - } -} - -/* ARGSUSED */ -static void -act_file_click(Widget w, XEvent *event, String *params, Cardinal *num_params) -{ - select_file_entry(w); -} - -static void -select_by_seq(seq) - int seq; -{ - Widget w = widget_list[seq]; - - select_file_entry(w); - file_hl_seq = seq; - XtCallActionProc(w, "highlight", NULL, NULL, 0); -} - -/* ARGSUSED */ -static void -act_file_arrow(Widget w, XEvent *event, String *params, Cardinal *num_params) -{ - Dimension ch; /* height of clip widget */ - Position fy; /* (minus) position of list in vport */ - Position ey; /* position of highlit entry */ - Dimension eh, eb; - int hl_seq; - - if (wl_num == 0) - return; - - /* determine whether currently highlighted widget is visible */ - hl_seq = -1; - XtVaGetValues(f2form, XtNy, &fy, NULL); - if (file_highlit != NULL) { - XtVaGetValues(f2clip, XtNheight, &ch, NULL); - XtVaGetValues(f2form, XtNy, &fy, NULL); - XtVaGetValues(file_highlit, - XtNy, &ey, - XtNheight, &eh, - XtNborderWidth, &eb, - NULL); - eh += eb; /* only one border is counted here */ - ey += fy; /* position relative to viewable area */ - if (ey + (Position) eh > 0 && ey < (Position) ch) { - /* Widget is visible. Find its sequence number. */ - hl_seq = file_hl_seq; - if (hl_seq < 0) { - for (hl_seq = 0;; ++hl_seq) { - if (hl_seq >= wl_num) { - /* this shouldn't happen */ - file_highlit = NULL; - file_hl_seq = -1; - return; - } - if (widget_list[hl_seq] == file_highlit) - break; - } - } - if (*num_params > 0 && **params == '-') { /* if up */ - if (hl_seq == 0) hl_seq = wl_num; - --hl_seq; - } - else { /* down */ - ++hl_seq; - if (hl_seq >= wl_num) hl_seq = 0; - } - } - } - - if (hl_seq < 0) { /* if not visible */ - if (*num_params > 0 && **params == '-') { /* if up */ - /* select the lowest visible widget */ - XtVaGetValues(f2clip, XtNheight, &ch, NULL); - hl_seq = ((Position) ch - fy - f2ddist - 1) / file_entry_height; - } - else { /* down */ - /* select the highest visible widget */ - hl_seq = (-fy - f2ddist) / file_entry_height; - } - if (hl_seq < 0) hl_seq = 0; - if (hl_seq >= wl_num) hl_seq = wl_num - 1; - } - - /* Select the new widget. */ - select_by_seq(hl_seq); -} - -/* ARGSUSED */ -static void -act_file_home(Widget w, XEvent *event, String *params, Cardinal *num_params) -{ - if (wl_num != 0) - select_by_seq(0); -} - -/* ARGSUSED */ -static void -act_file_end(Widget w, XEvent *event, String *params, Cardinal *num_params) -{ - if (wl_num != 0) - select_by_seq(wl_num - 1); -} - -/* - * Page-Up, Page-Down, and wheel actions are pure scrolling actions: - * they do not change the highlighted entry, even if it scrolls off - * the window. - */ - -/* ARGSUSED */ -static void -act_file_scroll(Widget w, XEvent *event, String *params, Cardinal *num_params) -{ - Dimension ch, fh; /* clip and form (child) heights */ - Position y; - Widget sbar; - const char *arg; - ptrdiff_t sign; - ptrdiff_t dist; - - if (wl_num == 0) - return; - - XtVaGetValues(f2clip, XtNheight, &ch, NULL); - XtVaGetValues(f2form, XtNheight, &fh, XtNy, &y, NULL); - if (fh <= ch) - return; /* no scrolling possible */ - - sbar = XtNameToWidget(f2vport, "vertical"); - if (sbar == NULL) - return; - - arg = (*num_params != 0 ? *params : ""); - - sign = 1; - if (*arg == '-') { - sign = -1; - ++arg; - } - - if (*arg == 'w') { /* if wheel action */ - if (ch <= 16 * file_entry_height) - dist = (ch / (4 * file_entry_height) + 1) * file_entry_height; - else - dist = 5 * file_entry_height; - } - else { - if (ch <= 15 * file_entry_height) - dist = ch / 5; - else - dist = 3 * file_entry_height; - dist = ch - dist; - if (dist < file_entry_height) dist = file_entry_height; - } - - XtCallCallbacks(sbar, XtNscrollProc, (XtPointer) (sign * dist)); -} - -static void -rebuild_suffixes(s) - const char *s; -{ - struct suffix *sp; - size_t n; - const char *p, *p1; - char *q; - - /* First free the old suffixes */ - for (sp = suffixes; sp < suff_end; ++sp) - free((char *) sp->str); - - /* Next count the suffixes */ - n = 0; - p = s; - for (;;) { - while (*p == ' ' || *p == '\t' || *p == '\n' || *p == ',') ++p; - if (*p == '\0') - break; - ++n; - for (;;) { - if (*p == '\\' && p[1] != '\0') ++p; - else if (*p == ' ' || *p == '\t' || *p == '\n' || *p == ',') - break; - ++p; - if (*p == '\0') break; - } - } - - /* Allocate space */ - if (n > suff_max) { - if (suff_max != 0) free(suffixes); - suff_max = n; - suffixes = xmalloc(n * sizeof (*suffixes)); - } - - /* Fill the space */ - suff_end = suffixes; - p = s; - for (;;) { - while (*p == ' ' || *p == '\t' || *p == '\n' || *p == ',') ++p; - if (*p == '\0') - break; - n = 0; - p1 = p; - for (;;) { - if (*p1 == '\\' && p1[1] != '\0') ++p1; - else if (*p1 == ' ' || *p1 == '\t' || *p1 == '\n' || *p1 == ',') - break; - ++n; - ++p1; - if (*p1 == '\0') break; - } - suff_end->len = n; - suff_end->str = q = xmalloc(n); - ++suff_end; - - while (p < p1) { - if (*p == '\\') ++p; - *q++ = *p++; - } - } -} - -/* ARGSUSED */ -static void -act_file_suffixes(Widget w, XEvent *event, String *params, Cardinal *num_params) -{ - char *s; - - XtVaGetValues(f4text, XtNstring, &s, NULL); - rebuild_suffixes(s); - file_refresh(); -} - -static void -right_justify_widget(w, form_width) - Widget w; - Dimension form_width; -{ - Dimension w1, w2, bw1; - Position x; - - XtVaGetValues(w, - XtNx, &x, - XtNwidth, &w1, - XtNborderWidth, &bw1, - NULL); - w2 = form_width - x - 2 * bw1; - if (w2 > w1) - XtVaSetValues(w, XtNwidth, w2, NULL); -} - -/* ARGSUSED */ -void -Act_open_dvi_file(Widget w, XEvent *event, String *params, Cardinal *num_params) -{ - if (file_active) { - XRaiseWindow(DISP, XtWindow(file_shell)); - return; - } - - if (file_shell == NULL) { - Widget form; - Widget f1label, f1cmd1, f1cmd2; - Widget f3label; - Widget f4label; - Widget f5chk, f5label; - Widget f6ok, f6cancel; - static XtTranslations form_xlats, form_xlats2; - XtTranslations xlats; - int ddist; - char *p; - - XtAddActions(file_actions, XtNumber(file_actions)); - form_xlats = XtParseTranslationTable( -#ifdef XK_KP_Left - "#override \ -<Key>Up:file-arrow(-)\n\ -<Key>Down:file-arrow()\n\ -<Key>Prior:file-scroll(-)\n\ -<Key>Next:file-scroll()\n\ -<Key>Home:file-home()\n\ -<Key>End:file-end()\n\ -<Key>KP_Up:file-arrow(-)\n\ -<Key>KP_Down:file-arrow()\n\ -<Key>KP_Prior:file-scroll(-)\n\ -<Key>KP_Next:file-scroll()\n\ -<Key>KP_Home:file-home()\n\ -<Key>KP_End:file-end()\n\ -<Btn4Down>:file-scroll(-w)\n\ -<Btn5Down>:file-scroll(w)" -#else /* no XK_KP_Left */ - "#override \ -<Key>Up:file-arrow(-)\n\ -<Key>Down:file-arrow()\n\ -<Key>Prior:file-scroll(-)\n\ -<Key>Next:file-scroll()\n\ -<Key>Home:file-home()\n\ -<Key>End:file-end()\n\ -<Btn4Down>:file-scroll(-w)\n\ -<Btn5Down>:file-scroll(w)" -#endif /* no XK_KP_Left */ - ); - form_xlats2 = XtParseTranslationTable( - "#override \ -<Btn4Down>:file-scroll(-w)\n\ -<Btn5Down>:file-scroll(w)"); - file_xlats = XtParseTranslationTable( - "#replace \ -<Btn1Down>:highlight()file-click()\n\ -<Btn1Down>(2):file-go()\n\ -<Btn4Down>:file-scroll(-w)\n\ -<Btn5Down>:file-scroll(w)"); - - /* Set initial directory name. */ - if (dvi_name != NULL) { - p = rindex(dvi_name, '/'); - if (p == NULL || !get_dir_name(dvi_name, p - dvi_name)) - (void) xdvi_get_cwd(); - } - else - (void) xdvi_get_cwd(); - - /* Create shell widget and its child form widget. */ - - file_shell = XtVaCreatePopupShell("file", transientShellWidgetClass, - top_level, - XtNtitle, "Open file", - XtNmappedWhenManaged, False, - XtNtransientFor, top_level, - XtNallowShellResize, True, - NULL); - - form = XtVaCreateManagedWidget("form", formWidgetClass, file_shell, - XtNtranslations, form_xlats, - NULL); - XtVaGetValues(form, XtNdefaultDistance, &ddist, NULL); - - /* Row 1: Directory stuff. */ - - f1label = XtVaCreateManagedWidget("lookin", labelWidgetClass, form, - XtNlabel, "Look in:", - XtNborderWidth, 0, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - NULL); - - f1text = XtVaCreateManagedWidget("dir", asciiTextWidgetClass, - form, - XtNdataCompression, False, - XtNuseStringInPlace, True, - XtNstring, dirbuf, - XtNlength, dirlen, - XtNwidth, 250, - XtNtranslations, form_xlats, - XtNresizable, True, - XtNfromHoriz, f1label, - XtNleft, XawChainLeft, - XtNright, XawChainRight, - NULL); - - f1cmd1 = XtVaCreateManagedWidget("up", commandWidgetClass, - form, - XtNlabel, "Up directory", - XtNtranslations, form_xlats2, - XtNfromVert, f1text, - XtNhorizDistance, ddist + FILEINDENT, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - NULL); - XtAddCallback(f1cmd1, XtNcallback, cb_file_up, NULL); - - f1cmd2 = XtVaCreateManagedWidget("home", commandWidgetClass, - form, - XtNlabel, "Home directory", - XtNtranslations, form_xlats2, - XtNfromHoriz, f1cmd1, - XtNfromVert, f1text, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - NULL); - XtAddCallback(f1cmd2, XtNcallback, cb_file_home, NULL); - - /* Row 2: The viewport. */ - - f2vport = XtVaCreateManagedWidget("vport", viewportWidgetClass, - form, - XtNwidth, 300, - XtNheight, 200, - XtNallowHoriz, True, - XtNallowVert, True, - XtNuseRight, True, - XtNuseBottom, True, - XtNfromVert, f1cmd1, - XtNleft, XawChainLeft, - XtNright, XawChainRight, - NULL); - - f2clip = XtNameToWidget(f2vport, "clip"); - - f2form = XtCreateWidget("vform", formWidgetClass, f2vport, - NULL, 0); - - rebuild_suffixes(file_save_suff); - file_refresh(); - - /* Rows 3 and 4: File name and suffixes. */ - - f3label = XtVaCreateManagedWidget("filename", labelWidgetClass, - form, - XtNlabel, "File name:", - XtNborderWidth, 0, - XtNfromVert, f2vport, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - NULL); - - f3text = XtVaCreateManagedWidget("filetext", asciiTextWidgetClass, - form, - XtNdataCompression, False, - XtNeditType, XawtextEdit, - XtNtranslations, form_xlats, - XtNresizable, True, - XtNfromHoriz, f3label, - XtNfromVert, f2vport, - XtNleft, XawChainLeft, - XtNright, XawChainRight, - NULL); - xlats = XtParseTranslationTable("<Key>Return:file-go()"); - XtOverrideTranslations(f3text, xlats); - - f4label = XtVaCreateManagedWidget("sufflabel", labelWidgetClass, - form, - XtNlabel, "Suffixes:", - XtNborderWidth, 0, - XtNfromVert, f3text, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - NULL); - - f4text = XtVaCreateManagedWidget("sufftext", asciiTextWidgetClass, - form, - XtNdataCompression, False, - XtNeditType, XawtextEdit, - XtNstring, file_save_suff, - XtNtranslations, form_xlats, - XtNresizable, True, - XtNfromHoriz, f4label, - XtNfromVert, f3text, - XtNleft, XawChainLeft, - XtNright, XawChainRight, - NULL); - XawTextSetInsertionPoint(f4text, strlen(file_save_suff)); - xlats = XtParseTranslationTable("<Key>Return:file-suff()"); - XtOverrideTranslations(f4text, xlats); - - { /* align left edges of asciitext widgets */ - Dimension w3, w4; - - XtVaGetValues(f3label, XtNwidth, &w3, NULL); - XtVaGetValues(f4label, XtNwidth, &w4, NULL); - if (w4 > w3) - XtVaSetValues(f3text, XtNhorizDistance, ddist + (w4 - w3), - NULL); - else if (w3 > w4) - XtVaSetValues(f4text, XtNhorizDistance, ddist + (w3 - w4), - NULL); - } - - /* Row 5: Checkbox for showing hidden files. */ - - filechk_pm = XCreateBitmapFromData(DISP, - mane.win != (Window) 0 ? mane.win : RootWindowOfScreen(SCRN), - (const char *) filechk_bits, filechk_width, filechk_height); - - fileunchk_pm = XCreateBitmapFromData(DISP, - mane.win != (Window) 0 ? mane.win : RootWindowOfScreen(SCRN), - fileunchk_bits, filechk_width, filechk_height); - - f5chk = XtVaCreateManagedWidget("hidchk", commandWidgetClass, form, - XtNbitmap, filehide == '.' ? fileunchk_pm : filechk_pm, - XtNtranslations, form_xlats2, - XtNfromVert, f4text, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - NULL); - XtAddCallback(f5chk, XtNcallback, cb_file_hidechk, NULL); - - f5label = XtVaCreateManagedWidget("hidlabel", labelWidgetClass, - form, - XtNlabel, "Show hidden files and directories", - XtNborderWidth, 0, - XtNfromHoriz, f5chk, - XtNfromVert, f4text, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - NULL); - - /* Row 6: Action buttons. */ - - f6ok = XtVaCreateManagedWidget("ok", commandWidgetClass, form, - XtNlabel, "Open", - XtNtranslations, form_xlats2, - XtNaccelerators, accels_cr, - XtNfromVert, f5chk, - XtNleft, XawChainLeft, - XtNright, XawChainLeft, - NULL); - XtAddCallback(f6ok, XtNcallback, cb_file_go, NULL); - XtInstallAccelerators(form, f6ok); - XtInstallAccelerators(f3text, f6ok); - - f6cancel = XtVaCreateManagedWidget("cancel", commandWidgetClass, - form, - XtNlabel, "Cancel", - XtNtranslations, form_xlats2, - XtNfromHoriz, f6ok, - XtNfromVert, f5chk, - XtNleft, XawChainRight, - XtNright, XawChainRight, - NULL); - XtAddCallback(f6cancel, XtNcallback, cb_file_cancel, NULL); - - /* Realize and set destroy callback */ - XdviXawRealizePopup(file_shell, cb_file_cancel); - - { /* Move various things to the right margin */ - Dimension fw, w1, w2, bw1, bw2, tw; - - /* get the form width */ - XtVaGetValues(form, XtNwidth, &fw, NULL); - fw -= ddist; - - /* stretch various widgets to the right */ - right_justify_widget(f1text, fw); - XtVaSetValues(f2vport, XtNresizable, True, NULL); - right_justify_widget(f2vport, fw); - XtVaSetValues(f2vport, XtNresizable, False, NULL); - right_justify_widget(f3text, fw); - right_justify_widget(f4text, fw); - - /* move the cancel button over */ - XtVaGetValues(f6ok, XtNwidth, &w1, XtNborderWidth, &bw1, NULL); - XtVaGetValues(f6cancel, XtNwidth, &w2, XtNborderWidth, &bw2, - NULL); - tw = w1 + w2 + 2 * (bw1 + bw2 + ddist); - if (tw < fw) - XtVaSetValues(f6cancel, XtNhorizDistance, fw - tw + ddist, - NULL); - } - - reposition = True; - } - else { /* if widget already exists */ - file_refresh(); - } - - if (reposition) { - /* Center the popup over the main window */ - Position x, y; - Dimension w1, h1, w2, h2; - - /* Get the size and location of the main window */ - x = y = 0; - w1 = WidthOfScreen(SCRN); - h1 = HeightOfScreen(SCRN); - if (mane.win != (Window) 0) - XtVaGetValues(top_level, XtNx, &x, XtNy, &y, - XtNwidth, &w1, XtNheight, &h1, NULL); - - /* Get the size of the popup window */ - XtVaGetValues(file_shell, XtNwidth, &w2, XtNheight, &h2, NULL); - - /* Move the popup */ - XtVaSetValues(file_shell, XtNx, x + (w1 - w2) / 2, - XtNy, y + (h1 - h2) / 2, NULL); - - reposition = False; - } - - XtPopup(file_shell, XtGrabNone); - file_active = True; -} - - - /* * Print popup - pop up a window to allow the user to print page(s) * from the dvi file. diff --git a/xdvi.c b/xdvi.c @@ -254,7 +254,6 @@ static const char base_translations[] = "" "^<Key>j:forward-page()\n" "^<Key>l:forward-page(0)\n" "^<Key>h:back-page()\n" -"^<Key>o:open-dvi-file()\n" "^<Key>p:print()\n" "a<Key>p:show-display-attributes()\n" "\"q\":quit()\n" @@ -1517,43 +1516,10 @@ or invalid argument:\n\t\"%s\", \"%s\".", postpone_popups = False; act_addr_go(NULL, NULL, NULL, 0); dvi_name = "resume.dvi"; - // Act_open_dvi_file(NULL, NULL, NULL, 0); (void) read_events(EV_GE_NEWDOC); ev_flags &= ~EV_NEWDOC; postpone_popups = True; } - else { - char *new_name; - size_t n; - - n = strlen(dvi_name); - - /* - * Try foo.dvi before foo, in case there's an executable foo with - * documentation foo.tex. Unless it already ends with ".dvi". - */ - - if (n < 4 || memcmp(dvi_name + n - 4, ".dvi", 4) != 0) { - new_name = xmalloc(n + 5); - memcpy(new_name, dvi_name, n); - memcpy(new_name + n, ".dvi", 5); - if (open_dvi_file(new_name)) /* if found */ - dvi_name = new_name; - else - free(new_name); - } - - /* Then try `foo', in case the user likes DVI files without `.dvi' - (or if `foo' already included .dvi). */ - - if (dvi_file == NULL) { - if (!open_dvi_file(dvi_name)) { - perror(dvi_name); - return 1; - } - dvi_name = xstrdup(dvi_name); - } - } if (resource.src_pos != NULL) { if (src_client_check()) { diff --git a/xdvi.h b/xdvi.h @@ -506,7 +506,6 @@ char *dvi_name = NULL; /* dvi file name */ FILE *dvi_file; /* user's file */ Boolean dvi_file_ready = False; /* done with font generation and prescanning */ -time_t dvi_time; /* last modification time */ ino_t dvi_inode; /* used for source specials */ unsigned char *dvi_property; /* for setting in window */ size_t dvi_property_length; @@ -790,7 +789,6 @@ extern Widget warning_popup(const char *, const char *, XtCallbackProc); extern Widget warning_popup_long(const char *, const char *, XtCallbackProc, ...); extern void Act_print(Widget, XEvent *, String *, Cardinal *); -extern void Act_open_dvi_file(Widget, XEvent *, String *, Cardinal *); extern void reset_fonts(void); extern void reset_colors(void); extern void full_reset_colors(void); @@ -801,7 +799,6 @@ extern struct font *define_font(FILE *, wide_ubyte, struct font *, struct font **, unsigned int, struct tn **); extern void init_page(void); -extern Boolean open_dvi_file(const char *); extern void form_dvi_property(ino_t); extern void init_dvi_file(void); extern void set_dvi_property(void);