Valhalla Legends Archive

Programming => General Programming => Topic started by: Yegg on May 20, 2005, 04:04 PM

Title: MS-DOS String Parsing
Post by: Yegg on May 20, 2005, 04:04 PM
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?
Title: Re: MS-DOS String Parsing
Post by: Kp on May 20, 2005, 05:07 PM
Sure.getc(); getc(); getc();
c = getc();
printf ("%c", c);
Title: Re: MS-DOS String Parsing
Post by: Yegg on May 20, 2005, 05:27 PM
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?
Title: Re: MS-DOS String Parsing
Post by: Maddox on May 20, 2005, 05:29 PM
This reminds me of another recent thread.
Title: Re: MS-DOS String Parsing
Post by: Warrior on May 20, 2005, 05:41 PM
Yegg, we have different definitions of Complex it seems </melaughingatsarcasmovertheinternet>
Title: Re: MS-DOS String Parsing
Post by: Kp on May 20, 2005, 06:02 PM
Quote from: Yegg on May 20, 2005, 05:27 PM
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?

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.
Title: Re: MS-DOS String Parsing
Post by: Newby on May 20, 2005, 06:15 PM
Specify the language.
Title: Re: MS-DOS String Parsing
Post by: R.a.B.B.i.T on May 20, 2005, 06:30 PM
That would help...
Title: Re: MS-DOS String Parsing
Post by: Yegg on May 20, 2005, 06:47 PM
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.
Title: Re: MS-DOS String Parsing
Post by: Kp on May 20, 2005, 08:48 PM
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!).
Title: Re: MS-DOS String Parsing
Post by: Newby on May 20, 2005, 09:34 PM
I'm gonna go out on a limb here and guess he wants it in batch.
Title: Re: MS-DOS String Parsing
Post by: MyndFyre on May 20, 2005, 11:11 PM
Quote from: Newby on May 20, 2005, 09:34 PM
I'm gonna go out on a limb here and guess he wants it in batch.

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.
Title: Re: MS-DOS String Parsing
Post by: Mangix on May 21, 2005, 12:11 AM
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.
Title: Re: MS-DOS String Parsing
Post by: effect on May 21, 2005, 01:35 AM
Quote from: Mangix on May 21, 2005, 12:11 AM
he used to program in DOS.

Quote from: Mangix on May 21, 2005, 12:11 AM
yes DOS isnt a Programming Language.

Your such a moron u make me cry!
Title: Re: MS-DOS String Parsing
Post by: R.a.B.B.i.T on May 21, 2005, 08:03 AM
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.
Title: Re: MS-DOS String Parsing
Post by: Yegg on May 21, 2005, 01:55 PM
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.
Title: Re: MS-DOS String Parsing
Post by: Adron on May 21, 2005, 06:06 PM
Quote from: Yegg on May 21, 2005, 01:55 PM
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.

It's impossible with only what's built-in to the MS-DOS batch file (command) interpreter. You need to call some program.
Title: Re: MS-DOS String Parsing
Post by: Yegg on May 21, 2005, 07:00 PM
    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;

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.
Title: Re: MS-DOS String Parsing
Post by: Kp on May 21, 2005, 07:10 PM
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. :)
Title: Re: MS-DOS String Parsing
Post by: Yegg on May 21, 2005, 07:14 PM
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.
Title: Re: MS-DOS String Parsing
Post by: Adron on May 22, 2005, 10:47 AM
Quote from: Yegg on May 21, 2005, 07:14 PM
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.

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:


for %%a in (0 1 2 3 4 5 6 7 8 9 10 11 12) do ...
Title: Re: MS-DOS String Parsing
Post by: Yegg on May 22, 2005, 05:24 PM
Quote from: Adron on May 22, 2005, 10:47 AM
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.
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.
Title: Re: MS-DOS String Parsing
Post by: Kp on May 22, 2005, 09:47 PM
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.
Title: Re: MS-DOS String Parsing
Post by: R.a.B.B.i.T on May 22, 2005, 10:23 PM
Maybe he's writing in BASIC?
Title: Re: MS-DOS String Parsing
Post by: Adron on May 23, 2005, 12:43 AM
Quote from: Yegg on May 22, 2005, 05:24 PM
Quote from: Adron on May 22, 2005, 10:47 AM
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.
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.

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.
Title: Re: MS-DOS String Parsing
Post by: Yegg on May 23, 2005, 02:38 PM
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).
:: 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
Title: Re: MS-DOS String Parsing
Post by: iNsAnE-MS on May 23, 2005, 03:11 PM
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!
Title: Re: MS-DOS String Parsing
Post by: Yegg on May 23, 2005, 04:00 PM
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?
Title: Re: MS-DOS String Parsing
Post by: Kp on May 23, 2005, 05:05 PM
What version of DOS is this, btw?  A Win9x-related DOS, or something earlier?
Title: Re: MS-DOS String Parsing
Post by: Yegg on May 23, 2005, 09:34 PM
Actually, I have no cluu what version this is. Is something different about it than usual?
Title: Re: MS-DOS String Parsing
Post by: MyndFyre on May 23, 2005, 10:27 PM
Quote from: Yegg on May 23, 2005, 04:00 PM
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?

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*
Title: Re: MS-DOS String Parsing
Post by: R.a.B.B.i.T on May 25, 2005, 05:55 PM
Quote from: Yegg on May 23, 2005, 09:34 PM
Actually, I have no cluu what version this is. Is something different about it than usual?
> ver