home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / src.lha / src / amitcp / kern / config_var.awk < prev    next >
Encoding:
AWK Script  |  1996-09-08  |  6.2 KB  |  263 lines

  1. # -*- C -*- --- well, not actually...
  2. # $Id: config_var.awk,v 1.7 1993/11/06 23:51:22 ppessi Exp puhuri $
  3. #
  4. # Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  5. #                  Helsinki University of Technology, Finland.
  6. #                  All rights reserved.
  7. #
  8. # Created      : Wed Apr 28 21:09:22 1993 puhuri
  9. # Last modified: Thu Nov  4 07:33:09 1993 ppessi
  10. #
  11. # $Log: config_var.awk,v $
  12. # Revision 1.7  1993/11/06  23:51:22  ppessi
  13. # Added `global' definitions, allowing to export second level strings.
  14. #
  15. # Revision 1.6  1993/06/04  11:16:15  jraja
  16. # Fixes for first public release.
  17. #
  18. # Revision 1.5  1993/05/04  13:44:00  ppessi
  19. # Fixed Aliasing, removed level 0 \begin{description} \end{description}
  20. #
  21. # Revision 1.4  93/05/03  13:46:42  13:46:42  puhuri (Markus Peuhkuri)
  22. # Modified to use \Alias(es) command.
  23. # Revision 1.3  93/04/29  22:05:16  22:05:16  puhuri (Markus Peuhkuri)
  24. # Now gawk supouse substitute FILENAME
  25. # Revision 1.2  93/04/29  08:55:05  08:55:05  puhuri (Markus Peuhkuri)
  26. # Changed field seperator to ; surrounded by zero or more spaces or tabs.
  27. # Revision 1.1  93/04/28  21:55:56  21:55:56  ppessi (Pekka Pessi)
  28. # Initial revision
  29.  
  30. BEGIN {
  31.   FS="[\t ]*;[\t ]*"; 
  32.   level=1; 
  33.   tab=""; 
  34.   vars=""; 
  35.   var2="";
  36.   GFN = "kern/variables.src (" FILENAME ")";
  37.   TEXTARGET=0;CTARGET=0;TEXITARGET=0
  38.   if (TARGETTI == "TEX") {
  39.     TEXTARGET = 1;
  40.     startcomment = "% -*- LaTeX -*-";
  41.     comment = "%";
  42.     endcomment = "%";
  43.   }else if (TARGETTI == "TEXINFO") {
  44.     level = 0; 
  45.     TEXITARGET = 1;
  46.     startcomment = "@c -*- Texinfo -*-";
  47.     comment = "@c ";
  48.     endcomment = "@c ";
  49.   } else if (TARGETTI == "C") {
  50.     CTARGET = 1;
  51.     startcomment = "/* -*- C -*-";
  52.     comment = " *";
  53.     endcomment = " */";
  54.   } else printf "Unknown target format '%s'\n",TARGETTI > "/dev/stderr"
  55.   print startcomment;
  56.   printf "%s This file is automatically generated from %s\n", comment, GFN;
  57.   print comment;
  58.   printf "%s Do not change this file\n", comment;
  59.   print endcomment;
  60.   if (CTARGET) {
  61.     print "";
  62.     print "\#include <sys/param.h>";
  63.     print "\#include <sys/socket.h>";
  64.     print "\#include <netinet/in.h>";
  65.     print "\#include <kern/amiga_includes.h>";
  66.     print "\#include <kern/amiga_config.h>";
  67.     print "";
  68.   }
  69. }
  70.  
  71. # skip comments and empty lines
  72. /^#/ { next } 
  73. /^ *$/ { next }
  74. # Collect global variables
  75. /^global/ { 
  76.   gsub("^global ", ""); 
  77.   globals = globals "\n" $0;
  78.   next;
  79. }
  80. # Change _ to \_ in TeX
  81. TEXTARGET && /_/ { gsub("_","\\_") }
  82. # Generate indentation, add environment parenthesis
  83. level != $2 && TEXTARGET { 
  84.   if (level < $2) 
  85.     for(i=level; i < $2; i++) {
  86.       tab = sprintf("%"2*i"s", "");
  87.       print tab "\\begin{description}";
  88.     } 
  89.   else 
  90.     for(i=level; i > $2; i--) {
  91.       tab = sprintf("% "2*i "s", "");
  92.       print tab "\\end{description}";
  93.     }
  94.   level = $2;
  95.   tab = sprintf("%" 2*level "s", "");
  96.   print "";
  97. }
  98. TEXTARGET { 
  99.   n = split($1,temp,"=");
  100.   printf "%s\\item[\\code{%s}] %s\n",tab,temp[n],$3;
  101.   if(n>1) {
  102.     printf tab " \\Alias%s{%s",(n>2)?"es":"",temp[1];
  103.       for(i=2;i<n;i++) 
  104.     printf "{\\rm ,} %s",temp[i];
  105.     print "}";
  106.   }
  107.   print "";
  108.   if ($2 == 1) {
  109.     # Skip C declarations
  110.     getline dummy; 
  111.     getline dummy; 
  112.   }
  113. }
  114. #
  115. # TEXINFO
  116. #
  117. $2 == 2 && TEXITARGET { 
  118.   if (level == 1)
  119.       print "@table @code";    
  120.   n = split($1,temp,"=");print "level=" $2, n > "/dev/stderr"
  121.   printf "@item %s\n",temp[n];
  122.   for(i=1;i<n;i++) {
  123.     printf "@itemx %s\n",temp[i];
  124.   }
  125.   gsub("\\\\n","\n",$3) # replace with newlines
  126.   print $3;print "";
  127.   level = $2;
  128.   print "";
  129. }
  130. $2 == 1 && TEXITARGET { 
  131.   if (level == 2)
  132.     print "@end table";
  133.   if (level != 0)
  134.     print "@end deffn\n";
  135.   n = split($1,temp,"="); print "level=" $2, n > "/dev/stderr"
  136.   printf "@deffn {AREXX Variable} %s\n",temp[n];
  137.   for(i=1;i<n;i++) {
  138.     printf "@deffnx {AREXX Variable} %s\n",temp[i];
  139.   }
  140.   gsub("\\\\n","\n",$3) # replace with newlines
  141.   print $3;print "";
  142.   level = $2;
  143.   print "";
  144.  
  145.   if ($2 == 1) {
  146.     # Skip C declarations
  147.     getline dummy; 
  148.     getline dummy; 
  149.   }
  150. }
  151. ($2 != 1 && $2 != 2) && TEXITARGET {
  152.   print FILENAME ":" FNR ": Invalid level: " $2 > "/dev/stderr"
  153. }
  154. #
  155. # Make a C file
  156. #
  157. CTARGET {
  158.   n = split($1, temp, "=");
  159.   if ($2 == 1) {
  160.     if (length(var2) > 0) {
  161.       printf "/* %s */\n#define KW_%s \\\n \"", varcom, curvar;
  162.       n2 = split(var2, t2, ",");
  163.       cnt = 0;
  164.       for (i = 1; i < n2; i++) {
  165.     if ((cnt + length(t2[i])) > 60) {
  166.       printf "\" \\\n \"";
  167.       cnt=0;
  168.     }
  169.     cnt += length(t2[i]);
  170.     printf "%s,",t2[i];
  171.       }
  172.       if (length(t2[n2]) + cnt > 60) 
  173.     printf "\" \\\n \"";
  174.       printf "%s\"\n\n", t2[n2];
  175.     }
  176.     curvar=temp[n];
  177.     varcom=$3;
  178.     if (length(vars) > 0) {
  179.       vars=vars "," $1;
  180.     } else {
  181.       vars=$1;
  182.     }
  183.     var2 = "";
  184.     # Get external vars
  185.     getline extern;
  186.     externs = externs "\n" extern;
  187.     # get variables line
  188.     getline varline;
  189.     if (length(varlines) > 0) {
  190.       varlines = varlines ",\n" varline;
  191.     } else {
  192.       varlines = varline;
  193.     }
  194.   } else {
  195.     if(length(var2) == 0) {
  196.       var2=$1;
  197.     } else {
  198.       var2 = var2 "," $1;
  199.     }
  200.   }
  201. }
  202.     
  203. END {
  204.   if (TEXTARGET) {
  205.     for(i = level; i > 1; i--)
  206.       print "\\end{description}";
  207.   } else if(TEXITARGET) {
  208.     if (level == 2)
  209.        print "@end table";
  210.     if (level != 0)
  211.        print "@end deffn\n";
  212.   } else if(CTARGET) {
  213.     if (length(var2) > 0) {
  214.       printf "/* %s */\n#define KW_%s \\\n \"", varcom, curvar;
  215.       n2 = split(var2, t2, ",");
  216.       cnt = 0;
  217.       for(i=1;i<n2;i++) {
  218.     if((cnt+length(t2[i]))>60) {
  219.       printf "\" \\\n \"";
  220.       cnt=0;
  221.     }
  222.     cnt += length(t2[i]);
  223.     printf "%s,",t2[i];
  224.       }
  225.       if (length(t2[n2])+cnt> 60) printf "\" \\\n \"";
  226.       printf "%s\"\n\n", t2[n2];
  227.     }
  228.  
  229.     if (length(vars) > 0) {
  230.       printf "/* %s */\nSTRPTR KW_%s =\n  \"", "Level 1 variables", "VARS";
  231.       n2 = split(vars, t2, ","); cnt=0;
  232.       for(i=1; i<n2; i++) {
  233.     if(cnt + length(t2[i]) > 60) {
  234.       printf "\"\n  \"";
  235.       cnt=0;
  236.     }
  237.     cnt+=length(t2[i]);
  238.     printf "%s,",t2[i];
  239.       }
  240.       printf "%s\";\n\n", t2[n2];
  241.     }
  242.     if (length(externs)) {
  243.       print "/* extern declarations */";
  244.       print externs;
  245.       print;
  246.     }
  247.     if (length(globals)) {
  248.       printf "/* Global variables */";
  249.       print globals;
  250.       print;
  251.     }
  252.     if (length(varlines)) {
  253.       print "struct cfg_variable variables[] = {";
  254.       print varlines;
  255.       print "};";
  256.     }
  257.   }
  258. }
  259.