1#!/usr/bin/awk -f
2# $Id$
3# My Arealist: make arealist.NA from fidoconfig and echolist
4
5# English:
6# Parameters: file()s) with ''echoarea'' (or 'filearea'') lines from fidoconfig
7# and echolist files in the comma-separated format (echo50.lst), in any order
8#
9# Russian (UTF-8 encoded):
10# Параметры: файлы со строками echoarea или filearea от фидоконфига и файлы
11# эхолистов в формате "значения разделённые запятыми" (как echo50.lst), порядок
12# следования файлов - любой
13#
14
15BEGIN {
16 if( ARGC < 2 ) {
17   print "USAGE: myarealist fidoconfig/echoareas fileecho/xofcelist/echo50.lst [...]"
18   exit 1
19 }
20}
21
22func add_areadesc(areaname,desc) {
23  areadesc[toupper(areaname)]=desc
24}
25
26func add_area(aname,   upperareaname) { # upperareaname - local variable
27  upperareaname = toupper(aname)
28  if( !(upperareaname in area) ) {
29    area[length(area)+1]=upperareaname
30  }
31}
32
33
34func parse_echolist_line() {
35  if( /^[[:alnum:]]*,/ ) {
36    FS = "," ; $0 = $0
37    add_areadesc($2,$3)
38  }
39}
40
41func parse_fidoconf_line() {
42  if(/^[[:space:]]*([eE][cC][hH][oO]|[fF][iI][lL][eE])[Aa][rR][eE][aA][[:space:]]/) {
43    FS = " " ; $0 = $0
44    add_area($2)
45  }
46}
47
48/^[[:alnum:]]*,/ {
49  parse_echolist_line()
50}
51
52/^[[:space:]]*([eE][cC][hH][oO]|[fF][iI][lL][eE])[Aa][rR][eE][aA][[:space:]]/ {
53  parse_fidoconf_line()
54}
55
56END {
57  maxi=asort(area)
58  for( i=1; i<=maxi;i++ ) {
59    printf "%16-s %s\n", area[i], areadesc[area[i]]
60  }
61}
62
63