⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htags.c

📁 代码检索工具GLOBAL源码。可用来浏览分析LINUX源码。
💻 C
📖 第 1 页 / 共 4 页
字号:
	/* 	 * insert htags_options at the head of argv.	 */	if (htags_options)		argv = append_options(&argc, argv);	while ((optchar = getopt_long(argc, argv, "acd:DfFgm:noqsS:t:vwx", long_options, &option_index)) != EOF) {		switch (optchar) {                case 0:                case 1:			if (!strcmp("action", long_options[option_index].name))                                action_value = optarg;			else if (!strcmp("nocgi", long_options[option_index].name))                                cgi = 0;			else if (!strcmp("id", long_options[option_index].name))                                id_value = optarg;			else if (!strcmp("cvsweb", long_options[option_index].name))                                cvsweb_url = optarg;			else if (!strcmp("cvsweb-cvsroot", long_options[option_index].name))                                cvsweb_cvsroot = optarg;			else if (!strcmp("gtagsconf", long_options[option_index].name))				;	/*  --gtagsconf is estimated only once. */			else if (!strcmp("gtagslabel", long_options[option_index].name))				;	/* --gtagslabel is estimated only once. */			else if (!strcmp("style-sheet", long_options[option_index].name))                                style_sheet = optarg;			else if (!strcmp("insert-header", long_options[option_index].name))				insert_header = optarg;			else if (!strcmp("insert-footer", long_options[option_index].name))				insert_footer = optarg;                        break;                case 'a':                        aflag++;                        break;                case 'c':                        cflag++;                        break;                case 'd':			strlimcpy(arg_dbpath, optarg, sizeof(arg_dbpath));                        break;                case 'D':			dynamic = 1;                        break;                case 'f':                        fflag++;                        break;                case 'F':                        Fflag++;                        break;                case 'm':			main_func = optarg;                        break;                case 'n':                        nflag++;                        break;                case 'g':                        gflag++;                        break;                case 'o':			other_files = 1;                        break;                case 's':			symbol = 1;                        break;                case 'S':			Sflag++;			cgidir = optarg;                        break;                case 't':			title = optarg;                        break;                case 'q':                        qflag++;                        break;                case 'v':                        vflag++;			setverbose();                        break;                case 'w':                        wflag++;                        break;		case 'x':			enable_xhtml = 1;                        break;                default:                        usage();                        break;		}	}	if (insert_header && !test("fr", insert_header))		die("page header file '%s' not found.", insert_header);	if (insert_footer && !test("fr", insert_footer))		die("page footer file '%s' not found.", insert_footer);	if (no_map_file)		map_file = 0;        argc -= optind;        argv += optind;        if (!av)                av = (argc > 0) ? *argv : NULL;	if (debug)		setdebug();        if (qflag) {                setquiet();		vflag = 0;	}	/*	 * If the --xhtml option is specified then all HTML tags which	 * are defined in configuration file are ignored. Instead, you can	 * customize XHTML tag using style sheet (See 'style.css').	 */	if (enable_xhtml)		setup_xhtml();	/*	 * If copy_files is true then htags copy tag files instead of linking.	 * Since Windows 32 environment doesn't have link system call	 * we set copy_files true.	 */	if (w32)		copy_files = 1;        if (show_version)                version(av, vflag);        if (show_help)                help();	if (gflag) {		STRBUF *sb = strbuf_open(0);		strbuf_puts(sb, gtags_path);		if (vflag)			strbuf_puts(sb, " -v");		if (wflag)			strbuf_puts(sb, " -w");		if (enable_idutils)			strbuf_puts(sb, " -I");		if (arg_dbpath[0]) {			strbuf_putc(sb, ' ');			strbuf_puts(sb, arg_dbpath);		}		if (system(strbuf_value(sb)))			die("cannot execute gtags(1) command.");		strbuf_close(sb);	}	/*	 * get dbpath.	 */	if (!getcwd(cwdpath, sizeof(cwdpath)))		die("cannot get current directory.");	if (arg_dbpath[0])		strlimcpy(dbpath, arg_dbpath, sizeof(dbpath));	else		strlimcpy(dbpath, cwdpath, sizeof(dbpath));	if (cflag && !usable("gzip")) {		warning("'gzip' command not found. -c option ignored.");		cflag = 0;	}	if (!title) {		char *p = strrchr(cwdpath, sep);		title = p ? p + 1 : cwdpath;	}	if (dynamic && Sflag)		die("Current implementation doesn't allow both -D(--dynamic) and the -S(--secure-cgi).");	if (style_sheet) {		char buf[MAXBUFLEN];		STRBUF *sb = strbuf_open(0);		FILE *ip = fopen(style_sheet, "r");		if (ip) {			while (fgets(buf, sizeof(buf), ip)) {				if (*buf != '\t' && *buf != '<')					strbuf_putc(sb, '\t');				strbuf_puts(sb, buf);			}			fclose(ip);		};		style_sheet = strbuf_value(sb);		/* Doesn't close string buffer. */	}	if (icon_list && !test("f", icon_list))		die("icon_list '%s' not found.", icon_list);	/*	 * decide directory in which we make hypertext.	 */	if (av) {		char realpath[MAXPATHLEN];		if (!test("dw", av))			die("'%s' is not writable directory.", av);		if (chdir(av) < 0)			die("directory '%s' not found.", av);		if (!getcwd(realpath, sizeof(realpath)))			die("cannot get current directory");		if (chdir(cwdpath) < 0)			die("cannot return to original directory.");		snprintf(distpath, sizeof(distpath), "%s/HTML", realpath);	} else {		snprintf(distpath, sizeof(distpath), "%s/HTML", cwdpath);	}	{		static char buf[MAXBUFLEN];		snprintf(buf, sizeof(buf), "%s/global.cgi", script_alias);		saction = buf;	}	if (Sflag) {		action = saction;		id = distpath;	}	/* --action, --id overwrite Sflag's value. */	if (action_value) {		action = action_value;	}	if (id_value) {		id = id_value;	}	if (!test("r", makepath(dbpath, dbname(GTAGS), NULL)) || !test("r", makepath(dbpath, dbname(GRTAGS), NULL)))		die("GTAGS and/or GRTAGS not found. Htags needs both of them.");	if (symbol && !test("r", makepath(dbpath, dbname(GSYMS), NULL)))		die("-s(--symbol) option needs GSYMS tag file.");	/*	 * make dbpath absolute.	 */	{		char buf[MAXPATHLEN];		if (realpath(dbpath, buf) == NULL)			die("cannot get realpath of dbpath.");		strlimcpy(dbpath, buf, sizeof(dbpath));	}	/*	 * for global(1) and gtags(1).	 */	set_env("GTAGSROOT", cwdpath);	set_env("GTAGSDBPATH", dbpath);	set_env("GTAGSLIBPATH", "");	/*	 * check directories	 */	if (fflag || cflag || dynamic) {		if (cgidir && !test("d", cgidir))			die("'%s' not found.", cgidir);		if (!Sflag) {			static char buf[MAXPATHLEN];			snprintf(buf, sizeof(buf), "%s/cgi-bin", distpath);			cgidir = buf;		}	} else {		Sflag = 0;		cgidir = 0;	}	/*------------------------------------------------------------------	 * MAKE FILES	 *------------------------------------------------------------------	 *       HTML/cgi-bin/global.cgi ... CGI program (1)	 *       HTML/cgi-bin/ghtml.cgi  ... unzip script (1)	 *       HTML/.htaccess          ... skeleton of .htaccess (1)	 *       HTML/help.html          ... help file (2)	 *       HTML/R/                 ... references (3)	 *       HTML/D/                 ... definitions (3)	 *       HTML/search.html        ... search index (4)	 *       HTML/defines.html       ... definitions index (5)	 *       HTML/defines/           ... definitions index (5)	 *       HTML/files/             ... file index (6)	 *       HTML/index.html         ... index file (7)	 *       HTML/mains.html         ... main index (8)	 *       HTML/null.html          ... main null html (8)	 *       HTML/S/                 ... source files (9)	 *       HTML/I/                 ... include file index (9)	 *       HTML/rebuild.sh         ... rebuild script (10)	 *       HTML/style.css          ... style sheet (11)	 *------------------------------------------------------------------	 */	/* for clean up */	signal_setup();	sethandler(clean);        HTML = (cflag) ? gzipped_suffix : normal_suffix;	message("[%s] Htags started", now());	start_all_time = time(NULL);	/*	 * (#) check if GTAGS, GRTAGS is the latest.	 */	if (!w32) {		/* UNDER CONSTRUCTION */	}	/*	 * (0) make directories	 */	message("[%s] (0) making directories ...", now());	{		int mode = 0775;		char *dirs[] = {"files", "defines", SRCS, DEFS, REFS, INCS, INCREFS, SYMS};		int i, lim = sizeof(dirs) / sizeof(char *);		if (!test("d", distpath)) {			if (mkdir(distpath, 0777) < 0)				die("cannot make directory '%s'.", distpath);		}		for (i = 0; i < lim; i++) {			char *p = dirs[i];			/*			 * dynamic mode doesn't require these directories.			 */			if (dynamic)				if (!strcmp(p, DEFS) || !strcmp(p, REFS) || !strcmp(p, SYMS))					continue;			if (!symbol)				if (!strcmp(p, SYMS))					continue;			path = makepath(distpath, p, NULL);			if (!test("d", path))				if (mkdir(path, mode))					die("cannot make '%s' directory.", p);		}		if (cgi && (fflag || cflag || dynamic)) {			path = makepath(distpath, "cgi-bin", NULL);			if (!test("d", path))				if (mkdir(path, mode) < 0)					die("cannot make cgi-bin directory.");		}	}	/*	 * (1) make CGI program	 */	if (cgi && (fflag || dynamic)) {		int i;		if (cgidir) {			message("[%s] (1) making CGI program ...", now());			makeprogram(cgidir, "global.cgi");			if (chmod(makepath(cgidir, "global.cgi", NULL), 0755) < 0)				die("cannot chmod CGI program.");		}		/*		 * Always make bless.sh.		 * Don't grant execute permission to bless script.		 */		makebless("bless.sh");		if (chmod(makepath(distpath, "bless.sh", NULL), 0640) < 0)			die("cannot chmod bless script.");		/*		 * replace G*** tag files.		 */		for (i = GPATH; i < GTAGLIM; i++) {			const char *name = dbname(i);			if (test("f", makepath(dbpath, name, NULL))) {				char path[MAXPATHLEN];				snprintf(path, sizeof(path), "%s/cgi-bin/%s", distpath, name);				unlink(path);				snprintf(path, sizeof(path), "%s/cgi-bin", distpath);				duplicatefile(name, dbpath, path);			}		}	} else {		message("[%s] (1) making CGI program ...(skipped)", now());	}	if (cgi && cflag) {		makehtaccess(".htaccess");		if (chmod(makepath(distpath, ".htaccess", NULL), 0644) < 0)			die("cannot chmod .htaccess skeleton.");		if (cgidir) {			makeghtml(cgidir, "ghtml.cgi");			if (chmod(makepath(cgidir, "ghtml.cgi", NULL), 0644) < 0)				die("cannot chmod unzip script.");		}	}	/*	 * (2) make help file	 */	message("[%s] (2) making help.html ...", now());	makehelp("help.html");	/*	 * (#) load GPATH	 */	load_gpath(dbpath);	/*	 * (3) make function entries (D/ and R/)	 *     MAKING TAG CACHE	 */	message("[%s] (3) making duplicate entries ...", now());	cache_open();	start_time = time(NULL);	func_total = makedupindex();	end_time = time(NULL);	message("Total %d functions.", func_total);	T_makedupindex = end_time - start_time;	/*	 * (4) search index. (search.html)	 */	if (Fflag && fflag) {		message("[%s] (4) making search index ...", now());		makesearchindex("search.html");	}	{		STRBUF *defines = strbuf_open(0);		STRBUF *files = strbuf_open(0);		/*		 * (5) make function index (defines.html and defines/)		 *     PRODUCE @defines		 */		message("[%s] (5) making function index ...", now());		start_time = time(NULL);		func_total = makedefineindex("defines.html", func_total, defines);		end_time = time(NULL);		message("Total %d functions.", func_total);		T_makedefineindex = end_time - start_time;		/*		 * (6) make file index (files.html and files/)		 *     PRODUCE @files, %includes		 */		message("[%s] (6) making file index ...", now());		init_inc();		start_time = time(NULL);		file_total = makefileindex("files.html", files);		end_time = time(NULL);		message("Total %d files.", file_total);		T_makefileindex = end_time - start_time;		file_count += file_total;		/*		 * [#] make include file index.		 */		message("[%s] (#) making include file index ...", now());		start_time = time(NULL);		makeincludeindex();		end_time = time(NULL);		T_makeincludeindex = end_time - start_time;		/*		 * [#] make a common part for mains.html and index.html		 *     USING @defines @files		 */		message("[%s] (#) making a common part ...", now());		index = makecommonpart(title, strbuf_value(defines), strbuf_value(files));		strbuf_close(defines);		strbuf_close(files);	}	/*	 * (7)make index file (index.html)	 */	message("[%s] (7) making index file ...", now());	makeindex("index.html", title, index);	/*	 * (8) make main index (mains.html)	 */	message("[%s] (8) making main index ...", now());	makemainindex("mains.html", index);	/*	 * (9) make HTML files (SRCS/)	 *     USING TAG CACHE, %includes and anchor database.	 */	message("[%s] (9) making hypertext from source code ...", now());	start_time = time(NULL);	makehtml(file_total);	end_time = time(NULL);	T_makehtml = end_time - start_time;	/*	 * (10) rebuild script. (rebuild.sh)	 *	 * Don't grant execute permission to rebuild script.	 */	makerebuild("rebuild.sh");	if (chmod(makepath(distpath, "rebuild.sh", NULL), 0640) < 0)		die("cannot chmod rebuild script.");	/*	 * (11) style sheet file (style.css)	 */	if (enable_xhtml) {		char src[MAXPATHLEN], dst[MAXPATHLEN];		snprintf(src, sizeof(src), "%s/gtags/style.css", datadir);		snprintf(dst, sizeof(dst), "%s/style.css", distpath);		copyfile(src, dst);	}	end_all_time = time(NULL);	message("[%s] Done.", now());	T_all = end_all_time - start_all_time;	if (vflag && cgi && (cflag || fflag)) {		message("\n[Information]\n");		if (cflag) {			message(" Your system may need to be setup to decompress *.%s files.", gzipped_suffix);			message(" This can be done by having your browser compiled with the relevant");			message(" options, or by configuring your http server to treat these as");			message(" gzipped files. (Please see 'HTML/.htaccess')\n");		}		if (fflag || dynamic) {			const char *path = (*action == '/') ? makepath("DOCUMENT_ROOT", action, NULL) : makepath("HTML", action, NULL);			message(" You need to setup http server so that %s", path);			message(" is executed as a CGI script. (DOCUMENT_ROOT means WWW server's data root.)\n");		}		message(" Good luck!\n");	}	/* This is not supported. */	if (icon_list && test("f", icon_list)) {		char command[MAXFILLEN];		snprintf(command, sizeof(command), "tar xzf %s -C %s", icon_list, distpath);		system(command);	}	/*	 * Print statistics information.	 */	if (statistics) {		setverbose();		message("- Elapsed time of making duplicate entries ............ %10ld seconds.", T_makedupindex);		message("- Elapsed time of making function index ............... %10ld seconds.", T_makedefineindex);		message("- Elapsed time of making file index ................... %10ld seconds.", T_makefileindex);		message("- Elapsed time of making include file index ........... %10ld seconds.", T_makeincludeindex);		message("- Elapsed time of making hypertext .................... %10ld seconds.", T_makehtml);		message("- The entire elapsed time ............................. %10ld seconds.", T_all);	}	clean();	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -