home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / MFKASM.ZIP / GET-CMD.ASM < prev    next >
Assembly Source File  |  1992-07-29  |  4KB  |  112 lines

  1. ;---------------------------------------------------------------------------;
  2. ; M.F.Kaplon  Begun:Mon  07-27-1992   Revised:Wed  07-29-1992
  3. ; Title : get-cmd.asm
  4. ;
  5. ; Get the command line using OS/2 call DosGetInfoBlocks
  6. ; In the command line the program name is 0 terminated and
  7. ; the remaining part of the command ine is 0 terminated
  8. ;
  9. ; Lists program name and # of space separated params passed on command line
  10. ;
  11. ; For System Function Calls
  12. ;
  13. ; 1 - Must use the C Calling Convention which means
  14. ;     Arguments Pushed on Stack in Reverse Order than declared in function
  15. ; 2 - Using .MODEL FLAT when using a pointer, all you have to do is push
  16. ;     the offset of the variable since in FLAT model everyting is NEAR
  17. ;     in the 32 bit space
  18. ; 3 - Uses a 16K stack
  19. ;
  20. ; cmd file to assemble and link is named mlc-w386
  21. ; and should be called as   :  mlc-w386 filename
  22. ; The cmd file assumes that "filename" is in d:\os2_asm
  23. ; Content of mlc-link386
  24. ;
  25. ; ml /c d:\os2_asm\%1.asm
  26. ; IF errorlevel 1  goto errexit
  27. ; link386 /PM:PM /ALIGN:16 /E %1.obj ;
  28. ; del *.obj
  29. ; quit
  30. ; :errexit
  31. ; Echo Compile Error NO Link
  32. ; --------------------------
  33. ;
  34. ; My source files are in D:\os2_asm and I make my calls from the C:
  35. ; root directory so that the EXE files and the OBJ file are in C:\
  36. ; and the EXE file has same name as the source file.
  37. ; If you are assembling and linking more than one then you have to
  38. ; make appropriate changes. The above does not make a map or list file
  39. ;
  40. ; I get one warning message
  41. ;
  42. ; LINK : warning L4036: no automatic data segment
  43. ;
  44. ; This message has to do with no DGROUP being defined
  45. ; It can be suppressed with DATA NONE in a "DEF" file
  46. ;
  47. ;---------------------------------------------------------------------------;
  48. ;
  49.  
  50. .386             ;preceeding .MODEL makes USE32 default
  51. .MODEL           FLAT,SYSCALL,OS_OS2
  52. ;---------- Conditionally required equates -------------
  53.  
  54. NUMBUFS             equ  1     ; Uncomment if need number routines
  55. ;
  56.  
  57. NOWIN               equ  1     ;Not a PM application
  58.  
  59. INCLUDE        c:\toolkt20\asm\os2inc\os2def.inc ;structure defns includes POINTL
  60. INCLUDELIB     c:\toolkt20\os2lib\os2386.lib     ;Library
  61.  
  62. INCLUDE        d:\os2_asm\equs386.inc       ;equates : MFK
  63. INCLUDE        d:\os2_asm\386_dos.mac       ;macros using DOS calls : MFK
  64.  
  65. .STACK    8096   ;8K stack
  66.  
  67. .DATA
  68.  
  69. IFDEF NUMBUFS                     ;To use  UNCOMMENT NUMBUFS equate above
  70.    $DefineNumBufs
  71. ENDIF
  72.  
  73. nwritten         DWORD   ?        ;needed for DosWrite
  74. NumParms         DWORD   0
  75. ;Command Line data
  76. ProgName          BYTE   9 dup(0) ;program name
  77.  
  78. .CODE
  79.  
  80. startup:                         ;need to do this way with flat model
  81.  
  82. ;----------- get command line ------------
  83.  
  84. $GetCmdLine
  85. mov     edi,offset  ProgName   ;initialize to zero
  86. ;-------------copy program name from command line to ProgName--------------
  87. .WHILE byte ptr [esi] != 0     ;get program name
  88.       movsb
  89. .ENDW
  90.  
  91. inc    esi                     ;now points to  1st space after command name
  92. .WHILE  byte ptr [esi] != 0    ;go to end of command line
  93.      .WHILE byte ptr [esi] == ' '
  94.           inc   esi
  95.      .ENDW
  96.      .IF byte ptr [esi] != ' ' && byte ptr [esi] != 0; if a space
  97.          inc    esi
  98.          inc    NumParms
  99.          .WHILE byte ptr [esi] != ' ' && byte ptr [esi] != 0
  100.               inc   esi
  101.          .ENDW
  102.      .ENDIF
  103. .ENDW
  104.  
  105. $DosWrite SIZEOF ProgName,offset ProgName,stdout
  106. $Printf s," Number of Space Separated Parameters on Command Line = ",dw,NumParms
  107. $NewLine
  108.  
  109. $DosExit
  110.  
  111. END   startup                  ;required
  112.