! This macro formats a C module in a standard way. To invoke it,
  type "mung cmat filename" where the filename does not have a ".c" !

! save the file name !

hxf

! open the file and read it into the edit buffer !

^U9eb

h:x9
:^U9.c

27:^U9

27:^U9

m9
ey

! delete leading and trailing blank lines !

!label1!0a-13"e1a-10"e2dolabel1''
!label2!z-4j0a-13"e1a-10"e2a-13"e3a-10"e2dolabel2''''

! Standardize the initial comment.  If it doesn't exist, then insert  !
! a standard format dummy comment.  If it does exist,  then make sure !
! the leading and trailing lines are standard. !

0j
0a-47"ni/*****************************************************************************

	gfi()

	This function...

*****************************************************************************/


|
1a-42"ncan't understand first line of file. Dying.
'
ki/*77<i*>i
s
*0lk77<i*>i/


'
'

! We're past on the line after the initial comment.  If it is blank,
  make sure that there's only one blank line before the first non-blank
  line.  If it is not blank,  insert a blank line. !

0a-13"e
l<0a-13"ek|1;'>
|
i
'

! We are now pointing at the # on the first include line. Check that !
! it is the include line for portab.h  For this line and all !
! succeeding include lines,  put in the standard comments at the !
! standard offset !

::S#include "portab.h""u
first line after comment isn't include line for portab.h. Dying.
odone

|
ki		/* define portability identifiers */
'

!label3!::S#include ""s
.ua
::SChrFuncs.h""s
ki		/* define character processing macros */
|qaj::SDefError.h""s
ki		/* define identifiers for error messages */
|qaj::SDefTeco.h""s
ki		/* define general identifiers */
|qaj::SDefChars.h""s
ki		/* define identifiers for characters */
|qaj::SDefScren.h""s
ki		/* define identifiers for screen i/o */
|
unrecognized include file. Dying.
odone'''''olabel3

'

0a-13"el|i
'
!label4!0a-13"e1a-10"e2dolabel4''


! We are now pointing at the first line of the external function !
! definitions,  if there are any.  For each line that contains the !
! string (); we want to line up the comments. !


<                                 ! for all function definition lines !
::1FB();"s                       ! if the line contains (); !
    0L
    ::Sextern"u
    iextern	

    |
    di	

    '
    s^es-di	                 ! move to tab after the descriptor !
    .uas();                     ! count length of function name !
    .ubs/rqb-.d                  ! delete from ; to / !
    (.-qa)-8"li	'                ! if it's a short name, add a tab !
    i	

    L
|                                 ! else it doesn't contain (); !
    1;                                ! exit the loop !
'
>


! and finally exit !

!done!ex
