A function and a macro with same name.

~# cat a.c
#include<stdio.h>
#define inc(a) inc(a,1)
int inc(int a, int b)
{
return a+b;
}
int main()
{
int k = 9;
k = inc(k);
printf("%d\n", k);
return 0;
}
~# gcc a.c
a.c:3:21: error: macro "inc" passed 2 arguments, but takes just 1
a.c:4:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
~#

Here both function and macro with same name can't co exist.
Preprocessor performs macro expansion at function definition as well (at line 3).
But we don't want preprocessor to perform macro expansion there.
So we simply enclose the function name with parentheses while defining the function.
And we are done.

~# cat a.c
#include<stdio.h>
#define inc(a) inc(a,1)
int (inc)(int a, int b)
{
return a+b;
}
int main()
{
int k = 9;
k = inc(k);
printf("%d\n", k);
return 0;
}
~# gcc a.c
~# ./a.out
10
~#

Answer Set Programming: with dlv and ASPIDE

- go to http://www.dlvsystem.com/dlv/
- download dlv.x86-64-linux-elf-static.bin
- go to https://www.mat.unical.it/ricca/aspide/download
- chose ".jar packages without installer" to download ASPIDE-Installer-Java-Package.zip
- # mv dlv.x86-64-linux-elf-static.bin dlv
- # chmod a+rx dlv
- extract ASPIDE-Installer-Java-Package.zip, it gives a folder ASPIDE
- go to ASPIDE
- # java -jar startAspide.jar
- internet connection is required here.
- it asks to install latest aspide, chose to install.
- it asks to install aspide add-ons. allow to install it.
- after installation, it asks for registration, register with your name and email.
- it sends a authentication code to mailbox and asks to input authentication code.
- provide authentication code and aspide starts...
- it asks for a project workspace path and then asks for path to dlv, provide them.
- now IDE of aspide opens... close it.
- now onwards aspide can be opened by # java -jar startAspide.jar
however, it needs internet to check updates etc. before starting IDE.
better to use # java -jar application/aspide/aspide.jar
- now IDE opens...
- create a new project
- create a new file : "DLV File with Arithmetic Expressions"
- write an asp program in the file and save it.
- to run the asp program, click Execute->Run.
- to make a query, click Execute->Query.
- query dialog opens, tick the checkbox "Epistemic Mode".
- type the query and suffix it with a question mark, then click "Execute".
- you may need to click "Run Configurations" and set path of dlv executable, if it asks: executable not found.
- enjoy.

Answer Set Programming: with clingo

- goto http://sourceforge.net/projects/potassco/files/clingo/4.4.0/
- download clingo-4.4.0-x86_64-linux.tar.gz
- # tar -xvzf clingo-4.4.0-x86_64-linux.tar.gz
- goto clingo-4.4.0-x86_64-linux folder
- execute an asp program as # ./clingo -n 0 family.lp
- it prints all answer sets; enjoy.

Some low level debugging tools in linux.

nm : just lists symbols from obj file
================
-n sort symbols numerically by address
-D shows dynamic symbols only

Symbol type:
If lowercase, the symbol is local;
if uppercase, the symbol is global (external).
A - symbol's value is absolute, will not be changed by further linking.
B - symbol is in the uninitialized data section (known as BSS).
C - symbol is common. Common symbols are uninitialized data.
D - symbol is in the initialized data section.
N - symbol is a debugging symbol.
R - symbol is in a read only data section.
T - symbol is in the text(code) section.
U - symbol is undefined.

objdump : shows details of obj files
================
-d disassembly
-S mix source code when disassembles
-x display section/program headers
-r display relocation entries
-w more than 80 character wide display

readelf : displays information about contents of ELF format files
================
-a Equivalent to: -h -l -S -s -r -d -V -A -I
-e Equivalent to: -h -l -S

-h Display the ELF file header
-l Display the program headers
-S Display the section headers

-s Display the symbol table
--dyn-syms Display the dynamic symbol table

-r Display the relocations (if present)
-d Display the dynamic section (if present)

-W more than 80 character wide display

good examples:
================
# gcc -c -o test test.c
# readelf -esr test > a.txt

# gcc -g -c -o test test.c
# objdump -drS test > b.txt

PHP code cleaning tools.

PHP LOC statistics:
1. wget --no-check-certificate https://phar.phpunit.de/phploc.phar
2. /opt/lampp/bin/php phploc.phar --exclude="lib" --exclude="Resources" /mnt/data/MyWebProject/ > loc.txt

PHP Mess Detector:
1. Download http://static.phpmd.org/php/2.1.1/phpmd.phar
2. /opt/lampp/bin/php phpmd.phar /mnt/data/MyWebProject/ text codesize --exclude lib,Resources --reportfile code_complexity.txt
[output format: text; available mess detectors: cleancode, codesize, controversial, design, naming, unusedcode]

PHP Code Sniffer (Enforces a coding standard):
1. Download http://download.pear.php.net/package/PHP_CodeSniffer-2.0.0RC1.tgz
2. /opt/lampp/bin/php PHP_CodeSniffer-2.0.0RC1/scripts/phpcs --report-file=code_sniff.txt --standard=Generic --extensions=php --ignore=*/lib/*,*/Resources/* /mnt/data/MyWebProject/

PHP Dead Code Detector:
1. wget --no-check-certificate https://phar.phpunit.de/phpdcd.phar
2. /opt/lampp/bin/php phpdcd.phar --recursive --exclude="lib" --exclude="Resources" /mnt/data/MyWebProject/ > dead_code.txt

PHP Copy Paste Detector
1. wget --no-check-certificate https://phar.phpunit.de/phpcpd.phar
2. /opt/lampp/bin/php phpcpd.phar --exclude="lib" --exclude="Resources" /mnt/data/MyWebProject/ > copy_paste.txt

While searching files with find, exclude some directories

find . -type f -name '*.php' ! -path "./lib/*" ! -path "./Resources/*" -exec vim -s /root/vimscript.scr "{}" \;

To print colored text in linux terminal

echo "$(tput setaf 1) Hello $(tput setaf 2) World! $(tput sgr0)"
or
echo -e "\033[31m Hello \033[32m World! \033[0m"

Option -e means "enable interpretation of backslash escapes"