Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to index page
Thread view  Board view
Cyberdyne

Estonia,
28.10.2022, 07:41
 

DOS tool to convert letters in text file to upper/lowercase. (Miscellaneous)

Googled all the way, and did not find any, is there one maybe....

---
Retrocomputing... a x86 DOS nut really!

mceric

Germany,
28.10.2022, 11:00

@ Cyberdyne
 

DOS tool to convert letters in text file to upper/lowercase.

> Googled all the way, and did not find any, is there one maybe....

You should be able to find a DOS version of TR (from textutils or coreutils, for example from Delorie DJGPP, or a 16-bit DOS version of something similar) which lets you do things such as

tr 'a-z' 'A-Z' < normal.txt > upper.txt

Interestingly, the TRCH tool by Jim Hall only translates ONE character at a time in the current version, so you would have to do

trch a A < normal.txt > temp.txt
trch b B < temp.txt > temp2.txt
trch c C < temp2.txt > temp.txt
...
trch z Z < temp.txt > upper.txt

unless I misunderstood how to use it?

---
FreeDOS / DOSEMU2 / ...

Cyberdyne

Estonia,
28.10.2022, 12:45

@ mceric
 

DOS tool to convert letters in text file to upper/lowercase.

Well even this would be nice. Just have to make a batch file with all the alphabet. Just can not find the DOS version.

---
Retrocomputing... a x86 DOS nut really!

jhall

Homepage

28.10.2022, 16:03

@ Cyberdyne
 

DOS tool to convert letters in text file to upper/lowercase.

Eric wrote:
> the TRCH tool by Jim Hall only translates ONE character at a time in
> the current version, so you would have to do [..]

Cyberdyne wrote:
> Well even this would be nice. Just have to make a batch file with all the
> alphabet. Just can not find the DOS version.

I don't remember my exact use case when I wrote TRCH, but I know I needed to translate only one letter at a time. At around the time I wrote it, someone else asked for a program to do the same thing, so I shared it. TRCH is included in FreeDOS.

There is a DOS version of tr.exe included in gnutut12.zip ("text utilities") in our copy of the GNUish archives. I haven't used this version in ages so I don't know what features are/not included, but you can find it at:

https://www.ibiblio.org/pub/micro/pc-stuff/freedos/gnuish/

jhall

Homepage

28.10.2022, 16:24

@ jhall
 

DOS tool to convert letters in text file to upper/lowercase.

Or, you could write a small program to do this for you. Compile this:

#include <stdio.h>

#define is_upper(A) ((A >= 'A') && (A <= 'Z'))
#define is_lower(A) ((A >= 'a') && (A <= 'z'))

#define to_lower(A) (A - 'A' + 'a')
#define to_upper(A) (A - 'a' + 'A')

int
main()
{
  int ch;

  while ((ch = getchar()) != EOF) {
    if (is_upper(ch)) {
      putchar( to_lower(ch) );
    }
    else {
      putchar(ch);
    }
  }

  return 0;
}


This is a very simple program (it doesn't read files, it relies on file redirection) to convert text from uppercase to lowercase. It leaves all other characters as they are (such as punctuation, numbers, etc.)

Save it as tolower.c and compile it with

> WCL tolower.c

(You'll need to install the Watcom C Compiler package and run the OWSETENV.BAT file to set your environment.)

To turn this program into a "convert to uppercase" program, copy the file to toupper.c and change the two lines inside the while loop to this:

    if (is_lower(ch)) {
      putchar( to_upper(ch) );


Then compile the new program with:

> WCL toupper.c

jhall

Homepage

28.10.2022, 16:47

@ jhall
 

DOS tool to convert letters in text file to upper/lowercase.

> Or, you could write a small program to do this for you. Compile this:
> ...

I've compiled the programs for you, if that helps. You can get them in the tolower.zip archive file, available here:

http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/util/file/

Since these are trivial programs, I released them under the public domain (cc0).

Note that these programs do not read files on their own; they rely on file redirection on the command line. For example, let's say you had a file called FILE.TXT that you wanted to convert entirely to lowercase text. You would run this command, which saves the new version as LOWER.TXT:

TOLOWER < FILE.TXT > LOWER.TXT

Converting to uppercase is the same way. Let's say you had a file called RUN.BAT that you wanted to convert entirely to uppercase text. You would run this command, which saves the new version as UPPER.BAT:

TOUPPER < RUN.BAT > UPPER.BAT

I hope that helps.

Rugxulo

Homepage

Usono,
31.10.2022, 23:55

@ mceric
 

DOS tool to convert letters in text file to upper/lowercase.

> You should be able to find a DOS version of TR (from textutils or
> coreutils, for example from Delorie DJGPP, or a 16-bit DOS version of
> something similar) which lets you do things such as
>
> tr 'a-z' 'A-Z' < normal.txt > upper.txt

Yes, DJGPP still has separate .ZIPs for CoreUtils (FileUtils + TextUtils + ShellUtils):

* http://www.delorie.com/pub/djgpp/current/v2gnu/txt20br3.zip (tr.exe)

rr

Homepage E-mail

Berlin, Germany,
28.10.2022, 19:02

@ Cyberdyne
 

DOS tool to convert letters in text file to upper/lowercase.

> Googled all the way, and did not find any, is there one maybe....

Case conversion is not as easy as it may seem.
If your letters are from the A-Z range, all is fine and you can use Jim's solution.

For other languages than English there may be more letters to translate, e.g., German has the umlauts ÄÖÜäöü. These are outside the A-Z range of the ASCII table. So you need a translation table suited for the language the text is in.

Timo Salmi's TSFLTB (download) includes sample filters for case conversion.

Usage is:
FILTXT.EXE INPUT.TXT OUTPUT.TXT LOWER.XLT
or
FILTXT.EXE INPUT.TXT OUTPUT.TXT UPPER.XLT

Unfortunately this tool suffers from the well-known Runtime Error 200 bug, so you have to run a fix. It works fine with Veit Kannegießer's R200FIX, which you can find at https://kannegieser.net/veit/programm/index_e.htm. This is a TSR, so you have load it again after rebooting your machine. Either include it in your AUTOEXEC.BAT or have a look at fixes patching the EXE file: FREE SOFTWARE FOR DOS — System Utilities

---
Forum admin

Laaca

Homepage

Czech republic,
28.10.2022, 21:38

@ rr
 

DOS tool to convert letters in text file to upper/lowercase.

> Case conversion is not as easy as it may seem.
> If your letters are from the A-Z range, all is fine and you can use Jim's
> solution.
>
> For other languages than English there may be more letters to translate,
> e.g., German has the umlauts ÄÖÜäöü. These are outside the A-Z range
> of the ASCII table. So you need a translation table suited for the language
> the text is in.

If you do not need a command line utility you can use Blocek text editor.
Load file, then main menu -> Text -> Block operations -> Convert case up

---
DOS-u-akbar!

RayeR

Homepage

CZ,
15.12.2022, 16:25

@ Laaca
 

DOS tool to convert letters in text file to upper/lowercase.

DOS Navigator built-in text editor also can do this, using it for so many years...
F4 - edit file
mark a block of text (Ctrl+K A for all)
menu: Block|Format|uppercase (Ctrl+k [ )

---
DOS gives me freedom to unlimited HW access.

bretjohn

Homepage E-mail

Rio Rancho, NM,
30.10.2022, 02:49

@ rr
 

DOS tool to convert letters in text file to upper/lowercase.

> Case conversion is not as easy as it may seem.
> If your letters are from the A-Z range, all is fine and you can use Jim's
> solution.
>
> For other languages than English there may be more letters to translate,
> e.g., German has the umlauts ÄÖÜäöü. These are outside the A-Z range
> of the ASCII table. So you need a translation table suited for the language
> the text is in.

Actually, it doesn't depend on the Language or Country but rather the Code Page. Ä is the upper-case of ä no matter what language you're using. The relationships between languages, keyboard layouts, and countries are very confusing and not at all straightforward. DOS has some internal functions to process case conversions (e.g., INT 2F.1213).

rr

Homepage E-mail

Berlin, Germany,
30.10.2022, 11:38

@ bretjohn
 

DOS tool to convert letters in text file to upper/lowercase.

> Actually, it doesn't depend on the Language or Country but rather the Code
> Page. Ä is the upper-case of ä no matter what language you're using.
> The relationships between languages, keyboard layouts, and countries are
> very confusing and not at all straightforward.

That's why I used that simplification.
Yes, "Ä is the upper-case of ä", but it doesn't matter, if you write in, e.g., English or the Cyrillic alphabet.

> DOS has some internal functions to process case conversions (e.g., INT
> 2F.1213).

It even has a documented function: INT 21 - DOS 4.0+ - COUNTRY-DEPENDENT CHARACTER CAPITALIZATION

But I didn't find a tolower() function. My guess: If the user supplied, e.g., lowercase "bäh" on the command line, DOS/command.com had to look for files like BÄH.EXE or BÄH.BAT, because uppercase is how filenames are stored on (FAT) disks. There simply was no need for a tolower() function.

Oh, INT 21 - DOS 3.3+ - GET EXTENDED COUNTRY INFORMATION reads "03h (DOS 6.2+ COUNTRY.SYS) get pointer to lowercase table".

---
Forum admin

bretjohn

Homepage E-mail

Rio Rancho, NM,
31.10.2022, 16:12
(edited by bretjohn, 31.10.2022, 22:07)

@ rr
 

DOS tool to convert letters in text file to upper/lowercase.

> But I didn't find a tolower() function. My guess: If the user supplied,
> e.g., lowercase "bäh" on the command line, DOS/command.com had to look for
> files like BÄH.EXE or BÄH.BAT, because uppercase is how filenames are
> stored on (FAT) disks. There simply was no need for a tolower() function.

Exactly. The DOS kernel really doesn't have a need for a tolower() function.

> Oh, INT 21 -
> DOS 3.3+ - GET EXTENDED COUNTRY INFORMATION reads "03h (DOS 6.2+
> COUNTRY.SYS) get pointer to lowercase table".

That is correct, but the contents of that table depend on the current Code Page. E.g., the Code Page I normally use is 437, but I have played around with some of the other Code Pages as well due to the nature of some of my programs (both released and unreleased/experimental). I think for at least most of the Code Pages, there are both lower-case and upper-case of the Latin-based letters that are in the Code Page. In such cases, you can go back and forth between lower- and upper-case if you need to.

But Code Page 437 also has some Greek letters (e.g., Alpha and Beta and Mu and Omega) but only has one of the two cases in the Code Page. So, even though those letters have case-equivalents you may never know it based on what DOS can tell you. DOS can't do a case-conversion unless there is something to display on the screen, and that depends on the Code Page.

Rugxulo

Homepage

Usono,
29.10.2022, 00:59

@ Cyberdyne
 

DOS tool to convert letters in text file to upper/lowercase.

Sed should do what you want.


y/abcdef/ABCDEF/


GNU Sed also supports \U, \L (see manual).

http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/util/unix/sed/

Doug

E-mail

30.10.2022, 08:47

@ Cyberdyne
 

DOS tool to convert letters in text file to upper/lowercase.

One might potentially cook up a routine using the 80x86 opcode "XLAT":

XLAT Locates a byte entry in a table in memory, using the contents of the AL register as a table index, then copies the contents of the table entry back into the AL register. AL should contain the unsigned index into a table addressed by DS:BX (for an address-size attribute of 16 bits) or DS:EBX (for an address-size attribute of 32 bits). The operand to XLAT allows for the possibility of a segment override.

https://www.scs.stanford.edu/05au-cs240c/lab/i386/XLAT.htm

- Doug B.

Back to index page
Thread view  Board view
22049 Postings in 2034 Threads, 396 registered users, 153 users online (1 registered, 152 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum