commit 921113377828d744b8941c5a6a0b5fee9eed3093
parent de5126589ecc841f6e9cf3384316d37b0050f021
Author: Kyle Milz <krwmilz@gmail.com>
Date: Thu, 9 Sep 2021 17:22:05 +0000
start cleaning up main()
- remove +page argument feature
- add some style(9)
- replace dvi file argument with url (WIP)
Diffstat:
M | xdvi.c | | | 104 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
1 file changed, 52 insertions(+), 52 deletions(-)
diff --git a/xdvi.c b/xdvi.c
@@ -61,7 +61,7 @@ NOTE:
* TEXXET support reflection dvi codes (right-to-left typesetting)
*/
-#include <ctype.h>
+#include <ctype.h> /* isdigit() */
#include <err.h>
#include <math.h> /* sometimes includes atof() */
#include <stdarg.h>
@@ -79,6 +79,7 @@ NOTE:
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Command.h>
+#include "default.h" /* default_dvi, default_dvi_len */
#include "dvi-init.h" /* init_dvi_file(), init_page() */
#include "dvi-draw.h" /* prescan() */
#include "events.h" /* enable_intr(), compile_action(), ... */
@@ -490,7 +491,7 @@ usage(const char *message, ...)
(void) vfprintf(stderr, message, args);
va_end(args);
- Fputs("\n\nUsage: xdvi [+[<page>]]", stderr);
+ Fputs("\n\nUsage: wdvi ", stderr);
for (opt = options; opt < options + XtNumber(options); ++opt) {
str1 = opt->option;
if (*str1 != '-') continue;
@@ -525,7 +526,7 @@ usage(const char *message, ...)
}
if (col + 9 < 80) Putc(' ', stderr);
else Fputs("\n\t", stderr);
- Fputs("dvi_file\n", stderr);
+ Fputs("url\n", stderr);
exit(1);
}
@@ -967,10 +968,11 @@ compile_wheel_actions()
int
main(int argc, char **argv)
{
+ const char *url = NULL;
+ const char *arg;
XrmDatabase db;
Dimension screen_w, screen_h;
int i;
- char *curr_page = NULL;
/*
@@ -978,61 +980,59 @@ main(int argc, char **argv)
*/
prog = rindex(*argv, '/');
- if (prog != NULL) ++prog; else prog = *argv;
+ if (prog != NULL)
+ ++prog;
+ else
+ prog = *argv;
top_level = XtInitialize(prog, "XDvi", options, XtNumber(options),
- &argc, argv);
+ &argc, argv);
XtAddActions(Actions, num_actions);
while (--argc > 0) {
- char *current_arg = *++argv;
-
- if (*current_arg == '+')
- if (curr_page != NULL)
- usage("More than one page-number argument given.");
- else curr_page = current_arg + 1;
- else if (dvi_name != NULL)
- usage("More than one dvi file name given, \
-or invalid argument:\n\t\"%s\", \"%s\".",
- dvi_name, current_arg);
- else dvi_name = current_arg;
+ arg = *++argv;
+
+ if (url != NULL)
+ warnx("more than one url given, discarding '%s'", arg);
+ else
+ url = arg;
}
DISP = XtDisplay(top_level);
SCRN = XtScreen(top_level);
- accels_cr = XtParseAcceleratorTable(
- "<Key>Return:set()notify()unset()");
+ /* for warning popups */
+ accels_cr = XtParseAcceleratorTable("<Key>Return:set()notify()unset()");
accels_cr_click = XtParseAcceleratorTable(
- "<Key>Return:set()notify()unset()\n\
-<Btn1Down>:set()\n\
-<Btn1Up>:notify()unset()");
+ "<Key>Return:set()notify()unset()\n"
+ "<Btn1Down>:set()\n"
+ "<Btn1Up>:notify()unset()");
db = XtScreenDatabase(SCRN);
/* It's easier to do this than track creations and deletions of the
scrollbars. */
XrmPutStringResource(&db, "XDvi.file.form.vport.vertical.translations",
- "#override<Btn4Down>:file-scroll(-w)\n<Btn5Down>:file-scroll(w)");
+ "#override<Btn4Down>:file-scroll(-w)\n<Btn5Down>:file-scroll(w)");
XrmPutStringResource(&db, "XDvi.file.form.vport.horizontal.translations",
- "#override<Btn4Down>:file-scroll(-w)\n<Btn5Down>:file-scroll(w)");
+ "#override<Btn4Down>:file-scroll(-w)\n<Btn5Down>:file-scroll(w)");
XtGetApplicationResources(top_level, (XtPointer) &resource,
- application_resources, XtNumber(application_resources),
- (ArgList) NULL, 0);
+ application_resources, XtNumber(application_resources),
+ (ArgList) NULL, 0);
shrink_factor = resource.shrinkfactor;
if (resource.version_flag) {
- Printf("xdvi version %s\n", VERSION);
- exit(0);
+ Printf("wdvi version %s\n", VERSION);
+ exit(0);
}
if (resource.debug_arg != NULL)
- debug = isdigit(*resource.debug_arg) ? atoi(resource.debug_arg)
+ debug = isdigit(*resource.debug_arg) ? atoi(resource.debug_arg)
: DBG_ALL;
if (!XInternAtoms(DISP, atom_names, XtNumber(atom_names), False, atoms))
- oops("XInternAtoms failed.");
+ oops("XInternAtoms failed.");
if (debug & DBG_CLIENT) {
for (i = 0; i < XtNumber(atom_names); ++i)
@@ -1049,14 +1049,16 @@ or invalid argument:\n\t\"%s\", \"%s\".",
enable_intr();
- if (dvi_name == NULL) {
- dvi_file = fopen("default.dvi", "r");
- //act_addr_go(NULL, NULL, NULL, 0);
- dvi_name = "resume.dvi";
- ev_flags |= EV_NEWDOC;
- (void) read_events(EV_GE_NEWDOC);
- ev_flags &= ~EV_NEWDOC;
- }
+ /*
+ * The default document is always available and simplifies startup
+ * by giving inital window sizes and no error popups.
+ */
+ if ((dvi_file = fmemopen(default_dvi, default_dvi_len, "r")) == NULL)
+ err(1, "fmemopen");
+ dvi_name = "default.dvi";
+ ev_flags |= EV_NEWDOC;
+ (void) read_events(EV_GE_NEWDOC);
+ ev_flags &= ~EV_NEWDOC;
if (resource.mfmode != NULL) {
char *p;
@@ -1076,24 +1078,26 @@ or invalid argument:\n\t\"%s\", \"%s\".",
}
}
if (shrink_factor < 0)
- usage("Invalid shrink factor: %d.", shrink_factor);
+ usage("Invalid shrink factor: %d.", shrink_factor);
if (density <= 0)
- usage("Invalid shrink density: %d.", density);
+ usage("Invalid shrink density: %d.", density);
if (pixels_per_inch <= 0)
- usage("Invalid dpi value: %d.", pixels_per_inch);
+ usage("Invalid dpi value: %d.", pixels_per_inch);
if (shrink_factor > 1) {
- bak_shrink = shrink_factor;
- mane.shrinkfactor = shrink_factor; /* otherwise it's 1 */
+ bak_shrink = shrink_factor;
+ mane.shrinkfactor = shrink_factor; /* otherwise it's 1 */
}
- if (resource.sidemargin) home_x = atopix(resource.sidemargin, False);
- if (resource.topmargin) home_y = atopix(resource.topmargin, False);
+ if (resource.sidemargin)
+ home_x = atopix(resource.sidemargin, False);
+ if (resource.topmargin)
+ home_y = atopix(resource.topmargin, False);
offset_x = resource.xoffset ? atopix(resource.xoffset, True)
: pixels_per_inch;
offset_y = resource.yoffset ? atopix(resource.yoffset, True)
: pixels_per_inch;
if (!set_paper_type()) {
- const char **p;
+ _Xconst char **p;
Fprintf(stderr,
"%s: Unrecognized paper type \"%s\". Legal values are:\n ",
@@ -1133,7 +1137,6 @@ argument is to override any papersize specials in the dvi file.\n\n", stderr);
app_pixel_resources, XtNumber(app_pixel_resources),
(ArgList) NULL, 0);
-
copy = resource.copy;
fore_color_data.pixel = fore_Pixel;
@@ -1153,11 +1156,6 @@ argument is to override any papersize specials in the dvi file.\n\n", stderr);
init_font_open();
init_dvi_file();
- if (curr_page) {
- current_page = (*curr_page ? atoi(curr_page) : total_pages) - 1;
- if (current_page < 0 || current_page >= total_pages)
- usage("Invalid initial page number: %d.", current_page + 1);
- }
if (resource.prescan)
prescan();
init_page();
@@ -1217,6 +1215,8 @@ argument is to override any papersize specials in the dvi file.\n\n", stderr);
addr_args[0].value = (XtArgVal) page_w;
addr_args[1].value = (XtArgVal) vport_widget;
+ if (url != NULL)
+ addr_args[4].value = (XtArgVal) url;
addr_widget = XtCreateManagedWidget("address", asciiTextWidgetClass,
form_or_top, addr_args, XtNumber(addr_args));