File indexing completed on 2024-04-14 05:33:34

0001 #!/bin/sh
0002 #
0003 # Copyright (c) 2018, Michal Policht. This file is dually licensed under terms of 
0004 # either WTFPL or BEER-WARE LICENSE. You may obtain the copy of WTFPL or BEER-WARE
0005 # LICENSE by googling it. NO WARRANTY. YOU WILL PAY ALL COSTS FOR ANY REPAIRS.
0006 #
0007 # A chain of commands to update header file include guard.
0008 #
0009 # usage: awkgward.sh awk_program header_file [prefix] [IORS]
0010 # example: awkgward.sh gawk header.hpp
0011 #
0012 # parameters:
0013 # awk_program - name of AWK implementation.
0014 # header_file - header file.
0015 # prefix - include guard prefix
0016 # IORS - input/output record separator (new lines style; typically: "\n" - unix mac "\r\n" - windows).
0017 #
0018 # required tools: sh, cut, grep, touch, stat, awk, echo, mv, awkgward.awk
0019 
0020 
0021 usage()
0022 {
0023     echo "usage: $0 awk_program header_file [prefix] [IORS]"
0024     echo "note: working directory from which this script is called"
0025     echo "      must be a directory containing awkgward directory."
0026 }
0027 
0028 if [ ! -e $2 ]; then
0029         echo $2 "does not exist"
0030         exit 1
0031 fi      
0032 
0033 if [ $# -lt 2 ]; then
0034     echo "error: too few arguments"
0035     usage
0036     exit 0
0037 fi
0038 
0039 if [ $# -gt 2 ]; then
0040     prefix=$3;
0041 else
0042     prefix=""
0043 fi
0044 
0045 if [ $# -gt 3 ]; then
0046     iors=$4;
0047 else
0048     iors="\n"
0049 fi
0050 
0051 awk_program=$1
0052 header_file=$2
0053 echo $header_file
0054 timestamp=`stat $header_file | grep 'Modify: ' | cut -d ' ' -f 2,3,4`
0055 $awk_program -v ORS="$iors" -v RS="$iors" -v prefix="$prefix" -f awkgward/awkgward.awk $header_file > $header_file.awkgward
0056 mv $header_file.awkgward $header_file
0057 touch -md "$timestamp" $header_file
0058