Tips and algorithms(?) in making a simple text viewer/editor 
Author Message
 Tips and algorithms(?) in making a simple text viewer/editor

Hello, first of all, i would like to say that im new to this NG, but i
use common sense, so dont worry i wont troll arround :P
I think NG's are really good for sharing info, and getting help, and i
should say that *we* (the newbies!) really appreciate you guys, every
help you do, is really helpful, so keep up the good work

Now to the problem:
Just came to my mind (i have the code, the program works, really good,
but i want to know of a side-solve)

did a TEXT VIEWER ^_^

well, after getting the file from the command line (easy!), i read the
1)first block of 25 lines in the file, what i do is:
(this is an extra procedure, since i call it several times)

PROCEDURE blah(position_i, position_f:integer)

takes the start position, and the final position, then do a while not
eof, and goes counting, when the counter reaches start position, then
start doing readln's.
this way i take the actual output to the screen.
(a way to improve this is use SEEK perhaps, so its faster, cuz the
counter actually goes from 1 to the line number i use for position_i!!)
(but since it says it cant work with text files, im stuck :|)

2) to scroll, i wanted to use READKEY; but it cant read arrow/pgup
keys!, so if anyone knows a solution

then if i press up or down, another counter (in the mail program) goes
up/down, so i pass thru each line, if that counter is >25 (max lines
p/screen) then it calls the BLAH procedure, using a new counter (added
+1)

3)now the problem is that when i scroll the screen, it flicks, or
flashes, taths cuz i rewrite everything on screen again (i use gotoxy,
so the writeln's wont do a weirdo output), is there a workarround on
this?

now to the editing part, i can write to it, but since i rewrite the
screen (and update all my array) each time i touch something, i dont
know what to do now, i tryed rewriting the original file, and then
adding into the exact line, the edited one, saving, and renaming it to
the filename (that sux i know, but since append seek wont work...)

4)is there a way to move the cursor position in a file, that would
really help me out, cuz then i just open the file for append, move to
the line, and write the new stuff, i know that should be done when
saving, but whatever, this is my first text editor lol)

i wont ask about undo levels, i think i know how this can be done, write
in several files the changes, and the actual file position as a code,
then, when undoing, just go to the file position, and write (or i can
even do it in any array/record

If anyone wants the code for it (ill comment if you need it hehee) just
post it (ill then post it here), or mail me at


anything)

5)is BP7 really that better comparing TP7?, i mean, i have tp, and it
just dont have any TD.EXE anywhere in the directories (and yes, i have
the pirate version, so maybe thats the problem)
(if you can send me a url to get it, that would be nice of you)

6)since im learning....
i reached chapter 8 of Glenn Grotzinger tutorial (its the best one i
found arround, if you know a best one, tell!! (url too if available)
and my worst problem is to find problems to solve, i mean, i HAD Pascal
in high school, but we only learned writeln(); (i swear, 1 year learning
that shit, at the end of that year, i got taste for pascal, and decided
to leave BASIC :P [last commad we saw was readln();])
so if you have any problem to solve using pascal (anything will be
cool), cuz im thinking of things to do myself recently only.
So please send me problems, and send me urls to problems (they dont
teach languages here, only math and math and math (getting sick!))
Or just ask me to do stuff (ill try my best, and if i cant, then ill do
pseudocode, for later code when i know more ^_^)

Thanks in advance to all who reply (and lets hope news.indianvalley.com
reads you all hehehe...) and all who reads in here, and like pascal like
me!

oh,oh! 7) any good/fast news server? -<think this one dont get all posts
:|)

TruchiSoft
(or Juan Jose from Argentina)
(or john)


PD: TPRJr11, if you are reading this, i did a encrypter too!, it just
encripts using ASCII code, so it sucks, but it works, and if you want to
take a look and compare code, mail me! (would be cool to learn together)

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Thu, 03 Apr 2003 12:18:03 GMT  
 Tips and algorithms(?) in making a simple text viewer/editor
hi conano,

some replies to your problems

Quote:
> 1)first block of 25 lines in the file, what i do is:
> (this is an extra procedure, since i call it several times)

> PROCEDURE blah(position_i, position_f:integer)

> takes the start position, and the final position, then do a while not
> eof, and goes counting, when the counter reaches start position, then
> start doing readln's.
> this way i take the actual output to the screen.
> (a way to improve this is use SEEK perhaps, so its faster, cuz the
> counter actually goes from 1 to the line number i use for position_i!!)
> (but since it says it cant work with text files, im stuck :|)

to start with you should use your way of reading textlines.

i guess something like this:

var textfile : text;
...
  readln(textfile, l[i]);
..

my tip: create extra procedures, functions for every access to the file.
even create a function like getOneLine(index) : string;

why not read the whole file in a dynamic list of pointers to string.

if you are not experienced in working with lists and pointers, you might use a big array.
..

Quote:
> 2) to scroll, i wanted to use READKEY; but it cant read arrow/pgup
> keys!, so if anyone knows a solution

> then if i press up or down, another counter (in the mail program) goes
> up/down, so i pass thru each line, if that counter is >25 (max lines
> p/screen) then it calls the BLAH procedure, using a new counter (added
> +1)

readkey is OK - readkey works like this :

c := readkey;
if c=#0 {NULLchar} then { you have pressed a special key - like Fx, pgup }
begin
  c := readkey; {read again !}
  case c of
    #72 : CrsUp
    #80 : CrsDN
    #75 : CrsLt
    #77 : CrsRt
  end;
end
else
  { you have pressed a normal key }

Quote:
> 3)now the problem is that when i scroll the screen, it flicks, or
> flashes, taths cuz i rewrite everything on screen again (i use gotoxy,
> so the writeln's wont do a weirdo output), is there a workarround on
> this?

> now to the editing part, i can write to it, but since i rewrite the
> screen (and update all my array) each time i touch something, i dont
> know what to do now, i tryed rewriting the original file, and then
> adding into the exact line, the edited one, saving, and renaming it to
> the filename (that sux i know, but since append seek wont work...)

> 4)is there a way to move the cursor position in a file, that would
> really help me out, cuz then i just open the file for append, move to
> the line, and write the new stuff, i know that should be done when
> saving, but whatever, this is my first text editor lol)

no, not for textfiles (text), opened as file of char or so you can, but
if the length of your new line differs from the old one, your textfile fill be corrupted.

Quote:

> i wont ask about undo levels, i think i know how this can be done, write
> in several files the changes, and the actual file position as a code,
> then, when undoing, just go to the file position, and write (or i can
> even do it in any array/record

to start with, you should probably handle the whole file in an array.

Quote:

> If anyone wants the code for it (ill comment if you need it hehee) just
> post it (ill then post it here), or mail me at


> anything)


Quote:

> 5)is BP7 really that better comparing TP7?, i mean, i have tp, and it
> just dont have any TD.EXE anywhere in the directories (and yes, i have
> the pirate version, so maybe thats the problem)
> (if you can send me a url to get it, that would be nice of you)

to start with, tp7 is ok.

Quote:

> 6)since im learning....
> i reached chapter 8 of Glenn Grotzinger tutorial (its the best one i
> found arround, if you know a best one, tell!! (url too if available)
> and my worst problem is to find problems to solve, i mean, i HAD pascal
> in high school, but we only learned writeln(); (i swear, 1 year learning
> that shit, at the end of that year, i got taste for pascal, and decided
> to leave BASIC :P [last commad we saw was readln();])
> so if you have any problem to solve using pascal (anything will be
> cool), cuz im thinking of things to do myself recently only.
> So please send me problems, and send me urls to problems (they dont
> teach languages here, only math and math and math (getting sick!))
> Or just ask me to do stuff (ill try my best, and if i cant, then ill do
> pseudocode, for later code when i know more ^_^)

if you really want so, an have the time to think of problems for some ...
i could send you some problems  or post them here.
but i think this isn't a NG for exercises.

Quote:

> Thanks in advance to all who reply (and lets hope news.indianvalley.com
> reads you all hehehe...) and all who reads in here, and like pascal like
> me!

> oh,oh! 7) any good/fast news server? -<think this one dont get all posts
> :|)

any good, fast and FREE servers ???

hth
Jochen

Quote:

> TruchiSoft
> (or Juan Jose from Argentina)
> (or john)


> PD: TPRJr11, if you are reading this, i did a encrypter too!, it just
> encripts using ASCII code, so it sucks, but it works, and if you want to
> take a look and compare code, mail me! (would be cool to learn together)

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Tips and algorithms(?) in making a simple text viewer/editor


...

Quote:
> PROCEDURE blah(position_i, position_f:integer)

> takes the start position, and the final position, then do a while
not
> eof, and goes counting, when the counter reaches start position,
then
> start doing readln's.
> this way i take the actual output to the screen.
> (a way to improve this is use SEEK perhaps, so its faster, cuz the
> counter actually goes from 1 to the line number i use for
position_i!!)
> (but since it says it cant work with text files, im stuck :|)

There are 3 types of file in TP: typed files, untyped files and text.
When opening a typed or untyped file, the compiler knows how big each
record is. With typed, you say "var f:File of t;" and the record size
is the size of an instance of that type; read(f,r) reads one record
into r. With untyped you say "var f:File;" and you get to say how many
bytes there are in a record (it's n in Reset(f, n); typically you use
Reset(f,1) but it defaults to 128 if you just say Reset(f)). You
BlockRead(f,buf,nTry,nRead) to try to read nTry records, and nRead
gets set to the number of records actually read.

So, since the compiler knows how big each record is, you can tell it
to look for, say, the 125th record and it knows where to look. In
other words, you get random access. On the other hand, Text files have
lines of varying length, so the only way of finding "record" X is by
starting at the top and reading X lines.

In other words, if you want to scroll up through a file on disc then
Text is not the best choice.

You could write code (put it in an object!) to read an untyped file
and return you the next line. Then you can work out where the line
starts in the file, so you can Seek back to it if you want to go up a
line.

Quote:

> 3)now the problem is that when i scroll the screen, it flicks, or
> flashes, taths cuz i rewrite everything on screen again (i use
gotoxy,
> so the writeln's wont do a weirdo output), is there a workarround on
> this?

You could write your own routines to access the screen, which is at
B000:0 if you are in mode 7 and  B800:0 for other modes. Or you can
rewrite the screen without clearing it first, if you overwrite every
character on the screen.

Quote:
> 4)is there a way to move the cursor position in a file, that would
> really help me out, cuz then i just open the file for append, move
to
> the line, and write the new stuff, i know that should be done when
> saving, but whatever, this is my first text editor lol)

The cursor position would be just your program's knowledge of what bit
you are editing at the moment. If you can seek around the file you can
move it, which means you need random access. If you can fit the file
into memory that's probably best, otherwise you need a type of file
that supports seek.
...

Quote:
> 5)is BP7 really that better comparing TP7?

if you run out of memory then probably, because you can use protected
mode memory. Even if your program is real mode, the fact that the IDE
uses PM means your program has more memory.

FP



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Making an Text-Editor

2. how to program a simple text editor?

3. which string-search-algorithm in tp-editor

4. Which string-searching-algorithm in TP-editor

5. Algorithm for making a FIXTURE LIST?

6. Making a new .CHR font editor.

7. Making a new .chr font editor.

8. Wordwrapped Text Viewer?

9. Looking for simple Console based Linux editor.

10. Sources for a simple editor needed!

11. HighEdit Component Text Editor

12. Text Editor > 64K

 

 
Powered by phpBB® Forum Software