Debian Codegraph @

tools/internal/examples_edit_readmes_helper

raw symbols SCIP
1 #!/bin/bash
2 set -eux
3
4 # ----------------------------------------------------------------------------
5 # Helper script used by examples_edit_readmes.
6 # Runs in particular project.
7 # ----------------------------------------------------------------------------
8
9 if ls *.lfm > /dev/null 2>&1; then
10 echo `pwd`": LCL project"
11 exit 0
12 fi
13
14 if ! ls README.md > /dev/null 2>&1; then
15 echo `pwd`": WARNING: No README.md"
16 exit 0
17 fi
18
19 PROJECT_PASCAL_NAME="`castle-engine output pascal-name`"
20
21 # Note: Escape regexp special characters like [] below.
22 # These are used with both grep and sed, we have to escape them.
23 # (While grep has --fixed-strings, sed has no such option.)
24 # See https://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions
25
26 # EXISTING_TEXT='[CGE Lazarus packages](https://castle-engine.io/documentation.php)'
27 # NEW_TEXT='[CGE Lazarus packages](https://castle-engine.io/lazarus)'
28
29 EXISTING_TEXT="- Or use [Lazarus](https://www.lazarus-ide.org/). Open in Lazarus \`${PROJECT_PASCAL_NAME}_standalone.lpi\` file and compile / run from Lazarus. Make sure to first register [CGE Lazarus packages](https://castle-engine.io/lazarus)."
30 NEW_TEXT="- Or use [Delphi](https://www.embarcadero.com/products/Delphi). Open in Delphi \`${PROJECT_PASCAL_NAME}_standalone.dproj\` file and compile / run from Delphi. See [CGE and Delphi](https://castle-engine.io/delphi) documentation for details."
31
32 EXISTING_TEXT='[CGE editor](https://castle-engine.io/manual_editor.php). Just use menu item _"Compile"_.'
33 NEW_TEXT='[CGE editor](https://castle-engine.io/editor). Just use menu items _"Compile"_ or _"Compile And Run"_.'
34
35 # Escape special regexp characters, like [], in input parameter $1.
36 # This replaces things for sed regexps.
37 function escape_regexp ()
38 {
39 # echo -- "$1"
40 echo "$1" |
41 sed --expression='s|\[|\\[|' \
42 --expression='s|\]|\\]|'
43 }
44
45 if grep --fixed-strings -- "${EXISTING_TEXT}" README.md; then
46 echo `pwd`": README.md contains expected text"
47 if grep --fixed-strings -- "${NEW_TEXT}" README.md; then
48 echo `pwd`": README.md already contains new text"
49 exit 0
50 fi
51
52 # Use this to append something to README.md:
53 #
54 # echo '' >> README.md
55 # echo "${NEW_TEXT}" >> README.md
56
57 # Use this to replace something in README.md:
58 #
59 NEW_TEXT_ESCAPED=$(escape_regexp "${NEW_TEXT}")
60 EXISTING_TEXT_ESCAPED=$(escape_regexp "${EXISTING_TEXT}")
61 sed --in-place --expression="s|${EXISTING_TEXT_ESCAPED}|${NEW_TEXT_ESCAPED}|" README.md
62 else
63 echo `pwd`": WARNING: README.md does not contain expected text"
64 fi