Examining Doxygen
by Al Williams


Listing One

BEGIN {
  cflag=0;  # comment in progress
  ocflag=0; # old comment in progress
  inblock=0;  # block flag
  afterbrace=0; #brace at end?
}

# user function to make a string have no regexp metachars
function escape(s) {
  gsub(/([\[\]\\\^\$\.\|\(\)\*\+\?\{\}])/,"\\\\&",s);
  return s;
  }


#Transform constants
$2=="con" || $2=="CON" || $2=="Con" || $2=="cOn" || $2=="coN" {
  a=$1
  b=$2
  c=$3
  apat=escape(a)
  cpat=escape(c)
  sub(b,"")
  sub(apat "[ \t]+" cpat,a " = " c);
}

# Transform x var y => y x; (should preserve comments)
$2=="var" || $2=="VAR" || $2=="Var" || $2=="vAr" || $2=="vaR" {
  a=$1
  b=$2
  c=$3
  apat=escape(a)
  cpat=escape(c)

  sub(b,"")
  sub(apat "[ \t]+" cpat,c " " a);
}


# Assume this is not a comment
  {
    cflag=0;
  }


# Whole line comment, start or extend
/^[ \t]*'/ {
  cflag=1;
# start
  if (ocflag==0)  sub("'","/*"); else sub("'","");
  ocflag=1;
  print;
  next;
  }


# process partial line comments and semicolons
  {
  if (!/[ \t]*#/) {
  if (/'/) {
    sub("'","; /*");
    $0=$0 " */"
  } else {
    if (!/:[ \t]*$/) $0=$0 ";"
    if ($0==";") $0=""
    }
   }
  }
   
# process all lines  
  {
  if (ocflag==1) {  # close pending comment
     print "*/";
     ocflag=0;
     }
  }

# handle label
match($1,/.*:/) {
  if (inblock==1) print "}";
  sub(":","",$1);
  print $1 "() {";
  inblock=1;
  sub($1,"");
}

# handle end of quasifunction
toupper($1)=="GOTO" || toupper($1)=="RETURN" {
  inblock=0;
  afterbrace=1;
}


 {
  print;
if (afterbrace==1) { 
  print "}";
  afterbrace=0;
   }
  }





2



