Add tags

Add tags to the following comment
 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
using System;
using System.Collections.Generic;

class P
{
  static void Main(string[] args)
  {
    bool o = false, q =false, d = false;
    int? dn = null;
    List<string> l = new List<string>();
    try
    {
      foreach (string s in args)
      {
        if (d && (dn == null))
        {
          if (s.Length != 1) throw new Exception();
          dn = s[0] - '0';
          continue;
        }
        if (l.Count > 0 || s[0] != '-')
        {
          l.Add(s);
          continue;
        }
        for (int i = 1; i < s.Length; i++)
        {
          switch (s[i])
          {
            case 'o':
              o = true;
              break;
            case 'q':
              q = true;
              break;
            case 'd':
              d = true;
              if (i < s.Length - 1)
                dn = s[++i] - '0';
              break;
            default:
              throw new Exception(s);
          }
        }
      }
      if (!o) throw new Exception();
      if (d && !(0 <= dn && dn <= 2)) throw new Exception();
      if (l.Count == 0) throw new Exception();
      Console.WriteLine("o(output): {0}", o ? "ON" : "OFF");
      Console.WriteLine("q(quote): {0}", q ? "ON" : "OFF");
      if (d) Console.WriteLine("d(debug): {0}", dn);
      for (int i = 0; i < l.Count; i++)
        Console.WriteLine("{0}: {1}", i, l[i]);
    }
    catch
    {
      Console.WriteLine
        ("usage: cmdopt -o [-q] [-d{0|1|2}] string [string ...]");
      Environment.Exit(-1);
    }
  }
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...