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

📄 man2hlp.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 2 页
字号:
	} /* Has parameters */
    } /* Command .SH */
    else if (strcmp (buffer, ".\\\"DONT_SPLIT\"") == 0){
	no_split_flag = 1;
    }
    else if (strcmp (buffer, ".\\\"SKIP_SECTION\"") == 0){
	skip_flag = 1;
    }
    else if (strcmp (buffer, ".\\\"LINK\"") == 0){
	/* Next input line is a link */
	link_flag = 1;
    }
    else if (strcmp (buffer, ".\\\"LINK2\"") == 0){
	/* Next two input lines form a link */
	link_flag = 2;
    }
    else if (strcmp (buffer, ".PP") == 0){
	/* End of paragraph */
	if (width){
	    /* HLP format */
	    if (col > 0) newline();
	} else /* HTML format */
	    print_string ("<p>");
	newline ();
    }
    else if (strcmp (buffer, ".nf") == 0){
	/* Following input lines are to be handled verbatim */
	verbatim_flag = 1;
	if (width){
	    /* HLP format */
	    if (col > 0) newline ();
	} else {
	    /* HTML format */
	    print_string ("<pre>");
	    newline ();
	}
    }
    else if (strcmp (buffer, ".I") == 0 || strcmp (buffer, ".B") == 0){
	/* Bold text or italics text */
	char type = buffer [1];

	buffer = strtok (NULL, "");
	if (buffer == NULL){
	    print_error ("Syntax error: .I / .B: no text");
	    return;
	}
	else {
	    if (!width){
		/* HTML format */
		/* Remove quotes */
		if (buffer[0] == '"'){
		    buffer ++;
		    len = strlen (buffer);
		    if (buffer[len-1] == '"'){
			len --;
			buffer[len] = 0;
		    }
		}
		printf_string ("<%c>%s</%c>", type, buffer, type);
		newline ();
	    } else /* HLP format */
		printf_string ("%c%s%c",
		    (type == 'I') ? CHAR_ITALIC_ON : CHAR_BOLD_ON,
		    buffer, CHAR_BOLD_OFF);
	}
    }
    else if (strcmp (buffer, ".TP") == 0){
	/* End of paragraph? */
	if (width){
	    /* HLP format */
	    if (col > 0) newline ();
	} else {
	    /* HTML format */
	    print_string ("<p>");
	}
	newline ();
    }
    else {
	/* Other commands are ignored */
    }
}

void handle_link (char *buffer)
{
    static char old [80];
    int len;

    switch (link_flag){
    case 1:
	/* Old format link */
	if (width) /* HLP format */
	    printf_string ("%c%s%c%s%c\n", CHAR_LINK_START, buffer, CHAR_LINK_POINTER, buffer, CHAR_LINK_END);
	else {
	    /* HTML format */
	    printf_string ("<a href=\"#%s\">%s</a>", buffer, buffer);
	    newline ();
	}
	link_flag = 0;
	break;
    case 2:
	/* First part of new format link */
	strcpy (old, buffer);
	link_flag = 3;
	break;
    case 3:
	/* Second part of new format link */
	if (buffer [0] == '.')
	    buffer++;
	if (buffer [0] == '\\')
	    buffer++;
	if (buffer [0] == '"')
	    buffer++;
	len = strlen (buffer);
	if (len && buffer [len-1] == '"'){
	    buffer [--len] = 0;
	}
	if (width) /* HLP format */
	    printf_string ("%c%s%c%s%c\n", CHAR_LINK_START, old, CHAR_LINK_POINTER, buffer, CHAR_LINK_END);
	else {
	    /* HTML format */
	    printf_string ("<a href=\"#%s\">%s</a>", buffer, old);
	    newline ();
	}
	link_flag = 0;
	break;
    }
}

int main (int argc, char **argv)
{
    int len;			/* Length of input line */
    FILE *file;			/* Input file */
    char buffer2 [BUFFER_SIZE];	/* Temp input line */
    char buffer [BUFFER_SIZE];	/* Input line */
    int i, j;

    /* Validity check for arguments */
    if (argc != 3 || (strcmp (argv[1], "0") && (width = atoi (argv[1])) <= 10)){
	fprintf (stderr, "Usage: man2hlp <width> <file.man>\n");
	fprintf (stderr, "zero width will create a html file instead of a hlp file\n");
	return 3;
    }

    /* Open the input file */
    filename = argv[2];
    file = fopen (filename, "r");
    if (file == NULL){
	sprintf (buffer, "man2hlp: Can't open file \"%s\"", filename);
	perror (buffer);
	return 3;
    }

    if (!width){
	/* HTML format */
	index_file = fopen ("index.html", "w");
	if (index_file == NULL){
	    perror ("man2hlp: Can't open file \"index.html\"");
	    return 3;
	}
	fprintf (index_file, "<html><head><title>Midnight Commander manual</title>\n");
	fprintf (index_file, "</head><body><pre><img src=\"mc.logo.small.gif\" width=180 height=85 align=\"right\" alt=\""
		 "                                                                            \n"
		 "______________           ____                          ____                 \n"
		 "|////////////#           |//#                          |//#                 \n"
		 "|//##+//##+//#           |//#                          |//#                 \n"
		 "|//# |//# |//# ____      |//#           ____           |//#                 \n"
		 "|//# |//# |//# |//#      |//#           |//#           |//#                 \n"
		 "|//# |//# |//# +###      |//#           +###           |//#        ____     \n"
		 "|//# |//# |//# ____ _____|//# _________ ____ _________ |//#______ _|//#__   \n"
		 "|@@# |@@# |@/# |//# |///////# |///////# |//# |///////# |////////# |/////#   \n"
		 "|@@# |@@# |@@# |@/# |//##+//# |//##+//# |//# |//##+//# |//###+//# +#/@###   \n"
		 "|@@# |@@# |@@# |@@# |@@# |@@# |@/# |//# |//# |//# |/@# |@@#  |@@#  |@@# ____\n"
		 "|@@# |@@# |@@# |@@# |@@#_|@@# |@@# |@@# |@@# |@@#_|@@# |@@#  |@@#  |@@#_|@@#\n"
		 "|@@# |@@# |@@# |@@# |@@@@@@@# |@@# |@@# |@@# |@@@@@@@# |@@#  |@@#  |@@@@@@@#\n"
		 "+### +### +### +### +######## +### +### +### +####+@@# +###  +###  +########\n"
		 "           _______________________________________|@@#                      \n"
		 "           |@@@@@@@@@@@ C O M M A N D E R @@@@@@@@@@@#                      \n"
		 "           +##########################################                      \n"
		 "                                                                            \n"
		 "\"></pre><h1>Manual</h1>\nThis is the manual for Midnight Commander version %s.\n"
		 "This HTML version of the manual has been compiled from the NROFF version at %s.<p>\n",
		 VERSION, __DATE__);
	fprintf (index_file, "<hr><h2>Contents</h2><ul>\n");
    }

    /* Repeat for each input line */
    while (!feof (file)){
	/* Read a line */
	if (!fgets (buffer2, BUFFER_SIZE, file)){
	    break;
	}
	if (!width){
	    /* HTML format */
	    if (buffer2 [0] == '\\' && buffer2 [1] == '&')
		i = 2;
	    else
		i = 0;
	    for (j = 0; i < strlen (buffer2); i++, j++){
		if (buffer2 [i] == '<'){
		    buffer [j++] = '&';
		    buffer [j++] = 'l';
		    buffer [j++] = 't';
		    buffer [j] = ';';
		} else if (buffer2 [i] == '>'){
		    buffer [j++] = '&';
		    buffer [j++] = 'g';
		    buffer [j++] = 't';
		    buffer [j] = ';';
		} else
		    buffer [j] = buffer2 [i];
	    }
	    buffer [j] = 0;
	} else {
	    /* HLP format */
	    if (buffer2 [0] == '\\' && buffer2 [1] == '&')
		strcpy (buffer, buffer2 + 2);
	    else
		strcpy (buffer, buffer2);
	}
	in_row ++;
	len = strlen (buffer);
	/* Remove terminating newline */
	if (buffer [len-1] == '\n')
	{
	    len --;
	    buffer [len] = 0;
	}
	if (verbatim_flag){
	    /* Copy the line verbatim */
	    if (strcmp (buffer, ".fi") == 0){
		verbatim_flag = 0;
	        if (!width) print_string ("</pre>"); /* HTML format */
	    } else {
		print_string (buffer);
		newline ();
	    }
	}
	else if (link_flag)
	    /* The line is a link */
	    handle_link (buffer);
	else if (buffer[0] == '.')
	    /* The line is a roff command */
	    handle_command (buffer);
	else
	{
	    /* A normal line, just output it */
	    print_string (buffer);
	    if (!width)	newline (); /* HTML format */
	}
    }

    /* All done */
    newline ();
    if (!width){
	/* HTML format */
	print_string ("<hr></body></html>");
	newline ();
	for (i = 0; i < old_heading_level; i += 2)
	    fprintf (index_file, "</ul>");
	old_heading_level = 0;
	fprintf (index_file, "</ul><hr>\n");
	fclose (index_file);
    }
    fclose (file);
    return 0;
}

⌨️ 快捷键说明

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