PDA

View Full Version : Editor in turboc



Gopala Krishna
12th September 2007, 13:24
Hi fellows,
We , in our college are supposed to code a text editor similar to the edit in dos using turbo c(i know its age old ;) ) without using any graphics (i.e no graphics.h utilities)
Since we are supposed to stick on to using C (no c++ :( ) I decided to use this opportunity to learn c in depth. So far i am able to display typed text and move cursor but i have these to problems

*) Which is the best data structure to store the text being displayed ? Currently i am using char array for testing purpose. Linked lists might fit in well but i want to know whether there are other efficient data structure or modified forms of data structure for this purpose ?

*) Secondly i don't have a clue on how to implement scrolling ? In one of the dos book there was an interrupt to do scrolling but i didn't understand how this works :p We are using framebuffer to display the text directly.

Can you people please help me out ? :)

wysota
12th September 2007, 21:47
You can emulate a data structure that is called a rope.

http://en.wikipedia.org/wiki/Rope_(computer_science)

See the links at the bottom.

As for scrolling... well.. did you try the obvious approach? :)

Gopala Krishna
13th September 2007, 17:18
You can emulate a data structure that is called a rope.

http://en.wikipedia.org/wiki/Rope_(computer_science)

See the links at the bottom.

As for scrolling... well.. did you try the obvious approach? :)

The rope seems to be pretty much what i wanted. I'll think about it. Meanwhile i am open to other ideas as well :)

The only approach i know is to paint/write everything manually to get the effect of scrolling(based on current column). But there should be memove or some similar trick which can be used to emulate scrolling rather than rewriting everything. May be the interrupt works this way.

wysota
13th September 2007, 23:56
Did you already ask your teacher the fundamental question "Why don't we use Qt instead of wasting time for implementing things nobody wants to use anymore?"?

Gopala Krishna
14th September 2007, 11:07
Did you already ask your teacher the fundamental question "Why don't we use Qt instead of wasting time for implementing things nobody wants to use anymore?"?

I am the only person knowing c++ (qt too :cool: ) amongst the students. Infact we are *starting* to learn data structures (from stack) now. This project is supposed to help us master C in better way and i think they are right. I am just a bit ahead of them :rolleyes: Also using qt at this level will be too fancy and i will be the odd one out.

But one good outcome would be i'll understand some basics in depth, for eg the interrupts and writing directly to frame buffer are nice concepts. I'll understand how exactly scrolling is done.

wysota
14th September 2007, 11:18
I am the only person knowing c++ (qt too :cool: ) amongst the students. Infact we are *starting* to learn data structures (from stack) now. This project is supposed to help us master C in better way and i think they are right.
By manipulating the frame buffer directly? I don't think so. It's not portable, may not work, etc. It's simply a dead end.


But one good outcome would be i'll understand some basics in depth, for eg the interrupts and writing directly to frame buffer are nice concepts.
What does it have to do with C or data structures?


I'll understand how exactly scrolling is done.
It's architecture dependent, so you'll only understand how scrolling is done in this single case. When you'll be given another architecture, you'll have to start learning from scratch. That's what I mean when I say the task is useless (unless you'll be writing your own device drivers, but I don't think that a good way to start learning C).

Gopala Krishna
14th September 2007, 13:11
Your advice may be perfect for me but not my other classmates since they really don't know anything other than turboc for now. That is the only IDE familiar to them which involves nice context help built in. So doing a small functional editor(similar to edit) will sprout interest in them , atleast that is what my teacher assumes. Since my classmates know only c and some dos programming , they can achieve this for now. So they cant think about portability at this stage. One more advantage for starters will be , some understanding on how events are generated and how to handle them.
I didn't want to be odd one out and so joined to help others too.
My idea is to do something special in this. For example i have better idea to handle the events and catch interrupts at right place. I am trying to be perfectionist in as many areas as possible and also would like to learn advanced data structures.

By frame buffer i meant accesing cga memory directly as in http://en.wikipedia.org/wiki/Pointer_%28computing%29#Memory-mapped_hardware

wysota
14th September 2007, 13:23
Your advice may be perfect for me but not my other classmates since they really don't know anything other than turboc for now. That is the only IDE familiar to them which involves nice context help built in. So doing a small functional editor(similar to edit) will sprout interest in them , atleast that is what my teacher assumes.
That's exactly what I mean. I think this assumption is wrong :) I don't say students shouldn't use turbo c, I'm saying they shouldn't implement such things with it, especially if they are new to the language.


So they cant think about portability at this stage.
It's not about thinking about portability. It's about knowing there are different architectures, not only x86/Win32. Using such concepts as programming interrupts as the basic of the C course seems very strange, based on the fact that for modern operating systems you'll never touch any interrupt handler, because they are hidden and well protected. Of course, again, this doesn't apply if you code a device driver, but that doesn't seem to be the case when using Turbo C :)


One more advantage for starters will be , some understanding on how events are generated and how to handle them.
What kind of events? I never heard of any events in TurboC.


I didn't want to be odd one out and so joined to help others too.
I'm not blaiming you. I'm just saying your teacher had a weird idea making his students implement a text editor as a starters project from C.


My idea is to do something special in this. For example i have better idea to handle the events and catch interrupts at right place. I am trying to be perfectionist in as many areas as possible and also would like to learn advanced data structures.
This is purely academical "perfection" - you'll never put that knowledge into practical use.


By frame buffer i meant accesing cga memory directly as in http://en.wikipedia.org/wiki/Pointer_%28computing%29#Memory-mapped_hardware
I understand that. What operating system are you using? Emulation of DOS, right? Do you have DOS on your desktop computer? Have you tried using the framebuffer directly inside WinXP or Vista for a non DOS-based application?

That's one of the reasons I graduated CS on a technical university instead of a theoretical one :)

Gopala Krishna
14th September 2007, 13:45
Though we are going off topic this discussion is interesting.


That's exactly what I mean. I think this assumption is wrong I don't say students shouldn't use turbo c, I'm saying they shouldn't implement such things with it, especially if they are new to the language.

They are not very new to language but ofcourse to data structures. You are right but we are just supposed to get a working editor with no fancy things and so that shouldn't be a big problem.



It's not about thinking about portability. It's about knowing there are different architectures, not only x86/Win32. Using such concepts as programming interrupts as the basic of the C course seems very strange, based on the fact that for modern operating systems you'll never touch any interrupt handler, because they are hidden and well protected. Of course, again, this doesn't apply if you code a device driver, but that doesn't seem to be the case when using Turbo C

True, this was ofcourse informed. Think this to be a system software ;)



What kind of events? I never heard of any events in TurboC.

Can we call this over influence of Qt ? :D Actually i meant interrupts.




This is purely academical "perfection" - you'll never put that knowledge into practical use.

But since i have already been committed to this i don't bother whether this will be really useful. Playing with pointers is fun and ofcourse not everything will be waste.



I understand that. What operating system are you using? Emulation of DOS, right? Do you have DOS on your desktop computer? Have you tried using the framebuffer directly inside WinXP or Vista for a non DOS-based application?

That's one of the reasons I graduated CS on a technical university instead of a theoretical one :)

Very true. As i said before, this is meant to be introductory and my friends have learned basic 'C'. Experimenting so much with other subjects to study will be tough to manage. Getting a simple editor working will be enough as of now.
And also the practical part is in our hands and its our duty/curiosity to experiment
Well actually its worth to know the theory behind too. :)

wysota
14th September 2007, 14:02
Playing with pointers is fun

That's what you say. I'm not a masochist :)

Gopala Krishna
14th September 2007, 14:19
That's what you say. I'm not a masochist :)

I am sorry. May be you are just looking at faults rather than trying to help. Well i don't want to say anything more and thanks for answering in this thread.

Gopala Krishna
16th September 2007, 17:36
Sorry wysota, i guess i lost my cool for no reason :o

wysota
16th September 2007, 22:54
No problem. By the way, I thought of something yesterday, but I forgot to write it here :)

You wanted something regarding scrolling. If you can read the frame buffer, you can implement scrolling by reading the chunk of data that represent all the visible lines of the editor but one (the one that'll fall out of the screen) and writing it back again at a different offset. This way you'll have to recalculate and draw only a single line (first or last, depending on the scroll direction). I don't know if that helps, but maybe it'll give you something to start with.