Wednesday, March 9, 2011

Non-Printing characters Removal.

There are many characters that print nothing still take space in your document. You use many of these characters every day, but probably don't think of them as characters (as such). The list of non-printing characters that Word uses includes the following:
  • Column breaks
  • Hidden text
  • Newline characters
  • Optional hyphens
  • Page breaks
  • Paragraph marks
  • Section breaks
  • Spaces
  • Tabs
Here I will show you how does these non-printing characters creep into your document, how to view them and how to remove them.

For example: you copy this peace of code below, a simple kernel module and try to compile it with the Makefile and if you really want to prove your self try even to remove those compilation errors...!

Code for test.c:

#include <linux/module.h>  /* Needed by all modules */
#include <linux/kernel.h>/* Needed for KERN_INFO */
#include <linux/init.h> 
#include <linux/version.h>

MODULE_LICENSE(“GPL”)
MODULE_DESCRIPTION(“This is a basic test moudle)
MODULE_AUTHOR(“Vamshi Krishna Gajjela)

int init_module(void)
{
printk(KERN_INFO "My first test module loaded.\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO “Test module unloaded\n");
}

Makefile:

obj-m += test.o

all:
      make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
      make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

after compilation you will end up with stray errors like this, shown in the below image, and these stray errors are because of non printing characters.




















Viewing Non-Printing characters:

To view the non-printing character use the following command as below :

$ cat --show-nonprinting test.c






















Removing Non-Printing characters:

To remove the non-printing character use the following command as below :

$ cat  'test.c' | tr -dc [\\n,[:print:]]> new_test.c

Now the source code is redirected to the new file "new_test.c" which is free from non-printing characters.

Note: Hey this may even remove the double quotes so go through for any such errors in your new_test.c .

No comments:

Post a Comment