{{{  comments
; This is a macropackage to convert ansi-c functiondeclarations
; to K&R-c syntax.
; You can either use ansi-to-kr, which translates the header, or
; ifdef-ansi-to-kr, which leaves the original header and put #ifdef STD_C
; in the code.


; the macros work only correct, if

; the header is a correct ansi-c-header
; the ( of the argumentlist and the functiontype are on the same line

{{{  examples for using ifdef-ansi-to-kr
@if-using (GDGGDGDGDGDDG) ; hope this isn't defined :-)
{{{  1

void f(void)

is modified to

#ifdef STD_C
void f(void)
#else
f()
#fi

}}}
{{{  2

test_typ intd(int ggg,int (*getc_fcn)())

is modified to

#ifdef STD_C
test_typ intd(int ggg,int (*getc_fcn)())
#else
test_typ intd(ggg,getc_fcn)
int ggg;
int (*getc_fcn)();
#fi

}}}
{{{  3

int lp(int x,
       bool y,
       ... )

is modified to

#ifdef STD_C
int lp(int x,
       bool y,
       ... )
#else
int lp(x,y)
int x;
bool y;
#fi

}}}
{{{  4

int lp(
  int x,
  bool y,...
  )

is modified to

#ifdef STD_C
int lp(
  int x,
  bool y,...
  )
#else
int lp(x,y)
int x;
bool y;
#fi

}}}
@fi
}}}
{{{  examples for using ansi-to-kr
@if-using (GDGGDGDGDGDDG) ; hope this isn't defined :-)
{{{  1

void f(void)

is modified to

f()

}}}
{{{  2

test_typ intd(int ggg,int (*getc_fcn)())

is modified to

test_typ intd(ggg,getc_fcn)
int ggg;
int (*getc_fcn)();

}}}
{{{  3

int lp(int x,
       bool y,
       ... )

is modified to

int lp(x,y)
int x;
bool y;

}}}
{{{  4

int lp(x,y)
int x;
bool y;

is modified to

int lp(
  int x,
  bool y,...
  )

}}}
@fi
}}}
}}}
@if-using not(STDC)
  @use (STDC)
  {{{  libs
  {{{F fun/error
  :::F fun/error
  }}}
  {{{F fun/go-match
  :::F fun/go-match
  }}}
  {{{F fun/delspaces
  :::F fun/delspaces
  }}}
  {{{F fun/append
  :::F fun/append
  }}}
  {{{F fun/pre-char
  :::F fun/pre-char
  }}}
  {{{F fun/next-char
  :::F fun/next-char
  }}}
  }}}
  {{{  vars
  ( defvar
     ( y1           ; local help
       y2           ;     "
     )
  )
  }}}
  {{{  local needed macros
  {{{  header-folder
  (deffun header-folder (
    {{{  make header fold
    {{{  look for line ending with ); or )
    end-of-line
    backward-character
    while not(or(test-char "),
              and(test-char ";,pre(backward-character) test-char ") )))
      (next-line end-of-line backward-character)
    }}}
    {{{  create a fold around the header
    local (y1 y2) (
      set-counter y2 store-line
      goto-matching-fence
      if test-begin-line (previous-line) fi
      set-counter y1 +(y2 -(1 store-line))
      beginning-of-line
      create-fold
      while counter>0 y1 (next-line set-counter y1 +(y1 -1))
      create-fold
    )
    }}}
    }}}
  ))
  }}}
  {{{  ansi-fold-to-kr-fold
  ( deffun ansi-fold-to-kr-fold
     ( if test-overwrite ( failed ) fi
       screen-off
       beginning-of-line
       create-fold
       next-line
       create-fold
       enter-fold
       {{{  header, ( arguments ); all on own lines!
       enter-fold
       end-of-fold
       search-reverse ") newline-and-indent
       newline-and-indent
       {{{  complete argumentlist parsed
       previous-line
       end-of-line
       backward-character
       while not(test-top) (
         if test-char "  (
           {{{  delete the empty line
           delete-line
           previous-line
           end-of-line
           backward-character
           }}}
         ) else (
           {{{  handle the line
           case
             (test-char ", (
               {{{  comma between arguments
               newline-and-indent
               previous-line
               end-of-line
               backward-character
               }}}
             ))
             (test-char ". (
               {{{  delete arglist
               forward-character
               while not(pre (
                           delete-previous-character
                           undo-delete-character
                           backward-character
                         ) test-char ",)
               (
                 delete-character
               )
               delete-character
               delspaces
               if test-char ") (newline-and-indent previous-line end-of-line) fi
               backward-character
               }}}
             ))
           default
             (
               {{{  argument - must be complete on one line!!!!!!!!!!!!!!!!
               while not(or(test-begin-line,test-char ", ,test-char "( ))
                 ( goto-matching-fence backward-character )
               if test-char ", (
                 newline-and-indent
                 forward-character
                 newline-and-indent
                 previous-line
               ) else (
                 if test-char "( (
                   newline-and-indent
                   forward-character
                   newline-and-indent
                   beginning-of-fold
                 ) fi
               )fi
               previous-line
               end-of-line
               backward-character
               }}}
             )
           esac
           }}}
         ) fi
       )
       }}}
       beginning-of-line
       while not(test-bottom) (
         delspaces
         if test-end-line (delete-line) else (next-line) fi
       )
       end-of-fold
       previous-line
       previous-line
       if and(test-char "v,
              pre (forward-character) test-char "o,
              pre (forward-character) test-char "i,
              pre (forward-character) test-char "d,
              pre (forward-character) test-end-line)
        ( delete-line ) fi
       exit-fold
       }}}
       double-line
       {{{  change , to ;
       enter-fold
       beginning-of-line
       while not(test-char "() (delete-line)
       delete-line
       while not(test-char "))
        ( if test-char ", ( delete-line previous-line end-of-line "; ) fi
          next-line beginning-of-line
        )
       delete-line
       previous-line
       end-of-line
       if not(test-top) ("; ) fi
       exit-fold
       }}}
       previous-line
       {{{  remove types and combine lines
       enter-fold
       end-of-fold
       previous-line
       previous-line
       beginning-of-line
       while not(test-char "()
        ( if not(test-char ",)
           {{{  cut varname
           ( end-of-line
             backward-character
             while or(test-char "],test-char "))
              ( if test-char "] (goto-matching-fence) fi
                backward-character
                if test-char "( (backward-character) fi
              )
             forward-character
             delete-to-end-of-line
             backward-character
             while not(or(test-char "*,test-char "(, test-char " ,test-char ")))
              ( backward-character )
             forward-character
             newline-and-indent
             previous-line
             delete-line
           )
           }}}
          fi
          next-line
          append-to-previous-line
          previous-line
          beginning-of-line
        )
       append-to-previous-line
       next-line
       append-to-previous-line
       beginning-of-line
       if and(test-char "v,
              pre (forward-character) test-char "o,
              pre (forward-character) test-char "i,
              pre (forward-character) test-char "d,
              pre
               ( forward-character while test-char "  ( forward-text-character )
               ) not(or(test-char "*,test-char "( )))
        ( previous-text-character
          delete-previous-character
          delete-previous-character
          delete-previous-character
          delete-previous-character
          if test-end-line (delete-character) fi
          delspaces
        )
       fi
       exit-fold
       }}}
       unfold-fold
       next-line
       unfold-fold
       exit-fold
       screen-on
       redraw-display
     )
  )
  }}}
  }}}
  {{{  ifdef-ansi-to-kr
  (deffun ifdef-ansi-to-kr (
    if test-overwrite ( failed ) fi
    screen-off
    delete-mode-overwrite
    header-folder
    beginning-of-line newline-and-indent previous-line
    "#ifdef "  "STD_C
    next-line
    double-line
    beginning-of-line newline-and-indent previous-line
    "#else
    next-line
    end-of-line
    newline-and-indent "#endif
    previous-line
    ansi-fold-to-kr-fold
    {{{  remove folds
    unfold-fold
    previous-line
    unfold-fold
    previous-line
    unfold-fold
    }}}
    screen-on
    redraw-display
  ))
  }}}
  {{{  ansi-to-kr
  (deffun ansi-to-kr (
    screen-off
    header-folder
    ansi-fold-to-kr-fold
    unfold-fold
    screen-on
    redraw-display
  ))
  }}}
  {{{  undeclare
  ( undeclare ( y1 y2 header-folder ansi-fold-to-kr-fold ) )
  }}}
@fi
