Hi

I want to be reducing the use of status_replace so I don't want to add
it back to display-message.

It is a good idea to use format_* inside status_replace, but first it
needs to be changed to support the length modifiers. Then it can replace
most of status_replace1. I haven't done this yet because I haven't
really decided what to do with jobs.

Cheers



On Sat, Mar 03, 2012 at 11:35:57PM -0500, Ben Boeckel wrote:
> Hi,
> 
> Attached is a patch which cleans up memory in display-message when using
> a format. It also puts the message back through status_replace for the
> strftime expansion (reduce duplication of code and such).
> 
> In addition, status_replace has its own format_tree which expands
> session and client information.
> 
> --Ben

> diff --git a/cmd-display-message.c b/cmd-display-message.c
> index 1b87e77..f8b69d0 100644
> --- a/cmd-display-message.c
> +++ b/cmd-display-message.c
> @@ -49,8 +49,7 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx 
> *ctx)
>       const char              *template;
>       char                    *msg;
>       struct format_tree      *ft;
> -     char                     out[BUFSIZ];
> -     time_t                   t;
> +     char                    *line;
>  
>       if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
>               return (-1);
> @@ -77,19 +76,18 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx 
> *ctx)
>               template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)";
>  
>       ft = format_create();
> -     format_client(ft, c);
> -     format_session(ft, s);
>       format_winlink(ft, s, wl);
>       format_window_pane(ft, wp);
>  
> -     t = time(NULL);
> -     strftime(out, sizeof out, template, localtime(&t));
> +     line = format_expand(ft, template);
> +     msg = status_replace(c, s, wl, wp, line, time(NULL), 0);
>  
> -     msg = format_expand(ft, out);
>       if (args_has(self->args, 'p'))
>               ctx->print(ctx, "%s", msg);
>       else
>               status_message_set(c, "%s", msg);
> +     xfree(line);
> +     format_free(ft);
>       xfree(msg);
>  
>       return (0);
> diff --git a/status.c b/status.c
> index 4df6745..6d48fe8 100644
> --- a/status.c
> +++ b/status.c
> @@ -503,9 +503,10 @@ char *
>  status_replace(struct client *c, struct session *s, struct winlink *wl,
>      struct window_pane *wp, const char *fmt, time_t t, int jobsflag)
>  {
> -     static char     out[BUFSIZ];
> -     char            in[BUFSIZ], ch, *iptr, *optr;
> -     size_t          len;
> +     static char              out[BUFSIZ];
> +     char                     in[BUFSIZ], ch, *iptr, *optr, *line;
> +     size_t                   len;
> +     struct format_tree      *ft;
>  
>       len = strftime(in, sizeof in, fmt, localtime(&t));
>       in[len] = '\0';
> @@ -527,7 +528,15 @@ status_replace(struct client *c, struct session *s, 
> struct winlink *wl,
>       }
>       *optr = '\0';
>  
> -     return (xstrdup(out));
> +     ft = format_create();
> +     format_session(ft, s);
> +     format_client(ft, c);
> +
> +     line = format_expand(ft, out);
> +
> +     format_free(ft);
> +
> +     return line;
>  }
>  
>  /* Figure out job name and get its result, starting it off if necessary. */

> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing 
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/

> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to