From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Wed, 2 Feb 2005 09:37:14 +0900 From: arisawa@ar.aichi-u.ac.jp To: 9fans@cse.psu.edu MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: [9fans] Brdline Topicbox-Message-UUID: 3becfbe6-eace-11e9-9e20-41e7f4b1d025 Hello, The following program falls into endless loop if we execute echo -n alice | 8.out Try. #include #include #include void main() { Biobuf in; char *p; int lines; Binit(&in, 0, OREAD); lines = 0; for(;;){ p = Brdline(&in, '\n'); if(p == nil){ if(Blinelen(&in) == 0) break; }else lines++; } print("lines=%d\n",lines); } I have been desired to have such a Brdline that can work even if we execute: echo -n alice | 8.out Current Brdline requires delim as second argument, and the worse the delim is left untouched *mostly* at Blinelen -1 We must replace it using Blinelen by '\0' if we want the returned value to be used as string. This makes program difficult if input data doesn't have delim. My imagination of new Brdline (or some other name) is: void main() { Biobuf in; char *p; Binit(&in,0,OREAD); while((p = Brdline(&in))) print("%s", p); } '\n' is automatically replaced by '\0', and '\0' is automatically appended at EOF. p is nil only at EOF. some function will be required to detect buffer full. if buffer full the next Brdline should return the pointer of the character that is replaced by '\0' after fixing the value. Kenji Arisawa