On Thu, Sep 13, 2012 at 11:19 PM, Roberto E. Vargas Caballero
<[email protected]> wrote:
> xinit() is the function which performs all the X Windows initilization, so
> it can be desired doing the geometry parsing into that function, and let the
> argv loop of main as simple like other parameter cases.
> ---
>  st.c |   53 +++++++++++++++++++++++++++--------------------------
>  1 file changed, 27 insertions(+), 26 deletions(-)
>
> diff --git a/st.c b/st.c
> index 868300c..e87a0cd 100644
> --- a/st.c
> +++ b/st.c
> @@ -358,6 +358,7 @@ static Selection sel;
>  static int iofd = -1;
>  static char **opt_cmd  = NULL;
>  static char *opt_io    = NULL;
> +static char *opt_geo   = NULL;
>  static char *opt_title = NULL;
>  static char *opt_embed = NULL;
>  static char *opt_class = NULL;
> @@ -1965,6 +1966,11 @@ xinit(void) {
>         Cursor cursor;
>         Window parent;
>         int sw, sh;
> +       int bitm, xr, yr;
> +       unsigned int wr, hr;
> +
> +       xw.fw = xw.fh = xw.fx = xw.fy = 0;
> +       xw.isfixed = False;
>
>         if(!(xw.dpy = XOpenDisplay(NULL)))
>                 die("Can't open display\n");
> @@ -1981,6 +1987,23 @@ xinit(void) {
>         xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
>         xloadcols();
>
> +       if(opt_geo) {
> +               bitm = XParseGeometry(opt_geo, &xr, &yr, &wr, &hr);
> +               if(bitm & XValue)
> +                       xw.fx = xr;
> +               if(bitm & YValue)
> +                       xw.fy = yr;
> +               if(bitm & WidthValue)
> +                       xw.fw = (int)wr;
> +               if(bitm & HeightValue)
> +                       xw.fh = (int)hr;
> +               if(bitm & XNegative && xw.fx == 0)
> +                       xw.fx = -1;
> +               if(bitm & XNegative && xw.fy == 0)
> +                       xw.fy = -1;
> +               if(xw.fh != 0 && xw.fw != 0)
> +                       xw.isfixed = True;
> +       }
>         /* adjust fixed window geometry */
>         if(xw.isfixed) {
>                 sw = DisplayWidth(xw.dpy, xw.scr);
> @@ -2378,11 +2401,7 @@ run(void) {
>
>  int
>  main(int argc, char *argv[]) {
> -       int i, bitm, xr, yr;
> -       unsigned int wr, hr;
> -
> -       xw.fw = xw.fh = xw.fx = xw.fy = 0;
> -       xw.isfixed = False;
> +       int i;
>
>         for(i = 1; i < argc; i++) {
>                 switch(argv[i][0] != '-' || argv[i][2] ? -1 : argv[i][1]) {
> @@ -2398,31 +2417,13 @@ main(int argc, char *argv[]) {
>                 case 'f':
>                         if(++i < argc) opt_io = argv[i];
>                         break;
> +               case 'g':
> +                       if(++i < argc) opt_geo = argv[i];
> +                       break;
>                 case 'e':
>                         /* eat every remaining arguments */
>                         if(++i < argc) opt_cmd = &argv[i];
>                         goto run;
> -               case 'g':
> -                       if(++i >= argc)
> -                               break;
> -
> -                       bitm = XParseGeometry(argv[i], &xr, &yr, &wr, &hr);
> -                       if(bitm & XValue)
> -                               xw.fx = xr;
> -                       if(bitm & YValue)
> -                               xw.fy = yr;
> -                       if(bitm & WidthValue)
> -                               xw.fw = (int)wr;
> -                       if(bitm & HeightValue)
> -                               xw.fh = (int)hr;
> -                       if(bitm & XNegative && xw.fx == 0)
> -                               xw.fx = -1;
> -                       if(bitm & XNegative && xw.fy == 0)
> -                               xw.fy = -1;
> -
> -                       if(xw.fh != 0 && xw.fw != 0)
> -                               xw.isfixed = True;
> -                       break;
>                 case 'v':
>                 default:
>                         die(USAGE);
> --
> 1.7.10.4
>

-1
argv parsing belongs into one place.
the other two patches look fine (although not sure if I need them).

cheers!
mar77i

Reply via email to