Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

Wednesday, August 13, 2008

fun with gnu make utility

This idea is inspired from gnu's humor collections. there is a quote looks like this on that site:
%make love
Make: Don't no how to make `love'. Stop.

It's only a joke and doesn't implemented on every linux distro as far as I now. You wouldn't get a message like that when you type a command 'make love' on a console. But in forum, my friend post a message which almost as same as that joke when he type the command 'make love' in freebsd version 7.0. A message looks like this:
$ make love
Not war.

Because I don't have freebsd 7.0 installed on my lovely pc to see the fact, I start a challenge which mean It should be adopted too in slackware 12.1 that already installed. I check into source file of GNU Make utility on slackware installation dvd, which version is 3.81 as same as the last sources package in its official site. And also, it's the same version that included in freebsd 7.0 when I check on freebsd site repositories.

I'm curious which part of this utility has been modified by freebsd developer. Instead of trying to find out in freebsd version of gnu make, I try to find it from scratch which means from its original source. After consume so much time, I found it in 'remake.c' file. Exactly in complain function from that file. Here's a full modified source from that function:
/* Show a message stating the target failed to build. */
static void complain (const struct file *file)
{
const char *msg_noparent
= _("%sNo rule to make target `%s'%s");
const char *msg_parent
= _("%sNo rule to make target `%s', needed by `%s'%s");

if (!keep_going_flag)
{
if (file->parent == 0)
{
if (strcmp(file->name,"love")==0)
{
fprintf (stdout,"Have fun! :^)\n");
exit(1);
}
else
fatal (NILF, msg_noparent, "", file->name, "");
}
fatal (NILF, msg_parent, "", file->name, file->parent->name, "");
}

if (file->parent == 0)
error (NILF, msg_noparent, "*** ", file->name, ".");
else
error (NILF, msg_parent, "*** ", file->name, file->parent->name, ".");
}


What I modify is just to generate an output like this:

mine@unique:~$ make love
Have fun! :^)


I think this is not the only one trick to generate a message like that, but it work as I want. Now, FreeBSD 7.0 not the only one which can do it. Slackware 12.1 too! ;-)

-Simplicity is yours-

Tuesday, February 27, 2007

Coding day's for fun

this code was inspired from people in forum when ask me an algorithm. this is an implementation from the algorithm. It's only for fun and for wasting a time. also to learn programming language. I hope this's not the last.

Bash script version
-------------------
start here
-------------------
#!/bin/bash
echo -n "Your input: "; read input
let temp=$input/2
let temp=$temp+1
let count=0
let i=1
echo $temp
while ((i<=input))
do
let j=1
let left=1
let right=$input
if [[ $i -le $temp ]]; then
let count=$count+1
elif [[ $i -gt $temp ]]; then
let count=$count-1
fi

while ((j<=input))
do
if [[ $left -le $count ]]; then
echo -n "$left "
elif [[ $right -le $count ]]; then
echo -n "$right "
else
echo -n "$count "
fi
let left=$left+1
let right=$right-1
let j=$j+1
done
let i=$i+1;
echo ""
done

C Version
---------------
Start here
---------------
#filename: funcode.c
int main ()
{
int input, temp=0, count=0;
int i,j,left,right;

printf ("Your input: ");scanf("%d",&input);
printf ("
Dimention: %d \n",input);
temp=(input/2) + 1;
printf("temp: %d \n",temp);

for (i=1; i<=input; i++)
{
j=1;
left=1;
right=input;

if (i <= temp)
count++;
else if (i> temp)
count--;

for (j=1; j<=input; j++)
{
if (left <= count)
printf("%d ",left);
else if (right <= count)
printf("%d ",right);
else
printf("%d ",count);
left++;
right--;
}
printf("\n");
}
return 0;
}

An output is here:
mine@unique:~$ ./funcode
Your input: 5
Dimention: 5
temp: 3
1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1
mine@unique:~$