wdvi

network DVI viewer
Log | Files | Refs

commit d2c4b273dc78dce3c504e8508baf24eaf6da080e
parent cc9171323aa3640b49c53b938d1bfad28af076e4
Author: Kyle Milz <krwmilz@gmail.com>
Date:   Tue,  7 Sep 2021 16:27:08 +0000

Remove source special features

xdvi has a feature that spawns an editor at a selectable place in the
DVI file. We do not need this, so delete it.

Diffstat:
Mdvi-draw.c | 909-------------------------------------------------------------------------------
Mdvi-init.c | 13-------------
Mevents.c | 130-------------------------------------------------------------------------------
Mutil.c | 134-------------------------------------------------------------------------------
Mxdvi.c | 233-------------------------------------------------------------------------------
Mxdvi.h | 24------------------------
6 files changed, 0 insertions(+), 1443 deletions(-)

diff --git a/dvi-draw.c b/dvi-draw.c @@ -39,8 +39,6 @@ NOTE: #include "dvi.h" -#define DEFAULT_SOURCE_PATH ".:%S" /* files edited by source specials */ - static struct frame frame0; /* dummy head of list */ #ifdef TEXXET static struct frame *scan_frame; /* head frame for scanning */ @@ -1514,7 +1512,6 @@ draw_page() * so the global variables must be separate. */ -static struct frame geom_frame0; /* dummy head of list */ #if TEXXET static struct frame *geom_scan_frame; /* head frame for scanning */ #endif @@ -1932,644 +1929,6 @@ geom_scan_part(g_info, minframe, current_dimconv) } /* end for */ } - -/* - * Main scanning routine. - */ - -static void -geom_scan(g_info) - struct geom_info *g_info; -{ - off_t pos_save; - struct drawinf currinf_save; - ubyte maxchar_save; - - if (dvi_pointer_frame != NULL) - pos_save = fseek(dvi_file, 0L, SEEK_CUR) - - (dvi_pointer_frame->end - dvi_pointer_frame->pos); - (void) fseek(dvi_file, page_info[current_page].offset, - SEEK_SET); - - currinf_save = currinf; - maxchar_save = maxchar; - - bzero((char *) &currinf.data, sizeof currinf.data); - currinf.tn_table_len = TNTABLELEN; - currinf.tn_table = tn_table; - currinf.tn_head = tn_head; - currinf.pos = currinf.end = dvi_buffer; - currinf.virtual = NULL; - - if (!setjmp(g_info->done_env)) - geom_scan_part(g_info, geom_current_frame = &geom_frame0, dimconv); - - maxchar = maxchar_save; - currinf = currinf_save; - - if (dvi_pointer_frame != NULL) { - (void) fseek(dvi_file, pos_save, SEEK_SET); - dvi_pointer_frame->pos = dvi_pointer_frame->end = dvi_buffer; - } -} - - -/* - * Routines for source special lookup - */ - -static void -src_spec_box(struct geom_info *, long, long, long, long); - -static void -src_spec_special(struct geom_info *, const char *); - -struct src_parsed_special { - int line; - int col; - char *filename; - size_t filename_len; -}; - -struct src_spec_data { - long x, y; /* coordinates we're looking for */ - unsigned long distance; /* best distance so far */ - Boolean recent_in_best; /* most recent string == XXX->best */ - struct src_parsed_special /* best special so far */ - best; - struct src_parsed_special /* most recent special */ - recent; -}; - -static void -src_parse(str, parsed) - const char *str; - struct src_parsed_special *parsed; -{ - const char *p; - - p = str + 4; /* skip "src:" */ - - if (*p >= '0' && *p <= '9') { - parsed->line = atoi(p); - do ++p; - while (*p >= '0' && *p <= '9'); - } - - parsed->col = 0; - if (*p == ':') { - ++p; - parsed->col = atoi(p); - while (*p >= '0' && *p <= '9') ++p; - } - - if (*p == ' ') ++p; - - if (*p != '\0') { - size_t len = strlen(p) + 1; - - if (len > parsed->filename_len) { - if (parsed->filename_len != 0) - free(parsed->filename); - parsed->filename_len = (len & -8) + 64; - parsed->filename = xmalloc(parsed->filename_len); - } - memcpy(parsed->filename, p, len); - } -} - -static void -src_spec_box(g_info, ulx, uly, lrx, lry) - struct geom_info *g_info; - long ulx, uly, lrx, lry; -{ - struct src_spec_data *data = g_info->geom_data; - unsigned long distance; - - distance = 0; - - if (data->x < ulx) distance += (ulx - data->x) * (ulx - data->x); - else if (data->x > lrx) distance += (data->x - lrx) * (data->x - lrx); - - if (data->y < uly) distance += (uly - data->y) * (uly - data->y); - else if (data->y > lry) distance += (data->y - lry) * (data->y - lry); - - if (distance < data->distance) { - data->distance = distance; - - /* Copy it over */ - if (!data->recent_in_best) { - data->best.line = data->recent.line; - data->best.col = data->recent.col; - if (data->recent.filename_len != 0) { - if (data->best.filename_len < data->recent.filename_len) { - if (data->best.filename_len != 0) - free(data->best.filename); - data->best.filename_len = data->recent.filename_len; - data->best.filename = xmalloc(data->best.filename_len); - } - memcpy(data->best.filename, data->recent.filename, - data->recent.filename_len); - } - - data->recent_in_best = True; - } - - /* Quit early if we've found our glyph. */ - if (distance == 0 && data->best.filename_len != 0) - longjmp(g_info->done_env, 1); - } -} - -static void -src_spec_special(g_info, str) - struct geom_info *g_info; - const char *str; -{ - struct src_spec_data *data = g_info->geom_data; - - if (memcmp(str, "src:", 4) != 0) - return; - - src_parse(str, &data->recent); - - /* - * If this is the first special on the page, we may already have - * spotted the nearest box. - */ - - if (data->best.filename_len == 0) { - data->best.line = data->recent.line; - data->best.col = data->recent.col; - if (data->recent.filename_len != 0) { - if (data->best.filename_len < data->recent.filename_len) { - if (data->best.filename_len != 0) - free(data->best.filename); - data->best.filename_len = data->recent.filename_len; - data->best.filename = xmalloc(data->best.filename_len); - } - memcpy(data->best.filename, data->recent.filename, - data->recent.filename_len); - - data->recent_in_best = True; - } - - if (data->distance == 0) - longjmp(g_info->done_env, 1); - } - else - data->recent_in_best = False; -} - -/* - * Routines for reverse searches on other pages. - */ - -static struct src_parsed_special found; -static jmp_buf scan_env; - -static void -scan_first_src_spcl(str) - char *str; -{ - if (memcmp(str, "src:", 4) != 0) - return; - - src_parse(str, &found); - - longjmp(scan_env, 1); -} - -static void -scan_last_src_spcl(str) - char *str; -{ - if (memcmp(str, "src:", 4) != 0) - return; - - src_parse(str, &found); -} - -/* - * Information on how to search for source files. - */ - -#include "filf-app.h" /* application-related defs, etc. */ -#include "filefind.h" - -static const char no_f_str_tex[] = "/%f"; - -static struct findrec search_tex = { - /* path1 */ no_f_str_tex, /* flag value: uninitialized */ -#if CFGFILE - /* envptr */ NULL, -#endif - /* path2 */ DEFAULT_SOURCE_PATH, - /* type */ "source", - /* fF_etc */ "fF", - /* x_var_char */ 'f', - /* n_var_opts */ 2, - /* no_f_str */ no_f_str_tex, - /* no_f_str_end */ no_f_str_tex + sizeof(no_f_str_tex) - 1, - /* abs_str */ "%f", - /* pct_s_str */ "%qtex//", - { - /* v.stephead */ NULL, - /* v.pct_s_head */ NULL, - /* v.pct_s_count */ 0, - /* v.pct_s_atom */ NULL, - /* v.rootp */ NULL, - } -}; - - -static void -src_spawn_editor(parsed) - const struct src_parsed_special *parsed; -{ - char scr_str[5 * sizeof(int) / 2]; - const char *filename2; - Boolean found_filename = False; - size_t buffer_pos; - int argc; - char **argv; - const char *p, *p1; - char *q; - FILE *f; - int i; - - /* Used to store argv[] text. */ - static char *buffer; - static size_t buffer_len = 0; - - /* first, determine the editor if necessary */ - if (resource.editor == NULL || *resource.editor == '\0') { - p = getenv("XEDITOR"); - if (p != NULL) - resource.editor = xstrdup(p); - else { - - p = getenv("VISUAL"); - if (p == NULL) { - p = getenv("EDITOR"); - if (p == NULL) - p = "vi"; - } - q = xmalloc(strlen(p) + 10); - memcpy(q, "xterm -e ", 9); - strcpy(q + 9, p); - resource.editor = q; - } - } - - /* Now search for the file (same algorithm as PS files). */ - f = NULL; - /* first try the same path as the dvi file */ - if (parsed->filename[0] != '/') { - p = rindex(dvi_name, '/'); - if (p == NULL) filename2 = parsed->filename; - else { - unsigned len1, len2; - - len1 = ++p - dvi_name; - len2 = strlen(parsed->filename) + 1; - if (len1 + len2 > ffline_len) - expandline(len1 + len2); - bcopy(dvi_name, ffline, len1); - bcopy(parsed->filename, ffline + len1, len2); - filename2 = ffline; - } - if (debug & DBG_OPEN) Printf("Trying source special file %s\n", - filename2); - f = xfopen(filename2, "r"); - } - - if (f == NULL) { - - /* - * Set up the paths, if necessary. - */ - - if (search_tex.path1 == no_f_str_tex) { /* if uninitialized */ -#if CFGFILE - if ((search_tex.path1 = getenv("XDVISOURCES")) == NULL) - search_tex.path1 = getenv("TEXINPUTS"); - search_tex.envptr = ffgetenv("TEXINPUTS"); - /* clear it if it's a getenv() placeholder */ - if (search_tex.envptr != NULL - && search_tex.envptr->value == NULL) - search_tex.envptr = NULL; -#else /* not CFGFILE */ - if ((search_tex.path1 = getenv("XDVISOURCES")) == NULL - && (search_tex.path1 = getenv("TEXINPUTS")) == NULL) { - search_tex.path1 = search_tex.path2; - search_tex.path2 = NULL; - } -#endif /* not CFGFILE */ - } - - f = filefind(parsed->filename, &search_tex, (const char **) NULL); - filename2 = ffline; - } - - /* if still no luck, complain */ - if (f == NULL) - WARN1(XmDIALOG_ERROR, "Cannot find source special file\n`%s'", - parsed->filename); - else { - struct stat buf; - - if (fstat(fileno(f), &buf) == -1) { - perror(parsed->filename); - } - - Fclose(f); - ++n_files_left; - - if (buffer_len == 0) - buffer = xmalloc(buffer_len = 128); - buffer_pos = 0; - argc = 0; - - p = resource.editor; - while (*p == ' ' || *p == '\t') ++p; - - for (;;) { - size_t len; - - if (*p == '%') { - p1 = p; - switch (p[1]) { - case '\0': - --p; /* partially undo p += 2 later */ - /* control falls through */ - case '%': - len = 1; - break; - case 'l': - p1 = scr_str; - len = snprintf(scr_str, sizeof scr_str, "%d", - parsed->line); - break; - case 'c': - if (parsed->col == 0) { - p += 2; - continue; - } - p1 = scr_str; - len = snprintf(scr_str, sizeof scr_str, "%d", - parsed->col); - break; - case 'f': - p1 = filename2; - len = strlen(filename2); - found_filename = True; - break; - default: - len = 2; - } - p += 2; - } - else if (*p == '\0' || *p == ' ' || *p == '\t') { - buffer[buffer_pos++] = '\0'; - ++argc; - while (*p == ' ' || *p == '\t') ++p; - if (*p == '\0') { - if (found_filename) - break; /* done */ - p = "+%l %f"; - } - continue; /* don't copy anything over */ - } - else { - p1 = p; - len = strcspn(p, "% \t"); - p += len; - } - - /* copy over len bytes starting at p1 into the buffer, */ - /* leaving at least one byte free */ - if (buffer_pos + len >= buffer_len) { - buffer_len = ((buffer_pos + len) / 128 + 1) * 128; - buffer = xrealloc(buffer, buffer_len); - } - memcpy(buffer + buffer_pos, p1, len); - buffer_pos += len; - } - - argv = xmalloc((argc + 1) * sizeof(char *)); - q = buffer; - for (i = 0; i < argc; ++i) { - argv[i] = q; - q += strlen(q) + 1; - } - - /* NULL-terminate argument list */ - argv[argc] = NULL; - - Fflush(stdout); /* to avoid double buffering */ - Fflush(stderr); - - switch (vfork()) { - case -1: - perror("[xdvi] vfork"); - break; - case 0: /* child */ - execvp(argv[0], argv); - - Fprintf(stderr, "%s: Execvp of %s failed.\n", prog, - argv[0]); - Fflush(stderr); - _exit(1); - } - - free(argv); - } -} - - -/* - * The main routine for source specials (reverse search). - */ - -void -source_reverse_search(x, y) - int x, y; -{ - struct geom_info g_info; - struct src_spec_data data; - struct src_parsed_special *foundp; - - g_info.geom_box = src_spec_box; - g_info.geom_special = src_spec_special; - g_info.geom_data = &data; - - data.x = x; - data.y = y; - data.distance = 0xffffffff; - data.recent_in_best = True; - data.best.filename_len = data.recent.filename_len = 0; - foundp = &data.best; - - geom_scan(&g_info); - - if (data.best.filename_len == 0) { - /* - * nothing found on current page; - * scan next and previous pages with increasing offset - */ - int upper, lower; - off_t pos_save; - struct drawinf currinf_save; - ubyte maxchar_save; - - /* Save file position */ - - if (dvi_pointer_frame != NULL) - pos_save = fseek(dvi_file, 0L, SEEK_CUR) - - (dvi_pointer_frame->end - dvi_pointer_frame->pos); - - currinf_save = currinf; - maxchar_save = maxchar; - - upper = lower = current_page; - found.filename_len = 0; /* mark it as empty */ - for (;;) { - - if (++upper < total_pages) { - (void) fseek(dvi_file, page_info[upper].offset, - SEEK_SET); - bzero((char *) &currinf.data, sizeof currinf.data); - currinf.tn_table_len = TNTABLELEN; - currinf.tn_table = tn_table; - currinf.tn_head = tn_head; - currinf.pos = currinf.end = dvi_buffer; - currinf.virtual = NULL; - - if (setjmp(scan_env) == 0) { - /* find first src special */ - spcl_scan(scan_first_src_spcl); - } - else { /* found it */ - lower = upper; - break; - } - } - else if (lower < 0) - break; - - if (--lower >= 0) { - (void) fseek(dvi_file, page_info[lower].offset, - SEEK_SET); - bzero((char *) &currinf.data, sizeof currinf.data); - currinf.tn_table_len = TNTABLELEN; - currinf.tn_table = tn_table; - currinf.tn_head = tn_head; - currinf.pos = currinf.end = dvi_buffer; - currinf.virtual = NULL; - - spcl_scan(scan_last_src_spcl); - if (found.filename_len != 0) - break; - } - } - - if (found.filename_len != 0) - WARN1(XmDIALOG_WARNING, - "No source specials on this page - nearest on page %d", - lower + pageno_correct); - else { - /* nothing found at all; complain */ - XBell(DISP, 0); - WARN(XmDIALOG_ERROR, "No source specials in this .dvi file"); - } - - /* Restore file status. */ - - maxchar = maxchar_save; - currinf = currinf_save; - - if (dvi_pointer_frame != NULL) { - (void) fseek(dvi_file, pos_save, SEEK_SET); - dvi_pointer_frame->pos = dvi_pointer_frame->end = dvi_buffer; - } - - foundp = &found; - } - - if (data.recent.filename_len != 0) - free(data.recent.filename); - - if (foundp->filename_len != 0) { - src_spawn_editor(foundp); - free(foundp->filename); - } -} - - -/* - * Debug routines for source special display (highlight the first box - * after each source special, or highlight each box). - */ - -static void -src_spec_show_box(struct geom_info *, long, long, long, long); - -static void -src_spec_show_special(struct geom_info *, const char *); - -struct src_spec_show_data { - Boolean do_this_one; /* flag set after source special */ - Boolean do_them_all; /* flag to reset the above to */ -}; - -static void -src_spec_show_box(g_info, ulx, uly, lrx, lry) - struct geom_info *g_info; - long ulx, uly, lrx, lry; -{ - struct src_spec_show_data *data = g_info->geom_data; - - if (data->do_this_one) { - long x = ulx / mane.shrinkfactor; - long y = uly / mane.shrinkfactor; - - XDrawRectangle(DISP, mane.win, highGC, - x - mane_base_x, y - mane_base_y, - lrx / mane.shrinkfactor - x, lry / mane.shrinkfactor - y); - - data->do_this_one = data->do_them_all; - } -} - - /* ARGSUSED */ -static void -src_spec_show_special(g_info, str) - struct geom_info *g_info; - const char *str; -{ - if (memcmp(str, "src:", 4) != 0) - return; - - ((struct src_spec_show_data *)g_info->geom_data)->do_this_one = True; -} - -void -source_special_show(wide_bool do_them_all) -{ - struct geom_info g_info; - struct src_spec_show_data data; - - g_info.geom_box = src_spec_show_box; - g_info.geom_special = src_spec_show_special; - g_info.geom_data = &data; - - data.do_this_one = data.do_them_all = do_them_all; - - geom_scan(&g_info); -} - - /* * Routines for forward search (look up a source line). * @@ -2580,142 +1939,13 @@ source_special_show(wide_bool do_them_all) * special, and the box to highlight. */ -/* These variables are referenced by src_scan_special(). */ - -static int src_this_line; -static size_t src_this_file_strcmp; -static int src_line; -static int src_col; -static const char *src_file; -static int src_page; -static jmp_buf src_env; -static Boolean found_src; -static unsigned long best_distance; -static unsigned long best_col_dist; -static int best_line; -static int best_page; -static off_t best_offset; -static off_t max_offset; - /* Some of the above, plus these below, are used by geom_scan_part(). */ -static Boolean src_fwd_active; static long src_fwd_min_x, src_fwd_max_x; static long src_fwd_min_y, src_fwd_max_y; static long src_fwd_min_x2, src_fwd_max_x2; /* hot point for spcl */ static long src_fwd_min_y2, src_fwd_max_y2; -static void -src_scan_special(str) - char *str; -{ - char *p; - int col = 0; - unsigned long distance; - unsigned long col_dist; - - if (memcmp(str, "src:", 4) != 0) - return; - - found_src = True; - - p = str + 4; - if (*p >= '0' && *p <= '9') { - src_this_line = atoi(p); - do ++p; - while (*p >= '0' && *p <= '9'); - } - - if (*p == ':') { - ++p; - col = atoi(p); - while (*p >= '0' && *p <= '9') ++p; - } - - if (*p == ' ') ++p; - - if (*p == '.' && p[1] == '/') /* ignore leading ./ path component */ - p += 2; - - if (*p != '\0') - src_this_file_strcmp = strcmp(p, src_file); - - if (src_this_file_strcmp != 0) - return; - - distance = (src_line > src_this_line - ? src_line - src_this_line - : 2 * (src_this_line - src_line)); /* favor earlier lines */ - - if (distance < best_distance) { /* found a better line */ - best_distance = distance; - best_line = src_this_line; - best_page = src_page; - max_offset = best_offset = xtell(currinf.pos); - } - else if (distance == best_distance) /* if still on a good line */ - max_offset = xtell(currinf.pos); - - if (distance == 0 && best_distance == 0) { /* found a better col */ - col_dist = (src_col > col - ? src_col - col - : 2 * (col - src_col)); - - if (col_dist < best_col_dist) { - best_col_dist = col_dist; - best_page = src_page; - max_offset = best_offset = xtell(currinf.pos); - } - else if (col_dist == best_col_dist) - max_offset = xtell(currinf.pos); - } -} - -static void -src_spec_fwd_box(struct geom_info *, long, long, long, long); - -static void -src_spec_fwd_special(struct geom_info *, const char *); - - /* ARGSUSED */ -static void -src_spec_fwd_box(g_info, ulx, uly, lrx, lry) - struct geom_info *g_info; - long ulx, uly, lrx, lry; -{ - if (src_fwd_active) { - if (ulx < src_fwd_min_x) src_fwd_min_x = ulx; - if (uly < src_fwd_min_y) src_fwd_min_y = uly; - if (lrx > src_fwd_max_x) src_fwd_max_x = lrx; - if (lry > src_fwd_max_y) src_fwd_max_y = lry; - } -} - -static void -src_spec_fwd_special(g_info, str) - struct geom_info *g_info; - const char *str; -{ - long pos; - - if (memcmp(str, "src:", 4) != 0) /* if not "src:" */ - return; - - pos = xtell(currinf.pos); - if (pos >= best_offset) - src_fwd_active = True; - - if (src_fwd_active) { - if (G_PXL_H < src_fwd_min_x2) src_fwd_min_x2 = G_PXL_H; - if (G_PXL_H > src_fwd_max_x2) src_fwd_max_x2 = G_PXL_H; - if (PXL_V < src_fwd_min_y2) src_fwd_min_y2 = PXL_V; - if (PXL_V > src_fwd_max_y2) src_fwd_max_y2 = PXL_V; - - if (pos > max_offset) - longjmp(g_info->done_env, 1); - } -} - /* * Routine to actually draw the box. */ @@ -2745,142 +1975,3 @@ source_fwd_draw_box() (src_fwd_max_y + PAD) / mane.shrinkfactor - y); } } - -void -source_forward_search(str) - const char *str; -{ - off_t pos_save; - struct drawinf currinf_save; - ubyte maxchar_save; - struct geom_info g_info; - - if (debug & DBG_CLIENT) - printf("Entering source_forward_search(%s)\n", str); - - src_file = str; - while (*src_file == '0') ++src_file; - if (*src_file < '1' || *src_file > '9') { - fprintf(stderr, - "Badly formatted source special; ignoring: \"%s\"\n", str); - return; - } - src_line = atoi(src_file); - while (*src_file >= '0' && *src_file <= '9') ++src_file; - - src_col = 0; - if (*src_file == ':') { - ++src_file; - src_col = atoi(src_file); - while (*src_file >= '0' && *src_file <= '9') ++src_file; - } - - if (*src_file == ' ') ++src_file; - - if (debug & DBG_CLIENT) - printf("File = \"%s\", line = %d, col = %d\n", src_file, src_line, - src_col); - - /* Save status of dvi_file reading (in case we hit an error and resume - drawing). */ - - if (dvi_pointer_frame != NULL) - pos_save = fseek(dvi_file, 0L, SEEK_CUR) - - (dvi_pointer_frame->end - dvi_pointer_frame->pos); - (void) fseek(dvi_file, page_info[0].offset, SEEK_SET); - - currinf_save = currinf; - maxchar_save = maxchar; - - bzero((char *) &currinf.data, sizeof currinf.data); - currinf.tn_table_len = TNTABLELEN; - currinf.tn_table = tn_table; - currinf.tn_head = tn_head; - currinf.pos = currinf.end = dvi_buffer; - currinf.virtual = NULL; - - /* Start search over pages */ - - found_src = False; - best_distance = best_col_dist = 0xffffffff; - src_this_line = 0; /* initialize things that are kept as defaults*/ - src_this_file_strcmp = 1; - if (setjmp(src_env) == 0) { - - /* These two lines do the actual scanning (first pass). */ - for (src_page = 0; src_page < total_pages; ++src_page) - spcl_scan(src_scan_special); - - if (best_distance == 0xffffffff) { - if (!found_src) - WARN(XmDIALOG_ERROR, "No source specials in the dvi file"); - else - WARN1(XmDIALOG_ERROR, - "No references to source file \"%s\" in dvi file", - src_file); - - /* Restore file position. */ - maxchar = maxchar_save; - currinf = currinf_save; - - if (dvi_pointer_frame != NULL) { - (void) fseek(dvi_file, pos_save, SEEK_SET); - dvi_pointer_frame->pos = dvi_pointer_frame->end - = dvi_buffer; - } - - return; - } - if (debug & DBG_CLIENT) - printf("Found close match: line %d on page %d, offset %jd\n", - best_line, best_page + pageno_correct, best_offset); - } - else { - if (debug & DBG_CLIENT) - printf("Found exact match on page %d, offset %jd\n", - best_page + pageno_correct, best_offset); - } - - /* - * In this case we don't need to restore maxchar and currinf, since - * we won't resume drawing -- we'll jump to a new page instead. - */ - - /* Move to that page. */ - - if (current_page != best_page) - goto_page(best_page, home); - ev_flags |= EV_NEWPAGE; - XMapRaised(DISP, XtWindow(top_level)); - - /* Now search that particular page. */ - - g_info.geom_box = src_spec_fwd_box; - g_info.geom_special = src_spec_fwd_special; - g_info.geom_data = NULL; - - src_fwd_active = False; - src_fwd_min_x = src_fwd_min_x2 = src_fwd_min_y = src_fwd_min_y2 = - 0x7fffffff; - src_fwd_max_x = src_fwd_max_x2 = src_fwd_max_y = src_fwd_max_y2 = - -0x7fffffff; - source_fwd_box_page = -1; /* in case of error, suppress box */ - - (void) fseek(dvi_file, page_info[best_page].offset, SEEK_SET); - currinf.tn_table_len = TNTABLELEN; - currinf.tn_table = tn_table; - currinf.tn_head = tn_head; - currinf.pos = currinf.end = dvi_buffer; - currinf.virtual = NULL; - - if (!setjmp(g_info.done_env)) - geom_scan_part(&g_info, geom_current_frame = &geom_frame0, dimconv); - - if (!src_fwd_active) { - if (debug & DBG_CLIENT) - fprintf(stderr, - "geom_scan_part() failed to re-find the special!\n"); - } - else - source_fwd_box_page = current_page; -} diff --git a/dvi-init.c b/dvi-init.c @@ -814,19 +814,6 @@ init_dvi_file() (void) internal_init_dvi(); } -/** - ** set_dvi_property sets the appropriate property for the main - ** window (used in source special handoff). - **/ - -void -set_dvi_property() -{ - XChangeProperty(DISP, XtWindow(top_level), ATOM_DVI_FILE, ATOM_DVI_FILE, - 8, PropModeReplace, dvi_property, dvi_property_length); -} - - static Widget dvi_popup = NULL; /* warning popup for corrupt dvi file */ /** diff --git a/events.c b/events.c @@ -138,9 +138,6 @@ static ACTION_DECL(Act_hwheel); static ACTION_DECL(Act_wheel_actions); static ACTION_DECL(Act_motion); static ACTION_DECL(Act_release); -ACTION_DECL(Act_source_special); -ACTION_DECL(Act_show_source_specials); -ACTION_DECL(Act_show_all_boxes); XtActionsRec Actions[] = { @@ -177,9 +174,6 @@ XtActionsRec Actions[] = { {"wheel-actions", Act_wheel_actions}, {"motion", Act_motion}, {"release", Act_release}, - {"source-special", Act_source_special}, - {"show-source-specials",Act_show_source_specials}, - {"show-all-boxes", Act_show_all_boxes}, }; Cardinal num_actions = XtNumber(Actions); @@ -1884,73 +1878,11 @@ ACTION(Act_release) mouse_release(event); } - - -/* Actions for source specials. */ - -ACTION(Act_source_special) -{ - Window ww; - - if ((event->type == ButtonPress && mouse_release != null_mouse) - || alt.win != (Window) 0) { - XBell(DISP, 0); - return; - } - - source_reverse_x = event->xbutton.x; - source_reverse_y = event->xbutton.y; - if (event->xbutton.window != mane.win) - (void) XTranslateCoordinates(DISP, - RootWindowOfScreen(SCRN), mane.win, - event->xbutton.x_root, event->xbutton.y_root, - &source_reverse_x, &source_reverse_y, - &ww); /* throw away last argument */ - - source_reverse_x = (source_reverse_x + mane_base_x) * mane.shrinkfactor; - source_reverse_y = (source_reverse_y + mane_base_y) * mane.shrinkfactor; - - ev_flags |= EV_SRC; -} - -ACTION(Act_show_source_specials) -{ - if ((event->type == ButtonPress && mouse_release != null_mouse) - || alt.win != (Window) 0) { - XBell(DISP, 0); - return; - } - - if (!(ev_flags & EV_SRC)) { - source_reverse_x = -1; - source_show_all = False; - ev_flags |= EV_SRC; - } -} - -ACTION(Act_show_all_boxes) -{ - if ((event->type == ButtonPress && mouse_release != null_mouse) - || alt.win != (Window) 0) { - XBell(DISP, 0); - return; - } - - if (!(ev_flags & EV_SRC)) { - source_reverse_x = -1; - source_show_all = True; - ev_flags |= EV_SRC; - } -} - - #undef ACTION #undef GET_ARG4 #undef GET_ARG #undef TOGGLE - - /*ARGSUSED*/ void handle_expose(widget, closure, ev, cont) @@ -1978,44 +1910,6 @@ handle_expose(widget, closure, ev, cont) #undef event - -void -/* ARGSUSED */ -handle_property_change(widget, junk, ev, cont) - Widget widget; - XtPointer junk; - XEvent *ev; - Boolean *cont; /* unused */ -#define event (&(ev->xproperty)) -{ - char *src_goto_property; - size_t src_goto_len; - - if (event->window != XtWindow(top_level) - || event->atom != ATOM_SRC_GOTO) /* if spurious event */ - return; - - /* - * Retrieve the data from our window property. - */ - - src_goto_len = property_get_data(XtWindow(top_level), ATOM_SRC_GOTO, - (unsigned char **) &src_goto_property, XGetWindowProperty); - - if (src_goto_len == 0) { - if (debug & DBG_CLIENT) - puts("SRC_GOTO gave us nothing"); - return; - } - - source_forward_string = src_goto_property; - ev_flags |= EV_SRC; -} - -#undef event - - - void handle_messages(widget, closure, event, cont) Widget widget; @@ -2034,7 +1928,6 @@ handle_messages(widget, closure, event, cont) } - /* * Interrupt system for receiving events. The program sets a flag * whenever an event comes in, so that at the proper time (i.e., when @@ -2874,29 +2767,6 @@ do_pages() (void) check_dvi_file(); } - else if (ev_flags & EV_SRC) { - /* Source special operations are deferred to here because - * they call geom_scan(), which may call define_font(), - * which may call makefont(), which may call read_events() - * recursively. - */ - if (!check_dvi_file()) - /* if dvi file is corrupted or has changed */ - continue; - - ev_flags &= ~EV_SRC; - if (source_forward_string != NULL) { - const char *s = source_forward_string; - - source_forward_string = NULL; - source_forward_search(s); - } - else if (source_reverse_x != -1) - source_reverse_search(source_reverse_x, - source_reverse_y); - else source_special_show(source_show_all); - } - else if (ev_flags & EV_MAG_MOVE) { if (alt.win == (Window) 0) ev_flags &= ~EV_MAG_MOVE; else if (abs(new_mag_x - mag_x) > diff --git a/util.c b/util.c @@ -34,8 +34,6 @@ NOTE: #include <pwd.h> #include <stdarg.h> -#include <X11/Xmd.h> /* get WORD64 and LONG64 */ - #include "xdvi.h" @@ -43,58 +41,6 @@ NOTE: * General utility routines. */ -static void -exit_clean_windows() -{ - long *window_list; - size_t window_list_len; - long *window_list_end; - long *wp; - - window_list_len = property_get_data(DefaultRootWindow(DISP), - ATOM_XDVI_WINDOWS, (unsigned char **) &window_list, - XGetWindowProperty); - - if (window_list_len == 0) - return; - - if (window_list_len % sizeof(long) != 0) { - XDeleteProperty(DISP, DefaultRootWindow(DISP), ATOM_XDVI_WINDOWS); - return; - } - - window_list_len /= sizeof(long); - - /* Loop over list of windows. */ - - window_list_end = window_list + window_list_len; - - for (wp = window_list; wp < window_list_end; ++wp) - if (*wp == XtWindow(top_level)) { - - --window_list_len; - --window_list_end; - memcpy(wp, wp + 1, (window_list_end - wp) * sizeof(long)); - - if (window_list_len == 0) - XDeleteProperty(DISP, DefaultRootWindow(DISP), - ATOM_XDVI_WINDOWS); - else - XChangeProperty(DISP, DefaultRootWindow(DISP), - ATOM_XDVI_WINDOWS, ATOM_XDVI_WINDOWS, 32, PropModeReplace, - (unsigned char *) window_list, window_list_len); - - XFlush(DISP); - return; - } - - if (debug & DBG_CLIENT) - printf("Cannot find window %08lx in list when exiting.\n", - XtWindow(top_level)); - - return; -} - /* * This routine should be used for all exits, except for really early ones. @@ -104,9 +50,6 @@ void xdvi_exit(status) int status; { - /* Clean up the "xdvi windows" property in the root window. */ - if (top_level) - exit_clean_windows(); exit(status); } @@ -621,83 +564,6 @@ avladd(key, key_len, headp, size) return ap; } - - -/* - * On 64-bit platforms, XGetWindowProperty and related functions convert - * properties with format=32 to arrays of longs. This function keeps that - * convention. - * The return value is the total number of bytes in the buffer. - */ - -#if defined(WORD64) || defined(LONG64) -# define LONG_CONV_64(bytes, format) ((bytes) << ((format) >> 5)) -#else -# define LONG_CONV_64(bytes, format) (bytes) -#endif - -size_t -property_get_data(w, a, ret_buf, x_get_property) - Window w; - Atom a; - unsigned char **ret_buf; - int (*x_get_property) (Display *, Window, Atom, long, - long, Bool, Atom, Atom *, int *, unsigned long *, - unsigned long *, unsigned char **); -{ - /* all of these are in 8-bit units */ - unsigned long byte_offset = 0; - Atom type_ret; - int format_ret; - unsigned long nitems_ret; - unsigned long bytes_after_ret = 0; - unsigned char *prop_ret = NULL; - - /* - * buffer for collecting returned data; this is static to - * avoid expensive malloc()s at every call (which is often!) - */ - static unsigned char *buffer = NULL; - static size_t buffer_len = 0; - - while (x_get_property(DISP, w, - a, byte_offset / 4, (bytes_after_ret + 3) / 4, False, a, - &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop_ret) - == Success) { - - if (type_ret != a || format_ret == 0) break; - - nitems_ret *= (format_ret / 8); /* convert to bytes */ - - if (LONG_CONV_64(byte_offset + nitems_ret, format_ret) - >= buffer_len) { - buffer_len += 256 - * ((LONG_CONV_64(byte_offset + nitems_ret, format_ret) - - buffer_len) / 256 + 1); - buffer = (buffer == NULL ? xmalloc(buffer_len) - : xrealloc(buffer, buffer_len)); - } - - /* the +1 captures the extra '\0' that Xlib puts after the end. */ - memcpy(buffer + LONG_CONV_64(byte_offset, format_ret), prop_ret, - LONG_CONV_64(nitems_ret, format_ret) + 1); - byte_offset += nitems_ret; - - XFree(prop_ret); - prop_ret = NULL; - - if (bytes_after_ret == 0) /* got all data */ - break; - } - - if (prop_ret != NULL) - XFree(prop_ret); - - *ret_buf = buffer; - return LONG_CONV_64(byte_offset, format_ret); -} - - /* * Prepare the file descriptor to generate SIGPOLL/SIGIO events. * If called with a True argument, set it up for non-blocking I/O. diff --git a/xdvi.c b/xdvi.c @@ -200,10 +200,6 @@ static XrmOptionDescRec options[] = { {"+nomakepk", ".makePk", XrmoptionNoArg, (XPointer) "on"}, #endif {"-mfmode", ".mfMode", XrmoptionSepArg, (XPointer) NULL}, -{"-editor", ".editor", XrmoptionSepArg, (XPointer) NULL}, -{"-sourceposition",".sourcePosition", XrmoptionSepArg, (XPointer) NULL}, -{"-nofork", ".fork", XrmoptionNoArg, (XPointer) "off"}, -{"+nofork", ".fork", XrmoptionNoArg, (XPointer) "on"}, {"-l", ".listFonts", XrmoptionNoArg, (XPointer) "on"}, {"+l", ".listFonts", XrmoptionNoArg, (XPointer) "off"}, {"-nofreetypefonts", ".freetypeFonts", XrmoptionNoArg, (XPointer) "off"}, @@ -301,9 +297,6 @@ static const char base_translations[] = "" "s<Btn1Down>:drag(|)\n" "s<Btn2Down>:drag(+)\n" "s<Btn3Down>:drag(-)\n" -"c<Btn1Down>:source-special()\n" -"c<Btn2Down>:show-source-specials()\n" -"c<Btn3Down>:show-all-boxes()\n" "<Btn1Down>:magnifier(*1)\n" "<Btn2Down>:magnifier(*2)\n" "<Btn3Down>:magnifier(*3)\n" @@ -355,12 +348,6 @@ static XtResource application_resources[] = { #endif {"mfMode", "MfMode", XtRString, sizeof(char *), offset(mfmode), XtRString, MFMODE}, -{"editor", "Editor", XtRString, sizeof(char *), - offset(editor), XtRString, (XtPointer) NULL}, -{"sourcePosition", "SourcePosition", XtRString, sizeof(char *), - offset(src_pos), XtRString, (XtPointer) NULL}, -{"fork", "Fork", XtRBoolean, sizeof(Boolean), - offset(src_fork), XtRString, "true"}, {"listFonts", "ListFonts", XtRBoolean, sizeof(Boolean), offset(_list_fonts), XtRString, "false"}, {"freetypeFonts", "FreetypeFonts", XtRBoolean, sizeof(Boolean), @@ -438,8 +425,6 @@ static const char *usagestr[] = { /* paper */ "papertype", /* altfont */ "font", /* mfmode */ "mode-def", - /* editor */ "editor", - /* sourceposition */ "\"linenumber filename\"", /* rv */ "^-l", "-rv", /* mgs */ subst, /* mgs1 */ silent, @@ -758,183 +743,6 @@ XdviCvtStringToBool3(dpy, args, num_args, fromVal, toVal, closure_ret) } - -/* - * Routines for running as source-special client. - * - * Resources are used as follows: - * - * ATOM_XDVI_WINDOWS is attached to the root window of the default screen - * of the display; it contains a list of (hopefully active) xdvi - * windows. - * ATOM_DVI_FILE is attached to the main xdvi window; it tells the world - * what dvi file is being viewed. It is set by that copy of xdvi - * and read by this routine. The first 8 bytes are the inode - * number, and the rest is the file name. We use 8 instead of - * sizeof(ino_t) because the latter may vary from machine to - * machine, and the format needs to be machine independent. - * ATOM_SRC_GOTO is attached to the main xdvi window; it tells that copy - * of xdvi to go to that position in the dvi file. It is set by - * this routine and read by the displaying copy of xdvi. - */ - -static int XdviErrorHandler(Display *, XErrorEvent *); - -static unsigned long xdvi_next_request = 0; -static int xerrno; -static int (*XdviOldErrorHandler)(Display *, XErrorEvent *); - -static int -XdviErrorHandler(d, event) - Display *d; - XErrorEvent *event; -{ - if (event->serial != xdvi_next_request - || event->error_code != BadWindow) - return XdviOldErrorHandler(d, event); - - xerrno = 1; - return 0; -} - -static int -XdviGetWindowProperty(display, w, property, long_offset, long_length, delete, - req_type, actual_type_return, actual_format_return, nitems_return, - bytes_after_return, prop_return) - Display *display; - Window w; - Atom property; - long long_offset, long_length; - Bool delete; - Atom req_type; - Atom *actual_type_return; - int *actual_format_return; - unsigned long *nitems_return; - unsigned long *bytes_after_return; - unsigned char **prop_return; -{ - int retval; - - xdvi_next_request = NextRequest(display); - xerrno = 0; - - retval = XGetWindowProperty(display, w, property, long_offset, - long_length, delete, req_type, actual_type_return, - actual_format_return, nitems_return, bytes_after_return, prop_return); - - return (xerrno != 0 ? BadWindow : retval); -} - -/* - * src_client_check() - Check for another running copy of xdvi viewing - * the same file. If one exists, return true and send that copy of xdvi - * the argument to -sourceposition. If not, return false. - */ - -static Boolean -src_client_check() -{ - long *window_list; - size_t window_list_len; - long *window_list_end; - long *wp; - unsigned char *p; - Boolean need_rewrite; - Boolean retval = False; - - /* - * Get window list. Copy it over - * (we'll be calling property_get_data() again). - */ - - window_list_len = property_get_data(DefaultRootWindow(DISP), - ATOM_XDVI_WINDOWS, &p, XGetWindowProperty); - - if (window_list_len == 0) { - if (debug & DBG_CLIENT) - puts("No \"xdvi windows\" property found"); - return False; - } - - if (window_list_len % sizeof(long) != 0) { - if (debug & DBG_CLIENT) - puts( - "\"xdvi windows\" property had incorrect size; deleting it."); - XDeleteProperty(DISP, DefaultRootWindow(DISP), ATOM_XDVI_WINDOWS); - return False; - } - - window_list = xmalloc(window_list_len); - memcpy(window_list, p, window_list_len); - - XdviOldErrorHandler = XSetErrorHandler(XdviErrorHandler); - - /* Loop over list of windows. */ - - need_rewrite = False; - window_list_len /= sizeof(long); - window_list_end = window_list + window_list_len; - for (wp = window_list; wp < window_list_end; ++wp) { - Window w = *wp; - unsigned char *buf_ret; - size_t len; - - if (debug & DBG_CLIENT) { - printf("Checking window %08lx -- ", w); - fflush(stdout); - } - - len = property_get_data(w, ATOM_DVI_FILE, &buf_ret, - XdviGetWindowProperty); - - if (len == 0) { - if (debug & DBG_CLIENT) - puts("(null)"); - --window_list_len; - --window_list_end; - memcpy(wp, wp + 1, (window_list_end - wp) * sizeof(long)); - --wp; - need_rewrite = True; - continue; - } - - if (debug & DBG_CLIENT) { - unsigned long ino; - int i; - - ino = 0; - for (i = 7; i >= 0; --i) - ino = (ino << 8) | buf_ret[i]; - printf("%lu `%s'\n", ino, buf_ret + 8); - } - - if (len == dvi_property_length - && memcmp(buf_ret, dvi_property, len) == 0) { - - if (debug & DBG_CLIENT) - puts("Matched!"); - - XChangeProperty(DISP, w, - ATOM_SRC_GOTO, ATOM_SRC_GOTO, 8, PropModeReplace, - (const unsigned char *) resource.src_pos, - strlen(resource.src_pos)); - - retval = True; - break; - } - } - - (void) XSetErrorHandler(XdviOldErrorHandler); - - if (need_rewrite) - XChangeProperty(DISP, DefaultRootWindow(DISP), - ATOM_XDVI_WINDOWS, ATOM_XDVI_WINDOWS, 32, PropModeReplace, - (unsigned char *) window_list, window_list_len); - - return retval; -} - - /* * Translations of valid paper types to dimensions, which are used * internally. @@ -1523,29 +1331,6 @@ or invalid argument:\n\t\"%s\", \"%s\".", postpone_popups = True; } - if (resource.src_pos != NULL) { - if (src_client_check()) { - XFlush(DISP); /* necessary to get the property set */ - return 0; - } - else if (resource.src_fork) { - /* - * No suitable xdvi found, so we start one by - * self-backgrounding. - */ - Fflush(stdout); /* these avoid double buffering */ - Fflush(stderr); - XFlush(DISP); - if (fork()) /* if initial process (do NOT use vfork()!) */ - return 0; - /* Need to adjust for changed process ID */ - prep_fd(ConnectionNumber(DISP), False); - } - } - - /* Needed for source specials and for calling ghostscript */ - xputenv("DISPLAY", XDisplayString(DISP)); - if (resource.mfmode != NULL) { char *p; @@ -1842,8 +1627,6 @@ argument is to override any papersize specials in the dvi file.\n\n", stderr); */ - XtAddEventHandler(top_level, PropertyChangeMask, False, - handle_property_change, (XtPointer) NULL); XtAddEventHandler(vport_widget, StructureNotifyMask, False, handle_resize, (XtPointer) NULL); XtAddEventHandler(draw_widget, ExposureMask, False, handle_expose, @@ -1885,17 +1668,6 @@ argument is to override any papersize specials in the dvi file.\n\n", stderr); image->byte_order = *((char *) &endian); } - /* Store window id for use by src_client_check(). */ - - { - long data = XtWindow(top_level); - - XChangeProperty(DISP, DefaultRootWindow(DISP), - ATOM_XDVI_WINDOWS, ATOM_XDVI_WINDOWS, 32, PropModeAppend, - (unsigned char *) &data, 1); - } - set_dvi_property(); - /* * Step 6: Assign colors and GCs. * Because of the latter, this has to go after Step 5. @@ -1975,11 +1747,6 @@ argument is to override any papersize specials in the dvi file.\n\n", stderr); XFreePixmap(DISP, arrow_mask); } - if (resource.src_pos != NULL) { - source_forward_string = resource.src_pos; - ev_flags |= EV_SRC; - } - do_pages(); /* NOTREACHED */ } diff --git a/xdvi.h b/xdvi.h @@ -224,14 +224,6 @@ Boolean psfig_begun = False; int source_fwd_box_page = -1; /* -1 means no box */ /* - * Information on deferred source operation. See do_pages() for meaning. - */ -const char *source_forward_string = NULL; -int source_reverse_x, source_reverse_y; -int source_show_all; - - -/* * Bitmap structure for raster ops. */ struct bitmap { @@ -364,9 +356,6 @@ extern struct _resource { Boolean makepk; #endif const char *mfmode; - const char *editor; - const char *src_pos; - Boolean src_fork; Boolean _list_fonts; Boolean freetype; Boolean reverse; @@ -566,7 +555,6 @@ Pixel *pixeltbl_t; #define EV_MAG_MOVE (1<<3) /* magnifier moved */ #define EV_MAG_GONE (1<<4) /* magnifier gone while being drawn */ #define EV_ACK (1<<5) /* used internally */ -#define EV_SRC (1<<6) /* source special operation is pending */ #define EV_NEWPAGE (1<<7) /* new page requested */ #define EV_PS_TOGGLE (1<<8) /* PostScript toggled on or off */ #define EV_NEWDOC (1<<9) /* new dvi file requested */ @@ -746,9 +734,6 @@ mouse_proc mouse_release = null_mouse; Atom atoms[5]; -#define ATOM_XDVI_WINDOWS (atoms[0]) -#define ATOM_DVI_FILE (atoms[1]) -#define ATOM_SRC_GOTO (atoms[2]) #define XA_WM_DELETE_WINDOW (atoms[3]) #define XA_WM_PROTOCOLS (atoms[4]) @@ -769,7 +754,6 @@ extern void home(wide_bool); extern void reconfig(void); extern void handle_resize(Widget, XtPointer, XEvent *, Boolean *); extern void handle_expose(Widget, XtPointer, XEvent *, Boolean *); -extern void handle_property_change(Widget, XtPointer, XEvent *, Boolean *); extern void handle_messages(Widget, XtPointer, XEvent *, Boolean *); extern void goto_page(int, home_proc); extern void set_chld(struct xchild *); @@ -801,7 +785,6 @@ extern struct font *define_font(FILE *, wide_ubyte, extern void init_page(void); extern void form_dvi_property(ino_t); extern void init_dvi_file(void); -extern void set_dvi_property(void); extern Boolean check_dvi_file(void); extern void reload_dvi_file(void); #ifndef TEXXET @@ -818,9 +801,6 @@ extern void set_ft_char(wide_ubyte, wide_ubyte); extern void open_font_file(struct font *); extern void prescan(void); extern void draw_page(void); -extern void source_reverse_search(int, int); -extern void source_special_show(wide_bool); -extern void source_forward_search(const char *); #if CFGFILE extern void readconfig(void); #endif @@ -856,10 +836,6 @@ extern const struct passwd *ff_getpw(const char **, const char *); extern unsigned long num(FILE *, int); extern long snum(FILE *, int); extern struct avl *avladd(const char *, size_t, struct avl **, size_t); -extern size_t property_get_data(Window, Atom, unsigned char **, - int (*x_get_property) (Display *, Window, Atom, long, - long, Bool, Atom, Atom *, int *, unsigned long *, - unsigned long *, unsigned char **)); extern void prep_fd(int, wide_bool); extern void read_PK_index(struct font *, wide_bool); extern void read_GF_index(struct font *, wide_bool);