#!/bin/bash [ ! -d .git ] && exit 1 opt=$1; shift chapters="par gnx mp pfor alsk" subdirs="alg fig lst" acronyms= commands= for subdir in $(echo ${subdirs}); do rm -rf "src/${subdir}/*" done rm -f 'src/tikz/*' # gather chapter sources chn=0 cp '../remerciements/src/thanks.tex' "src/${chn}_1_thanks.tex" for chapter in $(echo ${chapters}); do rm -rf "src/${chapter}" cp -rf "../${chapter}/src/${chapter}" 'src' chn=$((chn+1)) if [ "${opt}" != 'contents' ]; then cp "../${chapter}/src/${chapter}.tex" "src/${chn}_${chapter}.tex" fi rm -rf "img/${chapter}" cp -rf "../${chapter}/img/${chapter}" 'img' cp "../${chapter}/src/tikz/"* 'src/tikz/' for subdir in $(echo ${subdirs}); do dir="../${chapter}/src/${subdir}/${chapter}" if [ -d "${dir}" ]; then cp -rf "${dir}" "src/${subdir}/" fi done acronymsfile="../${chapter}/src/acronyms.tex" if [ -f "${acronymsfile}" ]; then acronyms="${acronyms} ${acronymsfile}" fi commandsfile="../${chapter}/src/commands.tex" if [ -f "${commandsfile}" ]; then commands="${commands} ${commandsfile}" fi done # merge all acronyms files letter=A previous= while read line; do current=$(echo "${line}"|cut -d'{' -f2|cut -d'}' -f1) curletter=$(echo "${current}"|cut -c1) if [ "${curletter}" != "${letter}" ]; then echo letter="${curletter}" fi if [ "${current}" = "${previous}" ]; then echo>&2 "[acronyms] incoherent duplicate for {${current}}" fi previous="${current}" echo "${line}" done<<<$(sort -u ${acronyms}|grep -Ev '^$'|sed 's,\\,\\\\,g')>src/acronyms.tex # merge all commands files declare -A arrcmds for cmds in ${commands}; do chapter=$(echo "${cmds}"|cut -d'/' -f2) echo "%{{{ ${chapter} \"" while read line; do cmd=$(sed -re 's/[^{]*\{([^}]+)\}.*/\1/'<<<"${line}") if [ -n "${cmd}" ]; then if [ ${arrcmds[${cmd}]+x} ]; then if [ ${arrcmds[${cmd}]} != ${line} ]; then echo>&2 "[commands] incoherent duplicate for ${cmd}" fi echo -n "% " else arrcmds[${cmd}]="${line}" fi echo "${line}" fi done<<<$(sed 's,\\,\\\\,g' ${cmds}) echo "%}}}" done>src/commands.tex