home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #----------------------------------------------------------------------
- # NOM
- # Bookmarks = Construit des pages HTML a partir d'un Bookmarks.
- #
- # SYNTAXE
- # Bookmarks -h|H (aide)
- # Bookmarks [-b rgb] [-B image] [-s suffixe] [-T titre]
- # bookmarks_netscape
- #
- #----------------------------------------------------------------------
- # VERSION
- # 1.0
- #
- # DESCRIPTION
- # Contruit a partir un d'un fichier de bookmarks (html) issues de
- # Netscape des pages HTML avec utilisation de FRAME verticale.
- # La premiere concerne la table des Bookmarks (table des matieres). La
- # seconde la liste des references HTTP.
- #
- # La table des Bookmarks utilise les Folder principaux comme "tete de
- # chapitre". Les separateurs et l'arborescence sont conserves.
- #
- #
- # OPTIONS
- # -h|H aide courte ou longue.
- #
- # -b rgb Pour fixer une couleur RGB en fond des Frames.
- #
- # -B image Pour fixer une image en fond des Frames.
- #
- # -s suffixe Donne un suffixe particulier au fichier, par defaut
- # le suffixe .htm est utilise.
- #
- # -T titre Precise un titre inscrit sur la page des bookmarks,
- # par defaut le titre du fichier passe en argument est
- # utilise.
- #
- #
- # EXEMPLE(S)
- # * Lancement de l'application avec affichage de l'aide longue:
- # $ Bookmarks -H
- #
- # * Construit de nouvelles pages suffixees par html. Un fond blanc
- # est applique au FRAME avec un titre :
- # $ Bookmarks -T "Mes Marks" -s html -b "#FFFFFF" book.html
- #
- #
- # REMARQUE(S)
- # * Procedure distribuee en Freeware/Gratuiciel.
- #
- # AUTEUR
- # Copyright (c) 1998 Bertrand LE QUELLEC, All Rigths Reserved.
- #
- # CONTACT
- # eMail : blq@mygale.org ou blq@wanadoo.fr
- # Url : http://www.mygale.org/09/blq/ ou http://perso.wanadoo.fr/blq/
- #
- # Cree : 01/07/98
- #----------------------------------------------------------------------
- # Permission to use, copy, modify, distribute, and sell this software
- # and its documentation for any purpose is hereby granted without fee,
- # provided that the above copyright notice appear in all copies and
- # that both that copyright notice and this permission notice appear in
- # supporting documentation, and that the name of Bertrand LE QUELLEC
- # not be used in advertising or publicity pertaining to distribution
- # of the software without specific, written prior permission.
- # Bertrand LE QUELLEC makes no representations about the suitability
- # of this software for any purpose. It is provided "as is" without
- # express or implied warranty.
- #
- # THIS SOFTWARE IS PROVIDED BY Bertrand LE QUELLEC `AS IS' AND ANY
- # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Bertrand LE QUELLEC BE
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- #----------------------------------------------------------------------
-
- # ------------------------------------------
- # ZONE DE DEFINITION DES VARIABLES GLOBALES:
- # ------------------------------------------
- NOM_PROCEDURE=`basename $0`
- LA_PROCEDURE=$0
- CD=`pwd`
- AWK=`[ -f /usr/bin/nawk ] && echo "nawk" || echo "awk" `
-
-
- ##
- ## Variables particulieres:
- ##
- DATE=`date "+%d/%m/%y"`
- MODE_COULEUR=0
- VISU_HTML=netscape
-
- USE_PIPE=0
- PIPE=/tmp/pipe$$
-
-
- ##
- ## Les variables concernant l'utilisateur:
- ##
- DEFAUT_AUTEUR=`whoami`
- DEFAUT_EDITEUR=${EDITOR}:-vi
- DEFAUT_SHELL=${SHELL}:-/bin/sh
-
-
- #----------------------------------------------------------------------
- # -----------------------------------------
- # ZONE DE DEFINITION DES FONCTIONS LOCALES:
- # -----------------------------------------
- # La fonction doit etre precedee d'un commentaire avec en debut de ligne
- # le caractere # (diese) repete deux fois.
-
- ##
- ## Affiche un message en rouge si l'on se trouve dans une fenetre hpterm
- ## et se met en attente de 2 secondes.
- ## Il est possible de recuperer le code retour de la fonction.
- ##
- Erreur()
- {
- [ $# -eq 0 ] && return -1
-
- echo "\n\t${ROUGE}$*${NORMAL}"
- echo "\n Appuyez sur la touche Entree (Enter) pour continuer \c"
- read choix
-
- return 0
- }
-
-
- ##
- ## En cas d'une interruption la fonction suivante est executee.
- ## Les interruptions sont des signaux envoyes au processus du script,
- ## par la commande Unix: kill(1). La "capture" de ces signaux est
- ## identifiee par la commande Shell: trap definie apres la zone des
- ## options.
- ##
- TrapInterrup()
- {
- # Vous pouvez executer des instructions avant une sortie
- # par signal (ou brutale!).
- exit 1
- }
-
-
- ##
- ## Renvoie le PATH et nom d'un ou plusieurs executables.
- ## Si le ou les executables sont introuvables la fonction ne renvoie rien.
- ## Dans le cas d'un alias la fonction ne renvoie rien, car le PATH n'est
- ## pas recuperable.
- ##
- Type()
- {
- [ $# -ne 0 ] && type $* | ${AWK} '$2=="is" && $4!="alias" {print $NF}'
- }
-
-
- ##
- ## Affiche l'aide indiquee en en-tete du script shell.
- ## Ne pas supprimer car cette fonction est utilisee a l'appel de la
- ## procedure avec les options -H ou -H
- ##
- AideProc()
- {
- fichier=$1
- niveau=$2
-
- [ -z "$fichier" ] && {
- Erreur "AideProc(): nombre d'argument incorect."
- return 0
- }
-
- [ ! -f "$fichier" ] && {
- [ -f "`basename $fichier`" ] && fichier=`basename $fichier` || {
- Erreur "AideProc(): impossible d'atteindre le fichier $fichier."
- return 0
- }
- }
-
- [ ${niveau:=2} = 2 ] && {
- ${AWK} 'BEGIN {i=2}
- /^#[-]+/{
- if(--i<=0)exit
- next
- }
- /^#[ ]*[A-Z]*[ ]*$/{
- next
- }
- /^#[^!]/{
- print substr($0,1,80)
- }
- /^#[ \t]*$/{
- print ""
- }
- ' $fichier | sed -e 's/^#[ ]*//'
- } || {
- ${AWK} '\
- /^#[-]+/{
- if(--i<=0) exit
- next
- }
- /^#[^!]/{
- print substr($0,2,80)
- }
- /^#[ \t]*$/{
- print ""
- }
- ' i=$niveau $fichier | pg -e
- }
- }
-
-
- ##
- ## Renvoie le type de la machine ou l'on se trouve et surtout le
- ## systeme d'exploitation en cours. La fonction renvoie un des numero
- ## suivant en reponse:
- ##
- ## inconue 0
- ##
- ## SunOs 1
- ## Sun Solaris 2
- ## HP s700 3
- ## HP s800 4
- ## HP s300 5
- ## Silicon Graphic 6
- ## IBM AIX 7
- ##
- ## Pour recuperer le code retour de la fonction, utilisez la variable $?
- ##
- Machine()
- {
- os=`uname`
-
- [ "$os" = "Solaris" ] && return 2
-
- [ "$os" = "SunOS" ] && {
- [ -f /vmunix ] && return 1 || return 2
- }
-
- [ "$os" = "HP-UX" ] && {
- if uname -a | grep "PA-RISC" 1> /dev/null
- then
- return 3
- elif uname -a | grep "HP-PA" 1> /dev/null
- return 4
- then
- return 5
- fi
- }
-
- [ "$os" = "IRIX" ] && return 6
-
- [ "$os" = "AIX" ] && return 7
-
- return 0
- }
-
-
- ##
- ## Permet de visualiser un fichier HTML avec le bon executable:
- ## netscape ou mosaic
- ##
- VoirHTML ()
- {
- fichier="$*"
-
- [ -z "$VISU_HTML" ] && VISU_HTML=mosaic
-
- chemin=`Type $VISU_HTML`
- [ -z "$chemin" ] && VISU_HTML=netscape
-
- chemin=`Type $VISU_HTML`
- [ -z "$chemin" ] && {
- Erreur "Executable du visualiseur HTML non accessible !"
- return 0
- }
-
- $VISU_HTML $fichier &
- return 1
- }
-
-
- #----------------------------------------------------------------------
- # ----------------------------------------------
- # DEFENITION DES VARIABLES LOCALES AU PROGRAMME:
- # ----------------------------------------------
-
-
- #----------------------------------------------------------------------
- # ----------------------------------------------
- # DEFENITION DES FONCTIONS LOCALES AU PROGRAMME:
- # ----------------------------------------------
-
- LISTE_FICHIERS=""
-
- BackCOLOR=""
- BackIMAGE=""
- Titre=""
-
- Suffixe="htm"
-
-
- #----------------------------------------------------------------------
- # -------------------------
- # RECUPERATION DES OPTIONS:
- # -------------------------
- set -- `getopt hHxb:B:T:s: $*`
- for opt in $*
- do
- case $opt in
- -h) AideProc $LA_PROCEDURE ; exit 0 ;;
- -H) AideProc $LA_PROCEDURE 3 ; exit 0 ;;
-
- -x) set -x ; shift ;;
-
- -b) BackCOLOR=" bgcolor=\"$2\"" ; shift ; shift ;;
- -B) BackIMAGE=" background=\"$2\"" ; shift ; shift ;;
- -T) Titre="\"$2\"" ; shift ; shift ;;
-
- -s) Suffixe="$2" ; shift ; shift ;;
-
- -) cat - > $PIPE
- USE_PIPE=1
- exec <&- ; shift ;;
-
- --) shift ; break ;;
- esac
- done
-
- LISTE_FICHIERS="$*"
-
- HTML_TABLE="BookTable.${Suffixe}"
- HTML_DISPLAY="BookDisplay.${Suffixe}"
- HTML_INDEX="bookmarks.${Suffixe}"
-
-
- #----------------------------------------------------------------------
- # AUTRES DEFINITIONS:
- # -------------------
- trap TrapInterrup 3 2 15 # Recuperation des interruptions 3, 2 et 15
-
- #----------------------------------------------------------------------
- # DEBUT ZONE DU PROGRAMME:
- # ------------------------
-
- [ -z "$LISTE_FICHIERS" ] && exit 0
-
-
- # ------------------------------------------
- # --- INDEX.HTM
- echo "\n Creation en cours $HTML_INDEX ..."
-
- echo "<HTML>
- <HEAD><TITLE>` [ -z \"$Titre\" ] && echo \"Liste de Bookmarks\" || echo $Titre`</TITLE></HEAD>
- <FRAMESET COLS=\"30%,75%\" NAME=\"bookmarks\" BORDER=1 FRAMEBORDER=\"YES\" FRAMESPACING=0 SCOLLING=\"auto\">
- <FRAME SRC=$HTML_TABLE NAME=\"table\">
- <FRAME SRC=$HTML_DISPLAY NAME=\"display\">
- </FRAMESET>
- </HTML> " > $HTML_INDEX
-
-
- # ------------------------------------------
- # --- TABLE.HTM
- echo " Creation en cours $HTML_TABLE ..."
-
- echo "<HTML>
- <HEAD><TITLE>Table des Bookmarks</TITLE></HEAD>
- <BODY${BackCOLOR}${BackIMAGE}>
- <CENTER><H3>Table des Bookmarks</H3></CENTER>
- " > $HTML_TABLE
-
- for file in $LISTE_FICHIERS
- do
- echo "\tTraitement ${AWK} $file ..."
- $AWK -F ">" ' BEGIN { flag=0 }
- /<DL><p>/ {
- if ( flag == 1 )
- print "<UL>"
-
- flag=flag+1
- next
- }
- /<\/DL><p>/ {
- flag=flag-1
-
- if ( flag == 1 )
- print "</UL>"
-
- next
- }
- /<HR/ {
- print "<HR SIZE=6><BR>"
- next
- }
- /<DT><H3 FOLDED ADD_DATE/ {
- gsub(/Θ/, "\é", $0)
- pos1=index($3, "<")
-
- if ( pos1 )
- if ( flag == 1 )
- printf("<A HREF=\"%s#%s\" TARGET=\"display\"><B>%s</B></A><BR>\n", disp_html, substr($3, 1, pos1-1), substr($3, 1, pos1-1))
- else
- printf("<LI>%s<BR>\n", substr($3, 1, pos1-1))
- else
- printf("%s\n", $3)
- }' disp_html=$HTML_DISPLAY $file >> $HTML_TABLE
- done
-
- echo "</BODY></HTML>" >> $HTML_TABLE
-
-
- # ------------------------------------------
- # --- DISPLAY.HTM
- echo " Creation en cours $HTML_DISPLAY ..."
-
- echo "<HTML>
- <HEAD><TITLE>Affichage des Bookmarks</TITLE></HEAD>
- <BODY $BackCOLOR>
- " > $HTML_DISPLAY
-
- for file in $LISTE_FICHIERS
- do
- echo "\tTraitement $file ..."
- sed -e 's%^\(.*\) ADD_DATE\(.*\)">\(.*\)$%\1>\3%' $file | $AWK -F ">" '
- BEGIN { dtFlag=0 ; flag=0 }
- /<H1>/ {
- gsub(/Θ/, "\é", $0)
- if (length(leT))
- print "<CENTER><H1>", leT, "</H1></CENTER>"
- else
- print "<CENTER>", $0, "</CENTER>"
-
- next
- }
- /<DL><p>/ {
- if ( dtFlag == 1 )
- print "<UL>"
-
- dtFlag=dtFlag+1
- next
- }
- /<\/DL><p>/ {
- dtFlag=dtFlag-1
-
- if ( dtFlag == 1 )
- print "</UL>"
-
- next
- }
- /<DT><H3 FOLDED/ {
- flag=1
- gsub(/Θ/, "\é", $0)
- pos1=index($3, "<")
-
- printf("<A NAME=\"%s\">\n", substr($3, 1, pos1-1))
- gsub(/ FOLDED/, "", $0)
-
- if ( dtFlag == 1 )
- print "<P>", $0
- else
- print "sub_h3", $0
-
- next
- }
- // {
- if (flag == 1 )
- {
- gsub(/Θ/, "\é", $0)
- print $0
- }
- }' leT=$Titre | sed -e 's%sub_h3\(.*\)<H3>\(.*\)</H3>%<DT><H4><I>\2</I></H4>%' >> $HTML_DISPLAY
- done
-
- echo "</BODY></HTML>" >> $HTML_DISPLAY
-