youtube/gopher: print views with thousand separator - frontends - front-ends for some sites (experiment)
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 7385c0b104dea41686519ed734825da88ca2fb32
 (DIR) parent 4dcebc72f5a00e9b94a8e2338fb0127662933fa3
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Tue,  7 Mar 2023 19:26:17 +0100
       
       youtube/gopher: print views with thousand separator
       
       Diffstat:
         M youtube/gopher.c                    |      31 +++++++++++++++++++++++++++++--
       
       1 file changed, 29 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/youtube/gopher.c b/youtube/gopher.c
       @@ -42,6 +42,32 @@ info(const char *s)
                line('i', s, "");
        }
        
       +/* print views with thousand separators */
       +static void
       +printviews(const char *s)
       +{
       +        const char *p;
       +        int ndigits = 0;
       +
       +        /* first count all digits */
       +        for (p = s; *p; p++)
       +                if (*p >= '0' && *p <= '9')
       +                        ndigits++;
       +
       +        for (p = s; *p; p++) {
       +                if (!(*p >= '0' && *p <= '9'))
       +                        continue;
       +
       +                putchar(*p);
       +                ndigits--;
       +
       +                /* show separator on every 3 digits and when there are
       +                   digits remaining */
       +                if ((ndigits % 3) == 0 && ndigits > 0)
       +                        putchar(',');
       +        }
       +}
       +
        void
        header(void)
        {
       @@ -144,7 +170,7 @@ render_search(struct search_response *r)
                        }
                        if (v->viewcount[0]) {
                                OUT("iViews:         ");
       -                        OUTTEXT(v->viewcount);
       +                        printviews(v->viewcount);
                                printf("\t%s\t%s\t%s\r\n", "", host, port);
                        }
                }
       @@ -198,7 +224,8 @@ render_video(struct video_response *r)
                }
        
                OUT("iViews:     ");
       -        printf("%ld", r->viewcount);
       +        snprintf(buf, sizeof(buf), "%ld", r->viewcount);
       +        printviews(buf);
                printf("\t%s\t%s\t%s\r\n", "", host, port);
        
                if (r->publishdate[0]) {