Friday, October 12, 2007

XPM File format

Intro
XPM or XPixMap is a bitmap format in unix based systems. It is a relatively easy format to understand, XPM files have a format similar to a C source code of a string array.


/* XPM */
static char * var name[] = {
"","","" //etc....
};


The first line is XPM in standard C comments. Second is an array declaration with a valid token as variable name.
The array index 0 [0] : contains the following %d %d %d %d [%d %d] [%d]
which are :
Width,Height,Number of colors, Characters Per Pixel, optional X & Y Hotspots, optional XPM Extension.
The array indexes 1-> number of colors indicates the color section.
The strings in these section take the following format :
%s %s %s
The first contains the characters that represent the pixels. The number of characters used to represent a pixel is given by Characters Per Pixel field in array[0].
The second string represents control characters that defines what the following field is about.
switch(control character)
{
case 'm' : Mono color
case 's' : Symbolic name
case 'c' : Color value
case 'g4': 4 Level Gray Scale
case 'g' : Grayscale
}

the third string is then
a color name eg: black
a # followed by RGB Hex
a % followed by HSV Hex
a symbolic name
a "None" indicating a transparent.

The rest of the section contains the actual pixels. With each (Character Per Pixel) representing a pixel on the screen. Each string is width pixels long and there will be height number of strings.

There might be an optional XPM Extension following the pixels.

Examples:

/* XPM */
static char * plaid[] =
{
/* plaid pixmap */
/* width height ncolors chars_per_pixel */
"22 22 4 2 0 0 XPMEXT",
/* colors */
" c red m white s light_color",
"Y c green m black s ines_in_mix",
"+ c yellow m white s lines_in_dark ",
"x m black s dark_color ",
/* pixels */
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
"Y Y Y Y Y x Y Y Y Y Y + x + x + x + x + x + ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
"x x x x x x x x x x x x x x x x x x x x x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
"XPMEXT ext1 data1",
"XPMEXT ext2",
"data2_1",
"data2_2",
"XPMEXT ext3",
"data3",
"XPMEXT",
"data4",
"XPMENDEXT"
};

Another one :

/* XPM */
static char * example_xpm[] = {
"24 20 3 1",
" c None",
". c #0000FF",
"+ c #FF0000",
" ",
" .. ",
" .... ",
" ......++++++++ ",
" .........+++++++ ",
" ..........+++++++ ",
" ............++++++ ",
" .............++++++ ",
" ..............++++ ",
" +.............+++ ",
" ++.............++ ",
" +++.............+ ",
" +++++............. ",
" ++++++.............. ",
" ++++++++............ ",
" +++++++++........... ",
" +++++++++......... ",
" ++++++++++....... ",
" ++++++++++..... ",
" +++++++++ ... "};


Thats all
for a Hi Fi version
refer this.

Monday, October 1, 2007

PERL Referencing and Dereferencing

Intro

PERL - Practical Extraction and Report Language.

Referencing a variable means creating a pointer to the variable.
Referencing in C is done by the & operator, but in PERL referencing is done by the \(backslash) operator.

Check out the following examples to understand better:

my $scalar = "http://digitalpbk.blogspot.com";
my $scalar_ptr = \$scalar; //Scalar reference

my $array= (1,2,4,3,5);
my $array_ptr = \@array; //Array reference
//or

my $array_ptr = [1,2,3,4,5];//Array reference
//Note the [Square brackets]


my %hash = ("one",1,"two",2);
my $hash_ptr = \%hash; //Hash reference
//or

my $hash_ptr = {"one" => 1,"two"=>2};//Hash reference
//Note the {Curly brackets}


my $sub_ref = \&a_subroutine;//Subroutine reference
//or

my $sub_ref = sub { print "somethings"; };//Sub reference




Dereferencing is the opposite of referencing i.e, to get the value pointed by the referencing/pointing variable. Dereferencing in C is done by the * operator, whereas in PERL it is done by prepending, adding an appropriate @,$ or % to the reference variable.



my $scalar_ptr = \$scalar; //Scalar reference
my $scalar = $$scalar_ptr; //Scalar Var

my $array_ptr = \@array; //Array reference
//or

my $array_ptr = [1,2,3,4,5];//Array reference
my $array = @$array; // Array Var


my $hash_ptr = \%hash; //Hash reference
my %hash = %$hash //Hash Var

my $sub_ref = \&a_subroutine;//Subroutine reference
my $sub_ref = sub { print "somethings"; };//Sub reference
&$sub_ref //Call Subroutine



Thats all about referencing and dereferencing...

Monday, September 17, 2007

Introduction to Windows - Programming for Windows

History - DOS
Disk Operating System aka DOS was one of the earlier operating systems, it was a single task system, where the whole system and the OS was devoted to executing a single program and was basically a text based OS.

With the advent of the Windows Operating System, multiple process or applications could be run and it became a graphical OS (interface). So in order to support new features the basic structure of C/C++ programs changed from the main(){...} procedure to
something of a program as shown below and the a new compiler is required for compiling and generating Windows Executables, Visual C++ is such an example.

/*Program to
Display a Window on Windows
Test Compiled using Visual C++
*/


#include <windows.h>

LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);

char szWinName[] = "MyWin";

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgs,
int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;

wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hInstance;
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = NULL;
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);

wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;

wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

if(!RegisterClassEx(&wcl)) return 0;

hwnd = CreateWindow(szWinName,"Windows XP",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);


ShowWindow(hwnd,nWinMode);
UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK WindowFunc(HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
}
return 0;
}


Windows OS Skeleton
Windows is called so because all things you see on your desktop is broken into small Windows. A Window can have many child windows, parent window, and many other windows on the same level.

Getting Started to Windows Programming in C(++)?
A minimal Windows program must have atleast 2 functions
  • WinMain()
  • WindowFunc()


the WinMain() Function
The WinMain() function is the entry point to your program, i.e, the execution of your program starts with WinMain().
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszArgs,int WinMode)

The WinMain function must
  1. Define a window class

  2. Register the class (RegisterClassEx)

  3. Create Window (CreateWindowEx)

  4. Display Window (ShowWindow)

  5. Get the message loop running(while(GetMessage(...)))



The contents in italics is the functions used for doing the specified actions. Check them out in the code.

the Window Procedure
The window Procedure is the link between your program and windows. It is the window procedure that windows calls to send messages to your application.

That's all for now
stay tuned.

Saturday, September 8, 2007

Perl - cPanel V3 and the @INC

Modifying @INC in a SCRIPT

use Module;

is executed during compile time so if you modify the @INC array at run time it will not be reflected back in the compile time. So if you have to include any more include locations in the @INC inside a script, give it inside the BEGIN { }block.


BEGIN
{
push @INC,"location";
}

The BEGIN blocks are executed during compile time. So @INC is updated at compile time and the use module are correctly searched for in the updated directories.

cPanel-v3 Script

my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
if (-d $homedir . '/perl' . $INC[$i]) {
unshift(@INC,$homedir . '/perl' . $INC[$i]);
$n_inc++;
$i++;
}
}


This script dint work for me much, so I manually included the include locations into the BEGIN segment.


#! /usr/bin/perl -w
BEGIN {
unshift @INC,"/home/directory/perl/usr/lib/perl5/site_perl/5.8.7/";
}
.
.
.

Monday, September 3, 2007

Multiple Instances of yahoo messenger

Yahoo Messenger
is a popular instant messaging software around. Yahoo messenger, by default, runs only a single copy on a single machine so for people with multiple yahoo id's this is a problem. Here is a short snippet that makes yahoo messenger to run multiple versions.

REGEDIT
Open the registry editor.
Start > Run > regedit

Navigate to


+- HKEY_CURRENT_USER
+- Software
+- yahoo
+- pager


Create a new key inside pager named Test
Now inside the Test folder create REG_DWORD named pluralwith value 1.

Now you should be able to run multiple instances of yahoo messenger.

Alternate Method

Copy paste the text below exactly to a file with extension ".reg"


REGEDIT4

[HKEY_CURRENT_USER\Software\yahoo\pager\Test]
"Plural"=dword:00000001



Double click the reg file and press "yes".

Thats all folks

Long time since made a post.
Howz life guys ?