Monday, July 19, 2010

A compact PC-Lint error output file parser

This code has been hanging around in my drafts folder for quite some time now. I needed to get it out. I wrote this simple parser for extracting information from the .out file PC-Lint provides as output after its analysis. This information will further be fed to a VS add-in that would integrate this content with the editor. It's going to be a cool one! I'm going to setup the alpha version of the add-in next month on Google Code.

Here's the code.

public class PCLintOutputReader
{
    public PCLintOutputReader(string filePath)
    {
        _content = File.ReadAllText(filePath);
    }

    public List<ErrorMessageInfo> ParseTextErrorMessages()
    {
        const string errorPatternAsString = @"T:\s*(?<Type>\w*)\r\n"
                                          + @"N:\s*(?<ErrorNumber>[0-9]*)\r\n"
                                          + @"F:\s*(?<FileName>.*)\r\n"
                                          + @"L:\s*(?<LineNumber>[0-9]*)\r\n"
                                          + @"M:\s*(?<Message>.*)\r\n";

        Regex errorPattern = new Regex(errorPatternAsString, RegexOptions.Compiled | RegexOptions.IgnoreCase);

        var errorMessages = new List<ErrorMessageInfo>();
        var matches = errorPattern.Matches(_content);
        foreach (Match match in matches)
        {
            GroupCollection groups = match.Groups;
            errorMessages.Add(
                ErrorMessageInfo.Parse(groups["Type"].Value, groups["ErrorNumber"].Value, groups["FileName"].Value,
                    groups["LineNumber"].Value, groups["Message"].Value)
            );
        }

        return errorMessages;
    }

    private string _content;
}


public class ErrorMessageInfo
{
    public ErrorMessageInfo() { }
    public MessageType Type { get; set; }
    public int ErrorNumber { get; set; }
    public string FileName { get; set; }
    public int LineNumber { get; set; }
    public string Message { get; set; }

    public static ErrorMessageInfo Parse(string aType, string aErrorNumber, string aFileName, string aLineNumber, string aMessage)
    {
        ErrorMessageInfo errorMessage = new ErrorMessageInfo();
        switch (aType)
        {
            case "Info":
                errorMessage.Type = MessageType.Info;
                break;
            case "Warning":
                errorMessage.Type = MessageType.Warning;
                break;
            case "Error":
                errorMessage.Type = MessageType.Error;
                break;
            default:
                throw new ArgumentException("Could not identify the type of PC-Lint error.", aType);
        }

        int temp = 0;
        int.TryParse(aErrorNumber, out temp);
        errorMessage.ErrorNumber = temp;

        int.TryParse(aLineNumber, out temp);
        errorMessage.LineNumber = temp;

        errorMessage.FileName = aFileName;
        errorMessage.Message = aMessage;
        return errorMessage;
    }
}


public enum MessageType
{
    Info,
    Warning,
    Error
}

Disclaimer: This is a very amateur implementation of the solution. Kindly use the code at your own risk and don't blame me if your laptop bursts into flames. Please forgive any obvious coding convention errors. And let me know if you find any bugs.
Have fun!

Sunday, July 4, 2010

The Engineering Sprint

I was listening to Episode 164: Agile Testing with Lisa Crispin on SE-Radio a few days ago. It was a nice podcast and Lisa's views are very much similar to the views of hundreds of Agile experts out there. While describing the work she's currently into, she mentioned the term "Engineering Sprint".
An Engineering sprint is a 2 week long iteration every 6 months where the team tries out new tools, upgrades existing tools and tries out some new approach to do things better than the way its always done.
I really liked the idea. I do that on a regular basis. I'm always on the lookout to find new and better tools to do my work more efficiently. Nowadays, we do a lot of work - which with a little bit of thinking - can be automated and we can save ourselves a whole bunch of time. But, the team usually doesn't have time to look at the existing situation and evaluate options to make it better. It's the scrum master's responsibility to allocate enough time to each individual to make such evaluation and it is the team's responsibility to make sure they make the best of it.

I'm not asking for a 20% personal time like Google does. But, even letting the team know that such suggestions are welcome can go a long way in making things better. There are always people in the team who are bored of doing the same shitty work everyday. Let them do something different, something interesting and something which will make them more productive in future.

Friday, July 2, 2010

Give it a name!

We all make mistakes, both big and small. But there are always opportunities in life where the smart ones learn to hide their mistakes by redirecting attention to something good (or at least something that looks good). For example, I feel most of the famous and most delicious recipes have been the result of a screw-up. Like when the chef added a little too much pepper in the chicken, they called it 'Hot Pepper Chicken', more ginger and they called it 'Ginger Chicken'. Well, for one, these are fairly easy instances to get out of and second, you cannot always be a smart-ass. The lucky ones get away with murder.


But, making excuses is great till the time someone somewhere catches your bluff. It's really embarrassing then. Not trying to be some kind of a wise man or something. I just came across this topic tonight while preparing dinner when I added too much ginger garlic paste in the chicken. I'll call it 'Pro Ginger Garlic Chicken'.

Since you wasted your precious time reading this crap, the least I can do is leave you with a thought -
'When life gives you lemons - you don't make lemonade; you sell the lemons at double the price, buy lemonade with the first half and keep the second.'


Update: This variation of 'When life gives you lemons' was my own creation and it provoked me to look for more such related interesting quotes. I could find these -
"When life gives you lemons, buy a lemonade stand and use the profits to buy a machine gun. Lets see if life makes the same mistake twice."
"When God gives you lemons, find a new God."
"When life gives you lemons, make grape juice. Then sit back and watch the world try to figure out how you did it."
"When life gives you lemons, throw them at mean people."
"When life gives you lemons, trade it for an apple or something."
"When life gives you lemons, squeeze the juice into a squirt gun and squirt it into someone's eye. It'll make you feel better."
"When life gives you lemons, throw them away! WHO THE FUCK gives lemons out? Mercury Sympathizers thats who!"
"When life gives you lemons, make lemonade. Then give it to your enemies cause it'll be real shitty unless life gave you sugar too."
"When life gives you lemons, you should be use to it because you are a loser and you already have a shitload of them."
"When life gives you lemons, find someone who's life gives them fish & chips and enjoy."
"When life gives you lemons, gentically modify them and use your Super Lemons to destroy the world!"
"When life gives you lemons, rip said lemons in half and jam the wet ends into life's eyes. That'll teach the fucker."
"When life gives you lemons, sell them on e-bay."
"When life gives you lemons, ask for the receipt."
"When life hands you lemons, make lemonade and find someone else who life handed vodka to, and have a party."

P.S. I promise my future posts will definitely be more sensible.