📄 support.c
字号:
/* *//* * Copyright (c) 1989, 1990, 1991 by the University of Washington *//* * *//* * For copying and distribution information, please see the file *//* * <copyright.h>. *//* * Miscellaneous routines pulled from ~beta/lib/pfs and ~beta/lib/filters */#include "pmachine.h"#include <sys/file.h>#include "pfs.h"#include "pprot.h"#include "perrno.h"#include "pcompat.h"#include "pauthent.h"#include "regex.h"int pfs_enable = PMAP_ATSIGN;/* *//* * wcmatch - Match string s against template containing widlcards *//* * *//* * WCMATCH takes a string and a template, and returns *//* * true if the string matches the template, and *//* * FALSE otherwise. *//* * *//* * ARGS: s - string to be tested *//* * template - Template containing optional wildcards *//* * *//* * RETURNS: TRUE (non-zero) on match. FALSE (0) otherwise. *//* * *//* * NOTE: If template is NULL, will return TRUE. *//* * */intwcmatch(s,template) char *s; char *template; { char temp[200]; char *p = temp; if(!template) return(TRUE); *p++ = '^'; while(*template) { if(*template == '*') {*(p++)='.'; *(p++) = *(template++);} else if(*template == '?') {*(p++)='.';template++;} else if(*template == '.') {*(p++)='\\';*(p++)='.';template++;} else if(*template == '[') {*(p++)='\\';*(p++)='[';template++;} else if(*template == '$') {*(p++)='\\';*(p++)='$';template++;} else if(*template == '^') {*(p++)='\\';*(p++)='^';template++;} else if(*template == '\\') {*(p++)='\\';*(p++)='\\';template++;} else *(p++) = *(template++); } *p++ = '$'; *p++ = '\0'; if(re_comp(temp)) return(FALSE);#ifdef AUX if (re_exec(s) == (char *)NULL) return 0; return 1;#else return(re_exec(s));#endif }/* *//* * ul_insert - Insert a union link at the right location *//* * *//* * UL_INSERT takes a directory and a union link to be added *//* * to a the list of union links in the directory. It then *//* * inserts the union link in the right spot in the linked *//* * list of union links associated with that directory. *//* * *//* * If an identical link already exists, then the link which *//* * would be evaluated earlier (closer to the front of the list) *//* * wins and the other one is freed. If this happens, an error *//* * will also be returned. *//* * *//* * ARGS: ul - link to be inserted *//* * vd - directory to get link *//* * p - vl that this link will apper after *//* * NULL - This vl will go at end of list *//* * vd - This vl will go at head of list *//* * *//* * RETURNS: Success, or UL_INSERT_ALREADY_THERE or UL_INSERT_SUPERSEDING */intul_insert(ul,vd,p) VLINK ul; /* Link to be inserted */ PVDIR vd; /* Directory to receive link */ VLINK p; /* Union link to appear prior to new one */ { VLINK current; /* This is the first ul in the directory */ if(vd->ulinks == NULL) { vd->ulinks = ul; ul->previous = NULL; ul->next = NULL; return(PSUCCESS); } /* This ul will go at the head of the list */ if(p == (VLINK) vd) { ul->next = vd->ulinks; ul->next->previous = ul; vd->ulinks = ul; ul->previous = NULL; } /* Otherwise, decide if it must be inserted at all If an identical */ /* link appears before the position at which the new one is to be */ /* inserted, we can return without inserting it */ else { current = vd->ulinks; while(current) { /* p == NULL means we insert after last link */ if(!p && (current->next == NULL)) p = current; if(vl_comp(current,ul) == 0) { vlfree(ul); return(UL_INSERT_ALREADY_THERE); } if(current == p) break; current = current->next; } /* If current is null, p was not found */ if(current == NULL) return(UL_INSERT_POS_NOTFOUND); /* Insert ul */ ul->next = p->next; p->next = ul; ul->previous = p; if(ul->next) ul->next->previous = ul; } /* Check for identical links after ul */ current = ul->next; while(current) { if(vl_comp(current,ul) == 0) { current->previous->next = current->next; if(current->next) current->next->previous = current->previous; vlfree(current); return(UL_INSERT_SUPERSEDING); } current = current->next; } return(PSUCCESS); }/* *//* * vl_insert - Insert a directory link at the right location *//* * *//* * VL_INSERT takes a directory and a link to be added to a *//* * directory and inserts it in the linked list of links for *//* * that directory. *//* * *//* * If a link already exists with the same name, and if the *//* * information associated with the new link matches that in *//* * the existing link, an error is returned. If the information *//* * associated with the new link is different, but the magic numbers *//* * match, then the new link will be added as a replica of the *//* * existing link. If the magic numbers do not match, the new *//* * link will only be added to the list of "replicas" if the *//* * allow_conflict flag has been set. *//* * *//* * If the link is not added, an error is returned and the link *//* * is freed. Ordering for the list of links is by the link name. *//* * *//* * If vl is a union link, then VL_INSERT calls ul_insert with an *//* * added argument indicating the link is to be included at the *//* * end of the union link list. *//* * *//* * ARGS: vl - Link to be inserted, vd - directory to get link *//* * allow_conflict - insert links with conflicting names *//* * *//* * RETURNS: Success, or VL_INSERT_ALREADY_THERE */intvl_insert(vl,vd,allow_conflict) VLINK vl; /* Link to be inserted */ PVDIR vd; /* Directory to receive link */ int allow_conflict; /* Allow duplicate names */ { VLINK current; /* To step through list */ VLINK crep; /* To step through list of replicas */ int retval; /* Temp for checking returned values */ /* This can also be used to insert union links at end of list */ if(vl->linktype == 'U') return(ul_insert(vl,vd,NULL)); /* If this is the first link in the directory */ if(vd->links == NULL) { vd->links = vl; vl->previous = NULL; vl->next = NULL; vd->lastlink = vl; return(PSUCCESS); } /* If no sorting is to be done, just insert at end of list */ if(allow_conflict == VLI_NOSORT) { vd->lastlink->next = vl; vl->previous = vd->lastlink; vl->next = NULL; vd->lastlink = vl; return(PSUCCESS); } /* If it is to be inserted at start of list */ if(vl_comp(vl,vd->links) < 0) { vl->next = vd->links; vl->previous = NULL; vl->next->previous = vl; vd->links = vl; return(PSUCCESS); } current = vd->links; /* Otherwise, we must find the right spot to insert it */ while((retval = vl_comp(vl,current)) > 0) { if(!current->next) { /* insert at end */ vl->previous = current; vl->next = NULL; current->next = vl; vd->lastlink = vl; return(PSUCCESS); } current = current->next; } /* If we found an equivilant entry already in list */ if(!retval) { if(vl_equal(vl,current)) { vlfree(vl); return(VL_INSERT_ALREADY_THERE); } if((allow_conflict == VLI_NOCONFLICT) && ((vl->f_magic_no != current->f_magic_no) || (vl->f_magic_no==0))) return(VL_INSERT_CONFLICT); /* Insert the link into the list of "replicas" If magic is 0, */ /* then create a pseudo magic number */ if(vl->f_magic_no == 0) vl->f_magic_no = -1; crep = current->replicas; if(!crep) { current->replicas = vl; vl->next = NULL; vl->previous = NULL; } else { while(crep->next) { /* If magic was 0, then we need a unique magic number */ if((crep->f_magic_no < 0) && (vl->f_magic_no < 1)) (vl->f_magic_no)--; crep = crep->next; } /* If magic was 0, then we need a unique magic number */ if((crep->f_magic_no < 0) && (vl->f_magic_no < 1)) (vl->f_magic_no)--; crep->next = vl; vl->previous = crep; vl->next = NULL; } return(PSUCCESS); } /* We found the spot where vl is to be inserted */ vl->next = current; vl->previous = current->previous; current->previous = vl; vl->previous->next = vl; return(PSUCCESS); }/* *//* * nlsindex - Find first instance of string 2 in string 1 following *//* newline *//* * *//* * NLSINDEX scans string 1 for the first instance of string *//* * 2 that immediately follows a newline. If found, NLSINDEX *//* * returns a pointer to the first character of that instance. *//* * If no instance is found, NLSINDEX returns NULL (0). *//* * *//* * NOTE: This function is only useful for searching strings that *//* * consist of multiple lines. s1 is assumed to be preceeded *//* * by a newline. Thus, if s2 is at the start of s1, it will *//* * be found. *//* * ARGS: s1 - string to be searched *//* * s2 - string to be found *//* * RETURNS: First instance of s2 in s1, or NULL (0) if not found */char *nlsindex(s1,s2) char *s1; /* String to be searched */ char *s2; /* String to be found */ { register int s2len = strlen(s2); char *curline = s1; /* Pointer to start of current line */ /* In case s2 appears at start of s1 */ if(strncmp(curline,s2,s2len) == 0) return(curline); /* Check remaining lines of s1 */ while((curline = (char *) index(curline,'\n')) != NULL) { curline++; if(strncmp(curline,s2,s2len) == 0) return(curline); } /* We didn't find it */ return(NULL); }/* *//* * month_sname - Return a month name from it's number *//* * *//* * MONTH_SNAME takes a number in the range 0 *//* * to 12 and returns a pointer to a string *//* * representing the three letter abbreviation *//* * for that month. If the argument is out of *//* * range, MONTH_SNAME returns a pointer to "Unk". *//* * *//* * ARGS: n - Number of the month *//* * RETURNS: Abbreviation for selected month */char *month_sname(n) int n; /* Month number */{ static char *name[] = { "Unk", "Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec" };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -