Index: gtags/gtags.c =================================================================== RCS file: /sources/global/global/gtags/gtags.c,v retrieving revision 1.259 diff -c -r1.259 gtags.c *** gtags/gtags.c 12 Dec 2013 21:52:03 -0000 1.259 --- gtags/gtags.c 4 Mar 2014 03:27:35 -0000 *************** *** 1,6 **** /* * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2008, ! * 2009, 2010, 2012 Tama Communications Corporation * * This file is part of GNU GLOBAL. * --- 1,7 ---- /* * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2008, ! * 2009, 2010, 2012, 2014 ! * Tama Communications Corporation * * This file is part of GNU GLOBAL. * *************** *** 346,353 **** --- 347,367 ---- dbop_close(dbop); exit(0); } else if (Iflag) { + #define REQUIRED_MKID_VERSION "4.5" + char *p; + if (!usable("mkid")) die("mkid not found."); + if (read_first_line("mkid --version", sb)) + die("mkid cannot executed."); + p = strrchr(strbuf_value(sb), ' '); + if (p == NULL) + die("illegal version string of mkid: %s", strbuf_value(sb)); + switch (check_version(p + 1, REQUIRED_MKID_VERSION)) { + case 1: break; /* OK */ + case 0: die("mkid version %s or later is required.", REQUIRED_MKID_VERSION); + default: die("illegal version string of mkid: %s", strbuf_value(sb)); + } } /* *************** *** 496,506 **** * create idutils index. */ if (Iflag) { tim = statistics_time_start("Time of creating ID"); if (vflag) fprintf(stderr, "[%s] Creating indexes for idutils.\n", now()); strbuf_reset(sb); ! strbuf_puts(sb, "mkid"); if (vflag) strbuf_puts(sb, " -v"); strbuf_sprintf(sb, " --file=%s/ID", quote_shell(dbpath)); --- 510,524 ---- * create idutils index. */ if (Iflag) { + FILE *op; + GFIND *gp; + char *path; + tim = statistics_time_start("Time of creating ID"); if (vflag) fprintf(stderr, "[%s] Creating indexes for idutils.\n", now()); strbuf_reset(sb); ! strbuf_puts(sb, "mkid --files0-from=-"); if (vflag) strbuf_puts(sb, " -v"); strbuf_sprintf(sb, " --file=%s/ID", quote_shell(dbpath)); *************** *** 511,523 **** strbuf_puts(sb, " 1>&2"); } else { strbuf_puts(sb, " >" NULL_DEVICE); } if (debug) fprintf(stderr, "executing mkid like: %s\n", strbuf_value(sb)); ! if (system(strbuf_value(sb))) ! die("mkid failed: %s", strbuf_value(sb)); ! if (chmod(makepath(dbpath, "ID", NULL), 0644) < 0) ! die("cannot chmod ID file."); statistics_time_end(tim); } if (vflag) --- 529,555 ---- strbuf_puts(sb, " 1>&2"); } else { strbuf_puts(sb, " >" NULL_DEVICE); + #ifdef __DJGPP__ + if (is_unixy()) /* test for 4DOS as well? */ + #endif + strbuf_puts(sb, " 2>&1"); } if (debug) fprintf(stderr, "executing mkid like: %s\n", strbuf_value(sb)); ! op = popen(strbuf_value(sb), "w"); ! if (op == NULL) ! die("popen failed."); ! gp = gfind_open(dbpath, NULL, GPATH_BOTH); ! while ((path = gfind_read(gp)) != NULL) { ! fputs(path, op); ! fputc('\0', op); ! } ! gfind_close(gp); ! if (pclose(op) != 0) ! die("terminated abnormally. '%s'", strbuf_value(sb)); ! if (test("f", makepath(dbpath, "ID", NULL))) ! if (chmod(makepath(dbpath, "ID", NULL), 0644) < 0) ! die("cannot chmod ID file."); statistics_time_end(tim); } if (vflag) Index: libutil/fileop.c =================================================================== RCS file: /sources/global/global/libutil/fileop.c,v retrieving revision 1.9 diff -c -r1.9 fileop.c *** libutil/fileop.c 22 Jan 2014 04:21:58 -0000 1.9 --- libutil/fileop.c 4 Mar 2014 03:27:35 -0000 *************** *** 1,5 **** /* ! * Copyright (c) 2006, 2013 * Tama Communications Corporation * * This file is part of GNU GLOBAL. --- 1,5 ---- /* ! * Copyright (c) 2006, 2013, 2014 * Tama Communications Corporation * * This file is part of GNU GLOBAL. *************** *** 45,50 **** --- 45,51 ---- #include "die.h" #include "fileop.h" #include "makepath.h" + #include "strbuf.h" #include "strlimcpy.h" #include "test.h" *************** *** 250,252 **** --- 251,272 ---- } (void)closedir(dirp); } + /** + * read the first line of command's output + * + * @param[in] com command line + * @param[in] sb string buffer + * @return 0: normal, -1: error + */ + int + read_first_line(const char *com, STRBUF *sb) + { + FILE *ip = popen(com, "r"); + char *p; + + if (ip == NULL) + return -1; + p = strbuf_fgets(sb, ip, STRBUF_NOCRLF); + pclose(ip); + return (p == NULL) ? -1 : 0; + } Index: libutil/fileop.h =================================================================== RCS file: /sources/global/global/libutil/fileop.h,v retrieving revision 1.4 diff -c -r1.4 fileop.h *** libutil/fileop.h 18 Nov 2013 01:14:50 -0000 1.4 --- libutil/fileop.h 4 Mar 2014 03:27:35 -0000 *************** *** 1,5 **** /* ! * Copyright (c) 2006, 2013 * Tama Communications Corporation * * This file is part of GNU GLOBAL. --- 1,5 ---- /* ! * Copyright (c) 2006, 2013, 2014 * Tama Communications Corporation * * This file is part of GNU GLOBAL. *************** *** 26,31 **** --- 26,32 ---- #include #include "gparam.h" + #include "strbuf.h" #define FILEOP_INPUT 1 #define FILEOP_OUTPUT 2 *************** *** 44,48 **** --- 45,50 ---- void close_file(FILEOP *); void copyfile(const char *, const char *); void copydirectory(const char *, const char *); + int read_first_line(const char *, STRBUF *); #endif /* ! _FILEOP_H */ Index: libutil/usable.c =================================================================== RCS file: /sources/global/global/libutil/usable.c,v retrieving revision 1.19 diff -c -r1.19 usable.c *** libutil/usable.c 13 Oct 2012 07:01:39 -0000 1.19 --- libutil/usable.c 4 Mar 2014 03:27:35 -0000 *************** *** 1,5 **** /* ! * Copyright (c) 1998, 1999, 2000, 2002 * Tama Communications Corporation * * This file is part of GNU GLOBAL. --- 1,5 ---- /* ! * Copyright (c) 1998, 1999, 2000, 2002, 2014 * Tama Communications Corporation * * This file is part of GNU GLOBAL. *************** *** 107,109 **** --- 107,147 ---- strbuf_close(sb); return *path ? path : NULL; } + /** + * version_check: check if the version meets condition + * + * @param[in] target_version + * @param[in] required_version + * @return -1: error
+ * 0: does not meet the requirement
+ * 1: meets the requirement + */ + int + check_version(const char *target_version, const char *required_version) + { + int result = 0; + const char *tp = target_version; + const char *rp = required_version; + + while (tp && rp) { + if (!isdigit(*tp) || !isdigit(*rp)) + return -1; + result = atoi(tp) - atoi(rp); + if (result < 0) + return 0; + else if (result > 0) + return 1; + else { + if ((tp = strchr(tp, '.')) != 0) + tp++; + if ((rp = strchr(rp, '.')) != 0) + rp++; + } + } + if (tp == 0 && rp == 0) + return 1; + else if (rp == 0) + return 1; + else + return 0; + } Index: libutil/usable.h =================================================================== RCS file: /sources/global/global/libutil/usable.h,v retrieving revision 1.8 diff -c -r1.8 usable.h *** libutil/usable.h 5 Jul 2007 06:52:05 -0000 1.8 --- libutil/usable.h 4 Mar 2014 03:27:35 -0000 *************** *** 1,5 **** /* ! * Copyright (c) 1998, 1999, 2000 * Tama Communications Corporation * * This file is part of GNU GLOBAL. --- 1,5 ---- /* ! * Copyright (c) 1998, 1999, 2000, 2014 * Tama Communications Corporation * * This file is part of GNU GLOBAL. *************** *** 22,26 **** --- 22,27 ---- #define _USABLE_H_ char *usable(const char *); + int check_version(const char *, const char *); #endif /* ! _USABLE_H_ */