* .version: Updated to 2.3.1
[fw/sdcc] / src / SDCCutil.h
1 /*-------------------------------------------------------------------------
2   SDCCutil.c - Small utility functions.
3
4              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
5
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.
10
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.
15
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.
19
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 -------------------------------------------------------------------------*/
24
25 #ifndef SDCCUTIL_H
26 #define SDCCUTIL_H
27
28 #include "SDCChasht.h"
29
30 /* PENDING: Hacks as I can't work autoconf */
31 #define BINDIR  PREFIX "/bin"
32
33 /** Given an array of name, value string pairs creates a new hash
34     containing all of the pairs.
35 */
36 hTab *populateStringHash(const char **pin);
37
38 /** Given an array of string pointers and another string, adds the
39     string to the end of the list.  The end of the list is assumed to
40     be the first NULL pointer.
41 */
42 void addToList (const char **list, const char *str);
43
44 /** Given an array of string pointers returns a string containing all
45     of the strings seperated by spaces.  The returned string is on the
46     heap.  The join stops when a NULL pointer is hit.
47 */
48 char *join(const char **pplist);
49
50 /** Given an array of string pointers, returns a string containing all
51     of the strings seperated by spaces.  The returned string is on the
52     heap.  n is the number of strings in the list.
53 */
54 char *joinn(char **pplist, int n);
55
56 /** Returns the characters in p2 past the last matching characters in
57     p1.  
58 */
59 char *getStringDifference (char *pinto, const char *p1, const char *p2);
60
61 /** Given a file with path information in the binary files directory,
62     returns what PREFIX must be to get this path.  Used for discovery
63     of where SDCC is installed.  Returns NULL if the path is
64     impossible.
65 */
66 char *getPrefixFromBinPath (const char *prel);
67
68 /** Returns true if the given path exists.
69  */
70 bool pathExists (const char *ppath);
71
72 void setMainValue (const char *pname, const char *pvalue);
73
74 void populateMainValues (const char **ppin);
75
76 void buildCmdLine2 (char *pbuffer, const char *pcmd);
77
78 /** Returns true if sz starts with the string given in key.
79  */
80 bool startsWith (const char *sz, const char *key);
81
82 /** Removes any newline characters from the string.  Not strictly the
83     same as perl's chomp.
84 */
85 void chomp (char *sz);
86
87 #endif
88