Skip to content

Commit

Permalink
Declare internal routines as static
Browse files Browse the repository at this point in the history
Use "static" functions where possible to give the compiler more
freedom for optimizations.
  • Loading branch information
donald committed Mar 22, 2019
1 parent 2e074ca commit 3a00b22
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions xdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ int ncols = NCOLS;
* internal routines
*/
// char *strdup();
void addtree();
void parse_file();
void parse_entry();
static void addtree();
static void parse_file();
static void parse_entry();
void dumptree();
void clearrects();
void sorttree();
static void clearrects();
static void sorttree();

/*
* order to sort paths by
Expand Down Expand Up @@ -139,7 +139,7 @@ long nnodes = 0;
/*
* create a new node with the given name and size info
*/
struct node*
static struct node*
makenode(char* name, long long size)
{
struct node* np;
Expand All @@ -157,7 +157,7 @@ makenode(char* name, long long size)
* Return the node (if any) which has a draw rectangle containing
* the given x,y point.
*/
struct node*
static struct node*
findnode(struct node* treep, int x, int y)
{
struct node* np;
Expand Down Expand Up @@ -188,7 +188,7 @@ findnode(struct node* treep, int x, int y)
/*
* return a count of the number of children of a given node
*/
int numchildren(struct node* nodep)
static int numchildren(struct node* nodep)
{
int n;

Expand All @@ -207,7 +207,7 @@ int numchildren(struct node* nodep)
* had their sizes initialized. [DPT911113]
* * * * This function is recursive * * *
*/
long fix_tree(struct node* top)
static long fix_tree(struct node* top)
{
struct node* nd;

Expand Down Expand Up @@ -278,7 +278,7 @@ int main(int argc, char** argv)
exit(0);
}

void parse_file(char* filename)
static void parse_file(char* filename)
{
char buf[4096];
char name[4096];
Expand Down Expand Up @@ -317,7 +317,7 @@ void parse_file(char* filename)
/*
* bust up a path string and link it into the tree
*/
void parse_entry(char* name, long long size)
static void parse_entry(char* name, long long size)
{
char* path[MAXDEPTH]; /* break up path into this list */
char buf[MAXNAME]; /* temp space for path element
Expand Down Expand Up @@ -369,7 +369,7 @@ void parse_entry(char* name, long long size)
* 0 if it is a toss up.
* 1 if it should go after.
*/
int compare(struct node* n1, struct node* n2, int order)
static int compare(struct node* n1, struct node* n2, int order)
{
switch (order) {
case ORD_SIZE:
Expand Down Expand Up @@ -424,7 +424,7 @@ int compare(struct node* n1, struct node* n2, int order)
/*
* add path as a child of top - recursively
*/
void addtree(struct node* top, char* path[], long long size)
static void addtree(struct node* top, char* path[], long long size)
{
struct node* np;

Expand Down Expand Up @@ -493,7 +493,7 @@ void dumptree(struct node* np, int level)
}
}

void sorttree(struct node* np, int order)
static void sorttree(struct node* np, int order)
{
struct node* subnp;
struct node *np0,
Expand Down Expand Up @@ -541,7 +541,7 @@ void sorttree(struct node* np, int order)
* Draws all children of a node within the given rectangle.
* Recurses on children.
*/
void drawchildren(struct node* nodep, struct rect rect)
static void drawchildren(struct node* nodep, struct rect rect)
{
long long totalsize;
int totalheight;
Expand Down Expand Up @@ -618,7 +618,7 @@ void drawchildren(struct node* nodep, struct rect rect)
* Draws a node in the given rectangle, and all of its children
* to the "right" of the given rectangle.
*/
void drawnode(struct node* nodep, struct rect rect)
static void drawnode(struct node* nodep, struct rect rect)
{
struct rect subrect;

Expand Down Expand Up @@ -651,7 +651,7 @@ void drawnode(struct node* nodep, struct rect rect)
* clear the rectangle information of a given node
* and all of its decendents
*/
void clearrects(struct node* nodep)
static void clearrects(struct node* nodep)
{
struct node* np;

Expand All @@ -671,7 +671,7 @@ void clearrects(struct node* nodep)
}
}

void pwd(void)
static void pwd(void)
{
struct node* np;
struct node* stack[MAXDEPTH];
Expand Down Expand Up @@ -702,7 +702,7 @@ void pwd(void)
}

#ifdef NEED_STRDUP
char* strdup(char* s)
static char* strdup(char* s)
{
int n;
char* cp;
Expand Down Expand Up @@ -874,7 +874,7 @@ XDU Version %s - Keyboard Commands\n\
XDU_VERSION);
}

void fprintpsstart(FILE* fp)
static void fprintpsstart(FILE* fp)
{
fprintf(fp,
"%%!\n"
Expand All @@ -901,7 +901,7 @@ void fprintpsstart(FILE* fp)
"/xduorigctm matrix currentmatrix def\n\n");
}

void fprintpsend(FILE* fp)
static void fprintpsend(FILE* fp)
{
fprintf(fp,
"grestore\n"
Expand All @@ -914,7 +914,7 @@ void fprintpsend(FILE* fp)
"%%%%EOF\n");
}

void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2)
static void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2)
{
fprintf(fp,
"%%BOX\n"
Expand All @@ -932,7 +932,7 @@ void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2)
x1, y1, x2 + x1, y1, x2 + x1, y2 + y1, x1, y2 + y1);
}

void fprintpstext(FILE* fp, int x, int y, char* s)
static void fprintpstext(FILE* fp, int x, int y, char* s)
{
fprintf(fp,
"%%TEXT\n"
Expand All @@ -945,7 +945,7 @@ void fprintpstext(FILE* fp, int x, int y, char* s)
x, y, s);
}

void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize)
static void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize)
{
long long size, totalsize;
int totalheight,
Expand Down Expand Up @@ -1016,7 +1016,7 @@ void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize
}
}

void savepsnode(FILE* fp, struct node* nodep, struct rect rect, int showsize)
static void savepsnode(FILE* fp, struct node* nodep, struct rect rect, int showsize)
{
struct rect subrect;
char label[1024],
Expand Down Expand Up @@ -1081,24 +1081,24 @@ void savetops(char* fname, int showsize)
}
}

void fprintsvgstart(FILE* fp, int width, int height)
static void fprintsvgstart(FILE* fp, int width, int height)
{
fprintf(fp, "<?xml version=\"1.0\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"%d\" height=\"%d\">\n", width, height);
}

void fprintsvgend(FILE* fp)
static void fprintsvgend(FILE* fp)
{
fprintf(fp, "</svg>");
}

void fprintsvgnode(FILE* fp, struct rect rect)
static void fprintsvgnode(FILE* fp, struct rect rect)
{
fprintf(fp,
" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" stroke=\"black\" stroke-width=\"1px\" fill=\"white\"/>\n",
rect.left, rect.top, rect.width, rect.height);
}

void fprintsvgnodetext(FILE* fp, int x, int y, long long size, char* name, int showsize)
static void fprintsvgnodetext(FILE* fp, int x, int y, long long size, char* name, int showsize)
{
char buffer[1024],
*text="n/a";
Expand Down Expand Up @@ -1135,7 +1135,7 @@ void fprintsvgnodetext(FILE* fp, int x, int y, long long size, char* name, int s
x, y, text);
}

void savesvgnode(FILE* fp, struct node* nodep, int showsize, int depth)
static void savesvgnode(FILE* fp, struct node* nodep, int showsize, int depth)
{
struct node* np;

Expand Down

0 comments on commit 3a00b22

Please sign in to comment.