#!/usr/bin/awk -f
# name : mef2html
# categorie : html
# version : 1.6
# date : 12/02/2015
# historique: 06/11/2014 1.0 initial
# 10/11/2014 1.1 liste et puces, liste de définition
# 14/11/2014 1.2 ajout tags html (, mef2html.awk s'utilise de 3 manières possibles"
print " "
print " "
print " "
print " Les tags utilisés par mef2html.awk commencent toujours par le caractère @."
print " Les tags se terminant par / correspondent à des commandes de blocs."
print " Les tags délimités par ( ) correspondent à des fonctions soit de mise en forme de texte, soit des fonctions fournissant une chaine (heure, date par exemple)."
print " Les tags se terminant par un = indique des affectations de variables ou des directives de mise en forme."
print " Les tags définissant les blocs sont: @tab/ ou @table/ début de tableau"
print " les colonnes sont séparées par un caractère défini par la variable [sep]."
print " @screen/ ou @scr/ ou @cons/ début du mode console"
print " @code/ ou @lst/ début du mode listing"
print " @list/ début d'une liste"
print "v@list fin d'une liste"
print
print " @download/ début d'un tableau de download"
print " @system/ execute une commande et insère le résultat"
print " Les variables et directives que l'on peut définir pour la mise en forme sont:"
print " "
print " @border= bordure d'un tableau (0,1,2,..)"
print " Les commentaires sont insérés avec une ligne commençant par ::"
print
}
#---------------------------------------------------------------
function right(str,pos)
{
return substr(str,pos,length(str)-pos+1)
}
#------------------------------------------------------------------
# replace(str,ch,rep,rep2) - remplace ch par rep ch rep2 dans str
#------------------------------------------------------------------
function replace(str,ch,rep,rep2)
{
s=1
size=length(ch)
while(s>0) {
s=index(str,ch)
if (s==0) { break; }
e=index(str,")")
str=substr(str,1,s-1) rep substr(str,s+size,e-s-size) rep2 substr(str,e+1,length(str)-e)
}
return str
}
#------------------------------------------------------------------
# replace_function_2args(str,ch,rep1,rep2,rep3) - remplace ch par rep ch rep2 dans str
#------------------------------------------------------------------
function replace_function_2args(str,ch,rep1,rep2,rep3)
{
s=1
while(s>0) {
s=index(str,ch)
if (s>0) { str=rep_link(str,ch,rep1,rep2,rep3) }
}
return str
}
function rep_link(str,ch)
{
a=index(str,ch)
b=index(str,",")
c=index(str,")")
l=length(ch)
v=substr(str,1,a-1) "" substr(str,b+1,c-b-1) "" substr(str,c+1,length(s)-c)
# v=substr(str,1,a-1) rep1 substr(str,a+l,b-a-l) "\">" substr(str,b+1,c-b-1) "" substr(str,c+1,length(s)-c)
return v
}
#---------------------------------------------------------------
function replace_one(str,ch,rep)
{
s=1
size=length(ch)
lg=length(str)
while(s>0) {
s=index(str,ch)
if (s==0) { break; }
str=substr(str,1,s-1) rep substr(str,s+size,lg-s-size+1)
}
return str
}
#---------------------------------------------------------------
# alen(array) -- retourne le nombre d'éléments d'un tableau
#---------------------------------------------------------------
function alen(array) {
len=0
for (dummy in array)
len++;
return len;
}
#---------------------------------------------------------------
# gettimeofday.awk --- get the time of day in a usable format
# Returns a string in the format of output of date(1)
# Populates the array argument time with individual values:
# time["second"] -- seconds (0 - 59)
# time["minute"] -- minutes (0 - 59)
# time["hour"] -- hours (0 - 23)
# time["althour"] -- hours (0 - 12)
# time["monthday"] -- day of month (1 - 31)
# time["month"] -- month of year (1 - 12)
# time["monthname"] -- name of the month
# time["shortmonth"] -- short name of the month
# time["year"] -- year modulo 100 (0 - 99)
# time["fullyear"] -- full year
# time["weekday"] -- day of week (Sunday = 0)
# time["altweekday"] -- day of week (Monday = 0)
# time["dayname"] -- name of weekday
# time["shortdayname"] -- short name of weekday
# time["yearday"] -- day of year (0 - 365)
# time["timezone"] -- abbreviation of timezone name
# time["ampm"] -- AM or PM designation
# time["weeknum"] -- week number, Sunday first day
# time["altweeknum"] -- week number, Monday first day
function date()
{
now = systime()
ret = strftime("%d/%m/%Y", now)
print ret
}
function time2()
{
now = systime()
ret = strftime("%H:%M:%S", now)
print ret
}
function dateex(mode)
{
# return date(1)-style output
ret = strftime("%a %b %d %H:%M:%S %Z %Y", now)
# clear out target array
delete time
# fill in values, force numeric values to be
# numeric by adding 0
time["second"] = strftime("%S", now) + 0
time["minute"] = strftime("%M", now) + 0
time["hour"] = strftime("%H", now) + 0
time["althour"] = strftime("%I", now) + 0
time["monthday"] = strftime("%d", now) + 0
time["month"] = strftime("%m", now) + 0
time["monthname"] = strftime("%B", now)
time["shortmonth"] = strftime("%b", now)
time["year"] = strftime("%y", now) + 0
time["fullyear"] = strftime("%Y", now) + 0
time["weekday"] = strftime("%w", now) + 0
time["altweekday"] = strftime("%u", now) + 0
time["dayname"] = strftime("%A", now)
time["shortdayname"] = strftime("%a", now)
time["yearday"] = strftime("%j", now) + 0
time["timezone"] = strftime("%Z", now)
time["ampm"] = strftime("%p", now)
time["weeknum"] = strftime("%U", now) + 0
time["altweeknum"] = strftime("%W", now) + 0
# print time[mode]
print ret
}
#---------------------------------------------------------------
# gestion des tableaux
#---------------------------------------------------------------
function raw(str,sep)
{
n=split(str,word,sep)
if(bicolor==0) {
printf ""
print "
"
print "
convertit en html fichier"
print "
affiche l'usage"
print "
affiche une documentation en html"
print "
version du programme"
print "PRINCIPES
"
print "
"
print "
si le tag est @key/ , le bloc se termine par @key et le formattage s applique au bloc définit."
print "BLOCS
"
print "
"
for (i=1;i<=6;i++) { printf ("
@h%d/ header niveau %d\n",i,i) }
print
print "
@tab ou @table fin de tableau"
print "
la taille de la bordure est fixée par la variable [border]."
print
print "
@screen ou @scr ou @cons fin du mode console"
print
print "
@code ou @lst fin du mode listing"
print
print "
@download fin d'un tableau de download"
print
print "
@include/ insère un fichier"
print
print "TAGS
"
print "Les tags de mise en forme du texte:
"
for (j=0;jVARIABLES
"
print "
@sep= séparateur de colonne dans un tableau (; . : ...)"
print "
@puce= type de puce : disc, square, circle"
print "
"
print "
@bicolor=0 tableau sans couleur"
print "
@bicolor=1 tableau avec couleur de fond color1 et color2"
print "
@color1= couleur format #F7F7F7 par exemple"
print "
@color2= couleur format #A7A7A7 par exemple"
print
print "INTERNE
"
print
print "
"
for (i=1;i<=n;i++) printf " "
}
else { if (nbl == 0) {color=color1 ; nbl=1 } else { color=color2 ; nbl=0}
printf ("" word[i] " "
print "",color)
for (i=1;i<=n;i++) printf (" "
}
}
#---------------------------------------------------------------
# gestion des fichiers à télécharger
#---------------------------------------------------------------
function download(str,sep)
{
delete word
split(str,word,sep)
printf "%s " ,color,word[i])
print ""
for (i=1; i \n"
}
#---------------------------------------------------------------
function readfile2(file)
{
save_rs = RS
RS = "^$"
getline tmp < file
close(file)
RS = save_rs
return tmp
}
#---------------------------------------------------------------
function readfile(file)
{
if ((getline tmp < file) < 0)
return
print tmp
while ((getline tmp < file) > 0)
print tmp
close(file)
return
}
#---------------------------------------------------------------
function process(str)
{
str=replace_function_2args(str,"@link(","" word[i] " "
printf "" ; rep2[i++]=""
tag[i]= "@sup(" ; comment[i] ="exposant" ; rep[i]= "" ; rep2[i++]=""
tag[i]= "@sub(" ; comment[i] ="indice" ; rep[i]= "" ; rep2[i++]=""
tag[i]= "@em(" ; comment[i] ="emphase" ; rep[i]= "" ; rep2[i++]=""
tag[i]= "@small(" ; comment[i] ="small" ; rep[i]= "" ; rep2[i++]=""
tag[i]= "@mark(" ; comment[i] ="marque" ; rep[i]= "" ; rep2[i++]=""
tag[i]= "@strong(" ; comment[i] ="strong" ; rep[i]= "" ; rep2[i++]=""
tag[i]= "@abbr(" ; comment[i] ="abréviation" ; rep[i]= "" ; rep2[i++]=""
tag[i]= "@acronym(" ; comment[i] ="acronym" ; rep[i]= "" ; rep2[i++]=""
tag[i]= "@acro(" ; comment[i] ="acronym" ; rep[i]= "" ; rep2[i++]=""
tag[i]= "@def(" ; comment[i] ="définition" ; rep[i]= "
"; find[j]="@li/" ; comment[i] ="liste" ; repl[j++]="
"; find[j]="@pre" ; comment[i] ="break" ; repl[j++]=""; find[j]="@br/" ; comment[i] ="break" ; repl[j++]="
"; find[j]="@p" ; comment[i] ="fin paragraphe" ; repl[j++]="
"; nb_repl=j parse_args() } #============================================================================= #----------------------------------------------------------------------------- # commentaires #----------------------------------------------------------------------------- /^::/ { next } #----------------------------------------------------------------------------- # header #----------------------------------------------------------------------------- /^@h1\// { print "librairie | version | date | fichier |
---|
" ; mode=0 ; next } /@code|@lst/ { print "
"; next } /(@screen\/|@scr\/|@cons\/)/ { print "
" ; mode=0 ; next } /@screen|@scr|@cons/ { print "
"; next } #----------------------------------------------------------------------------- # listes #----------------------------------------------------------------------------- /@list\// { print "