Dash:
[t2-trunk.git] / misc / lua / parse-db.lua
blob6346b6ee816cc641c88a4a72f8ff8d5a3627ca54
1 -- --- T2-COPYRIGHT-NOTE-BEGIN ---
2 -- This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 --
4 -- T2 SDE: misc/lua/parse-db.lua
5 -- Copyright (C) 2005 - 2006 The T2 SDE Project
6 --
7 -- More information can be found in the files COPYING and README.
8 --
9 -- This program is free software; you can redistribute it and/or modify
10 -- it under the terms of the GNU General Public License as published by
11 -- the Free Software Foundation; version 2 of the License. A copy of the
12 -- GNU General Public License can be found in the file COPYING.
13 -- --- T2-COPYRIGHT-NOTE-END ---
15 -- parse all packages.db information into tables
16 -- filelist saving commented out (eats another 30M)
18 require "lzlib"
19 require "t2_desc"
21 function block_lines()
22 local line = lines();
23 if (line == nil) or (line=="\023") then
24 return nil;
25 end
26 return line;
27 end
29 function read_deps()
30 local deps={}
31 for line in block_lines do
32 _,_,dependency = string.find(line, "[^ ]* (.*)");
33 table.insert (deps, dependency);
34 end
35 return deps;
36 end
38 function read_flist()
39 local files={};
40 local cksums={};
41 local sizes={};
42 local usage=0;
43 for line in block_lines do
44 _,_,cksum,size,file = string.find(line, "^([0-9]+) ([0-9]+) (.*)");
45 -- uncomment theese lines if you want to save complete file list
46 -- table.insert (files, file);
47 -- table.insert (cksums, 1 * cksum);
48 -- table.insert (sizes, 1 * size);
49 usage = usage + size;
50 end
51 return usage,files,cksums,sizes;
52 end
55 zf,error = lzlib.open("./packages.db", "r");
56 if not zf then -- failed to open file, print error
57 print(error);
58 else
59 lines = zf:lines(); -- obtain line iterator
61 packages = {};
63 repeat -- parse packages
64 pkgname = lines();
65 if pkgname then
66 print(pkgname);
67 local pkg_data = {};
69 if lines() ~= "\023" then -- separator line
70 print ("terminating line missing\n");
71 end
73 pkg_data.desc=t2_desc.parse (block_lines);
74 pkg_data.deps=read_deps ();
75 pkg_data.usage = read_flist ();
76 if lines() ~= "\004" then -- separator line
77 print ("terminating line missing\n");
78 end
80 packages[pkgname] = pkg_data;
81 end
82 until pkgname == nil;
84 _,normal_eof,error = zf:eof ();
85 if not normal_eof then -- check if stream ended because of error
86 print ("-- abnormal end of stream: ", error);
87 end
89 ok,error = zf:close();
90 if not ok then
91 print ("could not close stream: ", error);
92 end
93 x = gcinfo ();
94 print(x, "kb dynamic memory used.");
95 end