Re: [dev] I wrote a pager - errno

2016-09-16 Thread Greg Reagle
On Fri, Sep 16, 2016, at 12:26 PM, u...@netbeisser.de wrote:
> > #include 
> > #include 
> > 
> > int main()
> > {
> > const int page_size = 22;
> > int count = 0;
> > int ch;
> > FILE *tty;
> > 
> > if ((tty = fopen("/dev/tty", "a+")) == NULL)
> > return(errno);
> > 
> > ch = getchar();
> > while (ch != EOF) {
> > putchar(ch);
> > if (ch == '\n') {
> > ++count;
> > if (count >= page_size) {
> > fgetc(tty);
> > count = 0;
> > }
> > }
> > ch = getchar();
> > }
> > fclose(tty);
> > }
> 
> hm, do you really need errno ? 

Well, I don't know.  Like I wrote, I am not an expert C programmer.  I
could just return a value of 1, but the user might be interested to know
what the error was.



Re: [dev] I wrote a pager - errno

2016-09-16 Thread u
On Fri, Sep 16, 2016 at 11:43:37AM -0400, Greg Reagle wrote:
> On Fri, Sep 16, 2016, at 10:01 AM, Greg Reagle wrote:
> > Greetings.  I am running stali in qemu and and it seems to lack a pager.
> >  Is it a goal of the suckless project to write a suckless pager for
> > sbase?  I see that plan9port already has a pager called "p".  What about
> > importing that into 9base?
> 
> Since I know that code is king around here, I wrote a pager program.  I
> am not an expert C programmer, so I might have done some things wrong. 
> But I think it does a good job of being minimalist.
> 
> What do you think?  Would you like to put it into sbase or stali? If yes
> then I can clone the sbase repo and submit a proper git patch.
> 
> #include 
> #include 
> 
> int main()
> {
>   const int page_size = 22;
>   int count = 0;
>   int ch;
>   FILE *tty;
> 
>   if ((tty = fopen("/dev/tty", "a+")) == NULL)
>   return(errno);
> 
>   ch = getchar();
>   while (ch != EOF) {
>   putchar(ch);
>   if (ch == '\n') {
>   ++count;
>   if (count >= page_size) {
>   fgetc(tty);
>   count = 0;
>   }
>   }
>   ch = getchar();
>   }
>   fclose(tty);
> }

hm, do you really need errno ?