source: trunk/insertphp.sh @ 95

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

add rest2web for manuals production (and start sphinx but not yet ok)

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