* updated libxspf (1.2.0 -> 1.2.1)
[t2-trunk.git] / source / desc-parser.hh
blob3554156c1d5099e2f864d0817a94afcbd7e7cd5a
1 /*
2 * --- T2-COPYRIGHT-NOTE-BEGIN ---
3 * T2 SDE: source/desc-parser.hh
4 * Copyright (C) 2004 - 2021 The T2 SDE Project
5 *
6 * This Copyright note is generated by scripts/Create-CopyPatch,
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 version 2.
11 * --- T2-COPYRIGHT-NOTE-END ---
14 #include "tag-parser.hh"
15 #include <sstream>
17 // some inteligent Version information class, that contains
18 // some logic to compare version numbers, including -beta and
19 // -alpha suffixes
21 class DownloadInfo
23 public:
24 std::string chksum;
25 std::string file;
26 std::string url;
27 std::string down_url;
28 std::string protocol;
31 class DownloadTag : public Tag
33 public:
34 DownloadTag () : Tag ("D","DOWN","DOWNLOAD") {}
36 bool Parse ()
38 std::string::size_type line_start = 0;
39 std::string::size_type line_end;
40 do {
41 line_end = value.find('\n', line_start);
42 std::string line = value.substr(line_start, line_end-line_start);
43 ParseLine (line);
44 line_start = line_end+1;
45 } while (line_end != std::string::npos && line_end < value.length()-1);
47 return true;
50 virtual void ClearImpl ()
52 download_infos.clear ();
55 std::vector<DownloadInfo> download_infos;
57 private:
58 bool ParseLine (const std::string& line)
59 { // Todo: Error evaluation !
60 DownloadInfo info;
61 std::stringstream sstr(line);
62 sstr >> info.chksum;
63 sstr >> info.file;
64 sstr >> info.url;
66 if (info.url[0] == '!') { // overwriting filename
67 info.url.erase(0,1);
68 info.down_url = info.url;
69 std::string::size_type url_end = info.url.rfind('/');
70 info.url = info.url.substr(0,url_end);
71 } else
72 info.down_url = info.url+info.file;
74 std::string::size_type protocol_end = info.url.find(':');
75 info.protocol = info.url.substr(0, protocol_end);
77 download_infos.push_back(info);
78 return true;
83 // TODO: IMHO better tag bookkeeping ... -ReneR
84 class Package : public TagParser
86 public:
87 Package()
88 : copyright("COPY","",""),
90 title("I","","INFO"),
91 text("T","","TEXT"),
92 url("U","","URL"),
94 author("A","AUTH","AUTHOR"),
95 maintainer("M","","MAINTAINER"),
96 category("C","","CATEGORY"),
97 flags("F","","FLAGS"),
98 arch("R","ARCH","ARCHITECTUR"),
99 kernel("K","KERN","KERNEL"),
100 dependency("E","DEP","DEPENDENCY"),
102 license("L","","LICENCE"),
103 status("S","","STATUS"),
104 version("V","VER","VERSION"),
105 priority("P","","PRIORITY"),
107 download (),
108 cv_url("","","CV-URL"),
109 cv_flags("","","CV-FLAGS"),
111 sourcepackage("SRC","","SRCPACKAGE"),
112 conf("O","","CONF")
114 tags.push_back(&copyright);
115 tags.push_back(&title);
116 tags.push_back(&text);
117 tags.push_back(&url);
119 tags.push_back(&author);
120 tags.push_back(&maintainer);
122 tags.push_back(&category);
123 tags.push_back(&flags);
124 tags.push_back(&arch);
125 tags.push_back(&kernel);
126 tags.push_back(&dependency);
128 tags.push_back(&license);
129 tags.push_back(&status);
130 tags.push_back(&version);
131 tags.push_back(&priority);
133 tags.push_back(&download);
134 tags.push_back(&cv_url);
135 tags.push_back(&cv_flags);
136 tags.push_back(&sourcepackage);
137 tags.push_back(&conf);
140 ~Package()
143 bool ParsePackage(const std::string& file)
145 return Parse(file) && download.Parse();
148 Tag copyright;
150 Tag title;
151 Tag text;
152 Tag url;
154 Tag author;
155 Tag maintainer;
157 Tag category;
158 Tag flags;
159 Tag arch;
160 Tag kernel;
161 Tag dependency;
163 Tag license;
164 Tag status;
165 Tag version;
166 Tag priority;
168 DownloadTag download;
169 Tag cv_url;
170 Tag cv_flags;
172 Tag sourcepackage;
173 Tag conf;