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
|
/*
* pfile.cc: Part of GNU CSSC.
*
* Copyright (C) 1997,1998,1999,2001 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.
*
*
* Common members of the class sccs_pfile.
*
*/
#include "cssc.h"
#include "linebuf.h"
#include "pfile.h"
#include "err_no.h"
#ifdef CONFIG_SCCS_IDS
static const char rcs_id[] = "CSSC $Id: pfile.cc,v 1.16 2001/09/29 19:39:41 james_youngman Exp $";
#endif
NORETURN
sccs_pfile::corrupt(int lineno, const char *msg) const {
p_corrupt_quit("%s: line %d: p-file is corrupt. (%s)",
pname.c_str(), lineno, msg);
}
sccs_pfile::sccs_pfile(sccs_name &n, enum _mode m)
: name(n), mode(m), pos(-1) {
if (!name.valid()) {
ctor_fail(-1, "%s: Not a SCCS file.", name.c_str());
}
pname = name.pfile();
if (mode != READ) {
if (name.lock()) {
ctor_fail(-1,
"%s: SCCS file is locked. Try again later.",
name.c_str());
}
}
FILE *pf = fopen(pname.c_str(), "r");
if (pf == NULL) {
if (errno != ENOENT) {
ctor_fail(-1, "%s: Can't open p-file for reading.",
pname.c_str());
}
} else {
cssc_linebuf linebuf;
int lineno = 0;
while (!linebuf.read_line(pf)) {
// chomp the newline
// TODO: make me 8-bit clean!
linebuf[strlen(linebuf.c_str()) - 1] = '\0';
lineno++;
char *args[7];
int argc = linebuf.split(0, args, 7, ' ');
if (argc < 5) {
corrupt(lineno, "Expected 5-7 args");
}
char *incl = NULL, *excl = NULL;
int i;
for(i = 5; i < argc; i++) {
if (args[i][0] == '-') {
if (args[i][1] == 'i') {
incl = args[i] + 2;
} else if (args[i][1] == 'x') {
excl = args[i] + 2;
}
}
}
if ((argc == 6 && excl == NULL && incl == NULL)
|| (argc == 7 && (excl == NULL || incl == NULL))) {
corrupt(lineno, "Bad -i or -x option");
}
struct edit_lock tmp(args[0], args[1], args[2],
args[3], args[4],
incl, excl);
if (!tmp.got.valid() || !tmp.got.valid()) {
corrupt(lineno, "Invalid SID");
}
if (!tmp.date.valid()) {
corrupt(lineno, "Invalid date");
}
if (!tmp.include.valid() || !tmp.exclude.valid()) {
corrupt(lineno, "Invalid SID list");
}
edit_locks.add(tmp);
}
if (ferror(pf))
{
errormsg_with_errno("%s: Read error.", pname.c_str());
ctor_fail_nomsg(-1);
}
fclose(pf);
}
}
int
sccs_pfile::is_locked(sid id) {
rewind();
sccs_pfile &it = *this;
while (next()) {
if (it->got == id) {
return 1;
}
}
return 0;
}
int
sccs_pfile::is_to_be_created(sid id) {
rewind();
sccs_pfile &it = *this;
while (next()) {
if (it->delta == id) {
return 1;
}
}
return 0;
}
int
sccs_pfile::print_lock_sid(FILE *fp)
{
const edit_lock& l = edit_locks.select(pos);
const sid& s = l.delta;
return s.print(fp);
}
sccs_pfile::~sccs_pfile() {
if (mode != READ) {
name.unlock();
}
}
/* Local variables: */
/* mode: c++ */
/* End: */
|