source: trunk/insertphp.sh @ 76

Last change on this file since 76 was 76, checked in by pinsard, 16 years ago

no more NEMO reference in XSL files; project information (name and home page are in main.xml

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