Subversion Repositories SvarDOS

Rev

Rev 500 | Rev 506 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 500 Rev 505
Line 29... Line 29...
29
#include <string.h>
29
#include <string.h>
30
 
30
 
31
#include <process.h>
31
#include <process.h>
32
 
32
 
33
#include "cmd.h"
33
#include "cmd.h"
-
 
34
#include "doserr.h"
34
#include "env.h"
35
#include "env.h"
35
#include "helpers.h"
36
#include "helpers.h"
36
#include "redir.h"
37
#include "redir.h"
37
#include "rmodinit.h"
38
#include "rmodinit.h"
38
#include "sayonara.h"
39
#include "sayonara.h"
Line 534... Line 535...
534
  unsigned short batname_seg = FP_SEG(rmod->batfile);
535
  unsigned short batname_seg = FP_SEG(rmod->batfile);
535
  unsigned short batname_off = FP_OFF(rmod->batfile);
536
  unsigned short batname_off = FP_OFF(rmod->batfile);
536
  unsigned short filepos_cx = rmod->batnextline >> 16;
537
  unsigned short filepos_cx = rmod->batnextline >> 16;
537
  unsigned short filepos_dx = rmod->batnextline & 0xffff;
538
  unsigned short filepos_dx = rmod->batnextline & 0xffff;
538
  unsigned char blen = 0;
539
  unsigned char blen = 0;
-
 
540
  unsigned short errv = 0;
539
 
541
 
540
  /* open file, jump to offset filpos, and read data into buff.
542
  /* open file, jump to offset filpos, and read data into buff.
541
   * result in blen (unchanged if EOF or failure). */
543
   * result in blen (unchanged if EOF or failure). */
542
  _asm {
544
  _asm {
543
    push ax
545
    push ax
544
    push bx
546
    push bx
545
    push cx
547
    push cx
546
    push dx
548
    push dx
547
 
549
 
548
    /* open file (read-only) */
550
    /* open file (read-only) */
-
 
551
    mov bx, 0xffff        /* preset BX to 0xffff to detect error conditions */
549
    mov dx, batname_off
552
    mov dx, batname_off
550
    mov ax, batname_seg
553
    mov ax, batname_seg
551
    push ds     /* save DS */
554
    push ds     /* save DS */
552
    mov ds, ax
555
    mov ds, ax
553
    mov ax, 0x3d00
556
    mov ax, 0x3d00
554
    int 0x21    /* handle in ax on success */
557
    int 0x21    /* handle in ax on success */
555
    pop ds      /* restore DS */
558
    pop ds      /* restore DS */
556
    jc DONE
559
    jc ERR
557
    mov bx, ax  /* save handle to bx */
560
    mov bx, ax  /* save handle to bx */
558
 
561
 
559
    /* jump to file offset CX:DX */
562
    /* jump to file offset CX:DX */
560
    mov ax, 0x4200
563
    mov ax, 0x4200
561
    mov cx, filepos_cx
564
    mov cx, filepos_cx
562
    mov dx, filepos_dx
565
    mov dx, filepos_dx
563
    int 0x21  /* CF clear on success, DX:AX set to cur pos */
566
    int 0x21  /* CF clear on success, DX:AX set to cur pos */
564
    jc CLOSEANDQUIT
567
    jc ERR
565
 
568
 
566
    /* read the line into buff */
569
    /* read the line into buff */
567
    mov ah, 0x3f
570
    mov ah, 0x3f
568
    xor ch, ch
571
    xor ch, ch
569
    mov cl, buffmaxlen
572
    mov cl, buffmaxlen
570
    mov dx, buff
573
    mov dx, buff
571
    int 0x21 /* CF clear on success, AX=number of bytes read */
574
    int 0x21 /* CF clear on success, AX=number of bytes read */
572
    jc CLOSEANDQUIT
575
    jc ERR
573
    mov blen, al
576
    mov blen, al
-
 
577
    jmp CLOSEANDQUIT
-
 
578
 
-
 
579
    ERR:
-
 
580
    mov errv, ax
574
 
581
 
575
    CLOSEANDQUIT:
582
    CLOSEANDQUIT:
576
    /* close file (handle in bx) */
583
    /* close file (if bx contains a handle) */
-
 
584
    cmp bx, 0xffff
-
 
585
    je DONE
577
    mov ah, 0x3e
586
    mov ah, 0x3e
578
    int 0x21
587
    int 0x21
579
 
588
 
580
    DONE:
589
    DONE:
581
    pop dx
590
    pop dx
Line 584... Line 593...
584
    pop ax
593
    pop ax
585
  }
594
  }
586
 
595
 
587
  /* printf("blen=%u filepos_cx=%u filepos_dx=%u\r\n", blen, filepos_cx, filepos_dx); */
596
  /* printf("blen=%u filepos_cx=%u filepos_dx=%u\r\n", blen, filepos_cx, filepos_dx); */
588
 
597
 
-
 
598
  if (errv != 0) outputnl(doserr(errv));
-
 
599
 
589
  /* on EOF - abort processing the bat file */
600
  /* on EOF - abort processing the bat file */
590
  if (blen == 0) goto OOPS;
601
  if (blen == 0) goto OOPS;
591
 
602
 
592
  /* find nearest \n to inc batch offset and replace \r by NULL terminator
603
  /* find nearest \n to inc batch offset and replace \r by NULL terminator
593
   * I support all CR/LF, CR- and LF-terminated batch files */
604
   * I support all CR/LF, CR- and LF-terminated batch files */