1 //-----------------------------------------------------------------------------
2 // Alias
3 //-----------------------------------------------------------------------------
4 
5 #ifndef __ALIAS_H__
6 #define __ALIAS_H__
7 
8 #define MAX_ALIAS_NAME    32        /**< maximum length of alias names */
9 
10 /**
11  * maximum amount of recursive call<br>
12  * Use to avoid infinite recursions.
13  */
14 #define MAX_ALIAS_DEPTH   16
15 
16 /**
17  * Alias structure
18  * This structure describes an alias. An alias is a couple name-value. A
19  * pointer is also added and used in the list structure of the Alias class.
20  * @see Alias
21  */
22 typedef struct alias_s
23 {
24   struct alias_s *next;         /**< pointer on the next alias in aliases lits */
25   char    name[MAX_ALIAS_NAME];   /**< alias name */
26   char    *value;           /**< alias value */
27 } alias_t;
28 
29 /**
30  * Alias class.
31  * Alias can be used to replace existing words, commands or variables
32  * with others.
33  */
34 class Alias
35 {
36   alias_t   *alias;     /**< Pointer on the first alias of the list */
37 
38   public:
39     Alias(void);
40     ~Alias(void);
41 
42     /**
43      * Recursion depth.
44      * Used to avoid infinit recursions
45      */
46     int depth;
47 
48     /**
49      * Finds an alias of the list.
50      * @param a_name the name of alias to get
51      * @return a pointer to the alias or NULL pointer if alias cannot be
52      *         found in the list
53      */
54     alias_t* FindAlias(char *a_name);
55 
56     /**
57      * Modifiy the value of an existing alias or add a new alias with
58      * given value.
59      * @param a_name the name of alias
60      * @param value the new value of alias
61      */
62     void SetAlias(char *a_name, char *value, ...);
63 
64     /**
65      * Removes an alias from the list.
66      * The function try to find the alias in the list and removes it if
67      * it can find it. The alias is destroyed and memory is freed.
68      * @param a_name the name of alias to remove
69      */
70     void RemoveAlias(char *a_name);
71 
72     /**
73      * Gets the value of an alias.
74      * @param a_name the name of alias to get
75      * @return the corresponding value for requested alias
76      */
77     char *GetAlias(char *a_name);
78 
79     /**
80      * Autocompletes alias name.
81      * @param partial the beginning of alias name
82      * @return the full name for first matching alias
83      */
84     char *CompleteAlias(char *partial);
85 
86     /**
87      * Gets the aliases list.
88      * @return a pointer to the first alias of the list
89      */
90     alias_t* GetAliasList(void);
91 
92     /**
93      * Prints a list of defined aliases to the console.
94      */
95     void printList(void);
96 
97     /**
98      * Returns the number of aliases.
99      * @return the number of aliases
100      */
101     int GetNumber(void);
102 
103     /**
104      * Get the name of alias at position \a i in the aliases list
105      * @param i the position of alias in the list
106      * @return the name of alias \a i, a empty string if \a i is not correct
107      */
108     char *GetName(int i);
109 };
110 
111 #endif  /* __ALIAS_H__ */
112