1. DESIGN PROBLEM
CSE207T
Topic:Design a text editor in linux
Submitted by:
SANJAY KUMAR CHAKRAVARTI
ROLL:A28
SEC:K2R13
REG:11006964
Submitted to:
Mr. Sandeep Ranjan
Cse dept.,LPU
Phagwara,Punjab
144402
2. ABSTRACT
Text editor is highly essential in every operating system.Without text
editor an operating system look likes ,trees without leaves.To Design
a text editor is very tough task.But I have made easy to understand.
This Design Problems gives a learning environment ,with theoretically
and practically.This Design paper contain some features,so why this
will helpful for all.The features are listed below:
1. Modulization of Design problems
2. Comment line in programme
3. Best approach of Algorithms provided
4. Best working model on file
So,these features of text editor in this paper make different to
all.
4. INTRODUCTION
A text editor is used to edit plain text files. Text editors differ from word processors,
such as Microsoft Word or WordPerfect in that they do not add additional formatting
information to documents. You might write a paper in Word, because it contains tools
to change fonts, margins, and layout, but Word by default puts that formatting and
layout information directly into the file, which will confuse the compiler. If you open a
.doc file in a text editor, you will notice that most of the file is formatting codes. Text
editors, however, do not add formatting codes, which makes it easier to compile your
code.
Text editors have a feature set different from that of a traditional word processing
program. For example most won't let you include pictures, or include tables, or
double-space your writing. The features of text editors vary from implementation to
implementation, but there are several kinds of features that most editors have. Below
are listed some of the most common and useful features.
1.Creating a new file
2.Delete an existing file
3.Save a file
4.counting of charaters,words,ros,coloms and etc.
These are basic work of a text editor. An advance text editor contains many features as
following:
1.coloring
2.Font changing
3.Draw panel
5. PREREQUISITE
There are some prerequisite for Design a text editor as given following:
1.Knowledge of „c‟ language
2.Best knowledge of file handling
3.Linux operating
6. DESIGNED METHHODOLOGY
To Design a text editor a plan should must keep in mind which segments
are require at which position.First of all create all requied module using
structures or functions. In this project I have used mostly functions,
becaude it will easily understandable.There are two important steps for
writing a progrrame for text editor as following:
1.Algorithm
2.Code
Now, at first I am discussing about “algorithm” using functions.
ALGORITHM:
F1.
void passwd()
step
1. Enter your name in “name”
2. Enter your age in “age”
3. Pass=rand()/10000+age+(int)name
4. Print remember your password
5. Enter your password in “pas”
6. If (pas==pass) Then call show() function
Else
Print Invalid password try again
Goto step 5.
7. Stop.
void show()
7. step1.print “press following key as given menu:1.Menu 2.Search 3.View
4.Help” in key
Step2: if (key=1)
Then call menu() function
Else if (key=2)
Then call search() function
Else if(key=3)
Then call view() function
Else if(key=4)
Then call help() function
Else
Print “Sorry wrong choice”
Goto step1.
Step3: exit.
void Create()
Step1: call show() function
Step2:open an exist file fp1=fopen(“temp.txt”,”w+”)
Step3: print “Type your text and press ESCAPE to save”
Step4:while(1)
C=getchar();
9. void Delete()
Step1:call function show()
Step2:Enter a file to be deleted in fn
Step3:Open the file i.e fp=fopen(fn, ”r”)
If(fp==NULL),then
Print “File not found
Step4:rm=remove(fn)
If(rm==0),then
Printf “file successfully deleted”
Step5:exit
void Display()
Step1:call show() function
Step2:Enter filename to be open in fn
Step3:open file i.e fp=fopen(fn,”r”)
If(fp==NULL),then
Print “file not found”
Else
While(!feof(fn))
C=getc(fn)
Print value of „c‟
Step4:exit
10. void search()
Step1:call function show()
Step2:Enter string to be search in str
Step3:system(grep “$str” temp.txt)
Step4:exit
void menu()
Step1:Enter you choice from list:”1.new file 2.open 3.open with editing
4.delete 0.exit” in choice
Step2:if(choice=1),then
Call function create()
Else If(choice==2),then
Call function display()
Else If(choice==3),then
Call function append()
Else if(choice==4),then
Call function delete()
Else
Exit(0)
Step3:exit
11. void count()
Step1:print number of characters is “countc”
Step2:print number of words is “countw”
Step3:print numbers of rows is “row”
Step4:exit
CODE
/*This text editor programme only Run and Compile with linux
operating system*/
#include<stdio.h>
#include<stdlib.h>
int i,j,ec,fg,ec2,countc=0,countw=0,row=1,col;
char fn[20],e,c;
FILE *fp1,*fp2,*fp;
void name();
void cwsh1();
void cws();
void show();
void ohelp();
void fhelp();
void soon();
void look();
void Create();
void sanjeev();
void shubham();
void rahul();
void abhay();
void sanjay();
void Append();
void Delete();
void Display();
void menu();
12. void passwd();
void search();
void count();
void main()
{
system("clear");
passwd();
//show();
}
void sanjeev()
{
printf("nnt");
printf("┬── ─── ─
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ──
──── ──── ─── ───
─── ─── ──── ──── ─── ───
─── ─── ──┐n");
printf("t│ Name: SANJEE KUMAR, age:20 Years is currently study in LOVELY
PROFFESSIONAL UNIVERSITY b.tech 2nd │n");
printf("t│ year. He is a bestc and c++ programmer. His primary and secondary
education in KENDRIYA VDYALYA │n");
printf("t│ NO.-1, bokaro steel city.In class 10th he has got 78% ,In class 12th he has
got 70%. │n");
printf("t│ you can contact with him: │n");
printf("t│ Mob:7837830703 │n");
printf("t│ email: tunsanju@gmail.com
│n");
printf("t┴── ──── ────
─── ── ──── ─── ───
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ──
──── ──── ─── ───
─── ─── ──── ──── ─── ───
─── ─── ───┴n");
int je;
scanf("%d",&je);
switch(je)
{
default:system("clear");
show();
break;
}
}
void search()
{
13. char str[20];
int ser;
printf("tt║1.Copy ║n");
printf("tt║2.Cut ║n");
printf("tt║3.Paste ║n");
printf("tt║4.Back ║n");
printf("tt╚═══════════════╝");
//printf("nnttEnter string to be searched:");
//gets(str);
scanf("%d",&ser);
switch(ser)
{
case 4:system("clear");
show();
break;
}
/*switch(ser)
{
case 1:copy();
break;
case 2:cut();
break;
case 3:paste();
break;
default:exit(0);
}*/
fp1=fopen("temp.txt","w+");
system("grep $str temp.txt");
}
void look()
{
printf("╔═══════════════╦═══════════════╦════════════
═══╦═══════════════╦═══════════════════════╦═════
═══╗n");
printf("║1.Menutt║2.Searcht║3.Viewtt║4.Helptt║5.Corporate with ust║6.Exit
║n");
17. void cws()
{
system("clear");
look();
printf("nnTHIS PROGRAMME IS CREATED BY:SANJAY KUMAR CHAKRAVARTIn");
printf("nttttREG:11006964nnn");
printf("nApart from the efforts of me, the success of this project depends largely on
the encouragement and ");
printf("guidelines of many others. I take this opportunity to express my gratitude to
the people who have been");
printf(" instrumental in the successful completion of this project." );
printf("I would like to show my greatest appreciation to Mr. Sandeep ranjan. I can’t say
thank you enough for his");
printf(" tremendous support and help. I feel motivated and encouraged every time I
attend his Extra classes.");
printf(" Without his encouragement and guidance this project would not have
materialized.");
printf("The guidance and support received from all the team members including
n1.SANJEEV KUMAR(LPU)n2.SHUBHAM PATEL(LPU)n3.ABHAY ");
printf("KUMAR(LPU)n4.RAHUL TEHLANI(LPU)n who contributed and are contributing
to this project, was vital for the success of the");
printf("project. I am grateful for their constant support and help.nn");
}
void ohelp()
{
int fl;
printf("nn");
printf("┬── ─── ─
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ─── ───
─── ─── ──── ──────
──── ──── ─── ───
─── ─── ┐n");
printf("│ │n");
printf("│Please go on following link: │n");
printf("│ 1.www.gnu.com │n");
printf("│ 2.www.cpluplusprogramming.com │n");
printf("│ 3.www.cprogramming.com │n");
printf("│ 4.www.deniweb.com │n");
printf("│ 5.www.math-linux.com/IMG/pdf/Linuxbible.com │n");
18. printf("│ 6.www.ibblio.org/pub/linux/docs/HOWTO-other-formats/pdf/Linux-Init-
HOWTO.pdf │n");
printf("└─ ──── ──
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ─
──── ──── ─── ───
─── ─── ┴n");
scanf("%d",&fl);
switch(fl)
{
default:system("clear");
show();
break;
}
}
void fhelp()
{
printf("nn");
printf("┬── ─── ─
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ──
──── ──── ─── ───
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ┐n");
printf("│A text editor is used to edit plain text files. Text editors differ from word
processors, such as Microsoft │n");
printf("│Word or WordPerfect in that they do not add additional formatting
information to documents. You might write │n"); printf("│a paper in Word, because
it contains tools to change fonts, margins, and layout, but Word by default │n");
printf("│puts that formatting and layout information directly into the file, which will
confuse the compiler. If │n");
printf("│you open a .doc file in a text editor, you will notice that most of the file is
formatting codes. Text │n");
printf("│editors, however, do not add formatting codes, which makes it easier to
compile your code. │n");
printf("│Text editors have a feature set different from that of atraditional word
processing program. For example │n");
printf("│most won't let you include pictures, or include tables, or double- space your
writing. The features of │n");
printf("│text editors vary from implementation to implementation, but there are
several kinds of features that most │n");
printf("│editors have. Below are listed some of the most common and useful features.
│n");
printf("└─ ──── ──
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ─
──── ──── ─── ───
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ┴n");
19. printf("│ 1.Creating a new file │n");
printf("│ 2.Delete an existing file │n");
printf("│ 3.Save a file │n");
printf("│ 4.counting of charaters,words,ros,coloms and etc.│n");
printf("└─ ──── ──
─── ─── ──── ──── ─── ───
─── ─── ──── ──── ───
─── ───┴n");
printf("These are basic work of a text editor. An advance text editor contains many
features as following:n");
printf("┬── ─── ─
─── ─── ──── ──── ─┐n");
printf("│ 1.coloring │n");
printf("│ 2.Font changing │n");
printf("│ 3.Draw panel │n");
printf("└─ ──── ──
─── ─── ──── ──── ┴n");
}
void soon()
{
int so;
printf("nnntt┬─ ────
─── ──── ─── ───
─── ─── ──── ──── ─┐n");
───
printf("tt│ │n");
printf("tt│ This module is under construction │n");
printf("tt│ 0.Return │n");
printf("tt└── ─── ────
─── ── ──── ─── ───
─── ─── ──── ──┴n");
scanf("%d",&so);
switch(so)
{
default:system("clear");
show();
break;
}
}
void view()
{
//printf("nttttt1.Largenttttt2.Smallnttttt3.Mediumn");
printf("tttt║1.Large ║n");
printf("tttt║2.Small ║n");
printf("tttt║3.Medium ║n");
printf("tttt║4.Back ║n");
printf("tttt╚═══════════════╝n");
int vi;