Plan 9 from Bell Labs’s /usr/web/sources/contrib/sl/src/json2utf.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <bio.h>

Biobuf	bin;
Biobuf	bout;

void
main(void)
{
	int c, i, o, oo;
	char s[7];

	Binit(&bin, 0, OREAD);
	Binit(&bout, 1, OWRITE);
	Blethal(&bin, 0);
	Blethal(&bout, 0);
	o = oo = 0;
	while((c = Bgetc(&bin)) != -1){
		if(oo == '\\' && o == 'u'){
			snprint(s, sizeof(s), "0x%c", c);
			for(i=3; i<6; i++)
				s[i] = Bgetc(&bin);
			Bprint(&bout, "%C", atoi(s));
		}else if(o != '\\' && c != '\\')
			Bputc(&bout, c);
		oo = o;
		o = c;
	}

	exits(0);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].