Yearly Archives: 2011

Visual Studio Add-Ins that will boost your productivity

I changed jobs about a month ago. My new job involves extensive use of Visual Studio line of products and MS SQL Server. I started as C++ programmer in a company called CSoft.

Here is a list of Dev studio add ins I find useful. They boost my productivity and saves coding or code documenting time.

1. Visual Assist X
This is an add-in that I can’t live with ought. Think of V Assist X as InteliSense on steroids. The add-in helps you with code completion and refactoring, has syntax highlighting enhancements and much more. View complete list of features here. We write products using VS .Net 2003 till VS 2010. Visual Assist X is available for a wide range of Visual Studio versions. Including Visual C++ 6.

2. AtomineerUtils
This add-in helps you with code documentation. The add-in support different documentation styles such as JavaDoc comments, Qt style comments and and DocXml format which is supported by Visual Studio from 2005 on. My new company has code base dating 10+ years back and having good documentation with that code base is priceless. Unfortunately this is not the case but we are trying to document every function and class member and this add-in comes in handy.

AtomineerUtils website: here

3. Productivity Power Tools
The pack includes a quick find extension for the editor, an enhanced scroll-bar, middle click scrolling, enhanced solution navigator – extremely useful when you have a solution with about 200 projects in it.  For a review of the mentioned features and more visit the add-in website.

4. Spell Checker
There is not much to say about this editor extension. It just checks your spelling in comments, strings and plain text. Pretty neat when you are having code review’s.

So this are the add-ins I found useful in my day to day work. Feel free to suggest others and also some nice color schemes.

SQL Server ODBC connection string

1
Driver={SQL Server};Server=Computer\Server;Database=DatabaseName;Uid=user;Pwd=password;Driver={SQL Server};Server=Computer\Server;Database=DatabaseName;Trusted_Connection =yes;

MFC: MDI singleton doc/view application

What singleton means? In our case it’s MDI application where the user can’t have more than one document of a given type open at any time. In order to implement this in doc/view fashion we need 2 things.

First we need a public member in our CDocument delivered class that when called will tell us whatever view of supplied type already exists. Here is the implementation of this public member function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * @brief Check's if given view is already loaded.
 * @param rtClass - the runtime class of the view.
 */
BOOL CVPhoneBookDoc::NeedViewCreation(CRuntimeClass *rtClass)
{
	POSITION pos = GetFirstViewPosition();
	while(pos != NULL)
	{
		CView *pView = GetNextView(pos);
		if(pView->GetRuntimeClass() == rtClass)
		{
			CMDIChildWnd * pViewFrame = (CMDIChildWnd *)pView->GetParentFrame();
			((CMDIFrameWnd*)AfxGetMainWnd())->MDIActivate(pViewFrame);
			return FALSE; // Already exists
		}
	}
 
	return TRUE; // Allow creation
}

The function iterates over the views associated with the document and try’s to find one that’s match our supplied run-time class. If match is found the view is activated and FALSE is returned. Else view creation is allowed.

Second we need to implement a custom member function, for example in the CWinApp delivered class that will be called as replacement of OnNewDocument() or OnOpenDocument(). Here is an example:

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
void CVPhoneBookApp::OnCreateContactVeiw()
{
	POSITION curTemplatePos = GetFirstDocTemplatePosition();
 
	while(curTemplatePos != NULL)
	{
		CDocTemplate* curTemplate =
			GetNextDocTemplate(curTemplatePos);
		CString str;
		curTemplate->GetDocString(str, CDocTemplate::docName);
		if(str == _T("Contacts"))
		{
			// We have only one document for template "Contacts"
			POSITION docPos = curTemplate->GetFirstDocPosition();
			if(docPos == NULL)
			{
				curTemplate->OpenDocumentFile(NULL);
			}
			else
			{
				CVPhoneBookDoc *pDoc = (CVPhoneBookDoc*)curTemplate->GetNextDoc(docPos);
				if(pDoc)
				{
					// Check if view of this type exists
					if(pDoc->NeedViewCreation(RUNTIME_CLASS(CContactsView)))
					{
						curTemplate->OpenDocumentFile(NULL);
					}
				}
			}
		}
	}
}

When called this function first checks if document is available. If it’s not available we call CDocTemplate member function OpenDocumentFile() else, we retrieve a pointer to the document class and checks if view of requested type need’s to be created.

Using the rpm command – part1

This article will show you how you can use the rpm command to preform various package management task , such as installing, removing, querying the rpm database, etc…

1. Installing, removing and updating packages

1.1. Installing packages
Package installation is done using rpm -i (or –install). The basic usage of the command is as follows:

rpm -i <package name>

for example to install htop – An Interactive text-mode Process Viewer for Linux, one wold obtain the rpm package of htop and install it as follows:

rpm -i htop-0.9-11.1.x86_64.rpm

Optionally the the -i option can take ftp or http address of the rpm package. In wich case rpm will download the package prior to installation.

Additional interesting rpm -i options are described in the table below. They can be passed after the -i argument, for example:

rpm -i <option> <package name>

NOTE: For a full list of options review the rpm man page, by typing man rpm.

Install-specific Options
Option Description Usage example
-h –hash If you add -h, RPM will print fifty hash marks (“#”) as the install proceeds. rpm -ih htop-0.9-11.1.x86_64.rpm
-v Provides additional output during the installation of a package. Combine this option with -h for nice output. rpm -iv htop-0.9-11.1.x86_64.rpm
–test Do not install the package, simply check for and report potential conflicts. rpm -i –test htop-0.9-11.1.x86_64.rpm
–excludedocs Don’t install any files which are marked as documentation (which includes man pages and texinfo documents). rpm -i –excludedocs htop-0.9-11.1.x86_64.rpm
–replacepkgs Replace a package with a new copy of itself.This option is normally used if the installed package has been damaged somehow and needs to be fixed up. rpm -i –replacepkgs htop-0.9-11.1.x86_64.rpm
–force Installs a package by ignoring conflicts with other packages and missing dependencies. rpm -i –replacepkgs htop-0.9-11.1.x86_64.rpm
–ignoresize

Don’t check mount file systems for sufficient disk space before installing this package.

rpm -i –ignoresize htop-0.9-11.1.x86_64.rpm
–ignorearch Allow installation or upgrading even if the architectures of the binary package and host don’t match.
–nodeps Don’t do a dependency check before installing or upgrading a package. Note that this will probably leave the package broken after installation. rpm -i –nodeps htop-0.9-11.1.x86_64.rpm
–ignoreos Allow installation or upgrading even if the operating systems of the binary package and host don’t match.

1.2 Upgrading packages

Package upgrade is preformed using rpm -U (or –upgrade). The basic usage of the command is as follows:

rpm -U <package name>

for example: if we want to upgrade our htop package to a newer version we would download the newer version of the package (for example 1.0) and issue the following command:

rpm -U htop-1.0.1-bla-bla.rpm

During execution the rpm -U command preforms two distinct operations:

  1. Installs the desired package
  2. Erases all older versions of the package, if any exists

As the -i option -U can take ftp or http address of the rpm package. In wich case rpm will download the package prior to upgrade.

rpm -U is a combination of two commands rpm -i – used for installing packages (see a bought) and the rpm -e command used for deleting(erasing) packages (see below). The additional rpm -i options described in section 1.1. Installing packages are relevant for the rpm -U command. As stated before, refer to the manual page of rpm for additional command line options.

1.3 Removing packages (erasing)

In rpm the process of removing packages from the system is called erasing. It’s preformed using the rpm -e (–erase) command. The basic usage of rpm -e is shown below:

rpm -e <package1> <package2> <package N>

If we want to remove the htop package from the system we will type:

rpm -e htop

RPM preforms number of steps during package removal:

  • It checks the RPM database to make sure that no other packages depend on the package being erased.
  • It executes a pre-uninstall script defined by the package (if one exists).
  • It checks to see if any of the package’s config files have been modified. If so, it saves copies of them.
  • It reviews the RPM database to find every file listed as being part of the package, and if they do not belong to another package, deletes them.
  • It executes a post-uninstall script defined by the package (if one exists).
  • It removes all traces of the package (and the files belonging to it) from the RPM database.

Additional rpm -e options are described in the table below. They can be passed after the -e argument, for example:

rpm -e <option> <package name>

NOTE: For a full list of options review the rpm man page, by typing man rpm.

Erase-specific Options

Option Description Usage example
–test Preform erase tests only.This option is useful if you want to see what will happen if you remove a package from your system.

rpm -e –test htop

–noscripts Do not execute pre- and post-uninstall scripts.In most cases this option will result in unusable package. rpm -e –noscripts htop

–nodeps

Do not check dependencies. If other packages depends on this particular package, using this option will break them. rpm -e –nodeps htop

2. Retrieving information for packages

In recent days the most useful future or the rpm command are the querying capabilities.By querying capabilities I mean things like retrieving information about a package, such as installed files, dependencies etc, all stored in the rpm database.

Querying the database is done using the rpm -q “query arguments” command. We will look at this “query arguments” one by one.

2.1. Obtaining general information about a package
General information(or package summary) about installed rpm package is obtained using the rpm -qi command. For example if we want to retrieve general information about the htop package we would type:

rpm -qi htop

This will result in output like this:

Name        : htop                         Relocations: (not relocatable)
Version     : 0.9                               Vendor: openSUSE
Release     : 11.1                          Build Date: Sat 19 Feb 2011 06:45:05 AM EET
Install Date: Wed 20 Jul 2011 02:50:36 PM EEST      Build Host: build22
Group       : System/Monitoring             Source RPM: htop-0.9-11.1.src.rpm
Size        : 151367                           License: GPLv2+
Signature   : RSA/8, Sat 19 Feb 2011 06:45:09 AM EET, Key ID b88b2fd43dbdc284
Packager    : http://bugs.opensuse.org
URL         : http://htop.sourceforge.net
Summary     : An Interactive text-mode Process Viewer for Linux
Description :
htop is an interactive text-mode process viewer for Linux. It aims to
be a better 'top' and requires ncurses. It is tested with Linux 2.6,
but is also reported to work (and was originally developed) with the

2.4 series.
 
Authors:
--------
Hisham H. Muhammad
Distribution: openSUSE 11.4

2.2. Listing files that belongs to a package
To list files that belongs to a package one would use the rpm -ql command. For example if we want to retrieve the files that belong to the htop package:

rpm -ql htop

This will result in output like this:

/usr/bin/htop
/usr/share/applications/htop.desktop

/usr/share/doc/packages/htop
/usr/share/doc/packages/htop/COPYING

/usr/share/man/man1/htop.1.gz
/usr/share/pixmaps/htop.png

rpm -qc command on the other hand will list only the configuration files that belongs to a package. For example if we want to list the configuration files that belongs to tomcat6 we would type:

rpm -qc tomcat6

This will result in output like this:

/etc/logrotate.d/tomcat6

/etc/tomcat6/catalina.policy
/etc/tomcat6/catalina.properties
/etc/tomcat6/context.xml

/etc/tomcat6/logging.properties
/etc/tomcat6/server.xml
/etc/tomcat6/tomcat-users.xml

/etc/tomcat6/tomcat6.conf
/etc/tomcat6/web.xml

rpm -qd will list only the package documentation files.

rpm -qs will display the state(modified or not) of each file in the package. Each file in the package may have one of the following states:

  1. normal – A file in the normal state has not been modified by installing another package on the system.
  2. replaced — Files in the replaced state have been modified by installing another package on the system.
  3. not installed – A file classified as not installed, is not installed :)

Here is the result of executing rpm -qs against tomcat6 package:

normal        /etc/init.d/tomcat6
normal        /etc/logrotate.d/tomcat6
normal        /etc/tomcat6
normal        /etc/tomcat6/Catalina
normal        /etc/tomcat6/catalina.policy
normal        /etc/tomcat6/catalina.properties
normal        /etc/tomcat6/context.xml
normal        /etc/tomcat6/logging.properties
normal        /etc/tomcat6/server.xml
normal        /etc/tomcat6/tomcat-users.xml
normal        /etc/tomcat6/tomcat6.conf
normal        /etc/tomcat6/web.xml
.......

Normal at the start of the line is the state.

2.3. Finding which package provides a file
To find which package provides a file one would use the rpm -qf command. For example if we want to view which package provides htop binary:

rpm -qf /usr/bin/htop

Result of the command should looks like this:

htop-0.9-11.1.x86_64

rpm -qf requires the exact file path (in our example /usr/bin/htop). One neat trick, if you don’t know where the file is located is to use the the which command (show a full path of a shell command) in combination with rpm -lf. For example:

rpm -qf $(which htop)

2.4. Querying all installed packages
If you want to review all packages that are installed on a system, rpm -qa is your friend. For example if I execute rpm -qa on my openSUSE box the result will looks like this:

oziris:/home/paskov # rpm -qa
licenses-20070810-92.1.noarch
netcat-1.10-1008.1.x86_64
libpth20-2.0.7-124.1.x86_64
libattr-2.4.44-11.1.x86_64
pptp-1.7.2-31.1.x86_64
libasm1-0.149-2.7.x86_64
perl-Net-Daemon-0.43-90.1.x86_64
xz-5.0.0-13.1.x86_64
usbutils-001-3.1.x86_64
....

The result of rpm -qa will be quite long so you may want to redirect it to a file or use more.

rpm -qa >> install_list #redirects the output to a file
rpm -qa | more #uses the more pager

Conclusion

This concludes part one of ‘Using the rpm command’ series. In the following articles we will look at more querying capabilities, and ways to format the output of rpm -q command. Also how to develop applications that make use of librpm.