Source file: /~heha/hs/runever.zip/runever.asm

	ideal
	P386
	model	flat

DELIM_NoTrimLeft=100h;
DELIM_NoTrimRight=200h;
DELIM_NilWhenNone=400h;	;{liefert NIL, wenn KEIN Element mehr da ist}
DELIM_Whitespace=800h;
ESCAP_SglQuote='''' shl 16;
ESCAP_DblQuote='"' shl 16;
DATASEG
IFDEF SHOWIT
MsgBoxTitle	db	'RUNEVER',0
ELSE
	db	?
ENDIF

CODESEG
extrn GetCommandLine: Proc
extrn MessageBox: Proc
extrn GetStartupInfo: Proc
extrn CreateProcess: Proc
extrn WaitForSingleObject: Proc
extrn FormatMessage: Proc
extrn GetLastError: Proc
extrn LocalFree: Proc

proc IsWS
;{testet AL auf Weißraum, d.h. $09, $0A, $0D, $20}
	cmp	al,09h
	jz	@@e
	cmp	al,0Ah
	jz	@@e
	cmp	al,0Dh
	jz	@@e
	cmp	al,' '
@@e:	ret
endp

proc OneItem stdcall
arg @s: dword, @escap_delim:dword
	 cld
	 mov	esi,[@s]
	 mov	edi,esi
	 or	esi,esi
	 jz	@@e	;{wenn da NIL drinsteht, immer durchreichen!}

	 mov	ecx,[dword @escap_delim+2]
	 mov	edx,[@escap_delim]

	 or	ch,ch
	 jnz	@@1
	 or	cl,cl
	 jz	@@1
	 mov	ch,cl	;{gleich machen wenn CH=0 und CL<>0}
@@1:
	 mov	ebx,edi	;{Abhack-Zeiger für TrimRight}
	 test	dh,1	;{NoTrimLeft?}
	 jnz	@@outquoteloop
@@trimleft:
	 lodsb
	 or al,al
	 jz @@raus
	 call	IsWS
	 jz	@@trimleft
	 jmp	@@oq1

@@oq3:	 mov	ebx,edi	;{Abhackposition vorrücken}
@@outquoteloop:
	 lodsb
	 or al,al
	 jz @@raus
@@oq1:	 cmp	al,cl
	 je	@@inquoteloop
	 test	dh,8	;{Whitespace als Trennzeichen?}
	 jnz	@@oq2
	 cmp	al,dl
	 je	@@raus_sep
	 stosb
	 test	dh,2	;{NoTrimRight?}
	 jnz	@@oq3
	 call	IsWS
	 jz	@@outquoteloop
	 jmp	@@oq3
@@oq2:
	 call	IsWS
	 jz	@@raus_sep
	 stosb
	 jmp	@@oq3

@@inquoteloop:
	 lodsb
	 or al,al
	 jz @@raus
	 cmp	al,ch
	 je	@@outquoteloop
	 stosb
	 mov	ebx,edi	;{hier jeden Weißraum mitnehmen!}
	 jmp	@@inquoteloop

@@raus:		;{ohne Separator: NIL in S einspeichern lassen!}
	 dec	esi	;{wieder AUF DIE NULL zurückstellen}
	 test	dh,4
	 jz	@@raus_sep
	 xor	esi,esi
@@raus_sep:
	;{Rechts-Trimmung ausführen, gleichzeitig terminieren}
	 mov	[byte ebx],0
	;{vorgerücktes S zurückliefern}
@@e:	 xchg	eax,esi	;{nach EAX}
	ret
endp

struc STARTUPINFO
 cb		dd	?
 lpReserved	dd	?
 lpDesktop	dd	?
 lpTitle	dd	?
 dwX		dd	?
 dwY		dd	?
 dwXSize	dd	?
 dwYSize	dd	?
 dwXCountChars	dd	?
 dwYCountChars	dd	?
 dwFillAttribute dd	?
 dwFlags	dd	?
 wShowWindow	dw	?
 cbReserved2	dw	?
 lpReserved2	dd	?
 hStdInput	dd	?
 hStdOutput	dd	?
 hStdError	dd	?
ends

struc PROCESS_INFORMATION
 hProcess	dd	?
 hThread	dd	?
 dwProcessId	dd	?
 dwThreadId	dd	?
ends

proc runever stdcall
local @startinf: StartupInfo
local @procinf: Process_Information
local @CmdLine: DWord
	call	GetCommandLine
	push	ESCAP_DblQuote or DELIM_Whitespace
	push	eax
	call	OneItem			;1. Argument (=Programmname) übergehen
	mov	[@CmdLine],eax
IFDEF SHOWIT
	push	1			;=MB_OKCancel
	push	offset MsgBoxTitle
	push	eax
	push	0
	call	MessageBox
	cmp	eax,1			;=IDOK
	jne	@@exi
ENDIF
@@l:
	lea	edi,[@startinf]
	mov	[(StartupInfo edi).cb],size STARTUPINFO
	push	edi
	call	GetStartupInfo		;Startup Info durchreichen
	lea	eax,[@procinf]
	push	eax
	lea	eax,[@startinf]
	push	eax
	xor	esi,esi
	push	esi
	push	esi
	push	esi
	push	esi
	push	esi
	push	esi
	push	[@CmdLine]
	push	esi
	call	CreateProcess
	or	eax,eax
	jz	@@e
	push	-1			;=unendlich
	push	[@procinf.hProcess]
	call	WaitForSingleObject
	jmp	@@l
@@e:
	lea	edi,[@CmdLine]
	call	GetLastError
	push	esi esi edi esi eax esi 1100h	;Allocate_Buffer|From_System
	call	FormatMessage
	mov	edi,[edi]
	push	esi esi edi esi
	call	MessageBox
	push	edi
	call	LocalFree	
@@exi:	ret
endp
	end	runever
Detected encoding: OEM (CP437)1
Wrong umlauts? - Assume file is ANSI (CP1252) encoded