Subversion Repositories SvarDOS

Rev

Rev 909 | Rev 914 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 909 Rev 912
Line 8... Line 8...
8
  files. buildidx will generate the index file and save it into the package
8
  files. buildidx will generate the index file and save it into the package
9
  repository.
9
  repository.
10
 
10
 
11
  requires php-zip
11
  requires php-zip
12
 
12
 
13
  21 feb 2022: buildidx collects categories looking at the dir layout of each package
13
  21 feb 2022: buildidx collects categories looking at the dir layout of each package + improved version string parsing (replaced version_compare call by dos_version_compare)
14
  17 feb 2022: checking for non-8+3 filenames in packages and duplicates + devload no longer part of CORE
14
  17 feb 2022: checking for non-8+3 filenames in packages and duplicates + devload no longer part of CORE
15
  16 feb 2022: added warning about overlong version strings and wild files location
15
  16 feb 2022: added warning about overlong version strings and wild files location
16
  15 feb 2022: index is generated as json, contains all filenames and alt versions
16
  15 feb 2022: index is generated as json, contains all filenames and alt versions
17
  14 feb 2022: packages are expected to have the *.svp extension
17
  14 feb 2022: packages are expected to have the *.svp extension
18
  12 feb 2022: skip source packages from being processed (*.src.zip)
18
  12 feb 2022: skip source packages from being processed (*.src.zip)
Line 60... Line 60...
60
  fclose($fd);
60
  fclose($fd);
61
  return($result);
61
  return($result);
62
}
62
}
63
 
63
 
64
 
64
 
-
 
65
// translates a version string into a array of integer values.
-
 
66
// Accepted formats follow:
-
 
67
//    300.12.1
-
 
68
//    1
-
 
69
//    12.2.34.2-4.5
-
 
70
//    1.2c
-
 
71
//    1.01 beta+3
-
 
72
//    2013-12-31
-
 
73
//    20220222 alpha
-
 
74
function vertoarr($verstr) {
-
 
75
  $subver = array(0,0,0,0);
-
 
76
 
-
 
77
  // switch string to lcase for easier processing and trim any leading or trailing white spaces
-
 
78
  $verstr = strtolower(trim($verstr));
-
 
79
 
-
 
80
  // replace all '-' and '/' characters to '.' (uniformization of sub-version parts delimiters)
-
 
81
  $verstr = strtr($verstr, '-/', '..');
-
 
82
 
-
 
83
  // is there a subversion value? (for example "+4" in "1.05+4")
-
 
84
  $i = strrpos($verstr, '+', 1);
-
 
85
  if ($i !== false) {
-
 
86
    // validate the svar-version is a proper integer
-
 
87
    $svarver = substr($verstr, $i + 1);
-
 
88
    if (! preg_match('/[1-9][0-9]*/', $svarver)) {
-
 
89
      return(false);
-
 
90
    }
-
 
91
    $subver[3] = intval($svarver); // set the +rev as a very minor item
-
 
92
    $verstr = substr($verstr, 0, $i);
-
 
93
  }
-
 
94
 
-
 
95
  // is the version ending with ' alpha', 'beta'?
-
 
96
  if (preg_match('/ (alpha|beta)$/', $verstr)) {
-
 
97
    $i = strrpos($verstr, ' ');
-
 
98
    $greek = substr($verstr, $i + 1);
-
 
99
    $verstr = trim(substr($verstr, 0, $i));
-
 
100
    if ($greek == 'alpha') {
-
 
101
      $subver[2] = 1;
-
 
102
    } else if ($greek == 'beta') {
-
 
103
      $subver[2] = 2;
-
 
104
    } else {
-
 
105
      return(false);
-
 
106
    }
-
 
107
  }
-
 
108
 
-
 
109
  // does the version string have a single-letter subversion? (1.0c)
-
 
110
  if (preg_match('/[a-z]$/', $verstr)) {
-
 
111
    $subver[1] = ord(substr($verstr, -1));
-
 
112
    $verstr = substr_replace($verstr, '', -1); // remove last character from string
-
 
113
  }
-
 
114
 
-
 
115
  // validate the format is supported, should be something no more complex than 1.05.3.33
-
 
116
  if (! preg_match('/[0-9][0-9.]{0,20}/', $verstr)) {
-
 
117
    return(false);
-
 
118
  }
-
 
119
 
-
 
120
  // NOTE: a zero right after a separator and trailed with a digit (as in 1.01)
-
 
121
  //       has a special meaning
-
 
122
  $exploded = explode('.', $verstr);
-
 
123
  if (count($exploded) > 16) {
-
 
124
    return(false);
-
 
125
  }
-
 
126
  $exploded[16] = $subver[0]; // unused yet
-
 
127
  $exploded[17] = $subver[1]; // a-z (1.0c)
-
 
128
  $exploded[18] = $subver[2]; // alpha/beta
-
 
129
  $exploded[19] = $subver[3]; // svar-ver (1.0+5)
-
 
130
  for ($i = 0; $i < 20; $i++) if (empty($exploded[$i])) $exploded[$i] = '0';
-
 
131
 
-
 
132
  ksort($exploded);
-
 
133
 
-
 
134
  return($exploded);
-
 
135
}
-
 
136
 
-
 
137
 
-
 
138
function dos_version_compare($v1, $v2) {
-
 
139
  $v1arr = vertoarr($v1);
-
 
140
  $v2arr = vertoarr($v2);
-
 
141
  for ($i = 0; $i < count($v1arr); $i++) {
-
 
142
    $r = strcmp($v1arr[$i], $v2arr[$i]);
-
 
143
    if ($r != 0) return($r);
-
 
144
  }
-
 
145
  return(0);
-
 
146
}
-
 
147
 
-
 
148
 
65
// reads file fil from zip archive z and returns its content, or false on error
149
// reads file fil from zip archive z and returns its content, or false on error
66
function read_file_from_zip($z, $fil) {
150
function read_file_from_zip($z, $fil) {
67
  $zip = new ZipArchive;
151
  $zip = new ZipArchive;
68
  if ($zip->open($z, ZipArchive::RDONLY) !== true) {
152
  if ($zip->open($z, ZipArchive::RDONLY) !== true) {
69
    echo "ERROR: failed to open zip file '{$z}'\n";
153
    echo "ERROR: failed to open zip file '{$z}'\n";
Line 246... Line 330...
246
    if (str_head_is($f, "drivers/{$pkgdir}/")) continue;
330
    if (str_head_is($f, "drivers/{$pkgdir}/")) continue;
247
    if ($f === 'drivers/') continue;
331
    if ($f === 'drivers/') continue;
248
    echo "WARNING: {$fname} contains a file in an illegal location: {$f}\n";
332
    echo "WARNING: {$fname} contains a file in an illegal location: {$f}\n";
249
  }
333
  }
250
 
334
 
-
 
335
  // do I understand the version string?
-
 
336
  if (vertoarr($lsmarray['version']) === false) echo "WARNING: {$fname} parsing of version string failed ('{$lsmarray['version']}')\n";
-
 
337
 
251
  $meta['fname'] = $fname;
338
  $meta['fname'] = $fname;
252
  $meta['desc'] = $lsmarray['description'];
339
  $meta['desc'] = $lsmarray['description'];
253
  $meta['cats'] = array_unique($catlist);
340
  $meta['cats'] = array_unique($catlist);
254
 
341
 
255
  $pkgdb[$pkgnam][$lsmarray['version']] = $meta;
342
  $pkgdb[$pkgnam][$lsmarray['version']] = $meta;
Line 264... Line 351...
264
 
351
 
265
// iterate over each svp package
352
// iterate over each svp package
266
foreach ($pkgdb as $pkg => $versions) {
353
foreach ($pkgdb as $pkg => $versions) {
267
 
354
 
268
  // sort filenames by version, highest first
355
  // sort filenames by version, highest first
269
  uksort($versions, "version_compare");
356
  uksort($versions, "dos_version_compare");
270
  $versions = array_reverse($versions, true);
357
  $versions = array_reverse($versions, true);
271
 
358
 
272
  foreach ($versions as $ver => $meta) {
359
  foreach ($versions as $ver => $meta) {
273
    $fname = $meta['fname'];
360
    $fname = $meta['fname'];
274
    $desc = $meta['desc'];
361
    $desc = $meta['desc'];