home *** CD-ROM | disk | FTP | other *** search
-
- **********************************************************************
- * This is my startup-routine, which passes in _ArgV a pointer to *
- * a ToolTypes-Array and in _ArgC there`s the amount of arguments. *
- * If _ArgC=0 you can bet, that the prg was launched from the Cli *
- * or by accessing the _OurTask variable. The routine opens the *
- * dos-/icon-libraries and stores the pointers to their bases *
- * in _DOSBase and _IconBase. *
- * You can access the Arguments passed to your program from the CLI *
- * by using FindToolType, since the arguments are handled the same *
- * as in the DiskObject-Structure :-) *
- *In _stdout you can find the handle to output, _stdin for input if *
- *the prg was launched from cli. This routine works on Kick 1.3 and on*
- * OS 2.x *
- * Written by Kai Iske in 1991. You can use it whereever you want, it *
- * is Public Domain......If you like it let me know....:-) *
- **********************************************************************
-
-
-
- IFND LIBRARIES_DOSEXTENS_I
- INCLUDE Libraries/DosExtens.i
- ENDC
-
- IFND WORKBENCH_STARTUP_I
- INCLUDE WorkBench/StartUp.i
- ENDC
-
- IFND EXEC_MEMORY_I
- INCLUDE Exec/Memory.i
- ENDC
-
- IFND WORKBENCH_WORKBENCH_I
- INCLUDE WorkBench/WorkBench.i
- ENDC
-
- IFND MISC_MYMACROS_I
- INCLUDE Misc/MyMacros.i
- ENDC
-
-
- HardStartUp20 movem.l d0/a0,-(sp) ; Store valuable registers
-
- lea .SUpDosName(pc),a1
- moveq #0,d0
- CALLSYS OpenLibrary
- tst.l d0
- beq .ErrorStartUp
- move.l d0,_DOSBase
-
- lea .SUpIconName(pc),a1
- moveq #0,d0
- DOLIB OpenLibrary
- tst.l d0
- beq .ErrorStartUp
- move.l d0,_IconBase
-
- sub.l a1,a1
- DOLIB FindTask
- move.l d0,_OurTask ; Get address of task
- move.l d0,a0
-
- movem.l (sp)+,d7/a4 ; Get registers
-
- tst.l pr_CLI(a0) ; Launched from CLI
- beq .FromWorkBench
-
- movem.l d7/a4,-(sp)
-
- LNKLIB Output,_DOSBase ; Get Output handle
- move.l d0,_stdout
-
- LNKLIB Input,_DOSBase ; Get Input handle
- move.l d0,_stdin
-
- movem.l (sp)+,d7/a4
-
- move.l _OurTask(pc),a0 ; Get address of command-name
- move.l pr_CLI(a0),a0
- add.l a0,a0
- add.l a0,a0
- move.l cli_CommandName(a0),a0
- add.l a0,a0
- add.l a0,a0
- move.l a0,.ComBuff ; Store address
- moveq #0,d0
- move.b 0(a0),d0 ; Length of Command-Name
- add.l d7,d0 ; + Length of command-line
- addq.l #2,d0 ; + two NULL-Bytes
- move.l d0,.ArgLen ; Store length
- move.l #MEMF_CLEAR|MEMF_CHIP,d1
- CALLSYS AllocMem ; Get memory for command-line
- tst.l d0
- beq .ErrorStartUp
- move.l d0,.ArgLine ; Store address
-
- move.l .ComBuff(pc),a0
- move.l .ArgLine(pc),a1
-
- moveq #0,d0
- move.b (a0)+,d0 ; Get len and skip length byte
- move.l d0,d6
- subq.l #1,d6
- .CpyCommand move.b (a0)+,(a1)+ ; Copy Command-Name
- dbf d6,.CpyCommand
- move.b #0,(a1)+ ; Mark end of string
- move.l a4,a0 ; Append command-line
- move.l d7,d6
- subq.l #1,d6
- .CpyCommandLine move.b (a0)+,(a1)+
- dbf d6,.CpyCommandLine
-
- move.l #1,_ArgC ; We already have on argument
- addq.l #1,d0 ; One more byte
- move.l .ArgLine(pc),a0
- add.l d0,a0 ; a0 = Start of command(s)
- move.l a0,a1
-
- .FindArgs moveq #0,d0
- move.b (a0)+,d0 ; Get char
- .FindArgStart cmp.b #' ',d0 ; as long as it is....
- beq .FindArgs ; a Space
- cmp.b #9,d0
- beq .FindArgs ; a Tab
- cmp.b #12,d0
- beq .FindArgs ; a FormFeed
- cmp.b #13,d0
- beq .FindArgs ; a Carrier Return
- cmp.b #10,d0
- beq .FindArgs ; or a return ist
- subq.l #1,a0 ; Reget char
- move.b (a0),d0
- cmp.b #' ',d0 ; Smaller than a SPACE ???
- blt.s .ArgsFound ; All args done
-
- cmp.b #'"',d0 ; Is it a quote ?
- bne.s .NoQuote ; no -> normal argument
- addq.l #1,a0 ; skip quote
- .DoQuotes move.b (a0)+,d0 ; Get new char
- move.b d0,(a1)+ ; Copy it to new location
- cmp.b #'"',d0 ; as long as it ain`t no quote
- bne.s .DoQuotes
- move.b (a0),d0 ; Next char
- cmp.b #'"',d0 ; again a quote
- bne.s .EndQuoteArg ; nope -> argument parsed
- addq.l #1,a0 ; skip and go on
- bra .DoQuotes
- .EndQuoteArg move.b #0,-1(a1) ; End of string
- bra.s .ArgDone
- .NoQuote move.b (a0)+,d0 ; Get char
- cmp.b #' ',d0 ; End it, if it is (see above)
- beq.s .EndNQuoteArg
- cmp.b #9,d0
- beq.s .EndNQuoteArg
- cmp.b #12,d0
- beq.s .EndNQuoteArg
- cmp.b #13,d0
- beq.s .EndNQuoteArg
- cmp.b #10,d0
- beq.s .EndNQuoteArg
- move.b d0,(a1)+ ; Copy char to new location
- bra .NoQuote ; Here we go again
- .EndNQuoteArg move.b #0,(a1)+ ; end of string
- .ArgDone addq.l #1,_ArgC ; one more argument
- tst.b d0 ; Is it an end of string ??
- bne .FindArgs ; No -> next arg
- subq.l #1,a0 ; one char backwards
- bra .FindArgs ; -> go on with next arg
- .ArgsFound move.b #0,(a1) ; Last end of string
- move.l _ArgC(pc),d0 ; Amount of args
- addq.l #1,d0 ; One more for the zero-pointer
- asl.l #2,d0 ; * 4 (for Pointer)
- move.l #MEMF_CLEAR|MEMF_CHIP,d1
- DOLIB AllocMem ; Get memory for ArgV
- tst.l d0
- beq .ErrorStartUp
- move.l d0,_ArgV
-
- move.l .ArgLine(pc),a0 ; Get address of parsed string
- move.l d0,a1
- move.l _ArgC(pc),d7
- subq.l #1,d7
- .MakeArgVs move.l a0,(a1)+ ; Store address of argument
- move.l a0,a2
- moveq #1,d0
- .GetArgLen tst.b (a2)+ ; Get length of argument
- beq.s .GotArgLen
- addq.l #1,d0
- bra .GetArgLen
- .GotArgLen add.l d0,a0 ; Get address of next arg
- dbf d7,.MakeArgVs ; Loop
- move.l #0,(a1) ; End of array
-
- bra.s .EndHardSUp20 ; finally start the prg
-
- .FromWorkBench move.l a0,a4
- lea pr_MsgPort(a4),a0 ; Wait for StartUp-Msg
- move.l a0,_WBMsgPort ; Store pointer to port
- CALLSYS WaitPort
- lea pr_MsgPort(a4),a0
- DOLIB GetMsg ; Get msg
- move.l d0,_WBStartUp
-
- move.l _WBStartUp(pc),a4
- move.l sm_ArgList(a4),a4 ; Get pointer to arglist
- cmp.l #0,a4 ; if NULL -> go on
- beq.s .EndHardSUp20
- move.l wa_Lock(a4),d1 ; Get lock to Prg-Dir
- LNKLIB CurrentDir,_DOSBase
- move.l wa_Name(a4),a0 ; Read in .info-File
- LNKLIB GetDiskObject,_IconBase
- tst.l d0 ; Error -> quit
- beq.s .ErrorStartUp
- move.l d0,.SUpDiskObj ; Store address
- move.l d0,a0
- move.l do_ToolTypes(a0),_ArgV ; Store pointer to array (like CLI)
- move.l #0,_ArgC ; No arguments (for identify)
-
- .EndHardSUp20 jsr _main ; Start main routine
- bra.s .NoErrorStartUp
-
- .ErrorStartUp move.l #20,d0 ; Prg-Failed
- .NoErrorStartUp move.l d0,-(sp) ; Store Error-Code
-
- tst.l _WBStartUp ; Did we come from WB ?
- beq.s .ExitFromDOS ; No -> go on
-
- tst.l .SUpDiskObj ; Do we have a Disk-Object ?
- beq.s .EndStartUp
- move.l .SUpDiskObj(pc),a0
- LNKLIB FreeDiskObject,_IconBase ; Free the object
- bra.s .EndStartUp
-
- .ExitFromDOS tst.l _ArgV ; Do we have ArgV ?
- beq.s .NoArgV
- move.l _ArgV(pc),a1 ; Free memory
- move.l _ArgC(pc),d0
- addq.l #1,d0
- asl.l #2,d0
- CALLSYS FreeMem
-
- .NoArgV tst.l .ArgLine ; Command-buffer ?
- beq.s .EndStartUp
- move.l .ArgLine(pc),a1 ; Free memory
- move.l .ArgLen(pc),d0
- DOLIB FreeMem
-
- .EndStartUp tst.l _IconBase
- beq.s .NoSIBase
- move.l _IconBase(pc),a1
- CALLSYS CloseLibrary
-
- .NoSIBase tst.l _DOSBase
- beq.s .NoSDBase
- move.l _DOSBase(pc),a1
- DOLIB CloseLibrary
-
- .NoSDBase tst.l _WBStartUp
- beq.s .NoWB
- CALLSYS Forbid
- move.l _WBStartUp(pc),a1 ; Finally reply the Msg
- DOLIB ReplyMsg
-
- .NoWB move.l (sp)+,d0 ; restore error-code
- rts
- .SUpIconName dc.b "icon.library",0
- EVEN
- .SUpDosName dc.b "dos.library",0
- EVEN
- .ArgLine dc.l 0
- .ArgLen dc.l 0
- .ComBuff dc.l 0
- .SUpDiskObj dc.l 0
- _ArgC dc.l 0
- _ArgV dc.l 0
- _stdout dc.l 0
- _stdin dc.l 0
- _OurTask dc.l 0
- _WBMsgPort dc.l 0
- _WBStartUp dc.l 0
- _DOSBase dc.l 0
- _IconBase dc.l 0
-
- _main
-
-