Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ; command line parsing code for aclock
  2. ;
  3. ; Copyright (c) 2003 Thomas Mathys
  4. ; killer@vantage.ch
  5. ;
  6. ; This program is free software; you can redistribute it and/or modify
  7. ; it under the terms of the GNU General Public License as published by
  8. ; the Free Software Foundation; either version 2 of the License, or
  9. ; (at your option) any later version.
  10. ;
  11. ; This program is distributed in the hope that it will be useful,
  12. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ; GNU General Public License for more details.
  15. ;
  16. ; You should have received a copy of the GNU General Public License
  17. ; along with this program; if not, write to the Free Software
  18. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19. ;
  20. %ifndef _CMDLINE_INC
  21. %define _CMDLINE_INC
  22.  
  23.  
  24. ;********************************************************************
  25. ;       parse the command line
  26. ;       input           :       nothing
  27. ;       output          :       wndXPos, wndYPos, wndWidth, wndHeight
  28. ;                               are changed.
  29. ;       destroys        :       nothing
  30. ;********************************************************************
  31. parseCommandLine:
  32.         pushad
  33.         pushfd
  34.  
  35.         ; terminate command line, just to be sure
  36.         mov     byte [cmdLine + 256],0
  37.  
  38.         ; go through all tokens
  39.         mov     eax,cmdLine             ; eax -> command line
  40. .parseloop:
  41.         mov     ebx,delimiters          ; ebx -> token delimiter list
  42.         call    strtok                  ; get next parameter
  43.         or      eax,eax                 ; no more parameters ?
  44.         jz      .nomoretokens
  45.         mov     cl,[eax]                ; get 1st char of parameter
  46.         cmp     cl,'x'                  ; which parameter is it ?
  47.         je      .param_x
  48.         cmp     cl,'y'
  49.         je      .param_y
  50.         cmp     cl,'w'
  51.         je      .param_w
  52.         cmp     cl,'h'
  53.         je      .param_h
  54.         ; if we reach this line it's an unknown parameter, ignore it
  55. .nextparam:
  56.         xor     eax,eax                 ; set eax = 0 to continue
  57.         jmp     .parseloop              ; after last token.
  58. .nomoretokens:
  59.         DBG_BOARD_PRINTDWORD [wndXPos]
  60.         DBG_BOARD_PRINTCHAR 32
  61.         DBG_BOARD_PRINTDWORD [wndYPos]
  62.         DBG_BOARD_PRINTCHAR 32
  63.         DBG_BOARD_PRINTDWORD [wndWidth]
  64.         DBG_BOARD_PRINTCHAR 32
  65.         DBG_BOARD_PRINTDWORD [wndHeight]
  66.         DBG_BOARD_PRINTNEWLINE
  67.         popfd
  68.         popad
  69.         ret
  70.  
  71.         ; eax -> first character of the parameter
  72. .param_x:
  73.         push    eax
  74.         call    parsePositionParam
  75.         mov     [wndXPos],eax
  76.         pop     eax
  77.         jmp     .nextparam
  78.  
  79.         ; eax -> first character of the parameter
  80. .param_y:
  81.         push    eax
  82.         call    parsePositionParam
  83.         mov     [wndYPos],eax
  84.         pop     eax
  85.         jmp     .nextparam
  86.  
  87.         ; eax -> first character of the parameter
  88. .param_w:
  89.         push    eax
  90.         call    parseSizeParam
  91.         mov     [wndWidth],eax
  92.         pop     eax
  93.         jmp     .nextparam
  94.  
  95.         ; eax -> first character of the parameter
  96. .param_h:
  97.         push    eax
  98.         call    parseSizeParam
  99.         mov     [wndHeight],eax
  100.         pop     eax
  101.         jmp     .nextparam
  102.  
  103. ; parse position parameter
  104. ; input         :       eax = address of first character of parameter
  105. ; output        :       eax contains position
  106. ; destroys      :       nothing
  107. parsePositionParam:
  108.         push    ebx
  109.         push    esi
  110.         pushfd
  111.  
  112.         ; is the second char of the parameter a '-' ?
  113.         inc     eax
  114.         xor     ebx,ebx                 ; assume it isn't
  115.         cmp     byte [eax],'-'
  116.         jne     .nominus
  117.         mov     ebx,1                   ; yes -> set flag...
  118.         inc     eax                     ; ...and move to next char
  119. .nominus:
  120.  
  121.         ; convert rest of parameter to doubleword
  122.         mov     esi,eax
  123.         call    string2dword
  124.  
  125.         ; negate if necessary
  126.         or      ebx,ebx
  127.         jz      .rotationshyperboloid
  128.         neg     eax
  129. .rotationshyperboloid:
  130.  
  131.         popfd
  132.         pop     esi
  133.         pop     ebx
  134.         ret
  135.  
  136. ; parse dimension parameter
  137. ; input         :       eax = address of first char of parameter
  138. ; output        :       eax contains dimension
  139. ; destroys      :       nothing
  140. parseSizeParam:
  141.         push    esi
  142.         pushfd
  143.         lea     esi,[eax + 1]           ; esi -> 2nd char of parameter
  144.         call    string2dword
  145.         popfd
  146.         pop     esi
  147.         ret
  148.  
  149.  
  150. %endif
  151.  
  152.