/*
 * ssrclean.c
 *
 * Delete lots of files (saves typing in Makefiles)
 *
 *  1998 Straylight/Edgeware
 */

/*----- Licensing note ----------------------------------------------------*
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, write to the Free Software Foundation,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/*----- Header files ------------------------------------------------------*/

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "swis.h"
#include "swiv.h"

#include "cmdr.h"

/*----- Install programs --------------------------------------------------*/

static int exitstat = 0;		/* Exit status */

/* -- @wipe@ --- *
 *
 * Arguments:	@const char *f@ = pointer to filename
 *
 * Returns:	---
 *
 * Use:		Expunges a file.
 */

static void wipe(const char *f)
{
  _kernel_oserror *e;

  e = _swix(OS_FSControl, _in(0) | _in(1) | _in(3), 27, f, 0);
  if (e) {
    fprintf(stderr, "ssrclean: error deleting `%s': %s\n",
            f, e->errmess);
    exitstat = 1;
  }
}

/* --- @main@ --- *
 *
 * Arguments:	@int argc@ = number of arguments
 *		@char *argv[]@ = list of arguments
 *
 * Returns:	Zero if all went well
 *
 * Use:		Deletes files.  This is an `rm' rip-off
 */

int main(int argc, char *argv[])
{
  int i;

  /* --- Expand wildcards in the arguments --- */

  cmdreplace(&argc, &argv);

  /* --- Report an error if there aren't enough arguments --- */

  if (argc < 2) {
    fprintf(stderr, "Usage: ssrclean FILE [FILE...]\n");
    exit(1);
  }

  /* --- Wipe things --- */

  for (i = 1; i < argc; i++)
    wipe(argv[i]);

  /* --- Done --- */

  return (exitstat);
}

/*----- That's all, folks -------------------------------------------------*/
