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

📄 de.c

📁 ftam等标准协议服务器和客户端的源代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
      }    }  }}intdoPRR(matchstring, searchparent)char matchstring [];int searchparent;{  if ((strcmp(qinfo[PERSON].entered, qinfo[PERSON].defvalue) == 0) &&      (qinfo[PERSON].lp != NULLLIST) && (qinfo[PERSON].listlen == 1))  {        printListPRRs(qinfo[PERSON].entered, qinfo[PERSON].lp, searchparent, TRUE);    return NAME_PRINTED;  }    for (;;)  {    /* inits */    freePRRs(&qinfo[PERSON].lp);    pagerOn(NUMBER_ALLOWED);        if (listPRRs(matchstring, qinfo[PERSON].entered, &qinfo[PERSON].lp) != OK)    {      if (searchFail(PERSON) != SF_ABANDONED)        (void) strcpy(qinfo[PERSON].entered, "");      return PARENT_PRINTED;    }    qinfo[PERSON].listlen = listlen(qinfo[PERSON].lp);    if (qinfo[PERSON].listlen == 0)    {      if (strcmp(qinfo[PERSON].entered, "*") == 0)        resetprint("      No entries for people found.  ");      else        resetprint("      No persons match `%s'.  ", qinfo[PERSON].entered);      if (qinfo[ORGUNIT].lp != NULLLIST)      {        resetprint("Printing departmental details.\n\n");	printNames(ORGUNIT);        printDetails(ORGUNIT, qinfo[ORGUNIT].lp);      }      else      {        resetprint("Printing organisation details.\n\n");	printNames(ORGUNIT);        printDetails(ORG, qinfo[ORG].lp);      }      return PARENT_PRINTED;    }    else if (qinfo[PERSON].listlen == 1)    {      if (testRedisplay())        printNames(ORGUNIT);      printListPRRs(qinfo[PERSON].entered, qinfo[PERSON].lp, searchparent, TRUE);      return NAME_PRINTED;    }    else /* qinfo[PERSON].listlen > 1 */    {      if (qinfo[PERSON].listlen > maxPersons)      {        if (strcmp(qinfo[PERSON].entered, "*") == 0)          foundFollowing();        else	  matchFollowing();	printNames(ORGUNIT);        printListPRRs(qinfo[PERSON].entered, qinfo[PERSON].lp, searchparent, FALSE);        /* If number entered, continue trying to resolve the query.	   Otherwise start a fresh query */        if (strcmp(qinfo[PERSON].entered, "*") == 0)	  (void) strcpy(qinfo[PERSON].defvalue, "");        else          (void) strcpy(qinfo[PERSON].defvalue, qinfo[PERSON].entered);	if (enterString(PERSON) == 0)	  break;	else	  continue;      }      else      {        if (testRedisplay())	  printNames(ORGUNIT);        printListPRRs(qinfo[PERSON].entered, qinfo[PERSON].lp, searchparent, TRUE);      }      return NAME_PRINTED;    }  }  return START_NEW_QUERY;}printNames(objectType)int objectType;{	switch (objectType)	{		case COUNTRY:			printLastComponent(INDENTON, qinfo[COUNTRY].lp->name, 			                                         COUNTRY, 0);			break;		case ORG:			printLastComponent(INDENTON, qinfo[COUNTRY].lp->name,			                                         COUNTRY, 0);			printLastComponent(INDENTON, qinfo[ORG].lp->name,			                                             ORG, 0);			break;		case ORGUNIT:			printLastComponent(INDENTON, qinfo[COUNTRY].lp->name,			                                         COUNTRY, 0);			printLastComponent(INDENTON, qinfo[ORG].lp->name,			                                             ORG, 0);			if (qinfo[ORGUNIT].lp != NULLLIST)			  printLastComponent(INDENTON, qinfo[ORGUNIT].lp->name,			                                           ORGUNIT, 0);			break;		case PERSON:			break;	}}printCountry(){  printLastComponent(INDENTON, qinfo[COUNTRY].lp->name, COUNTRY, 0);}voidfoundFollowing(){  resetprint("\nFound the following entries.  Please select one from the list\n");  resetprint("by typing the number corresponding to the entry you want.\n\n");}voidmatchFollowing(){  resetprint("\nGot the following approximate matches.  Please select one from the list\n");  resetprint("by typing the number corresponding to the entry you want.\n\n");}/* routine returns the number of an entry selected from a list, or zero   otherwise */intenterString(objectType)int objectType;{char prompt[LINESIZE];static char prstr[] = ":-";static char gotValue[LINESIZE] = "";int numEnt;  setRedisplay();  if (boundToDSA == TRUE)    startUnbindTimer();  switch(objectType)  {    case PERSON:      if (strlen(gotValue) != 0)      {        (void) strcpy(qinfo[objectType].entered, gotValue);	gotValue[0] = '\0';	break;      }      (void) sprintf(prompt, "\nPerson's name, q to quit, ");      if (strlen(qinfo[objectType].defvalue) != 0)        (void) sprintf(prompt, "%s<CR> for `%s', ", prompt, 	       qinfo[objectType].defvalue);      (void) sprintf(prompt, "%s* to %s, ? for help\n%s", prompt,              browseMess ? "browse" : "list people", prstr);      enterAndValidate(prompt, qinfo[objectType].entered, objectType,                        qinfo[objectType].defvalue, qinfo[objectType].lp, &numEnt);      /* if a string was entered, but a number could validly have been      entered, store value in gotValue for next invocation of this function */      if ((highNumber > 0) && (numEnt == 0))        (void) strcpy(gotValue, qinfo[objectType].entered);      break;    case ORGUNIT:        (void) sprintf(prompt, "Department name, * to %s, ",	     browseMess ? "browse" : "list depts");        if (strcmp(qinfo[objectType].defvalue, "*") == 0)          (void) sprintf(prompt, "%s<CR> to %s all depts, ", prompt,	     browseMess ? "browse" : "list");	else	{	  if (strlen(qinfo[objectType].defvalue) == 0)	  {	    if (strlen(qinfo[PERSON].entered) != 0)	      (void) sprintf(prompt, "%s<CR> to search all depts, ", prompt);	  }	  else	  {            (void) strcat(prompt, "- to search all departments,\n           ");	    (void) sprintf(prompt, "%s<CR> to search for `%s', ", 	                                 prompt, qinfo[objectType].defvalue);	  }	}        (void) sprintf(prompt, "%s? for help\n%s", prompt, prstr);        enterAndValidate(prompt, qinfo[objectType].entered, objectType, 	                    qinfo[objectType].defvalue, qinfo[objectType].lp, &numEnt);        break;    case ORG:        (void) sprintf(prompt, "Organisation name, ");	if (strcmp(qinfo[objectType].defvalue, "") != 0)	{	  (void) sprintf(prompt, "%s<CR> to search `%s', ", prompt,	                                        qinfo[objectType].defvalue);          if ((int)strlen(qinfo[objectType].defvalue) > 10)	    (void) sprintf(prompt, "%s\n           ", prompt);	}        (void) sprintf(prompt, "%s* to %s, ", prompt, 	               browseMess ? "browse" : "list orgs");        (void) sprintf(prompt, "%s? for help\n%s", prompt, prstr);        enterAndValidate(prompt, qinfo[objectType].entered, objectType, 	                    qinfo[objectType].defvalue, qinfo[objectType].lp, &numEnt);        break;    case COUNTRY:        (void) sprintf(prompt, "Country name, ");	if ((strcmp(qinfo[objectType].defvalue, "") != 0) &&	    (strcmp(qinfo[objectType].defvalue, "*") != 0))	  (void) sprintf(prompt, "%s<CR> to search `%s', ", prompt, 	                                         qinfo[objectType].defvalue);        (void) sprintf(prompt, "%s* to %s, ", prompt,	               browseMess ? "browse" : "list countries");        (void) sprintf(prompt, "%s? for help\n%s", prompt, prstr);        enterAndValidate(prompt, qinfo[objectType].entered, objectType, 	                    qinfo[objectType].defvalue, qinfo[objectType].lp, &numEnt);        break;    default:      (void) fprintf(stderr, "Unknown type in enterString\n");      break;  }  stopUnbindTimer();  if (lexnequ(qinfo[objectType].entered, "quit",	                        strlen(qinfo[objectType].entered)) == 0)  {    if (objectType == PERSON)      cleanupok();    if (enterYesNo() == 'y')      cleanupok();    else      longjmp(sjbuf, 0);  }  return numEnt;}enterAndValidate(prompt, buf, objectType, defaultValue, lp, nep)char * prompt, * buf;int objectType;char * defaultValue;struct namelist * lp;int * nep;{char * cp, * cp2;int i, n, isnum;  *nep = 0;  /* this picks up any number that was entered at the pager prompt */  if ((n = getpnum()) != -1)  {    if ((n > highNumber) || (n < 1)) /* check number against valid range */    {      if (highNumber > 0)        (void) fprintf(stderr, "Invalid number entered (maximum = %d)\n\n", 	                                                        highNumber);      else	(void) fprintf(stderr, 	         "No list of entries current.  Entry of a number invalid\n");    }    else /* valid number */    {      for (i = 1; i < n; i++, lp = lp->next) {};      cp = copy_string(lastComponent(lp->name, objectType));      exactMatch = objectType;      (void) strcpy(exactString, lp->name);      (void) strcpy(buf, cp);      free(cp);      *nep = n;      return;    }  }  for (;;)  {    exactMatch = -1;    writeInverse(prompt);    (void) putchar(' ');    if (gets(buf) == NULLCP) /* deal with control-D */      if (objectType == PERSON)        /* exit the program */        cleanup(0);      else      {        /* behave as for an interrupt */	clearerr(stdin);        onint1();      }    cp = copy_string(TidyString(buf));    if (strlen(cp) == 0) /* default accepted */    {      free(cp);      cp = copy_string(defaultValue);      break;    }    /* if "-" entered, convert this to a null entry, unless entering a        country.  In this case, "-" is treated as search international orgs */    if (objectType != COUNTRY)      if (strcmp(cp, "-") == 0)      {        *cp ='\0';	break;      }    if (strcmp(cp, "?") == 0) /* help on current input requested */    {      switch (objectType)      {        case PERSON:          displayHelp(findHelp("name"));	  break;	case ORGUNIT:	  displayHelp(findHelp("department"));	  break;	case ORG:	  displayHelp(findHelp("organisation"));	  break;	case COUNTRY:	  displayHelp(findHelp("country"));	  break;      }      continue;    }    if (*cp == '?') /* help on some other specific topic requested */    {      for (cp++; *cp == ' '; cp++) {};      if ((lexequ(cp, "?") == 0) ||           (lexequ(cp, "help") == 0)) /* help about help requested */        displayHelp(findHelp("help"));      else         displayHelp(findHelp(cp));      continue;    }    /* if a number has been entered, check that it is in range, and        map the number onto the appropriate name */    isnum = TRUE;    for (cp2 = cp; *cp2 != '\0'; cp2++)    {      if (! isdigit(*cp2))      {        isnum = FALSE;	break;      }    }    if (isnum)    {      n = atoi(cp);      if ((n > highNumber) || (n < 1)) /* check number against valid range */      {        if (highNumber > 0)          (void) fprintf(stderr, "Invalid number entered (maximum = %d)\n\n", 	                                                          highNumber);	else	  (void) fprintf(stderr, 	          "No list of entries current.  Entry of a number invalid\n");	continue;      }      else      {	for (i = 1; i < n; i++, lp = lp->next) {};	free(cp);	cp = copy_string(lastComponent(lp->name, objectType));        exactMatch = objectType;	(void) strcpy(exactString, lp->name);        *nep = n;      }    }    if (index(cp, '*') == 0) /* no wild cards */      break;     if (*cp == '*')    {      if (strlen(cp) == 1)        break;      cp2 = index(cp + 1, '*');      if (cp2 == NULLCP)        break;      if (cp2 == cp + 1) /* i.e. string is ** */      {        displayValidWildCards();	free(cp);	continue;      }      if (*(cp2 + 1) != '\0')      {        displayValidWildCards();	free(cp);        continue;      }      break;    }    /* string has at least one asterisk - make sure it's only one */    if (index(cp, '*') == rindex(cp, '*'))      break;    else    {      displayValidWildCards();      free(cp);      continue;    }  }  (void) strcpy(buf, cp);  free(cp);}char enterYesNo(){char buf[LINESIZE];int i;  for (;;)  {    (void) printf("Do you want to quit the Directory Service (y/n) ");    if (gets(buf) == NULLCP) /* control-D */      return 'y';    for (i = 0; buf[i] != '\0'; i++)      buf[i] = uptolow(buf[i]);    if ((buf[0] == 'y') || (buf[0] == 'n'))      return buf[0];    else      continue;  }}displayValidWildCards(){  (void) printf("The following wild-card formats are acceptable:\n");  (void) printf("\t*\n\txxx*\n\t*xxx*\n\t*xxx\n\txx*xx\n\n");}countryCodeMessage(str){  (void) printf("<%s> is not a valid two-letter country code.\n", str);  (void) printf("Either enter a valid two-letter code, or enter the country name more fully.\n\n", str);}voidonint1(){  (void) putchar('\n');  /* simulate search failure -      this ensures that the "country question" is asked */  searchfail = TRUE;  longjmp(sjbuf, 0);}SFD cleanupok(){  cleanup(0);}intcleanup(exitCode)int exitCode;{  if (boundToDSA == TRUE)    (void) de_unbind(); #ifdef SPEC_MALL  stop_malloc_trace();#endif  de_exit(exitCode);}/* the flushes need dealing with properly */voidonalarm(){  (void) signal(SIGALRM, (VFP) onalarm);  (void) alarm(2);  switch (alarmCount)  {    case 0:      resetprint("\nThis operation is taking some time.\nControl-C, if you wish to abandon the operation.\n\n");      break;    case 1:      resetprint("Still trying ...");      (void) fflush(stdout);      break;    default:      resetprint(".");      (void) fflush(stdout);      break;  }  alarmCount++;}searchFail(objectType)int objectType;{int problem;  searchfail = TRUE;  if (abandoned)  {     resetprint("\nSearch abandoned\n");     return SF_ABANDONED;  }  if (accessrightproblem)  {    problem = SF_ACCRIGHT;    resetprint("\nSearching this part of the Directory is restricted by the managers\n");    resetprint("of the data.\n\n");  }  else  {    problem = SF_OPFAIL;    resetprint("\nThe search ");    if (strcmp(qinfo[objectType].entered, "*") != 0)      resetprint("for '%s' ", qinfo[objectType].entered);    resetprint("has failed, probably because a Directory \n");    resetprint("server is unavailable.  ");    if (objectType == ORGUNIT)    {      resetprint("In the meantime, displaying organisation details.\n");      resetprint("For information on people or departments,");      resetprint(" try again a little later.\n\n");    }    else if (objectType == PERSON)    {      if (qinfo[ORGUNIT].lp == NULLLIST)        resetprint("In the meantime, displaying organisation details.\n");      else        resetprint("In the meantime, displaying department details.\n");      resetprint("For information on people,");      resetprint(" try again a little later.\n\n");    }  }  if (objectType == ORGUNIT)  {    printNames(ORG);    printDetails(ORG, qinfo[ORG].lp);    return problem;  }  if (objectType == PERSON)  {    if (qinfo[ORGUNIT].lp != NULLLIST)    {       printNames(ORGUNIT);       printDetails(ORGUNIT, qinfo[ORGUNIT].lp);    }    else    {       printNames(ORG);       printDetails(ORG, qinfo[ORG].lp);     }     return problem;  }  return problem;}voidde_exit(exitCode)int exitCode;{void exit();  if (byeByeMessage == TRUE)    displayFile("byebye", FALSE); /* FALSE means not a help screen */  exit(exitCode);}

⌨️ 快捷键说明

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