*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
}
#endif
-void message(const char *format, ...)
+void mdvi_message(const char *format, ...)
{
va_list ap;
va_end(ap);
}
-void crash(const char *format, ...)
+void mdvi_crash(const char *format, ...)
{
va_list ap;
abort();
}
-void error(const char *format, ...)
+void mdvi_error(const char *format, ...)
{
va_list ap;
va_end(ap);
}
-void warning(const char *format, ...)
+void mdvi_warning(const char *format, ...)
{
va_list ap;
va_end(ap);
}
-void fatal(const char *format, ...)
+void mdvi_fatal(const char *format, ...)
{
va_list ap;
void *ptr = malloc(nelems);
if(ptr == NULL)
- fatal(_("out of memory allocating %u bytes\n"),
- (unsigned)nelems);
+ mdvi_fatal(_("out of memory allocating %u bytes\n"),
+ (unsigned)nelems);
return ptr;
}
void *ptr;
if(newsize == 0)
- crash(_("attempted to reallocate with zero size\n"));
+ mdvi_crash(_("attempted to reallocate with zero size\n"));
ptr = realloc(data, newsize);
if(ptr == NULL)
- fatal(_("failed to reallocate %u bytes\n"), (unsigned)newsize);
+ mdvi_fatal(_("failed to reallocate %u bytes\n"), (unsigned)newsize);
return ptr;
}
void *ptr;
if(nmemb == 0)
- crash(_("attempted to callocate 0 members\n"));
+ mdvi_crash(_("attempted to callocate 0 members\n"));
if(size == 0)
- crash(_("attempted to callocate %u members with size 0\n"),
+ mdvi_crash(_("attempted to callocate %u members with size 0\n"),
(unsigned)nmemb);
ptr = calloc(nmemb, size);
if(ptr == 0)
- fatal(_("failed to allocate %ux%u bytes\n"),
- (unsigned)nmemb, (unsigned)size);
+ mdvi_fatal(_("failed to allocate %ux%u bytes\n"),
+ (unsigned)nmemb, (unsigned)size);
return ptr;
}
void mdvi_free(void *ptr)
{
if(ptr == NULL)
- crash(_("attempted to free NULL pointer\n"));
+ mdvi_crash(_("attempted to free NULL pointer\n"));
free(ptr);
}
return ptr;
}
+char *mdvi_strrstr (const char *haystack, const char *needle)
+{
+ size_t i;
+ size_t needle_len;
+ size_t haystack_len;
+ const char *p;
+
+ needle_len = strlen (needle);
+ haystack_len = strlen (haystack);
+
+ if (needle_len == 0)
+ return NULL;
+
+ if (haystack_len < needle_len)
+ return (char *)haystack;
+
+ p = haystack + haystack_len - needle_len;
+ while (p >= haystack) {
+ for (i = 0; i < needle_len; i++)
+ if (p[i] != needle[i])
+ goto next;
+
+ return (char *)p;
+
+ next:
+ p--;
+ }
+
+ return NULL;
+}
+
+char *mdvi_build_path_from_cwd (const char *path)
+{
+ char *ptr;
+ char *buf = NULL;
+ size_t buf_size = 512;
+
+ while (1) {
+ buf = mdvi_realloc (buf, buf_size);
+ if ((ptr = getcwd (buf, buf_size)) == NULL && errno == ERANGE) {
+ buf_size *= 2;
+ } else {
+ buf = ptr;
+ break;
+ }
+ }
+
+ buf = mdvi_realloc (buf, strlen (buf) + strlen (path) + 2);
+ strcat (buf, "/");
+ strncat (buf, path, strlen (path));
+
+ return buf;
+}
+
double unit2pix_factor(const char *spec)
{
double val;