File: wunzip.c

package info (click to toggle)
hspell 1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,556 kB
  • sloc: ansic: 2,808; perl: 1,989; makefile: 209; sh: 109; awk: 15
file content (40 lines) | stat: -rw-r--r-- 797 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char **argv)
{
	char sbuf[256];
	int slen=0;
	int c,n;
	while((c=getchar())!=EOF){
		if(c>='0' && c<='9'){
			/* new word - output old word first */
			sbuf[slen]='\0';
			puts(sbuf);
			/* and read how much to go back */
			n=0;
			do {
				/* base 10... */
				n*=10;
				n+=(c-'0');
			} while ((c=getchar())!=EOF && c>='0' && c<='9');
			slen-=n;
			if(slen<0 || slen >= sizeof(sbuf)-1){
				fprintf(stderr,"bad backlength %d... exiting.\n", slen);
				exit(1);
			}
			/* we got a new letter c - continue the loop */
		}
		/* word letter - add it */
		if(slen>=sizeof(sbuf)-1){
			fprintf(stderr,"word too long... exiting.\n");
			exit(1);
		}
		sbuf[slen++]=c;
	}
	/* output last word */
	sbuf[slen]='\0';
	puts(sbuf);
	return 0;
}