admin.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 1,184 行 · 第 1/2 页
C
1,184 行
} time(&dt.d_datetime); /* get time and date */ copy(logname(),dt.d_pgmr); /* get user's name */ dt.d_serial = 1; dt.d_pred = 0; del_ba(&dt,line); /* form and write */ putline(&gpkt,line); /* delta-table entry */ /* If -m flag, enter MR numbers */ if (Mrs) { if (had_flag[CMFFLAG - 'a']) { /* CMF check routine */ if (cmrcheck (Mrs, CMFAPPL) != 0) { /* check them */ fatal ("Bad CMR number(s)."); } } mrfixup(); if (z && valmrs(&gpkt,z)) fatal("invalid MRs (de9)"); putmrs(&gpkt); } /* Enter comment line for `chghist' */ if (HADY) { sprintf(line,"%c%c ",CTLCHAR,COMMENTS); putline(&gpkt,line); sprintf(line,"%s",savecmt(Comments)); putline(&gpkt,line); putline(&gpkt,"\n"); } else { /* insert date/time and pgmr into comment line */ cmt_ba(&dt,line); putline(&gpkt,line); } /* End of delta-table. */ sprintf(line,CTLSTR,CTLCHAR,EDELTAB); putline(&gpkt,line); /* Beginning of user-name section. */ sprintf(line,CTLSTR,CTLCHAR,BUSERNAM); putline(&gpkt,line); } else /* For old file, copy to x-file until user-name section is found. */ flushto(&gpkt,BUSERNAM,COPY); /* Write user-names to be added to list of those allowed to make deltas. */ if (HADA) for (k = 0; k < asub; k++) { sprintf(line,"%s\n",anames[k]); putline(&gpkt,line); } /* Do not copy those user-names which are to be erased. */ if (HADE && !HADN) while ((cp = getline(&gpkt)) && !(*cp++ == CTLCHAR && *cp == EUSERNAM)) { for (k = 0; k < esub; k++) { cp = gpkt.p_line; while (*cp) /* find and */ cp++; /* zero newline */ *--cp = '\0'; /* character */ if (equal(enames[k],gpkt.p_line)) { /* Tell getline not to output previously read line. */ gpkt.p_wrttn = 1; break; } else *cp = '\n'; /* restore newline */ } } if (HADN) { /* N E W F I L E */ /* End of user-name section. */ sprintf(line,CTLSTR,CTLCHAR,EUSERNAM); putline(&gpkt,line); } else /* For old file, copy to x-file until end of user-names section is found. */ if (!HADE) flushto(&gpkt,EUSERNAM,COPY); /* For old file, read flags and their values (if any), and store them. Check to see if the flag read is one that should be deleted. */ if (!HADN) while ((cp = getline(&gpkt)) && (*cp++ == CTLCHAR && *cp == FLAG)) { gpkt.p_wrttn = 1; /* don't write previous line */ cp += 2; /* point to flag character */ k = *cp - 'a'; f = *cp; if (f == LOCKFLAG) { p_lval = cp; ++p_lval; tval = fmalloc(size(gpkt.p_line)-5); copy(++p_lval,tval); lval = tval; while(*tval) ++tval; *--tval = '\0'; } if (f == LOCKGET) { p_lval = cp; ++p_lval; tval = fmalloc(size(gpkt.p_line)-5); copy(++p_lval,tval); lval = tval; while(*tval) ++tval; *--tval = '\0'; } if (!had_flag[k] && !rm_flag[k]) { had_flag[k] = 2; /* indicate flag is */ /* from file, not */ /* from arg list */ if (*++cp != '\n') { /* get flag value */ q = fmalloc(size(gpkt.p_line)-5); copy(++cp,q); flag_p[k] = q; while (*q) /* find and */ q++; /* zero newline */ *--q = '\0'; /* character */ } } if (rm_flag[k]) { if (f == LOCKFLAG || f == LOCKGET) { if (unlock) { in_f = lval; if ((lval = adjust(in_f)) && !had_flag[k]) ck_it = had_flag[k] = 1; } else had_flag[k] = 0; } else had_flag[k] = 0; } } /* Write out flags. */ /* test to see if the CMFFLAG is safe */ if (had_flag[CMFFLAG - 'a']) { if (had_flag[VALFLAG - 'a'] && !rm_flag[VALFLAG - 'a']) fatal ("Can't use -fz with -fv."); } for (k = 0; k < NFLAGS; k++) if (had_flag[k]) { if (flag_p[k] || lval) { if (('a' + k) == LOCKFLAG && had_flag[k] == 1) { if (flag_p[k] == "a" || lval == "a") locks = "a"; else if (lval && flag_p[k]) locks = cat(nline,lval," ",flag_p[k],0); else if (lval) locks = lval; else locks = flag_p[k]; sprintf(line,"%c%c %c %s\n", CTLCHAR,FLAG,'a' + k,locks); locks = 0; if (lval) { ffree(lval); tval = lval = 0; } if (ck_it) had_flag[k] = ck_it = 0; } else sprintf(line,"%c%c %c %s\n", CTLCHAR,FLAG,'a'+k,flag_p[k]); if (('a' + k) == LOCKGET && had_flag[k] == 1) { if (flag_p[k] == "a" || lval == "a") locks = "a"; else if (lval && flag_p[k]) locks = cat(nline,lval," ",flag_p[k],0); else if (lval) locks = lval; else locks = flag_p[k]; sprintf(line,"%c%c %c %s\n", CTLCHAR,FLAG,'a' + k,locks); locks = 0; if (lval) { ffree(lval); tval = lval = 0; } if (ck_it) had_flag[k] = ck_it = 0; } else sprintf(line,"%c%c %c %s\n", CTLCHAR,FLAG,'a'+k,flag_p[k]); } else sprintf(line,"%c%c %c\n", CTLCHAR,FLAG,'a'+k); /* flush imbeded newlines from flag value */ i = 4; if (line[i] == ' ') for (i++; line[i+1]; i++) if (line[i] == '\n') line[i] = ' '; putline(&gpkt,line); if (had_flag[k] == 2) { /* flag was taken from file */ had_flag[k] = 0; if (flag_p[k]) { ffree(flag_p[k]); flag_p[k] = 0; } } } if (HADN) { /* Beginning of descriptive (user) text. */ sprintf(line,CTLSTR,CTLCHAR,BUSERTXT); putline(&gpkt,line); } else /* Write out BUSERTXT record which was read in above loop that processes flags. */ gpkt.p_wrttn = 0; putline(&gpkt,(char *) 0); /* Get user description, copy to x-file. */ if (HADT) { if (*tfile) { iptr = xfopen(tfile,0); fgetchk(line, sizeof line,iptr,tfile,&gpkt); fclose(iptr); } /* If old file, ignore any previously supplied commentary. (i.e., don't copy it to x-file.) */ if (!HADN) flushto(&gpkt,EUSERTXT,NOCOPY); } if (HADN) { /* N E W F I L E */ /* End of user description. */ sprintf(line,CTLSTR,CTLCHAR,EUSERTXT); putline(&gpkt,line); /* Beginning of body (text) of first delta. */ sprintf(line,"%c%c %u\n",CTLCHAR,INS,1); putline(&gpkt,line); if (HADI) { /* get body */ /* Set indicator to check lines of body of file for keyword definitions. If no keywords are found, a warning will be produced. */ check_id = 1; /* Set indicator that tells whether there were any keywords to 'no'. */ Did_id = 0; if (*ifile) iptr = xfopen(ifile,0); /* from a file */ else iptr = stdin; /* from standard input */ /* Read and copy to x-file, while checking first character of each line to see that it is not the control character (octal 1). Also, count lines read, and set statistics' structure appropriately. The 'fgetchk' routine will check for keywords. */ stats.s_ins = fgetchk(line, sizeof line,iptr,ifile,&gpkt); stats.s_del = stats.s_unc = 0; /* If no keywords were found, issue warning. */ if (!Did_id) { if (had_flag[IDFLAG - 'a']) fatal("no id keywords (cm6)"); else fprintf(stderr,"%s\n","No id keywords (cm7)"); } check_id = 0; Did_id = 0; } /* End of body of first delta. */ sprintf(line,"%c%c %u\n",CTLCHAR,END,1); putline(&gpkt,line); } else { /* Indicate that EOF at this point is ok, and flush rest of (old) s-file to x-file. */ gpkt.p_chkeof = 1; while (getline(&gpkt)) ; } /* Flush the buffer, take care of rewinding to insert checksum and statistics in file, and close. */ flushline(&gpkt,&stats); /* Change x-file name to s-file, and delete old file. Unlock file before returning. */ if (!HADH) { if (!HADN) stat(gpkt.p_file,&sbuf); xrename(auxf(gpkt.p_file,'x'),&gpkt); if (!HADN) chown(gpkt.p_file,sbuf.st_uid,sbuf.st_gid); xrm(&gpkt); unlockit(auxf(afile,'z'),getpid()); }}fgetchk(strp,len,inptr,file,pkt)register char *strp;register int len;FILE *inptr;register char *file;register struct packet *pkt;{ register int k; int i; for (k = 1; fgets(strp,len,inptr); k++) { if (*strp == CTLCHAR) { sprintf(Error,"%s illegal data on line %d (ad21)", file,k); fatal(Error); } i = strlen(strp); if(i == (len-1) && strp[i-1] != '\n') { sprintf(Error, "%s line %d is longer than %d characters", /* (ad??) */ file, k, LINEWIDTH); fatal(Error); } if(strp[i-1] != '\n') { sprintf(Error, "%s line %d does not end with a newline", /* (ad??) */ file, k); fatal(Error); } if (check_id) chkid(strp); putline(pkt,strp); } return(k - 1);}clean_up(){ xrm(&gpkt); if (Xiop) fclose(Xiop); unlink(auxf(gpkt.p_file,'x')); if (HADN) unlink(gpkt.p_file); if (!HADH) unlockit(Zhold,getpid());}cmt_ba(dt,str)register struct deltab *dt;char *str;{ register char *p; char *date_ba(); p = str; *p++ = CTLCHAR; *p++ = COMMENTS; *p++ = ' '; copy("date and time created",p); while (*p++) ; --p; *p++ = ' '; date_ba(&dt->d_datetime,p); while (*p++) ; --p; *p++ = ' '; copy("by",p); while (*p++) ; --p; *p++ = ' '; copy(dt->d_pgmr,p); while (*p++) ; --p; *p++ = '\n'; *p = 0;}putmrs(pkt)struct packet *pkt;{ register char **argv; char str[64]; extern char **Varg; for (argv = &Varg[PWVSTART]; *argv; argv++) { sprintf(str,"%c%c %s\n",CTLCHAR,MRNUM,*argv); putline(pkt,str); }}char *adjust(line)char *line;{ register int k; register int i; char *t_unlock; char t_line[LINEWIDTH+1]; char rel[5]; t_unlock = unlock; while(*t_unlock) { NONBLANK(t_unlock); t_unlock = getval(t_unlock,rel); while ((k = pos_ser(line,rel)) != -1) { for(i = k; i < (size(rel) + k); i++) { line[i] = '+'; if (line[i++] == ' ') line[i] = '+'; else if (line[i] == '\0') break; else --i; } k = 0; for(i = 0; i < length(line); i++) if (line[i] == '+') continue; else if (k == 0 && line[i] == ' ') continue; else t_line[k++] = line[i]; if (t_line[strlen(t_line) - 1] == ' ') t_line[strlen(t_line) - 1] = '\0'; t_line[k] = '\0'; line = t_line; } } if (length(line)) return(line); else return(0);}char *getval(sourcep,destp)register char *sourcep;register char *destp;{ while (*sourcep != ' ' && *sourcep != '\t' && *sourcep != '\0') *destp++ = *sourcep++; *destp = 0; return(sourcep);}val_list(list)register char *list;{ register int i; if (list[0] == 'a') return(1); else for(i = 0; list[i] != '\0'; i++) if (list[i] == ' ' || numeric(list[i])) continue; else if (list[i] == 'a') { list[0] = 'a'; list[1] = '\0'; return(1); } else return(0); return(1);}pos_ser(s1,s2)char *s1;char *s2;{ register int offset; register char *p; char num[5]; p = s1; offset = 0; while(*p) { NONBLANK(p); p = getval(p,num); if (equal(num,s2)) { return(offset);} offset = offset + size(num); } return(-1);}range(line)register char *line;{ register char *p; char rel[BUFSIZ]; p = line; while(*p) { NONBLANK(p); p = getval(p,rel); if (size(rel) > 5) return(0); } return(1);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?