Close
0%
0%

Open vi editor with a customised C file template

This is a simple code to develop a command to open a custom template
while creating a C file in Linux(Ubuntu).

Similar projects worth following
We often see that editors in modern IDE's (Integrated Development Environtment) open with in built template. I wanted to do a similar thing in LINUX using the vi editor(mostly because I was tired of writing the same thing again and again). I have been learning basics of system programming where I encountered the exec family of commands and it occurred to me I can make my own command to open a C file with a ready made template.
What you put into the template is only bounded by your imagination(and logic ofcourse!). Mine contains:

1.Code information:This includes desciption about the code, author's name and the time of creation. The code writes user name and time of creation automatically to the file.

2. Header files

3. Main code block

The code is designed to perform the following steps:



1. Taking in the file name as a command line argument.



2. Check if the file, the user wants to creates already exists. If it does just open the file using



execlp("vi","vi",argv[1],NULL);



and if it doesn't, proceed to the next steps.



3. At this point of time we need to have a standard template file(mine is called startupC), the content of which will be copied to the new file using filehandling API's of C. While filling up the new file, the entries to the author and time fields are done by the code itself. The current time of the system is obtained using time() and ctime() functions.



4. After the completion of the code a executable file is to made. My c file name was viC.c and the executable file was named vic.



$cc -g -Wall viC.c -o vic



5. Then, I copied 'vic' to the standard folder /usr/bin and the standard template file to a self made directory /usr/files/




Now that we are done with the dirty work our own command is ready. Use the command:



$vic file.c



and voila! you own C file template with you name on it!

viC.c

The C code <Open with notepad++>

x-csrc - 1.38 kB - 02/02/2016 at 18:23

Download

startupC

The template. <Open with notepad++>

startupC - 304.00 bytes - 01/31/2016 at 16:39

Download

  • 1
    Step 1

    Make the desired template.

  • 2
    Step 2

    Compile the C code and make the executable file.

  • 3
    Step 3

    Copy the executable file and the template file to the standard directories usr/bin and usr/files.

View all 4 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates