r63: Removed unused bspline option
[ctsim.git] / src / sdf-2.c
index 3a1843848bae049e4cb199570fcbf4393163ef52..57a8469f739cf2fb0b6429f279b0dadc240cb82b 100644 (file)
@@ -2,10 +2,23 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: sdf-2.c,v 1.1 2000/04/28 13:02:44 kevin Exp $
+**  $Id: sdf-2.c,v 1.5 2000/05/24 22:50:04 kevin Exp $
 **  $Log: sdf-2.c,v $
-**  Revision 1.1  2000/04/28 13:02:44  kevin
-**  Initial revision
+**  Revision 1.5  2000/05/24 22:50:04  kevin
+**  Added support for new SGP library
+**
+**  Revision 1.4  2000/05/16 04:33:59  kevin
+**  Improved option processing
+**
+**  Revision 1.3  2000/05/11 01:06:30  kevin
+**  Changed sprintf to snprintf
+**
+**  Revision 1.2  2000/05/08 20:02:32  kevin
+**  ANSI C changes
+**
+**  Revision 1.1.1.1  2000/04/28 13:02:44  kevin
+**  Initial CVS import for first public release
+**
 **
 **
 **  This program is free software; you can redistribute it and/or modify
 **  along with this program; if not, write to the Free Software
 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ******************************************************************************/
+
 /* FILE
  *   sdf-2.c         Generate a SDF file from two input SDF files
  */
 
 #include "ct.h"
 
-#define O_ADD      1
-#define O_SUB      2
-#define O_MUL      3
-#define O_COMP     4
-#define O_VERBOSE  7
-#define O_HELP     8
-#define O_VERSION  9
+enum {O_ADD, O_SUB, O_MUL, O_COMP, O_VERBOSE, O_HELP, O_VERSION};
 
 static struct option my_options[] =
 {
@@ -48,9 +56,9 @@ static struct option my_options[] =
 };
 
 void 
-usage (const char *program)
+sdf2_usage (const char *program)
 {
-  fprintf(stdout, "usage: %s infile1 infile2 outfile [OPTIONS]\n", kbasename(program));
+  fprintf(stdout, "sdf2_usage: %s infile1 infile2 outfile [OPTIONS]\n", kbasename(program));
   fprintf(stdout, "Generate an SDF2D file from two input SDF2D files\n");
   fprintf(stdout, "\n");
   fprintf(stdout, "     infile1    Name of first input SDF file\n");
@@ -61,13 +69,12 @@ usage (const char *program)
   fprintf(stdout, "     --mul      Multiply images\n");
   fprintf(stdout, "     --comp     Compare images\n");
   fprintf(stdout, "     --verbose  Verbose modem\n");
-  fprintf(stdout,     --version  Print version\n");
+  fprintf(stdout, "     --version  Print version\n");
   fprintf(stdout, "     --help     Print this help message\n");
-  exit(1);
 }
 
 int 
-main (int argc, char *const argv[])
+sdf2_main (int argc, char *const argv[])
 {
   IMAGE *im_in1;
   IMAGE *im_in2;
@@ -114,18 +121,18 @@ main (int argc, char *const argv[])
          exit(0);
        case O_HELP:
        case '?':
-         usage(argv[0]);
-         exit(0);
+         sdf2_usage(argv[0]);
+         return (0);
        default:
-         usage(argv[0]);
-         exit(1);
+         sdf2_usage(argv[0]);
+         return (1);
        }
     }
 
   if (optind + 3 != argc)
     {
-      usage(argv[0]);
-      exit(1);
+      sdf2_usage(argv[0]);
+      return (1);
     }
   
   in_file1 = argv[optind];
@@ -134,11 +141,21 @@ main (int argc, char *const argv[])
 
   im_in1 = image_load (in_file1);
   im_in2 = image_load (in_file2);
+  if (im_in1 == NULL || im_in2 == NULL) {
+      fprintf(stderr, "Error reading an image");
+      return (1);
+  }
+
   if (im_in1->nx != im_in2->nx || im_in1->ny != im_in2->ny) {
-    fprintf(stderr, "Size of image 1 (%d,%d) and image 2 (%d,%d) do not match\n",
+    fprintf(stderr, "Error: Size of image 1 (%d,%d) and image 2 (%d,%d) do not match\n",
            im_in1->nx, im_in1->ny, im_in2->nx, im_in2->ny);
-    exit(1);
+    return(1);
   }
+  if (im_in1->nx < 0 || im_in1->ny < 0) {
+      fprintf(stderr, "Error: Size of image < 0");
+      return(1);
+  }
+
   im_out = image_create (out_file, im_in1->nx, im_in1->ny);
 
   if (opt_add) {
@@ -194,3 +211,12 @@ main (int argc, char *const argv[])
 
   return (0);
 }
+
+#ifndef NO_MAIN
+int 
+main (int argc, char *const argv[])
+{
+  return (sdf2_main(argc, argv));
+}
+#endif
+