"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libutil/args.c" between
global-6.6.4.tar.gz and global-6.6.5.tar.gz

About: GNU GLOBAL is a source code tag system that works the same way across diverse environments. It is similar to ctags or etags, but it is independent of any editor.

args.c  (global-6.6.4):args.c  (global-6.6.5)
/* /*
* Copyright (c) 2010, 2014 Tama Communications Corporation * Copyright (c) 2010, 2014, 2020 Tama Communications Corporation
* *
* This file is part of GNU GLOBAL. * This file is part of GNU GLOBAL.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
skipping to change at line 25 skipping to change at line 25
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include "getopt.h"
#include "checkalloc.h" #include "checkalloc.h"
#include "die.h" #include "die.h"
#include "env.h" #include "env.h"
#include "locatestring.h" #include "locatestring.h"
#include "strbuf.h" #include "strbuf.h"
#include "test.h" #include "test.h"
#include "gpathop.h" #include "gpathop.h"
#include "args.h"
#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__) #if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
#include "path.h" #include "path.h"
#endif #endif
#define ARGS_NOP 0 #define ARGS_NOP 0
#define ARGS_ARGS 1 #define ARGS_ARGS 1
#define ARGS_FILELIST 2 #define ARGS_FILELIST 2
#define ARGS_GFIND 3 #define ARGS_GFIND 3
#define ARGS_BOTH 4 #define ARGS_BOTH 4
int type; static int type;
const char **argslist; static char *const *argslist;
FILE *ip; static FILE *ip;
GFIND *gp; static GFIND *gp;
/** /**
* args_open: * args_open:
* *
* @param[in] args args array * @param[in] args args array
*/ */
void void
args_open(const char **args) args_open(char *const *argv)
{ {
type = ARGS_ARGS; type = ARGS_ARGS;
argslist = args; argslist = argv;
} }
/** /**
* args_open_filelist: args_open like interface for handling output of find(1). * args_open_filelist: args_open like interface for handling output of find(1).
* *
* @param[in] filename file including list of file names. * @param[in] filename file including list of file names.
* When "-" is specified, read from standard input. * When "-" is specified, read from standard input.
*/ */
void void
args_open_filelist(const char *filename) args_open_filelist(const char *filename)
{ {
skipping to change at line 84 skipping to change at line 86
} }
} }
/** /**
* args_open_both: args_open like interface for argument and file list. * args_open_both: args_open like interface for argument and file list.
* *
* @param[in] args args array * @param[in] args args array
* @param[in] filename file including list of file names. * @param[in] filename file including list of file names.
* When "-" is specified, read from standard input. * When "-" is specified, read from standard input.
*/ */
void void
args_open_both(const char **args, const char *filename) args_open_both(char *const *argv, const char *filename)
{ {
type = ARGS_BOTH; type = ARGS_BOTH;
argslist = args; argslist = argv;
if (!strcmp(filename, "-")) { if (!strcmp(filename, "-")) {
ip = stdin; ip = stdin;
} else { } else {
ip = fopen(filename, "r"); ip = fopen(filename, "r");
if (ip == NULL) if (ip == NULL)
die("cannot open '%s'.", filename); die("cannot open '%s'.", filename);
} }
} }
/** /**
* args_open_gfind: args_open like interface for handling output of gfind. * args_open_gfind: args_open like interface for handling output of gfind.
skipping to change at line 179 skipping to change at line 181
default: default:
die("something wrong."); die("something wrong.");
} }
} }
/** /**
* preparse_options * preparse_options
* *
* @param[in] argc main()'s argc integer * @param[in] argc main()'s argc integer
* @param[in] argv main()'s argv string array * @param[in] argv main()'s argv string array
* *
* Setup the "GTAGSCONF" and the "GTAGSLABEL" environment variables * Setup the "GTAGSCONF" and "GTAGSLABEL" environment variables
* according to the --gtagsconf and --gtagslabel options. * according to the --gtagsconf and --gtagslabel options.
* Additionally changes directory acording to the --directory.
*/ */
void int
preparse_options(int argc, char *const *argv) preparse_options(int argc, char *const *argv)
{ {
int i; int optchar;
char *p; int option_index = 0;
char *confpath = NULL; char *confpath = NULL;
char *label = NULL; char *label = NULL;
const char *opt_gtagsconf = "--gtagsconf"; char *dir = NULL;
const char *opt_gtagslabel = "--gtagslabel"; extern const char *short_options;
extern struct option const long_options[];
for (i = 1; i < argc; i++) {
if ((p = locatestring(argv[i], opt_gtagsconf, MATCH_AT_FIRST))) { /*
if (*p == '\0') { * restart scanning of the same argv by setting optind = 1.
if (++i >= argc) */
die("%s needs an argument.", opt_gtagscon optind = 1;
f); while ((optchar = getopt_long(argc, argv, short_options, long_options, &o
confpath = argv[i]; ption_index)) != EOF) {
} else { switch (optchar) {
if (*p++ == '=' && *p) case 'C':
confpath = p; dir = optarg;
} break;
} else if ((p = locatestring(argv[i], opt_gtagslabel, MATCH_AT_FI case OPT_GTAGSCONF:
RST))) { confpath = optarg;
if (*p == '\0') { break;
if (++i >= argc) case OPT_GTAGSLABEL:
die("%s needs an argument.", opt_gtagslab label = optarg;
el); break;
label = argv[i]; case '?':
} else { return -1;
if (*p++ == '=' && *p) default:
label = p; break;
}
} }
} }
/*
* Change the directory before doing all the work including parameter ana
lysis.
*/
if (dir)
if (chdir(dir) < 0)
die("cannot change directory to '%s'.", dir);
if (confpath) { if (confpath) {
char real[MAXPATHLEN]; char real[MAXPATHLEN];
if (!test("f", confpath)) if (!test("f", confpath))
die("%s file not found.", opt_gtagsconf); die("--gtagsconf file not found.");
if (!realpath(confpath, real)) if (!realpath(confpath, real))
die("cannot get absolute path of %s file.", opt_gtagsconf ); die("cannot get absolute path of --gtagsconf file.");
set_env("GTAGSCONF", real); set_env("GTAGSCONF", real);
} }
if (label) if (label)
set_env("GTAGSLABEL", label); set_env("GTAGSLABEL", label);
/*
* restart scanning of the same argv by setting optind = 1.
* This is needed for the calling of getopt() in main().
*/
optind = 1;
return 0;
} }
/** /**
* prepend_options: creates a new argv main() array, by prepending (space separa ted) * prepend_options: creates a new argv main() array, by prepending (space separa ted)
* options and arguments from the string argument options. * options and arguments from the string argument options.
* *
* @param[in,out] argc pointer to main()'s argc integer * @param[in,out] argc pointer to main()'s argc integer
* @param[in] argv main()'s argv string array * @param[in] argv main()'s argv string array
* @param[in] options string * @param[in] options string
* @return The new argv array. * @return The new argv array.
* *
 End of changes. 17 change blocks. 
40 lines changed or deleted 55 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)