| 1 | /* ----------------------------- MNI Header ----------------------------------- |
| 2 | @NAME : mincexpand |
| 3 | @INPUT : argc, argv - command line arguments |
| 4 | @OUTPUT : (none) |
| 5 | @RETURNS : status |
| 6 | @DESCRIPTION: Program to expand a compressed minc image volume, if necessary. |
| 7 | @METHOD : |
| 8 | @GLOBALS : |
| 9 | @CALLS : |
| 10 | @CREATED : January 20, 1995 (Peter Neelin) |
| 11 | @MODIFIED : |
| 12 | * $Log: mincexpand.c,v $ |
| 13 | * Revision 6.6 2008-01-17 02:33:02 rotor |
| 14 | * * removed all rcsids |
| 15 | * * removed a bunch of ^L's that somehow crept in |
| 16 | * * removed old (and outdated) BUGS file |
| 17 | * |
| 18 | * Revision 6.5 2008/01/12 19:08:15 stever |
| 19 | * Add __attribute__ ((unused)) to all rcsid variables. |
| 20 | * |
| 21 | * Revision 6.4 2006/05/19 00:35:58 bert |
| 22 | * Add config.h to several files that might need it |
| 23 | * |
| 24 | * Revision 6.3 2004/12/14 23:51:24 bert |
| 25 | * Get rid of compilation warning with c99 |
| 26 | * |
| 27 | * Revision 6.2 2004/11/01 22:38:38 bert |
| 28 | * Eliminate all references to minc_def.h |
| 29 | * |
| 30 | * Revision 6.1 1999/10/19 14:45:22 neelin |
| 31 | * Fixed Log subsitutions for CVS |
| 32 | * |
| 33 | * Revision 6.0 1997/09/12 13:24:16 neelin |
| 34 | * Release of minc version 0.6 |
| 35 | * |
| 36 | * Revision 5.0 1997/08/21 13:25:15 neelin |
| 37 | * Release of minc version 0.5 |
| 38 | * |
| 39 | * Revision 4.0 1997/05/07 20:02:02 neelin |
| 40 | * Release of minc version 0.4 |
| 41 | * |
| 42 | * Revision 3.0 1995/05/15 19:32:41 neelin |
| 43 | * Release of minc version 0.3 |
| 44 | * |
| 45 | * Revision 1.3 1995/01/24 09:06:19 neelin |
| 46 | * Added -name_only option. |
| 47 | * |
| 48 | * Revision 1.2 95/01/24 08:48:57 neelin |
| 49 | * Added optional output file argument. |
| 50 | * |
| 51 | * Revision 1.1 95/01/23 08:33:31 neelin |
| 52 | * Initial revision |
| 53 | * |
| 54 | * Revision 1.1 95/01/20 15:51:32 neelin |
| 55 | * Initial revision |
| 56 | * |
| 57 | @COPYRIGHT : |
| 58 | Copyright 1995 Peter Neelin, McConnell Brain Imaging Centre, |
| 59 | Montreal Neurological Institute, McGill University. |
| 60 | Permission to use, copy, modify, and distribute this |
| 61 | software and its documentation for any purpose and without |
| 62 | fee is hereby granted, provided that the above copyright |
| 63 | notice appear in all copies. The author and McGill University |
| 64 | make no representations about the suitability of this |
| 65 | software for any purpose. It is provided "as is" without |
| 66 | express or implied warranty. |
| 67 | ---------------------------------------------------------------------------- */ |
| 68 | |
| 69 | #if HAVE_CONFIG_H |
| 70 | #include "config.h" |
| 71 | #endif |
| 72 | |
| 73 | #define _GNU_SOURCE 1 |
| 74 | #include <stdlib.h> |
| 75 | #include <stdio.h> |
| 76 | #include <string.h> |
| 77 | #include <minc.h> |
| 78 | #include <ParseArgv.h> |
| 79 | |
| 80 | /* Constants */ |
| 81 | #ifndef TRUE |
| 82 | # define TRUE 1 |
| 83 | # define FALSE 0 |
| 84 | #endif |
| 85 | |
| 86 | /* Variables used for argument parsing */ |
| 87 | int header_only = FALSE; |
| 88 | int name_only = FALSE; |
| 89 | |
| 90 | /* Argument table */ |
| 91 | ArgvInfo argTable[] = { |
| 92 | {"-header_only", ARGV_CONSTANT, (char *) TRUE, (char *) &header_only, |
| 93 | "Expand only enough file to get the header."}, |
| 94 | {"-all_data", ARGV_CONSTANT, (char *) FALSE, (char *) &header_only, |
| 95 | "Expand the whole file (default)."}, |
| 96 | {"-name_only", ARGV_CONSTANT, (char *) TRUE, (char *) &name_only, |
| 97 | "Print out only the file name."}, |
| 98 | {NULL, ARGV_END, NULL, NULL, NULL} |
| 99 | }; |
| 100 | |
| 101 | /* Main program */ |
| 102 | |
| 103 | int main(int argc, char *argv[]) |
| 104 | { |
| 105 | char *filename, *tempfile, *newfile; |
| 106 | int created_tempfile; |
| 107 | |
| 108 | /* Check arguments */ |
| 109 | if (ParseArgv(&argc, argv, argTable, 0) || |
| 110 | (argc < 2) || (argc > 3)) { |
| 111 | (void) fprintf(stderr, |
| 112 | "\nUsage: %s [<options>] <infile> [<outfile>]\n", |
| 113 | argv[0]); |
| 114 | (void) fprintf(stderr, |
| 115 | " %s -help\n\n", argv[0]); |
| 116 | exit(EXIT_FAILURE); |
| 117 | } |
| 118 | filename = argv[1]; |
| 119 | if (argc == 3) |
| 120 | tempfile = argv[2]; |
| 121 | else |
| 122 | tempfile = NULL; |
| 123 | |
| 124 | /* Expand the file */ |
| 125 | ncopts = 0; |
| 126 | newfile = miexpand_file(filename, tempfile, header_only, &created_tempfile); |
| 127 | if (newfile == NULL) |
| 128 | newfile = strdup(filename); |
| 129 | |
| 130 | /* Print out file name and message about temporary file */ |
| 131 | (void) printf("%s\n", newfile); |
| 132 | if (!name_only) { |
| 133 | if (created_tempfile) { |
| 134 | (void) printf("Temporary\n"); |
| 135 | } |
| 136 | else { |
| 137 | (void) printf("Original\n"); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /* Free the temporary file name string */ |
| 142 | free(newfile); |
| 143 | |
| 144 | exit(EXIT_SUCCESS); |
| 145 | } |
| 146 |