117 lines
3.0 KiB
C#
117 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
|
|
namespace svgb
|
|
{
|
|
class Program
|
|
{
|
|
public static int SVGB_EXIT_OK = 0;
|
|
public static int SVGB_EXIT_USAGE = 1;
|
|
public static int SVGB_EXIT_ERROR = 2;
|
|
public static int SVGB_EXIT_UNSUPPORTED = 3;
|
|
public static string APP_VERSION = "0.9.1";
|
|
|
|
public static int Main(string[] argv)
|
|
{
|
|
int argc = argv.Length;
|
|
int ret = SVGB_EXIT_ERROR;
|
|
MEM_InitModule();
|
|
if(argc == 2 || argc == 3)
|
|
{
|
|
File * in = FILE_Open();
|
|
if(in)
|
|
{
|
|
File * out;
|
|
if(argc == 2)
|
|
{
|
|
outfile = "stdout";
|
|
out = FILE_AttachToFile();
|
|
}
|
|
else
|
|
{
|
|
outfile = argv[2];
|
|
out = FILE_Open();
|
|
}
|
|
if(out)
|
|
{
|
|
File * wrap = FILE_Wrap(2);
|
|
if(wrap)
|
|
{
|
|
if(SVGB_Decode())
|
|
{
|
|
ret = SVGB_EXIT_OK;
|
|
}
|
|
FILE_Detach();
|
|
FILE_Close();
|
|
}
|
|
else if(SVGB_Decode())
|
|
{
|
|
ret = SVGB_EXIT_OK;
|
|
}
|
|
FILE_Detach();
|
|
FILE_Close();
|
|
}
|
|
else
|
|
{
|
|
Error("%s: can't create output file %s\n");
|
|
}
|
|
FILE_Close();
|
|
}
|
|
else
|
|
{
|
|
Error("%s: can't open input file %s\n");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Output("Usage: %s input [output]\n");
|
|
ret = SVGB_EXIT_ERROR;
|
|
}
|
|
MEM_Shutdown();
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
int ret = SVGB_EXIT_ERROR;
|
|
string outfile;
|
|
string infile;
|
|
if (args.Length == 2 || args.Length == 3) {
|
|
infile = args[1];
|
|
BinaryReader ein = new BinaryReader(File.Open(infile, FileMode.Open), System.Text.Encoding.Default);
|
|
if (ein != null) {
|
|
StreamWriter aus;
|
|
if (args.Length == 2) {
|
|
outfile = "stdout";
|
|
aus = new StreamWriter(outfile);
|
|
} else {
|
|
outfile = args[2];
|
|
aus = new StreamWriter(outfile);
|
|
}
|
|
if (aus != null) {
|
|
SvgDec a = new SvgDec(ein, aus);
|
|
if (a.getReturnCode()) {
|
|
ret = SVGB_EXIT_OK;
|
|
}
|
|
aus.Close();
|
|
} else {
|
|
Console.WriteLine("{0} can't create output file {1}","svgb.exe",outfile);
|
|
}
|
|
ein.Close();
|
|
} else {
|
|
Console.WriteLine("{0} can't open input file {1}","svgb.exe",infile);
|
|
}
|
|
} else {
|
|
Console.WriteLine("SVGB to SVG converter version "+APP_VERSION);
|
|
Console.WriteLine("Usage: {0} input [output]\n", "svgb.exe");
|
|
ret = SVGB_EXIT_ERROR;
|
|
}
|
|
Environment.ExitCode = ret;
|
|
}
|
|
}
|
|
}
|