#!/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 (, ...) # 14/11/2014 1.3 ajout de la date et de l'heure # 20/11/2014 1.4 ajout de @link 'non générique) # 02/12/2014 1.5 @tab avec couleur # 03/12/2014 1.5.1 documentation associée # 10/12/2014 1.5.2 tags en plus small,mark # 15/12/2014 1.5.3 affichage de la version, meilleure documentation # 16/12/2014 1.5.4 commentaires # 14/01/2015 1.5.5 @lip/ ajouté # 12/02/2015 1.6 correction bug tab: split ne retourne pas une valeur ordonnée #--------------------------------------------------------------- function version() { print "mef2html.awk" print "version 1.6" print "12/02/2015" print "J.L BICQUELET" } #--------------------------------------------------------------- function usage() { print "USAGE" print "-----\n" print "1. awk -f mef2html.awk fichier" print "convertit en html fichier" print print "2. awk -f mef2html.awk usage ou awk -f mef2html.awk /?" print "affiche l'usage" print print "3. awk -f mef2html.awk doc ou awk -f mef2html.awk /d" print "affiche la documentation en html" print print "4. awk -f mef2html.awk ver ou awk -f mef2html.awk /v" print "affiche la version de mef2html" print print "BLOCS" print "-----\n" for (i=1;i<=6;i++) { printf ("@h%d/ header niveau %d\n",i,i) } print print "@tab/ ou @table/ début de tableau" print "@tab ou @table fin de tableau" print "les colonnes sont séparées par un caractère défini par la variable [sep]." print "la taille de la bordure est fixée par la variable [border]." print print "@screen/ ou @scr/ ou @cons/ début du mode console" print "@screen ou @scr ou @cons fin du mode console" print print "@code/ ou @lst/ début du mode listing" print "@code ou @lst fin du mode listing" print print "@list/ début d'une liste" print "@list fin d'une liste" print print "@download/ début d'un tableau de download" print "@download fin d'un tableau de download" print print "@system/ execute une commande et insère le résultat" print "@include/ insère un fichier" print print "TAGS" print "----\n" for (j=0;jUSAGE" print "

mef2html.awk s'utilise de 3 manières possibles" print "

    " print "
  1. awk -f mef2html.awk fichier" print "
    convertit en html fichier" print "

    " print "

  2. awk -f mef2html.awk usage (ou /?)" print "
    affiche l'usage" print "

    " print "

  3. awk -f conv.awk doc (ou /d)" print "
    affiche une documentation en html" print "

    " print "

  4. awk -f conv.awk version (ou /v)" print "
    version du programme" print "
" print "

PRINCIPES

" 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 "
    si le tag est @key/ , le bloc se termine par @key et le formattage s applique au bloc définit." 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 "

" print "

BLOCS

" print "

Les tags définissant les blocs sont:
" for (i=1;i<=6;i++) { printf ("
@h%d/ header niveau %d\n",i,i) } print print "

@tab/ ou @table/ début de tableau" print "
@tab ou @table fin de tableau" print "

les colonnes sont séparées par un caractère défini par la variable [sep]." print "
la taille de la bordure est fixée par la variable [border]." print print "

@screen/ ou @scr/ ou @cons/ début du mode console" print "
@screen ou @scr ou @cons fin du mode console" print print "

@code/ ou @lst/ début du mode listing" print "
@code ou @lst fin du mode listing" print 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 "
@download fin d'un tableau de download" print print "

@system/ execute une commande et insère le résultat" print "
@include/ insère un fichier" print print "

TAGS

" print "Les tags de mise en forme du texte:
" for (j=0;j" tag[j] ") - " comment[j] } print print "

VARIABLES

" 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 "
@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 "

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 "" for (i=1;i<=n;i++) printf "" word[i] "" print "" } else { if (nbl == 0) {color=color1 ; nbl=1 } else { color=color2 ; nbl=0} printf ("",color) for (i=1;i<=n;i++) printf ("%s" ,color,word[i]) print "" } } #--------------------------------------------------------------- # gestion des fichiers à télécharger #--------------------------------------------------------------- function download(str,sep) { delete word split(str,word,sep) printf "" for (i=1; i" word[i] "" } printf "" word[i] "" printf "\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(","","") for (i=0;i" ; rep2[i++]="" tag[i]= "@cb(" ; comment[i] ="couleur bleu" ; rep[i]= "" ; rep2[i++]="" tag[i]= "@cv(" ; comment[i] ="couleur verte" ; rep[i]= "" ; rep2[i++]="" tag[i]= "@cn(" ; comment[i] ="couleur noiree" ; rep[i]= "" ; rep2[i++]="" tag[i]= "@cj(" ; comment[i] ="couleur jaune" ; rep[i]= "" ; rep2[i++]="" tag[i]= "@cw(" ; comment[i] ="couleur blanche" ; rep[i]= "" ; rep2[i++]="" nb_tags=i j=0 find[j]="@ol/" ; comment[i] ="début liste numérotée" ; repl[j++]="

    "; find[j]="@ol" ; comment[i] ="fin liste numérotée" ;repl[j++]="
"; find[j]="@ul/" ; comment[i] ="début liste ordonnée" ;repl[j++]="
    "; find[j]="@ul" ; comment[i] ="fin liste ordonnée" ; repl[j++]="
"; find[j]="@lh/" ; comment[i] ="tete de liste" ; repl[j++]=""; find[j]="@lip/" ; comment[i] ="liste avec paragraphe" ; repl[j++]="
  • "; find[j]="@li/" ; comment[i] ="liste" ; repl[j++]="

  • "; find[j]="@li" ; comment[i] ="fin de liste" ; repl[j++]="
  • "; find[j]="@dl/" ; comment[i] ="liste de définition" ; repl[j++]="
    "; find[j]="@dl" ; comment[i] ="fin de liste de définition" ; repl[j++]=""; find[j]="@dt/" ; comment[i] ="terme" ; repl[j++]="
    "; find[j]="@dd/" ; comment[i] ="définition" ; repl[j++]="
    "; find[j]="@pre/" ; comment[i] ="break" ; repl[j++]="
    ";
    find[j]="@pre" ; comment[i] ="break" ; repl[j++]="
    "; find[j]="@br/" ; comment[i] ="break" ; repl[j++]="
    "; find[j]="@p/" ; comment[i] ="paragraphe" ; repl[j++]="

    "; find[j]="@p" ; comment[i] ="fin paragraphe" ; repl[j++]="

    "; nb_repl=j parse_args() } #============================================================================= #----------------------------------------------------------------------------- # commentaires #----------------------------------------------------------------------------- /^::/ { next } #----------------------------------------------------------------------------- # header #----------------------------------------------------------------------------- /^@h1\// { print "

    " right($0,5) "

    "; next } /^@h2\// { print "

    " right($0,5) "

    "; next } /^@h3\// { print "

    " right($0,5) "

    "; next } /^@h4\// { print "

    " right($0,5) "

    "; next } /^@h5\// { print "
    " right($0,5) "
    "; next } /^@h6\// { print "
    " right($0,5) "
    "; next } /^@que\// { print "

    " right($0,6) "

    "; next } #----------------------------------------------------------------------------- #system, include, date #----------------------------------------------------------------------------- /@system\// { split($0,val,"/"); system(val[2]) ; next } /@include\// { split($0,val,"/"); readfile(val[2]) ; next } #----------------------------------------------------------------------------- # tableaux #----------------------------------------------------------------------------- /@tab\// { printf("",border) ; mode =2; nbl=0; next} /@tab/ { print "
    " ; mode =0; next} /@table\// { printf("",border) ; mode =2; nbl=0; next} /@table/ { print "
    " ; mode =0; next} /@download\// { printf"" print "" ;mode =5; next} /@download/ { print "
    librairieversiondatefichier
    " ; mode =0; next} # /@date\// { date("dayname") ; next} #----------------------------------------------------------------------------- # codes #----------------------------------------------------------------------------- /(@code\/|@lst\/)/ { print "

    " ; mode=0 ; next }
    /@code|@lst/ { print "

    "; next } /(@screen\/|@scr\/|@cons\/)/ { print "

    " ; mode=0 ; next }
    /@screen|@scr|@cons/ { print "

    "; next } #----------------------------------------------------------------------------- # listes #----------------------------------------------------------------------------- /@list\// { print "

      " ; mode=4 ; next } /@list/ { print "
    "; mode=0 ; next} #----------------------------------------------------------------------------- # controle des variables #----------------------------------------------------------------------------- /@sep=/ { split($0,val,"=") ; sep=val[2]; next } /@border=/ { split($0,val,"=") ; border=val[2] ; next } /@puce=/ { split($0,val,"=") ; sep=val[2]; next } /@bicolor=/ { split($0,val,"=") ; bicolor=val[2]; next } /@color1=/ { split($0,val,"=") ; color1=val[2]; next } /@color2=/ { split($0,val,"=") ; color2=val[2]; next } #----------------------------------------------------------------------------- # modes: # 0 - ligne interprétée # 1 - ligne inchangée # 2 - tableau # 3 - retour au mode 1 # 4 - liste # 5 - download #----------------------------------------------------------------------------- mode==0 { print process($0) } mode==1 { print $0 } mode==2 { raw($0,sep) } mode==3 { mode=1} mode==4 { print "
  • " $0 "
  • " } mode==5 { download($0,sep) }