Code cleanup
This commit is contained in:
parent
79c62b8584
commit
972130f22f
|
@ -32,11 +32,13 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* chmod */
|
||||||
/* types */
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define CHMOD_PREFS_R 1
|
#define CHMOD_PREFS_R 1
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
/* chmod */
|
/* chmod */
|
||||||
static int _chmod_error(char const * message, int ret);
|
static int _chmod_error(char const * message, int ret);
|
||||||
static int _chmod_do(mode_t mode, char * file);
|
static int _chmod_do(mode_t mode, char * file);
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* chown */
|
||||||
/* types */
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define CHOWN_PREFS_h 0x1
|
#define CHOWN_PREFS_h 0x1
|
||||||
|
@ -42,6 +43,7 @@ typedef unsigned int Prefs;
|
||||||
#define CHOWN_PREFS_P 0xc
|
#define CHOWN_PREFS_P 0xc
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
/* chown */
|
/* chown */
|
||||||
static int _chown_error(char * message, int ret);
|
static int _chown_error(char * message, int ret);
|
||||||
static int _chown_owner(char * owner, uid_t * uid, gid_t * gid);
|
static int _chown_owner(char * owner, uid_t * uid, gid_t * gid);
|
||||||
|
|
2
src/cp.c
2
src/cp.c
|
@ -34,6 +34,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* cp */
|
||||||
/* types */
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define CP_PREFS_f 0x01
|
#define CP_PREFS_f 0x01
|
||||||
|
@ -45,6 +46,7 @@ typedef unsigned int Prefs;
|
||||||
#define CP_PREFS_P 0x40
|
#define CP_PREFS_P 0x40
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
/* cp */
|
/* cp */
|
||||||
static int _cp_error(char const * message, int ret);
|
static int _cp_error(char const * message, int ret);
|
||||||
static int _cp_single(Prefs * prefs, char const * src, char const * dst);
|
static int _cp_single(Prefs * prefs, char const * src, char const * dst);
|
||||||
|
|
4
src/df.c
4
src/df.c
|
@ -29,12 +29,14 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Prefs */
|
/* df */
|
||||||
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define DF_PREFS_k 1
|
#define DF_PREFS_k 1
|
||||||
#define DF_PREFS_P 2
|
#define DF_PREFS_P 2
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
/* df */
|
/* df */
|
||||||
static int _df_error(char const * message, int ret);
|
static int _df_error(char const * message, int ret);
|
||||||
static int _df_mtab(Prefs * prefs);
|
static int _df_mtab(Prefs * prefs);
|
||||||
|
|
4
src/du.c
4
src/du.c
|
@ -29,7 +29,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Prefs */
|
/* du */
|
||||||
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define DU_PREFS_a 0x01
|
#define DU_PREFS_a 0x01
|
||||||
#define DU_PREFS_s 0x02
|
#define DU_PREFS_s 0x02
|
||||||
|
@ -39,6 +40,7 @@ typedef unsigned int Prefs;
|
||||||
#define DU_PREFS_L 0x30
|
#define DU_PREFS_L 0x30
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
/* du */
|
/* du */
|
||||||
static int _du_do(Prefs * prefs, char const * filename);
|
static int _du_do(Prefs * prefs, char const * filename);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* prefs */
|
/* file */
|
||||||
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define FILE_PREFS_h 1
|
#define FILE_PREFS_h 1
|
||||||
#define FILE_PREFS_m 2
|
#define FILE_PREFS_m 2
|
||||||
|
@ -35,6 +36,7 @@ typedef unsigned int Prefs;
|
||||||
#define FILE_PREFS_i 8
|
#define FILE_PREFS_i 8
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
/* file */
|
/* file */
|
||||||
static int _file_do(Prefs * p, char const * filename);
|
static int _file_do(Prefs * p, char const * filename);
|
||||||
static int _file(Prefs * p, int argc, char * argv[])
|
static int _file(Prefs * p, int argc, char * argv[])
|
||||||
|
|
|
@ -35,12 +35,12 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* find */
|
||||||
/* types */
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define FIND_PREFS_H 1
|
#define FIND_PREFS_H 1
|
||||||
#define FIND_PREFS_L 2
|
#define FIND_PREFS_L 2
|
||||||
|
|
||||||
|
|
||||||
typedef enum _FindCmd
|
typedef enum _FindCmd
|
||||||
{
|
{
|
||||||
FC_INVALID = -1,
|
FC_INVALID = -1,
|
||||||
|
@ -66,6 +66,9 @@ typedef enum _FindCmd
|
||||||
} FindCmd;
|
} FindCmd;
|
||||||
#define FC_LAST FC_DEPTH
|
#define FC_LAST FC_DEPTH
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
/* find */
|
||||||
static int _find_error(char const * message, int ret);
|
static int _find_error(char const * message, int ret);
|
||||||
static int _find_error_user(char const * message, char const * error, int ret);
|
static int _find_error_user(char const * message, char const * error, int ret);
|
||||||
static int _find_do(Prefs * prefs, char const * pathname, int cmdc,
|
static int _find_do(Prefs * prefs, char const * pathname, int cmdc,
|
||||||
|
|
10
src/locale.c
10
src/locale.c
|
@ -25,7 +25,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* prefs */
|
/* locale */
|
||||||
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define LOCALE_PREFS_a 0x1
|
#define LOCALE_PREFS_a 0x1
|
||||||
#define LOCALE_PREFS_m 0x2
|
#define LOCALE_PREFS_m 0x2
|
||||||
|
@ -33,6 +34,13 @@ typedef unsigned int Prefs;
|
||||||
#define LOCALE_PREFS_k 0x8
|
#define LOCALE_PREFS_k 0x8
|
||||||
|
|
||||||
|
|
||||||
|
/* prototypes */
|
||||||
|
static int _locale(Prefs * p, int argc, char * argv[]);
|
||||||
|
|
||||||
|
static int _usage(void);
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
/* locale */
|
/* locale */
|
||||||
static int _locale_locales(void);
|
static int _locale_locales(void);
|
||||||
static int _locale_charsets(void);
|
static int _locale_charsets(void);
|
||||||
|
|
7
src/ls.c
7
src/ls.c
|
@ -34,10 +34,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* macros */
|
/* macros */
|
||||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
|
||||||
|
|
||||||
/* Prefs */
|
/* ls */
|
||||||
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define LS_PREFS_C 00001
|
#define LS_PREFS_C 00001
|
||||||
#define LS_PREFS_F 00002
|
#define LS_PREFS_F 00002
|
||||||
|
@ -416,7 +417,7 @@ static int _ls_do_files_short(Prefs * prefs, char const * directory,
|
||||||
for(cur = *files; cur != NULL; slist_next(&cur))
|
for(cur = *files; cur != NULL; slist_next(&cur))
|
||||||
{
|
{
|
||||||
lencur = strlen(slist_data(&cur));
|
lencur = strlen(slist_data(&cur));
|
||||||
lenmax = max(lenmax, lencur);
|
lenmax = MAX(lenmax, lencur);
|
||||||
}
|
}
|
||||||
if(*prefs & LS_PREFS_F)
|
if(*prefs & LS_PREFS_F)
|
||||||
lenmax++;
|
lenmax++;
|
||||||
|
|
30
src/mv.c
30
src/mv.c
|
@ -33,17 +33,22 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* mv */
|
||||||
/* types */
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define MV_PREFS_f 0x1
|
#define MV_PREFS_f 0x1
|
||||||
#define MV_PREFS_i 0x2
|
#define MV_PREFS_i 0x2
|
||||||
|
|
||||||
|
|
||||||
/* mv */
|
/* prototypes */
|
||||||
static int _mv_error(char const * message, int ret);
|
static int _mv_error(char const * message, int ret);
|
||||||
|
|
||||||
static int _mv_single(Prefs * prefs, char const * src, char const * dst);
|
static int _mv_single(Prefs * prefs, char const * src, char const * dst);
|
||||||
static int _mv_multiple(Prefs * prefs, int filec, char * const filev[]);
|
static int _mv_multiple(Prefs * prefs, int filec, char * const filev[]);
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
/* mv */
|
||||||
static int _mv(Prefs * prefs, int filec, char * filev[])
|
static int _mv(Prefs * prefs, int filec, char * filev[])
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
@ -68,13 +73,6 @@ static int _mv(Prefs * prefs, int filec, char * filev[])
|
||||||
return _mv_single(prefs, filev[0], filev[1]);
|
return _mv_single(prefs, filev[0], filev[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _mv_error(char const * message, int ret)
|
|
||||||
{
|
|
||||||
fputs(PROGNAME ": ", stderr);
|
|
||||||
perror(message);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _mv_confirm(char const * message)
|
static int _mv_confirm(char const * message)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
@ -87,9 +85,21 @@ static int _mv_confirm(char const * message)
|
||||||
return c == 'y';
|
return c == 'y';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* mv_error */
|
||||||
|
static int _mv_error(char const * message, int ret)
|
||||||
|
{
|
||||||
|
fputs(PROGNAME ": ", stderr);
|
||||||
|
perror(message);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* mv_single */
|
/* mv_single */
|
||||||
static int _mv_single_dir(Prefs * prefs, char const * src, char const * dst,
|
static int _mv_single_dir(Prefs * prefs, char const * src, char const * dst,
|
||||||
mode_t mode);
|
mode_t mode);
|
||||||
|
static int _mv_single_recurse(Prefs * prefs, char const * src, char const * dst,
|
||||||
|
mode_t mode);
|
||||||
static int _mv_single_fifo(char const * src, char const * dst, mode_t mode);
|
static int _mv_single_fifo(char const * src, char const * dst, mode_t mode);
|
||||||
static int _mv_single_nod(char const * src, char const * dst, mode_t mode,
|
static int _mv_single_nod(char const * src, char const * dst, mode_t mode,
|
||||||
dev_t rdev);
|
dev_t rdev);
|
||||||
|
@ -136,10 +146,6 @@ static int _mv_single(Prefs * prefs, char const * src, char const * dst)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _mv_single_dir */
|
|
||||||
static int _mv_single_recurse(Prefs * prefs, char const * src, char const * dst,
|
|
||||||
mode_t mode);
|
|
||||||
|
|
||||||
static int _mv_single_dir(Prefs * prefs, char const * src, char const * dst,
|
static int _mv_single_dir(Prefs * prefs, char const * src, char const * dst,
|
||||||
mode_t mode)
|
mode_t mode)
|
||||||
{
|
{
|
||||||
|
|
25
src/rm.c
25
src/rm.c
|
@ -30,6 +30,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* rm */
|
||||||
/* types */
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define RM_PREFS_f 0x1
|
#define RM_PREFS_f 0x1
|
||||||
|
@ -37,10 +38,16 @@ typedef unsigned int Prefs;
|
||||||
#define RM_PREFS_R 0x4
|
#define RM_PREFS_R 0x4
|
||||||
|
|
||||||
|
|
||||||
/* rm */
|
/* prototypes */
|
||||||
|
static int _rm(Prefs * prefs, int argc, char * argv[]);
|
||||||
|
|
||||||
static int _rm_error(char const * message, int ret);
|
static int _rm_error(char const * message, int ret);
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
/* rm */
|
||||||
static int _rm_do(Prefs * prefs, char * file);
|
static int _rm_do(Prefs * prefs, char * file);
|
||||||
|
|
||||||
static int _rm(Prefs * prefs, int argc, char * argv[])
|
static int _rm(Prefs * prefs, int argc, char * argv[])
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -51,13 +58,6 @@ static int _rm(Prefs * prefs, int argc, char * argv[])
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _rm_error(char const * message, int ret)
|
|
||||||
{
|
|
||||||
fputs(PROGNAME ": ", stderr);
|
|
||||||
perror(message);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _rm_confirm(char const * message, char const * type)
|
static int _rm_confirm(char const * message, char const * type)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
@ -140,6 +140,15 @@ static int _rm_do_recursive(Prefs * prefs, char * filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* rm_error */
|
||||||
|
static int _rm_error(char const * message, int ret)
|
||||||
|
{
|
||||||
|
fputs(PROGNAME ": ", stderr);
|
||||||
|
perror(message);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
|
|
26
src/uniq.c
26
src/uniq.c
|
@ -26,6 +26,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* uniq */
|
||||||
/* types */
|
/* types */
|
||||||
typedef unsigned int Prefs;
|
typedef unsigned int Prefs;
|
||||||
#define UNIQ_PREFS_c 1
|
#define UNIQ_PREFS_c 1
|
||||||
|
@ -33,12 +34,19 @@ typedef unsigned int Prefs;
|
||||||
#define UNIQ_PREFS_u 4
|
#define UNIQ_PREFS_u 4
|
||||||
|
|
||||||
|
|
||||||
|
/* prototypes */
|
||||||
|
static int _uniq(Prefs prefs, char const * fields, unsigned int skip,
|
||||||
|
char const * in, char const * out);
|
||||||
|
|
||||||
|
static int _uniq_error(char const * message, int ret);
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
/* uniq */
|
/* uniq */
|
||||||
/* PRE if in == NULL then out == NULL too
|
/* PRE if in == NULL then out == NULL too
|
||||||
* POST
|
* POST
|
||||||
* 0 success
|
* 0 success
|
||||||
* else error(s) occured */
|
* else error(s) occured */
|
||||||
static int _uniq_error(char const * message, int ret);
|
|
||||||
static int _uniq_do(Prefs prefs, char const * fields, unsigned int skip,
|
static int _uniq_do(Prefs prefs, char const * fields, unsigned int skip,
|
||||||
FILE * infp, FILE * outfp);
|
FILE * infp, FILE * outfp);
|
||||||
|
|
||||||
|
@ -67,13 +75,6 @@ static int _uniq(Prefs prefs, char const * fields, unsigned int skip,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _uniq_error(char const * message, int ret)
|
|
||||||
{
|
|
||||||
fputs(PROGNAME ": ", stderr);
|
|
||||||
perror(message);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _do_count(Prefs prefs, unsigned int skip, char * line, FILE * fp);
|
static void _do_count(Prefs prefs, unsigned int skip, char * line, FILE * fp);
|
||||||
static int _uniq_do(Prefs prefs, char const * fields, unsigned int skip,
|
static int _uniq_do(Prefs prefs, char const * fields, unsigned int skip,
|
||||||
FILE * infp, FILE * outfp)
|
FILE * infp, FILE * outfp)
|
||||||
|
@ -162,6 +163,15 @@ static int _count_repeated(char * lastline, char * line, unsigned int skip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* uniq_error */
|
||||||
|
static int _uniq_error(char const * message, int ret)
|
||||||
|
{
|
||||||
|
fputs(PROGNAME ": ", stderr);
|
||||||
|
perror(message);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user