⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filetype.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
		lcnt++;						/* LEVEL */		if(*p == '>') {			ep->e_level = 1;			p++;		}			/* OFFSET */		p2 = strchr(p, '\t');		if(p2 == NULL) {			if(cflg)				fprintf(stderr, "file: magic format error, no tab after %son line %d\n", p, lcnt);			continue;		}		*p2++ = NULL;		ep->e_off = atolo(p);		while(*p2 == '\t')			p2++;			/* TYPE */		p = p2;		p2 = strchr(p, '\t');		if(p2 == NULL) {			if(cflg)				fprintf(stderr, "file: magic format error, no tab after %son line %d\n", p, lcnt);			continue;		}		*p2++ = NULL;		if(*p == 's') {			if(*(p+1) == 'h')				ep->e_type = SHORT;			else				ep->e_type = STR;		} else if (*p == 'l')			ep->e_type = LONG;		while(*p2 == '\t')			*p2++;			/* OP-VALUE */		p = p2;		p2 = strchr(p, '\t');		if(p2 == NULL) {			if(cflg)				fprintf(stderr, "file: magic format error, no tab after %son line %d\n", p, lcnt);			continue;		}		*p2++ = NULL;		if(ep->e_type != STR) {			opc = *p++;			switch(opc) {			case '=':				ep->e_opcode = EQ;				break;			case '>':				ep->e_opcode = GT;				break;			case '<':				ep->e_opcode = LT;				break;			case 'x':				ep->e_opcode = ANY;				break;			default:				p--;			}		}		if(ep->e_opcode != ANY) {			if(ep->e_type != STR)				ep->e_value.num = atolo(p);			else {				ep->e_value.str = (char *)malloc(strlen(p) + 1);				p3 = ep->e_value.str;				while (*p != '\0') 				    if (*p == '\\')					switch (*++p) {					case 'n':						*p3++ = '\n';						p++;						break;					case 't':						*p3++ = '\t';						p++;						break;					case 'b':						*p3++ = '\b';						p++;						break;					case 'r':						*p3++ = '\r';						p++;						break;					case 'f':						*p3++ = '\f';						p++;						break;					case '0':					case '1':					case '2':					case '3':					case '4':					case '5':					case '6':					case '7':					case '8':					case '9':						{						int value = 0,						    base = 10;						while (*p >= '0' && *p <= '9') {							if (*p == '0' && value == 0) base = 8;							value = value*base + (*p++ - '0');							}						*p3++ = (unsigned char)value;						break;						}					default:						*p3++ = *p++;				}			   else				*p3++ = *p++;			*p3 = '\0';			p3 = (char *)fre_comp(ep->e_value.str);			if (p3 == 0) fprintf(stderr, "file: bad reg exp in magic file: %s\n", ep->e_value.str);			else {				free(ep->e_value.str);				ep->e_value.str = p3;			}			}		}		while(*p2 == '\t')			*p2++;			/* MAJOR/MINOR TYPE NUMBERS */		if (sscanf(p2, "%d,%d", &majnum, &minnum) < 2)			fprintf(stderr, "file: invalid major,minor numbers in magic file.\n");		ep->e_retcode = MASH(majnum, minnum);		p2 = strchr(p2, '\t');		while(*p2 == '\t')			*p2++;			/* STRING */		ep->e_str = (char *)malloc(strlen(p2) + 1);		p = ep->e_str;		while(*p2 != '\n') {			if(*p2 == '%')				ep->e_opcode |= SUB;			*p++ = *p2++;		}		*p = NULL;		ep++;		if(ep >= mend) {			fprintf(stderr, "file: magic table overflow.\n");			exit(2);		}	}	ep->e_off = -2L*(long)maxexecfn;}printmtab(){reg Entry *ep;	printf("level   offset  type    opcode  major,minor	value   string\n");	for(ep = mtab; ep->e_off > -2L*(long)maxexecfn; ep++) {		printf("%d\t%d\t%d\t%d\t%d,%d\t",			ep->e_level, ep->e_off, ep->e_type, ep->e_opcode, 			(short)(ep->e_retcode>>16),			(short)(ep->e_retcode & 0177777));		if (ep->e_type == STR) {			printstr(ep->e_value.str, 50);			printf("\t");			}		else			printf("%#lo\t", ep->e_value.num);		printf("%s", ep->e_str);		if (ep->e_opcode & SUB)			printf("\tsubst");		printf("\n");	}}printstr(p, n)unsigned char *p;int n;{	register unsigned char *sp;	register int c;	for (sp = p, c = 0; *sp != '\0' && c++ < n; sp++)		if (isprint(*sp)) printf("%c", *sp);		else if (*sp == '\n') printf("\\n");		else if (*sp == '\r') printf("\\r");		else if (*sp == '\t') printf("\\t");		else if (*sp == '\b') printf("\\b");		else if (*sp == '\b') printf("\\f");		else printf("\\%#o", *sp);}longatolo(s)reg	char	*s;{	reg	char	c;	reg	char	*fmt = "%ld";	auto	long	j = 0L;	if(*s == '0') {		s++;		if(*s == 'x') {			s++;			fmt = "%lx";		} else			fmt = "%lo";	}	sscanf(s, fmt, &j);	return(j);}int ci;cprog(){	int j, nl;	char ch;	ci = 0;	if (lookup(cstart) == 1)		return(1);	if(ccom() == 0) return(0);	while(buf[ci] == '#'){		j = ci;		while(buf[ci++] != '\n'){			if(ci - j > 255)				return(0);			if(ci >= in) return(0);		}		if(ccom() == 0) return(0);	}check:	if(lookup(c) == 1){		if (buf[0] == '%' && buf[1] == '!') return(0);	/* actually postscript */		while((ch = buf[ci++]) != ';' && ch != '{')if(ci >= in) return(0);		return(1);	}	nl = 0;	while(buf[ci] != '('){		if(buf[ci] <= 0)			return(0);		if(buf[ci] == ';'){			ci++; 			goto check; 		}		if(buf[ci++] == '\n')			if(nl++ > 6) return(0);		if(ci >= in) return(0);	}	while(buf[ci] != ')'){		if(buf[ci++] == '\n')			if(nl++ > 6) return(0);		if(ci >= in) return(0);	}	while(buf[ci] != '{'){		if(buf[ci++] == '\n')			if(nl++ > 6) return(0);		if(ci >= in) return(0);	}	if (buf[0] == '%' && buf[1] == '!') return(0);	/* actually postscript */	return(1);}ccom(){	char cc;	while((cc = buf[ci]) == ' ' || cc == '\t' || cc == '\n')if(ci++ >= in)return(0);	if(buf[ci] == '/' && buf[ci+1] == '*'){		ci += 2;		while(buf[ci] != '*' || buf[ci+1] != '/'){			if(buf[ci] == '\\')ci += 2;			else ci++;			if(ci >= in)return(0);		}		if((ci += 2) >= in)return(0);	}	if(buf[ci] == '\n')if(ccom() == 0)return(0);	return(1);}intfortprog(){	int i = 0;	while(buf[i] == 'c' || buf[i] == '#'){		while(buf[i++] != '\n')if(i >= in) return(0);	}	if(lookup(fort) == 1)		return(1);	return(0);}ascom(){	while(buf[i] == '/'){		i++;		while(buf[i++] != '\n')if(i >= in)return(0);		while(buf[i] == '\n')if(i++ >= in)return(0);	}	return(1);}sccs() {	reg int i;	if(buf[0] == 1 && buf[1] == 'h')		for(i=2; i<=6; i++)			if(isdigit(buf[i])) continue;			else return(0);	else		return(0);	return(1);}troffint(bp, n)char *bp;int n;{	int k;	i = 0;	for (k = 0; k < 6; k++) {		if (lookup(troff) == 0)			return(0);		if (lookup(troff) == 0)			return(0);		while (i < n && buf[i] != '\n')			i++;		if (i++ >= n)			return(0);	}	return(1);}lookup(tab)char *tab[];{	char r;	int k,j,l;	while(buf[i] == ' ' || buf[i] == '\t' || buf[i] == '\n')i++;	for(j=0; tab[j] != 0; j++){		l=0;		for(k=i; ((r=tab[j][l++]) == buf[k] && r != '\0');k++);		if(r == '\0')			if(buf[k] == ' ' || buf[k] == '\n' || buf[k] == '\t'			    || buf[k] == '{' || buf[k] == '/' || buf[k] == '>'){				i=k;				return(1);			}	}	return(0);}english (bp, n)char *bp;{# define NASC 128	int ct[NASC], j, vow, freq, rare;	int badpun = 0, punct = 0;	if (n<50) return(0); /* no point in statistics on squibs */	for(j=0; j<NASC; j++)		ct[j]=0;	for(j=0; j<n; j++)	{		if (bp[j]<NASC)			ct[bp[j]|040]++;		switch (bp[j])		{		case '.': 		case ',': 		case ')': 		case '%':		case ';': 		case ':': 		case '?':			punct++;			if ( j < n-1 &&			    bp[j+1] != ' ' &&			    bp[j+1] != '\n')				badpun++;		}	}	if (badpun*5 > punct)		return(0);	vow = ct['a'] + ct['e'] + ct['i'] + ct['o'] + ct['u'];	freq = ct['e'] + ct['t'] + ct['a'] + ct['i'] + ct['o'] + ct['n'];	rare = ct['v'] + ct['j'] + ct['k'] + ct['q'] + ct['x'] + ct['z'];	if (2*ct[';'] > ct['e']) return(0);	if ( (ct['>']+ct['<']+ct['/'])>ct['e']) return(0); /* shell file test */	return (vow*5 >= n-ct[' '] && freq >= 10*rare);}shell(bp, n, tab)	char *bp;	int n;	char *tab[];{	i = 0;	do {		if (buf[i] == '#' || buf[i] == ':')			while (i < n && buf[i] != '\n')				i++;		if (++i >= n)			break;		if (lookup(tab) == 1)			return (1);	} while (i < n);	return (0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -