stdheader.cc 6.58 KB
Newer Older
Phil Edwards committed
1 2 3 4 5 6 7 8 9 10 11 12 13
// This is a slow larval-stage kludge to help massage the generated man
// pages.  It's used like this:
const char* const usage = 
"\nTakes on stdin, whitespace-separated words of the form\n"
"\n"
"    [bits/]stl_foo.h\n"
"    [bits/]std_foo.h\n"
"\n"
"and writes on stdout the nearest matching standard header name.\n"
"\n"
"Takes no command-line arguments.\n"
"\n";

14
#include <cstdlib>
Phil Edwards committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <string>
#include <map>
#include <iostream>

typedef std::map<std::string, std::string>   Map;

Map  headers;

void init_map()
{
    // Enter the glamourous world of data entry!!  Maintain these!
    headers["algo.h"]                   = "algorithm";
    headers["algobase.h"]               = "algorithm";
    headers["algorithm.h"]              = "algorithm";
29
    headers["heap.h"]                   = "algorithm";
Phil Edwards committed
30 31 32 33
    headers["bitset.h"]                 = "bitset";
    headers["complex.h"]                = "complex";
    //headers["construct.h"]              stl_construct.h entirely internal
    headers["deque.h"]                  = "deque";
34
    headers["deque.tcc"]                = "deque";
Phil Edwards committed
35 36 37 38 39
    headers["fstream.h"]                = "fstream";
    headers["fstream.tcc"]              = "fstream";
    headers["function.h"]               = "functional";
    headers["functional.h"]             = "functional";
    headers["iomanip.h"]                = "iomanip";
40 41
    headers["basic_ios.h"]              = "ios";
    headers["basic_ios.tcc"]            = "ios";
Phil Edwards committed
42 43 44 45 46 47 48 49
    headers["ios.h"]                    = "ios";
    headers["iosfwd.h"]                 = "iosfwd";
    headers["iostream.h"]               = "iostream";
    headers["istream.h"]                = "istream";
    headers["istream.tcc"]              = "istream";
    headers["iterator.h"]               = "iterator";
    headers["iterator_base_funcs.h"]    = "iterator";
    headers["iterator_base_types.h"]    = "iterator";
50 51
    headers["stream_iterator.h"]        = "iterator";
    headers["streambuf_iterator.h"]     = "iterator";
Phil Edwards committed
52 53
    headers["limits.h"]                 = "limits";
    headers["list.h"]                   = "list";
54
    headers["list.tcc"]                 = "list";
55
    headers["codecvt.h"]                = "locale";
Phil Edwards committed
56
    headers["locale.h"]                 = "locale";
57 58
    headers["localefwd.h"]              = "locale";
    headers["locale_classes.h"]         = "locale";
Phil Edwards committed
59 60 61 62
    headers["locale_facets.h"]          = "locale";
    headers["locale_facets.tcc"]        = "locale";
    headers["map.h"]                    = "map";
    headers["multimap.h"]               = "map";
63 64 65 66 67
    headers["memory.h"]                 = "memory";
    headers["allocator.h"]              = "memory";
    headers["raw_storage_iter.h"]       = "memory";
    headers["tempbuf.h"]                = "memory";
    headers["uninitialized.h"]          = "memory";
Phil Edwards committed
68 69 70 71 72
    headers["numeric.h"]                = "numeric";
    headers["ostream.h"]                = "ostream";
    headers["ostream.tcc"]              = "ostream";
    headers["queue.h"]                  = "queue";
    headers["set.h"]                    = "set";
73
    headers["multiset.h"]               = "set";
Phil Edwards committed
74 75 76
    headers["sstream.h"]                = "sstream";
    headers["sstream.tcc"]              = "sstream";
    headers["stack.h"]                  = "stack";
77
    headers["functexcept.h"]            = "stdexcept";
Phil Edwards committed
78 79 80 81
    headers["stdexcept.h"]              = "stdexcept";
    headers["streambuf.h"]              = "streambuf";
    headers["streambuf.tcc"]            = "streambuf";
    headers["string.h"]                 = "string";
82 83 84 85
    headers["char_traits.h"]            = "string";
    headers["postypes.h"]               = "string";
    headers["basic_string.h"]           = "string";
    headers["basic_string.tcc"]         = "string";
Phil Edwards committed
86
    headers["tree.h"]                   = "backward/tree.h";
87
    headers["pair.h"]                   = "utility";
Phil Edwards committed
88
    headers["utility.h"]                = "utility";
89
    headers["relops.h"]                 = "utility";
90 91 92 93 94
    headers["gslice.h"]                 = "valarray";
    headers["gslice_array.h"]           = "valarray";
    headers["indirect_array.h"]         = "valarray";
    headers["mask_array.h"]             = "valarray";
    headers["slice_array.h"]            = "valarray";
Phil Edwards committed
95
    headers["valarray.h"]               = "valarray";
96 97
    headers["valarray_after.h"]         = "valarray";
    headers["valarray_before.h"]        = "valarray";
Phil Edwards committed
98 99 100
    headers["valarray_array.h"]         = "valarray";
    headers["valarray_array.tcc"]       = "valarray";
    headers["valarray_meta.h"]          = "valarray";
101
    headers["bvector.h"]                = "vector";
Phil Edwards committed
102
    headers["vector.h"]                 = "vector";
103
    headers["vector.tcc"]               = "vector";
Phil Edwards committed
104

105 106 107
    //headers["concurrence.h"]             who knows
    //headers["atomicity.h"]               who knows

Phil Edwards committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    // C wrappers -- probably was an easier way to do these, but oh well
    headers["cassert.h"]                = "cassert";
    headers["cctype.h"]                 = "cctype";
    headers["cerrno.h"]                 = "cerrno";
    headers["cfloat.h"]                 = "cfloat";
    headers["climits.h"]                = "climits";
    headers["clocale.h"]                = "clocale";
    headers["cmath.h"]                  = "cmath";
    headers["csetjmp.h"]                = "csetjmp";
    headers["csignal.h"]                = "csignal";
    headers["cstdarg.h"]                = "cstdarg";
    headers["cstddef.h"]                = "cstddef";
    headers["cstdio.h"]                 = "cstdio";
    headers["cstdlib.h"]                = "cstdlib";
    headers["cstring.h"]                = "cstring";
    headers["ctime.h"]                  = "ctime";
    headers["cwchar.h"]                 = "cwchar";
    headers["cwctype.h"]                = "cwctype";
}


void do_word (std::string const& longheader)
{
    std::string::size_type start = 0;

133 134 135 136 137 138 139
    // if it doesn't contain a "." then it's already a std header
    if (longheader.find(".") == std::string::npos)
    {
        std::cout << longheader << '\n';
        return;
    }

Phil Edwards committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
    if (longheader.substr(start,5) == "bits/")  start += 5;
    if ((longheader.substr(start,4) == "stl_") ||
        (longheader.substr(start,4) == "std_"))
    {
        start += 4;
    }

    // come on, gdb, find `p' already...
    const char* p = longheader.substr(start).c_str();
    Map::iterator word = headers.find(p);
    if (word != headers.end())
        std::cout << word->second << '\n';
    else std::cout << "MAYBE_AN_ERROR_MESSAGE_HERE\n";
}


int main (int argc, char**)
{
    if (argc > 1)
    {
        std::cerr << usage;
161
	std::exit(0);
Phil Edwards committed
162 163 164 165 166 167 168 169 170 171
    }

    init_map();

    std::string w;
    while (std::cin >> w)
        do_word (w);
}