4 include 'blfs-include.php';
7 $CHAPTERS = 'Chapters 6-8';
8 $START_PACKAGE = 'bluefish';
9 $STOP_PACKAGE = 'qemu';
14 $ignores[ 'zsh1' ] = '';
16 //$current="emacs"; // For debugging
19 //$regex[ 'joe' ] = "/^.*Download joe-(\d[\d\.]+).tar.*$/";
23 array( 'pkg' => 'joe',
25 'replace' => "http://sourceforge.net/projects/joe-editor/files" ),
27 array( 'pkg' => 'emacs',
29 'replace' => "https://ftp.gnu.org/gnu/emacs" ),
31 array( 'pkg' => 'gedit',
33 'replace' => "https://download.gnome.org/sources/gedit/" ),
35 array( 'pkg' => 'vim',
37 'replace' => "http://github.com/vim/vim/releases" ),
39 array( 'pkg' => 'nano',
41 'replace' => "https://www.nano-editor.org/dist/" ),
43 array( 'pkg' => 'dash',
45 'replace' => "https://git.kernel.org/pub/scm/utils/dash/dash.git/refs" ),
48 function get_packages( $package, $dirpath )
56 if ( isset( $current ) && $book_index != "$current" ) return 0;
58 // Fix up directory path
59 foreach ( $url_fix as $u )
61 $replace = $u[ 'replace' ];
62 $match = $u[ 'match' ];
64 if ( isset( $u[ 'pkg' ] ) )
66 if ( $package == $u[ 'pkg' ] )
68 $dirpath = preg_replace( "/$match/", "$replace", $dirpath );
74 if ( preg_match( "/$match/", $dirpath ) )
76 $dirpath = preg_replace( "/$match/", "$replace", $dirpath );
82 if ( preg_match( "/^ftp/", $dirpath ) ) $dirpath .= "/";
83 $lines = http_get_file( "$dirpath" );
85 if ( ! is_array( $lines ) ) return $lines;
87 if ( isset( $regex[ $package ] ) )
89 // Custom search for latest package name
90 foreach ( $lines as $l )
92 $ver = preg_replace( $regex[ $package ], "$1", $l );
93 if ( $ver == $l ) continue;
95 if ( $package == 'krb' ) $ver = "5-$ver";
96 return $ver; // Return first match of regex
99 return 0; // This is an error
103 if ( $book_index == "gedit" )
105 // Get max even directory
109 foreach ( $lines as $line )
111 if ( ! preg_match( " /\d\.\d+\//", $line ) ) continue;
113 $d = preg_replace( "/^.*(\d\.\d+)\/.*$/", "$1", $line );
114 list( $ma, $mi, $other ) = explode( ".", $d . ".0.0", 3 );
116 if ( $mi %
2 == 1 ) continue; // Skip odd minors
122 else if ( $ma == $major )
124 if ( $mi > $minor ) $minor = $mi;
128 $lines = http_get_file( "$dirpath/$major.$minor/" );
129 return find_max( $lines, '/gedit/', '/^.*gedit-([\d\.]+).tar.*$/' );
134 if ( $book_index == "joe" )
136 return find_max( $lines, '/joe/', '/^.*joe-([\d\.]+).tar.*$/' );
137 //$lines = http_get_file( "$dirpath/$dir" );
141 if ( $book_index == "vim" )
142 return find_max( $lines, '/v\d/', '/^.*v([\d\.]+).*$/' );
144 if ( $book_index == "nano" )
146 $dir = find_max( $lines, "/v/", "/^.*(v[\d\.]+)\/.*$/" );
147 $lines = http_get_file( "$dirpath/$dir" );
151 if ( $book_index == "zsh1" )
152 return find_max( $lines, '/doc/', '/^.*zsh-([\d\.]+)-doc.tar.*$/' );
155 //if ( $book_index == "emacs" )
156 // return find_max( $lines, '/latest/', '/^.*Emacs ([\d\.]+) .*$/' );
158 if ( $book_index == "dash" )
159 return find_max( $lines, '/^v\d/', '/^v([\d\.]+).*$/' );
161 // Most packages are in the form $package-n.n.n
162 // Occasionally there are dashes (e.g. 201-1)
163 $max = find_max( $lines, "/$package/", "/^.*$package-([\d\.]*\d)\.tar.*$/" );
167 Function get_pattern( $line )
169 // Set up specific patter matches for extracting book versions
172 //$match[ 0 ] = array( 'pkg' => 'ntfs',
173 // 'regex' => "/ntfs-3g_ntfsprogs-(\d.*\d)\D*$/" );
175 foreach( $match as $m )
178 if ( preg_match( "/$pkg/", $line ) )
179 return $m[ 'regex' ];
182 return "/\D*(\d.*\d)\D*$/";
185 get_current(); // Get what is in the book
187 // Get latest version for each package
188 foreach ( $book as $pkg => $data )
192 $base = $data[ 'basename' ];
193 $url = $data[ 'url' ];
194 $bver = $data[ 'version' ];
196 echo "book index: $book_index $bver $url\n";
198 $v = get_packages( $base, $url );
200 $vers[ $book_index ] = $v;
203 html(); // Write html output