Update svn merge history.
[sdcc.git] / sdcc / src / SDCCutil.h
blobdf732af51c10581f769bf3b28977f323e07089c5
1 /*-------------------------------------------------------------------------
2 SDCCutil.c - Small utility functions.
4 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
23 -------------------------------------------------------------------------*/
25 #ifndef SDCCUTIL_H
26 #define SDCCUTIL_H
28 #include "SDCChasht.h"
29 #include "dbuf.h"
30 #include <stdarg.h>
32 /** Given an array of name, value string pairs creates a new hash
33 * containing all of the pairs.
35 hTab *populateStringHash (const char **pin);
37 /** Given an array of name, value string pairs creates a new hash
38 * containing all of the pairs.
40 char *shell_escape (const char *str);
42 /** Escape string for string constants.
43 * Returns dynamically allocated string, which should be free-ed.
45 char *string_escape (const char *str);
47 /** Prints elements of the set to the file, each element on new line
49 void fputStrSet (FILE * fp, set * list);
51 /** Prepend / append given strings to each item of string set. The result is in a
52 * new string set.
54 set *processStrSet (set * list, const char *pre, const char *post, char *(*file) (const char *));
56 /** Given a set returns a string containing all of the strings separated
57 * by spaces. The returned string is on the heap.
59 const char *joinStrSet (set * list);
61 /** Split the path string to the directory and file name (including extension) components.
62 * The directory component doesn't contain trailing directory separator.
63 * Returns true if the path contains the directory separator.
65 int dbuf_splitPath (const char *path, struct dbuf_s *dir, struct dbuf_s *file);
67 /** Split the path string to the file name (including directory) and file extension components.
68 * The file name component doesn't contain trailing extension separator.
69 * Returns true if the path contains the extension separator.
71 int dbuf_splitFile (const char *path, struct dbuf_s *file, struct dbuf_s *ext);
73 /** Combile directory and the file name to a path string using the DIR_SEPARATOR_CHAR.
75 void dbuf_makePath (struct dbuf_s *path, const char *dir, const char *file);
77 /** Given a file with path information in the binary files directory,
78 * returns the directory component. Used for discovery of bin
79 * directory of SDCC installation. Returns NULL if the path is
80 * impossible.
82 const char *getBinPath (const char *prel);
84 /** Returns true if the given path exists.
86 bool pathExists (const char *ppath);
88 void setMainValue (const char *pname, const char *pvalue);
90 char *buildMacros (const char *cmd);
92 void populateMainValues (const char **ppin);
94 char *buildCmdLine (const char **cmds, const char *p1, const char *p2, const char *p3, set *list, set *list2);
96 char *buildCmdLine2 (const char *pcmd, ...);
98 /** Returns true if sz starts with the string given in key.
100 bool startsWith (const char *sz, const char *key);
102 /** Removes any newline characters from the string.
103 * Not strictly the same as perl's chomp.
105 void chomp (char *sz);
107 hTab *getRuntimeVariables (void);
109 /* strncpy() with guaranteed NULL termination.
111 char *strncpyz (char *dest, const char *src, size_t n);
113 /* like strncat() with guaranteed NULL termination
114 * The passed size should be the size of the dest buffer, not the number of
115 * bytes to copy.
117 char *strncatz (char *dest, const char *src, size_t n);
119 /* return SDCC build number
121 const char *getBuildNumber (void);
123 /* return environment used to build SDCC
125 const char *getBuildEnvironment (void);
127 /** snprintf, by hook or by crook.
129 size_t SDCCsnprintf (char *, size_t, const char *, ...);
131 #define SNPRINTF SDCCsnprintf
133 /** Pragma tokenizer
135 enum pragma_token_e
136 { TOKEN_UNKNOWN, TOKEN_STR, TOKEN_INT, TOKEN_EOL };
138 struct pragma_token_s
140 enum pragma_token_e type;
141 struct dbuf_s dbuf;
142 union
144 int int_val;
145 } val;
148 void init_pragma_token (struct pragma_token_s *token);
149 char *get_pragma_token (const char *s, struct pragma_token_s *token);
150 const char *get_pragma_string (struct pragma_token_s *token);
151 void free_pragma_token (struct pragma_token_s *token);
153 unsigned long int hexEscape (const char **src);
154 unsigned long int universalEscape (const char **src, unsigned int n);
155 unsigned long int octalEscape (const char **src);
156 const char *copyStr (const char *src, size_t *size);
158 void getPrefixSuffix(const char *);
159 char *setPrefixSuffix(const char *);
161 char *formatInlineAsm (char *);
162 #endif