SHARE
TWEET

AWK_gen_prg (2)

s243a Dec 14th, 2019 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/gawk -f
  2. function fixdepends(s,   p,a,sout,n) {
  3.     split(s,a,",")
  4.     for (p in a) {
  5.       sout = sout ",+" a[p]
  6.     }
  7.     sub(/^,/,"",sout) ; return sout;
  8. }
  9. function parse_pkg_name(s,        txz_split,arch_build){
  10.     match(s,/^([^\-]*)(\-.*)(\.([^\-]+))$/,txz_split)
  11.  
  12.     PKG=txz_split[1]
  13.     split(txz_split[2],ver_arch_build,"-") 
  14.     PKGVER=ver_arch_build[2]
  15.  
  16.     len=length(ver_arch_build)
  17.     if (len == 4){
  18.         BUILD_NO=ver_arch_build[4]
  19.         ARCH=ver_arch_build[3]
  20.     }
  21.     else if(len == 3){
  22.       if (ver_arch_build[len-1] ~ /^[0-9]+$/){
  23.         BUILD_NO=ver_arch_build[2]
  24.        }
  25.        else{
  26.            ARCH=ver_arch_build[3]
  27.       }
  28.     }  
  29.    
  30. }
  31. function maybe_parse_dec(s,        line_split){
  32.   if( PARSE_DEC_FLAG == 1){
  33.     match($0,/(\S+):\s+(.*)$/,line_split)
  34.     if(length(line_split) > 0){
  35.       if (line_split[1] == PKG){
  36.         PKGINFO=substr(line_split[2],1,200)
  37.         PARSE_DEC_FLAG=0
  38.       }
  39.     }
  40.   }
  41. }
  42. function cat_fallback(s){
  43.   if (length(s)>0){
  44.     switch(s){
  45.         case /vcs.*/:
  46.           return "Utility;development"
  47.           break
  48.         case /doc.*/:
  49.           return "Help"
  50.           break
  51.         case /admin.*/:
  52.           return "Setup"
  53.           break
  54.         case /games.*/:
  55.           return "Fun"
  56.           break
  57.         case /.{7,}/:
  58.           return "science"
  59.           break
  60.        default:
  61.           return "BuildingBlock"
  62.           break
  63.  
  64.     }
  65.   }
  66.   else
  67.   {
  68.       return "BuildingBlock"
  69.   }
  70. }
  71. function get_category(s1,v1,c1,     out,s2,sc1,sc2){
  72.   if ( s1 in pkg_categories){
  73.     return pkg_categories[s1]
  74.   }
  75.   sc1=get_canonical_name(s1,v1)
  76.   if (sc1 in pkg_categories_canonical){
  77.       return pkg_categories_canonical[sc1]
  78.   }
  79.   s2=gensub(/^(.+[^0-9])([0-9]*)$/,"\\1","g",s1)
  80.   if ( s2 in pkg_categories){
  81.     return pkg_categories[s2]
  82.   }
  83.   sc2=get_canonical_name(s2,v1)
  84.   if (sc2 in pkg_categories_canonical){
  85.       return pkg_categories_canonica[sc2]
  86.   }  
  87.   #TODO: consider also trying to look up category based on the full name.
  88.   return cat_fallback(c1)
  89. }
  90. function parse_cats(s){
  91.   i=index(s,"=")
  92.   if (i>0){
  93.     #catagory=( package1 package2 ... packageN)  
  94.     category=substr(s,0,i-1)
  95.     sub(/PKGCAT_/,"",category) #e.g. category=PKGCAT_Utility => category=Utility
  96.     sub(/_/,";",category) #e.g. category=Filesystem_filemanager => category=Filesystem;filemanager
  97.    
  98.     #e.g catagory=( package1 package2 ... packageN) => package1 package2 ... packageN
  99.     s=gensub(/^([^=]+="\s*)([^\s].*[^\s])(\s*"\s*)$/,"\\2","g",s)
  100.    
  101.     split(s,pkg_names," ")
  102.     for (pkg_i in pkg_names){
  103.       pkg=pkg_names[pkg_i]
  104.       pkg_categories[pkg]=category
  105.       pkg_categories_canonical[pkg]=get_canonical_name(category)
  106.     }  
  107.   }
  108. }
  109. function get_canonical_name(s,v){                  
  110.   if (s in CANONICAL_ARY){                      
  111.    return CANONICAL_ARY[s]                      
  112.   } else {                                      
  113.     switch(s "-" v){                                  
  114.       case /gtk\+2.*/:                              
  115.         return "gtk+"                      
  116.       case /libdbus-glib.*/:                              
  117.         return "dbus"                      
  118.       case /libdbus.*/:                              
  119.         return "dbus"                      
  120.       case /dbus.*/:                              
  121.         return "dbus"                      
  122.       case /mesa-common.*/:                              
  123.         return "mesa"                      
  124.       case /libgl1-mesa.*/:                              
  125.         return "mesa"                      
  126.       case /mesa_.*/:                              
  127.         return "mesa"                      
  128.       case /samba_.*/:                              
  129.         return "samba"                      
  130.       case /libgudev.*/:                              
  131.         return "udev"                      
  132.       case /libudev.*/:                              
  133.         return "udev"                      
  134.       case /udev_.*/:                              
  135.         return "udev"                      
  136.       case /perlapi.*/:                              
  137.         return "perl_tiny"                      
  138.     }                                            
  139.   }                                              
  140.   return s                                      
  141. }                                                
  142. function init_CANONICAL_ARY(){                            
  143.   CANONICAL_ARY["perl_tiny"]="perl_tiny"
  144.   CANONICAL_ARY["perl-base"]="perl_tiny"
  145.   CANONICAL_ARY["samba-tng"]="samba"
  146.   CANONICAL_ARY["sane-backends"]="sane"
  147.   CANONICAL_ARY["gtkdialog3"]="gtkdialog"
  148.   CANONICAL_ARY["xdg_puppy"]="xdg_puppy"
  149.   CANONICAL_ARY["mountcifs"]="samba"
  150.   CANONICAL_ARY["mesa"]="mesa"
  151.   CANONICAL_ARY["urxvt-unicode"]="rxvt-unicode"
  152.   CANONICAL_ARY["gtkdialog"]="gtkdialog"
  153.   CANONICAL_ARY["perl-modules"]="perl_tiny"
  154.   CANONICAL_ARY["urxvt"]="rxvt-unicode"
  155.   CANONICAL_ARY["rxvt-unicode"]="rxvt-unicode"
  156.   CANONICAL_ARY["xdg-utils"]="xdg_puppy"
  157.   CANONICAL_ARY["gtk+"]="gtk+"
  158.   CANONICAL_ARY["samba"]="samba"
  159.   CANONICAL_ARY["sane"]="sane"
  160.   CANONICAL_ARY["udev"]="udev"
  161. }
  162. BEGIN { init_CANONICAL_ARY() #MAPS a PKG NAME to a canonical name
  163.       }
  164. #FILENAME = ALIASFILE { }
  165. FILENAME==CATFILE {parse_cats($0)
  166.                     next} #https://www3.physnet.uni-hamburg.de/physnet/Tru64-Unix/HTML/APS32DTE/WKXXXXXX.HTM
  167. /^PACKAGE NAME:/     { sub(/^PACKAGE NAME:\s*/,""); PKGFILE=$0; parse_pkg_name($0); getline; }
  168. /^PACKAGE LOCATION:/     { sub(/^PACKAGE LOCATION:\s*/,""); sub(/^(.\/)?/,""); PKGPATH=$0; next; }
  169. /^PACKAGE SIZE \(uncompressed\):/ { sub(/^PACKAGE SIZE \(uncompressed\):\s*/,""); sub(/\s/,""); PKGSIZE=$0; next; }
  170. /^PACKAGE DESCRIPTION:/ { PARSE_DEC_FLAG=1; getline;  next; }
  171. /^PACKAGE REQUIRED:/ { sub(/^PACKAGE REQUIRED:\s*/,"");     PKGDEP=fixdepends($0);  next; }
  172. {maybe_parse_dec($0)}                      
  173. /^$/            {
  174.   if (length(PKG)>1){
  175.       PKGSECTION=get_category(PKG,PKGVER,PKGSECTION)
  176.     print PKG "_" PKGVER "|" PKG "|" PKGVER "|"  BUILD_NO "|" PKGSECTION "|" PKGSIZE "|" PKGPATH "|" PKGFILE  "|" PKGDEP "|" PKGINFO "|" PKGOS "|" PKGOSVER  "|"
  177.   };
  178.    
  179.                   PKG=""; PKGVER=""; PKGSECTION=""; PKGSIZE=""; PKGFILE=""; PKGPATH=""; PKGDEP=""; PKGINFO=""; PKGPRIO="";   BUILD_NO="";  ARCH=""; PARSE_DEC_FLAG=0; }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top