rhl51.htm

来自「linux的初学电子书」· HTM 代码 · 共 1,526 行 · 第 1/3 页

HTM
1,526 行
字号

<FONT COLOR="#000080">/* A little something for RCS */

#include &lt;stdio.h&gt;

main()

{

printf(&quot;Programming at its finest...\n&quot;);

}</FONT></PRE>

<P>The first step in creating an RCS file is to make an RCS directory:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ mkdir RCS</FONT></PRE>

<P>This is where your RCS files will be maintained. You can then check a file into RCS by issuing the ci (check-in) command. Using your trusty finest.c program, enter the following:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ ci finest.c</FONT></PRE>

<P>This operation prompts for comments, and then creates a file in the RCS directory called finest.c,v, which contains all the deltas on your file. After this, RCS transfers the contents of the original file and denotes it as revision 1.1. Anytime that you 
check in a file, RCS removes the working copy from the RCS directory.

<BR>

<BR>

<A NAME="E69E526"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Retrieving an RCS File</B></FONT></CENTER></H4>

<BR>

<P>To retrieve a copy of your file, use the co (check-out) command. If you use this command without any parameters, RCS gives you a read-only version of the file, which you can't edit. You need to use the -l option in order to obtain a version of the file 
that you can edit.

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ co -l finest.c</FONT></PRE>

<P>Whenever you finish making changes to the file, you can check it back in using ci. RCS prompts for text that is entered as a log of the changes made. This time the finest.c file is deposited as revision 1.2.

<BR>

<P>RCS revision numbers consist of release, level, branch, and sequence components. RCS commands typically use the most recent version of a file, unless they are instructed otherwise. For instance, say that the most recent version of finest.c is 2.7. If 
you want to check in finest.c as release 3, issue the ci command with the -r option, like this:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ ci -r3 finest.c</FONT></PRE>

<P>This creates a new release of the file as 3.1. You could also start a branch at revision 2.7 by issuing the following:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ ci -r2.7.1 finest.c</FONT></PRE>

<P>You can remove out-of-date versions with the rcs command and its -o option.

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ rcs -o2.6 finest.c</FONT></PRE>

<BR>

<A NAME="E69E527"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Using Keywords</B></FONT></CENTER></H4>

<BR>

<P>RCS lets you enter keywords as part of a file. These keywords contain specific information about such things as revision dates and creator names that can be extracted using the ident command. Keywords are embedded directly into the working copy of a 
file. When that file is checked in and checked out again, these keywords have values attached to them. The syntax is

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$keyword$</FONT></PRE>

<P>which is transformed into

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$keyword: value$</FONT></PRE>

<P>Some keywords used by RCS are shown in the following list.

<BR>



<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

$Author$

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

The user who checked in a revision</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

$Date$

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

The date and time of check-in</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

$Log$

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Accumulated messages that describe the file</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Revision$

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

The revision number</FONT>

</TABLE><P>If your finest.c file used the keywords from the previous table, the command

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ ident finest.c</FONT></PRE>

<P>produces output like this:

<BR>

<PRE>

<FONT COLOR="#000080">$Author: pete $

$Date: 95/01/15 23:18:15 $

$Log: finest.c,v $

<A NAME="I2"></A># Revision 1.2 95/01/15 23:18:15 pete

# Some modifications

#

# Revision 1.1 95/01/15 18:34:09 pete

# The grand opening of finest.c!

#

$Revision: 1.2 $</FONT></PRE>

<BR>

<A NAME="E68E396"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Retrieving Version Information from an RCS File</B></FONT></CENTER></H3>

<BR>

<P>Instead of querying the contents of an RCS file based on keywords, you might be interested in obtaining summary information about the version attributes using the rlog command with the -t option. On the finest.c RCS file, the output from

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ rlog -t finest.c</FONT></PRE>

<P>would produce output formatted like this:

<BR>

<PRE>

<FONT COLOR="#000080">RCS file: finest.c,v; Working file: finest.c

head: 3.2

locks: pete: 2.1; strict

access list: rick tim

aymbolic names:

comment leader: &quot; * &quot;

total revisions: 10;

description:

You know...programming at its finest...

=========================================================</FONT></PRE>

<P>head refers to the version number of the highest revision in the entire stream. locks describes which users have versions checked out and the type of lock (strict or implicit for the RCS file owner). access list is a list of users who have been 
authorized to make deltas on this RCS file. The next section illustrates how user access privileges for an RCS file can be changed.

<BR>

<BR>

<A NAME="E68E397"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Administering Access</B></FONT></CENTER></H3>

<BR>

<P>One of the most important functions of RCS is to mediate the access of users to a set of files. For each file, RCS maintains a list of users who have permission to create deltas on that file. This list is empty to begin with, so that all users have 
permission to make deltas. The rcs command is used to assign user names or group names with delta privileges. The command

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ rcs -arick,tim finest.c</FONT></PRE>

<P>enables the users Rick and Tim to make deltas on finest.c and simultaneously restricts all other users (except the owner) from that privilege.

<BR>

<P>Perhaps you change your mind and decide that the user Rick is not worthy of making deltas on your wonderful finest.c program. You can deny him that privilege using the -e option:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">&amp; rcs -erick finest.c</FONT></PRE>

<P>Suddenly, in a fit of paranoia, you can trust no one to make deltas on finest.c. Like a software Mussolini, you place a global lock (which applies to everyone, including the owner) on release 2 of finest.c using the -e and -L options:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ rcs -e -L2 finest.c</FONT></PRE>

<P>so that no one can make changes on any delta in the release 2 stream. Only the file owner could make changes, but this person still would have to explicitly put a lock on the file for every check-out and check-in operation.

<BR>

<BR>

<A NAME="E68E398"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Comparing and Merging Revisions</B></FONT></CENTER></H3>

<BR>

<P>Revisions can be compared to each other to discover what, if any, differences lie between them. This can be used as a means of safely merging together edits of a single source file by different developers. The rcsdiff command is used to show differences 
between revisions existing in an RCS file, or between a checked-out version and the most current revision in the RCS file. To compare the finest.c 1.2 version to the 1.5 version, enter

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ rcsdiff -r1.2 -r1.5 finest.c</FONT></PRE>

<P>The output would appear something like

<BR>

<PRE>

<FONT COLOR="#000080">RCS file: finest.c,v

retrieving revision 1.1

rdiff -r1.2 -r1.5 finest.c

6a7,8

&gt;

&gt; /* ...but what good is this? */</FONT></PRE>

<P>This output indicates that the only difference between the files is that two new lines have been added after the original line six. To just compare your current checked-out version with that of the &quot;head&quot; version in the RCS file, simply enter

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ rcsdiff finest.c</FONT></PRE>

<P>Once you have determined if there are any conflicts in your edits with others, you may decide to merge together revisions. You can do this with the rcsmerge command. The format of this command is to take one or two filenames representing the version to 
be merged, and a third filename indicating the working file (in the following example, this is finest.c).

<BR>

<P>The command

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">$ rcsmerge -r1.3 -r1.6 finest.c</FONT></PRE>

<P>produces output like this:

<BR>

<PRE>

<FONT COLOR="#000080">RCS file: finest.c,v

retrieving revision 1.3

retrieving revision 1.6

Merging differences between 1.3 and 1.6 into finest.c</FONT></PRE>

<P>If any lines between the two files overlapped, rcsmerge would indicate which lines originated from which merged file in the working copy. You would have to resolve these overlaps by explicitly editing the working copy to remove any conflicts before 
checking the working copy back into RCS.

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE>There is an implied order in which the files to be merged are placed in the rcsmerge command. If you are placing a higher version before a lower one at the -r options, this is essentially undoing the edits that have transpired from the older (lower) 
version to the newer (higher) version.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<BR>

<A NAME="E68E399"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Tying It All Together Working with </B><B>make</B><B> and RCS</B></FONT></CENTER></H3>

<BR>

<P>The make program supports interaction with RCS, enabling you to have a largely complete software development environment. However, the whole issue of using make with RCS is a sticky one if your software project involves several people sharing source 
code files. Clearly, it may be problematic if someone is compiling files that you need to be stable in order to do your own software testing. This may be more of a communication and scheduling issue between team members than anything else. At any rate, 
using make with RCS can be very convenient for a single programmer, particularly in the Linux environment.

<BR>

<P>make can handle RCS files through the application of user-defined suffix rules that recognize the ,v suffix. RCS interfaces well with make because its files use the ,v suffix, which works well within a suffix rule. You could write a set of RCS-specific 
suffix rules to compile C code as follows:

<BR>

<PRE>

<FONT COLOR="#000080">CO = co

.c,v.o:

${CO} $&lt;

${CC} ${CFLAGS} -c $*.c

- rm -f $*.c</FONT></PRE>

<P>The CO macro represents the RCS check-out command. The $*.c macro is necessary because make automatically strips off the .c suffix. The hyphen preceding the rm command instructs make to continue, even if the rm fails. For main.c stored in RCS, make 
generates these commands:

<BR>

<PRE>

<FONT COLOR="#000080">co main.c

cc -O -c main.c

rm -f main.c</FONT></PRE>

<BR>

<A NAME="E68E400"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Summary</B></FONT></CENTER></H3>

<BR>

<P>Linux offers two key utilities for managing software development: make and RCS. make is a program that generates commands for compilation, linking, and other related development activities. make can manage dependencies between source code and object 
files so that an entire project can be recompiled as much as is required for it to be up-to-date. RCS is a set of source code control programs that enables several developers to work on a software project simultaneously. It manages the use of a source code 
file by keeping a history of editing changes that have been applied to it. The other benefit of versioning control is that it can, in many cases, reduce disk space requirements for a project. CVS is an enhancement to the RCS programs. It automatically 
provides for the merging of revisions. This capability enables several developers to work on the same source code file at once, with the caveat that they are responsible for any merging conflicts that arise.

<P ALIGN=LEFT>

<A HREF="rhl50.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl50.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>

<A HREF="#I0" TARGET="_self"><IMG SRC="purtop.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Page Top"></A>

<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>

<A HREF="rhl52.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl52.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>


</BODY></HTML>



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?