home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / man / awk < prev    next >
Encoding:
Text File  |  1991-11-15  |  5.8 KB  |  264 lines

  1. #
  2.  
  3. function underline(s)
  4. {
  5.  gsub(/./,"_&",s); 
  6.  return s;
  7. }
  8.  
  9.  
  10. function header(s)
  11. {
  12.   print "\n";
  13.   print underline(sprintf("%d. %s", ++count,s)) "\n";
  14. }
  15.  
  16.  
  17. BEGIN { operation =  ARGV[2]; 
  18.         type = ARGV[1];
  19.         gsub(/\/.*\//, "",type);
  20.         gsub(/\.tex/, "",type);
  21.         ARGV[2] = ""; 
  22.         gsub(/_/, "\\_", operation); print " "; 
  23.         op_header = 0;
  24.        }
  25.  
  26.  
  27. /\{\\magonebf/ { 
  28. if (operation == "" || "definition" == operation)
  29. { gsub(/\{\\magonebf /, "");
  30.   gsub(/\}/, "");
  31.   gsub(/\\/, "");
  32.   print underline($0);
  33.   print " ";
  34.    if (operation == "") header("DEFINITION");
  35.     getline;
  36.     while ($1 == "") getline;
  37.     while ($1 !~ "skip" && $1 != "")
  38.       { gsub(/\\{/,"kl_auf");
  39.         gsub(/\\}/,"kl_zu");
  40.         gsub(/{/,"");
  41.         gsub(/}/,"");
  42.         gsub("kl_auf", "{");
  43.         gsub("kl_zu", "}");
  44.         gsub(/\$/,"");
  45.         gsub(/\\longrightarrow/, "---->");
  46.         gsub(/\\times/, " x");
  47.         gsub(/\\dots/, "...");
  48.         gsub(/\\cdot/, " *");
  49.         gsub(/\\le/,   " <=");
  50.         gsub(/\\ge/,   " >=");
  51.         gsub(/\\neq/,  " !=");
  52.         gsub(/\\ne/,   " !=");
  53.         gsub(/\\/, "");
  54.         gsub(/backslash/, "\\");
  55.         print;
  56.         getline; 
  57.        }
  58.     print " ";
  59.   }
  60. }
  61.  
  62. /\\decl/ { 
  63. if (operation == "" || "declaration" == operation) 
  64.   if (operation == "") header("DECLARATION");
  65.  
  66.   gsub(/\\/, "");
  67.   if ($1 == "decl")
  68.     { printf("declare(%s,%s)\n\n",$2,$3);
  69.       type = $2"("$3")";
  70.      }
  71.   else
  72.      if ($1 == "decltwo")
  73.      { printf("declare2(%s,%s,%s)\n\n",$2,$3,$4);
  74.        type = $2"("$3","$4")";
  75.       }
  76.      else
  77.         if ($1 == "declthree")
  78.         { printf("declare3(%s,%s,%s,%s)\n\n",$2,$3,$4,$5);
  79.           type = $2"("$3","$4","$5")";
  80.          }
  81.  
  82.   getline;
  83.   while ($1 == "") getline;
  84.   while ($1 !~ "skip" && $1 != "")
  85.     { gsub(/\\{/,"kl_auf");
  86.       gsub(/\\}/,"kl_zu");
  87.       gsub(/{/,"");
  88.       gsub(/}/,"");
  89.       gsub("kl_auf", "{");
  90.       gsub("kl_zu", "}");
  91.       gsub(/\$/,"");
  92.       gsub(/\\name/,type);
  93.       gsub(/\\/,"");
  94.       print;
  95.       getline; 
  96.      }
  97.   print " ";
  98. }
  99. }
  100.  
  101. /\\create/ { 
  102.   out = 0;
  103.   if (operation == "" || "creation" == operation) 
  104.   { out = 1
  105.     if (operation == "") header("CREATION");
  106.    }
  107.  
  108.   while ($0 ~ "\\\\create") 
  109.   { i = 1;
  110.     while ($i != "\\create") i++;
  111.     i++;
  112.     var = $i; 
  113.     gsub(/\\create/, type);
  114.     gsub(/\{\}/, "");
  115.     gsub(/\\/, "");
  116.     if (out==1) printf("%s;\n\n",$0);
  117.     getline;
  118.     while ($1 == "") getline;
  119.   }
  120.  
  121.  
  122.   if (out==1) 
  123.   { while ($1 !~ "skip" && $1 != "")
  124.     { gsub(/{/,"");
  125.       gsub(/}/,"");
  126.       gsub(/\$/,"");
  127.       gsub(/\\name/,type);
  128.       gsub(/\\var/,var);
  129.       gsub(/\\precond/, "Precondition:");
  130.       gsub(/\\/,"");
  131.       print;
  132.       getline; 
  133.      }
  134.    print " ";
  135.   }
  136. }
  137.  
  138.  
  139. #operations & operators: line starts with \+\op
  140.  
  141. /\\\+\\op/ {
  142. if ($3 == operation || operation == "" || "operations" == operation)
  143.   if (op_header==0) { if (operation == "") header("OPERATIONS"); 
  144.                       op_header=1; 
  145.                      }
  146.   gsub(/\\/,"");
  147.   gsub(/}/,"");
  148.   gsub(/{/,"");
  149.   gsub(/\$/,"");
  150.   gsub(/tilde/,"\~");
  151.  
  152.   if ($1 == "+op") #operation
  153.    { printf("%-9s %s.%s (",$2,var,$3);
  154.      for (i=4;i<=NF;i++) printf("%s ",$i);
  155.      if ($1 == "+op") printf(")");
  156.     }
  157.   else
  158.      if ($1 == "+opb") #binary operator
  159.       { printf("%-9s %s ",$2,var);
  160.         for (i=3;i<=NF;i++) printf("%s ",$i);
  161.        }
  162.      else  
  163.         if ($1 == "+ops") #stream operator
  164.          { printf("%-9s %s %s %s",$2,$4,$3,var);
  165.            for (i=5;i<=NF;i++) printf("%s ",$i);
  166.           }
  167.         else
  168.            if ($1 == "+opf") #function call operator
  169.            { printf("%-9s %s (",$2,var);
  170.              for (i=3;i<NF;i++) printf("%s ",$i);
  171.              printf("%s)",$i);
  172.             }
  173.            else
  174.              if ($1 == "+opu") #unary operator
  175.                printf("%-9s %s%s",$2,$3,var);
  176.              else
  177.              if ($1 == "+opa") #array access operator
  178.                printf("%-9s %s [%s %s]",$2,var,$3,$4);
  179.  
  180.   print " ";
  181.   getline;
  182.   if ("operations" != operation)
  183.   { print " ";
  184.     while ($1 !~ "skip" && $1 != "")
  185.     { start = 1;
  186.       if ($1 == "\\+\\nop") start = 2;
  187.       printf("                      ");
  188.       gsub(/\\precond/,"Precondition:");
  189.       gsub(/\\{/,"kl_auf");
  190.       gsub(/\\}/,"kl_zu");
  191.       gsub(/{/,"");
  192.       gsub(/}/,"");
  193.       gsub("kl_auf", "{");
  194.       gsub("kl_zu", "}");
  195.       gsub(/\$/,"");
  196.       gsub(/\\var/, var);
  197.       gsub(/\\longrightarrow/, "---->");
  198.       gsub(/\\times/, " x");
  199.       gsub(/\\phantom/, "");
  200.       gsub(/\\dots/, "...");
  201.       gsub(/\\cdot/, " *");
  202.       gsub(/\\le/,   " <=");
  203.       gsub(/\\ge/,   " >=");
  204.       gsub(/\\neq/,  " !=");
  205.       gsub(/\\ne/,   " !=");
  206.       gsub(/\\/, "");
  207.       gsub(/backslash/, "\\");
  208.       for (i=start;i<=NF;i++) printf("%s ",$i);
  209.       print " ";
  210.       getline; 
  211.      }
  212.    print " ";
  213.   }
  214. }
  215. }
  216.  
  217. /Iteration/ { 
  218. if (operation == "" || "iteration" == operation) 
  219. { if (operation == "") header("ITERATION");
  220.   getline;
  221.   while ($1  ~ "skip" || $1 == "") getline;
  222.   while ($1 !~ "skip")
  223.     { gsub(/\\{/,"kl_auf");
  224.       gsub(/\\}/,"kl_zu");
  225.       gsub(/{/,"");
  226.       gsub(/}/,"");
  227.       gsub("kl_auf", "{");
  228.       gsub("kl_zu", "}");
  229.       gsub(/\$/,"");
  230.       gsub(/\\dots/, "...");
  231.       gsub(/\\bf /, "");
  232.       gsub(/\\nl/, "");
  233.       gsub(/\\/, "");
  234.       print;
  235.       getline; 
  236.       while ($1 ~ "phantom" || $1 == "") getline;
  237.      }
  238.   print " ";
  239. }
  240. }
  241.  
  242. /Implementation/ { 
  243. if (operation == "" || "implementation" == operation) 
  244. { if (operation == "") header("IMPLEMENTATION");
  245.   getline;
  246.   while ($1  ~ "skip" || $1 == "") getline;
  247.   while ($1 !~ "skip" && $1 != "")
  248.     { gsub(/{/,"");
  249.       gsub(/}/,"");
  250.       gsub(/\$/,"");
  251.       gsub(/\\times/, " x");
  252.       gsub(/\\dots/, "...");
  253.       gsub(/\\cdot/, " *");
  254.       gsub(/\\le/,   " <=");
  255.       gsub(/\\/,"");
  256.       print;
  257.       getline; 
  258.      }
  259.   print " ";
  260. }
  261. }
  262.