]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - pldnotify.awk
- removed all uses of "is_there_line" - adapter can be now used as
[packages/rpm-build-tools.git] / pldnotify.awk
CommitLineData
6fb3305d 1#!/bin/awk -f
d4089f30 2# $Revision$, $Date$
6fb3305d 3
70a5e8d4
SZ
4function compare_ver(v1,v2) {
5# compares version numbers
6 while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
7 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
8 while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
9 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
10 sub("^0*","",v1)
11 sub("^0*","",v2)
12 if (DEBUG) print "v1 == " v1
13 if (DEBUG) print "v2 == " v2
14 count=split(v1,v1a,"\.")
15 count2=split(v2,v2a,"\.")
16
17 if (count<count2) mincount=count
18 else mincount=count2
19
20 for (i=1; i<=mincount; i++) {
db83adc3
SZ
21 if (v1a[i]=="") v1a[i]=0
22 if (v2a[i]=="") v2a[i]=0
70a5e8d4
SZ
23 if (DEBUG) print "i == " i
24 if (DEBUG) print "v1[i] == " v1a[i]
25 if (DEBUG) print "v2[i] == " v2a[i]
26 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
27 if (length(v2a[i])>length(v1a[i]))
28 return 1
29 else if (v2a[i]>v1a[i])
30 return 1
31 else if (length(v1a[i])>length(v2a[i]))
32 return 0
33 else if (v1a[i]>v2a[i])
34 return 0
35 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
36 if (v2a[i]>v1a[i])
37 return 1
38 else if (v1a[i]>v2a[i])
39 return 0
2e301ef5 40 } else if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"alpha"))
70a5e8d4
SZ
41 return 1
42 else
43 return 0
44 }
45 if ((count2==mincount)&&(count!=count2)) {
46 for (i=count2+1; i<=count; i++)
2e301ef5 47 if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"alpha"))
70a5e8d4
SZ
48 return 1
49 return 0
50 } else if (count!=count2) {
51 for (i=count+1; i<=count2; i++)
2e301ef5 52 if ((v2a[i]~"pre")||(v2a[i]~"beta")||(v2a[i]~"alpha"))
70a5e8d4
SZ
53 return 0
54 return 1
55 }
db4f445e 56 return 0
70a5e8d4
SZ
57}
58
2e301ef5 59function get_links(url, errno,link,oneline,retval,odp,tmpfile) {
70a5e8d4 60# get all <A HREF=..> tags from specified URL
db4f445e
SZ
61 "mktemp /tmp/XXXXXX" | getline tmpfile
62 close("mktemp /tmp/XXXXXX")
2e301ef5
SZ
63
64 if (DEBUG) print "Retrieving: " url
65 errno=system("wget -O - \"" url "\" > " tmpfile " 2>/dev/null" )
70a5e8d4 66
3f63995d 67 if (errno==0) {
7f460828
SZ
68 while (getline oneline < tmpfile)
69 odp=(odp " " oneline)
70 if ( DEBUG ) print "Odpowiedz: " odp
70a5e8d4 71 }
3f63995d
SZ
72
73 close(tmpfile)
2e301ef5 74 system("rm -f " tmpfile)
3f63995d 75 if ( errno==0) {
93c3b403
SZ
76 while ((tolower(odp) ~ /<frame[ \t]/)||(tolower(odp) ~ /href=/)) {
77 if (tolower(odp) ~ /<frame[ \t]/) {
78 match(tolower(odp),/<frame[ \t][^>]*>/)
79 ramka=substr(odp,RSTART,RLENGTH)
80 odp=substr(odp,RSTART+RLENGTH)
81 match(tolower(ramka),/src="[^"]+"/)
2e301ef5
SZ
82 newurl=substr(ramka,RSTART+5,RLENGTH-6)
83 if (DEBUG) print "Ramka: " newurl
84 retval=(retval " " get_links(newurl))
93c3b403
SZ
85 } else {
86 match(tolower(odp),/href="[^"]+"/)
87 link=substr(odp,RSTART,RLENGTH)
88 odp=substr(odp,RSTART+RLENGTH)
89 link=substr(link,7,length(link)-7)
90 retval=(retval " " link)
91 }
3f63995d
SZ
92 }
93 } else {
2e301ef5 94 retval=("WGET ERROR: " errno)
3f63995d
SZ
95 }
96
db4f445e 97
3f63995d 98 if (DEBUG) print "Zwracane: " retval
db4f445e 99 return retval
70a5e8d4
SZ
100}
101
6fb3305d 102function subst_defines(var,defs) {
3255b4c7 103# substitute all possible RPM macros
6fb3305d
SZ
104 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
105 oldvar=var
106 for (j in defs) {
107 gsub("%{" j "}", defs[j], var)
108 gsub("%" j , defs[j], var)
109 }
110 if (var==oldvar) {
111 if ( DEBUG ) for (i in defs) print i " == " defs[i]
112 return var
113 }
114 }
115 return var
116}
117
32aede2f 118function process_source(number,lurl,name,version) {
3255b4c7
SZ
119# fetches file list, and compares version numbers
120 if ( DEBUG ) print "Przetwarzam " lurl
3f63995d
SZ
121
122 if ( index(lurl,version)==0 ) {
123 if (DEBUG) print "Nie ma numeru wersji."
124 return 0
125 }
126
6fb3305d
SZ
127 sub("://",":",lurl)
128 sub("/",":/",lurl)
129 gsub("[^/]*$",":&",lurl)
130 split(lurl,url,":")
131 acc=url[1]
132 host=url[2]
133 dir=url[3]
70a5e8d4
SZ
134 filename=url[4]
135
3f63995d 136 if (index(dir,version)) {
70a5e8d4
SZ
137 dir=substr(dir,1,index(dir,version)-1)
138 sub("[^/]*$","",dir)
139 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
140 if ( DEBUG ) print "Sprawdze katalog: " dir
141 if ( DEBUG ) print "i plik: " filename
142 }
3f63995d 143
70a5e8d4
SZ
144 filenameexp=filename
145 gsub("\+","\\+",filenameexp)
146 sub(version,"[A-Za-z0-9\\.]+",filenameexp)
147 if ( DEBUG ) print "Wzorzec: " filenameexp
148 match(filename,version)
149 prever=substr(filename,1,RSTART-1)
150 postver=substr(filename,RSTART+RLENGTH)
151 if ( DEBUG ) print "Przed numerkiem: " prever
152 if ( DEBUG ) print "i po: " postver
153
3f63995d 154