Blame examples/common.h

Packit Service 20376f
/*
Packit Service 20376f
 * Utilities library for libgit2 examples
Packit Service 20376f
 *
Packit Service 20376f
 * Written by the libgit2 contributors
Packit Service 20376f
 *
Packit Service 20376f
 * To the extent possible under law, the author(s) have dedicated all copyright
Packit Service 20376f
 * and related and neighboring rights to this software to the public domain
Packit Service 20376f
 * worldwide. This software is distributed without any warranty.
Packit Service 20376f
 *
Packit Service 20376f
 * You should have received a copy of the CC0 Public Domain Dedication along
Packit Service 20376f
 * with this software. If not, see
Packit Service 20376f
 * <http://creativecommons.org/publicdomain/zero/1.0/>.
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
#include <stdio.h>
Packit Service 20376f
#include <string.h>
Packit Service 20376f
#include <stdlib.h>
Packit Service 20376f
#include <git2.h>
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check libgit2 error code, printing error to stderr on failure and
Packit Service 20376f
 * exiting the program.
Packit Service 20376f
 */
Packit Service 20376f
extern void check_lg2(int error, const char *message, const char *extra);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Exit the program, printing error to stderr
Packit Service 20376f
 */
Packit Service 20376f
extern void fatal(const char *message, const char *extra);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if a string has the given prefix.  Returns 0 if not prefixed
Packit Service 20376f
 * or the length of the prefix if it is.
Packit Service 20376f
 */
Packit Service 20376f
extern size_t is_prefixed(const char *str, const char *pfx);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Match an integer string, returning 1 if matched, 0 if not.
Packit Service 20376f
 */
Packit Service 20376f
extern int is_integer(int *out, const char *str, int allow_negative);
Packit Service 20376f
Packit Service 20376f
struct args_info {
Packit Service 20376f
	int    argc;
Packit Service 20376f
	char **argv;
Packit Service 20376f
	int    pos;
Packit Service 20376f
};
Packit Service 20376f
#define ARGS_INFO_INIT { argc, argv, 0 }
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check current `args` entry against `opt` string.  If it matches
Packit Service 20376f
 * exactly, take the next arg as a string; if it matches as a prefix with
Packit Service 20376f
 * an equal sign, take the remainder as a string; if value not supplied, 
Packit Service 20376f
 * default value `def` will be given. otherwise return 0.
Packit Service 20376f
 */
Packit Service 20376f
extern int optional_str_arg(
Packit Service 20376f
	const char **out, struct args_info *args, const char *opt, const char *def);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check current `args` entry against `opt` string.  If it matches
Packit Service 20376f
 * exactly, take the next arg as a string; if it matches as a prefix with
Packit Service 20376f
 * an equal sign, take the remainder as a string; otherwise return 0.
Packit Service 20376f
 */
Packit Service 20376f
extern int match_str_arg(
Packit Service 20376f
	const char **out, struct args_info *args, const char *opt);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check current `args` entry against `opt` string parsing as uint16.  If
Packit Service 20376f
 * `opt` matches exactly, take the next arg as a uint16_t value; if `opt`
Packit Service 20376f
 * is a prefix (equal sign optional), take the remainder of the arg as a
Packit Service 20376f
 * uint16_t value; otherwise return 0.
Packit Service 20376f
 */
Packit Service 20376f
extern int match_uint16_arg(
Packit Service 20376f
	uint16_t *out, struct args_info *args, const char *opt);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check current `args` entry against `opt` string parsing as uint32.  If
Packit Service 20376f
 * `opt` matches exactly, take the next arg as a uint16_t value; if `opt`
Packit Service 20376f
 * is a prefix (equal sign optional), take the remainder of the arg as a
Packit Service 20376f
 * uint32_t value; otherwise return 0.
Packit Service 20376f
 */
Packit Service 20376f
extern int match_uint32_arg(
Packit Service 20376f
	uint32_t *out, struct args_info *args, const char *opt);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check current `args` entry against `opt` string parsing as int.  If
Packit Service 20376f
 * `opt` matches exactly, take the next arg as an int value; if it matches
Packit Service 20376f
 * as a prefix (equal sign optional), take the remainder of the arg as a
Packit Service 20376f
 * int value; otherwise return 0.
Packit Service 20376f
 */
Packit Service 20376f
extern int match_int_arg(
Packit Service 20376f
	int *out, struct args_info *args, const char *opt, int allow_negative);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Basic output function for plain text diff output
Packit Service 20376f
 * Pass `FILE*` such as `stdout` or `stderr` as payload (or NULL == `stdout`)
Packit Service 20376f
 */
Packit Service 20376f
extern int diff_output(
Packit Service 20376f
	const git_diff_delta*, const git_diff_hunk*, const git_diff_line*, void*);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Convert a treeish argument to an actual tree; this will call check_lg2
Packit Service 20376f
 * and exit the program if `treeish` cannot be resolved to a tree
Packit Service 20376f
 */
Packit Service 20376f
extern void treeish_to_tree(
Packit Service 20376f
	git_tree **out, git_repository *repo, const char *treeish);