Wednesday, May 23, 2012

setup of IP camera

Thursday, May 10, 2012

Vim plugin


http://www.thegeekstuff.com/2009/04/ctags-taglist-vi-vim-editor-as-sourece-code-browser/


Ctags and Taglist: Convert Vim Editor to Beautiful Source Code Browser for Any Programming Language

by SATHIYAMOORTHY on APRIL 20, 2009
Code C Program using Vim Editor
Photo Courtesy: mint imperial
This article is part of the on-going Vi / Vim Tips and Tricks series. As a programmer or system administrator, you will be constantly browsing source codes and shell scripts.

Following are some typical activities that you may perform while browsing a source code file:
  1. Navigating to the function definition by specifying the function name.
  2. Navigating to the function definition from ‘function call’.
  3. Returning back again to function call from the definition.
  4. Viewing the prototype/signature of functions or variables.
  5. Viewing the number of functions in a file, etc.,

In this article, let us review how to perform the above activities efficiently in Vim editor usingctags and taglist plugin.

The techniques mentioned in this article using Vim editor can be used for any programming language.

I. Ctags Package Install and Configure

Step 1: Installing ctags Package

# apt-get install exuberant-ctags

(or)

# rpm -ivh ctags-5.5.4-1.i386.rpm
warning: ctags-5.5.4-1.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing...          ########################################### [100%]
   1:ctags            ########################################### [100%]

Step 2: Generating ctags on your source code

Go to the directory where your source code is located. In the example below, I have stored all my C programming source code under ~/src directory.
# cd ~/src

# ctags *.c
The ctags command will create a filename tags the will contain all required information (tags) about the *.c program files. Following is partial output of the tags entries in the ctags file.
# cat tags
AddAcl  dumputils.c     /^AddAcl(PQExpBuffer aclbuf, const char *keyword)$/;"   f       file:
ArchiveEntry    pg_backup_archiver.c    /^ArchiveEntry(Archive *AHX,$/;"        f
AssignDumpId    common.c        /^AssignDumpId(DumpableObject *dobj)$/;"        f

II. 4 Powerful Ctags Usages inside Vim Editor

1. Navigate to function definition by specifying the function name using :ta

In the example below, :ta main will take you to the main function definition inside the mycprogram.c
# vim mycprogram.c
:ta main
By using this facility you can navigate to any function definition by specifying the function name.

2. Navigating to the function definition from ‘function call’ using Ctrl + ]

When the cursor is under the function call, then press CTRL + ] to go to the function definition. In the following example, when the cursor is in the function call ssh_xcalloc, pressing Ctrl + ] will take you to the ssh_xcalloc function definition.
# vim mycprogram.c
            av = ssh_xcalloc(argc, sizeof(char *));
Note: If the ctags couldn’t find that function, you’ll get the following message in the vim status bar at the bottom: E426 tag not found ssh_xcalloc

3. Returning back again to function call from the definition using Ctrl + t

Press CTRL + t which will take back to the function call again.

4. Navigating through a list of function names which has the similar names

In this example, :ta will go to the function definition whose name starts with get, and also builds a list to navigate with the relevant functions.
# vim mycprogram.c

:ta /^get
Following vim commands can be used to navigate through relevant functions
  • :ts – shows the list.
  • :tn – goes to the next tag in that list.
  • :tp - goes to the previous tag in that list.
  • :tf – goes to the function which is in the first of the list.
  • :tl – goes to the function which is in the last of the list.

III. Taglist Plugin: Vim Editor as Ultimate Source Code Browser

The above Ctags might have not given a source code browsing feeling, as it is driven by commands instead of visually browsing the code. So if you want to navigate through the source as like navigating in the file browser, you need to use vim taglist plugin which makes vim as a source code browser.
Author of the vim taglist plugin Yegappan Lakshmanan, says about it as
The “Tag List” plugin is a source code browser plugin for Vim and provides an overview of the structure of source code files and allows you to efficiently browse through source code files for different programming languages.

Step 1: Download the Vim Taglist plugin

Download it from from vim.org website as shown below.
$ cd /usr/src

$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701

Step 2: Install the TagList Vim Plugin

$ mkdir ~/.vim # if the directory does not exist already

$ cd ~/.vim

$ unzip /usr/src/taglist.zip
Archive:  /usr/src/taglist.zip
  inflating: plugin/taglist.vim
  inflating: doc/taglist.txt

Step 3: Enable the plugin in the ~/.vimrc

Add the following line to the ~/.vimrc to enable the plugin for Vim editor.
$ vim ~/.vimrc
filetype plugin on
Pre-Requisite: ctags should be installed to use taglist plugin. But it is not a must to generate the tag list manually by ctags command for using taglist plugin.

IV. 5 Powerful Features of Taglist Vim Plugin

1. Open the Tag List Window in Vim using :TlistOpen

# vim mycprogram.c
:TlistOpen
From the vim editor, execute :TlistOpen as shown above, which opens the tag list window with the tags of the current file as shown in the figure below.
Function Browser Window inside Vim Editor
Fig: Vim – Source Code Tag/Function List Windows

2. Jump to the Function Definition inside a source code

By clicking on the function name in the left panel, you would be able to go to the definition of the function as shown in the Figure below.
Jump to a Function inside Vim Editor
Fig: Jump to a function definition quickly
Apart form jumping to the function names quickly, you can jump to classes, structures, variables, etc., by clicking on the corresponding values from the tag-browser in the left hand side.

3. Jump to the function definition which is in another source file

When you are going through a function in a source file and would want to go to the function definition which is in another file, you can do this in two different methods.

Method 1:

If you had the ctags generated for that file, when the cursor is in the function call pressing CTRL + ] will take you to the function definition. And automatically the tag list window will show the tags for that newly opened file.

Method 2:

Open another file also in the same vim session which will update the tag list window with the information about that file. Search for that function name in the tag list window, and by pressing on that function name in the tag list window you can go to the function definition.

4. Viewing the prototype/signature of functions or variables.

Press ‘space’ in the function name or in the variable name in the tag list window to show the prototype (function signature) of it in the VIM status bar as shown below. In the example below, click on selectDumpableTable function from the Tag-window and press space-bar, which displays the function signature for selectDumptableTable function in the bottom Vim Status bar.
Display Function Prototype inside Vim Editor
Fig: Display Function signature at the Vim Status Bar

5. Viewing the total number of functions or variables in a source code file

press ‘space’ in the tag type in the tag list window, which shows the count of it. In the example below, when the cursor is at ‘function’ press space, which will display the total number of functions in the current source code.
Display Total Number of functions for a source code inside Vim Editor
Fig: Display the total number of functions available in the source code
For effectively writing new source code files using Vim, please refer to our earlier articles:

Recommended Reading

Vim 101 Hacks, by Ramesh Natarajan. I’m a command-line junkie. So, naturally I’m a huge fan of Vi and Vim editors. Several years back, when I wrote lot of C code on Linux, I used to read all available Vim editor tips and tricks. Based on my Vim editor experience, I’ve written Vim 101 Hacks eBook that contains 101 practical examples on various advanced Vim features that will make you fast and productive in the Vim editor. Even if you’ve been using Vi and Vim Editors for several years and have not read this book, please do yourself a favor and read this book. You’ll be amazed with the capabilities of Vim editor.

screen man page


screen Multiplex a physical terminal between several processes (typically interactive shells). Syntax: Start a screen session: screen [ -options ] [ cmd [args] ] Resume a detached screen session: screen -r [[pid.]tty[.host]] screen -r sessionowner/[[pid.]tty[.host]] Options: -A -[r|R] Adapt all windows to the new display width & height. -c file Read configuration file instead of .screenrc -d (-r) Detach the elsewhere running screen (and reattach here). -dmS name Start as daemon: Screen session in detached mode. -D (-r) Detach and logout remote (and reattach here). -D -RR Do whatever is needed to Reattach a screen session. -d -m Start in "detached" mode. Useful for system startup scripts. -D -m Start in "detached" mode, & don't fork a new process. -list List our SockDir and do nothing else (-ls) -r Reattach to a detached screen process. -R Reattach if possible, otherwise start a new session. -t title Set title. (window's name). -U Tell screen to use UTF-8 encoding. -x Attach to a not detached screen. (Multi display mode). -X Execute cmd as a screen command in the specified session. Interactive commands (default key bindings): Control-a ? Display brief help Control-a " List all windows for selection Control-a ' Prompt for a window name or number to switch to. Control-a 0 Select window 0 Control-a 1 Select window 1 ... ... Control-a 9 Select window 9 Control-a A Accept a title name for the current window. Control-a b Send a break to window Control-a c Create new window running a shell Control-a C Clear the screen Control-a d Detach screen from this terminal. Control-a D D Detach and logout. Control-a f Toggle flow on, off or auto. Control-a F Resize the window to the current region size. Control-a h Write a hardcopy of the current window to file "hardcopy.n" Control-a H Begin/end logging of the current window to file "screenlog.n" Control-a i Show info about this window. Control-a k Kill (Destroy) the current window. Control-a l Fully refresh current window Control-a M Monitor the current window for activity {toggle on/off} Control-a n Switch to the Next window Control-a N Show the Number and Title of window Control-a p Switch to the Previous window Control-a q Send a control-q to the current window(xon) Control-a Q Delete all regions but the current one.(only) Control-a r Toggle the current window's line-wrap setting(wrap) Control-a s Send a control-s to the current window(xoff) Control-a w Show a list of windows (windows) Control-a x Lock this terminal (lockscreen) Control-a X Kill the current region(remove) Control-a Z Reset the virtual terminal to its "power-on" values Control-a Control-\ Kill all windows and terminate screen(quit) Control-a : Enter command line mode(colon) Control-a [ Enter copy/scrollback mode(copy) Control-a ] Write the contents of the paste buffer to stdin(paste) Control-a _ Monitor the current window for inactivity {toggle on/off} Control-a * Show a listing of all currently attached displays. When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would. Then, at any time, you can: Create new (full-screen) windows with other programs in them (including more shells) Kill existing windows View a list of windows Switch between windows - all windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the user's terminal. The interactive commands above assume the default key bindings. You can modify screen’s settings by creating a ~/.screenrc file in your home directory. This can change the default keystrokes, bind function keys F11, F12 or even set a load of programs/windows to run as soon as you start screen. Attaching and Detaching Once you have screen running, switch to any of the running windows and type Control-a d. this will detach screen from this terminal. Now, go to a different machine, open a shell, ssh to the machine running screen (the one you just detached from), and type: % screen -r This will reattach to the session. Just like magic, your session is back up and running, just like you never left it. Exiting screen completely Screen will exit automatically when all of its windows have been killed. Close whatever program is running or type `Exit ' to exit the shell, and the window that contained it will be killed by screen. (If this window was in the foreground, the display will switch to the previous window) When none are left, screen exits. This page is just a summary of the options available, type man screen for more. "Growing old is mandatory, but growing up is optional" - Motto of the Silver Screen Saddle Pals ======================================== Using screen (virtual terminal multiplexer) What is screen? “Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells).” (from man page) In every-day use you just type $ screen and it seems that nothing happens. :) In fact a program is run that manages multiple bash processes and allows doing cool stuff in console(s) without having to run X. Basics Ctrl+a is a basic command that allows you to control screen. After you've pressed Ctrl+a your input is not being sent to current console, but to the screen itself. That's where you issue one-letter commands. (and more, but let's not get you confused) basic commands Ctrl+a c - create new console Ctrl+a n - switch to next console (it loops) Ctrl+a p - switch to previous console (it loops) Ctrl+a a - send Ctrl+a combination to the program, I didn't want to call screen Ctrl+a k - kill current console (asks to confirm)(ends screen when last console is killed) Ctrl+a d - detach - exits screen but leaves consoles and theri processes running For jornada it might be comfortable to bind winkey to do Ctrl+a. I'll expand the tutorial when I find the best way to do it. Copy and paste [[awesome]] You like using links browser in text mode, but you hate having to start X or use wget to copy some text from a page? Screen is the answer! Ctrl+a [[ - switch to copy mode - then use arrows to move cursor - press Enter to start selection - move cursor to the end - press Enter again Now switch to another console with your awesome script being developed in an editor or just jump to a textfield on a page… Ctrl+a ]] - pastes the copied text Useful for transporting data between two separate instances of screen or for using copied text as an input file for programs: Ctrl+a > - writes copied buffer to a file given in config (/tmp/screen-exchange by default, but don't go looking through options - it'll tell you where it writes) Ctrl+a < - loads the file to buffer Splitting screen You can split your screen and display two (or more, but…) consoles at the same time. Screen avaliable in jlime repos supports only horizontal splitting, so I won't mention the vertical splitting keys. Ctrl+a S - does the split (S is Shift+s and it has to be capital S) - new screen region is created - you probably want to press //Ctrl+a c// to start a new console in there Ctrl+a Tab - switches between visible splits Ctrl+a :resize (Enter) - prompts for number of lines and resizes current split Ctrl+a X - removes current split Monitoring activity If you work in one console and running something in another you might want to monitor it. Ctrl+a M - starts monitoring current console for changes (Will inform you when a program outputs something new. Good for IM clients) Ctrl+a _ - start monitoring current console for silence (Will inform you when a program stops outputting new stuff. Good for compiling or downloading with wget) Sessions and attaching Mostly useful when working on a remote machine with screen, but you might want to know this. When you loose a connection or leave screen with Ctrl+a d your processes stay there. You might want to get to them again I suppose :) $ screen -ls There is a screen on: 21209.pts-0.computername (Detached) 1 Socket in /var/run/screen/S-username. To get back to the running screen type $ screen -r 21209 21209 in both examples above is a PID of the screen process. ===================================== http://snipplr.wordpress.com/2012/04/07/my-screenrc-with-custom-hardstatus-and-easy-switching-between-screens/ screen setup with custom hard status and dialog menu Posted on April 7, 2012 The following set of scripts produce a nice screen setup along with a dialog menu for the most common tasks. This is how it looks like And this is how it’s done. Please see inline comments for details. 01 #!/bin/bash 02 ## use shift-left/right to switch between windows 03 ## use ctrl-n to add new shellwindow 04 ## use shift-PgUp/PgDown for scrolling history hit esc to stop 05 ## use ctrl-a-k for killing a window 06 ## mark area with space, end marking with space, paste with ctrl-a-] 07 setenv TERM xterm 08 09 #kill startup messes 10 startup_message off 11 12 # detach on hangup 13 autodetach on 14 15 # define a bigger scrollback, default is 100 lines 16 defscrollback 4096 17 18 # shell 19 shell -bash 20 21 #make scrollbar work 22 termcapinfo xterm ti@:te@ 23 24 defmonitor on # turn monitoring on 25 activity "%" # tell me when stuff happens! 26 27 # Make shift-PgUp and shift-PgDn work like they do in xterm. (Note that this 28 # requires xterm to be configured to pass those keys through, and not try to 29 # act on them itself.) 30 bindkey "^[O2A" eval "copy" "stuff ^b" 31 bindkey -m "^[O2A" stuff ^u 32 bindkey -m "^[O2B" stuff ^d 33 34 bindkey "^[O2D" prev 35 bindkey "^[O2C" next 36 37 # ctrl-N for new window 38 bindkey "^N" screen 39 40 # ctrl-a-b to copy selection to osx-clipboard 41 #bind b eval "writebuf" "exec sh -c 'pbcopy < /tmp/screen-exchange'" 42 43 # Window numbering starts at 1, not 0. 44 bind c screen 1 45 bind 0 select 10 46 47 # Run everything in UTF-8. 48 defutf8 on 49 # If a window goes unresponsive, don't block the whole session waiting for it. 50 nonblock on 51 52 # An alternative hardstatus to display a bar at the bottom listing the 53 # windownames and highlighting the current windowname in blue. (This is only 54 # enabled if there is no hardstatus setting for your terminal) 55 # see http://www.debian-administration.org/articles/560 56 hardstatus on 57 hardstatus alwayslastline 58 hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a " 59 60 screen -t selector sh screen-selector.sh I use this via screen -c selector-screenrc. The helper script for initializing a screen session looks like this and would either connect to an existing one or create a new one. 1 #!/bin/bash 2 3 screenpid=`ps x|grep -E '(.*)SCREEN(.*)selector-screenrc\$'|awk '{print \$1}'|head -1` 4 if [ $screenpid -gt 0 ]; then 5 screen -x $screenpid -c selector-screenrc 6 else 7 screen -c selector-screenrc 8 fi The screen-selector.sh file is a bonus and provides a dialog menu for frequently used commands. It looks like this 01 #!/bin/bash 02 03 while [ 1 ]; do 04 05 select=`/opt/local/bin/dialog --stdout --menu "select task" 20 60 13 \`cat tasks | tr '\040' '_' | tr '\012' '\040'\`` 06 07 echo "selected $select" 08 09 if [ ! -z $select ]; then 10 11 echo $select 12 13 command=`grep $select tasks|awk 'BEGIN{FS=OFS="\t"}{print \$2}'|tr -d "\""` 14 15 echo "executing command \"$command\"" 16 17 $command 18 # sleep 2 19 else 20 exit 0 21 fi 22 23 done The “tasks” file holds a simple list of tasks/commands. See the example below. 1 su "screen -t rootshell sudo su -" 2 newshell "screen -t shell"

Tuesday, May 8, 2012

Data structure


http://www.data-structure-definition.blogspot.in/