diff --git a/Makefile b/Makefile index 59e8ac5..71e20bd 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,9 @@ xwin.o: xwin.c xdu.o: xdu.c +.PHONY: clean, nice clean: rm -f xdu xdu.o xwin.o -.PHONY: nice nice: - indent -kr -l0 --no-tabs $(SRCS) + clang-format -i -style=webkit $(SRCS) diff --git a/README.md b/README.md index eb57e8e..4b09ff4 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ This release was tested against MarIuX. ## Revision History +### Version 3.0p9 - Sep 13 2018 +- fix segmentation fault +- Niclas Hofmann, `niclas@molgen.mpg.de` + ### Version 3.0p8 - Sep 3 2018 - change and add mouse control - Niclas Hofmann, `niclas@molgen.mpg.de` diff --git a/xdu.c b/xdu.c index 1e1013f..37b0a02 100644 --- a/xdu.c +++ b/xdu.c @@ -970,7 +970,7 @@ void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2) " 10 setmiterlimit\n" " gsave\n" " newpath\n" - " %i %i moveto %i %i lineto %i %i lineto %i %i lineto\n" + " %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n" " closepath\n" " stroke\n" " grestore\n" @@ -994,11 +994,10 @@ void fprintpstext(FILE* fp, int x, int y, char* s) void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize) { - long long totalsize; + long long size, totalsize; int totalheight, height, - top, - size; + top; struct node* np; char *name, label[1024]; @@ -1060,7 +1059,7 @@ void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize savepschildren(fp, np, subrect, showsize); size += np->size; - top = rect.top + (totalsize ? (double)size / (double)totalsize * rect.height + 0.5 : 0); + top = rect.top + (int)(totalsize ? (double)size / (double)totalsize * rect.height + 0.5 : 0); } } @@ -1129,9 +1128,9 @@ void savetops(char* fname, int showsize) } } -void fprintsvgstart(FILE* fp) +void fprintsvgstart(FILE* fp, int width, int height) { - fprintf(fp, "\n"); + fprintf(fp, "\n\n", width, height); } void fprintsvgend(FILE* fp) @@ -1202,12 +1201,12 @@ void savesvgnode(FILE* fp, struct node* nodep, int showsize, int depth) } } -void savetosvg(char* fname, int showsize) +void savetosvg(char* fname, int showsize, int width, int height) { FILE* fp; if ((fp = fopen(fname, "w")) != NULL) { - fprintsvgstart(fp); + fprintsvgstart(fp, width, height); savesvgnode(fp, topp, showsize, 0); fprintsvgend(fp); fclose(fp); diff --git a/xwin.c b/xwin.c index 48d1553..0e87038 100644 --- a/xwin.c +++ b/xwin.c @@ -50,7 +50,7 @@ extern int nodeinfo(); extern int helpinfo(); extern int ncols; extern void savetops(char*, int); -extern void savetosvg(char*, int); +extern void savetosvg(char*, int, int, int); /* * EXPORTS: routines that this module exports outside @@ -206,8 +206,9 @@ static char defaultTranslations[] = "\ #define ALL_UNUSED_IMPL_(nargs) UNUSED##nargs #define ALL_UNUSED_IMPL(nargs) ALL_UNUSED_IMPL_(nargs) -#define UNUSED(...) ALL_UNUSED_IMPL(VA_NUM_ARGS(__VA_ARGS__)) \ -(__VA_ARGS__) +#define UNUSED(...) \ + ALL_UNUSED_IMPL(VA_NUM_ARGS(__VA_ARGS__)) \ + (__VA_ARGS__) /* * action routines @@ -272,36 +273,6 @@ a_saveps(Widget w, XEvent* e, String* params, Cardinal* num_params) fprintf(stderr, "saved !\n"); } -static void -a_savesvg(Widget w, XEvent* e, String* params, Cardinal* num_params) -{ - char* extension = ".svg"; - int len = strlen(res.svgfilename) + 3 + strlen(extension) + 1; - char tmp[len]; - char* fname; - int i; - - UNUSED(w, e, params, num_params); - - for (i = 0; i > -1; ++i) { - snprintf(tmp, len, "%s-%02d%s", res.svgfilename, i, extension); - if (access(tmp, F_OK) == -1) { - fname = tmp; - break; - } - } - - if (i < 0) { - fprintf(stderr, "ERROR: there are too many xdu_output files!!!\n"); - exit(1); - } - - fprintf(stderr, "saving as scalable vector graphic to file: %s ..", - fname); - savetosvg(fname, res.showsize); - fprintf(stderr, "saved !\n"); -} - static void a_up(Widget w, XEvent* e, String* params, Cardinal* num_params) { @@ -393,6 +364,39 @@ static Window win; static GC gc; static XtAppContext app_con; +static void +a_savesvg(Widget w, XEvent* e, String* params, Cardinal* num_params) +{ + char* extension = ".svg"; + int len = strlen(res.svgfilename) + 3 + strlen(extension) + 1; + char tmp[len]; + char* fname; + int i; + XWindowAttributes xwa; + + XGetWindowAttributes(dpy, win, &xwa); + + UNUSED(w, e, params, num_params); + + for (i = 0; i > -1; ++i) { + snprintf(tmp, len, "%s-%02d%s", res.svgfilename, i, extension); + if (access(tmp, F_OK) == -1) { + fname = tmp; + break; + } + } + + if (i < 0) { + fprintf(stderr, "ERROR: there are too many xdu_output files!!!\n"); + exit(1); + } + + fprintf(stderr, "saving as scalable vector graphic to file: %s ..", + fname); + savetosvg(fname, res.showsize, xwa.width, xwa.height); + fprintf(stderr, "saved !\n"); +} + Widget toplevel; /*