/* parse_argument.h */ /* remap Copyright (C) 2006 Fabrice Ducos, fabrice.ducos@icare.univ-lille1.fr 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 of the License, 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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef PARSE_ARGUMENT_H #define PARSE_ARGUMENT_H #include "grid.h" /** * parses a user argument in order to extract some useful values for a grid_type structure. * argv[iarg] must match the regular expression ^([^[@/]+)(\\[([0-9]+)\\])?(/[^@]+)?@(.*)$ * which means in clear one of the four alternatives : * - input_dataset\@input_file * - input_dataset[ichannel]\@input_file * - input_dataset/output_dataset\@input_file * - input_dataset[ichannel]/output_dataset\@input_file * * (with : ichannel an integer, input_dataset a char *, output_dataset a char *, and input_file a char *) * * * * @param iarg the index of the argument to parse (between 1 and argc - 1) * @param argv the list of the command arguments, from ::main * @param grid a pointer to a grid_type structure to update with infos found in the i-th argument * * @returns 0 on success, -1 on failure; the current implementation actually exits * in a brutal way when a invalid argument is found, simply sending an error message on the standard error as a side * effect. Indeed, an invalid argument was seen as a fatal error in the application context (no processing can be done), * so it was judged useless to continue. * * * The fields of grid_type updated by parse_argument include: * - grid_type::input_dataset * - grid_type::output_dataset (set to grid_type::input_dataset if not found in the regexp) * - grid_type::file * - grid_type::ichannel (set to 0 if not found in the regexp) * * @see ::tokenize (called by ::parse_argument) */ extern int parse_argument(int iarg, char *argv[], grid_type *grid); #endif