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

Yeah, I faced it and there was a discussion about this at the Fedora Core list as well.

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

Whenever I look at any config files, it has some settings as well as comments on it.
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'



:g/^#/d


and then saving to a different file should do.

man page under vim

<leader> K - thats it!

which means that the cursor is under the topic and you press Capital K.

ctags and some vim stuff

If you are editing a C program using vim, then create a tag file using ctags

:!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

This is gt a shell script in my /usr/local/bin


#!/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.



~

Commenting Lines using vim for bash,conf file etc

It was needed that I comment a number of lines in a file. The comments of a configuration file are usally like a # in the begining of the line.
So
Line 1
Line 2
Line 3
Should become

#Line 1
#Line 2
#Line 3

HOWTO:

1) Go to the First Column of the First Line.
2) Select the Block using cntl-v (for Linux) and cntl-q(for Windows, because cntl-v is mapped to paste function in gvim under windows)
3) With the Selected test, give the command :s/^/#/
4) That should do!

But vim users always look for yet another way, so I am.

Changeformat.sh

#!/bin/sh

# Change the Format from the ogg files in a directory to aiff

for i in `ls -1 *.ogg`
do
sox $i `echo $i|sed -e "s/ogg/aiff/"`

done

exit 0

Rapple

Rapple is Lightweight XML based transformation tool written in C that builds upon expat, tidylib and XSLT to tranform authored web content (incl. Word processor generated HTML) into styled web content suitable for publication.

Its a nice feeling when becoming member of a sourceforge project.
Thanks a lot Alan, for including me in the development list.
Try the Rapple Demo now!!