version 1.12, 2003/07/21 14:32:21 |
version 1.13, 2003/07/22 17:18:49 |
|
|
*/ |
*/ |
|
|
#ifndef lint |
#ifndef lint |
static char rcsid[] = "$OpenBSD$"; |
static const char rcsid[] = "$OpenBSD$"; |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
|
#include <ctype.h> |
|
#include <libgen.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <ctype.h> |
|
#include <libgen.h> |
|
#include <sys/types.h> |
|
#include "backupfile.h" |
#include "backupfile.h" |
#include "config.h" |
|
|
|
|
/* |
|
* DIRHEADER: This definition indicates which directory library header to |
|
* use. |
|
*/ |
|
#define DIRENT |
|
|
#ifdef DIRENT |
#ifdef DIRENT |
#include <dirent.h> |
#include <dirent.h> |
#ifdef direct |
#ifdef direct |
|
|
char *simple_backup_suffix = "~"; |
char *simple_backup_suffix = "~"; |
|
|
static char *concat(char *, char *); |
static char *concat(char *, char *); |
char *find_backup_file_name(char *); |
|
static char *make_version_name(char *, int); |
static char *make_version_name(char *, int); |
static int max_backup_version(char *, char *); |
static int max_backup_version(char *, char *); |
static int version_number(char *, char *, int); |
static int version_number(char *, char *, int); |
|
|
return concat(file, simple_backup_suffix); |
return concat(file, simple_backup_suffix); |
base_versions = concat(basename(file), ".~"); |
base_versions = concat(basename(file), ".~"); |
if (base_versions == 0) |
if (base_versions == 0) |
return 0; |
return NULL; |
dir = dirname(file); |
dir = dirname(file); |
if (dir == 0) { |
if (dir == 0) { |
free(base_versions); |
free(base_versions); |
return 0; |
return NULL; |
} |
} |
highest_backup = max_backup_version(base_versions, dir); |
highest_backup = max_backup_version(base_versions, dir); |
free(base_versions); |
free(base_versions); |
|
|
char *backup_name; |
char *backup_name; |
|
|
if (asprintf(&backup_name, "%s.~%d~", file, version) == -1) |
if (asprintf(&backup_name, "%s.~%d~", file, version) == -1) |
return 0; |
return NULL; |
return backup_name; |
return backup_name; |
} |
} |
|
|
|
|
char *newstr; |
char *newstr; |
|
|
if (asprintf(&newstr, "%s%s", str1, str2) == -1) |
if (asprintf(&newstr, "%s%s", str1, str2) == -1) |
return 0; |
return NULL; |
return newstr; |
return newstr; |
} |
} |
|
|
|
|
* does not match any element or -2 if it is ambiguous (is a prefix of more |
* does not match any element or -2 if it is ambiguous (is a prefix of more |
* than one element). |
* than one element). |
*/ |
*/ |
int |
static int |
argmatch(char *arg, char **optlist) |
argmatch(char *arg, char **optlist) |
{ |
{ |
int i; /* Temporary index in OPTLIST. */ |
int i; /* Temporary index in OPTLIST. */ |
|
|
* that was being matched. VALUE is the invalid value that was given. PROBLEM |
* that was being matched. VALUE is the invalid value that was given. PROBLEM |
* is the return value from argmatch. |
* is the return value from argmatch. |
*/ |
*/ |
void |
static void |
invalid_arg(char *kind, char *value, int problem) |
invalid_arg(char *kind, char *value, int problem) |
{ |
{ |
fprintf(stderr, "patch: "); |
fprintf(stderr, "patch: "); |