var.con commit Add Pine 4.63 help from Daniel. (1eb446f)
   1/*
   2 * GIT - The information manager from hell
   3 *
   4 * Copyright (C) Eric Biederman, 2005
   5 */
   6#include "cache.h"
   7#include <stdio.h>
   8#include <errno.h>
   9#include <string.h>
  10
  11static const char var_usage[] = "git-var [-l | <variable>]";
  12
  13struct git_var {
  14        const char *name;
  15        char *(*read)(void);
  16};
  17static struct git_var git_vars[] = {
  18        { "GIT_COMMITTER_IDENT", git_committer_info },
  19        { "GIT_AUTHOR_IDENT",   git_author_info },
  20        { "", NULL },
  21};
  22
  23static void list_vars(void)
  24{
  25        struct git_var *ptr;
  26        for(ptr = git_vars; ptr->read; ptr++) {
  27                printf("%s=%s\n", ptr->name, ptr->read());
  28        }
  29}
  30
  31static const char *read_var(const char *var)
  32{
  33        struct git_var *ptr;
  34        const char *val;
  35        val = NULL;
  36        for(ptr = git_vars; ptr->read; ptr++) {
  37                if (strcmp(var, ptr->name) == 0) {
  38                        val = ptr->read();
  39                        break;
  40                }
  41        }
  42        return val;
  43}
  44
  45int main(int argc, char **argv)
  46{
  47        const char *val;
  48        if (argc != 2) {
  49                usage(var_usage);
  50        }
  51        setup_ident();
  52        val = NULL;
  53
  54        if (strcmp(argv[1], "-l") == 0) {
  55                list_vars();
  56                return 0;
  57        }
  58        val = read_var(argv[1]);
  59        if (!val)
  60                usage(var_usage);
  61        
  62        printf("%s\n", val);
  63        
  64        return 0;
  65}