summaryrefslogtreecommitdiff
path: root/support/nlatexdb/nlatexdb/Program.cs
blob: 68b1960e8a4e3195beed5a7d8d060696c089e854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//    nlatexdb Version 0.03
//    Database Access in LaTeX
//    Copyright (C) 2011 Robin Höns, Integranova GmbH
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
//    For more information see the web page http://hoens.net/robin


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XGetoptCS;

namespace nlatexdb
{
    class Program
    {
        static void Help()
        {
            Console.WriteLine("NatexDB 0.03 Copyright (C) 2011 Robin Hoens");
            Console.WriteLine("This program comes with ABSOLUTELY NO WARRANTY.");
            Console.WriteLine("This is free software, and you are welcome to redistribute it");
            Console.WriteLine("under certain conditions.");
            Console.WriteLine("See file COPYING for details.");
            Console.WriteLine();
            Console.WriteLine("Usage:");
            Console.WriteLine("nlatexdb [Arguments] <texfile.tex> [Parameters...]");
            Console.WriteLine("Arguments can be:");
            Console.WriteLine("-p = call pdflatex on result");
            Console.WriteLine("-l = call latex on result");
            Console.WriteLine("-c <latexcommand> = call <latexcommand> on result");
            Console.WriteLine("-e <encoding> = use string <encoding> on input and output file");
            Console.WriteLine("-o <outpath> = write result to <outpath>");
            Console.WriteLine("-P = list known database providers");
            Console.WriteLine("-v = increase verbosity");
            Console.WriteLine("-h = output this help text");
        }


        static int Main(string[] args)
        {
            Processer proc = new Processer();
            int argc = args.Length;
            bool help = false;
            char c;
            XGetopt go = new XGetopt();
            while ((c = go.Getopt(argc, args, "plvho:c:Pe:")) != '\0')
            {
                switch (c)
                {
                    case 'P':
                        proc.ListProviders();
                        break;

                    case 'p':
                        proc.setLatexbefehl("pdflatex");
                        break;

                    case 'l':
                        proc.setLatexbefehl("latex");
                        break;

                    case 'c':
                        proc.setLatexbefehl(go.Optarg);
                        break;

                    case 'e':
                        proc.setEncoding(go.Optarg);
                        break;

                    case 'o':
                        proc.setOutpath(go.Optarg);
                        break;

                    case 'v':
                        proc.incVerbosity();
                        break;

                    case 'h':
                        help = true;
                        break;

                    case '?':
                        Console.WriteLine("illegal option or missing arg");
                        help = true;
                        break;
                }
            }

            if (go.Optarg != string.Empty)
            {
                proc.setInpath(go.Optarg);
                int i = go.Optind + 1;
                while (i < args.Length)
                {
                    proc.addCmdlineArg(args[i]);
                    i++;
                }
            }
            else 
            {
                help = true;
            }

            if (help)
            {
                Help();
                return 1;
            }

            return proc.Go();
        }
    }
}