I like the idea, but I don't like calling them ap_off_t and offttoa, I'd
just keep ap_pos and postoa and remove the linenum functions.



On Tue, Jan 12, 2016 at 11:50:51PM -0500, Michael McConville wrote:
> I'm working on bigger simplifications for less's string formatting, but
> this is a good start. We've removed the off_t aliases for linenums and
> positions, so we now have two identical sets of off_t formatting and
> appending functions. The below diff unifies them.
> 
> As you can see, there is more cleanup to be done.
> 
> Thoughts?
> 
> 
> Index: less.h
> ===================================================================
> RCS file: /cvs/src/usr.bin/less/less.h,v
> retrieving revision 1.21
> diff -u -p -r1.21 less.h
> --- less.h    12 Jan 2016 17:48:04 -0000      1.21
> +++ less.h    13 Jan 2016 04:43:15 -0000
> @@ -205,6 +205,5 @@ struct textlist {
>  #include "funcs.h"
>  
>  /* Functions not included in funcs.h */
> -void postoa(off_t, char *, size_t);
> -void linenumtoa(off_t, char *, size_t);
> +void offttoa(off_t, char *, size_t);
>  void inttoa(int, char *, size_t);
> Index: line.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/less/line.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 line.c
> --- line.c    12 Jan 2016 17:48:04 -0000      1.16
> +++ line.c    13 Jan 2016 04:43:15 -0000
> @@ -178,7 +178,7 @@ plinenum(off_t pos)
>               char buf[INT_STRLEN_BOUND(pos) + 2];
>               int n;
>  
> -             linenumtoa(linenum, buf, sizeof (buf));
> +             offttoa(linenum, buf, sizeof(buf));
>               n = strlen(buf);
>               if (n < MIN_LINENUM_WIDTH)
>                       n = MIN_LINENUM_WIDTH;
> Index: output.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/less/output.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 output.c
> --- output.c  12 Jan 2016 17:48:04 -0000      1.14
> +++ output.c  13 Jan 2016 04:43:15 -0000
> @@ -148,8 +148,7 @@ funcname(type num, char *buf, size_t len
>       (void) strlcpy(buf, s, len);            \
>  }
>  
> -TYPE_TO_A_FUNC(postoa, off_t)
> -TYPE_TO_A_FUNC(linenumtoa, off_t)
> +TYPE_TO_A_FUNC(offttoa, off_t)
>  TYPE_TO_A_FUNC(inttoa, int)
>  
>  /*
> @@ -173,7 +172,7 @@ iprint_linenum(off_t num)
>  {
>       char buf[INT_STRLEN_BOUND(num)];
>  
> -     linenumtoa(num, buf, sizeof (buf));
> +     offttoa(num, buf, sizeof(buf));
>       putstr(buf);
>       return (strlen(buf));
>  }
> Index: prompt.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/less/prompt.c,v
> retrieving revision 1.19
> diff -u -p -r1.19 prompt.c
> --- prompt.c  12 Jan 2016 23:01:23 -0000      1.19
> +++ prompt.c  13 Jan 2016 04:43:15 -0000
> @@ -116,23 +116,11 @@ ap_char(char c)
>   * Append a off_t (as a decimal integer) to the end of the message.
>   */
>  static void
> -ap_pos(off_t pos)
> +ap_off_t(off_t pos)
>  {
>       char buf[INT_STRLEN_BOUND(pos) + 2];
>  
> -     postoa(pos, buf, sizeof buf);
> -     ap_str(buf);
> -}
> -
> -/*
> - * Append a line number to the end of the message.
> - */
> -static void
> -ap_linenum(off_t linenum)
> -{
> -     char buf[INT_STRLEN_BOUND(linenum) + 2];
> -
> -     linenumtoa(linenum, buf, sizeof buf);
> +     offttoa(pos, buf, sizeof(buf));
>       ap_str(buf);
>  }
>  
> @@ -245,7 +233,7 @@ protochar(int c, int where)
>       case 'b':       /* Current byte offset */
>               pos = curr_byte(where);
>               if (pos != -1)
> -                     ap_pos(pos);
> +                     ap_off_t(pos);
>               else
>                       ap_quest();
>               break;
> @@ -255,7 +243,7 @@ protochar(int c, int where)
>       case 'd':       /* Current page number */
>               linenum = currline(where);
>               if (linenum > 0 && sc_height > 1)
> -                     ap_linenum(PAGE_NUM(linenum));
> +                     ap_off_t(PAGE_NUM(linenum));
>               else
>                       ap_quest();
>               break;
> @@ -266,13 +254,13 @@ protochar(int c, int where)
>                       ap_quest();
>               } else if (len == 0) {
>                       /* An empty file has no pages. */
> -                     ap_linenum(0);
> +                     ap_off_t(0);
>               } else {
>                       linenum = find_linenum(len - 1);
>                       if (linenum <= 0)
>                               ap_quest();
>                       else
> -                             ap_linenum(PAGE_NUM(linenum));
> +                             ap_off_t(PAGE_NUM(linenum));
>               }
>               break;
>       case 'E':       /* Editor name */
> @@ -293,7 +281,7 @@ protochar(int c, int where)
>       case 'l':       /* Current line number */
>               linenum = currline(where);
>               if (linenum != 0)
> -                     ap_linenum(linenum);
> +                     ap_off_t(linenum);
>               else
>                       ap_quest();
>               break;
> @@ -303,7 +291,7 @@ protochar(int c, int where)
>                   (linenum = find_linenum(len)) <= 0)
>                       ap_quest();
>               else
> -                     ap_linenum(linenum-1);
> +                     ap_off_t(linenum-1);
>               break;
>       case 'm':       /* Number of files */
>               n = ntags();
> @@ -333,7 +321,7 @@ protochar(int c, int where)
>       case 'B':
>               len = ch_length();
>               if (len != -1)
> -                     ap_pos(len);
> +                     ap_off_t(len);
>               else
>                       ap_quest();
>               break;
> 

Reply via email to