shtool 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451
  1. #!/bin/sh
  2. ##
  3. ## GNU shtool -- The GNU Portable Shell Tool
  4. ## Copyright (c) 1994-2001 Ralf S. Engelschall <rse@engelschall.com>
  5. ##
  6. ## See http://www.gnu.org/software/shtool/ for more information.
  7. ## See ftp://ftp.gnu.org/gnu/shtool/ for latest version.
  8. ##
  9. ## Version: 1.6.0 (23-Sep-2001)
  10. ## Contents: all available modules
  11. ##
  12. ##
  13. ## This program is free software; you can redistribute it and/or modify
  14. ## it under the terms of the GNU General Public License as published by
  15. ## the Free Software Foundation; either version 2 of the License, or
  16. ## (at your option) any later version.
  17. ##
  18. ## This program is distributed in the hope that it will be useful,
  19. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. ## General Public License for more details.
  22. ##
  23. ## You should have received a copy of the GNU General Public License
  24. ## along with this program; if not, write to the Free Software
  25. ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  26. ## USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
  27. ##
  28. ## NOTICE: Given that you include this file verbatim into your own
  29. ## source tree, you are justified in saying that it remains separate
  30. ## from your package, and that this way you are simply just using GNU
  31. ## shtool. So, in this situation, there is no requirement that your
  32. ## package itself is licensed under the GNU General Public License in
  33. ## order to take advantage of GNU shtool.
  34. ##
  35. ##
  36. ## Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]
  37. ##
  38. ## Available commands:
  39. ## echo Print string with optional construct expansion
  40. ## mdate Pretty-print modification time of a file or dir
  41. ## table Pretty-print a field-separated list as a table
  42. ## prop Display progress with a running propeller
  43. ## move Move files with simultaneous substitution
  44. ## install Install a program, script or datafile
  45. ## mkdir Make one or more directories
  46. ## mkln Make link with calculation of relative paths
  47. ## mkshadow Make a shadow tree through symbolic links
  48. ## fixperm Fix file permissions inside a source tree
  49. ## rotate Logfile rotation
  50. ## tarball Roll distribution tarballs
  51. ## subst Apply sed(1) substitution operations
  52. ## guessos Simple operating system guesser
  53. ## arx Extended archive command
  54. ## slo Separate linker options by library class
  55. ## scpp Sharing C Pre-Processor
  56. ## version Maintain a version information file
  57. ## path Deal with program paths
  58. ##
  59. if [ $# -eq 0 ]; then
  60. echo "$0:Error: invalid command line" 1>&2
  61. echo "$0:Hint: run \`$0 -h' for usage" 1>&2
  62. exit 1
  63. fi
  64. if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then
  65. echo "This is GNU shtool, version 1.6.0 (23-Sep-2001)"
  66. echo "Copyright (c) 1994-2001 Ralf S. Engelschall <rse@engelschall.com>"
  67. echo "Report bugs to <bug-shtool@gnu.org>"
  68. echo ''
  69. echo "Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]"
  70. echo ''
  71. echo 'Available global <options>:'
  72. echo ' -v, --version display shtool version information'
  73. echo ' -h, --help display shtool usage help page (this one)'
  74. echo ' -d, --debug display shell trace information'
  75. echo ' -r, --recreate recreate this shtool script via shtoolize'
  76. echo ''
  77. echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
  78. echo ' echo [-n|--newline] [-e|--expand] [<str> ...]'
  79. echo ' mdate [-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits]'
  80. echo ' [-f|--field-sep <str>] [-o|--order <spec>] <path>'
  81. echo ' table [-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns'
  82. echo ' <cols>] [-s|--strip <strip>] <str><sep><str>...'
  83. echo ' prop [-p|--prefix <str>]'
  84. echo ' move [-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve]'
  85. echo ' <src-file> <dst-file>'
  86. echo ' install [-v|--verbose] [-t|--trace] [-c|--copy] [-C|--compare-copy]'
  87. echo ' [-s|--strip] [-m|--mode <mode>] [-o|--owner <owner>]'
  88. echo ' [-g|--group <group>] [-e|--exec <sed-cmd>] <file> [<file>'
  89. echo ' ...] <path>'
  90. echo ' mkdir [-t|--trace] [-f|--force] [-p|--parents] [-m|--mode'
  91. echo ' <mode>] <dir> [<dir> ...]'
  92. echo ' mkln [-t|--trace] [-f|--force] [-s|--symbolic] <src-path>'
  93. echo ' [<src-path> ...] <dst-path>'
  94. echo ' mkshadow [-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>'
  95. echo ' fixperm [-v|--verbose] [-t|--trace] <path> [<path> ...]'
  96. echo ' rotate [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files'
  97. echo ' <count>] [-s|--min-size <size>] [-c|--copy] [-r|--remove]'
  98. echo ' [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>]'
  99. echo ' [-b|--background] [-d|--delay] [-p|--pad <len>] [-o|--owner'
  100. echo ' <owner>] [-g|--group <group>] [-m|--mode <mode>] [-M|--migrate'
  101. echo ' <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]'
  102. echo ' tarball [-t|--trace] [-v|--verbose] [-o|--output <tarball>]'
  103. echo ' [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user'
  104. echo ' <user>] [-g|--group <group>] [-e|--exclude <pattern>]'
  105. echo ' <path> [<path> ...]'
  106. echo ' subst [-v|--verbose] [-t|--trace] [-n|--nop] [-s|--stealth]'
  107. echo ' [-i|--interactive] [-b|--backup <ext>] [-e|--exec <cmd>]'
  108. echo ' [-f|--file <cmd-file>] [<file>] [...]'
  109. echo ' guessos '
  110. echo ' arx [-t|--trace] [-C|--command <cmd>] <op> <archive> [<file>'
  111. echo ' ...]'
  112. echo ' slo [-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib>'
  113. echo ' ...]'
  114. echo ' scpp [-v|--verbose] [-p|--preserve] [-f|--filter <filter>]'
  115. echo ' [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark'
  116. echo ' <mark>] [-D|--define <dname>] [-C|--class <cname>]'
  117. echo ' <file> [<file> ...]'
  118. echo ' version [-l|--language <lang>] [-n|--name <name>] [-p|--prefix'
  119. echo ' <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase'
  120. echo ' <knob>] [-d|--display <type>] <file>'
  121. echo ' path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename]'
  122. echo ' [-m|--magic] [-p|--path <path>] <str> [<str> ...]'
  123. echo ''
  124. exit 0
  125. fi
  126. if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then
  127. echo "GNU shtool 1.6.0 (23-Sep-2001)"
  128. exit 0
  129. fi
  130. if [ ".$1" = ".-r" -o ".$1" = ."--recreate" ]; then
  131. shtoolize -oshtool all
  132. exit 0
  133. fi
  134. if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then
  135. shift
  136. set -x
  137. fi
  138. name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
  139. case "$name" in
  140. echo|mdate|table|prop|move|install|mkdir|mkln|mkshadow|fixperm|rotate|tarball|subst|guessos|arx|slo|scpp|version|path )
  141. # implicit tool command selection
  142. tool="$name"
  143. ;;
  144. * )
  145. # explicit tool command selection
  146. tool="$1"
  147. shift
  148. ;;
  149. esac
  150. arg_spec=""
  151. opt_spec=""
  152. gen_tmpfile=no
  153. ##
  154. ## DISPATCH INTO SCRIPT PROLOG
  155. ##
  156. case $tool in
  157. echo )
  158. str_tool="echo"
  159. str_usage="[-n|--newline] [-e|--expand] [<str> ...]"
  160. arg_spec="0+"
  161. opt_spec="n.e."
  162. opt_alias="n:newline,e:expand"
  163. opt_n=no
  164. opt_e=no
  165. ;;
  166. mdate )
  167. str_tool="mdate"
  168. str_usage="[-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits] [-f|--field-sep <str>] [-o|--order <spec>] <path>"
  169. arg_spec="1="
  170. opt_spec="n.z.s.d.f:o:"
  171. opt_alias="n:newline,z:zero,s:shorten,d:digits,f:field-sep,o:order"
  172. opt_n=no
  173. opt_z=no
  174. opt_s=no
  175. opt_d=no
  176. opt_f=" "
  177. opt_o="dmy"
  178. ;;
  179. table )
  180. str_tool="table"
  181. str_usage="[-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns <cols>] [-s|--strip <strip>] <str><sep><str>..."
  182. arg_spec="1+"
  183. opt_spec="F:w:c:s:"
  184. opt_alias="F:field-sep,w:width,c:columns,s:strip"
  185. opt_F=":"
  186. opt_w=15
  187. opt_c=3
  188. opt_s=79
  189. ;;
  190. prop )
  191. str_tool="prop"
  192. str_usage="[-p|--prefix <str>]"
  193. arg_spec="0="
  194. opt_spec="p:"
  195. opt_alias="p:prefix"
  196. opt_p=""
  197. ;;
  198. move )
  199. str_tool="move"
  200. str_usage="[-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve] <src-file> <dst-file>"
  201. arg_spec="2="
  202. opt_spec="v.t.e.p."
  203. opt_alias="v:verbose,t:trace,e:expand,p:preserve"
  204. opt_v=no
  205. opt_t=no
  206. opt_e=no
  207. opt_p=no
  208. ;;
  209. install )
  210. str_tool="install"
  211. str_usage="[-v|--verbose] [-t|--trace] [-c|--copy] [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] [-e|--exec <sed-cmd>] <file> [<file> ...] <path>"
  212. arg_spec="2+"
  213. opt_spec="v.t.c.C.s.m:o:g:e+"
  214. opt_alias="v:verbose,t:trace,c:copy,C:compare-copy,s:strip,m:mode,o:owner,g:group,e:exec"
  215. opt_v=no
  216. opt_t=no
  217. opt_c=no
  218. opt_C=no
  219. opt_s=no
  220. opt_m="0755"
  221. opt_o=""
  222. opt_g=""
  223. opt_e=""
  224. ;;
  225. mkdir )
  226. str_tool="mkdir"
  227. str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode <mode>] <dir> [<dir> ...]"
  228. arg_spec="1+"
  229. opt_spec="t.f.p.m:"
  230. opt_alias="t:trace,f:force,p:parents,m:mode"
  231. opt_t=no
  232. opt_f=no
  233. opt_p=no
  234. opt_m=""
  235. ;;
  236. mkln )
  237. str_tool="mkln"
  238. str_usage="[-t|--trace] [-f|--force] [-s|--symbolic] <src-path> [<src-path> ...] <dst-path>"
  239. arg_spec="2+"
  240. opt_spec="t.f.s."
  241. opt_alias="t:trace,f:force,s:symbolic"
  242. opt_t=no
  243. opt_f=no
  244. opt_s=no
  245. ;;
  246. mkshadow )
  247. str_tool="mkshadow"
  248. str_usage="[-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>"
  249. arg_spec="2="
  250. opt_spec="v.t.a."
  251. opt_alias="v:verbose,t:trace,a:all"
  252. opt_v=no
  253. opt_t=no
  254. opt_a=no
  255. ;;
  256. fixperm )
  257. str_tool="fixperm"
  258. str_usage="[-v|--verbose] [-t|--trace] <path> [<path> ...]"
  259. arg_spec="1+"
  260. opt_spec="v.t."
  261. opt_alias="v:verbose,t:trace"
  262. opt_v=no
  263. opt_t=no
  264. ;;
  265. rotate )
  266. str_tool="rotate"
  267. str_usage="[-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files <count>] [-s|--min-size <size>] [-c|--copy] [-r|--remove] [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>] [-b|--background] [-d|--delay] [-p|--pad <len>] [-o|--owner <owner>] [-g|--group <group>] [-m|--mode <mode>] [-M|--migrate <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]"
  268. arg_spec="1+"
  269. opt_spec="v.t.f.n:s:c.r.a:z:b.d.p:o:g:m:M:P:E:"
  270. opt_alias="v:verbose,t:trace,f:force,n:num-files,s:size,m:min-size,c:copy,r:remove,a:archive-dir,z:compress,b:background,d:delay,p:pad,o:owner,g:group,m:mode,M:migrate,P:prolog,E:epilog"
  271. opt_v=no
  272. opt_t=no
  273. opt_f=no
  274. opt_n=10
  275. opt_s=""
  276. opt_c=no
  277. opt_r=no
  278. opt_a=""
  279. opt_z=""
  280. opt_b=no
  281. opt_d=no
  282. opt_p=1
  283. opt_o=""
  284. opt_g=""
  285. opt_m=""
  286. opt_M=""
  287. opt_P=""
  288. opt_E=""
  289. ;;
  290. tarball )
  291. str_tool="tarball"
  292. str_usage="[-t|--trace] [-v|--verbose] [-o|--output <tarball>] [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user <user>] [-g|--group <group>] [-e|--exclude <pattern>] <path> [<path> ...]"
  293. gen_tmpfile=yes
  294. arg_spec="1+"
  295. opt_spec="t.v.o:c:d:u:g:e:"
  296. opt_alias="t:trace,v:verbose,o:output,c:compress,d:directory,u:user,g:group,e:exclude"
  297. opt_t=no
  298. opt_v=no
  299. opt_o=""
  300. opt_c=""
  301. opt_d=""
  302. opt_u=""
  303. opt_g=""
  304. opt_e="CVS,\\.cvsignore,\\.[oa]\$"
  305. ;;
  306. subst )
  307. str_tool="subst"
  308. str_usage="[-v|--verbose] [-t|--trace] [-n|--nop] [-s|--stealth] [-i|--interactive] [-b|--backup <ext>] [-e|--exec <cmd>] [-f|--file <cmd-file>] [<file>] [...]"
  309. gen_tmpfile=yes
  310. arg_spec="0+"
  311. opt_spec="v.t.n.s.i.b:e+f:"
  312. opt_alias="v:verbose,t:trace,n:nop,s:stealth,i:interactive,b:backup,e:exec,f:file"
  313. opt_v=no
  314. opt_t=no
  315. opt_n=no
  316. opt_s=no
  317. opt_i=no
  318. opt_b=""
  319. opt_e=""
  320. opt_f=""
  321. ;;
  322. guessos )
  323. str_tool="guessos"
  324. str_usage=""
  325. arg_spec="0="
  326. opt_spec=""
  327. opt_alias=""
  328. ;;
  329. arx )
  330. str_tool="arx"
  331. str_usage="[-t|--trace] [-C|--command <cmd>] <op> <archive> [<file> ...]"
  332. arg_spec="2+"
  333. opt_spec="t.C:"
  334. opt_alias="t:trace,C:command"
  335. opt_t=no
  336. opt_C="ar"
  337. ;;
  338. slo )
  339. str_tool="slo"
  340. str_usage="[-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib> ...]"
  341. arg_spec="1+"
  342. opt_spec="p:"
  343. opt_alias="p:prefix"
  344. opt_p="SLO_"
  345. ;;
  346. scpp )
  347. str_tool="scpp"
  348. str_usage="[-v|--verbose] [-p|--preserve] [-f|--filter <filter>] [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark <mark>] [-D|--define <dname>] [-C|--class <cname>] <file> [<file> ...]"
  349. gen_tmpfile=yes
  350. arg_spec="1+"
  351. opt_spec="v.p.f+o:t:M:D:C:"
  352. opt_alias="v:verbose,p:preserve,f:filter,o:output,t:template,M:mark,D:define,C:class"
  353. opt_v=no
  354. opt_p=no
  355. opt_f=""
  356. opt_o="lib.h"
  357. opt_t="lib.h.in"
  358. opt_M="%%MARK%%"
  359. opt_D="cpp"
  360. opt_C="intern"
  361. ;;
  362. version )
  363. str_tool="version"
  364. str_usage="[-l|--language <lang>] [-n|--name <name>] [-p|--prefix <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase <knob>] [-d|--display <type>] <file>"
  365. arg_spec="1="
  366. opt_spec="l:n:p:s:i:e.d:"
  367. opt_alias="l:language,n:name,p:prefix,s:set,e:edit,i:increase,d:display"
  368. opt_l="txt"
  369. opt_n="unknown"
  370. opt_p=""
  371. opt_s=""
  372. opt_e="no"
  373. opt_i=""
  374. opt_d="short"
  375. ;;
  376. path )
  377. str_tool="path"
  378. str_usage="[-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path <path>] <str> [<str> ...]"
  379. gen_tmpfile=yes
  380. arg_spec="1+"
  381. opt_spec="s.r.d.b.m.p:"
  382. opt_alias="s:suppress,r:reverse,d:dirname,b:basename,m:magic,p:path"
  383. opt_s=no
  384. opt_r=no
  385. opt_d=no
  386. opt_b=no
  387. opt_m=no
  388. opt_p="$PATH"
  389. ;;
  390. -* )
  391. echo "$0:Error: unknown option \`$tool'" 2>&1
  392. echo "$0:Hint: run \`$0 -h' for usage" 2>&1
  393. exit 1
  394. ;;
  395. * )
  396. echo "$0:Error: unknown command \`$tool'" 2>&1
  397. echo "$0:Hint: run \`$0 -h' for usage" 2>&1
  398. exit 1
  399. ;;
  400. esac
  401. ##
  402. ## COMMON UTILITY CODE
  403. ##
  404. # commonly used ASCII values
  405. ASC_TAB=" "
  406. ASC_NL="
  407. "
  408. # determine name of tool
  409. if [ ".$tool" != . ]; then
  410. # used inside shtool script
  411. toolcmd="$0 $tool"
  412. toolcmdhelp="shtool $tool"
  413. msgprefix="shtool:$tool"
  414. else
  415. # used as standalone script
  416. toolcmd="$0"
  417. toolcmdhelp="sh $0"
  418. msgprefix="$str_tool"
  419. fi
  420. # parse argument specification string
  421. eval `echo $arg_spec |\
  422. sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
  423. # parse option specification string
  424. eval `echo h.$opt_spec |\
  425. sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
  426. # parse option alias string
  427. eval `echo h:help,$opt_alias |\
  428. tr 'x-' 'x_' | sed -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'`
  429. # interate over argument line
  430. opt_PREV=''
  431. while [ $# -gt 0 ]; do
  432. # special option stops processing
  433. if [ ".$1" = ".--" ]; then
  434. shift
  435. break
  436. fi
  437. # determine option and argument
  438. opt_ARG_OK=no
  439. if [ ".$opt_PREV" != . ]; then
  440. # merge previous seen option with argument
  441. opt_OPT="$opt_PREV"
  442. opt_ARG="$1"
  443. opt_ARG_OK=yes
  444. opt_PREV=''
  445. else
  446. # split argument into option and argument
  447. case "$1" in
  448. --[a-zA-Z0-9]*=*)
  449. eval `echo "x$1" |\
  450. sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'`
  451. opt_STR=`echo $opt_OPT | tr 'x-' 'x_'`
  452. eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
  453. ;;
  454. --[a-zA-Z0-9]*)
  455. opt_OPT=`echo "x$1" | cut -c4-`
  456. opt_STR=`echo $opt_OPT | tr 'x-' 'x_'`
  457. eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
  458. opt_ARG=''
  459. ;;
  460. -[a-zA-Z0-9]*)
  461. eval `echo "x$1" |\
  462. sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
  463. -e 's/";\(.*\)$/"; opt_ARG="\1"/'`
  464. ;;
  465. -[a-zA-Z0-9])
  466. opt_OPT=`echo "x$1" | cut -c3-`
  467. opt_ARG=''
  468. ;;
  469. *)
  470. break
  471. ;;
  472. esac
  473. fi
  474. # eat up option
  475. shift
  476. # determine whether option needs an argument
  477. eval "opt_MODE=\$opt_MODE_${opt_OPT}"
  478. if [ ".$opt_ARG" = . -a ".$opt_ARG_OK" != .yes ]; then
  479. if [ ".$opt_MODE" = ".:" -o ".$opt_MODE" = ".+" ]; then
  480. opt_PREV="$opt_OPT"
  481. continue
  482. fi
  483. fi
  484. # process option
  485. case $opt_MODE in
  486. '.' )
  487. # boolean option
  488. eval "opt_${opt_OPT}=yes"
  489. ;;
  490. ':' )
  491. # option with argument (multiple occurances override)
  492. eval "opt_${opt_OPT}=\"\$opt_ARG\""
  493. ;;
  494. '+' )
  495. # option with argument (multiple occurances append)
  496. eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\""
  497. ;;
  498. * )
  499. echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2
  500. echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
  501. exit 1
  502. ;;
  503. esac
  504. done
  505. if [ ".$opt_PREV" != . ]; then
  506. echo "$msgprefix:Error: missing argument to option \`$opt_PREV'" 1>&2
  507. echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
  508. exit 1
  509. fi
  510. # process help option
  511. if [ ".$opt_h" = .yes ]; then
  512. echo "Usage: $toolcmdhelp $str_usage"
  513. exit 0
  514. fi
  515. # complain about incorrect number of arguments
  516. case $arg_MODE in
  517. '=' )
  518. if [ $# -ne $arg_NUMS ]; then
  519. echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2
  520. echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
  521. exit 1
  522. fi
  523. ;;
  524. '+' )
  525. if [ $# -lt $arg_NUMS ]; then
  526. echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2
  527. echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
  528. exit 1
  529. fi
  530. ;;
  531. esac
  532. # establish a temporary file on request
  533. if [ ".$gen_tmpfile" = .yes ]; then
  534. if [ ".$TMPDIR" != . ]; then
  535. tmpdir="$TMPDIR"
  536. elif [ ".$TEMPDIR" != . ]; then
  537. tmpdir="$TEMPDIR"
  538. else
  539. tmpdir="/tmp"
  540. fi
  541. tmpfile="$tmpdir/.shtool.$$"
  542. rm -f $tmpfile >/dev/null 2>&1
  543. touch $tmpfile
  544. chmod 600 $tmpfile
  545. fi
  546. ##
  547. ## DISPATCH INTO SCRIPT BODY
  548. ##
  549. case $tool in
  550. echo )
  551. ##
  552. ## echo -- Print string with optional construct expansion
  553. ## Copyright (c) 1998-2001 Ralf S. Engelschall <rse@engelschall.com>
  554. ## Originally written for WML as buildinfo
  555. ##
  556. text="$*"
  557. # check for broken escape sequence expansion
  558. seo=''
  559. bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
  560. if [ ".$bytes" != .3 ]; then
  561. bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'`
  562. if [ ".$bytes" = .3 ]; then
  563. seo='-E'
  564. fi
  565. fi
  566. # check for existing -n option (to suppress newline)
  567. minusn=''
  568. bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'`
  569. if [ ".$bytes" = .3 ]; then
  570. minusn='-n'
  571. fi
  572. # determine terminal bold sequence
  573. term_bold=''
  574. term_norm=''
  575. if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[Bb]'`" != . ]; then
  576. case $TERM in
  577. # for the most important terminal types we directly know the sequences
  578. xterm|xterm*|vt220|vt220*)
  579. term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
  580. term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
  581. ;;
  582. vt100|vt100*)
  583. term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
  584. term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
  585. ;;
  586. # for all others, we try to use a possibly existing `tput' or `tcout' utility
  587. * )
  588. paths=`echo $PATH | sed -e 's/:/ /g'`
  589. for tool in tput tcout; do
  590. for dir in $paths; do
  591. if [ -r "$dir/$tool" ]; then
  592. for seq in bold md smso; do # 'smso' is last
  593. bold="`$dir/$tool $seq 2>/dev/null`"
  594. if [ ".$bold" != . ]; then
  595. term_bold="$bold"
  596. break
  597. fi
  598. done
  599. if [ ".$term_bold" != . ]; then
  600. for seq in sgr0 me rmso reset; do # 'reset' is last
  601. norm="`$dir/$tool $seq 2>/dev/null`"
  602. if [ ".$norm" != . ]; then
  603. term_norm="$norm"
  604. break
  605. fi
  606. done
  607. fi
  608. break
  609. fi
  610. done
  611. if [ ".$term_bold" != . -a ".$term_norm" != . ]; then
  612. break;
  613. fi
  614. done
  615. ;;
  616. esac
  617. if [ ".$term_bold" = . -o ".$term_norm" = . ]; then
  618. echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2
  619. fi
  620. fi
  621. # determine user name
  622. username=''
  623. if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[uUgG]'`" != . ]; then
  624. username="$LOGNAME"
  625. if [ ".$username" = . ]; then
  626. username="$USER"
  627. if [ ".$username" = . ]; then
  628. username="`(whoami) 2>/dev/null |\
  629. awk '{ printf("%s", $1); }'`"
  630. if [ ".$username" = . ]; then
  631. username="`(who am i) 2>/dev/null |\
  632. awk '{ printf("%s", $1); }'`"
  633. if [ ".$username" = . ]; then
  634. username='unknown'
  635. fi
  636. fi
  637. fi
  638. fi
  639. fi
  640. # determine user id
  641. userid=''
  642. if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%U'`" != . ]; then
  643. userid="`(id -u) 2>/dev/null`"
  644. if [ ".$userid" = . ]; then
  645. str="`(id) 2>/dev/null`"
  646. if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
  647. userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*//'`
  648. fi
  649. if [ ".$userid" = . ]; then
  650. userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
  651. sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  652. if [ ".$userid" = . ]; then
  653. userid=`(ypcat passwd) 2>/dev/null |
  654. egrep "^${username}:" | \
  655. sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  656. if [ ".$userid" = . ]; then
  657. userid='?'
  658. fi
  659. fi
  660. fi
  661. fi
  662. fi
  663. # determine (primary) group id
  664. groupid=''
  665. if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[gG]'`" != . ]; then
  666. groupid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
  667. sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
  668. if [ ".$groupid" = . ]; then
  669. groupid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \
  670. sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
  671. if [ ".$groupid" = . ]; then
  672. groupid='?'
  673. fi
  674. fi
  675. fi
  676. # determine (primary) group name
  677. groupname=''
  678. if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%g'`" != . ]; then
  679. groupname=`egrep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
  680. sed -e 's/:.*$//'`
  681. if [ ".$groupname" = . ]; then
  682. groupname=`(ypcat group) 2>/dev/null | \
  683. egrep "^[^:]*:[^:]*:${groupid}:" | \
  684. sed -e 's/:.*$//'`
  685. if [ ".$groupname" = . ]; then
  686. groupname='?'
  687. fi
  688. fi
  689. fi
  690. # determine host and domain name
  691. hostname=''
  692. domainname=''
  693. if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%h'`" != . ]; then
  694. hostname="`(uname -n) 2>/dev/null |\
  695. awk '{ printf("%s", $1); }'`"
  696. if [ ".$hostname" = . ]; then
  697. hostname="`(hostname) 2>/dev/null |\
  698. awk '{ printf("%s", $1); }'`"
  699. if [ ".$hostname" = . ]; then
  700. hostname='unknown'
  701. fi
  702. fi
  703. case $hostname in
  704. *.* )
  705. domainname=".`echo $hostname | cut -d. -f2-`"
  706. hostname="`echo $hostname | cut -d. -f1`"
  707. ;;
  708. esac
  709. fi
  710. if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%d'`" != . ]; then
  711. if [ ".$domainname" = . ]; then
  712. if [ -f /etc/resolv.conf ]; then
  713. domainname="`egrep '^[ ]*domain' /etc/resolv.conf | head -1 |\
  714. sed -e 's/.*domain//' \
  715. -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
  716. -e 's/^\.//' -e 's/^/./' |\
  717. awk '{ printf("%s", $1); }'`"
  718. if [ ".$domainname" = . ]; then
  719. domainname="`egrep '^[ ]*search' /etc/resolv.conf | head -1 |\
  720. sed -e 's/.*search//' \
  721. -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
  722. -e 's/ .*//' -e 's/ .*//' \
  723. -e 's/^\.//' -e 's/^/./' |\
  724. awk '{ printf("%s", $1); }'`"
  725. fi
  726. fi
  727. fi
  728. fi
  729. # determine current time
  730. time_day=''
  731. time_month=''
  732. time_year=''
  733. time_monthname=''
  734. if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[DMYm]'`" != . ]; then
  735. time_day=`date '+%d'`
  736. time_month=`date '+%m'`
  737. time_year=`date '+%Y' 2>/dev/null`
  738. if [ ".$time_year" = . ]; then
  739. time_year=`date '+%y'`
  740. case $time_year in
  741. [5-9][0-9]) time_year="19$time_year" ;;
  742. [0-4][0-9]) time_year="20$time_year" ;;
  743. esac
  744. fi
  745. case $time_month in
  746. 1|01) time_monthname='Jan' ;;
  747. 2|02) time_monthname='Feb' ;;
  748. 3|03) time_monthname='Mar' ;;
  749. 4|04) time_monthname='Apr' ;;
  750. 5|05) time_monthname='May' ;;
  751. 6|06) time_monthname='Jun' ;;
  752. 7|07) time_monthname='Jul' ;;
  753. 8|08) time_monthname='Aug' ;;
  754. 9|09) time_monthname='Sep' ;;
  755. 10) time_monthname='Oct' ;;
  756. 11) time_monthname='Nov' ;;
  757. 12) time_monthname='Dec' ;;
  758. esac
  759. fi
  760. # expand special ``%x'' constructs
  761. if [ ".$opt_e" = .yes ]; then
  762. text=`echo $seo "$text" |\
  763. sed -e "s/%B/${term_bold}/g" \
  764. -e "s/%b/${term_norm}/g" \
  765. -e "s/%u/${username}/g" \
  766. -e "s/%U/${userid}/g" \
  767. -e "s/%g/${groupname}/g" \
  768. -e "s/%G/${groupid}/g" \
  769. -e "s/%h/${hostname}/g" \
  770. -e "s/%d/${domainname}/g" \
  771. -e "s/%D/${time_day}/g" \
  772. -e "s/%M/${time_month}/g" \
  773. -e "s/%Y/${time_year}/g" \
  774. -e "s/%m/${time_monthname}/g" 2>/dev/null`
  775. fi
  776. # create output
  777. if [ .$opt_n = .no ]; then
  778. echo $seo "$text"
  779. else
  780. # the harder part: echo -n is best, because
  781. # awk may complain about some \xx sequences.
  782. if [ ".$minusn" != . ]; then
  783. echo $seo $minusn "$text"
  784. else
  785. echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text"
  786. fi
  787. fi
  788. ;;
  789. mdate )
  790. ##
  791. ## mdate -- Pretty-print modification time of a file or dir
  792. ## Copyright (c) 1995-1997 Free Software Foundation, Inc.
  793. ## Originally idea and basis code by Ulrich Drepper
  794. ## Enhanced by Ralf S. Engelschall for shtool
  795. ##
  796. fod="$1"
  797. case "$opt_o" in
  798. [dmy][dmy][dmy] )
  799. ;;
  800. * ) echo "$msgprefix:Error: invalid argument to option \`-o': $opt_o" 1>&2
  801. exit 1
  802. ;;
  803. esac
  804. if [ ! -r "$fod" ]; then
  805. echo "$msgprefix:Error: file or directory not found: $fod" 1>&2
  806. exit 1
  807. fi
  808. # prevent "date" giving response in another language
  809. LANG=C; export LANG
  810. LC_ALL=C; export LC_ALL
  811. LC_TIME=C; export LC_TIME
  812. # get the extended ls output of the file or directory.
  813. if ls -L /dev/null >/dev/null 2>&1; then
  814. set - x`ls -L -l -d $fod`
  815. else
  816. set - x`ls -l -d $fod`
  817. fi
  818. # The month is at least the fourth argument
  819. # (3 shifts here, the next inside the loop).
  820. shift; shift; shift
  821. # Find the month. Next argument is day, followed by the year or time.
  822. month=""
  823. while [ ".$month" = . ]; do
  824. shift
  825. case $1 in
  826. Jan) month=January; nummonth=1 ;;
  827. Feb) month=February; nummonth=2 ;;
  828. Mar) month=March; nummonth=3 ;;
  829. Apr) month=April; nummonth=4 ;;
  830. May) month=May; nummonth=5 ;;
  831. Jun) month=June; nummonth=6 ;;
  832. Jul) month=July; nummonth=7 ;;
  833. Aug) month=August; nummonth=8 ;;
  834. Sep) month=September; nummonth=9 ;;
  835. Oct) month=October; nummonth=10 ;;
  836. Nov) month=November; nummonth=11 ;;
  837. Dec) month=December; nummonth=12 ;;
  838. esac
  839. done
  840. day="$2"
  841. year="$3"
  842. # We finally have to deal with the problem that the "ls" output
  843. # gives either the time of the day or the year.
  844. case $year in
  845. *:*)
  846. this_year=`date '+%Y' 2>/dev/null`
  847. if [ ".$this_year" = . ]; then
  848. this_year=`date '+%y'`
  849. case $this_year in
  850. [5-9][0-9]) this_year="19$this_year" ;;
  851. [0-4][0-9]) this_year="20$this_year" ;;
  852. esac
  853. fi
  854. # for the following months of the last year the time notation
  855. # is usually also used for files modified in the last year.
  856. this_month=`date '+%m'`
  857. if (expr $nummonth \> $this_month) >/dev/null; then
  858. this_year=`expr $this_year - 1`
  859. fi
  860. year="$this_year"
  861. ;;
  862. esac
  863. # Optionally fill day and month with leeding zeros
  864. if [ ".$opt_z" = .yes ]; then
  865. case $day in
  866. [0-9][0-9] ) ;;
  867. [0-9] ) day="0$day" ;;
  868. esac
  869. case $nummonth in
  870. [0-9][0-9] ) ;;
  871. [0-9] ) nummonth="0$nummonth" ;;
  872. esac
  873. fi
  874. # Optionally use digits for month
  875. if [ ".$opt_d" = .yes ]; then
  876. month="$nummonth"
  877. fi
  878. # Optionally shorten the month name to three characters
  879. if [ ".$opt_s" = .yes ]; then
  880. month=`echo $month | cut -c1-3`
  881. fi
  882. # Output the resulting date string
  883. echo dummy | awk '{
  884. for (i = 0; i < 3; i++) {
  885. now = substr(order, 1, 1);
  886. order = substr(order, 2);
  887. if (now == "d")
  888. out = day;
  889. else if (now == "m")
  890. out = month;
  891. else if (now == "y")
  892. out = year;
  893. if (i < 2)
  894. printf("%s%s", out, field);
  895. else
  896. printf("%s", out);
  897. }
  898. if (newline != "yes")
  899. printf("\n");
  900. }' "day=$day" "month=$month" "year=$year" \
  901. "field=$opt_f" "order=$opt_o" "newline=$opt_n"
  902. ;;
  903. table )
  904. ##
  905. ## table -- Pretty-print a field-separated list as a table
  906. ## Copyright (c) 1998-2001 Ralf S. Engelschall <rse@engelschall.com>
  907. ## Originally written for Apache
  908. ##
  909. if [ $opt_c -gt 4 ]; then
  910. echo "$msgprefix:Error: Invalid number of colums (1..4 allowed only)" 1>&2
  911. exit 1
  912. fi
  913. case "x$opt_F" in
  914. x? ) ;;
  915. * ) echo "$msgprefix:Error: Invalid separator (one char allowed only)" 1>&2; exit 1 ;;
  916. esac
  917. # split the list into a table
  918. list=`
  919. IFS="$opt_F"
  920. for entry in $*; do
  921. if [ ".$entry" != . ]; then
  922. echo "$entry"
  923. fi
  924. done |\
  925. awk "
  926. BEGIN { list = \"\"; n = 0; }
  927. {
  928. list = list \\$1;
  929. n = n + 1;
  930. if (n < $opt_c) {
  931. list = list \":\";
  932. }
  933. if (n == $opt_c) {
  934. list = list \"\\n\";
  935. n = 0;
  936. }
  937. }
  938. END { print list; }
  939. "
  940. `
  941. # format table cells and make sure table
  942. # doesn't exceed maximum width
  943. OIFS="$IFS"
  944. IFS='
  945. '
  946. for entry in $list; do
  947. case $opt_c in
  948. 1 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s\\n\", \$1); }'" ;;
  949. 2 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s\\n\", \$1, \$2); }'" ;;
  950. 3 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s %-${opt_w}s\\n\", \$1, \$2, \$3); }'" ;;
  951. 4 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s %-${opt_w}s %-${opt_w}s\\n\", \$1, \$2, \$3, \$4); }'" ;;
  952. esac
  953. done |\
  954. awk "{
  955. if (length(\$0) > $opt_s) {
  956. printf(\"%s\\n\", substr(\$0, 0, $opt_s-1));
  957. } else {
  958. print \$0;
  959. }
  960. }"
  961. IFS="$OIFS"
  962. ;;
  963. prop )
  964. ##
  965. ## prop -- Display progress with a running propeller
  966. ## Copyright (c) 1998-2001 Ralf S. Engelschall <rse@engelschall.com>
  967. ## Originally written for mod_ssl
  968. ##
  969. perl=''
  970. for dir in `echo $PATH | sed -e 's/:/ /g'` .; do
  971. if [ -f "$dir/perl" ]; then
  972. perl="$dir/perl"
  973. break
  974. fi
  975. done
  976. if [ ".$perl" != . ]; then
  977. # Perl is preferred because writing to STDERR in
  978. # Perl really writes immediately as one would expect
  979. $perl -e '
  980. @p = ("|","/","-","\\");
  981. $i = 0;
  982. while (<STDIN>) {
  983. printf(STDERR "\r%s...%s\b", $ARGV[0], $p[$i++]);
  984. $i = 0 if ($i > 3);
  985. }
  986. printf(STDERR "\r%s \n", $ARGV[0]);
  987. ' "$opt_p"
  988. else
  989. # But if Perl doesn't exists we use Awk even
  990. # some Awk's buffer even the /dev/stderr writing :-(
  991. awk '
  992. BEGIN {
  993. split("|#/#-#\\", p, "#");
  994. i = 1;
  995. }
  996. {
  997. printf("\r%s%c\b", prefix, p[i++]) > "/dev/stderr";
  998. if (i > 4) { i = 1; }
  999. }
  1000. END {
  1001. printf("\r%s \n", prefix) > "/dev/stderr";
  1002. }
  1003. ' "prefix=$opt_p"
  1004. fi
  1005. ;;
  1006. move )
  1007. ##
  1008. ## move -- Move files with simultaneous substitution
  1009. ## Copyright (c) 1999-2001 Ralf S. Engelschall <rse@engelschall.com>
  1010. ## Originally written for shtool
  1011. ##
  1012. src="$1"
  1013. dst="$2"
  1014. # consistency checks
  1015. if [ ".$src" = . -o ".$dst" = . ]; then
  1016. echo "$msgprefix:Error: Invalid arguments" 1>&2
  1017. exit 1
  1018. fi
  1019. if [ ".$src" = ".$dst" ]; then
  1020. echo "$msgprefix:Error: Source and destination files are the same" 1>&2
  1021. exit 1
  1022. fi
  1023. expsrc="$src"
  1024. if [ ".$opt_e" = .yes ]; then
  1025. expsrc="`echo $expsrc`"
  1026. fi
  1027. if [ ".$opt_e" = .yes ]; then
  1028. if [ ".`echo "$src" | sed -e 's;^.*\\*.*$;;'`" = ".$src" ]; then
  1029. echo "$msgprefix:Error: Source doesn't contain wildcard ('*'): $dst" 1>&2
  1030. exit 1
  1031. fi
  1032. if [ ".`echo "$dst" | sed -e 's;^.*%[1-9].*$;;'`" = ".$dst" ]; then
  1033. echo "$msgprefix:Error: Destination doesn't contain substitution ('%N'): $dst" 1>&2
  1034. exit 1
  1035. fi
  1036. if [ ".$expsrc" = ".$src" ]; then
  1037. echo "$msgprefix:Error: Sources not found or no asterisk : $src" 1>&2
  1038. exit 1
  1039. fi
  1040. else
  1041. if [ ! -r "$src" ]; then
  1042. echo "$msgprefix:Error: Source not found: $src" 1>&2
  1043. exit 1
  1044. fi
  1045. fi
  1046. # determine substitution patterns
  1047. if [ ".$opt_e" = .yes ]; then
  1048. srcpat=`echo "$src" | sed -e 's/\\./\\\\./g' -e 's/;/\\;/g' -e 's;\\*;\\\\(.*\\\\);g'`
  1049. dstpat=`echo "$dst" | sed -e 's;%\([1-9]\);\\\\\1;g'`
  1050. fi
  1051. # iterate over source(s)
  1052. for onesrc in $expsrc; do
  1053. if [ .$opt_e = .yes ]; then
  1054. onedst=`echo $onesrc | sed -e "s;$srcpat;$dstpat;"`
  1055. else
  1056. onedst="$dst"
  1057. fi
  1058. errorstatus=0
  1059. if [ ".$opt_v" = .yes ]; then
  1060. echo "$onesrc -> $onedst"
  1061. fi
  1062. if [ ".$opt_p" = .yes ]; then
  1063. if [ -r $onedst ]; then
  1064. if cmp -s $onesrc $onedst; then
  1065. if [ ".$opt_t" = .yes ]; then
  1066. echo "rm -f $onesrc" 1>&2
  1067. fi
  1068. rm -f $onesrc || errorstatus=$?
  1069. else
  1070. if [ ".$opt_t" = .yes ]; then
  1071. echo "mv -f $onesrc $onedst" 1>&2
  1072. fi
  1073. mv -f $onesrc $onedst || errorstatus=$?
  1074. fi
  1075. else
  1076. if [ ".$opt_t" = .yes ]; then
  1077. echo "mv -f $onesrc $onedst" 1>&2
  1078. fi
  1079. mv -f $onesrc $onedst || errorstatus=$?
  1080. fi
  1081. else
  1082. if [ ".$opt_t" = .yes ]; then
  1083. echo "mv -f $onesrc $onedst" 1>&2
  1084. fi
  1085. mv -f $onesrc $onedst || errorstatus=$?
  1086. fi
  1087. if [ $errorstatus -ne 0 ]; then
  1088. break;
  1089. fi
  1090. done
  1091. exit $errorstatus
  1092. ;;
  1093. install )
  1094. ##
  1095. ## install -- Install a program, script or datafile
  1096. ## Copyright (c) 1997-2001 Ralf S. Engelschall <rse@engelschall.com>
  1097. ## Originally written for shtool
  1098. ##
  1099. # determine source(s) and destination
  1100. argc=$#
  1101. srcs=""
  1102. while [ $# -gt 1 ]; do
  1103. srcs="$srcs $1"
  1104. shift
  1105. done
  1106. dstpath="$1"
  1107. # type check for destination
  1108. dstisdir=0
  1109. if [ -d $dstpath ]; then
  1110. dstpath=`echo "$dstpath" | sed -e 's:/$::'`
  1111. dstisdir=1
  1112. fi
  1113. # consistency check for destination
  1114. if [ $argc -gt 2 -a $dstisdir = 0 ]; then
  1115. echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2
  1116. exit 1
  1117. fi
  1118. # iterate over all source(s)
  1119. for src in $srcs; do
  1120. dst=$dstpath
  1121. # if destination is a directory, append the input filename
  1122. if [ $dstisdir = 1 ]; then
  1123. dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
  1124. dst="$dst/$dstfile"
  1125. fi
  1126. # check for correct arguments
  1127. if [ ".$src" = ".$dst" ]; then
  1128. echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2
  1129. continue
  1130. fi
  1131. if [ -d "$src" ]; then
  1132. echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2
  1133. continue
  1134. fi
  1135. # make a temp file name in the destination directory
  1136. dsttmp=`echo $dst |\
  1137. sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \
  1138. -e "s;\$;/#INST@$$#;"`
  1139. # verbosity
  1140. if [ ".$opt_v" = .yes ]; then
  1141. echo "$src -> $dst" 1>&2
  1142. fi
  1143. # copy or move the file name to the temp name
  1144. # (because we might be not allowed to change the source)
  1145. if [ ".$opt_C" = .yes ]; then
  1146. opt_c=yes
  1147. fi
  1148. if [ ".$opt_c" = .yes ]; then
  1149. if [ ".$opt_t" = .yes ]; then
  1150. echo "cp $src $dsttmp" 1>&2
  1151. fi
  1152. cp $src $dsttmp || exit $?
  1153. else
  1154. if [ ".$opt_t" = .yes ]; then
  1155. echo "mv $src $dsttmp" 1>&2
  1156. fi
  1157. mv $src $dsttmp || exit $?
  1158. fi
  1159. # adjust the target file
  1160. if [ ".$opt_e" != . ]; then
  1161. sed='sed'
  1162. OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
  1163. for e
  1164. do
  1165. sed="$sed -e '$e'"
  1166. done
  1167. cp $dsttmp $dsttmp.old
  1168. eval "$sed <$dsttmp.old >$dsttmp" || exit $?
  1169. rm -f $dsttmp.old
  1170. fi
  1171. if [ ".$opt_s" = .yes ]; then
  1172. if [ ".$opt_t" = .yes ]; then
  1173. echo "strip $dsttmp" 1>&2
  1174. fi
  1175. strip $dsttmp || exit $?
  1176. fi
  1177. if [ ".$opt_o" != . ]; then
  1178. if [ ".$opt_t" = .yes ]; then
  1179. echo "chown $opt_o $dsttmp" 1>&2
  1180. fi
  1181. chown $opt_o $dsttmp || exit $?
  1182. fi
  1183. if [ ".$opt_g" != . ]; then
  1184. if [ ".$opt_t" = .yes ]; then
  1185. echo "chgrp $opt_g $dsttmp" 1>&2
  1186. fi
  1187. chgrp $opt_g $dsttmp || exit $?
  1188. fi
  1189. if [ ".$opt_m" != ".-" ]; then
  1190. if [ ".$opt_t" = .yes ]; then
  1191. echo "chmod $opt_m $dsttmp" 1>&2
  1192. fi
  1193. chmod $opt_m $dsttmp || exit $?
  1194. fi
  1195. # determine whether to do a quick install
  1196. # (has to be done _after_ the strip was already done)
  1197. quick=no
  1198. if [ ".$opt_C" = .yes ]; then
  1199. if [ -r $dst ]; then
  1200. if cmp -s $src $dst; then
  1201. quick=yes
  1202. fi
  1203. fi
  1204. fi
  1205. # finally, install the file to the real destination
  1206. if [ $quick = yes ]; then
  1207. if [ ".$opt_t" = .yes ]; then
  1208. echo "rm -f $dsttmp" 1>&2
  1209. fi
  1210. rm -f $dsttmp
  1211. else
  1212. if [ ".$opt_t" = .yes ]; then
  1213. echo "rm -f $dst && mv $dsttmp $dst" 1>&2
  1214. fi
  1215. rm -f $dst && mv $dsttmp $dst
  1216. fi
  1217. done
  1218. ;;
  1219. mkdir )
  1220. ##
  1221. ## mkdir -- Make one or more directories
  1222. ## Copyright (c) 1996-2001 Ralf S. Engelschall <rse@engelschall.com>
  1223. ## Originally written for public domain by Noah Friedman <friedman@prep.ai.mit.edu>
  1224. ## Cleaned up and enhanced for shtool
  1225. ##
  1226. errstatus=0
  1227. for p in ${1+"$@"}; do
  1228. # if the directory already exists...
  1229. if [ -d "$p" ]; then
  1230. if [ ".$opt_f" = .no -a ".$opt_p" = .no ]; then
  1231. echo "$msgprefix:Error: directory already exists: $p" 1>&2
  1232. errstatus=1
  1233. break
  1234. else
  1235. continue
  1236. fi
  1237. fi
  1238. # if the directory has to be created...
  1239. if [ ".$opt_p" = .no ]; then
  1240. if [ ".$opt_t" = .yes ]; then
  1241. echo "mkdir $p" 1>&2
  1242. fi
  1243. mkdir $p || errstatus=$?
  1244. if [ ".$opt_m" != . ]; then
  1245. if [ ".$opt_t" = .yes ]; then
  1246. echo "chmod $opt_m $p" 1>&2
  1247. fi
  1248. chmod $opt_m $p || errstatus=$?
  1249. fi
  1250. else
  1251. # the smart situation
  1252. set fnord `echo ":$p" |\
  1253. sed -e 's/^:\//%/' \
  1254. -e 's/^://' \
  1255. -e 's/\// /g' \
  1256. -e 's/^%/\//'`
  1257. shift
  1258. pathcomp=''
  1259. for d in ${1+"$@"}; do
  1260. pathcomp="$pathcomp$d"
  1261. case "$pathcomp" in
  1262. -* ) pathcomp="./$pathcomp" ;;
  1263. esac
  1264. if [ ! -d "$pathcomp" ]; then
  1265. if [ ".$opt_t" = .yes ]; then
  1266. echo "mkdir $pathcomp" 1>&2
  1267. fi
  1268. mkdir $pathcomp || errstatus=$?
  1269. if [ ".$opt_m" != . ]; then
  1270. if [ ".$opt_t" = .yes ]; then
  1271. echo "chmod $opt_m $pathcomp" 1>&2
  1272. fi
  1273. chmod $opt_m $pathcomp || errstatus=$?
  1274. fi
  1275. fi
  1276. pathcomp="$pathcomp/"
  1277. done
  1278. fi
  1279. done
  1280. exit $errstatus
  1281. ;;
  1282. mkln )
  1283. ##
  1284. ## mkln -- Make link with calculation of relative paths
  1285. ## Copyright (c) 1999-2001 Ralf S. Engelschall <rse@engelschall.com>
  1286. ## Originally written for shtool
  1287. ##
  1288. args=$?
  1289. srcs=""
  1290. while [ $# -gt 1 ]; do
  1291. srcs="$srcs $1"
  1292. shift
  1293. done
  1294. dst="$1"
  1295. if [ ! -d $dst ]; then
  1296. if [ $args -gt 2 ]; then
  1297. echo "$msgprefix:Error: multiple sources not allowed when target isn't a directory" 1>&2
  1298. exit 1
  1299. fi
  1300. fi
  1301. # determine link options
  1302. lnopt=""
  1303. if [ ".$opt_f" = .yes ]; then
  1304. lnopt="$lnopt -f"
  1305. fi
  1306. if [ ".$opt_s" = .yes ]; then
  1307. lnopt="$lnopt -s"
  1308. fi
  1309. # iterate over sources
  1310. for src in $srcs; do
  1311. # determine if one of the paths is an absolute path,
  1312. # because then we _have_ to use an absolute symlink
  1313. oneisabs=0
  1314. srcisabs=0
  1315. dstisabs=0
  1316. case $src in
  1317. /* ) oneisabs=1; srcisabs=1 ;;
  1318. esac
  1319. case $dst in
  1320. /* ) oneisabs=1; dstisabs=1 ;;
  1321. esac
  1322. # split source and destination into dir and base name
  1323. if [ -d $src ]; then
  1324. srcdir=`echo $src | sed -e 's;/*$;;'`
  1325. srcbase=""
  1326. else
  1327. srcdir=`echo $src | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`
  1328. srcbase=`echo $src | sed -e 's;.*/\([^/]*\)$;\1;'`
  1329. fi
  1330. if [ -d $dst ]; then
  1331. dstdir=`echo $dst | sed -e 's;/*$;;'`
  1332. dstbase=""
  1333. else
  1334. dstdir=`echo $dst | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`
  1335. dstbase=`echo $dst | sed -e 's;.*/\([^/]*\)$;\1;'`
  1336. fi
  1337. # consistency check
  1338. if [ ".$dstdir" != . ]; then
  1339. if [ ! -d $dstdir ]; then
  1340. echo "$msgprefix:Error: destination directory not found: $dstdir" 1>&2
  1341. exit 1
  1342. fi
  1343. fi
  1344. # make sure the source is reachable from the destination
  1345. if [ $dstisabs = 1 ]; then
  1346. if [ $srcisabs = 0 ]; then
  1347. if [ -d $srcdir ]; then
  1348. srcdir="`cd $srcdir; pwd | sed -e 's;/*$;;'`"
  1349. srcisabs=1
  1350. oneisabs=1
  1351. fi
  1352. fi
  1353. fi
  1354. # split away a common prefix
  1355. prefix=""
  1356. if [ ".$srcdir" = ".$dstdir" -a ".$srcdir" != . ]; then
  1357. prefix="$srcdir/"
  1358. srcdir=""
  1359. dstdir=""
  1360. else
  1361. while [ ".$srcdir" != . -a ".$dstdir" != . ]; do
  1362. presrc=`echo $srcdir | sed -e 's;^\([^/]*\)/.*;\1;'`
  1363. predst=`echo $dstdir | sed -e 's;^\([^/]*\)/.*;\1;'`
  1364. if [ ".$presrc" != ".$predst" ]; then
  1365. break
  1366. fi
  1367. prefix="$prefix$presrc/"
  1368. srcdir=`echo $srcdir | sed -e 's;^[^/]*/*;;'`
  1369. dstdir=`echo $dstdir | sed -e 's;^[^/]*/*;;'`
  1370. done
  1371. fi
  1372. # destination prefix is just the common prefix
  1373. dstpre="$prefix"
  1374. # determine source prefix which is the reverse directory
  1375. # step-up corresponding to the destination directory
  1376. srcpre=""
  1377. if [ $oneisabs = 0 ] || [ ".$prefix" != . -a ".$prefix" != ./ ]; then
  1378. pl="$dstdir/"
  1379. OIFS="$IFS"; IFS='/'
  1380. for pe in $pl; do
  1381. [ ".$pe" = . ] && continue
  1382. srcpre="../$srcpre"
  1383. done
  1384. IFS="$OIFS"
  1385. else
  1386. if [ $srcisabs = 1 ]; then
  1387. srcpre="$prefix"
  1388. fi
  1389. fi
  1390. # determine destination symlink name
  1391. if [ ".$dstbase" = . ]; then
  1392. if [ ".$srcbase" != . ]; then
  1393. dstbase="$srcbase"
  1394. else
  1395. dstbase=`echo "$prefix$srcdir" | sed -e 's;/*$;;' -e 's;.*/\([^/]*\)$;\1;'`
  1396. fi
  1397. fi
  1398. # now finalize source and destination directory paths
  1399. srcdir=`echo $srcdir | sed -e 's;\([^/]\)$;\1/;'`
  1400. dstdir=`echo $dstdir | sed -e 's;\([^/]\)$;\1/;'`
  1401. # run the final link command
  1402. if [ ".$opt_t" = .yes ]; then
  1403. echo "ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase"
  1404. fi
  1405. eval ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase
  1406. done
  1407. ;;
  1408. mkshadow )
  1409. ##
  1410. ## mkshadow -- Make a shadow tree through symbolic links
  1411. ## Copyright (c) 1998-2001 Ralf S. Engelschall <rse@engelschall.com>
  1412. ## Originally written for Apache
  1413. ##
  1414. # source and destination directory
  1415. src=`echo "$1" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'`
  1416. dst=`echo "$2" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'`
  1417. # check whether source exists
  1418. if [ ! -d $src ]; then
  1419. echo "$msgprefix:Error: source directory not found: \`$src'" 1>&2
  1420. exit 1
  1421. fi
  1422. # determine if one of the paths is an absolute path,
  1423. # because then we have to use an absolute symlink
  1424. oneisabs=0
  1425. case $src in
  1426. /* ) oneisabs=1 ;;
  1427. esac
  1428. case $dst in
  1429. /* ) oneisabs=1 ;;
  1430. esac
  1431. # determine reverse directory for destination directory
  1432. dstrevdir=''
  1433. if [ $oneisabs = 0 ]; then
  1434. # derive reverse path from forward path
  1435. pwd=`pwd`
  1436. OIFS="$IFS"; IFS='/'
  1437. for pe in $dst; do
  1438. if [ "x$pe" = "x.." ]; then
  1439. OIFS2="$IFS"; IFS="$DIFS"
  1440. eval `echo "$pwd" |\
  1441. sed -e 's:\([^/]*\)$:; dir="\1":' \
  1442. -e 's:^\(.*\)/[^/]*;:pwd="\1";:'\
  1443. -e 's:^;:pwd="";:'`
  1444. dstrevdir="$dir/$dstrevdir"
  1445. IFS="$OIFS2"
  1446. else
  1447. dstrevdir="../$dstrevdir"
  1448. fi
  1449. done
  1450. IFS="$OIFS"
  1451. else
  1452. src="`cd $src; pwd`";
  1453. fi
  1454. # create directory tree at destination
  1455. if [ ! -d $dst ]; then
  1456. if [ ".$opt_t" = .yes ]; then
  1457. echo "mkdir $dst" 1>&2
  1458. fi
  1459. mkdir $dst
  1460. fi
  1461. if [ ".$opt_a" = .yes ]; then
  1462. DIRS=`cd $src; find . -type d -print |\
  1463. sed -e '/^\.$/d' -e 's:^\./::'`
  1464. else
  1465. DIRS=`cd $src; find . -type d -print |\
  1466. sed -e '/\/CVS/d' -e '/^\.$/d' -e 's:^\./::'`
  1467. fi
  1468. for dir in $DIRS; do
  1469. if [ ".$opt_t" = .yes ]; then
  1470. echo "mkdir $dst/$dir" 1>&2
  1471. fi
  1472. mkdir $dst/$dir
  1473. done
  1474. # fill directory tree with symlinks to files
  1475. if [ ".$opt_a" = .yes ]; then
  1476. FILES="`cd $src; find . -depth -print |\
  1477. sed -e 's/^\.\///'`"
  1478. else
  1479. FILES="`cd $src; find . -depth -print |\
  1480. sed -e '/\.o$/d' -e '/\.a$/d' -e '/\.so$/d' \
  1481. -e '/\.cvsignore$/d' -e '/\/CVS/d' \
  1482. -e '/\/\.#/d' -e '/\.orig$/d' \
  1483. -e 's/^\.\///'`"
  1484. fi
  1485. for file in $FILES; do
  1486. # don't use `-type f' above for find because of symlinks
  1487. if [ -d "$src/$file" ]; then
  1488. continue
  1489. fi
  1490. basename=`echo $file | sed -e 's:^.*/::'`
  1491. dir=`echo $file | sed -e 's:[^/]*$::' -e 's:/$::' -e 's:$:/:' -e 's:^/$::'`
  1492. from=`echo "$src/$file" | sed -e 's/^\.\///'`
  1493. to="$dst/$dir$basename"
  1494. if [ $oneisabs = 0 ]; then
  1495. if [ ".$dir" != . ]; then
  1496. subdir=`echo $dir | sed -e 's:/$::'`
  1497. # derive reverse path from forward path
  1498. revdir=''
  1499. OIFS="$IFS"; IFS='/'
  1500. for pe in $subdir; do
  1501. revdir="../$revdir"
  1502. done
  1503. IFS="$OIFS"
  1504. # finalize from
  1505. from="$revdir$from"
  1506. fi
  1507. from="$dstrevdir$from"
  1508. fi
  1509. if [ ".$opt_v" = .yes ]; then
  1510. echo " $to" 1>&2
  1511. fi
  1512. if [ ".$opt_t" = .yes ]; then
  1513. echo "ln -s $from $to" 1>&2
  1514. fi
  1515. ln -s $from $to
  1516. done
  1517. ;;
  1518. fixperm )
  1519. ##
  1520. ## fixperm -- Fix file permissions inside a source tree
  1521. ## Copyright (c) 1996-2001 Ralf S. Engelschall <rse@engelschall.com>
  1522. ## Originally written for ePerl
  1523. ##
  1524. paths="$*"
  1525. # check whether the test command supports the -x option
  1526. if [ -x /bin/sh ] 2>/dev/null; then
  1527. minusx="-x"
  1528. else
  1529. minusx="-r"
  1530. fi
  1531. # iterate over paths
  1532. for p in $paths; do
  1533. for file in `find $p -depth -print`; do
  1534. if [ -f $file ]; then
  1535. if [ $minusx $file ]; then
  1536. if [ ".$opt_v" = .yes ]; then
  1537. echo "-rwxrwxr-x $file" 2>&1
  1538. fi
  1539. if [ ".$opt_t" = .yes ]; then
  1540. echo "chmod 775 $file" 2>&1
  1541. fi
  1542. chmod 775 $file
  1543. else
  1544. if [ ".$opt_v" = .yes ]; then
  1545. echo "-rw-rw-r-- $file" 2>&1
  1546. fi
  1547. if [ ".$opt_t" = .yes ]; then
  1548. echo "chmod 664 $file" 2>&1
  1549. fi
  1550. chmod 664 $file
  1551. fi
  1552. continue
  1553. fi
  1554. if [ -d $file ]; then
  1555. if [ ".$opt_v" = .yes ]; then
  1556. echo "drwxrwxr-x $file" 2>&1
  1557. fi
  1558. if [ ".$opt_t" = .yes ]; then
  1559. echo "chmod 775 $file" 2>&1
  1560. fi
  1561. chmod 775 $file
  1562. continue
  1563. fi
  1564. if [ ".$opt_v" = .yes ]; then
  1565. echo "?????????? $file" 2>&1
  1566. fi
  1567. done
  1568. done
  1569. ;;
  1570. rotate )
  1571. ##
  1572. ## rotate -- Logfile rotation
  1573. ## Copyright (c) 2001 Ralf S. Engelschall <rse@engelschall.com>
  1574. ## Originally written for use in OpenPKG
  1575. ##
  1576. # make sure we have at least one file to rotate
  1577. if [ ".$opt_n" = .0 ]; then
  1578. echo "$msgprefix:Error: invalid argument \`$opt_n' to option -n." 1>&2
  1579. exit 1
  1580. fi
  1581. # canonicalize -s option argument
  1582. if [ ".$opt_s" != . ]; then
  1583. if [ ".`expr $opt_s : '[0-9]*$'`" != .0 ]; then
  1584. :
  1585. elif [ ".`expr $opt_s : '[0-9]*[Kk]$'`" != .0 ]; then
  1586. opt_s=`expr $opt_s : '\([0-9]*\)[Kk]$'`
  1587. opt_s=`expr $opt_s \* 1024`
  1588. elif [ ".`expr $opt_s : '[0-9]*[Mm]$'`" != .0 ]; then
  1589. opt_s=`expr $opt_s : '\([0-9]*\)[Mm]$'`
  1590. opt_s=`expr $opt_s \* 1048576` # 1024*1024
  1591. elif [ ".`expr $opt_s : '[0-9]*[Gg]$'`" != .0 ]; then
  1592. opt_s=`expr $opt_s : '\([0-9]*\)[Gg]$'`
  1593. opt_s=`expr $opt_s \* 1073741824` # 1024*1024*1024
  1594. else
  1595. echo "$msgprefix:Error: invalid argument \`$opt_s' to option -s." 1>&2
  1596. exit 1
  1597. fi
  1598. fi
  1599. # option -d/-z consistency
  1600. if [ ".$opt_d" = .yes -a ".$opt_z" = . ]; then
  1601. echo "$msgprefix:Error: option -d requires option -z." 1>&2
  1602. exit 1
  1603. fi
  1604. # make sure target directory exists
  1605. if [ ".$opt_a" != . ]; then
  1606. if [ ! -d $opt_a ]; then
  1607. if [ ".$opt_f" = .no ]; then
  1608. echo "$msgprefix:Error: archive directory \`$opt_a' does not exist." 1>&2
  1609. exit 1
  1610. fi
  1611. mkdir $opt_a || exit $?
  1612. chmod 755 $opt_a
  1613. fi
  1614. if [ ! -w $opt_a ]; then
  1615. echo "$msgprefix:Error: archive directory \`$opt_a' not writable." 1>&2
  1616. exit 1
  1617. fi
  1618. fi
  1619. # determine compression approach
  1620. if [ ".$opt_z" != . ]; then
  1621. comp_lvl="$opt_z"
  1622. comp_prg=""
  1623. case $comp_lvl in
  1624. *:* ) eval `echo $comp_lvl |\
  1625. sed -e 's%^\(.*\):\(.*\)$%comp_prg="\1"; comp_lvl="\2"%'` ;;
  1626. esac
  1627. # compression level consistency
  1628. case $comp_lvl in
  1629. [0-9] )
  1630. ;;
  1631. * ) echo "$msgprefix:Error: invalid compression level \`$comp_lvl'" 1>&2
  1632. exit 1
  1633. ;;
  1634. esac
  1635. # determine a suitable compression tool
  1636. if [ ".$comp_prg" = . ]; then
  1637. # check whether the test command supports the -x option
  1638. if [ -x /bin/sh ] 2>/dev/null; then
  1639. minusx="-x"
  1640. else
  1641. minusx="-r"
  1642. fi
  1643. # search for tools in $PATH
  1644. paths="`echo $PATH |\
  1645. sed -e 's%/*:%:%g' -e 's%/*$%%' \
  1646. -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
  1647. -e 's/:/ /g'`"
  1648. for prg in bzip2 gzip compress; do
  1649. for path in $paths; do
  1650. if [ $minusx "$path/$prg" -a ! -d "$path/$prg" ]; then
  1651. comp_prg="$prg"
  1652. break
  1653. fi
  1654. done
  1655. if [ ".$comp_prg" != . ]; then
  1656. break
  1657. fi
  1658. done
  1659. if [ ".$comp_prg" = . ]; then
  1660. echo "$msgprefix:Error: no suitable compression tool found in \$PATH" 1>&2
  1661. exit 1
  1662. fi
  1663. fi
  1664. # determine standard compression extension
  1665. # and make sure it is a known tool
  1666. case $comp_prg in
  1667. */bzip2 | bzip2 ) comp_ext="bz2" comp_lvl="-$comp_lvl" ;;
  1668. */gzip | gzip ) comp_ext="gz" comp_lvl="-$comp_lvl" ;;
  1669. */compress | compress ) comp_ext="Z"; comp_lvl="" ;;
  1670. * ) echo "$msgprefix:Error: tool \`$comp_prg' is not a known compression tool" 1>&2
  1671. exit 1
  1672. ;;
  1673. esac
  1674. comp_suf=".$comp_ext"
  1675. fi
  1676. # iterate over all given logfile arguments
  1677. for file in $*; do
  1678. # make sure the logfile exists
  1679. if [ ! -f $file ]; then
  1680. if [ ".$opt_f" = .yes ]; then
  1681. continue
  1682. fi
  1683. echo "$msgprefix:Error: logfile \`$file' not found" 1>&2
  1684. exit 1
  1685. fi
  1686. # determine log directory (where original logfile is placed)
  1687. ldir="."
  1688. case $file in
  1689. */* ) eval `echo $file | sed -e 's%^\(.*\)/\([^/]*\)$%ldir="\1"; file="\2";%'` ;;
  1690. esac
  1691. # determine archive directory (where rotated logfiles are placed)
  1692. adir="$ldir"
  1693. if [ ".$opt_a" != . ]; then
  1694. case "$opt_a" in
  1695. /* | ./* ) adir="$opt_a" ;;
  1696. * ) adir="$ldir/$opt_a" ;;
  1697. esac
  1698. fi
  1699. # optionally take logfile size into account
  1700. if [ ".$opt_s" != . ]; then
  1701. # determine size of logfile
  1702. set -- `ls -l $ldir/$file | sed -e 's; -> .*$;;' -e 's;[ ][ ]*; ;g'`
  1703. n=`expr $# - 4`
  1704. eval "size=\`echo \${$n}\`"
  1705. # skip logfile if size is still too small
  1706. if [ $size -lt $opt_s ]; then
  1707. if [ ".$opt_v" = .yes ]; then
  1708. echo "$ldir/$file: still too small in size -- skipping"
  1709. fi
  1710. continue
  1711. fi
  1712. fi
  1713. # verbosity
  1714. if [ ".$opt_v" = .yes ]; then
  1715. echo "rotating $ldir/$file"
  1716. fi
  1717. # execute prolog
  1718. if [ ".$opt_P" != . ]; then
  1719. if [ ".$opt_t" = .yes ]; then
  1720. echo "$opt_P"
  1721. fi
  1722. eval $opt_P
  1723. [ $? -ne 0 ] && exit $?
  1724. fi
  1725. # kick away out-rotated logfile
  1726. n=`expr $opt_n - 1`
  1727. n=`echo dummy | awk "{ printf(\"%0${opt_p}d\", n); }" n=$n`
  1728. if [ -f "${adir}/${file}.${n}${comp_suf}" ]; then
  1729. # optionally migrate away the out-rotated logfile
  1730. if [ ".$opt_M" != . ]; then
  1731. if [ ".$opt_t" = .yes ]; then
  1732. echo "$opt_M ${adir}/${file}.${n}${comp_suf}"
  1733. fi
  1734. eval "$opt_M ${adir}/${file}.${n}${comp_suf}"
  1735. [ $? -ne 0 ] && exit $?
  1736. fi
  1737. # finally get rid of the out-rotated logfile
  1738. if [ ".$opt_t" = .yes ]; then
  1739. echo "rm -f ${adir}/${file}.${n}${comp_suf}"
  1740. fi
  1741. rm -f ${adir}/${file}.${n}${comp_suf} || exit $?
  1742. fi
  1743. # rotate already archived logfiles
  1744. while [ $n -gt 0 ]; do
  1745. m=$n
  1746. n=`expr $n - 1`
  1747. n=`echo dummy | awk "{ printf(\"%0${opt_p}d\", n); }" n=$n`
  1748. if [ $n -eq 0 -a ".$opt_d" = .yes ]; then
  1749. # special case: first rotation file under delayed compression situation
  1750. if [ ! -f "${adir}/${file}.${n}" ]; then
  1751. continue
  1752. fi
  1753. # compress file (delayed)
  1754. if [ ".$opt_b" = .yes ]; then
  1755. if [ ".$opt_t" = .yes ]; then
  1756. echo "mv ${adir}/${file}.${n} ${adir}/${file}.${m}"
  1757. fi
  1758. mv ${adir}/${file}.${n} ${adir}/${file}.${m} || exit $?
  1759. if [ ".$opt_t" = .yes ]; then
  1760. echo "(${comp_prg} ${comp_lvl} <${adir}/${file}.${m} >${adir}/${file}.${m}${comp_suf}; rm -f ${adir}/${file}.${m}) &"
  1761. fi
  1762. ( ${comp_prg} ${comp_lvl} \
  1763. <${adir}/${file}.${m} \
  1764. >${adir}/${file}.${m}${comp_suf} || exit $?
  1765. rm -f ${adir}/${file}.${m} || exit $?
  1766. ) </dev/null >/dev/null 2>&1 &
  1767. else
  1768. if [ ".$opt_t" = .yes ]; then
  1769. echo "${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${m}${comp_suf}"
  1770. fi
  1771. ${comp_prg} ${comp_lvl} \
  1772. <${adir}/${file}.${n} \
  1773. >${adir}/${file}.${m}${comp_suf} || exit $?
  1774. if [ ".$opt_t" = .yes ]; then
  1775. echo "rm -f ${adir}/${file}.${n}"
  1776. fi
  1777. rm -f ${adir}/${file}.${n} || exit $?
  1778. fi
  1779. # fix file attributes
  1780. if [ ".$opt_o" != . ]; then
  1781. if [ ".$opt_t" = .yes ]; then
  1782. echo "chown $opt_o ${adir}/${file}.${m}${comp_suf}"
  1783. fi
  1784. chown $opt_o ${adir}/${file}.${m}${comp_suf} || exit $?
  1785. fi
  1786. if [ ".$opt_g" != . ]; then
  1787. if [ ".$opt_t" = .yes ]; then
  1788. echo "chgrp $opt_g ${adir}/${file}.${m}${comp_suf}"
  1789. fi
  1790. chgrp $opt_g ${adir}/${file}.${m}${comp_suf} || exit $?
  1791. fi
  1792. if [ ".$opt_m" != . ]; then
  1793. if [ ".$opt_t" = .yes ]; then
  1794. echo "chmod $opt_m ${adir}/${file}.${m}${comp_suf}"
  1795. fi
  1796. chmod $opt_m ${adir}/${file}.${m}${comp_suf} || exit $?
  1797. fi
  1798. else
  1799. # standard case: second and following rotation file
  1800. if [ ! -f "${adir}/${file}.${n}${comp_suf}" ]; then
  1801. continue
  1802. fi
  1803. if [ ".$opt_t" = .yes ]; then
  1804. echo "mv ${adir}/${file}.${n}${comp_suf} ${adir}/${file}.${m}${comp_suf}"
  1805. fi
  1806. mv ${adir}/${file}.${n}${comp_suf} ${adir}/${file}.${m}${comp_suf} || exit $?
  1807. fi
  1808. done
  1809. # move away current logfile
  1810. if [ ".$opt_c" = .yes ]; then
  1811. # approach: copy[+truncate]
  1812. if [ ".$opt_t" = .yes ]; then
  1813. echo "cp -p ${ldir}/${file} ${adir}/${file}.${n}"
  1814. fi
  1815. cp -p ${ldir}/${file} ${adir}/${file}.${n} || exit $?
  1816. if [ ".$opt_r" = .no ]; then
  1817. if [ ".$opt_t" = .yes ]; then
  1818. echo "cp /dev/null ${ldir}/${file}"
  1819. fi
  1820. cp /dev/null ${ldir}/${file} || exit $?
  1821. fi
  1822. else
  1823. # approach: move[+touch]
  1824. if [ ".$opt_t" = .yes ]; then
  1825. echo "mv ${ldir}/${file} ${adir}/${file}.${n}"
  1826. fi
  1827. mv ${ldir}/${file} ${adir}/${file}.${n} || exit $?
  1828. if [ ".$opt_r" = .no ]; then
  1829. if [ ".$opt_t" = .yes ]; then
  1830. echo "touch ${ldir}/${file}"
  1831. fi
  1832. touch ${ldir}/${file} || exit $?
  1833. # fix file attributes
  1834. if [ ".$opt_o" != . ]; then
  1835. if [ ".$opt_t" = .yes ]; then
  1836. echo "chown $opt_o ${ldir}/${file}"
  1837. fi
  1838. chown $opt_o ${ldir}/${file} || exit $?
  1839. fi
  1840. if [ ".$opt_g" != . ]; then
  1841. if [ ".$opt_t" = .yes ]; then
  1842. echo "chgrp $opt_g ${ldir}/${file}"
  1843. fi
  1844. chgrp $opt_g ${ldir}/${file} || exit $?
  1845. fi
  1846. if [ ".$opt_m" != . ]; then
  1847. if [ ".$opt_t" = .yes ]; then
  1848. echo "chmod $opt_m ${ldir}/${file}"
  1849. fi
  1850. chmod $opt_m ${ldir}/${file} || exit $?
  1851. fi
  1852. fi
  1853. fi
  1854. # regular compression step
  1855. if [ ".$opt_z" != . -a ".$opt_d" = .no ]; then
  1856. # compress file
  1857. if [ ".$opt_b" = .yes ]; then
  1858. if [ ".$opt_t" = .yes ]; then
  1859. echo "(${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${n}${comp_suf}; rm -f ${adir}/${file}.${n}) &"
  1860. fi
  1861. ( ${comp_prg} ${comp_lvl} \
  1862. <${adir}/${file}.${n} \
  1863. >${adir}/${file}.${n}${comp_suf} || exit $?
  1864. rm -f ${adir}/${file}.${n} || exit $?
  1865. ) </dev/null >/dev/null 2>&1 &
  1866. else
  1867. if [ ".$opt_t" = .yes ]; then
  1868. echo "${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${n}${comp_suf}"
  1869. fi
  1870. ${comp_prg} ${comp_lvl} \
  1871. <${adir}/${file}.${n} \
  1872. >${adir}/${file}.${n}${comp_suf} || exit $?
  1873. if [ ".$opt_t" = .yes ]; then
  1874. echo "rm -f ${opt_a}${file}.${n}"
  1875. fi
  1876. rm -f ${adir}/${file}.${n} || exit $?
  1877. fi
  1878. # fix file attributes
  1879. if [ ".$opt_o" != . ]; then
  1880. if [ ".$opt_t" = .yes ]; then
  1881. echo "chown $opt_o ${adir}/${file}.${n}${comp_suf}"
  1882. fi
  1883. chown $opt_o ${adir}/${file}.${n}${comp_suf} || exit $?
  1884. fi
  1885. if [ ".$opt_g" != . ]; then
  1886. if [ ".$opt_t" = .yes ]; then
  1887. echo "chgrp $opt_g ${adir}/${file}.${n}${comp_suf}"
  1888. fi
  1889. chgrp $opt_g ${adir}/${file}.${n}${comp_suf} || exit $?
  1890. fi
  1891. if [ ".$opt_m" != . ]; then
  1892. if [ ".$opt_t" = .yes ]; then
  1893. echo "chmod $opt_m ${adir}/${file}.${n}${comp_suf}"
  1894. fi
  1895. chmod $opt_m ${adir}/${file}.${n}${comp_suf} || exit $?
  1896. fi
  1897. fi
  1898. # execute epilog
  1899. if [ ".$opt_E" != . ]; then
  1900. if [ ".$opt_t" = .yes ]; then
  1901. echo "$opt_E"
  1902. fi
  1903. eval $opt_E
  1904. [ $? -ne 0 ] && exit $?
  1905. fi
  1906. done
  1907. ;;
  1908. tarball )
  1909. ##
  1910. ## tarball -- Roll distribution tarballs
  1911. ## Copyright (c) 1999-2001 Ralf S. Engelschall <rse@engelschall.com>
  1912. ## Originally written for shtool
  1913. ##
  1914. srcs="$*"
  1915. # check whether the test command supports the -x option
  1916. if [ -x /bin/sh ] 2>/dev/null; then
  1917. minusx="-x"
  1918. else
  1919. minusx="-r"
  1920. fi
  1921. # find the tools
  1922. paths="`echo $PATH |\
  1923. sed -e 's%/*:%:%g' -e 's%/*$%%' \
  1924. -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
  1925. -e 's/:/ /g'`"
  1926. for spec in find:gfind,find tar:gtar,tar tardy:tardy,tarcust; do
  1927. prg=`echo $spec | sed -e 's/:.*$//'`
  1928. tools=`echo $spec | sed -e 's/^.*://'`
  1929. eval "prg_${prg}=''"
  1930. # iterate over tools
  1931. for tool in `echo $tools | sed -e 's/,/ /g'`; do
  1932. # iterate over paths
  1933. for path in $paths; do
  1934. if [ $minusx "$path/$tool" -a ! -d "$path/$tool" ]; then
  1935. eval "prg_${prg}=\"$path/$tool\""
  1936. break
  1937. fi
  1938. done
  1939. eval "val=\$prg_${prg}"
  1940. if [ ".$val" != . ]; then
  1941. break
  1942. fi
  1943. done
  1944. done
  1945. # expand source paths
  1946. exclude=''
  1947. for pat in `echo $opt_e | sed 's/,/ /g'`; do
  1948. exclude="$exclude | grep -v '$pat'"
  1949. done
  1950. if [ ".$opt_t" = .yes ]; then
  1951. echo "cp /dev/null $tmpfile.lst" 1>&2
  1952. fi
  1953. cp /dev/null $tmpfile.lst
  1954. for src in $srcs; do
  1955. if [ -d $src ]; then
  1956. if [ ".$opt_t" = .yes ]; then
  1957. echo "(cd $src && $prg_find . -type f -depth -print) | sed -e 's:^\\.\$::' -e 's:^\\./::' | cat $exclude >>$tmpfile.lst" 1>&2
  1958. fi
  1959. (cd $src && $prg_find . -type f -depth -print) |\
  1960. sed -e 's:^\.$::' -e 's:^\./::' | eval cat $exclude >>$tmpfile.lst
  1961. else
  1962. if [ ".$opt_t" = .yes ]; then
  1963. echo "echo $src >>$tmpfile.lst" 1>&2
  1964. fi
  1965. echo $src >>$tmpfile.lst
  1966. fi
  1967. done
  1968. sort <$tmpfile.lst >$tmpfile.lst.n
  1969. mv $tmpfile.lst.n $tmpfile.lst
  1970. if [ ".$opt_v" = .yes ]; then
  1971. cat $tmpfile.lst | sed -e 's/^/ /' 1>&2
  1972. fi
  1973. # determine tarball file and directory name
  1974. if [ ".$opt_o" != . ]; then
  1975. tarfile="$opt_o"
  1976. if [ ".$opt_d" != . ]; then
  1977. tarname="$opt_d"
  1978. else
  1979. tarname=`echo $tarfile | sed -e 's/\.tar.*$//' -e 's;.*/\([^/]*\)$;\1;'`
  1980. fi
  1981. else
  1982. if [ ".$opt_d" != . ]; then
  1983. tarname="$opt_d"
  1984. elif [ -d "$from" ]; then
  1985. tarname=`echo $from | sed -e 's;.*/\([^/]*\)$;\1;'`
  1986. else
  1987. tarname="out"
  1988. fi
  1989. tarfile="$tarname.tar"
  1990. fi
  1991. # roll the tarball
  1992. compress=''
  1993. if [ ".$opt_c" != . ]; then
  1994. compress="| $opt_c"
  1995. fi
  1996. if [ ".$prg_tardy" != . ]; then
  1997. # the elegant hackers way
  1998. tardy_opt="--prefix=$tarname"
  1999. tardy_opt="$tardy_opt --user_number=0 --group_number=0" # security!
  2000. if [ ".$opt_u" != . ]; then
  2001. tardy_opt="$tardy_opt --user_name=$opt_u"
  2002. fi
  2003. if [ ".$opt_g" != . ]; then
  2004. tardy_opt="$tardy_opt --group_name=$opt_g"
  2005. fi
  2006. if [ ".$opt_t" = .yes ]; then
  2007. echo "cat $tmpfile.lst | xargs $prg_tar cf - | $prg_tardy $tardy_opt | cat $compress >$tmpfile.out" 1>&2
  2008. fi
  2009. cat $tmpfile.lst |\
  2010. xargs $prg_tar cf - |\
  2011. $prg_tardy $tardy_opt |\
  2012. eval cat $compress >$tmpfile.out
  2013. if [ ".$opt_t" = .yes ]; then
  2014. echo "cp $tmpfile.out $tarfile" 1>&2
  2015. fi
  2016. cp $tmpfile.out $tarfile
  2017. else
  2018. # the portable standard way
  2019. if [ ".$opt_t" = .yes ]; then
  2020. echo "mkdir $tmpdir/$tarname" 1>&2
  2021. fi
  2022. mkdir $tmpdir/$tarname || exit 1
  2023. if [ ".$opt_t" = .yes ]; then
  2024. echo "cat $tmpfile.lst | xargs $prg_tar cf - | (cd $tmpdir/$tarname && $prg_tar xf -)" 1>&2
  2025. fi
  2026. cat $tmpfile.lst |\
  2027. xargs $prg_tar cf - |\
  2028. (cd $tmpdir/$tarname && $prg_tar xf -)
  2029. if [ ".$opt_u" != . ]; then
  2030. if [ ".$opt_t" = .yes ]; then
  2031. echo "chown -R $opt_u $tmpdir/$tarname >/dev/null 2>&1" 2>&1
  2032. fi
  2033. chown -R $opt_u $tmpdir/$tarname >/dev/null 2>&1 ||\
  2034. echo "$msgprefix:Warning: cannot set user name \`$opt_u' (would require root priviledges)"
  2035. fi
  2036. if [ ".$opt_g" != . ]; then
  2037. if [ ".$opt_t" = .yes ]; then
  2038. echo "chgrp -R $opt_g $tmpdir/$tarname >/dev/null 2>&1" 2>&1
  2039. fi
  2040. chgrp -R $opt_g $tmpdir/$tarname >/dev/null 2>&1 ||\
  2041. echo "$msgprefix:Warning: cannot set group name \`$opt_g' (would require root priviledges)"
  2042. fi
  2043. if [ ".$opt_t" = .yes ]; then
  2044. echo "(cd $tmpdir && $prg_find $tarname -type f -depth -print | sort | xargs $prg_tar cf -) | cat $compress >$tmpfile.out" 1>&2
  2045. fi
  2046. (cd $tmpdir && $prg_find $tarname -type f -depth -print | sort | xargs $prg_tar cf -) |\
  2047. eval cat $compress >$tmpfile.out
  2048. if [ ".$opt_t" = .yes ]; then
  2049. echo "cp $tmpfile.out $tarfile" 1>&2
  2050. fi
  2051. cp $tmpfile.out $tarfile
  2052. if [ ".$opt_t" = .yes ]; then
  2053. echo "rm -rf $tmpdir/$tarname" 1>&2
  2054. fi
  2055. rm -rf $tmpdir/$tarname
  2056. fi
  2057. # cleanup
  2058. if [ ".$opt_t" = .yes ]; then
  2059. echo "rm -f $tmpfile.lst $tmpfile.out" 1>&2
  2060. fi
  2061. rm -f $tmpfile.lst $tmpfile.out
  2062. ;;
  2063. subst )
  2064. ##
  2065. ## subst -- Apply sed(1) substitution operations
  2066. ## Copyright (c) 2001 Ralf S. Engelschall <rse@engelschall.com>
  2067. ## Originally written for OpenPKG's rpmtool
  2068. ##
  2069. # remember optional list of file(s)
  2070. files="$*"
  2071. # parameter consistency check
  2072. if [ $# -eq 0 -a ".$opt_b" != . ]; then
  2073. echo "$msgprefix:Error: option -b cannot be applied to stdin" 1>&2
  2074. exit 1
  2075. fi
  2076. if [ $# -eq 0 -a ".$opt_s" = .yes ]; then
  2077. echo "$msgprefix:Error: option -s cannot be applied to stdin" 1>&2
  2078. exit 1
  2079. fi
  2080. # build underlying sed(1) command
  2081. sedcmd='sed'
  2082. if [ ".$opt_e" != . ]; then
  2083. OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
  2084. for e
  2085. do
  2086. sedcmd="$sedcmd -e '$e'"
  2087. done
  2088. elif [ ".$opt_f" != . ]; then
  2089. if [ ! -f $opt_f ]; then
  2090. echo "$msgprefix:Error: command file \`$opt_f' not found" 1>&2
  2091. exit 1
  2092. fi
  2093. sedcmd="$sedcmd -f '$opt_f'"
  2094. else
  2095. echo "$msgprefix:Error: either -e option(s) or -f option required" 1>&2
  2096. exit 1
  2097. fi
  2098. # determine extension for original file
  2099. orig=".orig"
  2100. if [ ".$opt_b" != . ]; then
  2101. orig="$opt_b"
  2102. fi
  2103. # apply sed(1) operation(s)
  2104. if [ ".$files" != . ]; then
  2105. # apply operation(s) to files
  2106. for file in $files; do
  2107. test ".$file" = . && continue
  2108. if [ ! -f $file ]; then
  2109. echo "$msgprefix:Warning: file \`$file' not found" 1>&2
  2110. continue
  2111. fi
  2112. # handle interactive mode
  2113. if [ ".$opt_i" = .yes ]; then
  2114. eval "$sedcmd <$file >$file.new"
  2115. skip=no
  2116. if cmp $file $file.new >/dev/null 2>&1; then
  2117. rm -f $file.new
  2118. skip=yes
  2119. else
  2120. (diff -u1 $file $file.new >$tmpfile) 2>/dev/null
  2121. if [ ".`cat $tmpfile`" = . ]; then
  2122. (diff -C1 $file $file.new >$tmpfile) 2>/dev/null
  2123. if [ ".`cat $tmpfile`" = . ]; then
  2124. echo "$msgprefix:Warning: unable to show difference for file \`$file'" 1>&2
  2125. cp /dev/null $tmpfile
  2126. fi
  2127. fi
  2128. rm -f $file.new
  2129. cat $tmpfile
  2130. echo dummy | awk '{ printf("%s", TEXT); }' TEXT=">>> Apply [Y/n]: "
  2131. read input
  2132. if [ ".$input" != .Y ] &&\
  2133. [ ".$input" != .y ] &&\
  2134. [ ".$input" != . ]; then
  2135. skip=yes
  2136. fi
  2137. fi
  2138. if [ ".$skip" = .yes ]; then
  2139. if [ ".$opt_v" = .yes ]; then
  2140. echo "file \`$file' -- skipped" 1>&2
  2141. fi
  2142. continue
  2143. fi
  2144. fi
  2145. # apply sed(1) operation(s)
  2146. if [ ".$opt_v" = .yes ]; then
  2147. echo "patching \`$file'" 1>&2
  2148. fi
  2149. if [ ".$opt_t" = .yes ]; then
  2150. echo "\$ cp -p $file $file$orig"
  2151. echo "\$ $sedcmd <$file$orig >$file"
  2152. fi
  2153. if [ ".$opt_n" = .no ]; then
  2154. cp -p $file $file$orig
  2155. eval "$sedcmd <$file$orig >$file"
  2156. fi
  2157. # optionally fix timestamp
  2158. if [ ".$opt_s" = .yes ]; then
  2159. if [ ".$opt_t" = .yes ]; then
  2160. echo "\$ touch -r $file$orig $file"
  2161. fi
  2162. if [ ".$opt_n" = .no ]; then
  2163. touch -r $file$orig $file
  2164. fi
  2165. fi
  2166. # optionally remove preserved original file
  2167. if [ ".$opt_b" = . ]; then
  2168. if [ ".$opt_t" = .yes ]; then
  2169. echo "\$ rm -f $file$orig"
  2170. fi
  2171. if [ ".$opt_n" = .no ]; then
  2172. rm -f $file$orig
  2173. fi
  2174. fi
  2175. done
  2176. else
  2177. # apply operation(s) to stdin/stdout
  2178. if [ ".$opt_v" = .yes ]; then
  2179. echo "patching <stdin>" 1>&2
  2180. fi
  2181. if [ ".$opt_t" = .yes ]; then
  2182. echo "\$ $sedcmd"
  2183. fi
  2184. if [ ".$opt_n" = .no ]; then
  2185. eval "$sedcmd"
  2186. fi
  2187. fi
  2188. ;;
  2189. guessos )
  2190. ##
  2191. ## guessos -- Simple operating system guesser
  2192. ## Copyright (c) 1996-1999 The Apache Group, http://www.apache.org/
  2193. ## The Apache license applies (see http://www.apache.org/docs/LICENSE)
  2194. ## Originally written for Apache
  2195. ##
  2196. MACHINE=`(uname -m) 2>/dev/null` || MACHINE=`(uname -p) 2>/dev/null` || MACHINE="unknown"
  2197. RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
  2198. SYSTEM=`(uname -s) 2>/dev/null` || SYSTEM="unknown"
  2199. VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown"
  2200. XREL=`(uname -X) 2>/dev/null | grep "^Release" | awk '{print $3}'`
  2201. if [ "x$XREL" != "x" ]; then
  2202. if [ -f /etc/kconfig ]; then
  2203. case "$XREL" in
  2204. 4.0|4.1) echo "${MACHINE}-whatever-isc4"; exit 0 ;;
  2205. esac
  2206. else
  2207. case "$XREL" in
  2208. 3.2v4.2)
  2209. echo "whatever-whatever-sco3"; exit 0
  2210. ;;
  2211. 3.2v5.0*)
  2212. echo "whatever-whatever-sco5"; exit 0
  2213. ;;
  2214. 4.2MP)
  2215. if [ "x$VERSION" = "x2.1.1" ]; then
  2216. echo "${MACHINE}-whatever-unixware211"; exit 0
  2217. elif [ "x$VERSION" = "x2.1.2" ]; then
  2218. echo "${MACHINE}-whatever-unixware212"; exit 0
  2219. else
  2220. echo "${MACHINE}-whatever-unixware2"; exit 0
  2221. fi
  2222. ;;
  2223. 4.2)
  2224. echo "whatever-whatever-unixware1"; exit 0
  2225. ;;
  2226. 5)
  2227. case "$VERSION" in
  2228. 7*) echo "${MACHINE}-whatever-unixware7"; exit 0 ;;
  2229. esac
  2230. ;;
  2231. esac
  2232. fi
  2233. fi
  2234. case "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}" in
  2235. MiNT:*)
  2236. echo "m68k-atari-mint"; exit 0
  2237. ;;
  2238. A/UX:*)
  2239. echo "m68k-apple-aux3"; exit 0
  2240. ;;
  2241. AIX:*)
  2242. MACH=`echo $MACHINE | sed -e 's;[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F];;'`
  2243. echo "${MACH}-ibm-aix${VERSION}.${RELEASE}"; exit 0
  2244. ;;
  2245. dgux:*)
  2246. echo "${MACHINE}-dg-dgux"; exit 0
  2247. ;;
  2248. HI-UX:*)
  2249. echo "${MACHINE}-hi-hiux"; exit 0
  2250. ;;
  2251. HP-UX:*)
  2252. HPUXVER=`echo ${RELEASE}|sed -e 's/[^.]*.[0B]*//'`
  2253. MACHINE=`echo ${MACHINE}|sed -e 's:/:_:'`
  2254. echo "${MACHINE}-hp-hpux${HPUXVER}"; exit 0
  2255. ;;
  2256. IRIX:*)
  2257. if [ -f /usr/lib32/mips4/libm.so ]; then
  2258. echo "${MACHINE}/32-sgi-irix${RELEASE}"; exit 0
  2259. else
  2260. echo "${MACHINE}-sgi-irix${RELEASE}"; exit 0
  2261. fi
  2262. ;;
  2263. IRIX64:*)
  2264. echo "${MACHINE}/64-sgi-irix${RELEASE}"; exit 0
  2265. ;;
  2266. Linux:*)
  2267. V='whatever'
  2268. case "$MACHINE" in
  2269. i?86) V='pc' ;;
  2270. esac
  2271. R=''
  2272. case "$RELEASE" in
  2273. [1-9].*) R=`echo $RELEASE | cut -c1` ;;
  2274. esac
  2275. echo "${MACHINE}-${V}-linux-gnu${R}"; exit 0
  2276. ;;
  2277. LynxOS:*)
  2278. echo "${MACHINE}-lynx-lynxos"; exit 0
  2279. ;;
  2280. BSD/386|BSD/OS:3.*)
  2281. echo "${MACHINE}-whatever-bsdi3"; exit 0
  2282. ;;
  2283. BSD/386:*:*:*486*|BSD/OS:*:*:*:*486*)
  2284. echo "i486-whatever-bsdi"; exit 0
  2285. ;;
  2286. BSD/386:*|BSD/OS:*)
  2287. echo "${MACHINE}-whatever-bsdi"; exit 0
  2288. ;;
  2289. FreeBSD:*)
  2290. VERS=`echo ${RELEASE} | sed -e 's/[-(].*//'`
  2291. MACH=`/sbin/sysctl -n hw.model`
  2292. ARCH='whatever'
  2293. case ${MACH} in
  2294. *386* ) MACH="i386" ;;
  2295. *486* ) MACH="i486" ;;
  2296. Pentium\ II*) MACH="i686" ;;
  2297. Pentium* ) MACH="i586" ;;
  2298. Alpha* ) MACH="alpha" ;;
  2299. * ) MACH="$MACHINE" ;;
  2300. esac
  2301. case ${MACH} in
  2302. i[0-9]86 ) ARCH="pc" ;;
  2303. esac
  2304. echo "${MACH}-${ARCH}-freebsd${VERS}"; exit 0
  2305. ;;
  2306. NetBSD:*:*:*486*)
  2307. echo "i486-whatever-netbsd${RELEASE}"; exit 0
  2308. ;;
  2309. NetBSD:*)
  2310. echo "${MACHINE}-whatever-netbsd${RELEASE}"; exit 0
  2311. ;;
  2312. OpenBSD:*)
  2313. echo "${MACHINE}-whatever-openbsd"; exit 0
  2314. ;;
  2315. OSF1:*:*:*alpha*)
  2316. VERS=`echo $RELEASE | sed -e 's;^V;;'`
  2317. echo "${MACHINE}-dec-osf${VERS}"; exit 0
  2318. ;;
  2319. QNX:*)
  2320. if [ "$VERSION" -gt 422 ]; then
  2321. echo "${MACHINE}-qssl-qnx32"
  2322. else
  2323. echo "${MACHINE}-qssl-qnx"
  2324. fi
  2325. exit 0
  2326. ;;
  2327. Paragon*:*:*:*)
  2328. echo "i860-intel-osf1"; exit 0
  2329. ;;
  2330. SunOS:5.*)
  2331. VERSION=`echo $RELEASE | sed -e 's;^5\.;;'`
  2332. echo "${MACHINE}-sun-solaris2.${VERSION}"; exit 0
  2333. ;;
  2334. SunOS:*)
  2335. echo "${MACHINE}-sun-sunos4"; exit 0
  2336. ;;
  2337. UNIX_System_V:4.*:*)
  2338. echo "${MACHINE}-whatever-sysv4"; exit 0
  2339. ;;
  2340. unix:3.0.9*:*:88k)
  2341. echo "${MACHINE}-encore-sysv4"; exit 0
  2342. ;;
  2343. *:4*:R4*:m88k)
  2344. echo "${MACHINE}-whatever-sysv4"; exit 0
  2345. ;;
  2346. UnixWare:5:99*:*)
  2347. # Gemini, beta release of next rev of unixware
  2348. echo "${MACHINE}-whatever-unixware212"; exit 0
  2349. ;;
  2350. DYNIX/ptx:4*:*)
  2351. echo "${MACHINE}-whatever-sysv4"; exit 0
  2352. ;;
  2353. *:4.0:3.0:[345][0-9]?? | *:4.0:3.0:3[34]??[/,]* | library:*)
  2354. echo "x86-ncr-sysv4"; exit 0
  2355. ;;
  2356. ULTRIX:*)
  2357. echo "${MACHINE}-unknown-ultrix"; exit 0
  2358. ;;
  2359. SINIX-?:* | ReliantUNIX-?:*)
  2360. echo "${MACHINE}-siemens-sysv4"; exit 0
  2361. ;;
  2362. POSIX*BS2000)
  2363. echo "${MACHINE}-siemens-sysv4"; exit 0
  2364. ;;
  2365. machten:*)
  2366. echo "${MACHINE}-tenon-${SYSTEM}"; exit 0;
  2367. ;;
  2368. ConvexOS:*:11.*:*)
  2369. echo "${MACHINE}-v11-${SYSTEM}"; exit 0;
  2370. ;;
  2371. UNIX_SV:*:*:maxion)
  2372. echo "${MACHINE}-ccur-sysv4"; exit 0;
  2373. ;;
  2374. PowerMAX_OS:*:*:Night_Hawk)
  2375. MACHINE=`uname -p`
  2376. echo "${MACHINE}-concurrent-powermax"; exit 0;
  2377. ;;
  2378. UNIX_SV:*)
  2379. if [ -d /usr/nec ];then
  2380. echo "mips-nec-sysv4"; exit 0;
  2381. fi
  2382. ;;
  2383. NonStop-UX:4.[02]*:[BC]*:*)
  2384. echo "${MACHINE}-tandem-sysv4"; exit 0;
  2385. ;;
  2386. Rhapsody:*:*:*)
  2387. case "${MACHINE}" in
  2388. "Power Macintosh") MACHINE=powerpc ;;
  2389. esac
  2390. echo "${MACHINE}-apple-rhapsody${RELEASE}"; exit 0
  2391. ;;
  2392. "Mac OS":*:*:*)
  2393. MACHINE=`uname -p`
  2394. echo "${MACHINE}-apple-macos${RELEASE}"; exit 0
  2395. ;;
  2396. "RISC iX":*)
  2397. echo "arm-whatever-riscix"; exit 0;
  2398. ;;
  2399. *:4.0:2:*)
  2400. echo "whatever-unisys-sysv4"; exit 0;
  2401. ;;
  2402. *:*:dcosx:NILE*)
  2403. echo "pyramid-pyramid-svr4"; exit 0;
  2404. ;;
  2405. *:*:*:"DRS 6000")
  2406. echo "drs6000-whatever-whatever"; exit 0;
  2407. ;;
  2408. AmigaOS:*:*:* )
  2409. echo "${MACHINE}-whatever-${SYSTEM}${RELEASE}"; exit 0
  2410. ;;
  2411. esac
  2412. # Now NeXT
  2413. ISNEXT=`(hostinfo) 2>/dev/null`
  2414. case "$ISNEXT" in
  2415. *NeXT*)
  2416. # Swiped from a friendly uname clone for NEXT/OPEN Step.
  2417. NEXTOSVER="`hostinfo | sed -n 's/.*NeXT Mach \([0-9\.]*\).*/\1/p'`"
  2418. if [ "$NEXTOSVER" -gt 3.3 ]; then
  2419. NEXTOS="openstep"
  2420. else
  2421. NEXTOS="nextstep"
  2422. fi
  2423. NEXTREL="`hostinfo | sed -n 's/.*NeXT Mach \([0-9\.]*\).*/\1/p'`"
  2424. NEXTARCH=`arch`
  2425. echo "${NEXTARCH}-next-${NEXTOS}${NEXTREL}" ; exit 0
  2426. ;;
  2427. esac
  2428. # Fallback
  2429. echo "${MACHINE}-unknown-${SYSTEM}/${RELEASE}/${VERSION}"
  2430. ;;
  2431. arx )
  2432. ##
  2433. ## arx -- Extended archive command
  2434. ## Copyright (c) 1999-2001 Ralf S. Engelschall <rse@engelschall.com>
  2435. ## Originally written for shtool
  2436. ##
  2437. ar_prg="$opt_C"
  2438. ar_cmd="$1"; shift
  2439. archive="$1"; shift
  2440. files="$*"
  2441. # walk through the file list and expand archives members
  2442. tmpdir=`echo $archive | sed -e 's;[^/]*$;.arx;'`
  2443. nfiles=''
  2444. if [ ".$files" != . ]; then
  2445. for file in $files; do
  2446. if [ ! -f $file ]; then
  2447. echo "$msgprefix:Error: input file not found: $file" 1>&2
  2448. exit 1
  2449. fi
  2450. case $file in
  2451. *.a )
  2452. if [ ! -d $tmpdir ]; then
  2453. if [ ".$opt_t" = .yes ]; then
  2454. echo "mkdir $tmpdir" 1>&2
  2455. fi
  2456. mkdir $tmpdir
  2457. fi
  2458. case $tmpdir in
  2459. .arx )
  2460. from="../$file"
  2461. ;;
  2462. * )
  2463. dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'`
  2464. base=`echo $file | sed -e 's;.*/\([^/]*\)$;\1;'`
  2465. from="`cd $dir; pwd`/$base"
  2466. ;;
  2467. esac
  2468. if [ ".$opt_t" = .yes ]; then
  2469. echo "(cd $tmpdir && $ar_prg x $from)" 1>&2
  2470. fi
  2471. (cd $tmpdir && eval $ar_prg x $from)
  2472. if [ $? -ne 0 ]; then
  2473. echo "$msgprefix:Error: member extraction failed for archive: $file" 1>&2
  2474. exit 1
  2475. fi
  2476. for member in - `eval $ar_prg t $file | sed -e '/_\.SYMDEF/d'`; do
  2477. [ ".$member" = .- ] && continue
  2478. nfiles="$nfiles $tmpdir/$member"
  2479. done
  2480. ;;
  2481. * )
  2482. nfiles="$nfiles $file"
  2483. ;;
  2484. esac
  2485. done
  2486. fi
  2487. # run the final archive command
  2488. if [ ".$opt_t" = .yes ]; then
  2489. echo "$ar_prg $ar_cmd $archive $nfiles" 1>&2
  2490. fi
  2491. eval $ar_prg $ar_cmd $archive $nfiles
  2492. if [ $? -ne 0 ]; then
  2493. echo "$msgprefix:Error: archive command failed" 1>&2
  2494. exit $?
  2495. fi
  2496. # cleanup and die gracefully
  2497. if [ -d $tmpdir ]; then
  2498. if [ ".$opt_t" = .yes ]; then
  2499. echo "rm -rf $tmpdir" 1>&2
  2500. fi
  2501. rm -rf $tmpdir
  2502. fi
  2503. ;;
  2504. slo )
  2505. ##
  2506. ## slo -- Separate linker options by library class
  2507. ## Copyright (c) 1998-2001 Ralf S. Engelschall <rse@engelschall.com>
  2508. ## Originally written for Apache
  2509. ##
  2510. DIFS="$IFS"
  2511. # parse out -L and -l options from command line
  2512. DIRS=''
  2513. LIBS=''
  2514. ARGV=''
  2515. optprev=''
  2516. for opt
  2517. do
  2518. # concatenate with previous option if exists
  2519. if [ ".$optprev" != . ]; then
  2520. opt="${optprev}${opt}";
  2521. optprev=''
  2522. fi
  2523. # remember options for arg if used stand-alone
  2524. if [ ".$opt" = ".-L" -o ".$opt" = ".-l" ]; then
  2525. optprev="$opt"
  2526. continue;
  2527. fi
  2528. # split argument into option plus option argument
  2529. arg="`echo $opt | cut -c3-`"
  2530. opt="`echo $opt | cut -c1-2`"
  2531. # store into containers
  2532. case $opt in
  2533. -L) DIRS="$DIRS:$arg" ;;
  2534. -l) LIBS="$LIBS:$arg" ;;
  2535. *) ARGV="$ARGV $opt" ;;
  2536. esac
  2537. done
  2538. # set linker default directories
  2539. DIRS_DEFAULT='/lib:/usr/lib'
  2540. if [ ".$LD_LIBRARY_PATH" != . ]; then
  2541. DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH"
  2542. fi
  2543. # sort options by class
  2544. DIRS_OBJ=''
  2545. LIBS_OBJ=''
  2546. DIRS_PIC=''
  2547. LIBS_PIC=''
  2548. DIRS_DSO=''
  2549. LIBS_DSO=''
  2550. # for each library...
  2551. OIFS="$IFS"; IFS=':'
  2552. for lib in $LIBS; do
  2553. [ ".$lib" = . ] && continue
  2554. found='no'
  2555. found_indefdir='no'
  2556. found_type=''
  2557. found_dir=''
  2558. # for each directory...
  2559. OIFS2="$IFS"; IFS=":$DIFS"
  2560. for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do
  2561. [ ".$dir" = . ] && continue
  2562. [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes
  2563. [ ! -d $dir ] && continue
  2564. # search the file
  2565. OIFS3="$IFS"; IFS="$DIFS"
  2566. for file in '' `cd $dir && ls lib${lib}.* 2>/dev/null`; do
  2567. [ ".$file" = . ] && continue
  2568. case $file in
  2569. *.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* )
  2570. found=yes;
  2571. found_type=DSO;
  2572. break
  2573. ;;
  2574. *.lo|*.la )
  2575. found=yes;
  2576. found_type=PIC
  2577. ;;
  2578. *.a )
  2579. if [ ".$found_type" = . ]; then
  2580. found=yes
  2581. found_type=OBJ
  2582. fi
  2583. ;;
  2584. esac
  2585. done
  2586. IFS="$OIFS3"
  2587. if [ ".$found" = .yes ]; then
  2588. found_dir="$dir"
  2589. break
  2590. fi
  2591. done
  2592. IFS="$OIFS2"
  2593. if [ ".$found" = .yes ]; then
  2594. if [ ".$found_indefdir" != .yes ]; then
  2595. eval "dirlist=\"\${DIRS_${found_type}}:\""
  2596. if [ ".`echo \"$dirlist\" | fgrep :$found_dir:`" = . ]; then
  2597. eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\""
  2598. fi
  2599. eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
  2600. else
  2601. eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
  2602. fi
  2603. else
  2604. LIBS_OBJ="$LIBS_OBJ:$lib"
  2605. #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`"
  2606. #echo "slo:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1
  2607. #echo "slo:Warning: $dirlist" 1>&1
  2608. fi
  2609. done
  2610. IFS="$OIFS"
  2611. # also pass-through unused dirs even if it's useless
  2612. OIFS="$IFS"; IFS=':'
  2613. for dir in $DIRS; do
  2614. dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:"
  2615. if [ ".`echo \"$dirlist\" | fgrep :$dir:`" = . ]; then
  2616. DIRS_OBJ="$DIRS_OBJ:$dir"
  2617. fi
  2618. done
  2619. IFS="$OIFS"
  2620. # reassemble the options but separated by type
  2621. for type in OBJ PIC DSO; do
  2622. OIFS="$IFS"; IFS=':'
  2623. eval "libs=\"\$LIBS_${type}\""
  2624. opts=''
  2625. for lib in $libs; do
  2626. [ ".$lib" = . ] && continue
  2627. opts="$opts -l$lib"
  2628. done
  2629. eval "LIBS_${type}=\"$opts\""
  2630. eval "dirs=\"\$DIRS_${type}\""
  2631. opts=''
  2632. for dir in $dirs; do
  2633. [ ".$dir" = . ] && continue
  2634. opts="$opts -L$dir"
  2635. done
  2636. eval "DIRS_${type}=\"$opts\""
  2637. IFS="$OIFS"
  2638. done
  2639. # give back results
  2640. for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do
  2641. eval "val=\"\$${var}\""
  2642. val="`echo $val | sed -e 's/^ *//'`"
  2643. echo "${opt_p}${var}=\"${val}\""
  2644. done
  2645. ;;
  2646. scpp )
  2647. ##
  2648. ## scpp -- Sharing C Pre-Processor
  2649. ## Copyright (c) 1999-2001 Ralf S. Engelschall <rse@engelschall.com>
  2650. ## Originally written for GNU Pth
  2651. ##
  2652. srcs="$*"
  2653. output="${opt_o}.n"
  2654. # find a reasonable Awk
  2655. awk=''
  2656. paths=`echo $PATH |\
  2657. sed -e 's%/*:%:%g' -e 's%/$%%' \
  2658. -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
  2659. -e 's/:/ /g'`
  2660. for name in gawk nawk awk; do
  2661. for path in $paths; do
  2662. if [ -r "$path/$name" ]; then
  2663. awk="$path/$name"
  2664. break
  2665. fi
  2666. done
  2667. if [ ".$awk" != . ]; then
  2668. break
  2669. fi
  2670. done
  2671. if [ ".$awk" = . ]; then
  2672. echo "$msgprefix:Error: cannot find a reasonable Awk" 1>&2
  2673. exit 1
  2674. fi
  2675. # parse source file(s)
  2676. if [ ".$opt_v" = .yes ]; then
  2677. echo "Parsing:" | $awk '{ printf("%s", $0); }' 1>&2
  2678. fi
  2679. for src in $srcs; do
  2680. if [ ".$opt_v" = .yes ]; then
  2681. echo $src | $awk '{ printf(" %s", $0); }' 1>&2
  2682. fi
  2683. if [ ".$opt_f" != . ]; then
  2684. inputcmd="sed"
  2685. OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_f; IFS="$OIFS"
  2686. for e
  2687. do
  2688. inputcmd="$inputcmd -e '$e'"
  2689. done
  2690. inputcmd="$inputcmd $src"
  2691. else
  2692. inputcmd="cat $src"
  2693. fi
  2694. $inputcmd |\
  2695. $awk '
  2696. BEGIN {
  2697. ln = 0;
  2698. fln = 0;
  2699. level = 0;
  2700. mode = "";
  2701. store = "";
  2702. }
  2703. {
  2704. ln++;
  2705. }
  2706. /^#if.*/ {
  2707. level++;
  2708. }
  2709. /^#if [a-zA-Z_][a-zA-Z0-9_]* *$/ {
  2710. if ($2 == define) {
  2711. mode = "D";
  2712. printf("D:#line %d \"%s\"\n", ln, src);
  2713. next;
  2714. }
  2715. }
  2716. /^#endif.*/ {
  2717. level--;
  2718. if (mode == "D" && level == 0) {
  2719. mode = "";
  2720. next;
  2721. }
  2722. }
  2723. /^[a-zA-Z_][a-zA-Z0-9_].*;.*/ {
  2724. if ($1 == class) {
  2725. printf("V:#line %d \"%s\"\n", ln, src);
  2726. printf("V:%s\n", $0);
  2727. printf("J:%s\n", $0);
  2728. next;
  2729. }
  2730. }
  2731. /^[a-zA-Z_][a-zA-Z0-9_].*=.*/ {
  2732. if ($1 == class) {
  2733. printf("V:#line %d \"%s\"\n", ln, src);
  2734. printf("V:%s\n", $0);
  2735. printf("J:%s\n", $0);
  2736. next;
  2737. }
  2738. }
  2739. /^[a-zA-Z_][a-zA-Z0-9_]*/ {
  2740. if ($1 == class) {
  2741. fln = ln;
  2742. store = $0;
  2743. mode = "F";
  2744. next;
  2745. }
  2746. }
  2747. /^\{ *$/ {
  2748. if (mode == "F") {
  2749. printf("F:#line %d \"%s\"\n", fln, src);
  2750. printf("F:%s;\n", store);
  2751. printf("I:%s;\n", store);
  2752. store = "";
  2753. mode = "";
  2754. next;
  2755. }
  2756. }
  2757. {
  2758. if (mode == "D")
  2759. printf("D:%s\n", $0);
  2760. else if (mode == "F")
  2761. store = store " " $0;
  2762. }
  2763. ' "src=$src" "define=$opt_D" "class=$opt_C" >>$tmpfile
  2764. done
  2765. if [ ".$opt_v" = .yes ]; then
  2766. echo "" 1>&2
  2767. fi
  2768. # start generating output header
  2769. echo "/* $opt_o -- autogenerated from $opt_t, DO NOT EDIT! */" >$output
  2770. echo "#line 1 \"$opt_t\"" >>$output
  2771. sed <$opt_t -e "1,/^${opt_M} *\$/p" -e 'd' |\
  2772. sed -e "/^${opt_M} *\$/d" >>$output
  2773. # merge in the define blocks
  2774. grep '^D:' $tmpfile | sed -e 's/^D://' >>$output
  2775. # generate standard prolog
  2776. echo "#line 1 \"_ON_THE_FLY_\"" >>$output
  2777. echo "" >>$output
  2778. echo "/* make sure the scpp source extensions are skipped */" >>$output
  2779. echo "#define $opt_D 0" >>$output
  2780. echo "#define $opt_C /**/" >>$output
  2781. # generate namespace hiding for variables
  2782. echo "" >>$output
  2783. echo "/* move intern variables to hidden namespace */" >>$output
  2784. grep '^J:' $tmpfile | sed >>$output \
  2785. -e 's/^J://' \
  2786. -e 's/ */ /g' \
  2787. -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\)\[\];.*$/#define \1 __\1/' \
  2788. -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\)\[\] =.*$/#define \1 __\1/' \
  2789. -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\);.*$/#define \1 __\1/' \
  2790. -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\) =.*$/#define \1 __\1/'
  2791. # generate namespace hiding for functions
  2792. echo "" >>$output
  2793. echo "/* move intern functions to hidden namespace */" >>$output
  2794. grep '^I:' $tmpfile | sed >>$output \
  2795. -e 's/^I://' \
  2796. -e 's/\([ (]\) */\1/g' \
  2797. -e 's/ *\([),]\)/\1/g' \
  2798. -e 's/^[^(]*[ *]\([a-zA-Z0-9_]*\)(.*$/#define \1 __\1/'
  2799. # generate prototypes for variables
  2800. echo "" >>$output
  2801. echo "/* prototypes for intern variables */" >>$output
  2802. grep '^V:' $tmpfile | sed >>$output \
  2803. -e 's/^V://' \
  2804. -e 's/ */ /g' \
  2805. -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\[\]\);.*$/\1;/' \
  2806. -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\[\]\) =.*$/\1;/' \
  2807. -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\);.*$/\1;/' \
  2808. -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\) =.*$/\1;/' \
  2809. -e 's/ ;/;/g' \
  2810. -e "s/^$opt_C /extern /"
  2811. # generate prototypes for functions
  2812. echo "" >>$output
  2813. echo "/* prototypes for intern functions */" >>$output
  2814. grep '^F:' $tmpfile | sed >>$output \
  2815. -e 's/^F://' \
  2816. -e 's/\([ (]\) */\1/g' \
  2817. -e 's/ *\([),]\)/\1/g' \
  2818. -e 's/\([* ]\)[a-zA-Z0-9_]*,/\1,/g' \
  2819. -e 's/\([* ]\)[a-zA-Z0-9_]*);/\1);/g' \
  2820. -e 's/(\*[a-zA-Z0-9_]*)(/(*)(/g' \
  2821. -e 's/\([ (]\) */\1/g' \
  2822. -e 's/ *\([),]\)/\1/g' \
  2823. -e "s/^$opt_C /extern /"
  2824. # finish generating output header
  2825. n=`(echo ''; sed <$opt_t -e "1,/^${opt_M} *\$/p" -e 'd') |\
  2826. wc -l | sed -e 's;^ *\([0-9]*\) *$;\1;'`
  2827. echo "#line $n \"$opt_t\"" >>$output
  2828. sed <$opt_t -e "/^${opt_M} *\$/,\$p" -e 'd' |\
  2829. sed -e "/^${opt_M} *\$/d" >>$output
  2830. # create final output file
  2831. if [ -f $opt_o ]; then
  2832. if [ ".$opt_p" = .yes ]; then
  2833. grep -v '^#line' $opt_o >$tmpfile.o
  2834. grep -v '^#line' $output >$tmpfile.n
  2835. out_old="$tmpfile.o"
  2836. out_new="$tmpfile.n"
  2837. else
  2838. out_old="$opt_o"
  2839. out_new="$output"
  2840. fi
  2841. if cmp -s $out_old $out_new; then
  2842. :
  2843. else
  2844. cp $output $opt_o
  2845. fi
  2846. else
  2847. cp $output $opt_o
  2848. fi
  2849. rm -f $output
  2850. rm -f $tmpfile $tmpfile.* >/dev/null 2>&1
  2851. ;;
  2852. version )
  2853. ##
  2854. ## version -- Maintain a version information file
  2855. ## Copyright (c) 1994-2001 Ralf S. Engelschall <rse@engelschall.com>
  2856. ## Originally written for ePerl, rewritten from scratch for shtool
  2857. ##
  2858. file="$1"
  2859. # determine prefix and name
  2860. name="$opt_n"
  2861. prefix="$opt_p"
  2862. # determine current version
  2863. triple="$opt_s"
  2864. if [ ".$triple" != . ]; then
  2865. # use given triple
  2866. if [ ".`echo $triple | grep '[0-9]*.[0-9]*[sabp.][0-9]*'`" = . ]; then
  2867. echo "$msgprefix:Error: invalid argument to option \`-s': \`$opt_s'" 1>&2
  2868. exit 1
  2869. fi
  2870. eval `echo $triple |\
  2871. sed -e 's%\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\).*%\
  2872. ver="\1";rev="\2";typ="\3";lev="\4"%'`
  2873. tim=calc
  2874. elif [ -r $file ]; then
  2875. # determine triple from given file
  2876. eval `grep 'Version [0-9]*.[0-9]*[sabp.][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $file |\
  2877. head -1 | sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*%\
  2878. ver="\1";rev="\2";typ="\3";lev="\4";tim="\5"%'`
  2879. else
  2880. # intialise to first version
  2881. ver=0
  2882. rev=1
  2883. typ=.
  2884. lev=0
  2885. tim=calc
  2886. fi
  2887. # determine new version in batch
  2888. if [ ".$opt_i" != . ]; then
  2889. case $opt_i in
  2890. v ) ver=`expr $ver + 1`
  2891. rev=0
  2892. lev=0
  2893. ;;
  2894. r ) rev=`expr $rev + 1`
  2895. lev=0
  2896. ;;
  2897. l ) lev=`expr $lev + 1`
  2898. ;;
  2899. * ) echo "$msgprefix:Error: invalid argument to option \`-i': \`$opt_i'" 1>&2
  2900. exit 1
  2901. ;;
  2902. esac
  2903. tim=calc
  2904. fi
  2905. # determine new version interactively
  2906. if [ ".$opt_e" = .yes ]; then
  2907. echo "old version: ${ver}.${rev}${typ}${lev}"
  2908. while [ 1 ]; do
  2909. echo dummy | awk '{ printf("new version: "); }'
  2910. read triple
  2911. case $triple in
  2912. [0-9]*.[0-9]*[sabp.][0-9]* )
  2913. ;;
  2914. * ) echo "$msgprefix:Error: invalid version string entered: \`$triple'" 1>&2
  2915. continue
  2916. ;;
  2917. esac
  2918. break
  2919. done
  2920. eval `echo $triple |\
  2921. sed -e 's%^\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\)$%\
  2922. ver="\1";rev="\2";typ="\3";lev="\4"%'`
  2923. tim=calc
  2924. fi
  2925. # determine hexadecimal and libtool value of version
  2926. case $typ in
  2927. a ) typnum=0; levnum=$lev ;;
  2928. b ) typnum=1; levnum=$lev ;;
  2929. p | . ) typnum=2; levnum=$lev ;;
  2930. s ) typnum=15; levnum=255 ;; # snapshots are special
  2931. esac
  2932. hex=`echo "$ver:$rev:$typnum:$levnum" |\
  2933. awk -F: '{ printf("0x%x%02x%1x%02x", $1, $2, $3, $4); }' |\
  2934. tr 'abcdef' 'ABCDEF'`
  2935. ltv=`echo "$ver:$rev:$typnum:$levnum" |\
  2936. awk -F: '{ printf("%d:%d", $1*10 + $2, $3*10 + $4); }'`
  2937. # determine date
  2938. if [ ".$tim" = .calc ]; then
  2939. day=`date '+%d'`
  2940. month=`date '+%m'`
  2941. year=`date '+%Y' 2>/dev/null`
  2942. if [ ".$time_year" = . ]; then
  2943. year=`date '+%y'`
  2944. case $year in
  2945. [5-9][0-9]) year="19$year" ;;
  2946. [0-4][0-9]) year="20$year" ;;
  2947. esac
  2948. fi
  2949. case $month in
  2950. 1|01) month='Jan' ;;
  2951. 2|02) month='Feb' ;;
  2952. 3|03) month='Mar' ;;
  2953. 4|04) month='Apr' ;;
  2954. 5|05) month='May' ;;
  2955. 6|06) month='Jun' ;;
  2956. 7|07) month='Jul' ;;
  2957. 8|08) month='Aug' ;;
  2958. 9|09) month='Sep' ;;
  2959. 10) month='Oct' ;;
  2960. 11) month='Nov' ;;
  2961. 12) month='Dec' ;;
  2962. esac
  2963. tim="${day}-${month}-${year}"
  2964. fi
  2965. # perform result actions
  2966. mode=show
  2967. if [ ".$opt_i" != . ]; then
  2968. mode=edit
  2969. elif [ ".$opt_e" = .yes ]; then
  2970. mode=edit
  2971. elif [ ".$opt_s" != . ]; then
  2972. mode=edit
  2973. fi
  2974. if [ ".$mode" = .show ]; then
  2975. # just display the current version
  2976. case $opt_d in
  2977. short )
  2978. echo "${ver}.${rev}${typ}${lev}"
  2979. ;;
  2980. long )
  2981. echo "${ver}.${rev}${typ}${lev} ($tim)"
  2982. ;;
  2983. libtool )
  2984. echo "${ltv}"
  2985. ;;
  2986. hex )
  2987. echo "${hex}"
  2988. ;;
  2989. * ) echo "$msgprefix:Error: invalid argument to option \`-d': \`$opt_d'" 1>&2
  2990. exit 1
  2991. ;;
  2992. esac
  2993. else
  2994. # update the version file
  2995. # pre-generate various strings
  2996. triple="${ver}.${rev}${typ}${lev}"
  2997. vHex="$hex"
  2998. vShort="${triple}"
  2999. vLong="${triple} (${tim})"
  3000. vTeX="This is ${name}, Version ${triple} (${tim})"
  3001. vGNU="${name} ${triple} (${tim})"
  3002. vWeb="${name}/${triple}"
  3003. vSCCS="@(#)${name} ${triple} (${tim})"
  3004. vRCS="\$Id: ${name} ${triple} (${tim}) \$"
  3005. # determine string out of filename
  3006. # (do NOT try to optimize this in any way because of portability)
  3007. filestr=`echo $file |\
  3008. tr 'abcdefghijklmnopqrstuvwxyz./%+' \
  3009. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ____' | sed -e 's/-/_/g'`
  3010. # generate uppercase prefix
  3011. prefixupper=`echo $prefix |\
  3012. tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
  3013. # create the version file according the the selected language
  3014. echo "new version: ${vLong}"
  3015. cp /dev/null $file
  3016. case $opt_l in
  3017. txt )
  3018. echo >>$file ""
  3019. echo >>$file " ${file} -- Version Information for ${name} (syntax: Text)"
  3020. echo >>$file " [automatically generated and maintained by GNU shtool]"
  3021. echo >>$file ""
  3022. echo >>$file " $vTeX"
  3023. echo >>$file ""
  3024. ;;
  3025. c )
  3026. echo >>$file "/*"
  3027. echo >>$file "** ${file} -- Version Information for ${name} (syntax: C/C++)"
  3028. echo >>$file "** [automatically generated and maintained by GNU shtool]"
  3029. echo >>$file "*/"
  3030. echo >>$file ""
  3031. echo >>$file "#ifdef _${filestr}_AS_HEADER_"
  3032. echo >>$file ""
  3033. echo >>$file "#ifndef _${filestr}_"
  3034. echo >>$file "#define _${filestr}_"
  3035. echo >>$file ""
  3036. echo >>$file "#define ${prefixupper}VERSION ${vHex}"
  3037. echo >>$file ""
  3038. echo >>$file "typedef struct {"
  3039. echo >>$file " const int v_hex;"
  3040. echo >>$file " const char *v_short;"
  3041. echo >>$file " const char *v_long;"
  3042. echo >>$file " const char *v_tex;"
  3043. echo >>$file " const char *v_gnu;"
  3044. echo >>$file " const char *v_web;"
  3045. echo >>$file " const char *v_sccs;"
  3046. echo >>$file " const char *v_rcs;"
  3047. echo >>$file "} ${prefix}version_t;"
  3048. echo >>$file ""
  3049. echo >>$file "extern ${prefix}version_t ${prefix}version;"
  3050. echo >>$file ""
  3051. echo >>$file "#endif /* _${filestr}_ */"
  3052. echo >>$file ""
  3053. echo >>$file "#else /* _${filestr}_AS_HEADER_ */"
  3054. echo >>$file ""
  3055. echo >>$file "#define _${filestr}_AS_HEADER_"
  3056. echo >>$file "#include \"${file}\""
  3057. echo >>$file "#undef _${filestr}_AS_HEADER_"
  3058. echo >>$file ""
  3059. echo >>$file "${prefix}version_t ${prefix}version = {"
  3060. echo >>$file " ${vHex},"
  3061. echo >>$file " \"${vShort}\","
  3062. echo >>$file " \"${vLong}\","
  3063. echo >>$file " \"${vTeX}\","
  3064. echo >>$file " \"${vGNU}\","
  3065. echo >>$file " \"${vWeb}\","
  3066. echo >>$file " \"${vSCCS}\","
  3067. echo >>$file " \"${vRCS}\""
  3068. echo >>$file "};"
  3069. echo >>$file ""
  3070. echo >>$file "#endif /* _${filestr}_AS_HEADER_ */"
  3071. echo >>$file ""
  3072. ;;
  3073. perl )
  3074. echo >>$file "##"
  3075. echo >>$file "## ${file} -- Version Information for ${name} (syntax: Perl)"
  3076. echo >>$file "## [automatically generated and maintained by GNU shtool]"
  3077. echo >>$file "##"
  3078. echo >>$file ""
  3079. echo >>$file "my \$${prefix}version = {"
  3080. echo >>$file " 'v_hex' => ${vHex},"
  3081. echo >>$file " 'v_short' => \"${vShort}\","
  3082. echo >>$file " 'v_long' => \"${vLong}\","
  3083. echo >>$file " 'v_tex' => \"${vTeX}\","
  3084. echo >>$file " 'v_gnu' => \"${vGNU}\","
  3085. echo >>$file " 'v_web' => \"${vWeb}\","
  3086. echo >>$file " 'v_sccs' => \"${vSCCS}\","
  3087. echo >>$file " 'v_rcs' => \"\\${vRCS}/\""
  3088. echo >>$file "};"
  3089. echo >>$file ""
  3090. echo >>$file "1;"
  3091. echo >>$file ""
  3092. ;;
  3093. python )
  3094. echo >>$file "##"
  3095. echo >>$file "## ${file} -- Version Information for ${name} (syntax: Python)"
  3096. echo >>$file "## [automatically generated and maintained by GNU shtool]"
  3097. echo >>$file "##"
  3098. echo >>$file ""
  3099. echo >>$file "class ${prefix}version:"
  3100. echo >>$file " v_hex = ${vHex}"
  3101. echo >>$file " v_short = \"${vShort}\""
  3102. echo >>$file " v_long = \"${vLong}\""
  3103. echo >>$file " v_tex = \"${vTeX}\""
  3104. echo >>$file " v_gnu = \"${vGNU}\""
  3105. echo >>$file " v_web = \"${vWeb}\""
  3106. echo >>$file " v_sccs = \"${vSCCS}\""
  3107. echo >>$file " v_rcs = \"${vRCS}\""
  3108. echo >>$file ""
  3109. ;;
  3110. * ) echo "$msgprefix:Error: invalid argument to option \`-l': \`$opt_l'" 1>&2
  3111. exit 1
  3112. ;;
  3113. esac
  3114. fi
  3115. ;;
  3116. path )
  3117. ##
  3118. ## path -- Deal with program paths
  3119. ## Copyright (c) 1998-2001 Ralf S. Engelschall <rse@engelschall.com>
  3120. ## Originally written for Apache
  3121. ##
  3122. namelist="$*"
  3123. # check whether the test command supports the -x option
  3124. if [ -x /bin/sh ] 2>/dev/null; then
  3125. minusx="-x"
  3126. else
  3127. minusx="-r"
  3128. fi
  3129. # split path string
  3130. paths="`echo $opt_p |\
  3131. sed -e 's/^:/.:/' \
  3132. -e 's/::/:.:/g' \
  3133. -e 's/:$/:./' \
  3134. -e 's/:/ /g'`"
  3135. # SPECIAL REQUEST
  3136. # translate forward to reverse path
  3137. if [ ".$opt_r" = .yes ]; then
  3138. if [ "x$namelist" = "x." ]; then
  3139. rp='.'
  3140. else
  3141. rp=''
  3142. for pe in `IFS="$IFS/"; echo $namelist`; do
  3143. rp="../$rp"
  3144. done
  3145. fi
  3146. echo $rp | sed -e 's:/$::'
  3147. exit 0
  3148. fi
  3149. # SPECIAL REQUEST
  3150. # strip out directory or base name
  3151. if [ ".$opt_d" = .yes ]; then
  3152. echo "$namelist" |\
  3153. sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
  3154. exit 0
  3155. fi
  3156. if [ ".$opt_b" = .yes ]; then
  3157. echo "$namelist" |\
  3158. sed -e 's;.*/\([^/]*\)$;\1;'
  3159. exit 0
  3160. fi
  3161. # MAGIC SITUATION
  3162. # Perl Interpreter (perl)
  3163. if [ ".$opt_m" = .yes -a ".$namelist" = .perl ]; then
  3164. rm -f $tmpfile >/dev/null 2>&1
  3165. touch $tmpfile
  3166. found=0
  3167. pc=99
  3168. for dir in $paths; do
  3169. dir=`echo $dir | sed -e 's;/*$;;'`
  3170. nc=99
  3171. for name in perl perl5 miniperl; do
  3172. if [ $minusx "$dir/$name" -a ! -d "$dir/$name" ]; then
  3173. perl="$dir/$name"
  3174. pv=`$perl -e 'printf("%.3f", $]);'`
  3175. echo "$pv:$pc:$nc:$perl" >>$tmpfile
  3176. found=1
  3177. fi
  3178. nc=`expr $nc - 1`
  3179. done
  3180. pc=`expr $pc - 1`
  3181. done
  3182. if [ $found = 1 ]; then
  3183. perl="`cat $tmpfile | sort -u | tail -1 | cut -d: -f4`"
  3184. rm -f $tmpfile >/dev/null 2>&1
  3185. echo "$perl"
  3186. exit 0
  3187. fi
  3188. rm -f $tmpfile >/dev/null 2>&1
  3189. exit 1
  3190. fi
  3191. # MAGIC SITUATION
  3192. # C pre-processor (cpp)
  3193. if [ ".$opt_m" = .yes -a ".$namelist" = .cpp ]; then
  3194. echo >$tmpfile.c "#include <assert.h>"
  3195. echo >>$tmpfile.c "Syntax Error"
  3196. # 1. try the standard cc -E approach
  3197. cpp="${CC-cc} -E"
  3198. (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  3199. my_error=`grep -v '^ *+' $tmpfile.out`
  3200. if [ ".$my_error" != . ]; then
  3201. # 2. try the cc -E approach and GCC's -traditional-ccp option
  3202. cpp="${CC-cc} -E -traditional-cpp"
  3203. (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  3204. my_error=`grep -v '^ *+' $tmpfile.out`
  3205. if [ ".$my_error" != . ]; then
  3206. # 3. try a standalone cpp command in path and lib dirs
  3207. for path in $paths /lib /usr/lib /usr/local/lib; do
  3208. path=`echo $path | sed -e 's;/*$;;'`
  3209. if [ $minusx "$path/cpp" -a ! -d "$path/cpp" ]; then
  3210. cpp="$path/cpp"
  3211. break
  3212. fi
  3213. done
  3214. if [ ".$cpp" != . ]; then
  3215. (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  3216. my_error=`grep -v '^ *+' $tmpfile.out`
  3217. if [ ".$my_error" != . ]; then
  3218. # ok, we gave up...
  3219. cpp=''
  3220. fi
  3221. fi
  3222. fi
  3223. fi
  3224. rm -f $tmpfile >/dev/null 2>&1
  3225. rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1
  3226. if [ ".$cpp" != . ]; then
  3227. echo "$cpp"
  3228. exit 0
  3229. fi
  3230. exit 1
  3231. fi
  3232. # STANDARD SITUATION
  3233. # iterate over names
  3234. for name in $namelist; do
  3235. # iterate over paths
  3236. for path in $paths; do
  3237. path=`echo $path | sed -e 's;/*$;;'`
  3238. if [ $minusx "$path/$name" -a ! -d "$path/$name" ]; then
  3239. if [ ".$opt_s" != .yes ]; then
  3240. echo "$path/$name"
  3241. fi
  3242. exit 0
  3243. fi
  3244. done
  3245. done
  3246. exit 1
  3247. ;;
  3248. esac
  3249. exit 0
  3250. ##EOF##