Reacting on changes in the output of my local man -H

This commit is contained in:
Thomas Schmitt 2015-08-02 14:16:01 +00:00
parent c9fd4e22e5
commit e956594c0f
3 changed files with 141 additions and 14 deletions

View File

@ -1 +1 @@
#define Cdrskin_timestamP "2015.08.01.135727"
#define Cdrskin_timestamP "2015.08.02.141552"

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# convert_man_to_html.sh - ts A61214
# convert_man_to_html.sh - ts A61214 , B50802
#
# Generates a HTML version of man page cdrskin.1
#
@ -38,24 +38,25 @@ then
sed \
-e 's/<meta name="generator" content="groff -Thtml, see www.gnu.org">/<meta name="generator" content="groff -Thtml, via man -H, via cdrskin\/convert_man_to_html.sh">/' \
-e 's/<meta name="Content-Style" content="text\/css">/<meta name="Content-Style" content="text\/css"><META NAME="description" CONTENT="man page of cdrskin"><META NAME="keywords" CONTENT="man cdrskin, manual, cdrskin, CD, CD-RW, CD-R, burning, cdrecord, compatible"><META NAME="robots" CONTENT="follow">/' \
-e 's/<meta name="Content-Style" content="text\/css">/<meta name="Content-Style" content="text\/css"><META NAME="description" CONTENT="man page of cdrskin"><META NAME="keywords" CONTENT="man cdrskin, manual, cdrskin, CD-RW, CD-R, DVD-R, DVD-RW, DVD+R, DVD+RW, BD-R, BD-RE, burning, cdrecord, compatible"><META NAME="robots" CONTENT="follow">/' \
-e 's/<title>CDRSKIN<\/title>/<title>man 1 cdrskin<\/title>/' \
-e 's/<h1 align=center>CDRSKIN<\/h1>/<h1 align=center>man 1 cdrskin<\/h1>/' \
-e 's/<body>/<body BGCOLOR="#F5DEB3" TEXT=#000000 LINK=#0000A0 VLINK=#800000>/' \
-e 's/<b>Overview of features:<\/b>/\&nbsp;<BR><b>Overview of features:<\/b>/' \
-e 's/<b>General information paragraphs:<\/b>/\&nbsp;<BR><b>General information paragraphs:<\/b>/' \
-e 's/<b>Track recording model:<\/b>/\&nbsp;<BR><b>Track recording model:<\/b>/' \
-e 's/<b>Overview of features:<\/b>/<b>Overview of features:<\/b><BR>/' \
-e 's/<b>General information paragraphs:<\/b>/<b>General information paragraphs:<\/b><BR>/' \
-e 's/<b>Track recording model:<\/b>/\&nbsp;<BR><b>Track recording model:<\/b><BR>/' \
-e 's/^In general there are two types of tracks: data and audio./\&nbsp;<BR>In general there are two types of tracks: data and audio./' \
-e 's/^While audio tracks just contain a given/\&nbsp;<BR>While audio tracks just contain a given/' \
-e 's/<b>Write mode selection:<\/b>/\&nbsp;<BR><b>Write mode selection:<\/b>/' \
-e 's/<b>Recordable CD Media:<\/b>/\&nbsp;<BR><b>Recordable CD Media:<\/b>/' \
-e 's/<b>Overwriteable DVD Media:<\/b>/\&nbsp;<BR><b>Overwriteable DVD Media:<\/b>/' \
-e 's/<b>Sequentially Recordable DVD Media:<\/b>/\&nbsp;<BR><b>Sequentially Recordable DVD Media:<\/b>/' \
-e 's/<b>Write mode selection:<\/b>/<b>Write mode selection:<\/b><BR>/' \
-e 's/<b>Recordable CD Media:<\/b>/<b>Recordable CD Media:<\/b><BR>/' \
-e 's/<b>Overwriteable DVD or BD Media:<\/b>/<b>Overwriteable DVD or BD Media:<\/b><BR>/' \
-e 's/<b>Sequentially Recordable DVD or BD Media:<\/b>/<b>Sequentially Recordable DVD or BD Media:<\/b><BR>/' \
-e 's/^The write modes for DVD+R/\&nbsp;<BR>The write modes for DVD+R/' \
-e 's/<b>Drive preparation and addressing:<\/b>/\&nbsp;<BR><b>Drive preparation and addressing:<\/b>/' \
-e 's/<b>Drive preparation and addressing:<\/b>/<b>Drive preparation and addressing:<\/b><BR>/' \
-e 's/^If you only got one CD capable drive/\&nbsp;<BR>If you only got one CD capable drive/' \
-e 's/<b>Emulated drives:<\/b>/\&nbsp;<BR><b>Emulated drives:<\/b>/' \
-e 's/^Alphabetical list of options/\&nbsp;<BR>Alphabetical list of options/' \
-e 's/<b>Emulated drives:<\/b>/<b>Emulated drives:<\/b><BR>/' \
-e 's/for normal use: <b><br>/for normal use: <b><br><BR>/' \
-e 's/original cdrecord by Joerg Schilling:<\/p>/original cdrecord by Joerg Schilling:<\/p><BR>/' \
-e 's/<\/body>/<BR><HR><FONT SIZE=-1><CENTER>(HTML generated from '"$manpage"'.1 on '"$(date)"' by '$(basename "$0")' )<\/CENTER><\/FONT><\/body>/' \
-e 's/See section FILES/See section <A HREF="#FILES">FILES<\/A>/' \
-e 's/See section EXAMPLES/See section <A HREF="#EXAMPLES">EXAMPLES<\/A>/' \
@ -70,8 +71,10 @@ then
else
export BROWSER='cp "%s" '"$raw_html"
# export BROWSER='cp "%s" '"$raw_html"
export BROWSER=$(pwd)/'cdrskin/unite_html_b_line "%s" '"$raw_html"
man -H "$manpage"
# cp "$raw_html" /tmp/x.html
"$0" -work_as_filter "$raw_html"
rm "$raw_html"
rm "$man_dir"/man1

View File

@ -0,0 +1,124 @@
/*
( cd cdrskin ; cc -g -Wall -o unite_html_b_line unite_html_b_line.c )
*/
/*
Specialized converter for the output of man -H,
which unites lines where the line end is between <b> and </b>.
Copyright 2015 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
*/
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
int unite_lines(char *buffer, int *b_open, int *b_state, int flag)
{
char *cpt;
int last_was_nl= 0;
for(cpt= buffer; *cpt != 0; cpt++) {
if(*b_open) {
if(*b_state == 0 && *cpt == '<') {
*b_state= 1;
} else if(*b_state == 1) {
if(*cpt == '/')
*b_state= 2;
else
*b_state= 0;
} else if(*b_state == 2) {
if(*cpt == 'b' || *cpt == 'B')
*b_state= 3;
else
*b_state= 0;
} else if(*b_state == 3) {
if(*cpt == '>')
*b_open= 0;
*b_state= 0;
}
} else {
if(*b_state == 0 && *cpt == '<') {
*b_state= 1;
} else if(*b_state == 1) {
if(*cpt == 'b' || *cpt == 'B')
*b_state= 2;
else
*b_state= 0;
} else if(*b_state == 2) {
if(*cpt == '>')
*b_open= 1;
*b_state= 0;
}
}
last_was_nl= (*cpt == '\n');
}
if(*b_open && last_was_nl) {
/* replace newline */
*(cpt - 1)= ' ';
}
return(1);
}
int main(int argc, char **argv)
{
FILE *fpin, *fpout;
char buffer[4096], *respt;
int ret, b_open= 0, b_state= 0;
if(argc != 3) {
fprintf(stderr, "usage: %s input_path output_path\n", argv[0]);
return(1);
}
if(strcmp(argv[1], "-") == 0) {
fpin= stdin;
} else {
fpin= fopen(argv[1], "rb");
if(fpin == 0) {
fprintf(stderr, "Error with input file '%s' : %s\n",
argv[1], strerror(errno));
return(2);
}
}
if(strcmp(argv[2], "-") == 0) {
fpout= stdout;
} else {
fpout= fopen(argv[2], "wb");
if(fpout == 0) {
fprintf(stderr, "Error with output file '%s' : %s\n",
argv[2], strerror(errno));
return(3);
}
}
while(1) {
respt= fgets(buffer, sizeof(buffer), fpin);
if(respt == NULL)
break;
ret= unite_lines(buffer, &b_open, &b_state, 0);
if(ret <= 0)
break;
ret= fputs(buffer, fpout);
if(ret < 0) {
fprintf(stderr, "Error writing to output file '%s' : %s\n",
argv[2], strerror(errno));
return(4);
}
}
if(fpin != stdin)
fclose(fpin);
if(fpout != stdout)
fclose(stdout);
return(0);
}