[25334] in Source-Commits
/svn/athena r24908 - in trunk/athena/bin/delete: . debian man1
daemon@ATHENA.MIT.EDU (Greg Hudson)
Mon Nov 22 12:08:01 2010
Date: Mon, 22 Nov 2010 12:07:55 -0500
From: Greg Hudson <ghudson@MIT.EDU>
Message-Id: <201011221707.oAMH7tHP003454@drugstore.mit.edu>
To: source-commits@mit.edu
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Author: ghudson
Date: 2010-11-22 12:07:55 -0500 (Mon, 22 Nov 2010)
New Revision: 24908
Modified:
trunk/athena/bin/delete/col.c
trunk/athena/bin/delete/col.h
trunk/athena/bin/delete/debian/changelog
trunk/athena/bin/delete/delete.c
trunk/athena/bin/delete/directories.c
trunk/athena/bin/delete/directories.h
trunk/athena/bin/delete/errors.c
trunk/athena/bin/delete/expunge.c
trunk/athena/bin/delete/lsdel.c
trunk/athena/bin/delete/man1/delete.1
trunk/athena/bin/delete/pattern.c
trunk/athena/bin/delete/pattern.h
trunk/athena/bin/delete/shell_regexp.c
trunk/athena/bin/delete/stack.c
trunk/athena/bin/delete/stack.h
trunk/athena/bin/delete/undelete.c
trunk/athena/bin/delete/util.c
trunk/athena/bin/delete/util.h
Log:
In delete:
* Patches from Jonathan Kamens:
- The "-f" flag to delete should suppress nonexistent file errors but
not other errors.
- When the "-v" flag is specified to expunge, the correct totals
should be reported. Previously, the totals were incorrect.
- Code cleanup.
Modified: trunk/athena/bin/delete/col.c
===================================================================
--- trunk/athena/bin/delete/col.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/col.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,32 +9,26 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if (!defined(lint) && !defined(SABER))
- static char rcsid_col_c[] = "$Id: col.c,v 1.10 1999-01-22 23:08:50 ghudson Exp $";
-#endif
-
/*
* Note that this function has a lot of options I'm not really using
* because I took it out of other code that needed a lot more
* versatility.
*/
-#include <stdio.h>
#include <string.h>
#include "errors.h"
#include "delete_errs.h"
#include "col.h"
#include "mit-copying.h"
+#include "util.h"
-
static int calc_string_width(), calc_widths(), num_width();
static void trim_strings();
-int column_array(strings, num_to_print, screen_width, column_width,
- number_of_columns, margin, spread_flag,
- number_flag, var_col_flag, outfile)
-char **strings;
-FILE *outfile;
+int column_array(char **strings, int num_to_print, int screen_width,
+ int column_width, int number_of_columns, int margin,
+ int spread_flag, int number_flag, int var_col_flag,
+ FILE *outfile)
{
char buf[BUFSIZ];
int updown, leftright, height;
Modified: trunk/athena/bin/delete/col.h
===================================================================
--- trunk/athena/bin/delete/col.h 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/col.h 2010-11-22 17:07:55 UTC (rev 24908)
@@ -10,6 +10,8 @@
*/
#include "mit-copying.h"
+#include <stdio.h>
+
/*
* DEF_COL_WIDTH: the column with to try to use if none is specified.
* DEF_WAIT: 1 if the program is supposed to wait for stdin to get to
@@ -33,3 +35,8 @@
/* be when printed. Also, if we are supposed to work in wait mode */
/* and are not given a maxitems value, this is what is used. */
#define DEF_MAX_ITEMS 10000
+
+int column_array(char **strings, int num_to_print, int screen_width,
+ int column_width, int number_of_columns, int margin,
+ int spread_flag, int number_flag, int var_col_flag,
+ FILE *outfile);
Modified: trunk/athena/bin/delete/debian/changelog
===================================================================
--- trunk/athena/bin/delete/debian/changelog 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/debian/changelog 2010-11-22 17:07:55 UTC (rev 24908)
@@ -1,3 +1,14 @@
+debathena-delete (10.0.2-0debathena1) unstable; urgency=low
+
+ * Patches from Jonathan Kamens:
+ - The "-f" flag to delete should suppress nonexistent file errors but
+ not other errors.
+ - When the "-v" flag is specified to expunge, the correct totals
+ should be reported. Previously, the totals were incorrect.
+ - Code cleanup.
+
+ -- Greg Hudson <ghudson@mit.edu> Mon, 22 Nov 2010 12:05:35 -0500
+
debathena-delete (10.0.1-0debathena1) unstable; urgency=low
* Patches from Jonathan Kamens:
Modified: trunk/athena/bin/delete/delete.c
===================================================================
--- trunk/athena/bin/delete/delete.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/delete.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,10 +9,6 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if (!defined(lint) && !defined(SABER))
- static char rcsid_delete_c[] = "$Id: delete.c,v 1.33 1999-01-22 23:08:52 ghudson Exp $";
-#endif
-
#include <sys/types.h>
#ifdef HAVE_AFS
#include <sys/time.h>
@@ -26,12 +22,11 @@
#include <errno.h>
#include "errors.h"
#include "delete_errs.h"
-#include "util.h"
+#include "pattern.h"
#include "delete.h"
#include "mit-copying.h"
+#include "util.h"
-
-
/*
* ALGORITHM:
*
@@ -67,6 +62,12 @@
* (excluding . files) to delete().
*/
+static void usage(void);
+static int delete(char *filename, int recursed);
+static int recursive_delete(char *filename, struct stat stat_buf, int recursed);
+static int empty_directory(char *filename);
+static int do_move(char *filename, struct stat stat_buf, int subs_not_deleted);
+static int unlink_completely(char *filename);
int force, interactive, recursive, noop, verbose, filesonly, directoriesonly;
int emulate_rm, linked_to_rm, linked_to_rmdir;
@@ -74,9 +75,7 @@
struct timeval tvp[2];
#endif
-main(argc, argv)
-int argc;
-char *argv[];
+int main(int argc, char *argv[])
{
extern char *optarg;
extern int optind;
@@ -158,7 +157,7 @@
exit(1);
}
}
- report_errors = ! (force || emulate_rm);
+ report_errors = ! emulate_rm;
if (optind == argc) {
if (! force) {
@@ -172,12 +171,12 @@
error(argv[optind]);
optind++;
}
- exit(((! force) && error_occurred) ? 1 : 0);
+ exit(error_occurred ? 1 : 0);
}
-usage()
+static void usage()
{
printf("Usage: %s [ options ] filename ...\n", whoami);
printf("Options are:\n");
@@ -202,20 +201,21 @@
-delete(filename, recursed)
-char *filename;
-int recursed;
+static int delete(char *filename, int recursed)
{
struct stat stat_buf;
int retval;
/* can the file be lstat'd? */
if (lstat(filename, &stat_buf) == -1) {
- set_error(errno);
- if (emulate_rm && (! force))
- fprintf(stderr, "%s: %s nonexistent\n", whoami, filename);
- error(filename);
- return error_code;
+ if (! force) {
+ set_error(errno);
+ if (emulate_rm)
+ fprintf(stderr, "%s: %s nonexistent\n", whoami, filename);
+ error(filename);
+ return error_code;
+ }
+ return 0;
}
/* is the file a directory? */
@@ -233,11 +233,11 @@
if (filesonly) {
/* is the recursive option specified? */
if (recursive) {
- if (retval = recursive_delete(filename, stat_buf,
- recursed)) {
- error(filename);
- return retval;
- }
+ if ((retval = recursive_delete(filename, stat_buf,
+ recursed))) {
+ error(filename);
+ return retval;
+ }
}
else {
if (emulate_rm && (! force))
@@ -257,11 +257,11 @@
}
if (retval > 0) {
- /* remove it */
- if (retval = do_move(filename, stat_buf, 0)) {
- error(filename);
- return error_code;
- }
+ /* remove it */
+ if ((retval = do_move(filename, stat_buf, 0))) {
+ error(filename);
+ return error_code;
+ }
}
else {
/* is the directoriesonly option set? */
@@ -276,11 +276,11 @@
else {
/* is the recursive option specified? */
if (recursive) {
- if (retval = recursive_delete(filename, stat_buf,
- recursed)) {
- error(filename);
- return error_code;
- }
+ if ((retval = recursive_delete(filename, stat_buf,
+ recursed))) {
+ error(filename);
+ return error_code;
+ }
}
else {
if (emulate_rm && (! force))
@@ -305,10 +305,10 @@
return error_code;
}
else {
- if (retval = do_move(filename, stat_buf, 0)) {
- error(filename);
- return error_code;
- }
+ if ((retval = do_move(filename, stat_buf, 0))) {
+ error(filename);
+ return error_code;
+ }
}
}
return 0;
@@ -318,8 +318,7 @@
-empty_directory(filename)
-char *filename;
+static int empty_directory(char *filename)
{
DIR *dirp;
struct dirent *dp;
@@ -347,10 +346,7 @@
-recursive_delete(filename, stat_buf, recursed)
-char *filename;
-struct stat stat_buf;
-int recursed;
+static int recursive_delete(char *filename, struct stat stat_buf, int recursed)
{
DIR *dirp;
struct dirent *dp;
@@ -359,7 +355,7 @@
int retval = 0;
char **dir_contents = 0;
int num_dir_contents = 0, dir_contents_size = 0;
-
+
if (interactive && recursed) {
printf("%s: remove directory %s? ", whoami, filename);
if (! yes()) {
@@ -427,17 +423,15 @@
-do_move(filename, stat_buf, subs_not_deleted)
-char *filename;
-struct stat stat_buf;
-int subs_not_deleted; /* If the file in question is a directory, and */
- /* there is something underneath it that hasn't */
- /* been removed, this will be set to true. */
- /* The program asks if the user wants to delete */
- /* the directory, and if the user says yes, */
- /* checks the value of subs_not_deleted. If */
- /* it's true, an error results. */
- /* This is used only when emulating rm. */
+/*
+ * If the file in question is a directory, and there is something
+ * underneath it that hasn't been removed, then subs_not_deleted will
+ * be set to true. The program asks if the user wants to delete the
+ * directory, and if the user says yes, checks the value of
+ * subs_not_deleted. If it's true, an error results. This is used
+ * only when emulating rm.
+ */
+static int do_move(char *filename, struct stat stat_buf, int subs_not_deleted)
{
char *last;
char buf[MAXPATHLEN];
@@ -537,8 +531,7 @@
-unlink_completely(filename)
-char *filename;
+static int unlink_completely(char *filename)
{
char buf[MAXPATHLEN];
struct stat stat_buf;
Modified: trunk/athena/bin/delete/directories.c
===================================================================
--- trunk/athena/bin/delete/directories.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/directories.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,10 +9,6 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if !defined(lint) && !defined(SABER)
- static char rcsid_directories_c[] = "$Id: directories.c,v 1.28 1999-01-22 23:08:54 ghudson Exp $";
-#endif
-
#include <math.h>
#include <stdio.h>
#include <sys/types.h>
@@ -23,15 +19,18 @@
#include <errno.h>
#include <com_err.h>
#include "delete_errs.h"
-#include "util.h"
#include "directories.h"
#include "mit-copying.h"
#include "errors.h"
+#include "util.h"
static filerec root_tree;
static filerec cwd_tree;
-void free_leaf();
+void free_leaf(filerec *leaf);
+static int get_specs(char *path,
+ struct mystat *specs,
+ int follow);
/* These are not static because external routines need to be able to */
/* access them. */
@@ -108,11 +107,11 @@
cwd_tree = default_cwd;
current_time = time((time_t *)0);
- if (retval = get_specs(".", &cwd_tree.specs, FOLLOW_LINKS)) {
+ if ((retval = get_specs(".", &cwd_tree.specs, FOLLOW_LINKS))) {
error("get_specs on .");
return retval;
}
- if (retval = get_specs("/", &root_tree.specs, FOLLOW_LINKS)) {
+ if ((retval = get_specs("/", &root_tree.specs, FOLLOW_LINKS))) {
error("get_specs on /");
return retval;
}
@@ -130,7 +129,7 @@
struct mystat specs;
int retval;
- if (retval = get_specs(path, &specs, DONT_FOLLOW_LINKS)) {
+ if ((retval = get_specs(path, &specs, DONT_FOLLOW_LINKS))) {
char error_buf[MAXPATHLEN+14];
(void) sprintf(error_buf, "get_specs on %s", path);
@@ -159,13 +158,13 @@
(void) strcpy(next_name, firstpart(ptr, ptr));
while (*ptr) {
(void) strcat(built_path, next_name);
- if (retval = add_directory_to_parent(parent, next_name, False,
- &parent)) {
+ if ((retval = add_directory_to_parent(parent, next_name, False,
+ &parent))) {
error("add_directory_to_parent");
return retval;
}
(void) strcpy(next_name, firstpart(ptr, ptr));
- if (retval = get_specs(built_path, &parent->specs, FOLLOW_LINKS)) {
+ if ((retval = get_specs(built_path, &parent->specs, FOLLOW_LINKS))) {
char error_buf[MAXPATHLEN+14];
(void) sprintf(error_buf, "get_specs on %s", built_path);
@@ -196,10 +195,9 @@
-int get_specs(path, specs, follow)
-char *path;
-struct mystat *specs;
-int follow; /* follow symlinks or not? */
+static int get_specs(char *path,
+ struct mystat *specs,
+ int follow) /* follow symlinks or not? */
{
int status;
struct stat realspecs;
@@ -223,7 +221,6 @@
specs->st_mode = realspecs.st_mode;
specs->st_size = realspecs.st_size;
specs->st_ctim = realspecs.st_ctime;
- specs->st_blocks = realspecs.st_blocks;
return 0;
}
@@ -252,10 +249,11 @@
filerec *next_specified_leaf(leaf)
filerec *leaf;
{
- while (leaf = next_leaf(leaf))
- if (leaf->specified)
- return(leaf);
- return((filerec *) NULL);
+ while ((leaf = next_leaf(leaf))) {
+ if (leaf->specified)
+ return(leaf);
+ }
+ return((filerec *) NULL);
}
@@ -278,10 +276,11 @@
filerec *next_specified_directory(leaf)
filerec *leaf;
{
- while (leaf = next_directory(leaf))
- if (leaf->specified)
- return(leaf);
- return ((filerec *) NULL);
+ while ((leaf = next_directory(leaf))) {
+ if (leaf->specified)
+ return(leaf);
+ }
+ return ((filerec *) NULL);
}
@@ -308,10 +307,11 @@
filerec *next_specified_in_directory(leaf)
filerec *leaf;
{
- while (leaf = next_in_directory(leaf))
- if (leaf->specified)
- return(leaf);
- return ((filerec *) NULL);
+ while ((leaf = next_in_directory(leaf))) {
+ if (leaf->specified)
+ return(leaf);
+ }
+ return ((filerec *) NULL);
}
@@ -350,6 +350,7 @@
}
+/* This is a debugging function not actually used anywhere in any program. */
void print_paths_from(leaf)
filerec *leaf;
{
@@ -359,7 +360,12 @@
*/
static char buf[MAXPATHLEN];
- printf("%s\n", get_leaf_path(leaf, buf));
+ if (! get_leaf_path(leaf, buf)) {
+ printf("%s\n", buf);
+ }
+ else {
+ error("get_leaf_path");
+ }
if (leaf->dirs)
print_paths_from(leaf->dirs);
if (leaf->files)
@@ -369,6 +375,7 @@
}
+/* This is a debugging function not actually used anywhere in any program. */
void print_specified_paths_from(leaf)
filerec *leaf;
{
@@ -378,8 +385,14 @@
*/
static char buf[MAXPATHLEN];
- if (leaf->specified)
- printf("%s\n", get_leaf_path(leaf, buf));
+ if (leaf->specified) {
+ if (! get_leaf_path(leaf, buf)) {
+ printf("%s\n", buf);
+ }
+ else {
+ error("get_leaf_path");
+ }
+ }
if (leaf->dirs)
print_specified_paths_from(leaf->dirs);
if (leaf->files)
@@ -495,8 +508,7 @@
-void free_leaf(leaf)
-filerec *leaf;
+void free_leaf(filerec *leaf)
{
leaf->freed = True;
if (! (leaf->dirs || leaf->files)) {
@@ -611,9 +623,8 @@
}
-int get_leaf_path(leaf, leaf_buf)
-filerec *leaf;
-char leaf_buf[]; /* RETURN */
+int get_leaf_path(filerec *leaf,
+ char leaf_buf[]) /* RETURN */
{
char *name_ptr;
@@ -675,7 +686,7 @@
error("realloc");
return error_code;
}
- if (retval = get_leaf_path(leaf, newname)) {
+ if ((retval = get_leaf_path(leaf, newname))) {
error("get_leaf_path");
return retval;
}
@@ -688,18 +699,18 @@
}
(void) strcpy(strings[*num - 1], newname);
}
- if (leaf->files) if (retval = accumulate_names(leaf->files, &strings,
- num)) {
+ if (leaf->files && (retval = accumulate_names(leaf->files, &strings,
+ num))) {
error("accumulate_names");
return retval;
}
- if (leaf->dirs) if (retval = accumulate_names(leaf->dirs, &strings,
- num)) {
+ if (leaf->dirs && (retval = accumulate_names(leaf->dirs, &strings,
+ num))) {
error("accumulate_names");
return retval;
}
- if (leaf->next) if (retval = accumulate_names(leaf->next, &strings,
- num)) {
+ if (leaf->next && (retval = accumulate_names(leaf->next, &strings,
+ num))) {
error("accumulate_names");
return retval;
}
Modified: trunk/athena/bin/delete/directories.h
===================================================================
--- trunk/athena/bin/delete/directories.h 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/directories.h 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,7 +9,11 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
+#ifndef __DELETE_DIRECTORIES_H__
+#define __DELETE_DIRECTORIES_H__
+
#include "mit-copying.h"
+#include <dirent.h>
typedef short Boolean;
#define True (Boolean) 1
@@ -17,9 +21,7 @@
char *bytes_to_friendly(off_t);
-#define specs_to_space(x) ((x).st_blocks)
-#define space_to_k(x) ((x) / 2 + (((x) % 2) ? 1 : 0))
-#define specs_to_k(x) space_to_k((x).st_blocks)
+#define specs_to_space(x) ((x).st_size)
#define space_to_friendly(x) bytes_to_friendly((x))
#define specs_to_friendly(x) space_to_friendly((x).st_size)
@@ -61,6 +63,7 @@
filerec *first_in_directory();
filerec *first_specified_in_directory();
filerec *get_cwd_tree();
+int initialize_tree(void);
filerec *get_root_tree();
filerec *next_directory();
filerec *next_in_directory();
@@ -69,7 +72,9 @@
filerec *next_specified_in_directory();
filerec *next_specified_leaf();
-int get_leaf_path();
+int get_leaf_path(filerec *leaf, char leaf_buf[]);
int accumulate_names();
void free_leaf();
+
+#endif /* ! __DELETE_DIRECTORIES_H__ */
Modified: trunk/athena/bin/delete/errors.c
===================================================================
--- trunk/athena/bin/delete/errors.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/errors.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,14 +9,11 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if (!defined(lint) && !defined(SABER))
- static char rcsid_errors_c[] = "$Id: errors.c,v 1.5 1999-01-22 23:08:58 ghudson Exp $";
-#endif
-
#include <com_err.h>
#include <stdio.h>
#include "delete_errs.h"
#include "mit-copying.h"
+#include "util.h"
char *whoami;
int error_reported = 1;
Modified: trunk/athena/bin/delete/expunge.c
===================================================================
--- trunk/athena/bin/delete/expunge.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/expunge.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,10 +9,6 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if (!defined(lint) && !defined(SABER))
- static char rcsid_expunge_c[] = "$Id: expunge.c,v 1.25 1999-01-22 23:08:59 ghudson Exp $";
-#endif
-
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
@@ -21,8 +17,8 @@
#include <string.h>
#include <com_err.h>
#include <errno.h>
+#include <unistd.h>
#include "col.h"
-#include "util.h"
#include "directories.h"
#include "pattern.h"
#include "expunge.h"
@@ -30,7 +26,14 @@
#include "mit-copying.h"
#include "delete_errs.h"
#include "errors.h"
+#include "util.h"
+static void usage(void);
+static int purge(void), expunge(char **files, int num);
+static int process_files(char **files, int num), list_files(void);
+static int top_level(void), expunge_specified(filerec *leaf);
+static int really_do_expunge(filerec *file_ent);
+
extern time_t current_time;
extern char *whoami;
@@ -52,9 +55,7 @@
-main(argc, argv)
-int argc;
-char *argv[];
+int main(int argc, char *argv[])
{
extern char *optarg;
extern int optind;
@@ -134,7 +135,7 @@
-purge()
+static int purge()
{
char *home;
int retval;
@@ -147,14 +148,14 @@
}
timev = interactive = noop = verbose = force = 0;
yield = listfiles = recursive = 1;
- if (retval = get_home(home)) {
+ if ((retval = get_home(home))) {
error("purge");
return retval;
}
printf("Please be patient.... this may take a while.\n\n");
- if (retval = expunge(&home, 1)) {
+ if ((retval = expunge(&home, 1))) {
error("expunge");
return retval;
}
@@ -164,7 +165,7 @@
-usage()
+static void usage()
{
fprintf(stderr, "Usage: %s [ options ] [ filename [ ... ]]\n", whoami);
fprintf(stderr, "Options are:\n");
@@ -185,9 +186,7 @@
-int expunge(files, num)
-char **files;
-int num;
+static int expunge(char **files, int num)
{
char **found_files;
int num_found;
@@ -239,28 +238,28 @@
}
}
if (total && listfiles) {
- if (retval = list_files()) {
- error("list_files");
- return retval;
- }
- if (! force) if (! top_level()) {
- set_status(EXPUNGE_NOT_EXPUNGED);
- return error_code;
- }
+ if ((retval = list_files())) {
+ error("list_files");
+ return retval;
+ }
+ if (! (force || top_level())) {
+ set_status(EXPUNGE_NOT_EXPUNGED);
+ return error_code;
+ }
}
current = get_root_tree();
if (current) {
- if (retval = expunge_specified(current)) {
- error("expunge_specified");
- status = retval;
- }
+ if ((retval = expunge_specified(current))) {
+ error("expunge_specified");
+ status = retval;
+ }
}
current = get_cwd_tree();
if (current) {
- if (retval = expunge_specified(current)) {
- error("expunge_specified");
- status = retval;
- }
+ if ((retval = expunge_specified(current))) {
+ error("expunge_specified");
+ status = retval;
+ }
}
if (yield) {
char *friendly = space_to_friendly(space_removed);
@@ -275,8 +274,7 @@
-expunge_specified(leaf)
-filerec *leaf;
+static int expunge_specified(filerec *leaf)
{
int status = 0;
int do_it = 1;
@@ -289,7 +287,7 @@
*/
static char buf[MAXPATHLEN];
- if (retval = get_leaf_path(leaf, buf)) {
+ if ((retval = get_leaf_path(leaf, buf))) {
error("get_leaf_path");
return retval;
}
@@ -302,29 +300,29 @@
}
if (do_it) {
if (leaf->dirs) {
- if (retval = expunge_specified(leaf->dirs)) {
- error("expunge_specified");
- status = retval;
- }
+ if ((retval = expunge_specified(leaf->dirs))) {
+ error("expunge_specified");
+ status = retval;
+ }
}
if (leaf->files) {
- if (retval = expunge_specified(leaf->files)) {
- error("expunge_specified");
- status = retval;
- }
+ if ((retval = expunge_specified(leaf->files))) {
+ error("expunge_specified");
+ status = retval;
+ }
}
}
if (leaf->specified && (! status)) {
- if (retval = really_do_expunge(leaf)) {
- error("really_do_expunge");
- status = retval;
- }
+ if ((retval = really_do_expunge(leaf))) {
+ error("really_do_expunge");
+ status = retval;
+ }
}
if (leaf->next) {
- if (retval = expunge_specified(leaf->next)) {
- error("expunge_specified");
- status = retval;
- }
+ if ((retval = expunge_specified(leaf->next))) {
+ error("expunge_specified");
+ status = retval;
+ }
}
free_leaf(leaf);
@@ -332,9 +330,7 @@
}
-process_files(files, num)
-char **files;
-int num;
+static int process_files(char **files, int num)
{
int i, skipped = 0;
filerec *leaf;
@@ -362,14 +358,13 @@
-really_do_expunge(file_ent)
-filerec *file_ent;
+static int really_do_expunge(filerec *file_ent)
{
char real[MAXPATHLEN], user[MAXPATHLEN];
int status;
int retval;
- if (retval = get_leaf_path(file_ent, real)) {
+ if ((retval = get_leaf_path(file_ent, real))) {
error("get_leaf_path");
return retval;
}
@@ -427,7 +422,7 @@
-top_level()
+static int top_level()
{
if (interactive) {
printf("The above files, which have been marked for deletion, are about to be\n");
@@ -446,7 +441,7 @@
-list_files()
+static int list_files()
{
filerec *current;
char **strings;
@@ -464,17 +459,17 @@
printf("The following deleted files are going to be expunged: \n\n");
current = get_root_tree();
- if (retval = accumulate_names(current, &strings, &num)) {
+ if ((retval = accumulate_names(current, &strings, &num))) {
error("accumulate_names");
return retval;
}
current = get_cwd_tree();
- if (retval = accumulate_names(current, &strings, &num)) {
+ if ((retval = accumulate_names(current, &strings, &num))) {
error("accumulate_names");
return retval;
}
- if (retval = column_array(strings, num, DEF_SCR_WIDTH, 0, 0, 2, 1, 0,
- 1, stdout)) {
+ if ((retval = column_array(strings, num, DEF_SCR_WIDTH, 0, 0, 2, 1, 0,
+ 1, stdout))) {
error("column_array");
return retval;
}
Modified: trunk/athena/bin/delete/lsdel.c
===================================================================
--- trunk/athena/bin/delete/lsdel.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/lsdel.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,10 +9,6 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if (!defined(lint) && !defined(SABER))
- static char rcsid_lsdel_c[] = "$Id: lsdel.c,v 1.24 1999-01-22 23:09:01 ghudson Exp $";
-#endif
-
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
@@ -20,8 +16,8 @@
#include <string.h>
#include <errno.h>
#include <com_err.h>
+#include <unistd.h>
#include "col.h"
-#include "util.h"
#include "directories.h"
#include "pattern.h"
#include "lsdel.h"
@@ -29,16 +25,19 @@
#include "mit-copying.h"
#include "delete_errs.h"
#include "errors.h"
+#include "util.h"
+static void usage(void);
+static int ls(char **args, int num), process_files(char **files, int num);
+static int list_files(void), unique(char ***the_files, int *number);
+
extern time_t current_time;
int space_total = 0;
int dirsonly, recursive, yield, f_links, f_mounts, singlecolumn;
time_t timev;
-main(argc, argv)
-int argc;
-char *argv[];
+int main(int argc, char *argv[])
{
extern char *optarg;
extern int optind;
@@ -115,7 +114,7 @@
-usage()
+static void usage()
{
fprintf(stderr, "Usage: %s [ options ] [ filename [ ...]]\n", whoami);
fprintf(stderr, "Options are:\n");
@@ -133,9 +132,7 @@
-ls(args, num)
-char **args;
-int num;
+static int ls(char **args, int num)
{
char **found_files;
int num_found = 0, total = 0;
@@ -148,18 +145,18 @@
initialize_del_error_table();
#endif
- if (retval = initialize_tree()) {
+ if ((retval = initialize_tree())) {
error("initialize_tree");
return retval;
}
for ( ; num; num--) {
- if (retval = get_the_files(args[num - 1], &num_found,
- &found_files)) {
- error(args[num - 1]);
- status = retval;
- continue;
- }
+ if ((retval = get_the_files(args[num - 1], &num_found,
+ &found_files))) {
+ error(args[num - 1]);
+ status = retval;
+ continue;
+ }
if (num_found) {
num_found = process_files(found_files, num_found);
@@ -249,9 +246,7 @@
-process_files(files, num)
-char **files;
-int num;
+static int process_files(char **files, int num)
{
int i, skipped = 0;
filerec *leaf;
@@ -282,7 +277,7 @@
return(strcmp(*(char **) arg1, *(char **) arg2));
}
-list_files()
+static int list_files(void)
{
filerec *current;
char **strings;
@@ -297,25 +292,25 @@
return error_code;
}
current = get_root_tree();
- if (retval = accumulate_names(current, &strings, &num)) {
+ if ((retval = accumulate_names(current, &strings, &num))) {
error("accumulate_names");
return retval;
}
current = get_cwd_tree();
- if (retval = accumulate_names(current, &strings, &num)) {
+ if ((retval = accumulate_names(current, &strings, &num))) {
error("accumulate_names");
return retval;
}
qsort(strings, num, sizeof(char *), alphacmp);
- if (retval = unique(&strings, &num)) {
+ if ((retval = unique(&strings, &num))) {
error("unique");
return retval;
}
- if (retval = column_array(strings, num, DEF_SCR_WIDTH, 0, singlecolumn,
- 2, 1, 0, 1, stdout)) {
+ if ((retval = column_array(strings, num, DEF_SCR_WIDTH, 0, singlecolumn,
+ 2, 1, 0, 1, stdout))) {
error("column_array");
return retval;
}
@@ -327,9 +322,7 @@
}
-int unique(the_files, number)
-char ***the_files;
-int *number;
+static int unique(char ***the_files, int *number)
{
int i, last;
int offset;
Modified: trunk/athena/bin/delete/man1/delete.1
===================================================================
--- trunk/athena/bin/delete/man1/delete.1 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/man1/delete.1 2010-11-22 17:07:55 UTC (rev 24908)
@@ -87,7 +87,9 @@
.B \-f
Prevents
.I delete
-from asking any questions and from reporting any errors.
+from asking any questions and from reporting any errors about
+nonexistent files. However, as with rm, other errors (e.g.,
+permissions issues) are reported.
.TP
.B \-n
No file removals are performed. Instead,
Modified: trunk/athena/bin/delete/pattern.c
===================================================================
--- trunk/athena/bin/delete/pattern.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/pattern.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,10 +9,6 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if (!defined(lint) && !defined(SABER))
- static char rcsid_pattern_c[] = "$Id: pattern.c,v 1.28 1999-01-22 23:09:03 ghudson Exp $";
-#endif
-
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
@@ -21,7 +17,6 @@
#include <errno.h>
#include <com_err.h>
#include "pattern.h"
-#include "util.h"
#include "directories.h"
#include "undelete.h"
#include "shell_regexp.h"
@@ -29,10 +24,13 @@
#include "delete_errs.h"
#include "errors.h"
#include "stack.h"
+#include "util.h"
extern char *whoami;
-void free_list();
+static int do_match(char *name, int *num_found, char ***found,
+ Boolean match_undeleted, Boolean match_deleted);
+static int do_recurs(char *name, int *num_found, char ***found, int options);
/*
@@ -81,10 +79,7 @@
/*
* Add a string to a list of strings.
*/
-int add_str(strs, num, size, str)
-char ***strs;
-int num, *size;
-char *str;
+int add_str(char ***strs, int num, int *size, char *str)
{
char **ary;
@@ -416,11 +411,8 @@
* restore dirp from stack
* goto loop
*/
-int do_match(name, num_found, found, match_undeleted, match_deleted)
-char *name;
-int *num_found;
-char ***found;
-Boolean match_undeleted, match_deleted;
+static int do_match(char *name, int *num_found, char ***found,
+ Boolean match_undeleted, Boolean match_deleted)
{
char base[MAXPATHLEN];
struct dirent *dp;
@@ -760,11 +752,7 @@
* restore dirp from stack
* goto loop
*/
-int do_recurs(name, num_found, found, options)
-char *name;
-int *num_found;
-char ***found;
-int options;
+static int do_recurs(char *name, int *num_found, char ***found, int options)
{
char base[MAXPATHLEN];
struct dirent *dp;
@@ -1001,9 +989,7 @@
}
-void free_list(list, num)
-char **list;
-int num;
+void free_list(char **list, int num)
{
int i;
@@ -1023,8 +1009,7 @@
* means no non-quoted question marks, asterisks, or open square
* braces. Assumes a null-terminated string, and a valid globbing
*/
-int no_wildcards(name)
-char *name;
+int no_wildcards(char *name)
{
do {
switch (*name) {
Modified: trunk/athena/bin/delete/pattern.h
===================================================================
--- trunk/athena/bin/delete/pattern.h 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/pattern.h 2010-11-22 17:07:55 UTC (rev 24908)
@@ -20,6 +20,8 @@
int find_deleted_matches();
int find_recurses();
int find_deleted_recurses();
+void free_list(char **list, int num);
+int no_wildcards (char *name);
#define FIND_DELETED (1<<0)
#define FIND_UNDELETED (1<<1)
Modified: trunk/athena/bin/delete/shell_regexp.c
===================================================================
--- trunk/athena/bin/delete/shell_regexp.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/shell_regexp.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,15 +9,12 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if (!defined(lint) && !defined(SABER))
- static char rcsid_shell_regexp_c[] = "$Id: shell_regexp.c,v 1.4 1999-01-22 23:09:04 ghudson Exp $";
-#endif
-
#include <com_err.h>
#include "shell_regexp.h"
#include "delete_errs.h"
#include "errors.h"
#include "mit-copying.h"
+#include "util.h"
static int real_cmp();
Modified: trunk/athena/bin/delete/stack.c
===================================================================
--- trunk/athena/bin/delete/stack.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/stack.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,10 +9,6 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if (!defined(lint) && !defined(SABER))
- static char rcsid_stack_c[] = "$Id: stack.c,v 1.13 1999-01-22 23:09:06 ghudson Exp $";
-#endif
-
#include <string.h>
#include <sys/types.h>
#include <stdio.h>
@@ -27,9 +23,7 @@
-int dostack(data, op, bytes)
-caddr_t data;
-int op, bytes;
+int dostack(caddr_t data, int op, int bytes)
{
static caddr_t stack = (caddr_t) NULL;
static int size = 0, count = 0;
Modified: trunk/athena/bin/delete/stack.h
===================================================================
--- trunk/athena/bin/delete/stack.h 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/stack.h 2010-11-22 17:07:55 UTC (rev 24908)
@@ -14,6 +14,8 @@
#define STACK_POP 1
#define EMPTY_STACK 2
+int dostack(caddr_t data, int op, int bytes);
+
#define push(data, size) dostack((caddr_t) data, STACK_PUSH, size)
#define pop(data, size) dostack((caddr_t) data, STACK_POP, size)
#define popall() dostack((caddr_t) NULL, EMPTY_STACK, 0)
Modified: trunk/athena/bin/delete/undelete.c
===================================================================
--- trunk/athena/bin/delete/undelete.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/undelete.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,10 +9,6 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if (!defined(lint) && !defined(SABER))
- static char rcsid_undelete_c[] = "$Id: undelete.c,v 1.30 2002-11-20 19:09:24 zacheiss Exp $";
-#endif
-
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
@@ -20,21 +16,29 @@
#include <string.h>
#include <com_err.h>
#include <errno.h>
+#include <unistd.h>
#include "delete_errs.h"
#include "pattern.h"
-#include "util.h"
#include "directories.h"
#include "undelete.h"
#include "shell_regexp.h"
#include "mit-copying.h"
#include "errors.h"
+#include "util.h"
+static void usage(void);
+static int interactive_mode(void), undelete(char *name);
+static int recurs_and_undelete(filerec *leaf), do_undelete(filerec *file_ent);
+static int do_file_rename(char *real_name, char *user_name);
+static int process_files(char **files, int num);
+static int unlink_completely(char *filename);
+static int filecmp(const void *arg1, const void *arg2);
+static int choose_better(char *str1, char *str2);
+
int interactive, recursive, verbose, directoriesonly, noop, force;
-main(argc, argv)
-int argc;
-char *argv[];
+int main(int argc, char *argv[])
{
extern char *optarg;
extern int optind;
@@ -105,7 +109,7 @@
-interactive_mode()
+static int interactive_mode(void)
{
char buf[MAXPATHLEN];
char *ptr;
@@ -139,7 +143,7 @@
-usage()
+static void usage()
{
fprintf(stderr, "Usage: %s [ options ] [filename ...]\n", whoami);
fprintf(stderr, "Options are:\n");
@@ -153,8 +157,7 @@
fprintf(stderr, "-r and -D are mutually exclusive\n");
}
-undelete(name)
-char *name;
+static int undelete(char *name)
{
char **found_files;
int num_found;
@@ -162,26 +165,26 @@
filerec *current;
int retval;
- if (retval = get_the_files(name, &num_found, &found_files)) {
+ if ((retval = get_the_files(name, &num_found, &found_files))) {
error(name);
return retval;
}
if (num_found) {
- if (retval = process_files(found_files, num_found)) {
- error(name);
- return retval;
- }
- if (*name == '/')
- current = get_root_tree();
- else
- current = get_cwd_tree();
+ if ((retval = process_files(found_files, num_found))) {
+ error(name);
+ return retval;
+ }
+ if (*name == '/')
+ current = get_root_tree();
+ else
+ current = get_cwd_tree();
- status = recurs_and_undelete(current);
- if (status) {
- error(name);
- return status;
- }
+ status = recurs_and_undelete(current);
+ if (status) {
+ error(name);
+ return status;
+ }
}
else {
if (no_wildcards(name)) {
@@ -200,8 +203,7 @@
-int recurs_and_undelete(leaf)
-filerec *leaf;
+static int recurs_and_undelete(filerec *leaf)
{
int status = 0;
int retval;
@@ -251,9 +253,7 @@
-int process_files(files, num)
-char **files;
-int num;
+static int process_files(char **files, int num)
{
int i;
listrec *filelist;
@@ -287,28 +287,28 @@
}
free((char *) files);
- if (retval = sort_files(filelist, num)) {
+ if ((retval = sort_files(filelist, num))) {
error("sort_files");
return retval;
}
- if (retval = unique(&filelist, &num)) {
+ if ((retval = unique(&filelist, &num))) {
error("unique");
return retval;
}
- if (retval = initialize_tree()) {
+ if ((retval = initialize_tree())) {
error("initialize_tree");
return retval;
}
for (i = 0; i < num; i++) {
- if (retval = add_path_to_tree(filelist[i].real_name, ¬_needed)) {
- error("add_path_to_tree");
- return retval;
- }
- else {
- free(filelist[i].real_name);
- free(filelist[i].user_name);
- }
+ if ((retval = add_path_to_tree(filelist[i].real_name, ¬_needed))) {
+ error("add_path_to_tree");
+ return retval;
+ }
+ else {
+ free(filelist[i].real_name);
+ free(filelist[i].user_name);
+ }
}
free((char *) filelist);
return 0;
@@ -321,14 +321,13 @@
-do_undelete(file_ent)
-filerec *file_ent;
+static int do_undelete(filerec *file_ent)
{
struct stat stat_buf;
char user_name[MAXPATHLEN], real_name[MAXPATHLEN];
int retval;
- if (retval = get_leaf_path(file_ent, real_name)) {
+ if ((retval = get_leaf_path(file_ent, real_name))) {
if (! force)
fprintf(stderr, "%s: %s: %s\n", whoami, "get_leaf_path",
error_message(retval));
@@ -354,7 +353,7 @@
set_status(UNDEL_NOT_UNDELETED);
return error_code;
}
- if (! noop) if (retval = unlink_completely(user_name)) {
+ if ((! noop) && (retval = unlink_completely(user_name))) {
error(user_name);
return retval;
}
@@ -364,7 +363,7 @@
return 0;
}
- if (retval = do_file_rename(real_name, user_name)) {
+ if ((retval = do_file_rename(real_name, user_name))) {
error("do_file_rename");
return retval;
}
@@ -378,8 +377,7 @@
-do_file_rename(real_name, user_name)
-char *real_name, *user_name;
+static int do_file_rename(char *real_name, char *user_name)
{
char *ptr;
int retval;
@@ -406,7 +404,7 @@
*--ptr = '\0';
old_name[ptr - new_name] = '\0';
}
- if (retval = change_path(real_name, user_name)) {
+ if ((retval = change_path(real_name, user_name))) {
error("change_path");
return retval;
}
@@ -419,8 +417,7 @@
-filecmp(arg1, arg2)
-const void *arg1, *arg2;
+static int filecmp(const void *arg1, const void *arg2)
{
listrec *file1 = (listrec *) arg1, *file2 = (listrec *) arg2;
@@ -496,8 +493,7 @@
-choose_better(str1, str2)
-char *str1, *str2;
+static int choose_better(char *str1, char *str2)
{
char *pos1, *pos2;
@@ -521,8 +517,7 @@
-unlink_completely(filename)
-char *filename;
+static int unlink_completely(char *filename)
{
char buf[MAXPATHLEN];
struct stat stat_buf;
@@ -549,19 +544,19 @@
if (is_dotfile(dp->d_name))
continue;
(void) strcpy(buf, append(filename, dp->d_name));
- if (retval = unlink_completely(buf)) {
+ if ((retval = unlink_completely(buf))) {
error(buf);
status = retval;
}
}
closedir(dirp);
- if (retval = rmdir(filename)) {
+ if ((retval = rmdir(filename))) {
set_error(errno);
error(filename);
return error_code;
}
}
- else if (retval = unlink(filename)) {
+ else if ((retval = unlink(filename))) {
set_error(errno);
error(filename);
return error_code;
Modified: trunk/athena/bin/delete/util.c
===================================================================
--- trunk/athena/bin/delete/util.c 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/util.c 2010-11-22 17:07:55 UTC (rev 24908)
@@ -9,10 +9,6 @@
* For copying and distribution information, see the file "mit-copying.h."
*/
-#if (!defined(lint) && !defined(SABER))
- static char rcsid_util_c[] = "$Id: util.c,v 1.33 2002-11-20 19:09:24 zacheiss Exp $";
-#endif
-
#include <stdio.h>
#include <sys/param.h>
#include <sys/types.h>
@@ -20,6 +16,8 @@
#include <string.h>
#include <pwd.h>
#include <errno.h>
+#include <ctype.h>
+#include <unistd.h>
#ifdef HAVE_AFS
#include <sys/ioctl.h>
#include <rx/rx.h>
@@ -29,10 +27,10 @@
#include <afs/venus.h>
#endif
#include "delete_errs.h"
-#include "util.h"
#include "directories.h"
#include "mit-copying.h"
#include "errors.h"
+#include "util.h"
char *convert_to_user_name(real_name, user_name)
char real_name[];
@@ -56,7 +54,7 @@
char *str, *sub_str;
{
char *ptr = str;
- while (ptr = strchr(ptr, *sub_str)) {
+ while ((ptr = strchr(ptr, *sub_str))) {
if (! strncmp(ptr, sub_str, strlen(sub_str)))
return(ptr);
ptr++;
@@ -121,7 +119,8 @@
-yes() {
+int yes()
+{
char buf[BUFSIZ];
char *val;
@@ -130,10 +129,14 @@
printf("\n");
exit(1);
}
- if (! strchr(buf, '\n')) do
- (void) fgets(buf + 1, BUFSIZ - 1, stdin);
- while (! strchr(buf + 1, '\n'));
- return(*buf == 'y');
+ while (! strchr(buf, '\n')) {
+ val = fgets(buf + 1, BUFSIZ - 1, stdin);
+ if (! val) {
+ printf("\n");
+ exit(1);
+ }
+ }
+ return(tolower(*buf) == 'y');
}
@@ -188,8 +191,7 @@
-get_home(buf)
-char *buf;
+int get_home(char *buf)
{
char *user;
struct passwd *psw;
@@ -222,9 +224,7 @@
-timed_out(file_ent, current_time, min_days)
-filerec *file_ent;
-time_t current_time, min_days;
+int timed_out(filerec *file_ent, time_t current_time, time_t min_days)
{
if ((current_time - file_ent->specs.st_ctim) / 86400 >= min_days)
return(1);
@@ -234,8 +234,7 @@
-int directory_exists(dirname)
-char *dirname;
+int directory_exists(char *dirname)
{
struct stat stat_buf;
@@ -249,9 +248,7 @@
-is_link(name, oldbuf)
-char *name;
-struct stat *oldbuf;
+int is_link(char *name, struct stat *oldbuf)
{
#ifdef S_IFLNK
struct stat statbuf;
Modified: trunk/athena/bin/delete/util.h
===================================================================
--- trunk/athena/bin/delete/util.h 2010-11-15 23:18:45 UTC (rev 24907)
+++ trunk/athena/bin/delete/util.h 2010-11-22 17:07:55 UTC (rev 24908)
@@ -15,12 +15,15 @@
#define lstat stat
#endif
+#include "directories.h"
#include <stdlib.h>
char *append();
char *convert_to_user_name();
char *firstpart();
char *lastpart();
+int get_home(char *buf);
+int timed_out(filerec *file_ent, time_t current_time, time_t min_days);
char *strindex();
char *strrindex();
#ifdef MALLOC_DEBUG
@@ -29,8 +32,10 @@
#define Malloc(a) malloc(a)
#endif
-int is_mountpoint(), is_link();
+int is_mountpoint(), is_link(char *name, struct stat *oldbuf), yes(void);
+int directory_exists(char *dirname);
+
#define is_dotfile(A) ((*A == '.') && \
((*(A + 1) == '\0') || \
((*(A + 1) == '.') && \