1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/*
* sccsname.cc: Part of GNU CSSC.
*
*
* Copyright (C) 1997, Free Software Foundation, Inc.
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*
* CSSC was originally Based on MySC, by Ross Ridge, which was
* placed in the Public Domain.
*
*
* Members of the class sccs_name.
*
*/
#ifdef __GNUC__
#pragma implementation "sccsname.h"
#endif
#include "cssc.h"
#include "sccsname.h"
#include <ctype.h>
#ifdef CONFIG_SCCS_IDS
static const char rcs_id[] = "CSSC $Id: sccsname.cc,v 1.10 2001/09/29 19:39:41 james_youngman Exp $";
#endif
#ifdef CONFIG_MSDOS_FILES
#error The CONFIG_MSDOS_FILES option is no longer supported. See sccsname.cc.
// Please feel free to add the support yourself. Don't forget
// to send the patches to <jay@gnu.org>.
#endif
mystring
base_part(const mystring &name)
{
mystring dirname, basename;
split_filename(name, dirname, basename);
return basename;
}
int
sccs_name::valid_filename(const char *thename)
{
ASSERT(0 != thename);
if (thename && thename[0])
{
mystring base = base_part(mystring(thename));
const int valid = (base.at(0) == 's' && base.at(1) == '.');
#if 0
fprintf(stderr, "valid_filename returning %d\n", valid);
#endif
return valid;
}
else
{
// empty filename; not valid.
return 0;
}
}
void
sccs_name::create()
{
#if 0
fprintf(stderr, "sccs_name::create(): sname='%s'\n", sname.c_str());
#endif
// derive all other names from "name",
// when they're asked for.
mystring dirname, basename;
split_filename(sname, dirname, basename);
#if 0
fprintf(stderr, "sccs_name::create(): dirname='%s', basename='%s'\n",
dirname.c_str(), basename.c_str());
#endif
name_front = dirname;
if (basename.length() >= 2)
{
const char *s = basename.c_str();
// name_rear does not contain the "s"
// of the "s." but does contain the dot itself.
name_rear = mystring(s+1);
// The gname does not include the directory part,
// or the leading "s.".
gname = mystring(s+2);
}
else
{
name_rear = basename;
gname = mystring("");
}
}
// I don't think we EVER need this function.
// sccs_name::sccs_name(sccs_name const &from) : lock_cnt(from.lock_cnt)
// {
// sname = from.sfile();
// create();
// }
sccs_name &
sccs_name::operator =(const mystring &newname)
{
ASSERT(newname.length() != 0);
#if 0
fprintf(stderr, "sccs_name::operator=(const mystring&): newname='%s'\n",
newname.c_str());
#endif
sname = newname;
create();
return *this;
}
mystring sccs_name::
sub_file(char insertme) const
{
char prefix[2];
prefix[0] = insertme;
prefix[1] = 0;
mystring ret = name_front + mystring(prefix) + name_rear;
#if 0
fprintf(stderr,
"sccs_name::sub_file('%c') returning \"%s\".\n",
insertme, ret.c_str());
#endif
return ret;
}
#ifdef CONFIG_FILE_NAME_GUESSING
void
sccs_name::make_valid()
{
ASSERT(sname.length() != 0);
ASSERT(!valid_filename(sname.c_str()));
#if 0
fprintf(stderr, "Making filename '%s' valid...\n",
sname.c_str());
#endif
mystring dirpart, basepart;
split_filename(sname, dirpart, basepart);
// try dir/s.foo
const mystring s_dot_foo = mystring("s.") + basepart;
sname = dirpart + s_dot_foo;
if (!is_readable(sname.c_str()))
{
// try dir/SCCS/s.foo
const mystring tmp = dirpart + mystring("SCCS/") + s_dot_foo;
if (is_readable(tmp.c_str()))
sname = tmp;
}
create();
}
#endif /* CONFIG_FILE_NAME_GUESSING */
/* Local variables: */
/* mode: c++ */
/* End: */
|