Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

text editor in C

Posted on 2001-07-10
11
Medium Priority
?
254 Views
Last Modified: 2013-12-13
Hello.

I am working a project that requires me to develop a new test editor using C programming language.

This text editor should be able to allow the user to do the ff:
    * insert a new char/string
    * delete a char/line
    * save a file in text format.

I'm not that really proficient in C, but i need to have a starting to point to work with in this project.

Any suggestions/comments will be highly appreciated. But please make them simple.

Thanks in advance.
0
Comment
Question by:ylen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 49

Expert Comment

by:dbrunton
ID: 6271753
You are probably going to need an array of arrays to store your data in and a global variable to identify where your cursor is in these arrays.  That's your basic data structure and all else followis from that.
0
 
LVL 2

Expert Comment

by:smitty1276
ID: 6271816
Do you have to "wrap" the lines, or can the user just type and type on a single line as long as possible?  That will make a HUGE difference in how you need to store the data.  A fixed 2D array won't work if the lines aren't wrapped.  

If they are wrapped, you will have to check the length of the lines.  When the line reaches the max length (80 chars?) you will have to drop to the next line.  If the user is in INSERT mode (are you keeping up with that?) you will have to shift the entire array of arrays, starting at the bottom line and moving up, to the right by one character.
0
 
LVL 22

Expert Comment

by:cookre
ID: 6271910
One way of dealing with variable length lines is to store them sequentially with each line prefaced with its' length.  

Insertion performance can be enhanced by using a doubly linked chain of lines.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6272116
In my early projects I made some editor in TurboC 2.01.
Main structures are:

#define  MAXLINES  2000
#define  MAX_LONG   129
#define  WIN_HIGHT   23
typedef  char *LINESS[MAXLINES];
typedef struct {
     LINESS lines;
      char filename[75];
      int  win_hight;     /* Editor window height */
      int  max_long;      /* Max line length */
      int  insert_status; /* INSERT / OVERWRITE */
      int  caps_status;   /* CAPS LOCK-a ( ON / OFF ) */
      int  last_line;     /* Last line */
      int  temp_row;      /* Current file line */
      int  temp_col;      /* Current file column */
      int  screen_row;     /* Current screen line */
      int  screen_col;     /* Current screen column */
      int  first_row;    /* First visible file line */
      int  last_row;     /* Last visible file line */
      int  first_col;      /* First visible file column */
} TEXT_FILE;

All data are saved in that structure.
Text is saved in structure LINESS which is array of char pointers.
There is dynamic allocating for each row of text (on maximum line length).

Any questions.
0
 

Author Comment

by:ylen
ID: 6274361
Thanks for the replies folks.

I know those ideas are going to be really useful. But I what i really wanted is an editor which is similar to vi.
A simple version of vi, that is.

Say for example, the program name is NewEdit.c. If the user type in 'NewEdit newText.txt', the program should be able to remember that the file has to be named as newTest.txt, and a screen will be open to allow that user to start typing/editing. How do i do this?

It's really the UI that's givinng me a hard time.

Shall wait for your comments/replies.

Thanks again.
0
 
LVL 2

Expert Comment

by:smitty1276
ID: 6274414
You can variable to hold the file name...

void main( int argc, char **argv )
{
  //assuming the command line you used above was used
  char *fileName = argv[1];

}

Of course, you may want to thoroughly check out all of the command line arguments to make sure that they didn't enter things in the wrong order.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 6277659
> It's really the UI that's giving me a hard time.

You may want to also say what is already done (or will be soon) so we need not be redundantly repetetive and can focus better. [not that I good at that part, ;) ]

Can we say you want us focus on the command line interpreter piece? Or the visual editing? We can skip macros, of course. And fancy mass replacements. True?

You may well benefit from having the very last line (or top edge) of your screen be completely reserved for entry of manual commands. This avails you of good visual feedback of the input hitting your code (and text). Consider using the exact opposite of screen (bottom or top) to be simple status display, such as for the currently defined current filename. Current row&column. Etc.

You may want to invent commands. Once they are mapped out, come back and ask on_it.  For example, one command or special key on keyboard can be reserved to move the program focus from command line entry to visual editing. So you really have two Main program functions, that can nearly run complete on their own fairly running standalone.

Once in the visual editing main program, one main new piece is functions utilizing the cursor keys. Now, is this the place where you need the more help? The MadYugoslav structure seems fit to start with for a stripped down VI emulation.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 6277731
> allow that user to start typing/editing. How do i do this?

1) Fill screen displaying lines retrieved
2) Place cursor on last line for my example of command line entry
3) Enter something like "IHello World" <enter>
4) The screen should now place "Hello World" on very first line, while all other lines scroll down.

In my language, I defined symbol
"I" for insert command
and <enter> to complete it (also part of text entry).

You too must define a minimal command set. I take it you may be confused on the visual handling with mixing of commands, input characters, cursors, etc.

Thus I suggest you first get the commands to work, using less visual technique, but more manageable.

While doing so, your code should increase in value for functions like scrolling and buffering, so you can focus more on UI having confidence that the other scrolling and buffering is already in order (or, have you already done that part?)
0
 
LVL 2

Expert Comment

by:curri
ID: 6283320
Also, which library are you using for screen management ? may I recommend curses (it is available for unix and windows, probably for almost everything else :).

Basically you need some way of displaying characters at specific places on the screen. With just cout it is going to be a huge pain :)

When I did my first text editor I used direct memory access on the video memory (under DOS, about 10 years ago :)

Orlando
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7487623

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - PAQ'd and pts removed
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7518837
Per recommendation, points NOT refunded and question closed.

Netminder
EE Admin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Introduction to Processes

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question