Example #1
0
/**
 * @brief: Automatically loads all of the notes.
 */
void
autoload(void)
{				/* FIXME: Rewrite using dirents  */
	DIR            *dir;
	struct dirent  *p;
	char           *target = malloc(PATH_MAX);
	char           *targetf = malloc(PATH_MAX);
	struct stat     buf;

	sprintf(target, "%s/.e/apps/enotes/notes", getenv("HOME"));
	if ((dir = opendir(target)) != NULL) {

		while ((p = readdir(dir)) != NULL) {
			sprintf(targetf, "%s/%s", target, p->d_name);
			stat(targetf, &buf);
			if (S_ISREG(buf.st_mode)) {
				note_load(targetf);
			}
		}
		closedir(dir);
	}

	free(targetf);
	free(target);
}
Example #2
0
/* note_new_from_file */
Note * note_new_from_file(char const * filename)
{
	Note * note;

	if((note = note_new()) == NULL)
		return NULL;
	if(note_set_filename(note, filename) != 0
			|| note_load(note) != 0)
	{
		note_delete(note);
		return NULL;
	}
	return note;
}