Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 160 lines (149 sloc) 4.952 kb
09a61dc * config.cs: Add Prefix (base directory for output), BlogTemplate
Jonathan Pryor authored
1 using System;
fa15eda * lb.cs: Configuration data are now loaded from config.xml
Martin Willemoes Hansen authored
2 using System.Xml.Serialization;
3
8486397 @atsushieno 2003-12-16 Atsushi Enomoto <atsushi@ximian.com>
atsushieno authored
4 [XmlRoot("config")]
fa15eda * lb.cs: Configuration data are now loaded from config.xml
Martin Willemoes Hansen authored
5 public class Config {
6 [XmlAttribute] public string Author;
7 [XmlAttribute] public string BlogDirectory;
8 [XmlAttribute] public string BlogFileName;
9 [XmlAttribute] public string BlogWebDirectory;
5ccb9a2 @migueldeicaza Flush
migueldeicaza authored
10 [XmlAttribute] public string BlogImageBasedir;
fa15eda * lb.cs: Configuration data are now loaded from config.xml
Martin Willemoes Hansen authored
11 [XmlAttribute] public string Copyright;
12 [XmlAttribute] public string Description;
13 [XmlAttribute] public string ManagingEditor;
14 [XmlAttribute] public string Link;
15 [XmlAttribute] public string Title;
16 [XmlAttribute] public string RSSFileName;
7577226 * lb.cs: Read input & output file encodings from the config file
Jonathan Pryor authored
17 [XmlAttribute] public string InputEncoding;
18 [XmlAttribute] public string OutputEncoding;
a353072 @migueldeicaza Add analytics support
migueldeicaza authored
19 [XmlAttribute] public string AnalyticsStub;
09a61dc * config.cs: Add Prefix (base directory for output), BlogTemplate
Jonathan Pryor authored
20 [XmlAttribute] public string Prefix;
21 [XmlAttribute] public string BlogTemplate;
22 [XmlAttribute] public string EntryTemplate;
5e56455 @migueldeicaza Add support for comments to lame blog
migueldeicaza authored
23 [XmlAttribute] public string CommentsStub;
b6d92bf @migueldeicaza Add comments
migueldeicaza authored
24 [XmlAttribute] public string EntrySpecific;
6785c45 * lb.cs: .rss descriptions should be Translate()d and Render()d.
Jonathan Pryor authored
25 [XmlAttribute] public string ImageDirectory;
26 [XmlAttribute] public string ThumbnailCommand;
b2903b9 @migueldeicaza Small changes to try to merge a wordpress theme
migueldeicaza authored
27 public string ConfigFile;
28 public bool Verbose;
29
4044ba9 @migueldeicaza 2008-05-04 Miguel de Icaza <miguel@novell.com>
migueldeicaza authored
30 static public int EntriesPerPage = 15;
6785c45 * lb.cs: .rss descriptions should be Translate()d and Render()d.
Jonathan Pryor authored
31
32 internal string ThumbnailCommandFileName;
33 internal string ThumbnailCommandArguments;
09a61dc * config.cs: Add Prefix (base directory for output), BlogTemplate
Jonathan Pryor authored
34
35 public bool Parse (string[] args)
36 {
37 for (int i = 0; i < args.Length; ++i) {
38 string arg = args [i];
39 switch (arg) {
40 case "-h": case "--help":
41 PrintHelp ();
42 return false;
43 case "-p": case "--prefix":
44 if (NextArgument (args, ref i, ref Prefix))
45 break;
46 return false;
47 case "-d": case "--blog-directory":
48 if (NextArgument (args, ref i, ref BlogDirectory))
49 break;
50 return false;
51 case "-b": case "--blog-template":
52 if (NextArgument (args, ref i, ref BlogTemplate))
53 break;
54 return false;
55 case "-e": case "--entry-template":
56 if (NextArgument (args, ref i, ref EntryTemplate))
57 break;
58 return false;
59 case "-x": case "--rss-filename":
60 if (NextArgument (args, ref i, ref RSSFileName))
61 break;
62 return false;
6785c45 * lb.cs: .rss descriptions should be Translate()d and Render()d.
Jonathan Pryor authored
63 case "-t": case "--thumbnail-command":
64 if (NextArgument (args, ref i, ref ThumbnailCommand))
65 break;
66 return false;
b2903b9 @migueldeicaza Small changes to try to merge a wordpress theme
migueldeicaza authored
67 case "-c": case "--config":
68 if (NextArgument (args, ref i, ref ConfigFile))
69 break;
70 return false;
71 case "-v": case "--verbose":
72 Verbose = true;
73 break;
09a61dc * config.cs: Add Prefix (base directory for output), BlogTemplate
Jonathan Pryor authored
74 default:
75 if (ExtractArgument ("-p", arg, ref Prefix))
76 break;
77 if (ExtractArgument ("--prefix", arg, ref Prefix))
78 break;
79 if (ExtractArgument ("-b", arg, ref BlogTemplate))
80 break;
81 if (ExtractArgument ("--blog-template", arg, ref BlogTemplate))
82 break;
83 if (ExtractArgument ("-e", arg, ref EntryTemplate))
84 break;
85 if (ExtractArgument ("--entry-template", arg, ref EntryTemplate))
86 break;
87 if (ExtractArgument ("-d", arg, ref BlogDirectory))
88 break;
89 if (ExtractArgument ("--blog-directory", arg, ref BlogDirectory))
90 break;
91 if (ExtractArgument ("-x", arg, ref RSSFileName))
92 break;
93 if (ExtractArgument ("--rss-filename", arg, ref RSSFileName))
94 break;
6785c45 * lb.cs: .rss descriptions should be Translate()d and Render()d.
Jonathan Pryor authored
95 if (ExtractArgument ("-t", arg, ref ThumbnailCommand))
96 break;
97 if (ExtractArgument ("--thumbnail-command", arg, ref ThumbnailCommand))
98 break;
09a61dc * config.cs: Add Prefix (base directory for output), BlogTemplate
Jonathan Pryor authored
99 Error ("unrecognized option `{0}'", arg);
100 return false;
101 }
102 }
6785c45 * lb.cs: .rss descriptions should be Translate()d and Render()d.
Jonathan Pryor authored
103 if (ThumbnailCommand != null) {
104 ThumbnailCommandFileName = ThumbnailCommand.Split (' ')[0];
105 ThumbnailCommandArguments = ThumbnailCommand.Substring (ThumbnailCommandFileName.Length+1);
106 }
09a61dc * config.cs: Add Prefix (base directory for output), BlogTemplate
Jonathan Pryor authored
107 return true;
108 }
109
110 private static void PrintHelp ()
111 {
112 Console.WriteLine ("Usage: lb [OPTION]*");
113 Console.WriteLine ("lb (Lame Blog) is a blog engine.");
114 Console.WriteLine (@"
115 Options:
116 -p, --prefix=DIR Root directory for generated files.
117 -d, --blog-directory=DIR Where to find blog entry files (*.txt, *.html).
118 -b, --blog-template=FILE Blog template file .
119 -e, --entry-template=FILE Entry template file.
120 -x, --rss-filename=FILE Basename for RSS filename.
6785c45 * lb.cs: .rss descriptions should be Translate()d and Render()d.
Jonathan Pryor authored
121 -t, --thumbnail-command=CMD Command to use to generate thumbnails.
122 {0} is the input file.
123 {1} is the input file.
09a61dc * config.cs: Add Prefix (base directory for output), BlogTemplate
Jonathan Pryor authored
124 -h, --help Display this message and exit.
125 ");
126 }
127
128 private void Error (string format, params object[] args)
129 {
130 Console.Write ("lb: ");
131 Console.WriteLine (format, args);
132 Console.WriteLine ("Try `lb --help' for more information.");
133 }
134
135 private bool ExtractArgument (string prefix, string argument, ref string value)
136 {
137 if (argument.Length - 1 <= prefix.Length)
138 return false;
139 if (!argument.StartsWith (prefix))
140 return false;
141
142 char delim = argument [prefix.Length];
143 if (delim != '=' && delim != ':')
144 return false;
145
146 value = argument.Substring (prefix.Length+1);
147 return true;
148 }
149
150 private bool NextArgument (string[] args, ref int i, ref string value)
151 {
152 if ((i+1) >= args.Length) {
153 Error ("missing argument for `{0}'", args [i]);
154 return false;
155 }
156 value = args [++i];
157 return true;
158 }
fa15eda * lb.cs: Configuration data are now loaded from config.xml
Martin Willemoes Hansen authored
159 }
Something went wrong with that request. Please try again.