/********************************************************************* Example source code for using the argtable2 library to implement: mv [-bfiuv] [--backup=[CONTROL]] [--reply={yes,no,query}] [--strip-trailing-slashes] [-S SUFFIX] [--target-directory=DIRECTORY] [--help] [--version] SOURCE [SOURCE]... DEST|DIRECTORY This file is part of the argtable2 library. Copyright (C) 1998,1999,2000,2001,2003,2004,2005 Stewart Heitmann sheitmann@users.sourceforge.net The argtable2 library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This software 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. **********************************************************************/ #include "argtable2.h" int mymain(const char *backup_control, int backup, int force, int interactive, const char *reply, int strip_trailing_slashes, const char *suffix, const char *targetdir, int update, int verbose, const char **files, int nfiles) { int j; /* if verbose option was given then display all option settings */ if (verbose) { printf("backup = %s\n", ((backup)?"YES":"NO")); printf("backup CONTROL = %s\n", backup_control); printf("force = %s\n", ((force)?"YES":"NO")); printf("interactive mode = %s\n", ((interactive)?"YES":"NO")); printf("reply = %s\n", reply); printf("strip-trailing-slashes = %s\n", ((strip_trailing_slashes)?"YES":"NO")); printf("suffix = %s\n", suffix); printf("target-directory = %s\n", targetdir); printf("update = %s\n", ((update)?"YES":"NO")); printf("verbose = %s\n", ((verbose)?"YES":"NO")); } /* print the source filenames */ for (j=0; jsval[0] = "existing"; /* --backup={none,off,numbered,t,existing,nil,simple,never} */ suffix->sval[0] = "~"; /* --suffix=~ */ reply->sval[0] = "query"; /* --reply={yes,no,query} */ targetd->sval[0] = NULL; /* Parse the command line as defined by argtable[] */ nerrors = arg_parse(argc,argv,argtable); /* special case: '--help' takes precedence over error reporting */ if (help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout,argtable,"\n"); printf("Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n\n"); arg_print_glossary(stdout,argtable," %-30s %s\n"); printf("\nThe backup suffix is \"~\", unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n" "The version control method may be selected via the --backup option or through\n" "the VERSION_CONTROL environment variable. Here are the values:\n\n" " none, off never make backups (even if --backup is given)\n" " numbered, t make numbered backups\n" " existing, nil numbered if numbered backups exist, simple otherwise\n" " simple, never always make simple backups\n\n" "Report bugs to .\n"); exitcode=0; goto exit; } /* special case: '--version' takes precedence error reporting */ if (version->count > 0) { printf("'%s' example program for the \"argtable\" command line argument parser.\n",progname); printf("September 2003, Stewart Heitmann\n"); exitcode=0; goto exit; } /* If the parser returned any errors then display them and exit */ if (nerrors > 0) { /* Display the error details contained in the arg_end struct.*/ arg_print_errors(stdout,end,progname); printf("Try '%s --help' for more information.\n",progname); exitcode=1; goto exit; } /* Command line parsing is complete, do the main processing */ exitcode = mymain(backupc->sval[0], backup->count, force->count, interact->count, reply->sval[0], strpslsh->count, suffix->sval[0], targetd->sval[0], update->count, verbose->count, files->filename, files->count); exit: /* deallocate each non-null entry in argtable[] */ arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0])); return exitcode; }