WordPress syntax highlighting – String matching

So yeah i wanted to do this for ages! Proper code posting that works i played a lot with almost all plug-ins i am sure and like none of them worked for me and i just know it was probably something stupid but i really don’t know much about web-development if it isn’t talking about pointers to memory and command line interfaces it doesn’t interest me rofl…

People laugh at me using mplayer at work for my music player in a tty but i just prefer it at the moment i like applications like songbird etc but no music application except aTunes has had good music database refreshing. What i mean is generally most music applications like you add your music to them thats dead on but if you manually manipulate that directory and move rename or delete the previous entries are still there! And there is never a refresh button to go through the folders and clean the database!

Anyways so i want to re-post my string matching algorithm because i love it :) saves me a lot of time in some programs because in c there doesn’t seem to be that many nice string functions other than strcmp strcat and the relevant strncmp strncat for buffer-overflow and stack smashing error handling..

So here it is:

  1.  
  2.   /**
  3.   * @param str -> string you want to search through
  4.   * @param comap -> the string you want to search for in the str*
  5.   * @returns the the postion the comparison is in the string else -1
  6.   */
  7.   extern size_t str_getPlace( char* str, char* comp){
  8.  
  9.   size_t i, counter, complen=strlen(comp), skip_counter=0;
  10.   i=complen-1;
  11.  
  12.   for (;;) {
  13.     //printf("no: %i – orig: %c – %c\n",i,str[i],comp[complen-1]);
  14.     if( comp[complen-1] == str[i] ) {
  15.       //reset counter = 1 as we found one char already :)
  16.       counter=1;
  17.       if(complen > 1) {
  18.   int j;
  19.   for(j=complen-2; j>-1; –j){
  20.     –i;
  21.     if( comp[j] == str[i] )
  22.       counter++;
  23.     else{
  24.       //skipping length + the counter of already checked
  25.       i+=complen+counter;
  26.       break;
  27.     }
  28.   }
  29.       }
  30.       //printf("Counters: comp length: %i -counter %i\n",strlen(comp),counter);
  31.       if ( counter == strlen(comp) )
  32.   return i;
  33.     } else {
  34.       //if i is bigger than length of string or the remaining length is less than the length of the search
  35.       if (i >= strlen(str) || (strlen(str) -i) <= complen ){
  36.   skip_counter++;
  37.   //if skipped more than the length of the search as there is no match!
  38.   if( skip_counter >= complen )
  39.     break;
  40.   else
  41.     i=complen+skip_counter-1;
  42.       } else
  43.   i+=complen;
  44.     }
  45.   }
  46.   return -1;
  47. }
  48.  

I really shouldn’t be returning -1 when the function returns type size_t but that can be changed quickly! So lets see how this looks
So recently i have been getting interested in lots of work! I am concentrating on certain things and in my previous post i moved my main work over to launchpad. But i guess my main projects are:

silix-kernel, silix-compiler (just to be basic front-end compiler with gmp possibly)
I am trying to decide to make either a nice working compiler using proper libraries or a simple compiler for me to bootstrap gcc when i get my kernel a little further!

The one thing in OS development i see at the minute is that there is like GCC for a compiler and that is pretty much it, and the problem i see with gcc is that say if you make a simple new kernel for a project you still cant bootstrap this onto your computer you have to make yourself a basic iso standard compiler. And even with GCC you depend bison GMP big num library and a few other bits a bobs. So porting this is a simple OS is like like not an easy task! Oh and yeah you need auto tools. So yeah when you get gcc onto your os then your sorted but you need a simple compiler before that to get bash setup etc. But i am by no means even close to getting that far!

To get to that stage i need memory mangement to free deallocated memory! I keep crashing atm. And i need a binary format hopefully something like a.out cant be that bad i think an elf binary could be pretty complicated for me to begin with but even before that i need file-system support! Haha

You can see the amount of work there is into a OS but i love it. I just want more time to work on it. I got that book the Minix book on OS its is really good. Probably one of the best to be very implementation specific.

Anyways moving on! This post is getting quite long and i have work tomorrow, though Rambo 2 has just come on to the tv!

Anyways the main part of this post i want you guys to check out Dan Lynch’s Blog he put up and awesome post on Linux there recently: http://danlynch.org/blog/2009/03/critical/

It was really heart-warming and apparently his web-server died due to the digg-effect ;) . Dan and Fab from Linux outlaws have always been such a great inspiration to me for Linux and free-software. Mainly Linux because shows you normal people apricate what hackers are doing for the community and community tools. Imagine no Firefox or no open-office I’d be buggered! :P

Anyways i spent my st patricks day watching Star-wars and playing quake for a little this morning. But the main part i started playing with drizzle -yacc and twisted python networking framework its insane how powerful it is! It could have so many uses! Check it out over at: http://twistedmatrix.com/trac/

Its really easy to work with and makes sending data around networks really simple and no need for working with sockets :-D Even though i secretly love working with Socket Programming because in the end is just the simplest way it all works. Because i really Hate things like CIM and WBEM whats the point of saturating your network with XML everywhere just to send 32bit number over the network the odd time. And the worst part its so sparse and CIM and Wbem all talk about being cross-platform etc, all you do is draw up schema’s etc, but the problem is CIM and wbem i think has been designed from Client side application designers so in the end you end up with something that works nicely for Client side applications that make it all really abstracted but its a messy system side design.

Keep-your-attention

Keep-your-attention

Anyways this is why i think Twisted should be a good framework,. i have noticed a lot of people are getting into using xmpp for the same kind of thing my problem with xmpp is its great to program with but you rely on a jabber server like openfire, and each component you write has to have its own login and password to xmpp because essentially you are handling everything like you opened a chat-window to your code, which is kind of funny but really whats the need for a whole seprate server you just want your landscape each with a program from which you have a local client app to connect to each of these.

One more thing i have been keeping an up dated Belfast LUG webpage recently over at: http://www.belfastlinux.org/wiki/Main_Page

There is also Planet Belfast Linux which is an aggregation of all our blogs from the Belfast LUG http://planet.belfastlinux.org/

Anyways i might quickly post up a new page on java-ant basics because it should be pretty sort, anyways:

Peace <3 Linux- funny cats ;)

2 comments to WordPress syntax highlighting – String matching

  • Dan

    Hi mate, thanks for the kind words in mentioning my post. Much appreciated. Keep working on that OS hacking too, I wish I had more time to code these days, bit more skill wouldn’t go amiss either :P It sounds really cool, can’t wait to hear more about it. Take it easy :) – Dan

  • I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

    Sarah

    http://www.lyricsdigs.com

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>