Wednesday, June 24, 2009

How to create and remove a unix soft link

A soft link, or more common, a symlink, is link a shortcut to the targeted file or directory. So when is removed the original target stays present.

A symlink can be created like:

ln -s /path/ linkname

from the ln man pages:

ln [OPTION]… [-T] TARGET LINK_NAME (1st form)

-s, –symbolic
make symbolic links instead of hard links

to remove a symlink

rm linkname

You can't update the soft link to point to other target path, you must delete the soft link first and recreate it

Tuesday, June 9, 2009

C preprocessor use for replace string by '##'

C preprocessor allow us to replace string by putting '##' on variable

eg.

#include "stdio.h"

void func_replace(){printf("func_replace is called\n");}

#define REPLACE_FUNC(A) func_##A()

void main()
{
/*func_replace will be invoked*/
REPLACE_FUNC(replace);
}

Wednesday, June 3, 2009

SS7 point code converter

There are plenty of ss7 web base point code converter on web, but i can't find a open source version of point code converter. I had built a command line point code converter for my own used. here i share it out. :)



#include "stdio.h"
#include "string.h"

int main()
{
char buffer[200];
int point_code;
int point_code1,point_code2,point_code3;
int convertion_type;
while(1)
{
printf("please enter converted format \n"
"0 - quit \n"
"1 - [3-8-3] -> hex \n"
"2 - [8-8-8] -> hex \n"
"3 - hex -> [3-8-3] \n"
"4 - hex -> [8-8-8] \n");

gets(buffer);
sscanf(buffer,"%d",&convertion_type);

if(buffer[0]=='q')
{
printf("app exit\n");
}
switch(convertion_type)
{
case 1:
//eq - 0x2044
//0010000001000100
//--100 00001000 100
//4-8-4
printf("enter your point code [3-8-3]\n");
gets(buffer);
sscanf(buffer,"%d-%d-%d",
&point_code1,&point_code2,&point_code3);
point_code = (point_code1<<11) point_code =" %x\n" point_code =" (point_code1<<16)" point_code =" %x\n" point_code1 =" (point_code">>11)&0x00000007;
point_code2 = (point_code>>3)&0x000000ff;
point_code3 = (point_code)&0x00000007;
printf("point_code = %d-%d-%d\n",point_code1,point_code2,point_code3);
break;
case 4:
printf("enter your point code [Hex]\n");
gets(buffer);
sscanf(buffer,"%x",&point_code);
point_code1 = (point_code>>16)&0x000000ff;
point_code2 = (point_code>>8)&0x000000ff;
point_code3 = (point_code)&0x000000ff;
printf("point_code = %d-%d-%d\n",point_code1,point_code2,point_code3);
break;
}
}
return 0;
}


precompiled version of point code converter can be downloaded here
pc_convertor