/* * common.c * * Copyright (C) 2012 - 2019 James Booth * * This file is part of Profanity. * * Profanity 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 3 of the License, or * (at your option) any later version. * * Profanity 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 Profanity. If not, see . * * In addition, as a special exception, the copyright holders give permission to * link the code of portions of this program with the OpenSSL library under * certain conditions as described in each individual source file, and * distribute linked combinations including the two. * * You must obey the GNU General Public License in all respects for all of the * code used other than OpenSSL. If you modify file(s) with this exception, you * may extend this exception to your version of the file(s), but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. If you delete this exception statement from all * source files in the program, then also delete it here. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_NCURSESW_NCURSES_H #include #elif HAVE_NCURSES_H #include #endif #include "log.h" #include "common.h" struct curl_data_t { char *buffer; size_t size; }; static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data); gboolean create_dir(char *name) { struct stat sb; if (stat(name, &sb) != 0) { if (errno != ENOENT || mkdir(name, S_IRWXU) != 0) { return FALSE; } } else { if ((sb.st_mode & S_IFDIR) != S_IFDIR) { log_debug("create_dir: %s exists and is not a directory!", name); return FALSE; } } return TRUE; } gboolean mkdir_recursive(const char *dir) { int i; gboolean result = TRUE; for (i = 1; i <= strlen(dir); i++) { if (dir[i] == '/' || dir[i] == '\0') { gchar *next_dir = g_strndup(dir, i); result = create_dir(next_dir); g_free(next_dir); if (!result) { break; } } } return result; } gboolean copy_file(const char *const sourcepath, const char *const targetpath, const gboolean overwrite_existing) { GFile *source = g_file_new_for_path(sourcepath); GFile *dest = g_file_new_for_path(targetpath); GError *error = NULL; GFileCopyFlags flags = overwrite_existing ? G_FILE_COPY_OVERWRITE : G_FILE_COPY_NONE; gboolean success = g_file_copy (source, dest, flags, NULL, NULL, NULL, &error); g_object_unref(source); g_object_unref(dest); return success; } char* str_replace(const char *string, const char *substr, const char *replacement) { char *tok = NULL; char *newstr = NULL; char *head = NULL; if (string == NULL) return NULL; if ( substr == NULL || replacement == NULL || (strcmp(substr, "") == 0)) return strdup (string); newstr = strdup (string); head = newstr; while ( (tok = strstr ( head, substr ))) { char *oldstr = newstr; newstr = malloc ( strlen ( oldstr ) - strlen ( substr ) + strlen ( replacement ) + 1 ); if ( newstr == NULL ) { free (oldstr); return NULL; } memcpy ( newstr, oldstr, tok - oldstr ); memcpy ( newstr + (tok - oldstr), replacement, strlen ( replacement ) ); memcpy ( newstr + (tok - oldstr) + strlen( replacement ), tok + strlen ( substr ), strlen ( oldstr ) - strlen ( substr ) - ( tok - oldstr ) ); memset ( newstr + strlen ( oldstr ) - strlen ( substr ) + strlen ( replacement ) , 0, 1 ); head = newstr + (tok - oldstr) + strlen( replacement ); free (oldstr); } return newstr; } int str_contains(const char str[], int size, char ch) { int i; for (i = 0; i < size; i++) { if (str[i] == ch) return 1; } return 0; } gboolean strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg) { char *ptr; int val; errno = 0; val = (int)strtol(str, &ptr, 0); if (errno != 0 || *str == '\0' || *ptr != '\0') { GString *err_str = g_string_new(""); g_string_printf(err_str, "Could not convert \"%s\" to a number.", str); *err_msg = err_str->str; g_s
;;; init-project.el --- Project (and Perspective) Configuration File -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:

(use-package project
  :ensure nil
  :config
  (defun project-recentf ()
    "Show a list of recently visited files in a project."
    (interactive)
    (if (boundp 'recentf-list)
        (let* ((project-root (expand-file-name (project-root (project-current))))
               (project-recentf-files (mapcar
                                       (lambda (f) (file-relative-name f project-root))