about summary refs log tree commit diff stats
path: root/dwm.c
Commit message (Expand)AuthorAgeFilesLines
...
* applied Peter Hartlich's border collapse patchAnselm R. Garbe2007-09-301-3/+5
* improved tile() for the RESIZEHINTS == True case, now more space is consumed ...Anselm R. Garbe2007-09-271-5/+6
* fixed inclusion orderarg@suckless.org2007-09-271-1/+2
* introduced ISTILE, which can be easily extended with other layout functions t...Anselm R. Garbe2007-09-221-3/+3
* setmwfact and zoom check isarrange(floating) now, not !isarrange(tile) - this...Anselm R. Garbe2007-09-221-2/+2
* cosmetic fix 4.5Anselm R. Garbe2007-09-221-1/+2
* fixed a commentAnselm R. Garbe2007-09-201-1/+1
* applied Peters patch, applied yiyus hint to initfontarg@suckless.org2007-09-191-12/+12
* applied Peter Hartlich's togglemax patch to allow toggling tiled clients to m...Anselm R. Garbe2007-09-181-3/+12
* made all stuff non-static - so you can choose wether to use dwm the static or...arg@suckless.org2007-09-171-182/+179
* there might be envs which need Xlib.hAnselm R. Garbe2007-09-161-0/+1
* Mod1-Button2 on a floating but not-fixed client will make it tiled againAnselm R. Garbe2007-09-161-2/+6
* now tiled windows can be resized/moved, their floating state will be toggled ...Anselm R. Garbe2007-09-161-6/+10
* some more rearrangementsAnselm R. Garbe2007-09-161-147/+143
* ordered all functions alphabeticallyAnselm R. Garbe2007-09-161-1025/+1023
* corrected a misleading commentAnselm R. Garbe2007-09-161-1/+1
* macros which have been defined in config.h can only be used at function level...Anselm R. Garbe2007-09-161-6/+10
* ordered function forward definitionsAnselm R. Garbe2007-09-151-56/+57
* backporting my intro-comment of old dwm.hAnselm R. Garbe2007-09-151-1/+30
* removed grabkeys, not necessaryAnselm R. Garbe2007-09-151-26/+21
* micromizing dwm step 1Anselm R. Garbe2007-09-151-0/+1847
Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#
#
#            Nimrod's Runtime Library
#        (c) Copyright 2010 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## Parses & constructs URLs.


# From the spec:
#
#   This specification uses the Augmented Backus-Naur Form (ABNF)
#   notation of [RFC2234], including the following core ABNF syntax rules
#   defined by that specification: ALPHA (letters), CR (carriage return),
#   DIGIT (decimal digits), DQUOTE (double quote), HEXDIG (hexadecimal
#   digits), LF (line feed), and SP (space).
#
#
#   URI           = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
#
#   hier-part     = "//" authority path-abempty
#                 / path-absolute
#                 / path-rootless
#                 / path-empty
#
#   URI-reference = URI / relative-ref
#
#   absolute-URI  = scheme ":" hier-part [ "?" query ]
#
#  relative-ref  = relative-part [ "?" query ] [ "#" fragment ]
#
#   relative-part = "//" authority path-abempty
#                 / path-absolute
#                 / path-noscheme
#                 / path-empty
#
#   scheme        = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
#
#   authority     = [ userinfo "@" ] host [ ":" port ]
#   userinfo      = *( unreserved / pct-encoded / sub-delims / ":" )
#   host          = IP-literal / IPv4address / reg-name
#   port          = *DIGIT
#
#   IP-literal    = "[" ( IPv6address / IPvFuture  ) "]"
#
#   IPvFuture     = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
#
#   IPv6address   =                            6( h16 ":" ) ls32
#                 /                       "::" 5( h16 ":" ) ls32
#                 / [               h16 ] "::" 4( h16 ":" ) ls32
#                 / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
#                 / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
#                 / [ *3( h16 ":" ) h16 ] "::"    h16 ":"   ls32
#                 / [ *4( h16 ":" ) h16 ] "::"              ls32
#                 / [ *5( h16 ":" ) h16 ] "::"              h16
#                 / [ *6( h16 ":" ) h16 ] "::"
#
#   h16           = 1*4HEXDIG
#   ls32          = ( h16 ":" h16 ) / IPv4address
#   IPv4address   = dec-octet "." dec-octet "." dec-octet "." dec-octet
#
#   dec-octet     = DIGIT                 ; 0-9
#                 / %x31-39 DIGIT         ; 10-99
#                 / "1" 2DIGIT            ; 100-199
#                 / "2" %x30-34 DIGIT     ; 200-249
#                 / "25" %x30-35          ; 250-255
#
#   reg-name      = *( unreserved / pct-encoded / sub-delims )
#
#   path          = path-abempty    ; begins with "/" or is empty
#                 / path-absolute   ; begins with "/" but not "//"
#                 / path-noscheme   ; begins with a non-colon segment
#                 / path-rootless   ; begins with a segment
#                 / path-empty      ; zero characters
#
#   path-abempty  = *( "/" segment )
#   path-absolute = "/" [ segment-nz *( "/" segment ) ]
#   path-noscheme = segment-nz-nc *( "/" segment )
#   path-rootless = segment-nz *( "/" segment )
#   path-empty    = 0<pchar>
#
#   segment       = *pchar
#   segment-nz    = 1*pchar
#   segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
#                 ; non-zero-length segment without any colon ":"
#
#   pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
#
#   query         = *( pchar / "/" / "?" )
#
#   fragment      = *( pchar / "/" / "?" )
#
#   pct-encoded   = "%" HEXDIG HEXDIG
#
#   unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
#   reserved      = gen-delims / sub-delims
#   gen-delims    = ":" / "/" / "?" / "#" / "[" / "]" / "@"
#   sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
#                 / "*" / "+" / "," / ";" / "="
#


import strutils

type
  TUrl* = tuple[      ## represents a *Uniform Resource Locator* (URL)
                      ## any optional component is "" if it does not exist
    protocol: string  ## for example ``http:``
    username: string  ## for example ``paul`` (optional)
    password: string  ## for example ``r2d2`` (optional)
    subdomain: string ## 
    domain,
    port,
    path,
    query,
    anchor: string]

proc host*(u: TUrl): string =
  ## returns the host of the URL

proc parse*(url: string): TURL =
  const pattern = r"([a-zA-Z]+://)?(.+@)?(.+\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?"
  var m: array[0..7, string] #Array with the matches
  discard regexprs.match(url, pattern, m)
 
  var msplit = m[2].split(':')

  var username: string = ""
  var password: string = ""
  if m[2] != "":
    username = msplit[0]
    if msplit.len() == 2:
      password = msplit[1].replace("@", "")

  var path: string = ""
  var query: string = ""
  var anchor: string = ""
     
  if m[7] != nil:
    msplit = m[7].split('?')
    path = msplit[0]
    query = ""
    anchor = ""
    if msplit.len() == 2:
      query = "?" & msplit[1]
     
    msplit = path.split('#')
    if msplit.len() == 2:
      anchor = "#" & msplit[1]
      path = msplit[0]
    msplit = query.split('#')
    if msplit.len() == 2:
      anchor = "#" & msplit[1]
      query = msplit[0]
 
  result = (protocol: m[1], username: username, password: password,
    subdomain: m[3], domain: m[4] & m[5], port: m[6], path: path, query: query, anchor: anchor)
 
when isMainModule:
  proc test(r: TURL) =
    echo("protocol=" & r.protocol)
    echo("username=" & r.username)
    echo("password=" & r.password)
    echo("subdomain=" & r.subdomain)
    echo("domain=" & r.domain)
    echo("port=" & r.port)
    echo("path=" & r.path)
    echo("query=" & r.query)
    echo("anchor=" & r.anchor)
    echo("---------------")
   
  var r: TUrl
  r = parse(r"http://google.co.uk/search?var=bleahdhsad")
  test(r)
  r = parse(r"http://dom96:test@google.com:80/search.php?q=562gs6&foo=6gs6&bar=7hs6#test")
  test(r)
  r = parse(r"http://www.google.co.uk/search?q=multiple+subdomains&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:pl:official&client=firefox-a")
  test(r)