Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /tests/examples/gen-readme.sh
ViewVC logotype

Annotation of /tests/examples/gen-readme.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4640 - (view) (download) (as text)

1 : glk 4640 #!/usr/bin/env bash
2 :     set -o nounset
3 :    
4 :     # Look away! This is a super-cheesy bash script to generate README.md files
5 :     # from the (hopefully one) comment delimited by $flag in the (hopefully
6 :     # single) such diderot program per example directory. Normal people would use
7 :     # a proper text-processing DSL for this task.
8 :    
9 :     # This is the special flag, within the the top comment, that signifies
10 :     # that this is supposed to be put into a markdown file.
11 :     flag='=========================================='
12 :    
13 :     saveIFS="$IFS"
14 :    
15 :     examples=$(find . -depth 1 -type d -print | grep -v \.git)
16 :    
17 :     for exdir in $examples; do
18 :     echo $exdir ...
19 :     ddros=$(ls -1 $exdir/*.diderot)
20 :     got=""
21 :     gotnum=0
22 :     for ddr in $ddros; do
23 :     if grep -q -F $flag $ddr; then
24 :     got=$ddr
25 :     ((gotnum++))
26 :     fi
27 :     done
28 :     if [ $gotnum -eq 0 ]; then
29 :     continue
30 :     fi
31 :     if [ $gotnum -gt 1 ]; then
32 :     echo "$0: HEY got $gotnum programs with markdown, only processing last one: $got"
33 :     fi
34 :     rm -f $exdir/README.md ||:
35 :     touch $exdir/README.md
36 :     printing=0
37 :     echo " ... processing $got to create $exdir/README.md"
38 :     IFS='' # to preserve spaces and tabs when reading lines of README.md
39 :     cat $got | while read line; do
40 :     if [[ "$line" =~ $flag ]]; then
41 :     # toggle whether we print
42 :     printing=$((1 - $printing))
43 :     fi
44 :     # but don't print line that triggered toggling
45 :     if [[ $printing -eq 1 && ! "$line" =~ $flag ]]; then
46 :     echo "$line" >> $exdir/README.md
47 :     fi
48 :     done
49 :     IFS="$saveIFS"
50 :     done

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0