This is O.R.Senthil Kumaran's blogspot on programming and technical things. The title is a line from "Zen of Python".
Library installation in linux
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
Most of time, I have been adding the path to the /etc/ld.so.conf and doing ldconfig. Need to understand the other options.
Re: Assignment for July 19
Senthil wrote :
> Write a Linked List Program in C and C++.
> Single Linked List only.
>
/* Linked List program. A very simple one to understand the basics */
#include<stdio.h>
#include<stdlib.h>
struct node {
int data;
struct node* next;
};
int main(int argc,char **argv)
{
struct node* head=NULL;
struct node* second=NULL;
struct node* third=NULL;
head=malloc(sizeof(struct node));
second=malloc(sizeof(struct node));
third=malloc(sizeof(struct node));
head->data=1;
head->next=second;
second->data=2;
second->next=third;
third->data=3;
third->next=NULL;
return 0;
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/* Linked List Program in C Plus Plus */
#include<iostream>
using namespace std;
class list
{
private:
struct node {
int data;
struct node *next;
};
struct node *head,*first,*second;
public:
list();
~list();
void addnode();
};
list::list()
{
head=NULL;
first=NULL;
second=NULL;
}
list::~list()
{
while(head != NULL)
{
node *temp;
temp=head;
head=head->next;
delete temp;
}
}
void list::addnode()
{
head=(node *)malloc(sizeof(struct node));
first=(node *)malloc(sizeof(struct node));
second=(node *)malloc(sizeof(struct node));
head->data=1;
head->next=first;
first->data=2;
first->next=second;
second->data=3;
second->next=NULL;
}
int main(int argc,char **argv)
{
list listobj;
listobj.addnode();
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Observations:
- Struct node * head,first,second; does not serve the purpose. Either
they should as in the first program or as in the second program
- Allocation of memory, the first program accepted without typecasting
to (node *) whereas the second cpp program did not.
--
O.R.Senthil Kumaran
http://uthcode.sarovar.org
Unix Blog
where I plan to put my unix learnings while working from home. Coz, I need to do ftp/rsync from the shell where the local unixblog folder will be present.
Its powered by Nanoblogger.
If you have a Unix Machine online, give it a try.
Re: Ant: Re: Ant: Re: link checker task ?
#include<stdio.h>
#include<expat.h>
#include<string.h>
#define string_t char *
#define XML_BUFFER_BLK 8192
void *
memalloc(size_t n)
{
void *mp;
int errno=0;
if((mp=(void *)calloc(n,sizeof(string_t)))==NULL)
fprintf(stderr,"Out of Memory");
return mp;
}
static void
link_start(void *data,const char *el,const char **attr)
{
int i=0;
printf("\n<%s>",el);
for(i=0;attr[i];i++)
printf("\n%s",*(attr+i));
}
static void
link_end(void *data,const char *el)
{
printf("\n<\\%s>\n\n",el);
/* why do we need this function */
}
int
link_parser(string_t filename)
{
XML_Parser parser;
char *xml_buf;
int flag;
size_t length;
FILE *fp;
string_t msg;
if((fp=fopen(filename,"rb"))==NULL)
{
fprintf(stderr,"Could not open the file");
exit(-1);
}
if((parser=XML_ParserCreate(NULL))==NULL)
{
fprintf(stderr,"Could not create the parser");
exit(-1);
}
XML_SetElementHandler(parser,link_start,link_end);
/* parse the document */
xml_buf=(string_t)memalloc(XML_BUFFER_BLK+1);
do
{
length=fread(xml_buf,1,XML_BUFFER_BLK,fp);
flag= length < strlen(xml_buf);
if(XML_Parse(parser,xml_buf,length,flag)==XML_STATUS_ERROR)
{
fprintf(stderr,"Parse Error at line %d\n%s\n",XML_GetCurrentLineNumber(parser),XML_ErrorString(XML_GetErrorCode(parser)));
exit(-1);
}
}while(!flag);
return 0;
}
int main(int argc,char **argv)
{
link_parser(argv[1]);
return 0;
}
Hi Alan,
Greetings!
I could manage to write a basic outline of the link-parser(self-contained).
I have output the tags and the way of identifying links. It will display
tags <a> ,href and URL. Got enormous help from expat doc,files as well as
digestp.c.
But these are yet to be done.
- Check to See if the resource being pointed exists.
- Generate link Report
I shall be working on it as well.
Please find my linkparser.c below (and as an attached file):
Let me know your comments:
---
#include<stdio.h>
#include<expat.h>
#include<string.h>
#define string_t char *
#define XML_BUFFER_BLK 8192
void *
memalloc(size_t n)
{
void *mp;
int errno=0;
if((mp=(void *)calloc(n,sizeof(string_t)))==NULL)
fprintf(stderr,"Out of Memory");
return mp;
}
static void
link_start(void *data,const char *el,const char **attr)
{
int i=0;
printf("\n<%s>",el);
for(i=0;attr[i];i++)
printf("\n%s",*(attr+i));
}
static void
link_end(void *data,const char *el)
{
printf("\n<\\%s>\n\n",el);
/* why do we need this function */
}
int
link_parser(string_t filename)
{
XML_Parser parser;
char *xml_buf;
int flag;
size_t length;
FILE *fp;
string_t msg;
if((fp=fopen(filename,"rb"))==NULL)
{
fprintf(stderr,"Could not open the file");
exit(-1);
}
if((parser=XML_ParserCreate(NULL))==NULL)
{
fprintf(stderr,"Could not create the parser");
exit(-1);
}
XML_SetElementHandler(parser,link_start,link_end);
/* parse the document */
xml_buf=(string_t)memalloc(XML_BUFFER_BLK+1);
do
{
length=fread(xml_buf,1,XML_BUFFER_BLK,fp);
flag= length < strlen(xml_buf);
if(XML_Parse(parser,xml_buf,length,flag)==XML_STATUS_ERROR)
{
fprintf(stderr,"Parse Error at line
%d\n%s\n",XML_GetCurrentLineNumber(parser),XML_ErrorString(XML_GetErrorCode(parser)));
exit(-1);
}
}while(!flag);
return 0;
}
int main(int argc,char **argv)
{
link_parser(argv[1]);
return 0;
}
---
Warm Regards,
Senthil
> Thanks for the update - I realise that it will take time to get up to
> speed (there is a lot to read through ;)
>
> All the best,
> Alan.
>
> senthil@puggy.symonds.net schrieb:
> Alan,
> Just to keep you updated. I am still reading the code,understanding and
> trying to get started.
> Understood the recent updates,which I viewed using cvs diff.
> I shall email you with things I can puttogether and with the questions I
> have.
>
> ~, just to keep you updated...
>
> Thanks a lot!
> Senthil
>
>
>
>
>> Thanks,
>>
>> In that case I will assign you the link task. Don't worry about the
>> other
>> bugs (incl. -d) option for now as these are code stability details
>> (rather
>> than features) so I will clean them up as I would like to create a
>> workable distribution tarball reasonably soon.
>>
>> Now that you have installed, configured and got rapple to run then any
>> feedback concerning the documentation on the web would also be useful
>> (or
>> indeed anything you think needs to be added to the faq).
>>
>> Regards,
>> Alan.
>>
>>
>> senthil@puggy.symonds.net schrieb:
>> Hi Alan,
>>
>> Yeah, I would like to work on this module.
>> I have updated the rapple cvs and saw the digest file as well. But did
>> not
>> check the functionality yet.
>> I shall work on both the parser and handler part. I was also looking
>> into
>> the -d option feature request.
>>
>> I shall start the work on Monday, if it is ok with you. else, u can
>> assign
>> me any other other task as well.
>>
>> I am going to attend my friends wedding tommrow and I will be back home
>> only on Monday.
>>
>> Thanks for explaining this to me. I have come across and coded few
>> parser
>> related snippets from K&R, Together with that and with the other rapple
>> files, I think I should be able to do this.
>>
>> Regards,
>> Senthil
>>
>>
>>
>>
>>> Senthil,
>>>
>>> Here is a suggestion for a self contained but
>>> challenging task you might be interested in: do you
>>> want to give a try at writing the link checker parser
>>> (Task 115866) ?
>>>
>>> The idea is that there are two files involved: a
>>> parser and a handler. The handler invokes the parser
>>> and passes files to it, e.g., the handler would
>>> recursively traverse a directory tree and invoke the
>>> parser on each transformable file it can find.
>>>
>>> The parser is limited to processing inndividual files
>>> but would work like this: it reads the input file and
>>> scans it looking for certain elements that have
>>> attributes that link to resources (e.g., "img", "a").
>>> When it finds such an element it checks the
>>> appropriate attribute (e.g., for "img" it is "src" and
>>> for "a" it is "href") and checks to see if the
>>> resource being pointed to exists (e.g., is the "src"
>>> or "href" file present in the datastore). For now I
>>> would not propose you check external links (e.g., if
>>> "href" begins with "http://" then just ignore it and
>>> also ignore "mailto:" links etc.) The parser should
>>> generate a link report as it goes along (perhaps just
>>> naming files that are missing).
>>>
>>> If you have never worked with parsers before (they can
>>> be a bit confusing at first) then take a look at
>>> "digestp.*" files (which are the parsers) and
>>> "catalog.*" (which are handlers) for the digest parser
>>> I wrote last weekend (you will have to update your
>>> local working copies if you have not done so
>>> recently).
>>>
>>> If you like I can write the handler for you so that
>>> you can focus on the parser - other parser examples
>>> can be found in the examples directory of the expat
>>> source code.
>>>
>>> Let me know what you think.
>>>
>>> Regards,
>>> Alan.
Cntl + Alt +Fn* Does not work in Fedora Core 4
But thing is this is a bug in Fedora Core 4.Quite a serious one dude, especially if you cant switch to Virtual Terminal after X has loaded using Cntl+Alt+Fn.Finger poining to Somebug in latest X.org offering will not do.
For people who have stumbled here, try the below suggestion. It worked for me.
From Mike A. Harris
Bojan: Please try replacing the libvgahw.a module (after backing up the
original), with the following one:
ftp://people.redhat.com/mharris/libvgahw.a
This one is taken from the latest FC3 errata release, and many people
claim it solves the problem. If you could confirm this for me, it would
help us in solving the problem for a future update.
Thanks in advance.
Genesis

Imagine a world as being covered with a dark atmosphere, choking with smoke and clouds, air so thick that no light could glimmer through it - well, this is what our earth would soon look like. The black background symbolizes this darkness, pollution, smoke and all the bad elements arising out of man's creation.
With growing temperature, rising global warming, ozone layer depletion, and the earth is becoming a ball of fire. The varying shades of yellow, orange and red in concentric circles depict the exponential growth of the intensity of fire with time.
To prevent his cherished creation going in perils, God comes to rescue. This super human power extends his hand to help mankind. His touch creates a spark, giving rise to a strong thought of a new green revolution on earth. Man needs to be aware of this to bring back the old greener earth where he lived. As this small thought gets created on each human mind, the beautiful twigs sprout into tender green leaves.
Let this GENESIS of thought for a "green revolution" be deep rooted in the human mind.
- Collage by Praveen,Aarthi,Raj and Senthil prepared for the Environment day.
To known only uncommented lines
Now I want to extract only the settings to a different file to concentrate on it,add more,delete etc. and keep the commented file for reference only.
How do I separate the settings from the comments.
For eg, In /etc/Muttrc
#
# System configuration file for Mutt
#
# default list of header fields to weed when displaying
#
ignore "from " received content- mime-version status x-status message-id
ignore sender references return-path lines
# imitate the old search-body function
macro index \eb '/~b ' 'search in message bodies'
---------------------------------------
Separate the following lines from above.
ignore "from " received content- mime-version status x-status message-id
ignore sender references return-path lines
macro index \eb '/~b ' 'search in message bodies'
and then saving to a different file should do.
man page under vim
which means that the cursor is under the topic and you press Capital K.
ctags and some vim stuff
:!ctags . [ . for the current file ]
OR
:!ctags * [ * for all the .c and .h files, if you are in a src directory]
Now, the next time you stumble across a function name,variable name and you want to know its declaration, then just do a CNRL + ]. Thats it! Quite useful.
Another feature of Vim is Auto-completion. for example
#include<expat.h> has number of XML related declarations typing the first few characters of variable and then doing CNTL+N
should provide you list for the auto-completion. Interesting, huh?
XML_ERROR_JUNK_AFTER_DOC_ELEMENT
XML_SetProcessingInstructionHandler
XML_SetUnparsedEntityDeclHandler
XML_SetExternalEntityRefHandlerArg
I could have never typed the above properly (without losing my sense, CNTL+N helped me)
...creating a tags file is the first thing I do when browsing a program
- Bram Moolenar in Vim: Seven habits of effective text editing.
gt
#!/bin/bash
# Calling gnome-terminal which fills the display area
# hides the menu bar
# when used as a startup, this would give a terminal over the X
# Thus helping the people who have the habit of opening the gnome-terminal the first thing, they login in init 5.
# Those kind prefer init 3 in the /etc/initrd, but this script should help provide a near possible setup ;)
exec gnome-terminal --geometry=125x39+0+0 --hide-menubar --tab --active --tab --tab
exit 0
I have put this script to load as a startup program in GNOME using gnome-session-properties.
looking for command line way to include scripts / bins in the startup (when X starts).
Peeking through. the .gnome2 in the ~/ had some file called session-manual which had
[Default]
num_clients=2
0,RestartStyleHint=3
0,Priority=50
0,RestartCommand=/usr/bin/firefox
1,RestartStyleHint=3
1,Priority=50
1,RestartCommand=/usr/local/bin/gt
As always, there should be a better way, a more understandable way, to include a script/ bin to start automatically at the startup.
~