val.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 713 行 · 第 1/2 页
C
713 行
read_to(ch,pkt)register char ch;register struct packet *pkt;{ register char *n; while ((n = get_line(pkt)) && !(*n++ == CTLCHAR && *n == ch)) ; return;}/* This function places into a specified destination characters which * are delimited by either a space, tab or 0. It obtains the char- * acters from a line of characters.*/char *getval(sourcep,destp)register char *sourcep;register char *destp;{ while (*sourcep != ' ' && *sourcep != '\t' && *sourcep != '\0') *destp++ = *sourcep++; *destp = 0; return(sourcep);}/* This function will report the error that occured on the command * line. It will print one diagnostic message for each error that * was found in the named file.*/report(code,inp_line,file)register int code;register char *inp_line;register char *file;{ char percent; percent = '%'; /* '%' for -m and/or -y messages */ if (*inp_line) printf("%s\n\n",inp_line); if (code & NAME_ERR) printf(" %s: %cM%c, -m mismatch\n",file,percent,percent); if (code & TYPE_ERR) printf(" %s: %cY%c, -y mismatch\n",file,percent,percent); if (code & NONEXSID_ERR) printf(" %s: SID nonexistent\n",file); if (code & INVALSID_ERR) printf(" %s: SID invalid or ambiguous\n",file); if (code & FILENAM_ERR) printf(" %s: can't open file or file not SCCS\n",file); if (code & CORRUPT_ERR) printf(" %s: corrupted SCCS file\n",file); if (code & UNKDUP_ERR) printf(" %s: Unknown or dupilcate keyletter argument\n",file); if (code & FILARG_ERR) printf(" %s: missing file argument\n",file); return;}/* This function takes as it's argument the SID inputed and determines * whether or not it is valid (e. g. not ambiguous or illegal).*/invalid(i_sid)register char *i_sid;{ register int count; register int digits; count = digits = 0; if (*i_sid == '0' || *i_sid == '.') return (1); i_sid++; digits++; while (*i_sid != '\0') { if (*i_sid++ == '.') { digits = 0; count++; if (*i_sid == '0' || *i_sid == '.') return (1); } digits++; if (digits > 5) return (1); } if (*(--i_sid) == '.' ) return (1); if (count == 1 || count == 3) return (0); return (1);}/* Routine to read a line into the packet. The main reason for it is to make sure that pkt->p_wrttn gets turned off, and to increment pkt->p_slnno.*/char *get_line(pkt)register struct packet *pkt;{ register char *n; register char *p; if ((n = fgets(pkt->p_line,sizeof(pkt->p_line),pkt->p_iop)) != NULL) { pkt->p_slnno++; for (p = pkt->p_line; *p; ) pkt->p_chash += *p++; } else { if (!pkt->p_chkeof) infile_err |= CORRUPT_ERR; if (pkt->do_chksum && (pkt->p_chash ^ pkt->p_ihash)&0xFFFF) infile_err |= CORRUPT_ERR; } return(n);}/* Does initialization for sccs files and packet.*/sinit(pkt,file)register struct packet *pkt;register char *file;{ zero(pkt,sizeof(*pkt)); copy(file,pkt->p_file); pkt->p_wrttn = 1; pkt->do_chksum = 1; /* turn on checksum check for getline */}read_mod(pkt)register struct packet *pkt;{ register char *p; int ser; int iord; register struct apply *ap; while (get_line(pkt) != NULL) { p = pkt->p_line; if (*p++ != CTLCHAR) continue; else { if (!((iord = *p++) == INS || iord == DEL || iord == END)) { infile_err |= CORRUPT_ERR; return(0); } NONBLANK(p); satoi(p,&ser); if (iord == END) remq(pkt,ser); else /* The following code is commented out because it was full of null pointers. It should be fixed for all hardware platforms. Meanwhile it works fine with the code added below... if ((ap = &pkt->p_apply[ser])->a_code == APPLY) addq(pkt,ser,iord == INS ? YES : NO,iord, ap->a_reason & USER); else addq(pkt,ser,iord == INS ? NO : NULL,iord, ap->a_reason & USER); ... end of removed code, next line replaces it */ addq(pkt,ser,iord == INS ? NO:NULL,iord,USER); } } if (pkt->p_q) infile_err |= CORRUPT_ERR; return(0);}addq(pkt,ser,keep,iord,user)struct packet *pkt;int ser;int keep;int iord;{ register struct queue *cur, *prev, *q; /* added init of queue and added check for null pointer of cur */ if (!pkt->p_q) { pkt->p_q = q = (struct queue *) fmalloc(sizeof(*q)); cur = NULL; } else { for (cur = (struct queue *) (&pkt->p_q); cur =(prev=cur)->q_next;) if (cur->q_sernum <= ser) break; if (cur && cur->q_sernum == ser) infile_err |= CORRUPT_ERR; prev->q_next = q = (struct queue *) fmalloc(sizeof(*q)); } q->q_next = cur; q->q_sernum = ser; q->q_keep = keep; q->q_iord = iord; q->q_user = user; if (pkt->p_ixuser && (q->q_ixmsg = chkix(q,(struct queue *) (&pkt->p_q)))) ++(pkt->p_ixmsg); else q->q_ixmsg = 0; setkeep(pkt);}remq(pkt,ser)register struct packet *pkt;int ser;{ register struct queue *cur, *prev; for (cur = (struct queue *) (&pkt->p_q); cur = (prev = cur)->q_next; ) if (cur->q_sernum == ser) break; if (cur) { if (cur->q_ixmsg) --(pkt->p_ixmsg); prev->q_next = cur->q_next; ffree((char *) cur); setkeep(pkt); } else infile_err |= CORRUPT_ERR;}setkeep(pkt)register struct packet *pkt;{ register struct queue *q; register struct sid *sp; for (q = (struct queue *) (&pkt->p_q); q = q->q_next; ) if (q->q_keep != NULL) { if ((pkt->p_keep = q->q_keep) == YES) { sp = &pkt->p_idel[q->q_sernum].i_sid; pkt->p_inssid.s_rel = sp->s_rel; pkt->p_inssid.s_lev = sp->s_lev; pkt->p_inssid.s_br = sp->s_br; pkt->p_inssid.s_seq = sp->s_seq; } return; } pkt->p_keep = NO;}# define apply(qp) ((qp->q_iord == INS && qp->q_keep == YES) || \ (qp->q_iord == DEL && qp->q_keep == (NO & 0377)))chkix(new,head)register struct queue *new;struct queue *head;{ register int retval; register struct queue *cur; int firstins, lastdel; if (!apply(new)) return(0); for (cur = head; cur = cur->q_next; ) if (cur->q_user) break; if (!cur) return(0); retval = 0; firstins = 0; lastdel = 0; for (cur = head; cur = cur->q_next; ) { if (apply(cur)) { if (cur->q_iord == DEL) lastdel = cur->q_sernum; else if (firstins == 0) firstins = cur->q_sernum; } else if (cur->q_iord == INS) retval++; } if (retval == 0) { if (lastdel && (new->q_sernum > lastdel)) retval++; if (firstins && (new->q_sernum < firstins)) retval++; } return(retval);}/* This function reads the delta table entries and checks for the format * as specifed in sccsfile(V). If the format is incorrect, a corrupt * error will be issued by 'val'. This function also checks * if the sid requested is in the file (depending if '-r' was specified).*/do_delt(pkt,goods,d_sid)register struct packet *pkt;register int goods;register char *d_sid;{ char *l; while(getstats(pkt)) { if ((l = get_line(pkt)) && *l++ != CTLCHAR || *l++ != BDELTAB) return(1); if (HADR && !(infile_err & INVALSID_ERR)) { getdel(&del,l); if (equal(d_sid,del.osid) && del.type == 'D') goods++; } while ((l = get_line(pkt)) != NULL) if (pkt->p_line[0] != CTLCHAR) break; else { switch(pkt->p_line[1]) { case EDELTAB: break; case COMMENTS: case MRNUM: case INCLUDE: case EXCLUDE: case IGNORE: continue; default: return(1); } break; } if (l == NULL || pkt->p_line[0] != CTLCHAR) return(1); } if (pkt->p_line[1] != BUSERNAM) return(1); if (HADR && !goods && !(infile_err & INVALSID_ERR)) infile_err |= NONEXSID_ERR; return(0);}/* This function reads the stats line from the sccsfile */getstats(pkt)register struct packet *pkt;{ register char *p; p = pkt->p_line; if (get_line(pkt) == NULL || *p++ != CTLCHAR || *p != STATS) return(0); return(1);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?