Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with command line

Status
Not open for further replies.

NyCzMaGiX

Programmer
Nov 30, 2001
2
US
Hello All,
I'm trying to get the input filename and output filename from a user using the command line.

The only problem is, this doesn't seem to open the input filename. I am assuming that 81h is always going to be a space, therefore I started with 82h.

ex. thisprogram input.txt output.txt

I am storing "input.txt "
Should I be decreasing the variable by 1 position and then adding a 0 to the end like I'm doing in this program and am I doing it right?

Am I saving my handles correct as well?

Thank you very much.



MOV SI, 82h
XOR DI, DI

MOV AL, BYTE PTR ES:[SI]
CMP AL, 0dh
JE MISSING

INC SI
CMP AL, 0dh
JE MISSING

INPUT1:
CMP AL, 20h ; Test for Space
JE PREINPUT2
MOV NAME1[DI], AL
INC DI
INC SI
JMP INPUT1


PREINPUT2:
MOV NAME1[DI], 30h
INC SI
MOV DX, offset CHECK1 ; Display Check1
INT 21h
XOR DI, DI

INPUT2:
MOV AL, BYTE PTR ES:[SI]
CMP AL, 0Dh
JE MISSING1
CMP AL, 20h
JE OPENIN

MOV NAME2[DI], AL
INC DI
INC SI
JMP INPUT2

OPENIN:
MOV NAME2[DI], 0
MOV AH, 9
MOV DX, offset ANSCHECK
INT 21h

MOV DX, offset CHECK2 ; Display Check2
INT 21h
CLC

MOV DX, offset NAME1
MOV AH, 3Dh ; Open file code
MOV AL, 0
INT 21h
JC ERROR1
MOV HANDLE1, AX ; Save Open Input Handle
JMP OUTPUT

ERROR1:
JMP MISSMESSAGE1

MISSING1:
CALL MISSMESSAGE1
JMP THEEND


MISSMESSAGE1 proc
MOV AH, 9
MOV DX, offset INERROR
INT 21h
ret
MISSMESSAGE1 endp



CHECK1 DB 'Checking for Valid Input Filename...',0dh,0ah,'$'
CHECK2 DB 'Checking for Valid Output Filename...',0dh,0ah,'$'
ANSCHECK DB 'Check Done ... OK',0dh,0ah,'$'
INERROR DB '*ERROR with Input File*', 0dh, 0ah, '$'
NAME1 DB 32 DUP (?)
 
Hello,

Your code is a mess and doesn't work, so I wrote a program that seems to do what you want:

[tt]CODE SEGMENT
ASSUME CS:CODE,DS:CODE,ES:CODE

ORG 0100H
START:
MOV SI,82h ; copy from here (DS)
MOV DI,OFFSET NAME1 ; store it here (ES)
CMP BYTE PTR [SI-2],0 ; Any characters on commandline?
JE NOCMDLINE ; No
LOOP1:
LODSB ; same as mov al,[ds:si] inc si
STOSB ; same as mov [es:di],al inc di
CMP AL,20H ; space? (end of first file)
JNE CHECKEOL ; no, check for end of line
MOV BYTE PTR [DI-1],0 ; close first filename
MOV DI,OFFSET NAME2 ; store it here
JMP LOOP1 ; continue
CHECKEOL:
CMP AL,0DH ; end of line character?
JNE LOOP1 ; no, do next one
MOV BYTE PTR [DI-1],0 ; close filename

CMP BYTE PTR [NAME2],0 ; second filename copied
JE NOCMDLINE

MOV AX,3D00h ; Open file for reading
MOV DX,OFFSET NAME1 ; First name
INT 21H
JNC FILE1OPEN ; Fault with opening? No
MOV DX,OFFSET F1FAULT ; Display faultmessage
ERROR:
MOV AH,9 ; do display
INT 21H
INT 20H ; terminate .COM program
NOCMDLINE:
MOV DX,OFFSET NOFN ; No filenames found
JMP ERROR ; print message
FILE1OPEN: ; First file is opened
; rest of program
INT 20H

NOFN DB 'Two filenames on commandline needed',13,10,'$'
F1FAULT DB 'Error opening first file',13,10,'$'

NAME1 DB 32 DUP (0)
NAME2 DB 32 DUP (0)

CODE ENDS
END START
[/tt] Wouter Dijkslag

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top