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

📄 common.c

📁 代码检索工具GLOBAL源码。可用来浏览分析LINUX源码。
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2004, 2005 Tama Communications Corporation * * This file is part of GNU GLOBAL. * * GNU GLOBAL is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * GNU GLOBAL 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA. */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <stdio.h>#ifdef STDC_HEADERS#include <stdlib.h>#endif#ifdef HAVE_STRING_H#include <string.h>#else#include <strings.h>#endif#include <ctype.h>#include <sys/types.h>#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#ifdef HAVE_FCNTL_H#include <fcntl.h>#else#include <sys/file.h>#endif#include "global.h"#include "common.h"#include "path2url.h"#include "htags.h"/* * Tag definitions * * Htags generates HTML tag by default. */const char *html_begin		= "<html>";const char *html_end		= "</html>";const char *html_head_begin	= "<head>";const char *html_head_end	= "</head>";const char *html_title_begin	= "<title>";const char *html_title_end	= "</title>";const char *body_begin		= "<body>";const char *body_end		= "</body>";const char *title_begin		= "<h1><font color='#cc0000'>";const char *title_end		= "</font></h1>";const char *header_begin	= "<h2>";const char *header_end		= "</h2>";const char *cvslink_begin	= "<font size='-1'>";const char *cvslink_end		= "</font>";const char *caution_begin	= "<center>\n<blockquote>";const char *caution_end		= "</blockquote>\n</center>";const char *list_begin		= "<ol>";const char *list_end		= "</ol>";const char *item_begin		= "<li>";const char *item_end		= "";const char *define_list_begin	= "<dl>";const char *define_list_end	= "</dl>";const char *define_term_begin	= "<dt>";const char *define_term_end	= "";const char *define_desc_begin	= "<dd>";const char *define_desc_end	= "";const char *table_begin		= "<table>";const char *table_end		= "</table>";const char *comment_begin	= "<i><font color='green'>";const char *comment_end		= "</font></i>";const char *sharp_begin		= "<font color='darkred'>";const char *sharp_end		= "</font>";const char *brace_begin		= "<font color='blue'>";const char *brace_end		= "</font>";const char *verbatim_begin	= "<pre>";const char *verbatim_end	= "</pre>";const char *reserved_begin	= "<b>";const char *reserved_end	= "</b>";const char *position_begin	= "<font color='gray'>";const char *position_end	= "</font>";const char *warned_line_begin	= "<span style='background-color:yellow'>";const char *warned_line_end	= "</span>";const char *error_begin		= "<h1><font color='#cc0000'>";const char *error_end		= "</font></h1>";const char *message_begin	= "<h3>";const char *message_end		= "</h3>";const char *string_begin	= "<u>";const char *string_end		= "</u>";const char *quote_great		= "&gt;";const char *quote_little	= "&lt;";const char *quote_amp		= "&amp;";const char *quote_space		= "&nbsp;";const char *hr			= "<hr>";const char *br			= "<br>";const char *empty_element	= "";const char *noframes_begin	= "<noframes>";const char *noframes_end	= "</noframes>";/* * 1: Enforce XHTML1.0 strict or XHTML1.1. */static int strict_xhtml = 0;/* * print string and new line. * * This function is a replacement of fprintf(op, "%s\n", s) in htags. */intfputs_nl(s, op)	const char *s;	FILE *op;{	fputs(s, op);	putc('\n', op);	return 0;}/* * XHTML support. * * If the --xhtml option is specified, htags(1) generates XHTML output. * We define each style for the tags in 'style.css' in this directory. */voidsetup_xhtml(void){	if (!strcmp(xhtml_version, "1.1") && !Fflag)		strict_xhtml = 1;	html_begin		= "<html xmlns='http://www.w3.org/1999/xhtml'>";	html_end		= "</html>";	html_head_begin		= "<head>";	html_head_end		= "</head>";	html_title_begin	= "<title>";	html_title_end		= "</title>";	body_begin		= "<body>";	body_end		= "</body>";	title_begin		= "<h1 class='title'>";	title_end		= "</h1>";	header_begin		= "<h2 class='header'>";	header_end		= "</h2>";	cvslink_begin		= "<span class='cvs'>";	cvslink_end		= "</span>";	caution_begin		= "<div class='caution'>";	caution_end		= "</div>";	list_begin		= "<ol>";	list_end		= "</ol>";	item_begin		= "<li>";	item_end		= "</li>";	define_list_begin	= "<dl>";	define_list_end		= "</dl>";	define_term_begin	= "<dt>";	define_term_end		= "</dt>";	define_desc_begin	= "<dd>";	define_desc_end		= "</dd>";	table_begin		= "<table>";	table_end		= "</table>";	comment_begin		= "<em class='comment'>";	comment_end		= "</em>";	sharp_begin		= "<em class='sharp'>";	sharp_end		= "</em>";	brace_begin		= "<em class='brace'>";	brace_end		= "</em>";	verbatim_begin		= "<pre>";	verbatim_end		= "</pre>";	reserved_begin		= "<strong class='reserved'>";	reserved_end		= "</strong>";	position_begin		= "<em class='position'>";	position_end		= "</em>";	warned_line_begin	= "<em class='warned'>";	warned_line_end		= "</em>";	error_begin		= "<h2 class='error'>";	error_end		= "</h2>";	message_begin		= "<h3 class='message'>";	message_end		= "</h3>";	string_begin		= "<em class='string'>";	string_end		= "</em>";	quote_great		= "&gt;";	quote_little		= "&lt;";	quote_amp		= "&amp;";	quote_space		= "&nbsp;";	hr			= "<hr />";	br			= "<br />";	empty_element		= " /";	noframes_begin		= "<noframes>";	noframes_end		= "</noframes>";}/* * Generate upper directory. */const char *upperdir(dir)	const char *dir;{	STATIC_STRBUF(sb);	strbuf_clear(sb);	strbuf_sprintf(sb, "../%s", dir);	return strbuf_value(sb);}/* * Load text from file with replacing @PARENT_DIR@ macro. * Macro @PARENT_DIR@ is replaced with the parent directory * of the 'HTML' directory. */static const char *sed(ip, place)	FILE *ip;	int place;{	STATIC_STRBUF(sb);	const char *parent_dir = (place == SUBDIR) ? "../.." : "..";	int c, start_position = -1;	strbuf_clear(sb);	while ((c = fgetc(ip)) != EOF) {		strbuf_putc(sb, c);		if (c == '@') {			int curpos = strbuf_getlen(sb);			if (start_position == -1) {				start_position = curpos - 1;			} else {				if (!strncmp("@PARENT_DIR@",					strbuf_value(sb) + start_position,					curpos - start_position))				{					strbuf_setlen(sb, start_position);					strbuf_puts(sb, parent_dir);					start_position = -1;				} else {					start_position = curpos - 1;				}			}		} else if (!isalpha(c) && c != '_') {			if (start_position != -1)				start_position = -1;		}	}	return strbuf_value(sb);}/* * Generate custom header. */const char *gen_insert_header(place)	int place;{	static FILE *ip;	if (ip != NULL) {		rewind(ip);	} else {		ip = fopen(insert_header, "r");		if (ip == NULL)			die("cannot open include header file '%s'.", insert_header);	}	return sed(ip, place);}/* * Generate custom footer. */const char *gen_insert_footer(place)	int place;{	static FILE *ip;	if (ip != NULL) {		rewind(ip);	} else {		ip = fopen(insert_footer, "r");		if (ip == NULL)			die("cannot open include footer file '%s'.", insert_footer);	}	return sed(ip, place);}/* * Generate beginning of generic page * *	i)	title	title of this page *	i)	place	SUBDIR: this page is in sub directory *			TOPDIR: this page is in the top directory *	i)	use_frameset *			use frameset document type or not */static const char *gen_page_generic_begin(title, place, use_frameset)	const char *title;	int place;	int use_frameset;{	STATIC_STRBUF(sb);	const char *dir = (place == SUBDIR) ? "../" : "";	strbuf_clear(sb);	if (enable_xhtml) {		/*		 * Since some browser cannot treat "<?xml...>", we don't		 * write the declaration as long as XHTML1.1 is not required.		 */		if (strict_xhtml) {			strbuf_puts_nl(sb, "<?xml version='1.0' encoding='ISO-8859-1'?>");			strbuf_sprintf(sb, "<?xml-stylesheet type='text/css' href='%sstyle.css'?>\n", dir);		}		/*		 * If the --frame option are specified then we take		 * 'XHTML 1.0 Frameset' for index.html		 * and 'XHTML 1.0 Transitional' for other files,		 * else if the config variable 'xhtml_version' is		 * set to '1.1' then we take 'XHTML 1.1',		 * else 'XHTML 1.0 Transitional'.		 */		if (use_frameset)			strbuf_puts_nl(sb, "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Frameset//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd'>");		else if (!Fflag && strict_xhtml)			strbuf_puts_nl(sb, "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>");		else			strbuf_puts_nl(sb, "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");	}	strbuf_puts_nl(sb, html_begin);	strbuf_puts_nl(sb, html_head_begin);	strbuf_puts(sb, html_title_begin);	strbuf_puts(sb, title);	strbuf_puts_nl(sb, html_title_end);	strbuf_sprintf(sb, "<meta name='robots' content='noindex,nofollow'%s>\n", empty_element);	strbuf_sprintf(sb, "<meta name='generator' content='GLOBAL-%s'%s>\n", get_version(), empty_element);	if (enable_xhtml) {		strbuf_sprintf(sb, "<meta http-equiv='Content-Style-Type' content='text/css'%s>\n", empty_element);		strbuf_sprintf(sb, "<link rel='stylesheet' type='text/css' href='%sstyle.css'%s>\n", dir, empty_element);	}	if (style_sheet)		strbuf_puts(sb, style_sheet);	strbuf_puts(sb, html_head_end);	return strbuf_value(sb);}/* * Generate beginning of normal page * *	i)	title	title of this page *	i)	place	SUBDIR: this page is in sub directory *			TOPDIR: this page is in the top directory */const char *gen_page_begin(title, place)	const char *title;	int place;{	return gen_page_generic_begin(title, place, 0);}/* * Generate beginning of frameset page * *	i)	title	title of this page */const char *gen_page_frameset_begin(title)	const char *title;{	return gen_page_generic_begin(title, TOPDIR, 1);}/* * Generate end of page */const char *gen_page_end(void){	return html_end;}/* * Generate image tag. * *	i)	where	Where is the icon directory? *			CURRENT: current directory *			PARENT: parent directory *	i)	file	icon file without suffix. *	i)	alt	alt string */const char *gen_image(where, file, alt)	int where;	const char *file;	const char *alt;{	STATIC_STRBUF(sb);	const char *dir = (where == PARENT) ? "../icons" : "icons";	strbuf_clear(sb);	if (enable_xhtml)		strbuf_sprintf(sb, "<img class='icon' src='%s/%s.%s' alt='[%s]'%s>",			dir, file, icon_suffix, alt, empty_element);	else		strbuf_sprintf(sb, "<img src='%s/%s.%s' alt='[%s]' %s%s>",			dir, file, icon_suffix, alt, icon_spec, empty_element);	return strbuf_value(sb);}/* * Generate name tag. */const char *gen_name_number(number)	int number;{	static char buf[32];	snprintf(buf, sizeof(buf), "L%d", number);	return gen_name_string(buf);

⌨️ 快捷键说明

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