1#! /usr/bin/gawk -f 2# __ _ 3# |_) /| Copyright (C) 2001 | richard@ 4# | \/�| Richard Atterer | atterer.net 5# � '` � 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License, version 2. See 8# the file COPYING for details. 9 10# Convert the list of Debian mirrors from Debian CVS into entries for 11# the [Servers] section of a .jigdo file. 12 13function jigdo(str, comment) { 14 if (str in recorded) return; 15 recorded[str]; 16 result = str; 17 #result = substr(str, 7)" "substr(str, 1, 6); 18 if (comment) { 19 result = result substr(" ", 20 length(str)) " # " comment; 21 } 22 print result; 23} 24 25function entry() { 26 for (dummy in x) { # Array empty => ignore 27 comment = x["Country"]; 28 if ("Location" in x) { 29 # Remove repeated country name from Location 30 location = x["Location"]; 31 loc = index(location, substr(comment, 4)); 32 if (loc) { 33 comment = comment " (" substr(location, 1, loc - 1) \ 34 substr(location, loc + length(comment) - 3) ")"; 35 } else { 36 comment = comment " (" location ")"; 37 } 38 sub(/[ ,]+\)$| +\)/, ")", comment); 39 sub(/[ ,]+\( *\)$/, "", comment); 40 sub(/ +/, " ", comment); 41 } 42 if ("Archive-http" in x) 43 jigdo("Debian=http://" x["Site"] x["Archive-http"], comment); 44 else if ("Archive-ftp" in x) 45 jigdo("Debian=ftp://" x["Site"] x["Archive-ftp"], comment); 46 if ("NonUS-http" in x) 47 jigdo("Non-US=http://" x["Site"] x["NonUS-http"], comment); 48 else if ("NonUS-ftp" in x) 49 jigdo("Non-US=ftp://" x["Site"] x["NonUS-ftp"], comment); 50 split("", x); # Clear x[] 51 return; 52 } 53} 54 55/^$/ { 56 entry(); 57} 58 59($1 ~ /^[A-Za-z0-9_-]+:$/) { 60 field = substr($1, 1, length($1) - 1); 61 line = $0; sub(/^[^ ]+ /, "", line); 62 x[field] = line; 63} 64 65# Entry line continued on new line 66/^[ ]+[^ ]/ { 67 line = $0; sub(/^[ ]+/, " ", line); 68 x[field] = x[field] line; 69} 70 71END { 72 entry(); 73} 74