示例#1
0
RecentFiles::RecentFiles()
  : m_files(16)
  , m_paths(16)
{
  char buf[512];

  for (int c=m_files.limit()-1; c>=0; c--) {
    sprintf(buf, "Filename%02d", c);

    const char* filename = get_config_string("RecentFiles", buf, NULL);
    if (filename && *filename && base::is_file(filename)) {
      std::string fn = normalizePath(filename);
      m_files.addItem(fn, compare_path(fn));
    }
  }

  for (int c=m_paths.limit()-1; c>=0; c--) {
    sprintf(buf, "Path%02d", c);

    const char* path = get_config_string("RecentPaths", buf, NULL);
    if (path && *path) {
      std::string p = normalizePath(path);
      m_paths.addItem(p, compare_path(p));
    }
  }
}
示例#2
0
void RecentFiles::removeRecentFile(const char* filename)
{
  std::string fn = normalizePath(filename);
  m_files.removeItem(fn, compare_path(fn));

  std::string path = base::get_file_path(filename);
  m_paths.removeItem(path, compare_path(path));

  Changed();
}
示例#3
0
文件: utilities.c 项目: malaise/c
/* Get short label (trunk, branches/name or tags/name) */
extern void get_node_path (char *string) {
    int nb;
    int count= 0;
    int i;
    label_kind lab;

    /* Nb of / to pass before cutting */
    lab = compare_path (string);
    switch (lab) {
    case TRUNK:
        nb = 2;
        break;
    case TAG:
    case BRANCH:
        nb = 3;
        break;
    default:
        return;
    }

    /* Cut at nb '/'s */
    for (i = 0; i < (int) strlen (string); i++) {
        if (string[i] == '/') {
            count++;
            if (count == nb) {
                string[i] = '\0';
            }
        }
    }
}
示例#4
0
文件: sort.c 项目: kimiwangjm/pbspro
/**
 * @brief
 *		cmp_fair_share - compare on fair share percentage only.
 *			 This is for strict priority.
 *
 * @param[in]	j1	-	resource_resv 1
 * @param[in]	j2	-	resource_resv 2
 *
 * @return	int
 * @retval	1	: if j1 < j2
 * @retval	0 	: if j1 == j2
 * @retval	-1  : if j1 > j2
 */
int
cmp_fairshare(const void *j1, const void *j2)
{
	resource_resv *r1 = *(resource_resv**)j1;
	resource_resv *r2 = *(resource_resv**)j2;
	if (r1->job != NULL && r1->job->ginfo != NULL &&
		r2->job != NULL && r2->job->ginfo != NULL)
		return compare_path(r1->job->ginfo->gpath , r2->job->ginfo->gpath);

	return 0;
}
示例#5
0
文件: render.c 项目: FSX/zathura-cb
static GdkPixbuf*
load_pixbuf_from_archive(const char* archive, const char* file)
{
  if (archive == NULL || file == NULL) {
    return NULL;
  }

  struct archive* a = archive_read_new();
  if (a == NULL) {
    return NULL;
  }

  archive_read_support_filter_all(a);
  archive_read_support_format_all(a);
  int r = archive_read_open_filename(a, archive, LIBARCHIVE_BUFFER_SIZE);
  if (r != ARCHIVE_OK) {
    return NULL;
  }

  struct archive_entry* entry = NULL;
  while ((r = archive_read_next_header(a, &entry)) != ARCHIVE_EOF) {
    if (r < ARCHIVE_WARN) {
      archive_read_close(a);
      archive_read_free(a);
      return NULL;
    }

    const char* path = archive_entry_pathname(entry);
    if (compare_path(path, file) != 0) {
      continue;
    }

    GInputStream* is = g_memory_input_stream_new();
    if (is == NULL) {
      archive_read_close(a);
      archive_read_free(a);
      return NULL;
    }
    GMemoryInputStream* mis = G_MEMORY_INPUT_STREAM(is);

    size_t size = 0;
    const void* buf = NULL;
    off_t offset = 0;
    while ((r = archive_read_data_block(a, &buf, &size, &offset)) != ARCHIVE_EOF) {
      if (r < ARCHIVE_WARN) {
        archive_read_close(a);
        archive_read_free(a);
        g_object_unref(mis);
        return NULL;
      }

      if (size == 0) {
        continue;
      }

      void* tmp = g_malloc0(size);
      if (tmp == NULL) {
        archive_read_close(a);
        archive_read_free(a);
        g_object_unref(mis);
        return NULL;
      }

      memcpy(tmp, buf, size);
      g_memory_input_stream_add_data(mis, tmp, size, g_free);
    }

    GdkPixbuf* pixbuf = gdk_pixbuf_new_from_stream(is, NULL, NULL);
    if (pixbuf == NULL) {
      archive_read_close(a);
      archive_read_free(a);
      g_object_unref(mis);
      return NULL;
    }

    archive_read_close(a);
    archive_read_free(a);
    g_object_unref(mis);
    return pixbuf;
  }

  archive_read_close(a);
  archive_read_free(a);
  return NULL;
}
示例#6
0
文件: pbsfs.c 项目: bayucan/pbspro
/**
 * @brief
 * 		The entry point of pbsfs
 *
 * @return	int
 * @retval	0	: success
 * @retval	1	: something is wrong!
 */
int
main(int argc, char *argv[])
{
	char path_buf[256] = {0};
	char sched_name[PBS_MAXSCHEDNAME + 1] = "default";
	group_info *ginfo;
	group_info *ginfo2;
	int c;
	int flags = FS_PRINT;
	int flag1 = 0;
	double val;
	char *endp;
	char *testp;

	/* the real deal or output version and exit? */
	PRINT_VERSION_AND_EXIT(argc, argv);
	set_msgdaemonname("pbsfs");

#ifdef WIN32
	if (winsock_init()) {
		return 1;
	}
#endif


	if (pbs_loadconf(0) <= 0)
		exit(1);

	while ((c = getopt(argc, argv, "sgptdceI:-:")) != -1)
		switch (c) {
			case 'g':
				flags = FS_GET;
				break;
			case 's':
				flags = FS_SET | FS_WRITE_FILE;
				break;
			case 'p':
				flags = FS_PRINT;
				break;
			case 't':
				flags = FS_PRINT_TREE;
				break;
			case 'd':
				flags = FS_DECAY | FS_WRITE_FILE;
				break;
			case 'c':
				flags = FS_COMP;
				break;
			case 'e':
				flags = FS_TRIM_TREE | FS_WRITE_FILE;
				break;
			case 'I':
				snprintf(sched_name, sizeof(sched_name), "%s", optarg);
				break;
			case '-':
				flag1 = 1;
				break;
		}

	if (flag1 == 1) {
		fprintf(stderr, "Usage: pbsfs --version\n");
		exit(1);
	}
	if ((flags & (FS_PRINT | FS_PRINT_TREE)) && (argc - optind) != 0) {
		fprintf(stderr, "Usage: pbsfs -[ptdgcs] [-I sched_name]\n");
		exit(1);
	}
	else if ((flags & FS_GET)  && (argc - optind) != 1) {
		fprintf(stderr, "Usage: pbsfs [-I sched_name] -g <fairshare_entity>\n");
		exit(1);
	}
	else if ((flags & FS_SET) && (argc - optind) != 2) {
		fprintf(stderr, "Usage: pbsfs [-I sched_name] -s <fairshare_entity> <usage>\n");
		exit(1);
	}
	else if ((flags & FS_COMP) && (argc - optind) != 2) {
		fprintf(stderr, "Usage: pbsfs [-I sched_name] -c <entity1> <entity2>\n");
		exit(1);
	}

	if (strcmp(sched_name, "default") != 0) {
		int pbs_sd;
		struct batch_status *bs;
		struct batch_status *cur_bs;
		pbs_sd = pbs_connect(NULL);
		if (pbs_sd < 0) {
			fprintf(stderr, "Can't connect to the server\n");
			exit(1);
		}
		bs = pbs_statsched(pbs_sd, NULL, NULL);

		for (cur_bs = bs; cur_bs != NULL; cur_bs = cur_bs->next) {
			if (strcmp(cur_bs->name, sched_name) == 0) {
				struct attrl *cur_attrl;
				for (cur_attrl = cur_bs->attribs; cur_attrl != NULL; cur_attrl = cur_attrl->next) {
					if (strcmp(cur_attrl->name, ATTR_sched_priv) == 0) {
						strncpy(path_buf, cur_attrl->value, sizeof(path_buf));
						path_buf[sizeof(path_buf) - 1] = '\0';
						break;
					}
				}
				if (cur_attrl == NULL) {
					fprintf(stderr, "Scheduler %s does not have its sched_priv set\n", sched_name);
					exit(1);
				}
				break;
			}
		}
		if (cur_bs == NULL) {
			fprintf(stderr, "Scheduler %s does not exist\n", sched_name);
			exit(1);
		}
		pbs_disconnect(pbs_sd);

	} else
		snprintf(path_buf, sizeof(path_buf), "%s/sched_priv/", pbs_conf.pbs_home_path);

	if (chdir(path_buf) == -1) {
		perror("Unable to access fairshare data");
		exit(1);
	}
	init_config();
	parse_config(CONFIG_FILE);
	if ((conf.fairshare = preload_tree()) == NULL) {
		fprintf(stderr, "Error in preloading fairshare information\n");
		return 1;
	}
	if (parse_group(RESGROUP_FILE, conf.fairshare->root) == 0)
		return 1;

	if (flags & FS_TRIM_TREE)
		read_usage(USAGE_FILE, FS_TRIM, conf.fairshare);
	else
		read_usage(USAGE_FILE, 0, conf.fairshare);

	calc_fair_share_perc(conf.fairshare->root->child, UNSPECIFIED);
	calc_usage_factor(conf.fairshare);

	if (flags & FS_PRINT_TREE)
		print_fairshare(conf.fairshare->root, 0);
	else if (flags & FS_PRINT  ) {
		printf("Fairshare usage units are in: %s\n", conf.fairshare_res);
		print_fairshare(conf.fairshare->root, -1);
	}
	else if (flags & FS_DECAY)
		decay_fairshare_tree(conf.fairshare->root);
	else if (flags & (FS_GET | FS_SET | FS_COMP)) {
		ginfo = find_group_info(argv[optind], conf.fairshare->root);

		if (ginfo == NULL) {
			fprintf(stderr, "Fairshare Entity %s does not exist.\n", argv[optind]);
			return 1;
		}
		if (flags & FS_COMP) {
			ginfo2 = find_group_info(argv[optind + 1], conf.fairshare->root);

			if (ginfo2 == NULL) {
				fprintf(stderr, "Fairshare Entity %s does not exist.\n", argv[optind + 1]);
				return 1;
			}
			switch (compare_path(ginfo->gpath, ginfo2->gpath)) {
				case -1:
					printf("%s\n", ginfo->name);
					break;

				case 0:
					printf("%s == %s\n", ginfo->name, ginfo2->name);
					break;

				case 1:
					printf("%s\n", ginfo2->name);
			}
		}
		else if (flags & FS_GET)
			print_fairshare_entity(ginfo);
		else {
			testp = argv[optind + 1];
			val = strtod(testp, &endp);

			if (*endp == '\0')
				ginfo->usage = val;
		}
	}

	if (flags & FS_WRITE_FILE) {
		FILE *fp;
		/* make backup of database file */
		remove(USAGE_FILE ".bak");
		if (rename(USAGE_FILE, USAGE_FILE ".bak") < 0)
			perror("Could not backup usage database.");
		write_usage(USAGE_FILE, conf.fairshare);
		if ((fp = fopen(USAGE_TOUCH, "w")) != NULL)
			fclose(fp);
	}

	return 0;
}
示例#7
0
int
do_one_case (struct db_conn *conn, const struct test_data *data,
	     int load_extension)
{
    sqlite3 *db_handle = NULL;
    int ret;
    char *err_msg = NULL;
    int i;
    char **results;
    int rows;
    int columns;
    int read_only = 0;
    int empty_db = 0;
    int not_memory_db = 0;

    fprintf (stderr, "Test case: %s\n", data->test_case_name);
    if (strncmp
	("_RO", data->database_name + strlen (data->database_name) - 3,
	 strlen ("_RO")) == 0)
	read_only = 1;
    if (strcmp ("NEW:memory:", data->database_name) == 0)
	empty_db = 1;
    if (conn->db_handle != NULL)
      {
	  if (empty_db)
	      ;
	  else if (compare_path (conn->db_path, data->database_name, read_only))
	    {
		if (conn->read_only == read_only)
		  {
		      db_handle = conn->db_handle;
		      goto skip_init;
		  }
	    }
	  close_connection (conn);
      }

    if (conn->cache == NULL && !load_extension)
	spatialite_init (0);

    /* This hack checks if the name ends with _RO */
    if (strncmp
	("_RO", data->database_name + strlen (data->database_name) - 3,
	 strlen ("_RO")) == 0)
      {
	  fprintf (stderr, "opening read_only\n");
	  read_only = 1;
	  ret =
	      sqlite3_open_v2 (data->database_name, &db_handle,
			       SQLITE_OPEN_READONLY, NULL);
      }
    else if (empty_db)
      {
	  ret =
	      sqlite3_open_v2 (":memory:", &db_handle,
			       SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
			       NULL);
      }
    else
      {
	  if (strcmp (data->database_name, ":memory:") != 0)
	      not_memory_db = 1;
	  ret =
	      sqlite3_open_v2 (data->database_name, &db_handle,
			       SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
			       NULL);
      }
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open %s db: %s\n", data->database_name,
		   sqlite3_errmsg (db_handle));
	  sqlite3_close (db_handle);
	  db_handle = NULL;
	  return -1;
      }

    if (conn->cache != NULL)
	spatialite_init_ex (db_handle, conn->cache, 0);
    if (load_extension)
      {
	  if (!load_dyn_extension (db_handle))
	    {
		sqlite3_close (db_handle);
		db_handle = NULL;
		return -3;
	    }
      }
    save_connection (conn, data->database_name, db_handle, read_only, empty_db);

    if (read_only || not_memory_db)
	goto skip_init;
    ret =
	sqlite3_exec (db_handle, "SELECT InitSpatialMetadata(1)", NULL, NULL,
		      &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -2;
      }
  skip_init:

    ret =
	sqlite3_get_table (db_handle, data->sql_statement, &results, &rows,
			   &columns, &err_msg);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "Error: %s\n", err_msg);
	  sqlite3_free (err_msg);
	  return -10;
      }
    if ((rows != data->expected_rows) || (columns != data->expected_columns))
      {
	  fprintf (stderr, "Unexpected error: bad result: %i/%i.\n", rows,
		   columns);
	  return -11;
      }
    for (i = 0; i < (data->expected_rows + 1) * data->expected_columns; ++i)
      {
	  if (results[i] != NULL && data->expected_precision[i] == 0)
	    {
		data->expected_precision[i] = strlen (results[i]);
	    }
	  if (results[i] == NULL)
	    {
		if (strcmp ("(NULL)", data->expected_results[i]) == 0)
		  {
		      /* we expected this */
		      continue;
		  }
		else
		  {
		      fprintf (stderr, "Null value at %i.\n", i);
		      fprintf (stderr, "Expected value was: %s\n",
			       data->expected_results[i]);
		      return -12;
		  }
	    }
	  else if (strlen (results[i]) == 0)
	    {
		fprintf (stderr, "zero length result at %i\n", i);
		fprintf (stderr, "Expected value was    : %s|\n",
			 data->expected_results[i]);
		return -13;
	    }
	  else if (strncmp
		   (results[i], data->expected_results[i],
		    data->expected_precision[i]) != 0)
	    {
		fprintf (stderr, "Unexpected value at %i: %s|\n", i,
			 results[i]);
		fprintf (stderr, "Expected value was   : %s|\n",
			 data->expected_results[i]);
		return -14;
	    }
      }
    sqlite3_free_table (results);

    return 0;
}