2
// ProjectPackage.cs: A pkg-config package
5
// Marcos David Marin Amador <MarcosMarin@gmail.com>
7
// Copyright (C) 2007 Marcos David Marin Amador
10
// This source code is licenced under The MIT License:
12
// Permission is hereby granted, free of charge, to any person obtaining
13
// a copy of this software and associated documentation files (the
14
// "Software"), to deal in the Software without restriction, including
15
// without limitation the rights to use, copy, modify, merge, publish,
16
// distribute, sublicense, and/or sell copies of the Software, and to
17
// permit persons to whom the Software is furnished to do so, subject to
18
// the following conditions:
20
// The above copyright notice and this permission notice shall be
21
// included in all copies or substantial portions of the Software.
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
using System.Collections.Generic;
39
using MonoDevelop.Core;
40
using MonoDevelop.Core.Serialization;
46
[ItemProperty ("file")]
49
[ItemProperty ("name")]
52
[ItemProperty ("IsProject")]
53
private bool is_project;
55
private string description;
56
private string version;
57
private List<string> requires = new List<string>();
58
private List<string> libPaths = new List<string>();
59
private List<string> libs = new List<string>();
60
private List<string> cflags = new List<string>();
61
private Dictionary<string, string> vars = new Dictionary<string,string> ();
63
public Package (string file)
66
this.is_project = false;
68
ParsePackageEssentials ();
71
public Package (CProject project)
74
file = Path.Combine (project.BaseDirectory, name + ".md.pc");
77
ParsePackageEssentials ();
84
void ParsePackageEssentials ()
88
using (StreamReader reader = new StreamReader (file)) {
89
while ((line = reader.ReadLine ()) != null) {
90
if (line.StartsWith ("Name")) {
91
name = line.Split (':')[1].TrimStart ();
95
if (line.StartsWith ("Version")) {
96
version = line.Split (':')[1].TrimStart ();
103
public void ParsePackage ()
110
using (StreamReader reader = new StreamReader (file)) {
111
while ((line = reader.ReadLine ()) != null) {
112
if (line.StartsWith ("#"))
115
if (line.IndexOf ('=') >= 0)
118
if (line.IndexOf (':') >= 0)
119
ParseProperty (line);
126
void ParseVar (string line)
128
int i = line.IndexOf ('=');
129
string key = line.Substring (0, i);
130
string value = line.Substring (i+1, line.Length - i-1).Trim ();
131
string parsedValue = StringParserService.Parse (value, CustomTags ());
133
vars.Add (key, parsedValue);
136
void ParseProperty (string line)
138
int i = line.IndexOf (':');
139
string key = line.Substring (0, i);
140
string value = StringParserService.Parse (line.Substring (i+1, line.Length - i-1).Trim (), CustomTags ());
142
if (value.Length <= 0)
150
description = ProcessDescription (value);
156
ParseRequires (value);
167
void ParseRequires (string reqsline)
169
string[] splitted = reqsline.Split (' ');
171
foreach (string str in splitted) {
172
if (str.Trim () == string.Empty)
178
void ParseLibs (string libline)
184
i = libline.IndexOf ('-', i);
191
while (libline.Length > (count+i+2) && libline[count+i+2] != ' ')
194
lib = libline.Substring (i+2, count);
196
if (libline[i+1] == 'L') {
198
} else if (libline[i+1] == 'l') {
206
void ParseCFlags (string cflagsline)
208
string[] splitted = cflagsline.Split (' ');
210
foreach (string str in splitted) {
211
if (str.Trim () == string.Empty)
218
/// Insert '\n's to make sure string isn't too long.
220
/// <param name="desc">
221
/// The unprocessed description.
222
/// A <see cref="System.String"/>
225
/// The processed description.
226
/// A <see cref="System.String"/>
228
string ProcessDescription (string desc)
232
if (desc.Length <= length)
235
StringBuilder builder = new StringBuilder (desc);
239
while (i < desc.Length) {
242
if (i > lines * length) {
247
} while (desc [i] != ' ');
249
builder.Replace (' ', '\n', i, 1);
253
return builder.ToString ();
256
string[,] CustomTags ()
258
string[,] customTags = new string[vars.Count, 2];
261
foreach (KeyValuePair<string, string> kvp in vars) {
262
customTags[i, 0] = kvp.Key;
263
customTags[i, 1] = kvp.Value;
272
set { file = value; }
277
set { name = value; }
280
public bool IsProject {
281
get { return is_project; }
282
set { is_project = value; }
285
public string Version {
286
get { return version; }
287
set { version = value; }
290
public string Description {
291
get { return description; }
294
public List<string> Requires {
295
get { return requires; }
298
public List<string> LibPaths {
299
get { return libPaths; }
302
public List<string> Libs {
306
public List<string> CFlags {
307
get { return cflags; }
310
public override bool Equals (object o)
312
Package other = o as Package;
314
if (other == null) return false;
316
return other.File.Equals (file);
319
public override int GetHashCode ()
321
return (name + version).GetHashCode ();