Lman.awk
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:5k
开发平台:

MultiPlatform

  1. function underline(s)
  2. { gsub(/./,"_&",s); 
  3.   return s;
  4. }
  5. function header(s)
  6. { print "n";
  7.   print underline(sprintf("%d. %s", ++count,s)) "n";
  8. }
  9. function sub_tex()
  10. { gsub(/\{/,"kl_auf");
  11.   gsub(/\}/,"kl_zu");
  12.   gsub(/{/,"");
  13.   gsub(/}/,"");
  14.   gsub("kl_auf", "{");
  15.   gsub("kl_zu", "}");
  16.   gsub(/$/,"");
  17.   gsub(/\precond/,"Precondition:");
  18.   gsub(/\longrightarrow/, "---->");
  19.   gsub(/\phantom/, "");
  20.   gsub(/\times/, " x");
  21.   gsub(/\dots/, "...");
  22.   gsub(/\cdot/, " *");
  23.   gsub(/\tilde/,"~");
  24.   gsub(/\le/,   " <=");
  25.   gsub(/\ge/,   " >=");
  26.   gsub(/\neq/,  " !=");
  27.   gsub(/\ne/,   " !=");
  28.   gsub(/\bf /, "");
  29.   gsub(/\nl/, "");
  30.   gsub(/\/, "");
  31.   gsub(/backslash /, "\");
  32. }
  33. BEGIN { arg =  ARGV[2]; 
  34.         type = ARGV[1];
  35.         gsub(//.*//, "",type);
  36.         gsub(/.tex/, "",type);
  37.         ARGV[2] = ""; 
  38.         gsub(/_/, "\_", arg); print " "; 
  39.         op_header = 0;
  40.        }
  41. /\section/ { 
  42. if (arg == "")
  43.  { gsub(/\section *{/, "");
  44.    gsub(/\label *{.*}/, "");
  45.    gsub(/}/, "");
  46.    gsub(/\/, "");
  47.    print underline($0);
  48.    print " ";
  49.   }
  50. }
  51. /\definition/ { 
  52. if (arg == "" || "definition" == arg)
  53.  { if (arg == "") header("DEFINITION");
  54.     getline;
  55.     while ($1 == "") getline;
  56.     if ($1 ~ "\\decl") 
  57.     { if ($1 == "\declare")
  58.         type = $2;
  59.       else
  60.         if ($1 == "\declone")
  61.           type = $2"<"$3">";
  62.         else
  63.           if ($1 == "\decltwo")
  64.              type = $2"<"$3","$4">";
  65.           else
  66.              if ($1 == "\declthree")
  67.                 type = $2"<"$3","$4","$5">";
  68.      getline;
  69.     }
  70.     while ($1 == "") getline;
  71.     while ($1 != "")
  72.       { gsub(/\name/,type);
  73.         sub_tex();
  74.         print;
  75.         getline; 
  76.        }
  77.     print " ";
  78.   }
  79. }
  80. /\creation/ { 
  81.   out = 0;
  82.   if (arg == "" || "creation" == arg) 
  83.   { out = 1
  84.     if (arg == "") header("CREATION");
  85.    }
  86.   getline;
  87.   while ($1 == "") getline;
  88.   while ($0 ~ "\\create") 
  89.   { i = 1;
  90.     while ($i != "\create") i++;
  91.     i++;
  92.     var = $i; 
  93.     gsub(/\create/, type);
  94.     gsub(/ *{ *} */, "");
  95.     gsub(/\/, "");
  96.     if (out==1) printf("%s;nn",$0);
  97.     getline;
  98.     while ($1 == "") getline;
  99.   }
  100.   if (out==1) 
  101.   { while ($1 != "")
  102.     { gsub(/{/,"");
  103.       gsub(/}/,"");
  104.       gsub(/\tt /, "");
  105.       gsub(/$/,"");
  106.       gsub(/\name/,type);
  107.       gsub(/\var/,var);
  108.       gsub(/\precond/, "Precondition:");
  109.       gsub(/\/,"");
  110.       print;
  111.       getline; 
  112.      }
  113.    print " ";
  114.   }
  115. }
  116. #operations & operators: line starts with op,opl,binop,unop,funop, ...
  117. /\operations/ {
  118.   if (arg == "") header("OPERATIONS"); 
  119.   getline; 
  120.  }
  121. /\[a-z]*op/ {
  122.   if ($3 == arg || arg == "" || "operations" == arg)
  123.   { 
  124.     sub_tex();
  125.   
  126.     if ($1 == "op" || $1 == "opl") #operation
  127.      { long = 0;
  128.        if ($1 == "opl") long = 1;
  129.        printf("%-9s %s.%s (",$2,var,$3);
  130.        for (i=4;i<=NF;i++) printf("%s ",$i);
  131.        printf(")");
  132.       }
  133.     else
  134.        if ($1 == "binop") #binary operator
  135.         { printf("%-9s %s ",$2,var);
  136.           for (i=3;i<=NF;i++) printf("%s ",$i);
  137.          }
  138.        else  
  139.           if ($1 == "strop") #stream operator
  140.            { printf("%-9s %s %s %s",$2,$4,$3,var);
  141.              for (i=5;i<=NF;i++) printf("%s ",$i);
  142.             }
  143.           else
  144.              if ($1 == "funop") #function call operator  
  145.              { printf("%-9s %s (",$2,var);
  146.                for (i=3;i<NF;i++) printf("%s ",$i);
  147.                printf("%s)",$i);
  148.               }
  149.              else
  150.                if ($1 == "unop") #unary operator
  151.                  printf("%-9s %s%s",$2,$3,var);
  152.                else
  153.                if ($1 == "arrop") #array access operator
  154.                  printf("%-9s %s [%s %s]",$2,var,$3,$4);
  155.   
  156.     #if (long == 1) print " ";   # space between call sequence and description
  157.   
  158.     getline;
  159.     print " ";
  160.     if ("operations" != arg)
  161.     { while ($1 != "")
  162.       { gsub(/\var/, var);
  163.         sub_tex();
  164.         printf("                       ");
  165.         for (i=1;i<=NF;i++) printf("%s ",$i);
  166.         print " ";
  167.         getline; 
  168.        }
  169.      print " ";
  170.      print " ";
  171.     }
  172.   }
  173. }
  174. #/\iteration/ { 
  175. #if (arg == "" || "iteration" == arg) 
  176. #{ if (operation == "") header("ITERATION");
  177. #  getline;
  178. #  while ($1  ~ "skip" || $1 == "") getline;
  179. #  while ($1 !~ "skip")
  180. #    { sub_tex();
  181. #      print;
  182. #      getline; 
  183. #      while ($1 ~ "phantom" || $1 == "") getline;
  184. #     }
  185. #  print " ";
  186. #}
  187. #}
  188. /\implementation/ { 
  189.   if (arg == "" || "implementation" == arg) 
  190.   { if (arg == "") header("IMPLEMENTATION");
  191.     getline;
  192.     while ($1  ~ "skip" || $1 == "") getline;
  193.     while ($1 !~ "skip" && $1 != "")
  194.       { gsub(/{/,"");
  195.         gsub(/}/,"");
  196.         sub_tex();
  197.         print;
  198.         getline; 
  199.        }
  200.     print " ";
  201.    }
  202. }