December 18th, 2007
744 Part VI . Programming in Linux Finally, if you totally botch all of your changes to your working files and want to revert to the most recent versions, use the update command. It updates the specified directory with the most recent versions stored in the repository, as shown in the following example: $ cd ~/projects/newhello $ cvs update . cvs udate: Updating . U showit.c U msg.c U hello.c There s much more to CVS than the few examples presented here. For additional information, visit the CVS home page on the Web at www.cvshome.org. Debugging with GDB Software is buggy, and some programs have more bugs than other programs. While debugging sessions will never be aggravation-free, GDB s advanced features lighten the load and enable you to be more productive in squashing bugs. Time and effort invested in learning GDB is well spent if you can track down and fix a serious bug in just a few minutes. GDB can make this happen. Most of what you will need to accomplish with GDB can be done with a surprisingly small set of commands. The rest of this chapter explores GDB features and shows you enough GDB commands to get you going. Effective debugging requires that your source code be compiled with -g option to create a binary with an extended symbol table. For example, the following command: $ gcc -g file1 file2 -o prog causes prog to be created with debugging symbols in its symbol table. If you want, you can use GCC s -ggdb option to generate still more (GDB-specific) debugging information. However, to work most effectively, this option requires that you have access to the source code for every library against which you link. While this can be very useful in certain situations, it can also be expensive in terms of disk space. In most cases, you can get by with the plain -g option. Starting GDB To start a debugging session, simply type gdb progname, replacing progname with the name of the program you want to debug. Using a core file is optional but will enhance GDB s debugging capabilities. Of course, you ll need a program on which to try out GDB debugging, so Listing 28-5 provides one: debugme.c.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.
Posted in Linux | No Comments »
December 17th, 2007
Chapter 28 . Programming Tools and Utilities 743 When you check in a modified file, CVS opens an editor session to enable you to enter a log message that describes the changes you made. The editor used is the editor defined in the $EDITOR environment variable or compiled-in default (usually vi) if $EDITOR is undefined. This example did not use the -d option because the $CVSROOT environment variable is set. To check out a specific version, or revision, of a file, use the -r option following the checkout or co command, followed by a revision number. For example, to check out revision 1.1 of the showit.c file, use the following command: $ cvs checkout -r 1.1 newhello/showit.c U newhello/showit.c To see the differences between two revisions, use the diff command, using the -r m.n, where m.n indicates the revision number you want to check. If you specify -r only once, the indicated version will be diffed against the working file. If you specify -r twice, the two versions will be diffed against each other. The following example compares revision 1.2 of showit.c to the current working revision (the revision that is currently in the working directory): $ cvs diff -r 1.2 newhello/showit.c Index: newhello/showit.c =================================================================== RCS file: /space/cvs/newhello/showit.c,v retrieving revision 1.2 retrieving revision 1.3 diff -r1.2 -r1.3 9,10c9,10 < char msg_hi[] = { Hi there, programmer!n }; < char msg_bye[] = { Goodbye, programmer!n }; --- > char msg_hi[] = { Hi there, programmer! }; > char msg_bye[] = { Goodbye, programmer! }; 12c12 < printf( %s , msg_hi); --- > printf( %sn , msg_hi); The diff output is easier to understand than you might expect. Lines that begin with < appear in the first file (revision 1.2 of showit.c) but not in the second (revision 1.3 of showit.c. Similarly, lines beginning with > appear in the second file but not in the first. Each section of diff output begins with an alphanumeric sequence such as 9,10c9,10 or 12c12. The numeric values indicate the lines in the first and second files to which an operation must be applied to get the second file from the first. The operation to perform, such as inserting, deleting, or changing lines, is specified by the alphabetic character. So, for example, the sequence 9,10c9,10 means that to create the second file from the first you have to change (c) lines 9 and 10 of the first file to lines 9 and 10 of the second file.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.
Posted in Linux | No Comments »
December 15th, 2007
742 Part VI . Programming in Linux 6. Do as the instructions recommend; execute the command cvs commit to make the added files and directories permanent: $ cvs commit cvs commit: Examining . RCS file: /space/cvs/newhello/hello.c,v done Checking in hello.c; /space/cvs/newhello/hello.c,v <-- hello.c initial revision: 1.1 done RCS file: /space/cvs/newhello/msg.c,v done Checking in msg.c; /space/cvs/newhello/msg.c,v <-- msg.c initial revision: 1.1 done RCS file: /space/cvs/newhello/showit.c,v done Checking in showit.c; /space/cvs/newhello/showit.c,v <-- showit.c initial revision: 1.1 done Notice that CVS uses RCS file-naming conventions to work with files in the repository. This is because CVS was built on top of RCS and retains compatibility with the basic RCS feature set. CVS handles checking files in and out slightly differently than RCS. When checking a file out, it isn t necessary to specifically request a lock to get a writable copy of the file. To work on a file, you do need to use the checkout or co command: $ cd ~/projects $ cvs -d /space/cvs co newhello cvs checkout newhello U newhello/hello.c U newhello/msg.c U newhello/showit.c The checkout command used in this example specifies the path to the repository using the -d option. This is unnecessary if you set the $CVSROOT environment variable. After you have made changes to files, you can check them in using the cvs commit command (commit is comparable to RCS s ci command): $ cd ~/project/newhello $ cvs commit . cvs commit: Examining . [editor session] Checking in showit.c; /space/cvs/newhello/showit.c,v <-- showit.c new revision: 1.2; previous revision: 1.1 done
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.
Posted in Linux | No Comments »
December 14th, 2007
Chapter 28 . Programming Tools and Utilities 741 The Concurrent Versions System (CVS) supports both centralized repositories and network-based access. It is well-suited for use by multiple programmers, and a single CVS repository can support multiple projects. To keep the discussion simple, however, the example in this chapter deals only with a repository accessed locally. The following steps resemble the process described earlier for RCS, but they are slightly more involved and obviously use CVS concepts. 1. Create a CVS repository: $ mkdir /space/cvs $ export CVSROOT=/space/cvs $ cvs init The first command creates a directory named /space/cvs in which to establish the repository. The second command defines the environment variable $CVSROOT with this directory. Defining $CVSROOT makes using CVS much simpler. The third command initializes the repository, which creates some administrative directories CVS needs to work properly. 2. Create a top-level working directory in which to store your various projects and then cd into it: $ mkdir projects $ cd projects 3. Check out a copy of the CVS root directory into the top-level projects directory you just created: $ cvs -d $CVSROOT co -l . cvs checkout: Updating . The -d option tells cvs the directory containing the CVS repository ($CVSROOT, or /space/cvs); co means check out (just as with RCS); the -l option, which stands for local, means to work only in the current directory rather than recursing through subdirectories; and the . specifies the current directory. 4. Create a directory to hold a project and add it to the repository: $ mkdir newhello $ cvs add newhello Directory /space/cvs/newhello added to the repository 5. cd into the new directory, copy your project files into it, and then add those files (and any directories that might be present) to the repository: $ cp /projects/* . $ cvs add * Directory /space/cvs/newhello/debugme added to the repository cvs add: scheduling file `hello.c for addition cvs add: scheduling file `msg.c for addition cvs add: scheduling file `showit.c for addition cvs add: use cvs commit to add these files permanently
Check Tomcat Web Hosting services for best quality webspace to host your web application.
Posted in Linux | No Comments »
December 13th, 2007
740 Part VI . Programming in Linux RCS s command-line options are cumulative, as you might expect, and RCS does a good job of disallowing incompatible options. To check out and lock a specific revision of howdy.c, you would use a command like co -l -r2.1 howdy.c. Similarly, ci -u -r3 howdy.c checks in howdy.c, assigns it revision number 3.1, and deposits a read-only revision 3.1 working file back into your current working directory. The following example creates revision 2.1 of howdy.c. Make sure you have checked out and changed howdy.c somehow before executing this command. $ ci -r2 howdy.c RCS/howdy.c,v <-- howdy.c new revision: 2.1; previous revision: 1.2 enter log message, terminated with single . or end of file: >> Added something >> . done This command is equivalent to ci -r2.1 howdy.c. The next example checks out revision 1.2 of howdy.c, disregarding the presence of higher-numbered revisions in the working directory. $ co -r1.2 howdy.c RCS/howdy.c,v –> howdy.c revision 1.2 done The handy command shown next discards all of the changes you ve made and lets you start over with a known good source file. $ co -l -f howdy.c RCS/howdy.c,v –> howdy.c revision 2.1 (locked) done When used with ci, -f forces RCS to check in a file even if it has not changed. Source Code Control with CVS You may have noticed that RCS has some shortcomings that make it inadequate for use on large projects. First, without some sophisticated wrapper scripts to provide the directory handling machinery, RCS doesn t work very well with a single, centralized repository. Its repository is always the current directory unless you exert yourself to use a directory located elsewhere. More pertinent for Linux and other open source projects, RCS is utterly unsuitable for distributed development because it doesn t support network protocols. (That is, it doesn t work over the Internet.)
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.
Posted in Linux | No Comments »
December 12th, 2007
Chapter 28 . Programming Tools and Utilities 739 With the file safely checked into the repository, you can check it out and modify it. To check a file out for editing, use the co command. Here s an example: $ co -l howdy.c RCS/howdy.c,v –> howdy.c revision 1.1 (locked) done The working file you just checked out is editable. If you do not want to edit it, omit the -l option. Making Changes to Repository Files To see version control in action, make a change to the working file. If you haven t already done so, check out and lock the howdy.c file. Change anything you want, but I recommend adding n to the end of fprintf() s string argument because Linux (and UNIX), unlike DOS and Windows, do not automatically add a newline to the end of console output. Then, check the file back in and RCS will increment the revision number to 1.2, ask for a description of the change you made, incorporate the changes you made into the RCS file, and (annoyingly) delete the original. To prevent deletion of your working files during check-in operations, use the -l or -u option with ci. Here s an example: $ ci -l howdy.c RCS/howdy.c,v <-- howdy.c new revision: 1.2; previous revision: 1.1 enter log message, terminated with single . or end of file: >> Added newline >> . done When used with ci, both the -l and -u options cause an implied check out of the file after the check-in procedure completes. -l locks the file so you can continue to edit it, while -u checks out an unlocked or read-only working file. Additional Command-Line Options In addition to -l and -u, ci and co accept two other very useful options: -r (for revision) and -f (force). Use -r to tell RCS which file revision you want to manipulate. RCS assumes you want to work with the most recent revision; -r overrides this default. The -f option forces RCS to overwrite the current working file. By default, RCS aborts a check-out operation if a working file of the same name already exists in your working directory. So if you really botch up your working file, use the -f option with co to get a fresh start.
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.
Posted in Linux | No Comments »
December 11th, 2007
738 Part VI . Programming in Linux RCS manages multiple versions of files, usually but not necessarily source code files. It automates file version storage and retrieval, change logging, access control, release management, and revision identification and merging. As an added bonus, RCS minimizes disk space requirements because it tracks only file changes. One of RCS s attractions is its simplicity. With only a few commands, you can accomplish a great deal. Checking Files In and Out You can accomplish a lot with RCS using only two commands (ci and co) and a directory named RCS. ci stands for check in, which means storing a working file in the RCS directory; co means check out and refers to retrieving an RCS file from the RCS repository. To get started, you need to create an RCS directory. All RCS commands will use this directory if it is present in your current working directory. The RCS directory is also called the repository. When you check a file in, RCS asks for a description of the file, copies it to the RCS directory, and deletes the original. Deletes the original? Ack! Don t worry, you can retrieve it with the check out command, co. Here s how to create an RCS directory: $ mkdir RCS Next, create the following source file shown (howdy.c) in the same directory in which you created the RCS directory. /* * $Id$ * howdy.c - Sample to demonstrate RCS Usage */ #include int main(void) { fprintf(stdout, Howdy, Linux programmer! ); return EXIT_SUCCESS; } Now, use the command ci howdy.c to check the file into the repository: $ ci howdy.c RCS/howdy.c,v <-- howdy.c enter description, terminated with single . or end of file: NOTE: This is NOT the log message! >> Simple program to illustrate RCS usage >> . initial revision: 1.1 done
Check Tomcat Web Hosting services for best quality webspace to host your web application.
Posted in Linux | No Comments »
December 11th, 2007
Chapter 28 . Programming Tools and Utilities 737 loaded prior to executing a program. You can use $LD_PRELOAD to override installed versions of a library with a specific version; this is often useful when you are testing a new (or different) library version but don t want to install the replacement library on your system. Source Code Control Version control is an automated process for keeping track of and managing changes made to source code files. Why bother? Because one day you will make that one fatal edit to a source file, delete its predecessor, and forget exactly which line or lines of code you fixed ; because simultaneously keeping track of the current release, the next release, and eight bug fixes manually will become mind-numbing and confusing; because frantically searching for the backup tape because one of your colleagues overwrote a source file for the fifth time will drive you over the edge; because, one day, over your morning cappuccino, you will say to yourself, Version control, it s the Right Thing to Do. Source Code Control Using RCS The Revision Control System (RCS) is a common solution to the version control problem. RCS, which is maintained by the GNU project, is available on almost all UNIX systems, not just on Linux. Two alternatives to RCS are the Concurrent Version System (CVS), which also is maintained by the GNU project, and the Source Code Control System (SCCS), a proprietary product. Before proceeding, however, Table 28-5 lists a few terms that will be used throughout the chapter. Because they are so frequently used, I want to make sure you understand their meaning insofar as RCS and version control in general are concerned. Table 28-5 Version Control Terms Term Description Lock A working file retrieved for editing such that no one else can edit it simultaneously. A working file is locked by the first user against edits by other users. RCS file Any file located in an RCS directory, controlled by RCS, and accessed using RCS commands. An RCS file contains all versions of a particular file. Normally, an RCS file has a .v extension. Revision A specific, numbered version of a source file. Revisions begin with 1.1 and increase incrementally, unless forced to use a specific revision number. Working file One or more files retrieved from the RCS source code repository (the RCS directory) into the current working directory and available for editing.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.
Posted in Linux | No Comments »
December 10th, 2007
736 Part VI . Programming in Linux ldd prints the names of the shared libraries file requires. Two of ldd s most useful options are -d, which reports any missing functions, and -r, which reports missing functions and missing data objects. For example, the following ldd reports that the mail client mutt (which may or may not be installed on your system) requires eight shared libraries. $ ldd /usr/bin/mutt libncursesw.so.5 => /lib/libncursesw.so.5 (0×40021000) libssl.so.0 => /usr/lib/libssl.so.0 (0×40066000) libcrypto.so.0 => /usr/lib/libcrypto.so.0 (0×40097000) libc.so.6 => /lib/libc.so.6 (0×40195000) libgpm.so.1 => /lib/libgpm.so.1 (0×402c5000) libdl.so.2 => /lib/libdl.so.2 (0×402cb000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0×40000000) libncurses.so.5 => /lib/libncurses.so.5 (0×402ce000) The output might be different on your system. The ldconfig Command ldconfig determines the runtime links required by shared libraries that are located in /usr/lib and /lib, specified in libs on the command line, and stored in /etc/ ld.so.conf. It works in conjunction with ld.so, the dynamic linker/loader, to create and maintain links to the most current versions of shared libraries available on a system. It has the following syntax: ldconfig [options] [libs] A bare ldconfig simply updates the cache file, /etc/ld.so.cache. options controls ldconfig s behavior. The -v option tells ldconfig to be verbose as it updates the cache. The -p option says to print without updating the current list of shared libraries about which ld.so knows. Environment Variables and Configuration Files The dynamic linker/loader ld.so uses a number of environment variables to customize and control its behavior. The first variable is $LD_LIBRARY_PATH, a colon-separated list of directories in which to search for shared libraries at runtime. It is similar to the $PATH environment variable. A second important variable is $LD_PRELOAD, which is a whitespace-separated list of additional, user-specified shared libraries to load before all other libraries. It is used selectively to override functions in other shared libraries. ld.so also uses two configuration files whose purposes parallel those environment variables. /etc/ld.so.conf contains a list of directories that the linker/loader should search for shared libraries in addition to the standard directories, /usr/lib and /lib. /etc/ld.so.preload is a disk-based version of the $LD_PRELOAD environment variable; it contains a whitespace-separated list of shared libraries to be
You want to have a cheap webhost for your apache application, then check apache web hosting services.
Posted in Linux | No Comments »
December 9th, 2007
Chapter 28 . Programming Tools and Utilities 735 The ar Command ar creates, modifies, or extracts archives. It is most commonly used to create static libraries, which are files that contain one or more object files. ar also creates and maintains a table that cross-references symbol names to the members in which they are defined. The ar command has the following syntax: ar {dmpqrtx} [options] [member] archive file […] ar creates the archive named archive from the file(s) listed in file. At least one of d, m, p, q, r, t, and x is required. You will usually use r. Table 28-4 lists the most commonly used ar options. Table 28-4 ar Command-Line Options Option Description -c Creates a new archive file archive if it doesn t exist, suppressing the warning ar would emit if archive doesn t already exist. -q Adds files to the end of archive without checking for replacements. -r Inserts files into archive, replacing any existing members whose name matches that being added. New members are added at the end of the archive. -s Creates or updates the map linking symbols to the member in which they are defined. Given an archive created with the ar command, you can speed up access to the archive by creating an index to the archive. ranlib does precisely this, storing the index in the archive file itself. ranlib s syntax is: ranlib [-v|-V] file This generates a symbol map in file. It is equivalent to ar -s file. The ldd Command While nm lists the symbols defined in an object file, unless you know what library defines which functions, it is not terribly helpful. That is ldd s job. It lists the shared libraries that a program requires to run. Its syntax is: ldd [options] file Tip
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.
Posted in Linux | No Comments »