changeset 2505:10b8b0dbca6a

* added outfile checks (with clobber) in minccalc
author rotor <rotor>
date Sat, 27 Mar 2010 15:24:03 +0000
parents 530f4a3b928d
children 26b834cf2953
files ChangeLog progs/minccalc/minccalc.c
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
    * shifted minchistory man to POD
    * conversion/vff2mnc/vff2mnc.c: added error checking for fgets
    * set default volume_io caching to none
+   * added checks for outfiles in minccalc
 
 2010-03-02  Andrew L Janke  <a.janke@gmail.com>
    * Added minccmp (minccmp.c and minccmp.man1)
--- a/progs/minccalc/minccalc.c
+++ b/progs/minccalc/minccalc.c
@@ -19,7 +19,10 @@
 This is predominately a rehash of mincmath by Peter Neelin
 
  * $Log: minccalc.c,v $
- * Revision 1.18  2008-01-17 02:33:02  rotor
+ * Revision 1.19  2010-03-27 15:24:03  rotor
+ *  * added outfile checks (with clobber) in minccalc
+ *
+ * Revision 1.18  2008/01/17 02:33:02  rotor
  *  * removed all rcsids
  *  * removed a bunch of ^L's that somehow crept in
  *  * removed old (and outdated) BUGS file
@@ -108,6 +111,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <unistd.h>
 #include <string.h>
 #include <ctype.h>
 #include <float.h>
@@ -291,11 +295,19 @@
       }
    }
 
+   /* check for output files */
+   for (i=0; i < nout; i++){
+      if(access(outfiles[i], F_OK) == 0 && !clobber){
+         fprintf(stderr, "%s: %s exists, use -clobber to overwrite\n\n",
+                 argv[0], outfiles[i]);
+         exit(EXIT_FAILURE);
+      }
+   }
+
    /* Get the list of input files either from the command line or
       from a file, or report an error if both are specified.
       Note that if -outfile is given then there is no output file name
       left on argv after option parsing. */
-
    nfiles = argc - 2;
    if (Output_list != NULL) nfiles++;
    if (filelist == NULL) {