Exemplo n.º 1
0
Arquivo: sort.c Projeto: sklnd/vifm
static int
compare_file_names(const char *s, const char *t, int ignore_case)
{
	char s_buf[NAME_MAX];
	char t_buf[NAME_MAX];

	snprintf(s_buf, sizeof(s_buf), "%s", s);
	chosp(s_buf);
	s = s_buf;
	snprintf(t_buf, sizeof(t_buf), "%s", t);
	chosp(t_buf);
	t = t_buf;

	if(ignore_case)
	{
		strtolower(s_buf);
		strtolower(t_buf);
	}

	if(!cfg.sort_numbers)
		return strcmp(s, t);
	else
#if defined(_WIN32) || defined(__APPLE__)
		return vercmp(s, t);
#else
		return strverscmp(s, t);
#endif
}
Exemplo n.º 2
0
struct pkglist *apply_favorites(struct pkglist *p)
{
	struct pkglist *newp=NULL;
	struct pkglist *tmp=NULL;
	while(p) {
		if((tmp=pkglist_find(p->name, ilenia_favoriterepo)) &&
		    strcmp(tmp->repo, p->repo)){

			p = p->next;
			continue;
		}
		
		if((tmp=pkglist_find(p->name, ilenia_favoriteversion)) &&
		   strcmp(tmp->version, p->version)){
			p = p->next;
			continue;
		}
 
		if((tmp=pkglist_find(p->name, newp))) {
			if(vercmp(tmp->version, p->version))
				newp = pkglist_remove(p->name, newp);
			else {
				p = p->next;
				continue;
			} 
		}

		newp = pkglist_add_ordered(p->name, p->version, p->repo, p->depends, newp);
			
		p = p->next;
	}
	return newp;
}
Exemplo n.º 3
0
int
pool_evrmatch(const Pool *pool, Id evrid, const char *epoch, const char *version, const char *release)
{
  const char *evr1;
  const char *s1;
  const char *r1;
  int r;

  evr1 = id2str(pool, evrid);
  for (s1 = evr1; *s1 >= '0' && *s1 <= '9'; s1++)
    ;
  if (s1 != evr1 && *s1 == ':')
    {
      if (epoch)
	{
	  r = vercmp(evr1, s1, epoch, epoch + strlen(epoch));
	  if (r)
	    return r;
	}
      evr1 = s1 + 1;
    }
  else if (epoch)
    {
      while (*epoch == '0')
	epoch++;
      if (*epoch)
	return -1;
    }
  for (s1 = evr1, r1 = 0; *s1; s1++)
    if (*s1 == '-')
      r1 = s1;
  if (version)
    {
      r = vercmp(evr1, r1 ? r1 : s1, version, version + strlen(version));
      if (r)
	return r;
    }
  if (release)
    {
      if (!r1)
	return -1;
      r = vercmp(r1 + 1, s1, release, release + strlen(release));
      if (r)
	return r;
    }
  return 0;
}
Exemplo n.º 4
0
Arquivo: sort.c Projeto: lyuts/vifm
/* Compares file names containing numbers correctly. */
TSTATIC int
strnumcmp(const char s[], const char t[])
{
#if !defined(HAVE_STRVERSCMP_FUNC) || !HAVE_STRVERSCMP_FUNC
	return vercmp(s, t);
#else
	const char *new_s = skip_leading_zeros(s);
	const char *new_t = skip_leading_zeros(t);
	return strverscmp(new_s, new_t);
#endif
}
Exemplo n.º 5
0
char * il_piu_aggiornato (char *pacchetto, struct db *p) {
  char _versione[255] = "";
  static char _collezione[255] = "";
  while (p != NULL) {
    if (strcmp (pacchetto, p->nome) == 0) {
      if (strcmp (_versione, "") == 0) {
	strcpy (_versione, p->versione);
	strcpy (_collezione, p->collezione);
      }	else {
	if (vercmp (_versione, p->versione)) {
	  strcpy (_versione, p->versione);
	  strcpy (_collezione, p->collezione);
	}
      }
    }
    p = p->prossimo;
  }
  return ((char *) _collezione);
}
Exemplo n.º 6
0
struct db *confronta (struct db *pacchetti_db, struct db *ports_db, int tipo, 
		      int opzioni, int stampa) {
  struct db *p = NULL;
  struct db *c = NULL;
  if (stampa)
    printf ("Name                   Installed Version  Repository    Port Version \n");
  while (pacchetti_db != NULL) {
    p = ports_db;
    while (p != NULL) {
      if (strcmp (p->nome, pacchetti_db->nome) == 0) {
	int test;
	int skip = 0;
	if (tipo == DIFFERENZE) {
	  test = strcmp (pacchetti_db->versione, p->versione);
	} else {
	  test = vercmp (pacchetti_db->versione, p->versione);
	}
	if ((pacchetti_db->collezione[0] == 'R') && (opzioni != NO_REPO
						     && opzioni != NO_FAVORITE)) {
	  if (strcmp (mid (pacchetti_db->collezione, 2, FINE), p->collezione) != 0)
	    skip = 1;
	}
	if ((pacchetti_db->collezione[0] == 'V') && (opzioni != NO_VERSION
						     && opzioni != NO_FAVORITE)) {
	  if (strcmp (mid (pacchetti_db->collezione, 2, FINE),
		      pacchetti_db->versione) == 0)
	    skip = 1;
	}
	if (test != 0 && skip != 1) {
	  c = inserisci_elemento_ordinato (pacchetti_db->nome, p->versione, p->collezione,
					   c);
	  if (stampa)
	    print_formattato(pacchetti_db->nome, pacchetti_db->versione, p->collezione,
			     p->versione);
	}
      }
      p = p->prossimo;
    }
    pacchetti_db = pacchetti_db->prossimo;
  }
  return (c);
}
Exemplo n.º 7
0
void event_action_init(void) {
	logprintf(LOG_STACK, "%s(...)", __FUNCTION__);

	#include "action_init.h"
	void *handle = NULL;
	void (*init)(void);
	void (*compatibility)(struct module_t *module);
	char path[PATH_MAX];
	struct module_t module;
	char pilight_version[strlen(PILIGHT_VERSION)+1];
	char pilight_commit[3];
	char *action_root = NULL;
	int check1 = 0, check2 = 0, valid = 1, action_root_free = 0;
	strcpy(pilight_version, PILIGHT_VERSION);

	struct dirent *file = NULL;
	DIR *d = NULL;
	struct stat s;

	memset(pilight_commit, '\0', 3);

	if(settings_find_string("action-root", &action_root) != 0) {
		/* If no action root was set, use the default action root */
		if(!(action_root = MALLOC(strlen(ACTION_ROOT)+1))) {
			logprintf(LOG_ERR, "out of memory");
			exit(EXIT_FAILURE);
		}
		strcpy(action_root, ACTION_ROOT);
		action_root_free = 1;
	}
	size_t len = strlen(action_root);
	if(action_root[len-1] != '/') {
		strcat(action_root, "/");
	}

	if((d = opendir(action_root))) {
		while((file = readdir(d)) != NULL) {
			memset(path, '\0', PATH_MAX);
			sprintf(path, "%s%s", action_root, file->d_name);		
			if(stat(path, &s) == 0) {
				/* Check if file */
				if(S_ISREG(s.st_mode)) {
					if(strstr(file->d_name, ".so") != NULL) {
						valid = 1;

						if((handle = dso_load(path)) != NULL) {
							init = dso_function(handle, "init");
							compatibility = dso_function(handle, "compatibility");
							if(init && compatibility) {
								compatibility(&module);
								if(module.name != NULL && module.version != NULL && module.reqversion != NULL) {
									char ver[strlen(module.reqversion)+1];
									strcpy(ver, module.reqversion);

									if((check1 = vercmp(ver, pilight_version)) > 0) {
										valid = 0;
									}

									if(check1 == 0 && module.reqcommit != NULL) {
										char com[strlen(module.reqcommit)+1];
										strcpy(com, module.reqcommit);
										sscanf(HASH, "v%*[0-9].%*[0-9]-%[0-9]-%*[0-9a-zA-Z\n\r]", pilight_commit);

										if(strlen(pilight_commit) > 0 && (check2 = vercmp(com, pilight_commit)) > 0) {
											valid = 0;
										}
									}
									if(valid == 1) {
										char tmp[strlen(module.name)+1];
										strcpy(tmp, module.name);
										event_action_remove(tmp);
										init();
										logprintf(LOG_DEBUG, "loaded event action %s v%s", file->d_name, module.version);
									} else {
										if(module.reqcommit != NULL) {
											logprintf(LOG_ERR, "event action %s requires at least pilight v%s (commit %s)", file->d_name, module.reqversion, module.reqcommit);
										} else {
											logprintf(LOG_ERR, "event action %s requires at least pilight v%s", file->d_name, module.reqversion);
										}
									}
								} else {
									logprintf(LOG_ERR, "invalid module %s", file->d_name);
								}
							}
						}
					}
				}
			}
		}
		closedir(d);
	}
	if(action_root_free) {
		FREE(action_root);
	}
}
Exemplo n.º 8
0
/* edition (e:v-r) compare */
int
pool_evrcmp_str(const Pool *pool, const char *evr1, const char *evr2, int mode)
{
  int r;
  const char *s1, *s2;
  const char *r1, *r2;

  if (evr1 == evr2)
    return 0;

#if 0
  POOL_DEBUG(DEBUG_EVRCMP, "evrcmp %s %s mode=%d\n", evr1, evr2, mode);
#endif
  for (s1 = evr1; *s1 >= '0' && *s1 <= '9'; s1++)
    ;
  for (s2 = evr2; *s2 >= '0' && *s2 <= '9'; s2++)
    ;
  if (mode == EVRCMP_MATCH && (*evr1 == ':' || *evr2 == ':'))
    {
      /* empty epoch, skip epoch check */
      if (*s1 == ':')
	evr1 = s1 + 1;
      if (*s2 == ':')
	evr2 = s2 + 1;
      s1 = evr1;
      s2 = evr2;
    }
  if (s1 == evr1 || *s1 != ':')
    s1 = 0;
  if (s2 == evr2 || *s2 != ':')
    s2 = 0;
  if (s1 && s2)
    {
      r = vercmp(evr1, s1, evr2, s2);
      if (r)
	return r;
      evr1 = s1 + 1;
      evr2 = s2 + 1;
    }
  else if (s1)
    {
      if (!pool->promoteepoch)
	{
	  while (*evr1 == '0')
	    evr1++;
	  if (*evr1 != ':')
	    return 1;
	}
      evr1 = s1 + 1;
    }
  else if (s2)
    {
      while (*evr2 == '0')
	evr2++;
      if (*evr2 != ':')
	return -1;
      evr2 = s2 + 1;
    }
  for (s1 = evr1, r1 = 0; *s1; s1++)
    if (*s1 == '-')
      r1 = s1;
  for (s2 = evr2, r2 = 0; *s2; s2++)
    if (*s2 == '-')
      r2 = s2;

  r = 0;
  if (mode != EVRCMP_MATCH || (evr1 != (r1 ? r1 : s1) && evr2 != (r2 ? r2 : s2)))
    r = vercmp(evr1, r1 ? r1 : s1, evr2, r2 ? r2 : s2);
  if (r)
    return r;

  if (mode == EVRCMP_COMPARE)
    {
      if (!r1 && r2)
	return -1;
      if (r1 && !r2)
	return 1;
    }
  if (mode == EVRCMP_COMPARE_EVONLY)
    return 0;
  if (r1 && r2)
    {
      if (s1 != ++r1 && s2 != ++r2)
        r = vercmp(r1, s1, r2, s2);
    }
  return r;
}