#!/bin/bash

extract() {
  echo "// file generated by $0, do not edit!"

  dump="0"
  while read line
  do
    # echo "[$dump]" $line
    if [ "$dump" == "1" ]
    then
      echo $line | grep "CLASS" >&/dev/null && break
    fi

    if [ "$dump" == "1" ]
    then
      decl="0"
      echo $line | grep 'double cam_xyz' >&/dev/null && decl="1"
      echo $line | grep 'cam_xyz_coeff'  >&/dev/null && decl="1"
      echo $line | grep '\.black'      >&/dev/null && echo -n "// "
      echo $line | grep '\.maximum'    >&/dev/null && echo -n "// "
      if [ "$decl" == "0" ]
      then
        echo "$line"
      fi
    else
      echo $line | grep "CLASS adobe_coeff" >&/dev/null && dump="1"
      if [ "$dump" == "1" ]
      then
        echo "static void dt_dcraw_adobe_coeff(const char *make, const char *model, float cam_xyz[1][12])"
      fi
    fi
    
  done
}

wget -nc www.cybercom.net/~dcoffin/dcraw/dcraw.c
cat dcraw.c | extract > adobe_coeff.c
git diff
