2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* util.h
|
|
|
|
*
|
2006-01-02 14:55:35 -05:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2005-03-14 20:51:43 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#ifndef _PM_UTIL_H
|
|
|
|
#define _PM_UTIL_H
|
|
|
|
|
2007-01-19 04:28:44 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <libintl.h>
|
|
|
|
|
|
|
|
#include <alpm.h>
|
|
|
|
#include <alpm_list.h>
|
2006-03-13 15:34:47 -05:00
|
|
|
|
2006-01-07 04:42:48 -05:00
|
|
|
#define MALLOC(p, b) do { \
|
|
|
|
if((b) > 0) { \
|
|
|
|
p = malloc(b); \
|
|
|
|
if (!(p)) { \
|
2006-10-15 15:34:52 -04:00
|
|
|
fprintf(stderr, "malloc failure: could not allocate %d bytes\n", (int)b); \
|
2007-01-18 11:52:57 -05:00
|
|
|
exit(EXIT_FAILURE); \
|
2006-01-07 04:42:48 -05:00
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
p = NULL; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-03-16 16:21:06 -05:00
|
|
|
#define FREE(p) do { if (p) { free(p); (p) = NULL; }} while(0)
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2005-12-20 18:59:56 -05:00
|
|
|
#define STRNCPY(s1, s2, len) do { \
|
|
|
|
strncpy(s1, s2, (len)-1); \
|
|
|
|
s1[(len)-1] = 0; \
|
|
|
|
} while(0)
|
|
|
|
|
2007-02-03 20:36:45 -05:00
|
|
|
/* update speed for the fill_progress based functions */
|
|
|
|
#define UPDATE_SPEED_SEC 0.2f
|
|
|
|
|
2006-05-14 22:19:57 -04:00
|
|
|
#define _(str) gettext(str)
|
2007-01-18 11:52:57 -05:00
|
|
|
unsigned int getcols();
|
2005-03-14 20:51:43 -05:00
|
|
|
int makepath(char *path);
|
|
|
|
int rmrf(char *path);
|
2007-01-18 11:52:57 -05:00
|
|
|
void indentprint(const char *str, unsigned int indent);
|
2005-03-14 20:51:43 -05:00
|
|
|
char *strtoupper(char *str);
|
2006-03-13 15:34:47 -05:00
|
|
|
char *strtrim(char *str);
|
2005-10-07 19:29:49 -04:00
|
|
|
int reg_match(char *string, char *pattern);
|
2007-01-19 04:28:44 -05:00
|
|
|
void list_display(const char *title, alpm_list_t *list);
|
2007-02-03 20:36:45 -05:00
|
|
|
void display_targets(alpm_list_t *pkgs);
|
|
|
|
float get_update_timediff(int first_call);
|
|
|
|
void fill_progress(const int percent, const int proglen);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
#endif /* _PM_UTIL_H */
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|