* as/hc08/lkaomf51.c (OutputName),
[fw/sdcc] / src / SDCCutil.h
index 55a8f9f68dc6771e039ad9710dc86342a9fcfa2a..d8956d49322aa078b6daed1a9f4f3b7eb00b0eaf 100644 (file)
 #define SDCCUTIL_H
 
 #include "SDCChasht.h"
-
-/* PENDING: Hacks as I can't work autoconf */
-#define BINDIR PREFIX "/bin"
+#include <stdarg.h>
 
 /** Given an array of name, value string pairs creates a new hash
     containing all of the pairs.
 */
 hTab *populateStringHash(const char **pin);
 
-/** Given an array of string pointers and another string, adds the
-    string to the end of the list.  The end of the list is assumed to
-    be the first NULL pointer.
-*/
-void addToList (const char **list, const char *str);
-
-/** Given an array of string pointers returns a string containing all
-    of the strings seperated by spaces.  The returned string is on the
-    heap.  The join stops when a NULL pointer is hit.
+/** Prints elements of the set to the file, each element on new line
 */
-char *join(const char **pplist);
+void fputStrSet(FILE *fp, set *list);
 
-/** Given an array of string pointers, returns a string containing all
-    of the strings seperated by spaces.  The returned string is on the
-    heap.  n is the number of strings in the list.
+/** Prepend / append given strings to each item of string set. The result is in a
+    new string set.
 */
-char *joinn(char **pplist, int n);
+set *appendStrSet(set *list, const char *pre, const char *post);
 
-/** Returns the characters in p2 past the last matching characters in
-    p1.  
+/** Given a set returns a string containing all of the strings seperated
+    by spaces. The returned string is on the heap.
 */
-char *getStringDifference (char *pinto, const char *p1, const char *p2);
+const char *joinStrSet(set *list);
 
 /** Given a file with path information in the binary files directory,
-    returns what PREFIX must be to get this path.  Used for discovery
-    of where SDCC is installed.  Returns NULL if the path is
+    returns the directory component. Used for discovery of bin
+    directory of SDCC installation. Returns NULL if the path is
     impossible.
 */
-char *getPrefixFromBinPath (const char *prel);
+char *getBinPath (const char *prel);
 
 /** Returns true if the given path exists.
  */
@@ -73,7 +62,7 @@ void setMainValue (const char *pname, const char *pvalue);
 
 void populateMainValues (const char **ppin);
 
-void buildCmdLine2 (char *pbuffer, const char *pcmd);
+void buildCmdLine2 (char *pbuffer, size_t len, const char *pcmd, ...);
 
 /** Returns true if sz starts with the string given in key.
  */
@@ -84,5 +73,43 @@ bool startsWith (const char *sz, const char *key);
 */
 void chomp (char *sz);
 
-#endif
+hTab *
+getRuntimeVariables(void);
+
+/* strncpy() with guaranteed NULL termination. */
+char *strncpyz(char *dest, const char *src, size_t n);
+
+/* like strncat() with guaranteed NULL termination
+ * The passed size should be the size of the dest buffer, not the number of 
+ * bytes to copy.
+ */
+char *strncatz(char *dest, const char *src, size_t n);
+
+/* return SDCC build number */
+const char *getBuildNumber(void);
+
+/* snprintf, by hook or by crook. */
+size_t SDCCsnprintf(char *, size_t, const char *, ...);
 
+# if defined(HAVE_VSNPRINTF)
+
+// best option: we can define our own snprintf which logs errors.
+#  define SNPRINTF SDCCsnprintf
+
+# elif defined(HAVE_SPRINTF)
+
+// if we can't build a safe snprintf for lack of vsnprintf but there
+// is a native snprintf, use it.
+#  define SNPRINTF snprintf
+
+# elif defined(HAVE_VSPRINTF)
+
+// we can at least define our own unsafe version.
+#  define SNPRINTF SDCCsnprintf
+
+# else
+// We don't have a native snprintf nor the functions we need to write one.
+#  error "Need at least one of snprintf, vsnprintf, vsprintf!"
+# endif
+
+#endif