SPECS: pldnotify.awk Avoid loops.

arekm arekm at pld-linux.org
Mon Dec 1 09:29:40 CET 2008


Author: arekm                        Date: Mon Dec  1 08:29:40 2008 GMT
Module: SPECS                         Tag: HEAD
---- Log message:
Avoid loops.

---- Files affected:
SPECS:
   pldnotify.awk (1.66 -> 1.67) 

---- Diffs:

================================================================
Index: SPECS/pldnotify.awk
diff -u SPECS/pldnotify.awk:1.66 SPECS/pldnotify.awk:1.67
--- SPECS/pldnotify.awk:1.66	Sun Nov 30 17:57:36 2008
+++ SPECS/pldnotify.awk	Mon Dec  1 09:29:34 2008
@@ -151,6 +151,17 @@
 	return 0
 }
 
+function link_seen(link) {
+	for (seenlink in frameseen) {
+		if (seenlink == link) {
+			if (DEBUG) print "Link: [" link "] seen already, skipping..."
+			return 1
+		}
+	}
+	frameseen[link]=1
+	return 0
+}
+
 function get_links(url,filename,errno,link,oneline,retval,odp,wholeodp,lowerodp,tmpfile) {
 # get all <A HREF=..> tags from specified URL
 	"mktemp /tmp/XXXXXX" | getline tmpfile
@@ -210,6 +221,12 @@
 					newurl=(urldir newurl)
 					if (DEBUG) print "Frame->: " newurl
 				}
+
+				if (link_seen(newurl)) {
+					newurl=""
+					continue
+				}
+
 				retval=(retval " " get_links(newurl))
 			} else if (lowerodp ~ /href=[ \t]*"[^"]*"/) {
 				sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
@@ -217,6 +234,12 @@
 				link=substr(odp,RSTART,RLENGTH)
 				odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
 				link=substr(link,7,length(link)-7)
+
+				if (link_seen(link)) {
+					link=""
+					continue
+				}
+
 				retval=(retval " " link)
 				if (DEBUG) print "href(\"\"): " link
 			} else if (lowerodp ~ /href=[ \t]*'[^']*'/) {
@@ -225,6 +248,12 @@
 				link=substr(odp,RSTART,RLENGTH)
 				odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
 				link=substr(link,7,length(link)-7)
+
+				if (link_seen(link)) {
+					link=""
+					continue
+				}
+
 				retval=(retval " " link)
 				if (DEBUG) print "href(''): " link
 			} else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) {
@@ -233,6 +262,12 @@
 				link=substr(odp,RSTART,RLENGTH)
 				odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
 				link=substr(link,6,length(link)-5)
+
+				if (link_seen(link)) {
+					link=""
+					continue
+				}
+
 				retval=(retval " " link)
 				if (DEBUG) print "href(): " link
 			} else {
@@ -424,6 +459,7 @@
 		for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i]
 		ARGC=ARGC-1
 	}
+	frameseen[0] = 1
 }
 
 FNR==1 {
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SPECS/pldnotify.awk?r1=1.66&r2=1.67&f=u



More information about the pld-cvs-commit mailing list