<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 596eda3dd3513870a5d1eefd8ac08ede0886596c Mon Sep 17 00:00:00 2001
From: Adam Sampson &lt;ats@offog.org&gt;
Date: Fri, 4 Jul 2025 01:04:33 +0100
Subject: [PATCH 4/6] Convert to modern prototypes.

Add missing #includes for system functions, and a new header for the
stuff shared between xdu.c and xwin.c. Make functions that aren't shared
static.
---
 xdu.c  | 171 +++++++++++++++++++++++----------------------------------
 xdu.h  |  42 ++++++++++++++
 xwin.c | 140 ++++++++++++++--------------------------------
 3 files changed, 152 insertions(+), 201 deletions(-)
 create mode 100644 xdu.h

diff --git a/xdu.c b/xdu.c
index 55eb52e..4b55279 100644
--- a/xdu.c
+++ b/xdu.c
@@ -21,31 +21,30 @@
  */
 #include &lt;inttypes.h&gt;
 #include &lt;stdio.h&gt;
-#include "version.h"
+#include &lt;stdlib.h&gt;
+#include &lt;string.h&gt;
+#include &lt;unistd.h&gt;
 
-extern char *malloc(), *calloc();
+#include "version.h"
+#include "xdu.h"
 
 #define	MAXDEPTH	80	/* max elements in a path */
 #define	MAXNAME		1024	/* max pathname element length */
 #define	MAXPATH		4096	/* max total pathname length */
 #define	NCOLS		5	/* default number of columns in display */
 
-/* What we IMPORT from xwin.c */
-extern int xsetup(), xmainloop(), xdrawrect(), xrepaint();
-
-/* What we EXPORT to xwin.c */
-extern int press(), reset(), repaint(), setorder(), reorder();
-extern nodeinfo(), helpinfo();
 int ncols = NCOLS;
 
 /* internal routines */
-char *strdup();
-void addtree();
-void parse_file();
-void parse_entry();
-void dumptree();
-void clearrects();
-void sorttree();
+struct rect;
+struct node;
+static void addtree(struct node *top, char *path[], intmax_t size);
+static void parse_file(char *filename);
+static void parse_entry(char *name, intmax_t size);
+static void dumptree(struct node *np, int level);
+static void drawchildren(struct node *nodep, struct rect rect);
+static void clearrects(struct node *np);
+static void sorttree(struct node *np, int order);
 
 /* order to sort paths by */
 #define	ORD_FIRST	1
@@ -89,10 +88,8 @@ long nnodes = 0;
 /*
  * create a new node with the given name and size info
  */
-struct node *
-makenode(name,size)
-char *name;
-intmax_t size;
+static struct node *
+makenode(char *name, intmax_t size)
 {
 	struct	node	*np;
 
@@ -109,10 +106,8 @@ intmax_t size;
  * Return the node (if any) which has a draw rectangle containing
  * the given x,y point.
  */
-struct node *
-findnode(treep, x, y)
-struct	node *treep;
-int	x, y;
+static struct node *
+findnode(struct node *treep, int x, int y)
 {
 	struct	node	*np;
 	struct	node	*np2;
@@ -137,9 +132,8 @@ int	x, y;
 /*
  * return a count of the number of children of a given node
  */
-int
-numchildren(nodep)
-struct node *nodep;
+static int
+numchildren(struct node *nodep)
 {
 	int	n;
 
@@ -158,9 +152,8 @@ struct node *nodep;
  * 	      had their sizes initialized. [DPT911113]
  *	      * * * This function is recursive * * *
  */
-intmax_t
-fix_tree(top)
-struct node *top;
+static intmax_t
+fix_tree(struct node *top)
 {
 	struct node *nd;
 
@@ -192,9 +185,8 @@ Graphically displays the output of du in an X window\n\
   Toolkit options: -fg, -bg, -rv, -display, -geometry, etc.\n\
 ";
 
-main(argc,argv)
-int argc;
-char **argv;
+int
+main(int argc, char **argv)
 {
 	top.name = strdup("[root]");
 	top.size = -1;
@@ -228,9 +220,8 @@ char **argv;
 	exit(0);
 }
 
-void
-parse_file(filename)
-char *filename;
+static void
+parse_file(char *filename)
 {
 	char	buf[4096];
 	char	name[4096];
@@ -254,10 +245,8 @@ char *filename;
 }
 
 /* bust up a path string and link it into the tree */
-void
-parse_entry(name,size)
-char *name;
-intmax_t size;
+static void
+parse_entry(char *name, intmax_t size)
 {
 	char	*path[MAXDEPTH]; /* break up path into this list */
 	char	buf[MAXNAME];	 /* temp space for path element name */
@@ -304,10 +293,8 @@ intmax_t size;
  *          0 if it is a toss up.
  *	    1 if it should go after.
  */
-int
-compare(n1,n2,order)
-struct node *n1, *n2;
-int order;
+static int
+compare(struct node *n1, struct node *n2, int order)
 {
 	intmax_t ret;
 
@@ -347,11 +334,11 @@ int order;
 	return	0;
 }
 
-void
-insertchild(nodep,childp,order)
-struct node *nodep;	/* parent */
-struct node *childp;	/* child to be added */
-int order;		/* FIRST, LAST, ALPHA, SIZE */
+static void
+insertchild(struct node *nodep, struct node *childp, int order)
+	/* nodep: parent */
+	/* childp: child to be added */
+	/* order: FIRST, LAST, ALPHA, SIZE */
 {
 	struct node *np, *np1;
 
@@ -390,11 +377,8 @@ int order;		/* FIRST, LAST, ALPHA, SIZE */
 }
 
 /* add path as a child of top - recursively */
-void
-addtree(top, path, size)
-struct node *top;
-char *path[];
-intmax_t size;
+static void
+addtree(struct node *top, char *path[], intmax_t size)
 {
 	struct	node *np;
 
@@ -429,10 +413,8 @@ intmax_t size;
 }
 
 /* debug tree print */
-void
-dumptree(np,level)
-struct node *np;
-int level;
+static void
+dumptree(struct node *np, int level)
 {
 	int	i;
 	struct	node *subnp;
@@ -446,10 +428,8 @@ int level;
 	}
 }
 
-void
-sorttree(np, order)
-struct node *np;
-int order;
+static void
+sorttree(struct node *np, int order)
 {
 	struct	node *subnp;
 	struct	node *np0, *np1, *np2, *np3;
@@ -486,9 +466,10 @@ int order;
  * Draws a node in the given rectangle, and all of its children
  * to the "right" of the given rectangle.
  */
-drawnode(nodep, rect)
-struct node *nodep;	/* node whose children we should draw */
-struct rect rect;	/* rectangle to draw all children in */
+static void
+drawnode(struct node *nodep, struct rect rect)
+	/* nodep: node whose children we should draw */
+	/* rect: rectangle to draw all children in */
 {
 	struct rect subrect;
 
@@ -515,9 +496,10 @@ struct rect rect;	/* rectangle to draw all children in */
  * Draws all children of a node within the given rectangle.
  * Recurses on children.
  */
-drawchildren(nodep, rect)
-struct node *nodep;	/* node whose children we should draw */
-struct rect rect;	/* rectangle to draw all children in */
+static void
+drawchildren(struct node *nodep, struct rect rect)
+	/* nodep: node whose children we should draw */
+	/* rect: rectangle to draw all children in */
 {
 	intmax_t totalsize;
 	int	totalheight;
@@ -573,9 +555,8 @@ struct rect rect;	/* rectangle to draw all children in */
  * clear the rectangle information of a given node
  * and all of its decendents
  */
-void
-clearrects(nodep)
-struct	node *nodep;
+static void
+clearrects(struct node *nodep)
 {
 	struct	node	*np;
 
@@ -593,7 +574,8 @@ struct	node *nodep;
 	}
 }
 
-pwd()
+static void
+pwd(void)
 {
 	struct node *np;
 	struct node *stack[MAXDEPTH];
@@ -623,25 +605,10 @@ pwd()
 		100.0*topp-&gt;size/rootp-&gt;size);
 }
 
-char *
-strdup(s)
-char *s;
-{
-	int	n;
-	char	*cp;
-
-	n = strlen(s);
-	cp = malloc(n+1);
-	strcpy(cp,s);
-
-	return	cp;
-}
-
 /**************** External Entry Points ****************/
 
-int
-press(x,y)
-int x, y;
+void
+press(int x, int y)
 {
 	struct node *np;
 
@@ -660,8 +627,8 @@ int x, y;
 	}
 }
 
-int
-reset()
+void
+reset(void)
 {
 	topp = &amp;top;
 	if (numchildren(topp) == 1)
@@ -669,9 +636,8 @@ reset()
 	xrepaint();
 }
 
-int
-repaint(width,height)
-int width, height;
+void
+repaint(int width, int height)
 {
 	struct	rect rect;
 
@@ -688,9 +654,8 @@ int width, height;
 #endif
 }
 
-int
-setorder(op)
-char *op;
+void
+setorder(char *op)
 {
 	if (strcmp(op, "size") == 0) {
 		order = ORD_SIZE;
@@ -730,17 +695,17 @@ char *op;
 	}
 }
 
-int
-reorder(op)
-char *op;	/* order name */
+void
+reorder(char *op)
+	/* op: order name */
 {
 	setorder(op);
 	sorttree(topp, order);
 	xrepaint();
 }
 
-int
-nodeinfo()
+void
+nodeinfo(void)
 {
 	struct node *np;
 
@@ -753,8 +718,8 @@ nodeinfo()
 	}
 }
 
-int
-helpinfo()
+void
+helpinfo(void)
 {
 	fprintf(stdout, "\n\
 XDU Version %s - Keyboard Commands\n\
diff --git a/xdu.h b/xdu.h
new file mode 100644
index 0000000..6dd35bc
--- /dev/null
+++ b/xdu.h
@@ -0,0 +1,42 @@
+/*
+ * XDU - Common definitions.
+ *
+ * Phillip C. Dykstra
+ * &lt;phil@arl.mil&gt;
+ * 4 Sep 1991.
+ *
+ * Copyright (c)	Phillip C. Dykstra	1991, 1993, 1994
+ * The X Consortium, and any party obtaining a copy of these files from
+ * the X Consortium, directly or indirectly, is granted, free of charge, a
+ * full and unrestricted irrevocable, world-wide, paid up, royalty-free,
+ * nonexclusive right and license to deal in this software and
+ * documentation files (the "Software"), including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons who receive
+ * copies from any such party to do so.  This license includes without
+ * limitation a license to do the foregoing actions under any patents of
+ * the party supplying this software to the X Consortium.
+ */
+
+#ifndef XDU_H
+#define XDU_H
+
+/* From xdu.c. */
+extern void press(int x, int y);
+extern void reset(void);
+extern void repaint(int width, int height);
+extern void reorder(char *op);
+extern void setorder(char *op);
+extern void nodeinfo(void);
+extern void helpinfo(void);
+extern int ncols;
+
+/* From xwin.c. */
+extern void xsetup(int *argcp, char **argv);
+extern void xmainloop(void);
+extern void xclear(void);
+extern void xrepaint(void);
+extern void xrepaint_noclear(void);
+extern void xdrawrect(char *name, intmax_t size, int x, int y, int width, int height);
+
+#endif
diff --git a/xwin.c b/xwin.c
index ab0c4f7..9d1b248 100644
--- a/xwin.c
+++ b/xwin.c
@@ -35,27 +35,11 @@
 #include &lt;stdlib.h&gt;	/* for exit() */
 #endif
 
-/* IMPORTS: routines that this module vectors out to */
-extern int press();
-extern int reset();
-extern int repaint();
-extern int reorder();
-extern int setorder();
-extern int nodeinfo();
-extern int helpinfo();
-extern int ncols;
-
-/* EXPORTS: routines that this module exports outside */
-extern int xsetup();
-extern int xmainloop();
-extern int xclear();
-extern int xrepaint();
-extern int xrepaint_noclear();
-extern int xdrawrect();
+#include "xdu.h"
 
 /* internal routines */
-static void help_popup();
-static void help_popdown();
+static void help_popup(void);
+static void help_popdown(void);
 
 static String fallback_resources[] = {
 "*window.width:		600",
@@ -104,15 +88,18 @@ static XrmOptionDescRec options[] = {
 };
 
 /* action routines */
-static void a_goto();
-static void a_reset();
-static void a_quit();
-static void a_reorder();
-static void a_size();
-static void a_ncol();
-static void a_info();
-static void a_help();
-static void a_removehelp();
+#define ACTION_FUNC(name) \
+	static void name(Widget w, XEvent *event, \
+		String *params, Cardinal *num_params)
+ACTION_FUNC(a_goto);
+ACTION_FUNC(a_reset);
+ACTION_FUNC(a_quit);
+ACTION_FUNC(a_reorder);
+ACTION_FUNC(a_size);
+ACTION_FUNC(a_ncol);
+ACTION_FUNC(a_info);
+ACTION_FUNC(a_help);
+ACTION_FUNC(a_removehelp);
 
 static XtActionsRec actionsTable[] = {
 	{ "reset",	a_reset },
@@ -157,39 +144,23 @@ static char defaultTranslations[] = "\
 
 /*  action routines  */
 
-static void a_quit(w, event, params, num_params)
-Widget w;
-XEvent *event;
-String *params;
-Cardinal *num_params;
+ACTION_FUNC(a_quit)
 {
 	XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
 	exit(0);
 }
 
-static void a_goto(w, event, params, num_params)
-Widget w;
-XEvent *event;
-String *params;
-Cardinal *num_params;
+ACTION_FUNC(a_goto)
 {
 	press(event-&gt;xbutton.x, event-&gt;xbutton.y);
 }
 
-static void a_reset(w, event, params, num_params)
-Widget w;
-XEvent *event;
-String *params;
-Cardinal *num_params;
+ACTION_FUNC(a_reset)
 {
 	reset();
 }
 
-static void a_reorder(w, event, params, num_params)
-Widget w;
-XEvent *event;
-String *params;
-Cardinal *num_params;
+ACTION_FUNC(a_reorder)
 {
 	if (*num_params != 1) {
 		fprintf(stderr, "xdu: bad number of params to reorder action\n");
@@ -198,11 +169,7 @@ Cardinal *num_params;
 	}
 }
 
-static void a_size(w, event, params, num_params)
-Widget w;
-XEvent *event;
-String *params;
-Cardinal *num_params;
+ACTION_FUNC(a_size)
 {
 	if (res.showsize)
 		res.showsize = 0;
@@ -211,11 +178,7 @@ Cardinal *num_params;
 	xrepaint();
 }
 
-static void a_ncol(w, event, params, num_params)
-Widget w;
-XEvent *event;
-String *params;
-Cardinal *num_params;
+ACTION_FUNC(a_ncol)
 {
 	int	n;
 
@@ -232,51 +195,33 @@ Cardinal *num_params;
 	xrepaint();
 }
 
-static void a_info(w, event, params, num_params)
-Widget w;
-XEvent *event;
-String *params;
-Cardinal *num_params;
+ACTION_FUNC(a_info)
 {
 	nodeinfo();
 }
 
-static void a_help(w, event, params, num_params)
-Widget w;
-XEvent *event;
-String *params;
-Cardinal *num_params;
+ACTION_FUNC(a_help)
 {
 	/*helpinfo();*/
 	help_popup();
 }
 
-static void a_removehelp(w, event, params, num_params)
-Widget w;
-XEvent *event;
-String *params;
-Cardinal *num_params;
+ACTION_FUNC(a_removehelp)
 {
 	help_popdown();
 }
 
 /* callback routines */
 
-static void c_resize(w, data, event, continue_to_dispatch)
-Widget w;
-XtPointer data;
-XEvent *event;
-Boolean *continue_to_dispatch;
+static void
+c_resize(Widget w, XtPointer data, XEvent *event, Boolean *continue_to_dispatch)
 {
 	/*printf("Resize\n");*/
 	xrepaint();
 }
 
-static void c_repaint(w, data, event, continue_to_dispatch)
-Widget w;
-XtPointer data;
-XEvent *event;
-Boolean *continue_to_dispatch;
+static void
+c_repaint(Widget w, XtPointer data, XEvent *event, Boolean *continue_to_dispatch)
 {
 	/*printf("Expose\n");*/
 	xrepaint_noclear();
@@ -296,10 +241,8 @@ Widget toplevel;
 
 /*  External Functions  */
 
-int
-xsetup(argcp, argv)
-int *argcp;
-char **argv;
+void
+xsetup(int *argcp, char **argv)
 {
 	XtTranslations trans_table;
 	Widget w;
@@ -350,18 +293,20 @@ char **argv;
 	ncols = res.ncol;
 }
 
-xmainloop()
+void
+xmainloop(void)
 {
 	XtAppMainLoop(app_con);
-	return(0);
 }
 
-xclear()
+void
+xclear(void)
 {
 	XClearWindow(dpy, win);
 }
 
-xrepaint()
+void
+xrepaint(void)
 {
 	XWindowAttributes xwa;
 
@@ -370,7 +315,8 @@ xrepaint()
 	repaint(xwa.width, xwa.height);
 }
 
-xrepaint_noclear()
+void
+xrepaint_noclear(void)
 {
 	XWindowAttributes xwa;
 
@@ -378,10 +324,8 @@ xrepaint_noclear()
 	repaint(xwa.width, xwa.height);
 }
 
-xdrawrect(name, size, x, y, width, height)
-char *name;
-intmax_t size;
-int x, y, width, height;
+void
+xdrawrect(char *name, intmax_t size, int x, int y, int width, int height)
 {
 	int	textx, texty;
 	char	label[1024];
@@ -412,7 +356,7 @@ int x, y, width, height;
 static Widget popup;
 
 static void
-help_popup()
+help_popup(void)
 {
 	Widget form, text, src;
 	Arg args[15];
@@ -491,7 +435,7 @@ Mouse Commands\n\
 }
 
 static void
-help_popdown()
+help_popdown(void)
 {
 	XtPopdown(popup);
 }
-- 
2.50.0

</pre></body></html>