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
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 -------------------------------------------------------------------------*/
28 #include "SDCChasht.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 /** Prints elements of the set to the file, each element on new line
39 void fputStrSet(FILE *fp, set *list);
41 /** Prepend / append given strings to each item of string set. The result is in a
44 set *appendStrSet(set *list, const char *pre, const char *post);
46 /** Given a set returns a string containing all of the strings seperated
47 by spaces. The returned string is on the heap.
49 const char *joinStrSet(set *list);
51 /** Given a file with path information in the binary files directory,
52 returns the directory component. Used for discovery of bin
53 directory of SDCC installation. Returns NULL if the path is
56 char *getBinPath (const char *prel);
58 /** Returns true if the given path exists.
60 bool pathExists (const char *ppath);
62 void setMainValue (const char *pname, const char *pvalue);
64 void populateMainValues (const char **ppin);
66 void buildCmdLine2 (char *pbuffer, size_t len, const char *pcmd, ...);
68 /** Returns true if sz starts with the string given in key.
70 bool startsWith (const char *sz, const char *key);
72 /** Removes any newline characters from the string. Not strictly the
75 void chomp (char *sz);
78 getRuntimeVariables(void);
80 /* strncpy() with guaranteed NULL termination. */
81 char *strncpyz(char *dest, const char *src, size_t n);
83 /* like strncat() with guaranteed NULL termination
84 * The passed size should be the size of the dest buffer, not the number of
87 char *strncatz(char *dest, const char *src, size_t n);
89 /* return SDCC build number */
90 const char *getBuildNumber(void);
92 /* snprintf, by hook or by crook. */
93 size_t SDCCsnprintf(char *, size_t, const char *, ...);
95 # if defined(HAVE_VSNPRINTF)
97 // best option: we can define our own snprintf which logs errors.
98 # define SNPRINTF SDCCsnprintf
100 # elif defined(HAVE_SPRINTF)
102 // if we can't build a safe snprintf for lack of vsnprintf but there
103 // is a native snprintf, use it.
104 # define SNPRINTF snprintf
106 # elif defined(HAVE_VSPRINTF)
108 // we can at least define our own unsafe version.
109 # define SNPRINTF SDCCsnprintf
112 // We don't have a native snprintf nor the functions we need to write one.
113 # error "Need at least one of snprintf, vsnprintf, vsprintf!"
118 enum pragma_token_e { TOKEN_UNKNOWN, TOKEN_STR, TOKEN_INT, TOKEN_EOL };
120 struct pragma_token_s {
121 enum pragma_token_e type;
128 void init_pragma_token(struct pragma_token_s *token);
129 char *get_pragma_token(const char *s, struct pragma_token_s *token);
130 const char *get_pragma_string(struct pragma_token_s *token);
131 void free_pragma_token(struct pragma_token_s *token);