Re: compress: remove cat_opts and decomp_opts, add static

2022-10-23 Thread Klemens Nanni
On Sat, Oct 22, 2022 at 02:09:40PM -0600, Todd C. Miller wrote:
> The cat_opts and decomp_opts fields in struct compressor are unused
> so just remove them.  Also mark functions unused outside of main.c
> as static.

OK kn



compress: remove cat_opts and decomp_opts, add static

2022-10-22 Thread Todd C . Miller
The cat_opts and decomp_opts fields in struct compressor are unused
so just remove them.  Also mark functions unused outside of main.c
as static.

 - todd

Index: usr.bin/compress/main.c
===
RCS file: /cvs/src/usr.bin/compress/main.c,v
retrieving revision 1.102
diff -u -p -u -r1.102 main.c
--- usr.bin/compress/main.c 22 Oct 2022 14:41:27 -  1.102
+++ usr.bin/compress/main.c 22 Oct 2022 20:06:43 -
@@ -61,9 +61,7 @@ const struct compressor {
const char *name;
const char *suffix;
const u_char *magic;
-   const char *comp_opts;
-   const char *decomp_opts;
-   const char *cat_opts;
+   const char *opts;
void *(*ropen)(int, char *, int);
int (*read)(void *, char *, int);
 #ifndef SMALL
@@ -78,8 +76,6 @@ const struct compressor {
".gz",
"\037\213",
"123456789ab:cdfhkLlNnOo:qrS:tVv",
-   "cfhkLlNno:qrtVv",
-   "fhqr",
gz_ropen,
gz_read,
 #ifndef SMALL
@@ -95,8 +91,6 @@ const struct compressor {
".Z",
"\037\235",
"123456789ab:cdfghlNnOo:qrS:tv",
-   "cfhlNno:qrtv",
-   "fghqr",
z_ropen,
zread,
z_wopen,
@@ -109,8 +103,6 @@ const struct compressor {
".zip",
"PK",
NULL,
-   "cfhkLlNno:qrtVv",
-   "fhqr",
zip_ropen,
zip_read,
NULL,
@@ -127,8 +119,6 @@ const struct compressor null_method = {
".nul",
"XX",
"123456789ab:cdfghlNnOo:qrS:tv",
-   "cfhlNno:qrtv",
-   "fghqr",
null_ropen,
null_read,
null_wopen,
@@ -137,19 +127,19 @@ const struct compressor null_method = {
 };
 #endif /* SMALL */
 
-int permission(const char *);
-__dead void usage(int);
-int docompress(const char *, char *, const struct compressor *,
+static int permission(const char *);
+static __dead void usage(int);
+static int docompress(const char *, char *, const struct compressor *,
 int, struct stat *);
-int dodecompress(const char *, char *, struct stat *);
-const struct compressor *check_method(int);
-const char *check_suffix(const char *);
-char *set_outfile(const char *, char *, size_t);
-void list_stats(const char *, const struct compressor *, struct z_info *);
-void verbose_info(const char *, off_t, off_t, u_int32_t);
+static int dodecompress(const char *, char *, struct stat *);
+static const char *check_suffix(const char *);
+static char *set_outfile(const char *, char *, size_t);
+static void list_stats(const char *, const struct compressor *,
+struct z_info *);
+static void verbose_info(const char *, off_t, off_t, u_int32_t);
 
-const struct option longopts[] = {
 #ifndef SMALL
+const struct option longopts[] = {
{ "ascii",  no_argument,0, 'a' },
{ "stdout", no_argument,0, 'c' },
{ "to-stdout",  no_argument,0, 'c' },
@@ -170,9 +160,11 @@ const struct option longopts[] = {
{ "version",no_argument,0, 'V' },
{ "fast",   no_argument,0, '1' },
{ "best",   no_argument,0, '9' },
-#endif /* SMALL */
{ NULL }
 };
+#else /* SMALL */
+const struct option *longopts = NULL;
+#endif /* SMALL */
 
 int
 main(int argc, char *argv[])
@@ -202,7 +194,7 @@ main(int argc, char *argv[])
method = M_COMPRESS;
 #endif /* SMALL */
}
-   optstr = method->comp_opts;
+   optstr = method->opts;
 
decomp = 0;
pmode = MODE_COMP;
@@ -617,7 +609,7 @@ docompress(const char *in, char *out, co
 #endif
 }
 
-const struct compressor *
+static const struct compressor *
 check_method(int fd)
 {
const struct compressor *method;
@@ -640,7 +632,7 @@ check_method(int fd)
return (NULL);
 }
 
-int
+static int
 dodecompress(const char *in, char *out, struct stat *sb)
 {
const struct compressor *method;
@@ -690,7 +682,7 @@ dodecompress(const char *in, char *out, 
return (FAILURE);
}
if (storename && oldname[0] != '\0') {
-   char *oldbase = basename(oldname);
+   const char *oldbase = basename(oldname);
char *cp = strrchr(out, '/');
if (cp != NULL) {
*(cp + 1) = '\0';
@@ -834,7 +826,7 @@ setfile(const char *name, int fd, struct
warn("futimens: %s", name);
 }
 
-int
+static int
 permission(const char *fname)
 {
int ch, first;
@@ -851,7 +843,7 @@ permission(const char *fname)
 /*
  * Check infile for a known suffix and return the suffix portion or NULL.
  */
-const char *
+static const char *
 check_suffix(const char *infile)
 {
int i;
@@ -878,7 +870,7 @@ check_suffix(const char *infile)
  * Set ou