Valhalla Legends Forums Archive | General Programming | MS-DOS String Parsing

AuthorMessageTime
Yegg
I'm pretty sure this is the correct forum section for this topic. I'm working on a small project in MS-DOS, and I need to split the input given by a user into separate strings, to better clarify this, I would like to declare each character in the string with its own variable. Is DOS capable of reading the 1st character of a string, the 2nd character of a string, the 3rd, and so on. So for instance, can you simply echo back the 4th character of the string that was input by the user? Or is this impossible?
May 20, 2005, 9:04 PM
Kp
Sure.[code]getc(); getc(); getc();
c = getc();
printf ("%c", c);
[/code]
May 20, 2005, 10:07 PM
Yegg
Thanks for the very complex response, it was so big and informative I wasn't sure if I could read the whole thing. Anyone else?
May 20, 2005, 10:27 PM
Maddox
This reminds me of another recent thread.
May 20, 2005, 10:29 PM
Quarantine
Yegg, we have different definitions of Complex it seems </melaughingatsarcasmovertheinternet>
May 20, 2005, 10:41 PM
Kp
[quote author=Yegg link=topic=11651.msg113156#msg113156 date=1116628045]
Thanks for the very complex response, it was so big and informative I wasn't sure if I could read the whole thing. Anyone else?
[/quote]

Well, if you're going to be writing MS-DOS code, you need to keep it simple.  Remember the memory limit.  So, I gave you simple code.
May 20, 2005, 11:02 PM
Newby
Specify the language.
May 20, 2005, 11:15 PM
R.a.B.B.i.T
That would help...
May 20, 2005, 11:30 PM
Yegg
Kp, I believe that "Sure", is not a valid answer in this case... The language is just DOS, I don't see what else you want to know unless it is the version of it, which doesn't seem to matter in this case. Also, I found a link that solved my problem.
May 20, 2005, 11:47 PM
Kp
The "Sure" was just an affirmation that you can do it.  The code was a demonstration of how to grab out (and echo) the fourth character.  DOS isn't a language; it's an operating system (specifically, the Disk Operating System!).
May 21, 2005, 1:48 AM
Newby
I'm gonna go out on a limb here and guess he wants it in batch.
May 21, 2005, 2:34 AM
Myndfyr
[quote author=Newby link=topic=11651.msg113196#msg113196 date=1116642854]
I'm gonna go out on a limb here and guess he wants it in batch.
[/quote]

That would make a lot of difference.  When you post in the "General Programming" forum, and then talk about variables, people expect that you're talking about a programming language.

DOS is not a language, as Kp pointed out, and IMO "batch programming" is something of a misnomer.
May 21, 2005, 4:11 AM
Mangix
i believe one language of DOS is BASIC which is what VB was based on. and its the language which my dad is an expert on since he used to program in DOS.

and yes DOS isnt a Programming Language as all these people said.
May 21, 2005, 5:11 AM
Null
[quote author=Mangix link=topic=11651.msg113212#msg113212 date=1116652309]
he used to program in DOS.
[/quote]

[quote author=Mangix link=topic=11651.msg113212#msg113212 date=1116652309]
yes DOS isnt a Programming Language.
[/quote]

Your such a moron u make me cry!
May 21, 2005, 6:35 AM
R.a.B.B.i.T
DOS is an OS, not a language.  That being said, DOS is not a language.  But DOS is an operating system.  Is it clear yet?  I think so.  Batch isn't a very good "language" to program in, because you need to call in a LOT of dependencies to make a large program.  Making a batch bot won't be very fun (or easy), and the code for it gets VERY messy VERY fast, trust me, I've tried.  Also, making a bot for DOS, which isn't a language, it's an operating system, specifically for Disks, is hard because batch isn't a very good "language" to program yet, especially for an operating system like DOS, which isn't a language.
May 21, 2005, 1:03 PM
Yegg
Ok ok, I should have referred to it as Batch. Also, I seem to be having fun programming in Batch. I'm creating a starcraft cdkey decoder in it. Yes I know it probably won't have much of a purpose, but I'm just doing it for fun.
May 21, 2005, 6:55 PM
Adron
[quote author=Yegg link=topic=11651.msg113257#msg113257 date=1116701705]
Ok ok, I should have referred to it as Batch. Also, I seem to be having fun programming in Batch. I'm creating a starcraft cdkey decoder in it. Yes I know it probably won't have much of a purpose, but I'm just doing it for fun.
[/quote]

It's impossible with only what's built-in to the MS-DOS batch file (command) interpreter. You need to call some program.
May 21, 2005, 11:06 PM
Yegg
    [code]def starkey(key):
        arrayKey = list(key);
        v = 3;
        for i in range(0, 12):
            c = arrayKey[i];
            n = int(c);
            n2 = v * 2;
            n ^= n2;
            v += n;
        v %= 10;
        if(hex(v) == arrayKey[12]):
            valid = [True];
        v = 194;
        for i in range(11, -1, -1):
            if(v < 7):
                break;
            c = arrayKey[i];
            n = int(v/12);
            n2 = v % 12;
            v -= 17;
            c2 = arrayKey[n2];
            arrayKey[i] = c2;
            arrayKey[n2] = c;
        v2 = 0x13AC9741;
        for i in range(11, -1, -1):
            c = arrayKey[i].upper();
            arrayKey[i] = c;
            if(ord(c) <= ord('7')):
                v = v2;
                c2 = v & 0xFF;
                c2 &= 7;
                c2 ^= int(c);
                v = int(v) >> 3;
                arrayKey[i] = c2;
                v2 = v;
            elif(ord(c) < 65):
                c2 = int(i);
                c2 &= 1;
                c2 ^= int(c);
                arrayKey[i] = c2;
        decode_starcraft_key = ''.join(map(str, arrayKey));
        return decode_starcraft_key;[/code]
Look at this code and tell me what this has that a MS-DOS batch file is not capable of. I'd really like to know.
May 22, 2005, 12:00 AM
Kp
It's been a while since I actually deigned to use something as weak as a DOS batch job, but I think the only thing in that code you could do without calling an external program would be a passable imitation at looping. :)
May 22, 2005, 12:10 AM
Yegg
If Adron's concern was looping then I guess he wasn't thinking clearly when he made that post. Of course I couldn't use anything built into DOS that works like a for loop (the way I needed it to work), that is why I created my own "loop" functions in my program. They work fine too.
May 22, 2005, 12:14 AM
Adron
[quote author=Yegg link=topic=11651.msg113287#msg113287 date=1116720881]
If Adron's concern was looping then I guess he wasn't thinking clearly when he made that post. Of course I couldn't use anything built into DOS that works like a for loop (the way I needed it to work), that is why I created my own "loop" functions in my program. They work fine too.
[/quote]

As Kp said, close to the only thing you can do is looping. You can't divide, you can't multiply, you can't xor, you can't index characters, you can't round, you can't take the ascii value of a character ... the list goes on.

You can use something built into DOS for a for loop though:

[code]
for %%a in (0 1 2 3 4 5 6 7 8 9 10 11 12) do ...
[/code]
May 22, 2005, 3:47 PM
Yegg
[quote author=Adron link=topic=11651.msg113358#msg113358 date=1116776870]
You can't divide, you can't multiply, you can't xor, you can't index characters, you can't round, you can't take the ascii value of a character ... the list goes on.
[/quote]
What are you talking about?? Batch can use bit shifting functions, or, xor, ad/subtract, multiply/divide, and more. I've already done that with Batch. If that wern't possible then I wouldn't be creating this program.
May 22, 2005, 10:24 PM
Kp
Then how about you show us the statements you're using which supposedly implement this?  To the best of my knowledge, no traditional DOS interpreter can do any of those operations.
May 23, 2005, 2:47 AM
R.a.B.B.i.T
Maybe he's writing in BASIC?
May 23, 2005, 3:23 AM
Adron
[quote author=Yegg link=topic=11651.msg113438#msg113438 date=1116800689]
[quote author=Adron link=topic=11651.msg113358#msg113358 date=1116776870]
You can't divide, you can't multiply, you can't xor, you can't index characters, you can't round, you can't take the ascii value of a character ... the list goes on.
[/quote]
What are you talking about?? Batch can use bit shifting functions, or, xor, ad/subtract, multiply/divide, and more. I've already done that with Batch. If that wern't possible then I wouldn't be creating this program.
[/quote]

You are then not using MS-DOS' batch file language. Its command interpreter does not have any of those commands. You are probably just confused.
May 23, 2005, 5:43 AM
Yegg
I hope I'm not confused......Here is my code, so far. There are a few minor errors but the math operators works (I've got to do a little more work to make the % operator work correctly).
[code]:: MS-DOS Starcraft CDKey Decoder was created by Yegg
@title Starcraft CDKey Decoder
@color 78

:begin
@set input=
@set /p input=Enter a CDKey:
@if '%input%'=='' (
  @echo You have not entered in a cdkey, please try again.
  @goto begin)
@call :makelist %input%

:makelist
@set listkey=[%1]
@call :decode %listkey%

:decode
@set newkey=%1
@set newkey=%newkey:~1, 13%
@set original=%newkey%
@set dig1=%newkey:~0, 1%
@set dig2=%newkey:~1, 1%
@set dig3=%newkey:~2, 1%
@set dig4=%newkey:~3, 1%
@set dig5=%newkey:~4, 1%
@set dig6=%newkey:~5, 1%
@set dig7=%newkey:~6, 1%
@set dig8=%newkey:~7, 1%
@set dig9=%newkey:~8, 1%
@set dig10=%newkey:~9, 1%
@set dig11=%newkey:~10, 1%
@set dig12=%newkey:~11, 1%
@set v=3
@for %%i in (1 2 3 4 5 6 7 8 9 10 11 12) do (
  @for %%d in (%dig1% %dig2% %dig3% %dig4% %dig5% %dig6% %dig7% %dig8% %dig9% %dig10% %dig11% %dig12%) do (
    @set c=%%d
    @set n=%c%
    @set /a n2=%v%*2
    @set /a n^=%n2%
    @set /a v+=%n%))
@set v=194
for %%1 in (12 11 10 9 8 7 6 5 4 3 2 1) do (
  for %%d in (%dig1% %dig2% %dig3% %dig4% %dig5% %dig6% %dig7% %dig8% %dig9% %dig10% %dig11% %dig12%) do (
    if not %v% lss 7 (
      @if %n2%==0 set var=%dig1%
      @if %n2%==1 set var=%dig2%
      @if %n2%==2 set var=%dig3%
      @if %n2%==3 set var=%dig4%
      @if %n2%==4 set var=%dig5%
      @if %n2%==5 set var=%dig6%
      @if %n2%==6 set var=%dig7%
      @if %n2%==7 set var=%dig8%
      @if %n2%==8 set var=%dig9%
      @if %n2%==9 set var=%dig10%
      @if %n2%==10 set var=%dig11%
      @if %n2%==11 set var=%dig12%
      @set c=%%d
      @set /a n=%v%/12
      @set /a n2=%v% % 12
      @set /a v-=17
      @set c2=%var%
      @set %%d=%c2%
      @set %var%=%c%)))
@set v2=330078017
@for %%i in (12 11 10 9 8 7 6 5 4 3 2 1) do (
  @for %%d in (%dig1% %dig2% %dig3% %dig4% %dig5% %dig6% %dig7% %dig8% %dig9% %dig10% %dig11% %dig12%) do (
    @set c=%%d
    @echo %%d
    @set %%d=%c%
    @if %c%==0 set val=48
    @if %c%==1 set val=49
    @if %c%==2 set val=50
    @if %c%==3 set val=51
    @if %c%==4 set val=52
    @if %c%==5 set val=53
    @if %c%==6 set val=54
    @if %c%==7 set val=55
    @if %c%==8 set val=56
    @if %c%==9 set val=57
    @if %val% leq 55 (
      @set v=%v2%
      @set /a c2=%v%&0xFF
      @set /a c2&=7
      @set /a c2^=%c%
      @set /a v>>=3
      @set %%d=%c2%
      @set v2=%v%)
    @if %val% lss 65 (
      @set c2=%%i
      @set /a c2&=1
      @set /a c2^=%c%
      @set %%d=%c2%)))
:finish
@echo %dig1%%dig2%%dig3%%dig4%%dig5%%dig6%%dig7%%dig8%%dig9%%dig10%%dig11%%dig12%
@goto begin[/code]
May 23, 2005, 7:38 PM
iNsAnE-MS
um... fyi...

@echo off

last DOS version I wrote batch processing for was 6.22, and it didn't support a majority of that (IE mathmatical routines LoL)>.<

still supported "@echo off" so you don't have to put @ at the beginning of each line though!
May 23, 2005, 8:11 PM
Yegg
I enjoy typing @ at the beginning of each line for your information. :). Plus I have echo on temporarily, for erorr finding purposes, until the program is done. When an error occurs, I remove the @ at the beginning of the suspected line and try to fix the problem. My program apparently supports all of that. I have no clue why it doesn't work for you. Maybe I installed some kind of add-on that I can't remember?
May 23, 2005, 9:00 PM
Kp
What version of DOS is this, btw?  A Win9x-related DOS, or something earlier?
May 23, 2005, 10:05 PM
Yegg
Actually, I have no cluu what version this is. Is something different about it than usual?
May 24, 2005, 2:34 AM
Myndfyr
[quote author=Yegg link=topic=11651.msg113523#msg113523 date=1116882003]
I enjoy typing @ at the beginning of each line for your information. :). Plus I have echo on temporarily, for erorr finding purposes, until the program is done. When an error occurs, I remove the @ at the beginning of the suspected line and try to fix the problem. My program apparently supports all of that. I have no clue why it doesn't work for you. Maybe I installed some kind of add-on that I can't remember?
[/quote]

Adding the @ symbol to the beginning of a line had something to do with ensuring that the line only executes one time.  I'll have to look it up when I get home.  *shrug*
May 24, 2005, 3:27 AM
R.a.B.B.i.T
[quote author=Yegg link=topic=11651.msg113561#msg113561 date=1116902080]
Actually, I have no cluu what version this is. Is something different about it than usual?
[/quote]> ver
May 25, 2005, 10:55 PM

Search