/******************************************************************************* * Example source code for using the argtable3 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 argtable3 library. * * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of STEWART HEITMANN nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ #include "argtable3.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; }