Category : C Source Code
Archive   : ARGEX2.ZIP
Filename : ARGV.ASM

 
Output of file : ARGV.ASM contained in archive : ARGEX2.ZIP

NAME argv
PAGE 60,132
;
; Alternate startup code module for setting up argv[]
; This code mimics the Unix handling of wildcard file names
; as program arguments. They will be expanded into a list
; of matching file names, each in a separate argv[] string.
;
; The job of this function is to call a C function with
; required parameters. The C function does the necessary
; expansion.
;
; John Maline 6-21-87
; Turbo C 1.00
;
; Turbo C 1.5 compatibility
; - use _argv and _argc as identifiers (not __argv, __argc)
; John Maline 2-24-88
;
INCLUDE rules.asi

[email protected]

; Externals

[email protected] _argc, WORD, __CDECL__
[email protected] _argv, __CDECL__
[email protected] _psp, WORD, __CDECL__
[email protected] _envseg, WORD, __CDECL__
[email protected] _envLng, WORD, __CDECL__
[email protected] _osmajor, BYTE, __CDECL__
[email protected] abort, __CDECL__
[email protected] _setargs, __CDECL__

CmdTailOfs equ 080h ; cmd tail offset in PSP

[email protected]

[email protected] _setargv, __CDECL__
;
; Set up parameters to expansion function
;
mov bp,sp
;
; Pointer to argc
;
IF LDATA
push ds
ENDIF
mov ax,offset [email protected]
push ax
;
; Pointer to argv pointer
;
IF LDATA
push ds
ENDIF
mov ax,offset [email protected]
push ax
;
; Far pointer to command tail
;
mov ax,[email protected]
push ax
mov ax,CmdTailOfs
push ax
;
; Far pointer to program name
; in DOS 3.x, prog name starts 2 bytes past end of environment
; in DOS 2.x, we don't get a prog name (give pointer to null string)
; we'll actually backup before the 2 junk bytes to the null
; that terminates the environment.
;
mov ax,[email protected]
push ax ;seg of prog name
mov ax,[email protected] ;end of env
dec ax ;back up to terminating \0
cmp [email protected],3
jb Dos2
add ax,3 ;DOS 3, mov up to prog name
Dos2 label near
push ax ;offs of prog name (or \0)
;
; Command line expansion function
; stat = _setargs(progname,cmdtail,argv,argc)
; (non-zero return indicates error)
;
call [email protected]
mov sp,bp ;fix stack
or ax,ax
jz ArgvOK ;zero return value?
jmp [email protected]

ArgvOK label near
ret

[email protected] _setargv, __CDECL__

[email protected]
END