Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Self include. */
- #include "globals.h"
- /* Standard includes. */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /* Own includes. */
- #include "defs.h"
- #include "git.h"
- /* Global variables. */
- /* Version description definitions and global variables. */
- /* XXXXXXXXXXXXX is versioned like
- * - MAJOR.MINOR.REVISION if it is in a git tag, or
- * - MAJOR.MINOR.REVISION.COMMIT_HASH if it is in a git clean status (no
- * uncommitted changes pending), or
- * - MAJOR.MINOR.REVISION.COMMIT_HASH(+|-)dev if it is in a git dirty
- * status with uncommitted changes present. */
- /* MAJOR, MINOR and REVISION are taken from defs.h. */
- /* Holds the commit hash, if applicable. */
- char * COMMIT_HASH = 0;
- /* Holds the commit hash, if applicable, including dev status, if
- * applicable. */
- char * COMMIT_HASH_INCLUDING_DEV_STATUS = 0;
- /* Holds all applicable version information. */
- char * VERSION = 0;
- /* Holds all applicable version information, with the program name
- * prepended. */
- char * VERSION_INCLUDING_NAME = 0;
- /* Program name. */
- char * program_name = "XXXXXXXXXXXXX";
- void fill_version()
- {
- char * _git_last_commit, * major, * minor, * revision, * version;
- extern char * COMMIT_HASH, * COMMIT_HASH_INCLUDING_DEV_STATUS, * VERSION,
- * VERSION_INCLUDING_NAME;
- major = malloc(1 + 1);
- minor = malloc(1 + 1);
- revision = malloc(2 + 1);
- sprintf(major, "%d", MAJOR);
- sprintf(minor, "%d", MINOR);
- sprintf(revision, "%d", REVISION);
- if (git_at_a_tag())
- {
- version = malloc(
- strlen(major) + 1 + strlen(minor) + 1 + strlen(revision) + 1);
- strcpy(version, major);
- strcat(version, ".");
- strcat(version, minor);
- strcat(version, ".");
- strcat(version, revision);
- }
- else
- {
- if (git_working_directory_clean())
- {
- _git_last_commit = git_last_commit();
- version = malloc(
- strlen(major) + 1 + strlen(minor) + 1 + strlen(revision) +
- 1 + strlen(_git_last_commit) + 1);
- strcpy(version, major);
- strcat(version, ".");
- strcat(version, minor);
- strcat(version, ".");
- strcat(version, revision);
- strcat(version, ".");
- strcat(version, _git_last_commit);
- COMMIT_HASH_INCLUDING_DEV_STATUS = malloc(
- strlen(_git_last_commit) + 1);
- strcpy(COMMIT_HASH_INCLUDING_DEV_STATUS, _git_last_commit);
- }
- else
- {
- _git_last_commit = git_last_commit();
- version = malloc(
- strlen(major) + 1 + strlen(minor) + 1 + strlen(revision) +
- 1 + strlen(_git_last_commit) + 1 + 1);
- strcpy(version, major);
- strcat(version, ".");
- strcat(version, minor);
- strcat(version, ".");
- strcat(version, revision);
- strcat(version, ".");
- strcat(version, _git_last_commit);
- strcat(version, "+");
- COMMIT_HASH_INCLUDING_DEV_STATUS = malloc(
- strlen(_git_last_commit) + 1 + 1);
- strcpy(COMMIT_HASH_INCLUDING_DEV_STATUS, _git_last_commit);
- strcat(COMMIT_HASH_INCLUDING_DEV_STATUS, "+");
- }
- COMMIT_HASH = _git_last_commit;
- }
- VERSION = version;
- VERSION_INCLUDING_NAME = malloc(
- strlen(program_name) + 1 + strlen(VERSION) + 1);
- strcpy(VERSION_INCLUDING_NAME, program_name);
- strcat(VERSION_INCLUDING_NAME, " ");
- strcat(VERSION_INCLUDING_NAME, VERSION);
- free(major);
- free(minor);
- free(revision);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement