SVN revision: 8961
This commit is contained in:
Kim Woelders 2004-02-13 18:13:55 +00:00
parent 41bd864b0d
commit 738a6eecde
7 changed files with 804 additions and 689 deletions

157
dox/dox.c
View File

@ -69,7 +69,8 @@
#define STARTPOS 4 /* to bypass next/prev/exit buttons for key binding positions */
typedef struct _mwmhints {
typedef struct _mwmhints
{
CARD32 flags;
CARD32 functions;
CARD32 decorations;
@ -87,7 +88,8 @@ Drawable vIcDrw;
#if USE_FNLIB
FnlibData *pFnlibData;
#endif
Window win_main, win_title, win_exit, win_next, win_prev, win_text, win_cover;
Window win_main, win_title, win_exit, win_next, win_prev, win_text,
win_cover;
int w, h, t;
Imlib_Image *im_text;
Imlib_Image *im_title;
@ -100,7 +102,8 @@ Window CreateWindow(Window parent, int x, int y, int ww, int hh);
int ReadHeader(FILE * f);
int ReadPages(FILE * f);
Window CreateWindow(Window parent, int x, int y, int ww, int hh)
Window
CreateWindow(Window parent, int x, int y, int ww, int hh)
{
Window win;
XSetWindowAttributes attr;
@ -213,7 +216,8 @@ XClearWindow(disp, win_text); \
} \
}
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
int pagenum;
int i, w, h, x, y;
@ -223,6 +227,7 @@ int main(int argc, char **argv)
Pixmap draw = 0;
Link *l = NULL, *ll = NULL;
Imlib_Border ibd;
#if !USE_IMLIB2
ImlibInitParams params;
#endif
@ -236,7 +241,8 @@ int main(int argc, char **argv)
y = 0;
pagenum = 0;
if((int)(disp = XOpenDisplay(NULL)) < 1) {
if ((int)(disp = XOpenDisplay(NULL)) < 1)
{
printf("%s: Cannot open X display.\n", argv[0]);
exit(0);
}
@ -280,7 +286,8 @@ int main(int argc, char **argv)
pFnlibData = Fnlib_init(pI1Ctx);
#endif
if (argc < 2) {
if (argc < 2)
{
printf("usage:\n"
"%s [-page page_number] [-file Edoc_fname] [-size width height] Edoc_dir\n",
argv[0]);
@ -289,15 +296,18 @@ int main(int argc, char **argv)
docdir = ".";
docfile = "MAIN";
for (i = 1; i < argc; i++) {
for (i = 1; i < argc; i++)
{
if ((!strcmp(argv[i], "-page")) && (i < (argc - 1)))
pagenum = atoi(argv[++i]);
else if ((!strcmp(argv[i], "-file")) && (i < (argc - 1)))
docfile = argv[++i];
else if ((!strcmp(argv[i], "-size")) && (i < (argc - 2))) {
else if ((!strcmp(argv[i], "-size")) && (i < (argc - 2)))
{
w = atoi(argv[++i]);
h = atoi(argv[++i]);
} else
}
else
docdir = strdup(argv[i]);
}
s = malloc(strlen(docdir) + strlen(docfile) + 2 + 20);
@ -323,7 +333,8 @@ int main(int argc, char **argv)
#else
f = fopen(s, "rt");
#endif
if (!f) {
if (!f)
{
strcpy(s, docdir);
strcat(s, "/");
strcat(s, docfile);
@ -332,8 +343,10 @@ int main(int argc, char **argv)
#else
f = fopen(s, "rt");
#endif
if (!f) {
printf("Edoc_dir %s does not contain a %s file\n", docdir, docfile);
if (!f)
{
printf("Edoc_dir %s does not contain a %s file\n", docdir,
docfile);
exit(1);
}
}
@ -351,7 +364,8 @@ int main(int argc, char **argv)
wy = (DisplayHeight(disp, DefaultScreen(disp)) - (h + t)) / 2;
#ifdef HAS_XINERAMA
{
if (XineramaIsActive(disp)) {
if (XineramaIsActive(disp))
{
Window rt, ch;
int d;
unsigned int ud;
@ -363,12 +377,17 @@ int main(int argc, char **argv)
&d, &d, &ud);
screens = XineramaQueryScreens(disp, &num);
for (i = 0; i < num; i++) {
if (pointer_x >= screens[i].x_org) {
if (pointer_x <= (screens[i].width + screens[i].x_org)) {
if (pointer_y >= screens[i].y_org) {
for (i = 0; i < num; i++)
{
if (pointer_x >= screens[i].x_org)
{
if (pointer_x <= (screens[i].width + screens[i].x_org))
{
if (pointer_y >= screens[i].y_org)
{
if (pointer_y <= (screens[i].height +
screens[i].y_org)) {
screens[i].y_org))
{
wx = ((screens[i].width - w) / 2)
+ screens[i].x_org;
wy = ((screens[i].height - (h + t)) / 2)
@ -385,10 +404,16 @@ int main(int argc, char **argv)
}
#endif
win_main = CreateWindow(root.win, wx, wy, w, h + t);
win_title = XCreateSimpleWindow(disp, win_main, 0, 0, (w - 64 - 64 - t), t, 0, 0, 0);
win_prev = XCreateSimpleWindow(disp, win_main, (w - 64 - 64 - t), 0, 64, t, 0, 0, 0);
win_next = XCreateSimpleWindow(disp, win_main, (w - 64 - 64 - t) + 64, 0, 64, t, 0, 0, 0);
win_exit = XCreateSimpleWindow(disp, win_main, (w - 64 - 64 - t) + 64 + 64, 0, t, t, 0, 0, 0);
win_title =
XCreateSimpleWindow(disp, win_main, 0, 0, (w - 64 - 64 - t), t, 0, 0, 0);
win_prev =
XCreateSimpleWindow(disp, win_main, (w - 64 - 64 - t), 0, 64, t, 0, 0, 0);
win_next =
XCreateSimpleWindow(disp, win_main, (w - 64 - 64 - t) + 64, 0, 64, t, 0,
0, 0);
win_exit =
XCreateSimpleWindow(disp, win_main, (w - 64 - 64 - t) + 64 + 64, 0, t, t,
0, 0, 0);
win_text = XCreateSimpleWindow(disp, win_main, 0, t, w, h, 0, 0, 0);
XSelectInput(disp, win_prev, ButtonPressMask | ButtonReleaseMask);
XSelectInput(disp, win_next, ButtonPressMask | ButtonReleaseMask);
@ -418,15 +443,18 @@ int main(int argc, char **argv)
page_hist[0] = 0;
for (;;) {
for (;;)
{
KeySym key;
XEvent ev;
XNextEvent(disp, &ev);
switch (ev.type) {
switch (ev.type)
{
case KeyPress:
key = XLookupKeysym(&ev.xkey, 0);
switch (key) {
switch (key)
{
case XK_Escape:
exit(0);
break;
@ -475,37 +503,47 @@ int main(int argc, char **argv)
ApplyImage2(win_next, im_next2);
else if (ev.xbutton.window == win_exit)
ApplyImage2(win_exit, im_exit2);
else {
else
{
int x, y;
x = ev.xbutton.x;
y = ev.xbutton.y;
ll = l;
while (ll) {
while (ll)
{
if ((x >= ll->x) && (y >= ll->y) &&
(x < (ll->x + ll->w)) && (y < (ll->y + ll->h))) {
(x < (ll->x + ll->w)) && (y < (ll->y + ll->h)))
{
int pg;
if (!strncmp("EXEC.", ll->name, 5)) {
if (!fork()) {
if (!strncmp("EXEC.", ll->name, 5))
{
if (!fork())
{
char *exe;
exe = &(ll->name[5]);
execl("/bin/sh", "/bin/sh", "-c", exe, NULL);
execl("/bin/sh", "/bin/sh", "-c", exe,
NULL);
exit(0);
}
} else if (!strncmp("INPUT.", ll->name, 6)) {
}
else if (!strncmp("INPUT.", ll->name, 6))
{
FILE *p;
char *exe, tmp[1024];
exe = &(ll->name[6]);
if (exe[0] != '/') {
if (exe[0] != '/')
{
sprintf(tmp, "%s/%s", docdir, exe);
findLocalizedFile(tmp);
exe = tmp;
}
p = popen(exe, "r");
if (p) {
if (p)
{
int dirlen = 0;
char *sp;
@ -515,7 +553,8 @@ int main(int argc, char **argv)
while ((*sp != '/') && (sp != exe))
sp--;
dirlen = sp - exe;
if (dirlen > 1) {
if (dirlen > 1)
{
free(docdir);
docdir = malloc(dirlen + 1);
memcpy(docdir, exe, dirlen);
@ -535,17 +574,22 @@ int main(int argc, char **argv)
l = RenderPage(draw, pagenum, w, h);
UPDATE;
}
} else {
}
else
{
pg = GetPage(ll->name);
if (pg >= 0) {
if (pg >= 0)
{
FREE_LINKS;
pagenum = pg;
page_hist_pos++;
if (page_hist_pos >= page_hist_len) {
if (page_hist_pos >= page_hist_len)
{
page_hist_len++;
page_hist =
realloc(page_hist,
sizeof(int) * page_hist_len);
sizeof(int) *
page_hist_len);
}
page_hist[page_hist_pos] = pagenum;
l = RenderPage(draw, pagenum, w, h);
@ -559,7 +603,8 @@ int main(int argc, char **argv)
}
break;
case ButtonRelease:
if (ev.xbutton.window == win_prev) {
if (ev.xbutton.window == win_prev)
{
ApplyImage3(win_prev, im_prev1);
FREE_LINKS;
page_hist_pos--;
@ -568,28 +613,35 @@ int main(int argc, char **argv)
pagenum = page_hist[page_hist_pos];
l = RenderPage(draw, pagenum, w, h);
UPDATE;
} else if (ev.xbutton.window == win_next) {
}
else if (ev.xbutton.window == win_next)
{
int prev_pagenum;
ApplyImage3(win_next, im_next1);
prev_pagenum = pagenum;
pagenum++;
pagenum = FixPage(pagenum);
if (pagenum != prev_pagenum) {
if (pagenum != prev_pagenum)
{
FREE_LINKS;
page_hist_pos++;
if (page_hist_pos >= page_hist_len) {
if (page_hist_pos >= page_hist_len)
{
page_hist_len++;
page_hist = realloc(page_hist,
sizeof(int) * page_hist_len);
page_hist[page_hist_pos] = pagenum;
} else
}
else
page_hist[page_hist_pos] = pagenum;
l = RenderPage(draw, pagenum, w, h);
UPDATE;
}
} else if (ev.xbutton.window == win_exit) {
}
else if (ev.xbutton.window == win_exit)
{
ApplyImage3(win_exit, im_exit1);
exit(0);
}
@ -608,16 +660,20 @@ int main(int argc, char **argv)
x = ev.xmotion.x;
y = ev.xmotion.y;
ll = l;
while (ll) {
while (ll)
{
if ((x >= ll->x) && (y >= ll->y) &&
(x < (ll->x + ll->w)) && (y < (ll->y + ll->h))) {
(x < (ll->x + ll->w)) && (y < (ll->y + ll->h)))
{
GC gc;
XGCValues gcv;
int r, g, b;
XColor xclr;
if (pl != ll) {
if (pl) {
if (pl != ll)
{
if (pl)
{
UPDATE_NOW;
}
GetLinkColors(pagenum, &r, &g, &b);
@ -636,7 +692,8 @@ int main(int argc, char **argv)
if (ll)
ll = ll->next;
}
if (!found) {
if (!found)
{
UPDATE_NOW;
pl = NULL;
}

View File

@ -164,7 +164,6 @@ extern Drawable vIcDrw;
#include <Fnlib.h>
#endif
#define FILEPATH_LEN_MAX 4096
#define DEFAULT_LINKCOLOR_R 30
@ -191,7 +190,6 @@ typedef struct _efont Efont;
putenv(envvar);\
}
typedef struct _root
{
Window win;
@ -353,6 +351,7 @@ Link *RenderPage(Window win, int page_num, int w, int h);
extern Display *disp;
extern Root root;
#if USE_FNLIB
extern FnlibData *pFnlibData;
#endif

View File

@ -357,6 +357,7 @@ username(int uid)
static int usr_uid = -1;
static char *usr_s = NULL;
char *s;
#ifndef __EMX__
struct passwd *pwd;
@ -385,6 +386,7 @@ homedir(int uid)
static int usr_uid = -1;
static char *usr_s = NULL;
char *s;
#ifndef __EMX__
struct passwd *pwd;
@ -415,6 +417,7 @@ usershell(int uid)
static int usr_uid = -1;
static char *usr_s = NULL;
char *s;
#ifndef __EMX__
struct passwd *pwd;
@ -619,19 +622,38 @@ word_mb(char *s, int num, char *wd, int *spaceflag)
char *start, *finish, *ss, *w;
int wcflg, mbflg;
struct char_class {
struct char_class
{
char *name;
wctype_t wt;
} *cc, char_class_tbl[] = {
} *cc, char_class_tbl[] =
{
#ifdef linux
/* Will be supported on glibc 2.1.3 or later */
{"jspace", 0}, {"jhira", 0}, {"jkata", 0}, {"jkanji", 0}, {"jdigit", 0},/* Japanese */
{"hangul", 0}, {"hanja", 0}, /* Korean */
{
"jspace", 0},
{
"jhira", 0},
{
"jkata", 0},
{
"jkanji", 0},
{
"jdigit", 0}, /* Japanese */
{
"hangul", 0},
{
"hanja", 0}, /* Korean */
/* {"?????"}, {"?????"}, *//* Chinese */
#endif
#ifdef sgi
/* SGI IRIX (Japanese, Chinese, Korean, etc..) */
{"special", 0}, {"phonogram", 0}, {"ideogram", 0},
{
"special", 0},
{
"phonogram", 0},
{
"ideogram", 0},
#endif
#ifdef sun
/* {"?????"}, {"?????"}, */
@ -639,10 +661,10 @@ word_mb(char *s, int num, char *wd, int *spaceflag)
#ifdef hpux
/* {"?????"}, {"?????"}, */
#endif
{NULL, 0}
{
NULL, 0}
};
if (!s)
return;
if (!wd)
@ -674,9 +696,12 @@ word_mb(char *s, int num, char *wd, int *spaceflag)
{
int len, oldflg = 1;
len = mblen(s + i, MB_CUR_MAX);
if ( len < 0 ) { i++; continue; }
if (len < 0)
{
i++;
continue;
}
/* Check multibyte character class */
if (wcflg)
@ -702,8 +727,7 @@ word_mb(char *s, int num, char *wd, int *spaceflag)
else
mbflg = len;
if ((cnt == num) && (
(s[i] == ' ') || (s[i] == '\t') ||
if ((cnt == num) && ((s[i] == ' ') || (s[i] == '\t') ||
(oldflg != mbflg) || (mbflg > 1)))
{
finish = &s[i];
@ -900,6 +924,7 @@ pathtofile(char *file)
char *p, *cp, *ep;
char *s;
int len, exelen;
#ifndef __EMX__
if (file[0] == '/')
#else

View File

@ -93,10 +93,8 @@ AddObject(Object * obj)
page[num_pages - 1].obj =
realloc(page[num_pages - 1].obj,
sizeof(Object) * (page[num_pages - 1].count));
page[num_pages - 1].obj[page[num_pages - 1].count - 1].type =
obj->type;
page[num_pages - 1].obj[page[num_pages - 1].count - 1].object =
obj->object;
page[num_pages - 1].obj[page[num_pages - 1].count - 1].type = obj->type;
page[num_pages - 1].obj[page[num_pages - 1].count - 1].object = obj->object;
}
void
@ -671,7 +669,8 @@ RenderPage(Window win, int page_num, int w, int h)
word(txt, wc, wd);
spaceflag = 1;
}
if (!wd[0]) eol = 1;
if (!wd[0])
eol = 1;
wc++;
eot++;
@ -712,18 +711,27 @@ RenderPage(Window win, int page_num, int w, int h)
j = 0;
linkflg = 0;
if ( wd[0] == '_' ) { j++; linkflg++; }
if (wd[0] == '_')
{
j++;
linkflg++;
}
k = strlen(link_txt);
for (; wd[j] != '(' && wd[j] != '\0'; j++, k++)
{
if (wd[j] == '_') link_txt[k] = ' ';
else link_txt[k] = wd[j];
if ( linkflg ) wd[ j - 1 ] = link_txt[k];
else wd[j] = link_txt[k];
if (wd[j] == '_')
link_txt[k] = ' ';
else
link_txt[k] = wd[j];
if (linkflg)
wd[j - 1] = link_txt[k];
else
wd[j] = link_txt[k];
}
link_txt[k] = '\0';
if ( linkflg ) wd[ j - 1 ] = '\0';
if (linkflg)
wd[j - 1] = '\0';
if (wd[j] == '(')
{
@ -765,7 +773,8 @@ RenderPage(Window win, int page_num, int w, int h)
{
if ((iix >= sx) && (iix <= ssx))
{
if (((ix + iix) / 2) > ((sx + ssx) / 2))
if (((ix + iix) / 2) >
((sx + ssx) / 2))
ssx = ix - 1;
else
sx = iix + 1;
@ -803,7 +812,8 @@ RenderPage(Window win, int page_num, int w, int h)
while (txt_disp[(point + cnt)])
{
len = mblen( txt_disp + point + cnt, MB_CUR_MAX);
len =
mblen(txt_disp + point + cnt, MB_CUR_MAX);
if (len < 0)
{
cnt++;
@ -814,7 +824,8 @@ RenderPage(Window win, int page_num, int w, int h)
p1[cnt] = txt_disp[point + cnt];
p1[cnt] = 0;
TextSize(&ts, p1, &tw, &th, 17);
if ((tw > xspace) || (!txt_disp[(point + cnt)]))
if ((tw > xspace)
|| (!txt_disp[(point + cnt)]))
{
if (txt_disp[(point + cnt)])
{
@ -830,9 +841,13 @@ RenderPage(Window win, int page_num, int w, int h)
}
wastext = 1;
TextDraw(&ts, win, p1, x + off, y,
xspace, 99999, 17, justification);
xspace, 99999, 17,
justification);
y += ts.height;
if (y >= (h - (pg->padding + ts.height - (ts.height - ts.xfontset_ascent))))
if (y >=
(h -
(pg->padding + ts.height -
(ts.height - ts.xfontset_ascent))))
{
y = pg->padding;
x += col_w + pg->padding;
@ -848,35 +863,50 @@ RenderPage(Window win, int page_num, int w, int h)
if (pg->obj[j].type == IMG)
{
img = pg->obj[j].object;
if ((img->w > 0) && (img->h > 0))
if ((img->w > 0)
&& (img->h > 0))
{
int ix,
iy,
iix,
iiy;
iy, iix, iiy;
ix = img->x;
iy = img->y;
iix = img->x + img->w - 1;
iiy = img->y + img->h - 1;
if ((iy <= ssy) && (iiy >= sy))
if ((iy <= ssy)
&& (iiy >= sy))
{
if ((ix >= sx) && (ix <= ssx))
if ((ix >= sx)
&& (ix <= ssx))
{
if ((iix >= sx) && (iix <= ssx))
if ((iix >= sx)
&& (iix <=
ssx))
{
if (((ix + iix) / 2) > ((sx + ssx) / 2))
ssx = ix - 1;
if (((ix +
iix) /
2) >
((sx +
ssx) /
2))
ssx =
ix -
1;
else
sx = iix + 1;
sx =
iix +
1;
}
else
{
ssx = ix - 1;
ssx =
ix - 1;
}
}
else if ((iix >= sx) && (iix <= ssx))
else if ((iix >= sx)
&& (iix <=
ssx))
{
sx = iix + 1;
}
@ -915,13 +945,15 @@ RenderPage(Window win, int page_num, int w, int h)
gc = XCreateGC(disp, win, 0, &gcv);
EGetColor(&ts.fg_col, &rr, &gg, &bb);
ESetColor(&ts.fg_col, pg->linkr, pg->linkg, pg->linkb);
ESetColor(&ts.fg_col, pg->linkr, pg->linkg,
pg->linkb);
EAllocColor(&ts.fg_col);
XSetForeground(disp, gc, ts.fg_col.pixel);
TextSize(&ts, txt_disp, &tw, &th, 17);
extra = ((xspace - tw) * justification) >> 10;
TextDraw(&ts, win, link_txt, x + off + lx + extra, y,
99999, 99999, 17, 0);
TextDraw(&ts, win, link_txt,
x + off + lx + extra, y, 99999, 99999,
17, 0);
TextSize(&ts, link_txt, &lw, &th, 17);
XDrawLine(disp, win, gc,
x + off + lx + extra,
@ -947,7 +979,10 @@ RenderPage(Window win, int page_num, int w, int h)
link_txt[0] = '\0';
}
y += ts.height;
if (y >= (h - (pg->padding + ts.height - (ts.height - ts.xfontset_ascent))))
if (y >=
(h -
(pg->padding + ts.height -
(ts.height - ts.xfontset_ascent))))
{
y = pg->padding;
x += col_w + pg->padding;
@ -964,7 +999,8 @@ RenderPage(Window win, int page_num, int w, int h)
default:
break;
}
if (y >= (h - (pg->padding + ts.height - (ts.height - ts.xfontset_ascent))))
if (y >=
(h - (pg->padding + ts.height - (ts.height - ts.xfontset_ascent))))
{
y = pg->padding;
x += col_w + pg->padding;

View File

@ -92,7 +92,8 @@ TextStateLoadFont(TextState * ts)
{
int as, ds;
Efont_extents(ts->efont, " ", &as, &ds, NULL, NULL, NULL, NULL, NULL);
Efont_extents(ts->efont, " ", &as, &ds, NULL, NULL, NULL,
NULL, NULL);
ts->xfontset_ascent = as;
ts->height = as + ds;
}
@ -145,8 +146,7 @@ TextStateLoadFont(TextState * ts)
}
void
TextSize(TextState * ts, char *text,
int *width, int *height, int fsize)
TextSize(TextState * ts, char *text, int *width, int *height, int fsize)
{
char **lines;
int i, num_lines;
@ -196,7 +196,8 @@ TextSize(TextState * ts, char *text,
{
XRectangle ret1, ret2;
XmbTextExtents(ts->xfontset, lines[i], strlen(lines[i]), &ret1, &ret2);
XmbTextExtents(ts->xfontset, lines[i], strlen(lines[i]), &ret1,
&ret2);
*height += ret2.height;
if (ret2.width > *width)
*width = ret2.width;
@ -234,8 +235,7 @@ TextSize(TextState * ts, char *text,
void
TextDraw(TextState * ts, Window win, char *text,
int x, int y, int w, int h, int fsize,
int justification)
int x, int y, int w, int h, int fsize, int justification)
{
char **lines;
int i, num_lines;
@ -319,7 +319,8 @@ TextDraw(TextState * ts, Window win, char *text,
{
XRectangle ret1, ret2;
XmbTextExtents(ts->xfontset, lines[i], strlen(lines[i]), &ret1, &ret2);
XmbTextExtents(ts->xfontset, lines[i], strlen(lines[i]), &ret1,
&ret2);
if (i == 0)
yy += ts->xfontset_ascent;
xx = x + (((w - ret2.width) * justification) >> 10);
@ -384,8 +385,7 @@ TextDraw(TextState * ts, Window win, char *text,
}
EAllocColor(&ts->fg_col);
XSetForeground(disp, gc, ts->fg_col.pixel);
XDrawString(disp, win, gc, xx, yy,
lines[i], strlen(lines[i]));
XDrawString(disp, win, gc, xx, yy, lines[i], strlen(lines[i]));
yy += ts->xfont->ascent + ts->xfont->descent;
}
}

View File

@ -213,13 +213,10 @@ extern int debug_level;
void Alert(char *fmt, ...);
void InitStringList(void);
void AssignIgnoreFunction(int (*FunctionToAssign) (void *),
void *params);
void AssignRestartFunction(int (*FunctionToAssign) (void *),
void *params);
void AssignExitFunction(int (*FunctionToAssign) (void *),
void *params);
void AssignTitleText(char *text);
void AssignIgnoreText(char *text);

View File

@ -230,7 +230,8 @@ cp(char *s, char *ss)
EDBUG_RETURN_;
}
time_t moddate(char *s)
time_t
moddate(char *s)
{
struct stat st;