1
1

Code cleanup: Use `static' where applicable.

This should also allow compilers to generate better code.
Этот коммит содержится в:
Yorhel 2011-10-31 15:09:12 +01:00
родитель dabe97f9c2
Коммит 5243e2daf4
7 изменённых файлов: 77 добавлений и 88 удалений

Просмотреть файл

@ -30,15 +30,11 @@
#include <ncurses.h> #include <ncurses.h>
int graph = 1, static int graph = 1, show_as = 0, info_show = 0, info_page = 0, info_start = 0;
show_as = 0,
info_show = 0,
info_page = 0,
info_start = 0;
void browse_draw_info(struct dir *dr) { static void browse_draw_info(struct dir *dr) {
struct dir *t; struct dir *t;
int i; int i;
@ -90,7 +86,7 @@ void browse_draw_info(struct dir *dr) {
} }
void browse_draw_item(struct dir *n, int row) { static void browse_draw_item(struct dir *n, int row) {
char ct, dt, *size, gr[11]; char ct, dt, *size, gr[11];
int i, o; int i, o;
float pc; float pc;

Просмотреть файл

@ -46,27 +46,27 @@
char calc_smfs = 0; char calc_smfs = 0;
/* global vars for internal use */ /* global vars for internal use */
char failed; /* 1 on fatal error */ static char failed; /* 1 on fatal error */
char *curpath; /* last lstat()'ed item, used for excludes matching and display */ static char *curpath; /* last lstat()'ed item, used for excludes matching and display */
char *lasterr; /* last unreadable dir/item */ static char *lasterr; /* last unreadable dir/item */
char errmsg[128]; /* error message, when failed=1 */ static char errmsg[128]; /* error message, when failed=1 */
struct dir *root; /* root directory struct we're calculating */ static struct dir *root; /* root directory struct we're calculating */
struct dir *orig; /* original directory, when recalculating */ static struct dir *orig; /* original directory, when recalculating */
dev_t curdev; /* current device we're calculating on */ static dev_t curdev; /* current device we're calculating on */
int anpos; /* position of the animation string */ static int anpos; /* position of the animation string */
int curpathl = 0, lasterrl = 0; static int curpathl = 0, lasterrl = 0;
// Table of struct dir items with more than one link (in order to detect hard links) // Table of struct dir items with more than one link (in order to detect hard links)
#define links_dir_hash(d) (kh_int64_hash_func((khint64_t)d->dev) ^ kh_int64_hash_func((khint64_t)d->ino)) #define links_dir_hash(d) (kh_int64_hash_func((khint64_t)d->dev) ^ kh_int64_hash_func((khint64_t)d->ino))
#define links_dir_equal(a, b) ((a)->dev == (b)->dev && (a)->ino == (b)->ino) #define links_dir_equal(a, b) ((a)->dev == (b)->dev && (a)->ino == (b)->ino)
KHASH_INIT(hl, struct dir *, char, 0, links_dir_hash, links_dir_equal); KHASH_INIT(hl, struct dir *, char, 0, links_dir_hash, links_dir_equal);
khash_t(hl) *links = NULL; static khash_t(hl) *links = NULL;
/* adds name to curpath */ /* adds name to curpath */
void calc_enterpath(char *name) { static void calc_enterpath(char *name) {
int n; int n;
n = strlen(curpath)+strlen(name)+2; n = strlen(curpath)+strlen(name)+2;
@ -81,7 +81,7 @@ void calc_enterpath(char *name) {
/* removes last component from curpath */ /* removes last component from curpath */
void calc_leavepath() { static void calc_leavepath() {
char *tmp; char *tmp;
if((tmp = strrchr(curpath, '/')) == NULL) if((tmp = strrchr(curpath, '/')) == NULL)
strcpy(curpath, "/"); strcpy(curpath, "/");
@ -93,7 +93,7 @@ void calc_leavepath() {
/* recursively checks a dir structure for hard links and fills the lookup array */ /* recursively checks a dir structure for hard links and fills the lookup array */
void calc_hlink_init(struct dir *d) { static void calc_hlink_init(struct dir *d) {
struct dir *t; struct dir *t;
for(t=d->sub; t!=NULL; t=t->next) for(t=d->sub; t!=NULL; t=t->next)
@ -108,7 +108,7 @@ void calc_hlink_init(struct dir *d) {
/* checks an individual file and updates the flags and cicrular linked list, /* checks an individual file and updates the flags and cicrular linked list,
* also updates the sizes of the parent dirs */ * also updates the sizes of the parent dirs */
void calc_hlink_check(struct dir *d) { static void calc_hlink_check(struct dir *d) {
struct dir *t, *pt, *par; struct dir *t, *pt, *par;
int i; int i;
@ -144,7 +144,7 @@ void calc_hlink_check(struct dir *d) {
} }
int calc_item(struct dir *par, char *name) { static int calc_item(struct dir *par, char *name) {
struct dir *t, *d; struct dir *t, *d;
struct stat fs; struct stat fs;
@ -216,7 +216,7 @@ int calc_item(struct dir *par, char *name) {
/* recursively walk through the directory tree, /* recursively walk through the directory tree,
assumes path resides in the cwd */ assumes path resides in the cwd */
int calc_dir(struct dir *dest, char *name) { static int calc_dir(struct dir *dest, char *name) {
struct dir *t; struct dir *t;
DIR *dir; DIR *dir;
struct dirent *dr; struct dirent *dr;
@ -295,7 +295,7 @@ int calc_dir(struct dir *dest, char *name) {
} }
void calc_draw_progress() { static void calc_draw_progress() {
static char antext[15] = "Calculating..."; static char antext[15] = "Calculating...";
char ani[15]; char ani[15];
int i; int i;
@ -333,7 +333,7 @@ void calc_draw_progress() {
} }
void calc_draw_error(char *cur, char *msg) { static void calc_draw_error(char *cur, char *msg) {
nccreate(7, 60, "Error!"); nccreate(7, 60, "Error!");
attron(A_BOLD); attron(A_BOLD);

Просмотреть файл

@ -36,14 +36,12 @@
#define DS_FAILED 2 #define DS_FAILED 2
struct dir *root, *nextsel, *curdir; static struct dir *root, *nextsel, *curdir;
char noconfirm = 0, static char noconfirm = 0, ignoreerr = 0, state, seloption;
ignoreerr = 0, static int lasterrno;
state, seloption;
int lasterrno;
void delete_draw_confirm() { static void delete_draw_confirm() {
nccreate(6, 60, "Confirm delete"); nccreate(6, 60, "Confirm delete");
ncprint(1, 2, "Are you sure you want to delete \"%s\"%c", ncprint(1, 2, "Are you sure you want to delete \"%s\"%c",
@ -68,7 +66,7 @@ void delete_draw_confirm() {
} }
void delete_draw_progress() { static void delete_draw_progress() {
nccreate(6, 60, "Deleting..."); nccreate(6, 60, "Deleting...");
ncaddstr(1, 2, cropstr(getpath(curdir), 47)); ncaddstr(1, 2, cropstr(getpath(curdir), 47));
@ -76,7 +74,7 @@ void delete_draw_progress() {
} }
void delete_draw_error() { static void delete_draw_error() {
nccreate(6, 60, "Error!"); nccreate(6, 60, "Error!");
ncprint(1, 2, "Can't delete %s:", cropstr(getpath(curdir), 42)); ncprint(1, 2, "Can't delete %s:", cropstr(getpath(curdir), 42));
@ -165,7 +163,7 @@ int delete_key(int ch) {
} }
int delete_dir(struct dir *dr) { static int delete_dir(struct dir *dr) {
struct dir *nxt, *cur; struct dir *nxt, *cur;
int r; int r;

Просмотреть файл

@ -39,8 +39,8 @@ int dirlist_sort_desc = 1,
dirlist_hidden = 0; dirlist_hidden = 0;
/* private state vars */ /* private state vars */
struct dir dirlist_parent_alloc; static struct dir dirlist_parent_alloc;
struct dir *head, *head_real, *selected, *top = NULL; static struct dir *head, *head_real, *selected, *top = NULL;
@ -50,7 +50,7 @@ struct dir *head, *head_real, *selected, *top = NULL;
int dirlist_cmp(struct dir *x, struct dir *y) { static int dirlist_cmp(struct dir *x, struct dir *y) {
int r; int r;
/* dirs are always before files when that option is set */ /* dirs are always before files when that option is set */
@ -90,7 +90,7 @@ int dirlist_cmp(struct dir *x, struct dir *y) {
} }
struct dir *dirlist_sort(struct dir *list) { static struct dir *dirlist_sort(struct dir *list) {
struct dir *p, *q, *e, *tail; struct dir *p, *q, *e, *tail;
int insize, nmerges, psize, qsize, i; int insize, nmerges, psize, qsize, i;
@ -142,7 +142,7 @@ struct dir *dirlist_sort(struct dir *list) {
* - makes sure one, and only one, visible item is selected * - makes sure one, and only one, visible item is selected
* - updates the dirlist_(maxs|maxa) values * - updates the dirlist_(maxs|maxa) values
* - makes sure that the FF_BSEL bits are correct */ * - makes sure that the FF_BSEL bits are correct */
void dirlist_fixup() { static void dirlist_fixup() {
struct dir *t; struct dir *t;
/* we're going to determine the selected items from the list itself, so reset this one */ /* we're going to determine the selected items from the list itself, so reset this one */
@ -225,7 +225,7 @@ struct dir *dirlist_next(struct dir *d) {
} }
struct dir *dirlist_prev(struct dir *d) { static struct dir *dirlist_prev(struct dir *d) {
if(!head || !d) if(!head || !d)
return NULL; return NULL;
while((d = d->prev)) { while((d = d->prev)) {

Просмотреть файл

@ -33,16 +33,16 @@
#include <sys/time.h> #include <sys/time.h>
#include <locale.h> #include <locale.h>
int pstate; int pstate;
int min_rows = 17,
min_cols = 60;
int read_only = 0; int read_only = 0;
long update_delay = 100, long update_delay = 100;
lastupdate = 999;
static int min_rows = 17, min_cols = 60;
static long lastupdate = 999;
void screen_draw() { static void screen_draw() {
switch(pstate) { switch(pstate) {
case ST_CALC: calc_draw(); break; case ST_CALC: calc_draw(); break;
case ST_BROWSE: browse_draw(); break; case ST_BROWSE: browse_draw(); break;
@ -92,7 +92,7 @@ int input_handle(int wait) {
/* parse command line */ /* parse command line */
char *argv_parse(int argc, char **argv) { static char *argv_parse(int argc, char **argv) {
int i, j, len; int i, j, len;
char *dir = NULL; char *dir = NULL;

Просмотреть файл

@ -48,7 +48,7 @@
a pointer to a reversed array of components is stored in res and the a pointer to a reversed array of components is stored in res and the
number of components is returned. number of components is returned.
cur is modified, and res has to be free()d after use */ cur is modified, and res has to be free()d after use */
int path_split(char *cur, char ***res) { static int path_split(char *cur, char ***res) {
char **old; char **old;
int i, j, n; int i, j, n;
@ -91,7 +91,7 @@ int path_split(char *cur, char ***res) {
/* copies path and prepends cwd if needed, to ensure an absolute path /* copies path and prepends cwd if needed, to ensure an absolute path
return value has to be free()'d manually */ return value has to be free()'d manually */
char *path_absolute(const char *path) { static char *path_absolute(const char *path) {
int i, n; int i, n;
char *ret; char *ret;
@ -125,8 +125,8 @@ char *path_absolute(const char *path) {
/* NOTE: cwd and the memory cur points to are unreliable after calling this function */ /* NOTE: cwd and the memory cur points to are unreliable after calling this function */
char *path_real_rec(char *cur, int *links) { static char *path_real_rec(char *cur, int *links) {
int i, j, n, tmpl, lnkl = 0; int i, n, tmpl, lnkl = 0;
char **arr, *tmp, *lnk, *ret = NULL; char **arr, *tmp, *lnk, *ret = NULL;
tmpl = strlen(cur)+1; tmpl = strlen(cur)+1;
@ -138,7 +138,6 @@ char *path_real_rec(char *cur, int *links) {
/* re-create full path */ /* re-create full path */
strcpy(tmp, "/"); strcpy(tmp, "/");
if(i > 0) { if(i > 0) {
j = 1;
lnkl = RPATH_CNKSZ; lnkl = RPATH_CNKSZ;
lnk = malloc(lnkl); lnk = malloc(lnkl);
if(chdir("/") < 0) if(chdir("/") < 0)

Просмотреть файл

@ -32,37 +32,30 @@
int winrows, wincols; int winrows, wincols;
int subwinr, subwinc; int subwinr, subwinc;
char cropstrdat[4096];
char formatsizedat[9]; /* "xxx.xMiB" */
char fullsizedat[20]; /* max: 999.999.999.999.999 */
char *getpathdat;
int getpathdatl = 0;
struct dir **links;
int linksl = 0, linkst = 0;
char *cropstr(const char *from, int s) { char *cropstr(const char *from, int s) {
static char dat[4096];
int i, j, o = strlen(from); int i, j, o = strlen(from);
if(o < s) { if(o < s) {
strcpy(cropstrdat, from); strcpy(dat, from);
return cropstrdat; return dat;
} }
j=s/2-3; j=s/2-3;
for(i=0; i<j; i++) for(i=0; i<j; i++)
cropstrdat[i] = from[i]; dat[i] = from[i];
cropstrdat[i] = '.'; dat[i] = '.';
cropstrdat[++i] = '.'; dat[++i] = '.';
cropstrdat[++i] = '.'; dat[++i] = '.';
j=o-s; j=o-s;
while(++i<s) while(++i<s)
cropstrdat[i] = from[j+i]; dat[i] = from[j+i];
cropstrdat[s] = '\0'; dat[s] = '\0';
return cropstrdat; return dat;
} }
char *formatsize(const off_t from) { char *formatsize(const off_t from) {
static char dat[9]; /* "xxx.xMiB" */
float r = from; float r = from;
char c = ' '; char c = ' ';
if(r < 1000.0f) { } if(r < 1000.0f) { }
@ -70,12 +63,13 @@ char *formatsize(const off_t from) {
else if(r < 1023e6f) { c = 'M'; r/=1048576.0f; } else if(r < 1023e6f) { c = 'M'; r/=1048576.0f; }
else if(r < 1023e9f) { c = 'G'; r/=1073741824.0f; } else if(r < 1023e9f) { c = 'G'; r/=1073741824.0f; }
else { c = 'T'; r/=1099511627776.0f; } else { c = 'T'; r/=1099511627776.0f; }
sprintf(formatsizedat, "%5.1f%c%cB", r, c, c == ' ' ? ' ' : 'i'); sprintf(dat, "%5.1f%c%cB", r, c, c == ' ' ? ' ' : 'i');
return formatsizedat; return dat;
} }
char *fullsize(const off_t from) { char *fullsize(const off_t from) {
static char dat[20]; /* max: 999.999.999.999.999 */
char tmp[20]; char tmp[20];
off_t n = from; off_t n = from;
int i, j; int i, j;
@ -90,13 +84,13 @@ char *fullsize(const off_t from) {
/* reverse and add thousand seperators */ /* reverse and add thousand seperators */
j = 0; j = 0;
while(i--) { while(i--) {
fullsizedat[j++] = tmp[i]; dat[j++] = tmp[i];
if(i != 0 && i%3 == 0) if(i != 0 && i%3 == 0)
fullsizedat[j++] = '.'; dat[j++] = '.';
} }
fullsizedat[j] = '\0'; dat[j] = '\0';
return fullsizedat; return dat;
} }
@ -170,7 +164,7 @@ void ncprint(int r, int c, char *fmt, ...) {
/* removes item from the hlnk circular linked list and size counts of the parents */ /* removes item from the hlnk circular linked list and size counts of the parents */
void freedir_hlnk(struct dir *d) { static void freedir_hlnk(struct dir *d) {
struct dir *t, *par, *pt; struct dir *t, *par, *pt;
int i; int i;
@ -204,7 +198,7 @@ void freedir_hlnk(struct dir *d) {
} }
void freedir_rec(struct dir *dr) { static void freedir_rec(struct dir *dr) {
struct dir *tmp, *tmp2; struct dir *tmp, *tmp2;
tmp2 = dr; tmp2 = dr;
while((tmp = tmp2) != NULL) { while((tmp = tmp2) != NULL) {
@ -249,6 +243,8 @@ void freedir(struct dir *dr) {
char *getpath(struct dir *cur) { char *getpath(struct dir *cur) {
static char *dat;
static int datl = 0;
struct dir *d, **list; struct dir *d, **list;
int c, i; int c, i;
@ -261,12 +257,12 @@ char *getpath(struct dir *cur) {
c++; c++;
} }
if(getpathdatl == 0) { if(datl == 0) {
getpathdatl = i; datl = i;
getpathdat = malloc(i); dat = malloc(i);
} else if(getpathdatl < i) { } else if(datl < i) {
getpathdatl = i; datl = i;
getpathdat = realloc(getpathdat, i); dat = realloc(dat, i);
} }
list = malloc(c*sizeof(struct dir *)); list = malloc(c*sizeof(struct dir *));
@ -274,13 +270,13 @@ char *getpath(struct dir *cur) {
for(d=cur; d!=NULL; d=d->parent) for(d=cur; d!=NULL; d=d->parent)
list[c++] = d; list[c++] = d;
getpathdat[0] = '\0'; dat[0] = '\0';
while(c--) { while(c--) {
if(list[c]->parent) if(list[c]->parent)
strcat(getpathdat, "/"); strcat(dat, "/");
strcat(getpathdat, list[c]->name); strcat(dat, list[c]->name);
} }
free(list); free(list);
return getpathdat; return dat;
} }