On Wed, Sep 16, 2015 at 10:36:57PM -0400, Michael McConville wrote:

> Michael McConville wrote:
> > fmt.c contains two functions that are only called by command() in
> > print.c. One of them is tiny, too. It seems simpler to have them in
> > print.c as statics.
> 
> I forgot to mention that I also changed their argument leftp's type from
> int to size_t, because that's what it's used as. Probably unnecessary.

It's bad for history to mix code changes and reorganizations. Beside
that, I do not see the point.

        -Otto

> 
> 
> > Index: Makefile
> > ===================================================================
> > RCS file: /cvs/src/bin/ps/Makefile,v
> > retrieving revision 1.9
> > diff -u -p -r1.9 Makefile
> > --- Makefile        16 Jul 2014 19:57:34 -0000      1.9
> > +++ Makefile        17 Sep 2015 02:24:50 -0000
> > @@ -1,7 +1,7 @@
> >  #  $OpenBSD: Makefile,v 1.9 2014/07/16 19:57:34 okan Exp $
> >  
> >  PROG=      ps
> > -SRCS=      fmt.c keyword.c nlist.c print.c ps.c
> > +SRCS=      keyword.c nlist.c print.c ps.c
> >  DPADD=     ${LIBM} ${LIBKVM}
> >  LDADD=     -lm -lkvm
> >  
> > Index: extern.h
> > ===================================================================
> > RCS file: /cvs/src/bin/ps/extern.h,v
> > retrieving revision 1.17
> > diff -u -p -r1.17 extern.h
> > --- extern.h        29 Jun 2015 15:03:33 -0000      1.17
> > +++ extern.h        17 Sep 2015 02:24:50 -0000
> > @@ -48,8 +48,6 @@ void       command(const struct kinfo_proc *,
> >  void        cputime(const struct kinfo_proc *, VARENT *);
> >  int         donlist(void);
> >  void        emulname(const struct kinfo_proc *, VARENT *);
> > -void        fmt_puts(const char *, int *);
> > -void        fmt_putc(int, int *);
> >  double      getpcpu(const struct kinfo_proc *);
> >  double      getpmem(const struct kinfo_proc *);
> >  void        gname(const struct kinfo_proc *, VARENT *);
> > Index: fmt.c
> > ===================================================================
> > RCS file: fmt.c
> > diff -N fmt.c
> > --- fmt.c   5 Jan 2015 13:14:24 -0000       1.13
> > +++ /dev/null       1 Jan 1970 00:00:00 -0000
> > @@ -1,82 +0,0 @@
> > -/* $OpenBSD: fmt.c,v 1.13 2015/01/05 13:14:24 tedu Exp $   */
> > -
> > -/*-
> > - * Copyright (c) 1990, 1993, 1994
> > - * The Regents of the University of California.  All rights reserved.
> > - *
> > - * Redistribution and use in source and binary forms, with or without
> > - * modification, are permitted provided that the following conditions
> > - * are met:
> > - * 1. Redistributions of source code must retain the above copyright
> > - *    notice, this list of conditions and the following disclaimer.
> > - * 2. Redistributions in binary form must reproduce the above copyright
> > - *    notice, this list of conditions and the following disclaimer in the
> > - *    documentation and/or other materials provided with the distribution.
> > - * 3. Neither the name of the University nor the names of its contributors
> > - *    may be used to endorse or promote products derived from this software
> > - *    without specific prior written permission.
> > - *
> > - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
> > - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> > - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
> > PURPOSE
> > - * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
> > - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
> > CONSEQUENTIAL
> > - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> > - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> > - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
> > STRICT
> > - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 
> > WAY
> > - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> > - * SUCH DAMAGE.
> > - */
> > -
> > -#include <sys/types.h>
> > -#include <sys/resource.h>
> > -#include <stdio.h>
> > -#include <stdlib.h>
> > -#include <string.h>
> > -#include <unistd.h>
> > -#include <vis.h>
> > -#include "ps.h"
> > -
> > -void
> > -fmt_puts(const char *s, int *leftp)
> > -{
> > -   static char *v = NULL;
> > -   static size_t maxlen = 0;
> > -   size_t len;
> > -
> > -   if (*leftp == 0)
> > -           return;
> > -   len = strlen(s) * 4 + 1;
> > -   if (len > maxlen) {
> > -           free(v);
> > -           maxlen = 0;
> > -           if (len < getpagesize())
> > -                   len = getpagesize();
> > -           v = malloc(len);
> > -           if (v == NULL)
> > -                   return;
> > -           maxlen = len;
> > -   }
> > -   strvis(v, s, VIS_TAB | VIS_NL | VIS_CSTYLE);
> > -   if (*leftp != -1) {
> > -           len = strlen(v);
> > -           if (len > *leftp) {
> > -                   v[*leftp] = '\0';
> > -                   *leftp = 0;
> > -           } else
> > -                   *leftp -= len;
> > -   }
> > -   printf("%s", v);
> > -}
> > -
> > -void
> > -fmt_putc(int c, int *leftp)
> > -{
> > -
> > -   if (*leftp == 0)
> > -           return;
> > -   if (*leftp != -1)
> > -           *leftp -= 1;
> > -   putchar(c);
> > -}
> > Index: print.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ps/print.c,v
> > retrieving revision 1.62
> > diff -u -p -r1.62 print.c
> > --- print.c 19 Jul 2015 19:26:00 -0000      1.62
> > +++ print.c 17 Sep 2015 02:24:50 -0000
> > @@ -49,6 +49,7 @@
> >  #include <unistd.h>
> >  #include <limits.h>
> >  #include <pwd.h>
> > +#include <vis.h>
> >  
> >  #include "ps.h"
> >  
> > @@ -59,6 +60,49 @@ static char *cmdpart(char *);
> >  
> >  #define    min(a,b)        ((a) < (b) ? (a) : (b))
> >  
> > +static void
> > +fmt_puts(const char *s, size_t *leftp)
> > +{
> > +   static char *v = NULL;
> > +   static size_t maxlen = 0;
> > +   size_t len;
> > +
> > +   if (*leftp == 0)
> > +           return;
> > +   len = strlen(s) * 4 + 1;
> > +   if (len > maxlen) {
> > +           free(v);
> > +           maxlen = 0;
> > +           if (len < getpagesize())
> > +                   len = getpagesize();
> > +           v = malloc(len);
> > +           if (v == NULL)
> > +                   return;
> > +           maxlen = len;
> > +   }
> > +   strvis(v, s, VIS_TAB | VIS_NL | VIS_CSTYLE);
> > +   if (*leftp != -1) {
> > +           len = strlen(v);
> > +           if (len > *leftp) {
> > +                   v[*leftp] = '\0';
> > +                   *leftp = 0;
> > +           } else
> > +                   *leftp -= len;
> > +   }
> > +   printf("%s", v);
> > +}
> > +
> > +static void
> > +fmt_putc(int c, size_t *leftp)
> > +{
> > +
> > +   if (*leftp == 0)
> > +           return;
> > +   if (*leftp != -1)
> > +           *leftp -= 1;
> > +   putchar(c);
> > +}
> > +
> >  static char *
> >  cmdpart(char *arg0)
> >  {
> > @@ -94,7 +138,8 @@ void
> >  command(const struct kinfo_proc *kp, VARENT *ve)
> >  {
> >     VAR *v;
> > -   int left, wantspace = 0;
> > +   size_t left;
> > +   int wantspace = 0;
> >     char **argv, **p;
> >  
> >     v = ve->var;

Reply via email to