source: trunk/insertphp.sh @ 110

Last change on this file since 110 was 109, checked in by pinsard, 14 years ago

usage of program directive

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1#! /bin/sh
2#+
3#
4# .. program:: insertphp.sh
5#
6# ============
7# insertphp.sh
8# ============
9#
10# -----------------------------------------------
11# ajoute des commandes php dans des fichiers html
12# -----------------------------------------------
13#
14# SYNOPSIS
15# ========
16#
17# ::
18#
19#  $ insertphp.sh -i filein -o fileout -s sedfile -d depth
20#
21#
22# DESCRIPTION
23# ===========
24#
25# ajoute des commandes php dans des fichiers html
26# en fonction d'info dans main.xml
27#
28# .. option:: -i  <input file>
29# .. option:: -o  <output file>
30# .. option:: -s  <sedfile>
31# .. option:: -d  <depth>
32#
33# EXAMPLES
34# ========
35#
36# To do the job on "one" branch::
37#
38#  $ ./insertphp.sh -i template_beforesed.php -o ./template_one.php -d 2 -s insertphp_one.sed
39#
40# To check::
41#
42#  $ diff template_beforesed.php template.php
43#
44#
45# To do the job on "many" branch::
46#
47#  $ ./insertphp.sh -i template_beforesed.php -o ./template_many.php -d 3 -s insertphp_many.sed
48#
49# see makefile
50#
51# EVOLUTIONS
52# ==========
53#
54# $Id$
55#
56# - fplod 2008-09-18T08:55:50Z aedon.locean-ipsl.upmc.fr (Darwin)
57#
58#   * add -d and -d option to perform one and many transformation
59#     with the same shell script
60#
61# - fplod 2008-09-17T15:12:32Z aedon.locean-ipsl.upmc.fr (Darwin)
62#
63#   * creation to encapsulate insertphp_one.sed usage and use
64#     main.xml title
65#
66#-
67system=$(uname)
68case "${system}" in
69   AIX|IRIX64)
70      echo " www : no specific posix checking"
71   ;;
72   *)
73     set -o posix
74   ;;
75esac
76unset system
77#
78command=$(basename ${0})
79log_date=$(date -u +"%Y%m%dT%H%M%SZ")
80log=/tmp/$(basename ${command} .sh).log.${log_date}
81#
82# test if xml is available
83tool=xml
84type ${tool} 1> /dev/null 2>&1
85status=${?}
86if [ ${status} -ne 0 ]
87then
88   echo " eee : ${tool} not found"
89   exit 1
90fi
91unset status
92unset tool
93#
94usage=" Usage : ${command} -i filein -o fileout -s sedfile -d depth"
95#
96minargcount=8
97#echo " narg ${#}"
98if [ ${#} -lt ${minargcount} ]
99then
100   echo "eee : not enought arguments"
101   echo "${usage}"
102   exit 1
103fi
104unset minargcount
105#
106set +u
107while [ ! -z "${1}" ]
108do
109   case ${1} in
110      -i)
111         filein=${2}
112         shift
113       ;;
114      -o)
115         fileout=${2}
116         shift
117      ;;
118      -s)
119         sedfile=${2}
120         shift
121      ;;
122      -d)
123         depth=${2}
124         shift
125      ;;
126      *)
127         # other choice
128         echo "eee : unknown option ${1}"
129         echo "${usage}"
130         exit 1
131      ;;
132   esac
133   # next flag
134   shift
135done
136unset usage
137#
138set -u
139#
140# check for filein
141if [ ! -f ${filein} ]
142then
143   echo "eee : ${filein} not found"
144   exit 1
145fi
146#
147# check for sedfile
148if [ ! -f ${sedfile} ]
149then
150   echo "eee : ${sedfile} not found"
151   exit 1
152fi
153#
154# check for depth
155if [ ${depth} -lt 0 ]
156then
157   echo "eee : ${depth} must be greater than 0"
158   exit 1
159fi
160# ++ check for fileout ++ overwrite
161#
162# check for main.xml  ++ path
163if [ ! -f ./main.xml ]
164then
165   echo "eee : ./main.xml not found"
166   exit 1
167fi
168#
169# get title from main.xml
170title=$(xml sel -N d="http://docbook.org/ns/docbook" -t -m "/d:article/d:title/node()" -c . main.xml)
171#
172dirphp="./"
173idepth=1
174while [ ${idepth} -le ${depth} ]
175do
176   dirphp=${dirphp}"../"
177   idepth=$((${idepth} + 1))
178done
179sed -f ${sedfile} \
180   -e "s@${title}@${title} <?php include(\"${dirphp}php/timestamp.php\"); ?>@" \
181   ${filein} > ${fileout}
182# end
183exit 0
Note: See TracBrowser for help on using the repository browser.