My blog on Linux and programming. Covers Linux, VoIP, C, mysql, php and everything else that I come across while tinkering with my Linux boxes.
Sunday, August 23, 2009
mysql-embedded
Well, I was looking at sqlite last week. But while doing a yum update I found this rpm package. "mysql-embedded". On doing a rpm -qi, it told me that this is a C interface to mysql that can directly be embedded in your application. I haven't tried it yet. But I am sure its going to be interesting. The package has only one shared library. However the size is ~7.5M. If I happen to use it, will post again here.
Sunday, August 9, 2009
Presentation database
My wife asked me for this simple application which will store and display the details of daily presentations that they do at their department. Well, I can create a simple text interface in C and it will not even take me an hour to complete. But, there are constraints.
1. This has to be a graphical application
2. This has to be usable by non-geeks
3. This has to run on MS Windows!
4. This has to be searchable
I was thinking of many things. Till requirement 3, I can manage with some vague wiki/CMS software. (Say twiki with table plugin). However, that is surely not going to be user friendly. I have been recently been working on Java. But, my Java skills are not that good. Besides Java will be a overkill for such a simple application.
It is at this point I noticed sqlite. (Well, this has pained me through firefox cookie database once before this). When I read about it, I found that it has a good tcl API. So, thats it! sqlite+tcl/tk!
I have just started. Will keep updating this space as and when I progress.
1. This has to be a graphical application
2. This has to be usable by non-geeks
3. This has to run on MS Windows!
4. This has to be searchable
I was thinking of many things. Till requirement 3, I can manage with some vague wiki/CMS software. (Say twiki with table plugin). However, that is surely not going to be user friendly. I have been recently been working on Java. But, my Java skills are not that good. Besides Java will be a overkill for such a simple application.
It is at this point I noticed sqlite. (Well, this has pained me through firefox cookie database once before this). When I read about it, I found that it has a good tcl API. So, thats it! sqlite+tcl/tk!
I have just started. Will keep updating this space as and when I progress.
Saturday, August 8, 2009
__VA__ARGS__
How to create a macro which takes variable number of arguments?
I had to do this as I wanted to replace a printf with a common debug function that can be turned on or off in the runtime. Besides, I wanted to print local variables from that function. The simplest way was to define a macro that will replace the printf.
However, printf takes variable number of arguments. How do I handle that in a macro? The answer was __VA_ARGS__. Using this, you can replace (more or less) any printf with something like what is shown below.
The downside is, you need to have minimum of two arguments for printfs. If you do not have minimum two arguments, you will get a compilation error.I solve this by providing a dummy variable.
The gcc way of doing this is different. That depends on the the pre-processor operator ## to achieve this. This method will help you solve the empty argument issue.
I had to do this as I wanted to replace a printf with a common debug function that can be turned on or off in the runtime. Besides, I wanted to print local variables from that function. The simplest way was to define a macro that will replace the printf.
However, printf takes variable number of arguments. How do I handle that in a macro? The answer was __VA_ARGS__. Using this, you can replace (more or less) any printf with something like what is shown below.
#define DBG_PRN(x,...) do {\
if ( is_debug_on() )\
{\
printf(x,__VA_ARGS__);\
}\
}while(0);
The downside is, you need to have minimum of two arguments for printfs. If you do not have minimum two arguments, you will get a compilation error.I solve this by providing a dummy variable.
The gcc way of doing this is different. That depends on the the pre-processor operator ## to achieve this. This method will help you solve the empty argument issue.
Saturday, July 18, 2009
Quick popup
Today I was downloading a file using bittorrent. I was using my laptop. I kept it on my lap and started working on a document when download was going on. After a while I noticed that the download has stopped. When I checked, I found that the network cable had come out. This repeated for a while and I found that how much ever I try, the cable will come out slowly as it was not really fitting in the socket. By the time I notice this, 10-15 minutes would have elapsed without network.
How do I know just when it gets disconnected? I was running XFCE. I knew that XFCE allowed to create widgets that can do this for me. But, reading and understanding them and again writing one will take time. Also, I cannot use any built in one as I want a real popup. (My panel auto hides. Can't waste height on a wide screen monitor).
This is what I did.
while sleep 1 ;
do
ping -c 3 www.google.com ;
[ $? == "1" ] && xterm -e "wall trouble && sleep 10";
done
Thats all! When my network went down, xterm just screamed on my face that there is trouble. Then I will push the cable a bit and press ctrl-c to dismiss the message. I love xterm... :)
How do I know just when it gets disconnected? I was running XFCE. I knew that XFCE allowed to create widgets that can do this for me. But, reading and understanding them and again writing one will take time. Also, I cannot use any built in one as I want a real popup. (My panel auto hides. Can't waste height on a wide screen monitor).
This is what I did.
while sleep 1 ;
do
ping -c 3 www.google.com ;
[ $? == "1" ] && xterm -e "wall trouble && sleep 10";
done
Thats all! When my network went down, xterm just screamed on my face that there is trouble. Then I will push the cable a bit and press ctrl-c to dismiss the message. I love xterm... :)
/dev/port
This is something that I had known for years but never had a chance to try out. Recently I had to write a program to control parallel ports. I decided to do with iopl and in/outb. However, they did not work for me. Then I tried this. Just open the file, seek till where your parallel port is, write the data! It worked like a charm. Below is a small code snippet to do it.
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
int fd1=-1;
unsigned char data=0xaa;
fd1=open("/dev/port",O_RDWR|O_NDELAY);
if ( fd1 < 0 ) return fd1;
lseek(fd1,(0x378+0x00),SEEK_SET);
write(fd1,&data,1);
return 0;
}
You will have to change 0x378 to your parallel port base address. Also data is at offset 0, status is at offset 1 and control is at offset 2.
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
int fd1=-1;
unsigned char data=0xaa;
fd1=open("/dev/port",O_RDWR|O_NDELAY);
if ( fd1 < 0 ) return fd1;
lseek(fd1,(0x378+0x00),SEEK_SET);
write(fd1,&data,1);
return 0;
}
You will have to change 0x378 to your parallel port base address. Also data is at offset 0, status is at offset 1 and control is at offset 2.
Subscribe to:
Posts (Atom)