1 //
2 // aegis - project change supervisor
3 // Copyright (C) 1997, 1999, 2002-2008, 2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #include <common/sizeof.h>
20 #include <common/symtab.h>
21 #include <libaegis/sub.h>
22 
23 #include <aefind/function/basename.h>
24 #include <aefind/function/execute.h>
25 #include <aefind/function.h>
26 #include <aefind/function/print.h>
27 #include <aefind/function/stat.h>
28 #include <aefind/lex.h>
29 #include <aefind/tree.h>
30 #include <aefind/tree/list.h>
31 #include <aefind/tree/this.h>
32 
33 
34 struct table_ty
35 {
36     const char *name;
37     tree::pointer (*func)(const tree_list &);
38 };
39 
40 
41 static table_ty table[] =
42 {
43     { "access_time", &tree_atime::create_l, },
44     { "atime", &tree_atime::create_l, },
45     { "basename", &tree_basename::create_l, },
46     { "change_time", &tree_ctime::create_l, },
47     { "ctime", &tree_ctime::create_l, },
48     { "execute", &tree_execute::create_l, },
49     { "gid", &tree_gid::create_l, },
50     { "group_id", &tree_gid::create_l, },
51     { "ino", &tree_ino::create_l, },
52     { "inode", &tree_ino::create_l, },
53     { "mode", &tree_mode::create_l, },
54     { "modify_time", &tree_mtime::create_l, },
55     { "mtime", &tree_mtime::create_l, },
56     { "nlink", &tree_nlink::create_l, },
57     { "print", &tree_print::create_l, },
58     { "size", &tree_size::create_l, },
59     { "st_atime", &tree_atime::create_l, },
60     { "st_ctime", &tree_ctime::create_l, },
61     { "st_gid", &tree_gid::create_l, },
62     { "st_ino", &tree_ino::create_l, },
63     { "st_mode", &tree_mode::create_l, },
64     { "st_mtime", &tree_mtime::create_l, },
65     { "st_nlink", &tree_nlink::create_l, },
66     { "st_size", &tree_size::create_l, },
67     { "st_uid", &tree_uid::create_l, },
68     { "type", &tree_type::create_l, },
69     { "uid", &tree_uid::create_l, },
70     { "user_id", &tree_uid::create_l, },
71 };
72 
73 
74 tree::pointer
function_indirection(string_ty * name,const tree_list & args)75 function_indirection(string_ty *name, const tree_list &args)
76 {
77     static symtab_ty *stp;
78     if (!stp)
79     {
80         stp = new symtab_ty(SIZEOF(table));
81         for (table_ty *tp = table; tp < ENDOF(table); ++tp)
82         {
83             string_ty *s = str_from_c(tp->name);
84             stp->assign(s, tp);
85             str_free(s);
86         }
87     }
88 
89     table_ty *tp = (table_ty *)stp->query(name);
90     if (!tp)
91     {
92         string_ty *guess = stp->query_fuzzy(name);
93         if (!guess)
94         {
95             sub_context_ty sc;
96             sc.var_set_string("Name", name);
97             cmdline_lex_error(&sc, i18n("the name \"$name\" is undefined"));
98         }
99         else
100         {
101             sub_context_ty sc;
102             sc.var_set_string("Name", name);
103             sc.var_set_string("Guess", guess);
104             cmdline_lex_error(&sc, i18n("no \"$name\", guessing \"$guess\""));
105         }
106         return tree_this::create();
107     }
108     return tp->func(args);
109 }
110 
111 
112 // vim: set ts=8 sw=4 et :
113