DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T c

⟦e8d03789c⟧ TextFile

    Length: 28641 (0x6fe1)
    Types: TextFile
    Names: »calls.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z« 
        └─⟦de7628f85⟧ 
            └─⟦this⟧ »isode-6.0/others/quipu/uips/widget2/calls.c« 

TextFile

/* calls.c - */

/*    This file has been modified by Damanjit Mahl @ Brunel University
 *    on 31st October 1989.
 */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/others/quipu/uips/widget2/RCS/calls.c,v 7.2 90/01/11 18:36:50 mrose Exp $";
#endif

/* 
 * $Header: /f/osi/others/quipu/uips/widget2/RCS/calls.c,v 7.2 90/01/11 18:36:50 mrose Exp $
 *
 *
 * $Log:	calls.c,v $
 * Revision 7.2  90/01/11  18:36:50  mrose
 * real-sync
 * 
 * Revision 7.1  89/12/06  08:22:04  mrose
 * sync
 * 
 * Revision 6.0  89/03/18  23:34:44  mrose
 * Release 5.0
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */

/*    This file has been modified by Damanjit Mahl @ Brunel University
 *    on 31st October 1989.
 */


#include "quipu/util.h"
#include "quipu/common.h"
#include "quipu/entry.h"
#include "tailor.h"
#include "sequence.h"


#define DEFEDITOR "/usr/ucb/vi"
#define RESBUF 100000
#define debug(a,b)

int scrollsize;
PS opt;
Attr_Sequence atseq, atseq2;

D_seq dnseq, textseq;
int current_entry, entry_number, display_entry;
int dn_print (), rdn_print(), as_print(), avs_comp_print();

char bound = FALSE;  /* indication of wether bound */
char * TidyString();

/* hack to get isode/curses compatability */
#define WINDOW char

#include "widget.h"
#include "wdgtdefs.h"

extern text_height;
int text_state;

#define DN_LIST 0
#define TEXT 1

/* These are common operation variables */
#define STRINGLEN 1000

char            goto_path[STRINGLEN];         /* Used by the 'G:goto' command*/
char            base_path[STRINGLEN];         /* Used by all DS operations   */
char            namestr[STRINGLEN];
char            cache [STRINGLEN];
char            bindpass [STRINGLEN];
char            srchvalue[STRINGLEN];         /* Used by search */
char            limit [STRINGLEN];            /* used by search / add */
char            commonname[STRINGLEN];
char            surname[STRINGLEN];
char            userclass[STRINGLEN];
char            roomnumber[STRINGLEN];
char            orgname[STRINGLEN];
char            orguname[STRINGLEN];
char            locality[STRINGLEN];
char            oclass[STRINGLEN];
char            countryname[STRINGLEN];
char            mtype [STRINGLEN];
char            mvalue [STRINGLEN];
char 		helpfile [STRINGLEN];

char     *filtvalue[] = {commonname, surname, userclass, roomnumber, orgname, orguname, locality, oclass, countryname};

#define commonname     0
#define organization   4
#define organizationalunit 5
#define countryname    7

static char     *filttype[] = {"commonName", "Surname", "UserClass","RoomNumber","OrganizationName", "OrganizationalUnitName", "LocalityName","countryName", NULLCP};

static char     *filtmatch[]= {"Exact ","Approx ",NULLCP};

#ifndef NO_STATS
extern LLog    *log_stat;
#endif 

/* These are used as the data for the binding connection */
char   passwd[STRINGLEN];
extern char     currentpath[];
extern char *   myname;

extern int sizelimit;
DN user_name;

char * addobj = NULLCP;

Filter search_filter;

user_tailor ()
{
	char           *part1;
	char           *part2;
	char           *getenv ();
	char            Dish_Home[BUFSIZ];

	FILE           *file;
	char            Read_in_Stuff[STRINGLEN];
	char           *p, 
		       *TidyString(),
		       *SkipSpace();
	extern char    *local_dit;
	
#ifndef NO_STATS
    	ll_hdinit (log_stat,"widget");
#endif

    	if ((opt = ps_alloc (std_open)) == NULLPS)
             fatal (-1,"ps_alloc failed");
	if (std_setup (opt,stdout) == NOTOK)
             fatal (-1,"std_setup failed");

	(void) sprintf (limit,"%d",sizelimit);
	namestr[0] = '\0';
	*passwd = '\0';
	cache[0] = '\0';
	currentpath[0] = '\0';

	if (p = getenv ("QUIPURC"))
	    (void) strcpy (Dish_Home, p);
	else
	    if (p = getenv ("HOME"))
		(void) sprintf (Dish_Home, "%s/.quipurc", p);
	    else
		(void) strcpy (Dish_Home, "./.quipurc");

	if ((file = fopen (Dish_Home, "r")) == 0) 
		return;

	while (fgets (Read_in_Stuff, STRINGLEN, file) != 0) {
		p = SkipSpace (Read_in_Stuff);
		if (( *p == '#') || (*p == '\0'))
			continue;  /* ignore comments and blanks */
			
		part1 = p;
		if ((part2 = index (p,':')) == NULLCP) 
			continue; /* ignore it */
		
		*part2++ = '\0';
		part2 = TidyString(part2);

		if (strcmp (part1, "username") == 0) 
			(void) strcpy (namestr, part2);
		else if (strcmp (part1, "password") == 0) 
			(void) strcpy (passwd, part2);
		else if (lexequ (part1, "dsap") == 0)
			(void) tai_string (part2);
		else if (lexequ (part1, "isode") == 0) {
			char * split;
			if ((split = index (part2,' ')) != NULLCP) {
				*split++ = 0;
				(void) isodesetvar (part2,split,0);
			}
		} else if (strcmp (part1, "service") == 0) 
			new_service (part2);
	}

	isodexport ();
}

/* These are the functions called by the main level of widgets */

main_help()
{
    cleartext();
    killwidgets(mainwdgts);
    setwidgets(dethelpwdgts,-1);
    help_cncs();
}

main_bind()
{
    cleartext();
    if (*passwd != 0)
        (void) strcpy(bindpass,"******");
    else
        bindpass[0] = '\0';
}

cnnct_quit ()
{
	quit (-1);
}

cnnct_bind()
{
struct ds_bind_arg bindarg;
struct ds_bind_arg bindresult;
struct ds_bind_error binderr;
extern  char * dsa_address,
	     * myname;
extern  char * tailfile;
FILE * fp;
char buf [BUFSIZ];

	/* set dsa_address */
	dsa_address = NULLCP;
	/* read tailor file to get address */
	if( (fp = fopen(isodefile(tailfile,0), "r")) == (FILE *)NULL) {
		tprint ("Cannot open tailor file %s\n",isodefile(tailfile,0));
		return;
	}
	while(fgets(buf, sizeof(buf), fp) != NULLCP)
		if ( (*buf != '#') && (*buf != '\n') )
			(void) tai_string (buf);

	(void) fclose(fp);

	if (dsa_address == NULLCP)
		dsa_address = myname;

	/* set password */
	if (bindpass[0] != 0) {
		if (strcmp (bindpass,"******") != 0)
			(void) strcpy (passwd,bindpass);
	} else 
		passwd[0] = 0;
        
	/* now bind */
	bindarg.dba_version = DBA_VERSION_V1988;
	if (passwd[0] == 0) {
		bindarg.dba_passwd_len = 0;
		bindarg.dba_passwd [0] = '\0';
	} else {
		bindarg.dba_passwd_len = strlen (passwd);
		(void) strcpy (bindarg.dba_passwd,passwd);
	}

	if (*namestr == 0)
		bindarg.dba_dn = NULLDN;	
	else
		bindarg.dba_dn = str2dn (namestr);

	if (ds_bind (&bindarg,&binderr,&bindresult) != DS_OK) {
	   if (binderr.dbe_type == DBE_TYPE_SECURITY)
		tprint ("Bind security error - Check name and pasword"); 
	   else
		tprint ("Bind service error - Can't contact DSA"); 
	} else {
		setdialogstr(getwidget(mainwdgts,'a'),  base_path, STRINGLEN);
		setdialogstr(getwidget(mainwdgts,'v'),  mvalue, STRINGLEN);
		setdialogstr(getwidget(mainwdgts,'*'),  srchvalue, 6);
		settogglstrs(getwidget(mainwdgts,'t'),filttype, countryname);
		settogglstrs(getwidget(mainwdgts,'k'),filtmatch,1);
		setwidgets (mainwdgts,-1);
		user_name = bindarg.dba_dn;
	        (void) strcpy (buf, "TERM");
		if(*local_dit)
		       (void) strcpy(base_path, local_dit);
		printdialog(getwidget(mainwdgts,'a'));
		set_default_type();
#ifndef NO_STATS
		LLOG (log_stat,LLOG_NOTICE,("bound ('%s' to '%s')",namestr,dsa_address));
#endif
#ifndef NO_STATS
                LLOG (log_stat,LLOG_NOTICE,("widget called from a ('%s')", getenv(buf)));
#endif
	}
        display_entry = 1;
        current_entry = 1;
        entry_number = 0;
        dnseq = NULLDS;
        text_state = TEXT;
        load_oid_table("oidtable");
        atseq = as_comp_new ( str2AttrT("commonName"),NULLAV,NULLACL_INFO);
        atseq2 = as_comp_new ( str2AttrT("surname"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("rfc822Mailbox"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("telephoneNumber"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("description"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("favouriteDrink"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("userid"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("roomNumber"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("userClass"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("friendlyCountryName"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("countryName"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("localityName"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("stateOrProvinceName"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("streetAddress"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("organizationName"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("organizationalUnitName"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("postalAddress"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("postalCode"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("postOfficeBox"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);
        atseq2 = as_comp_new ( str2AttrT("physicalDeliveryOfficeName"),NULLAV,NULLACL_INFO);
        atseq = as_merge ( atseq, atseq2);

        rd_start();
}

rd_start()
{
struct ds_read_arg read_arg;
struct ds_read_result   result;
struct DSError          error;
Entry read_entry;
		
    cleartext ();
    text_state = TEXT;

    if ( get_default_service (&read_arg.rda_common) != 0) {
   	xprint ("Default service error -> check your .quipurc\n");
	return ;
    }

	read_arg.rda_eis.eis_allattributes = FALSE;
	read_arg.rda_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES;
	read_arg.rda_eis.eis_select = atseq;
	
        if(*base_path)
        	read_arg.rda_object = str2dn(base_path);
        else
	        read_arg.rda_object = NULLDN;

	if ((read_entry = local_find_entry (read_arg.rda_object, FALSE)) != NULLENTRY) {
		read_print (as_print,(caddr_t)read_entry->e_attributes);
		return;
	}
#ifndef NO_STATS
	LLOG (log_stat,LLOG_NOTICE,("read +%s",base_path));
#endif
	
	if (ds_read (&read_arg,&error,&result) != DS_OK) {
		/* deal with error */
		/*quipu_error (&error);*/
	        cleartext();
		xprint("\nRead error - Sorry!");
	} else {
		/* use data */
		if (result.rdr_entry.ent_attr == NULLATTR) {
			xprint("No attributes");
			return;
		}
		xprint("Result of look up ...\n");
		if (result.rdr_common.cr_aliasdereferenced)
			xprint("Alias dereferenced)\n");

		(void) dn_decode (result.rdr_entry.ent_dn);
		(void) as_decode (result.rdr_entry.ent_attr);
		cache_entry (&(result.rdr_entry),TRUE,TRUE);
		read_print (as_print,(caddr_t)result.rdr_entry.ent_attr);
	}
}

back_start()
{
char *sptr, *str;

        str = base_path;
        if ( *str != '\0') {
		for (sptr = str; *sptr != '\0'; sptr++) {
		       if (*sptr == '@')
		              str = sptr;
		}
	        typetoggled = 0;
	}
        sptr = str;
        if (*--sptr == ' ') 
	       str = sptr;
        *str = '\0';
        set_default_type();
        printdialog(getwidget(mainwdgts, 'a'));
        rd_start();
}

set_default_type()
{
char *sptr, *str;
char c;
WIDGET *wdgt, *vwdgt;;

        wdgt = getwidget(mainwdgts,'t');
        vwdgt = getwidget(mainwdgts, 'v');
        if (*base_path) {
	       if (!typetoggled) {
		      sptr = str = base_path;
		      while (*str != '\0') 
			     str++;
		      while (str > sptr && *str != '@')
			     str--;
		      if (*str == '@')
			     sptr = ++str;
		      if (*str == ' ')
			     sptr = ++str;
		      while (*str != ' ' && *str != '=' && *str != '\0')
			     str++;
		      c = *str;
		      *str = '\0';
		      if (!strcmp ("countryName", sptr) || !strcmp("c", sptr)) {
			     (void) strcpy(filtvalue[wdgt->tindx], vwdgt->dstr);
			     wdgt->tindx = organization;
			     (void) strcpy(vwdgt->dstr, filtvalue[wdgt->tindx]);
		      }
		      else if (!strcmp ("organizationName", sptr) || !strcmp("o", sptr)) {
			     (void) strcpy(filtvalue[wdgt->tindx], vwdgt->dstr);
			     wdgt->tindx = organizationalunit ;
			     (void) strcpy(vwdgt->dstr, filtvalue[wdgt->tindx]);
		      }
		      else if (!strcmp ("organizationalUnitName", sptr) || !strcmp("ou", sptr)) {
			     (void) strcpy(filtvalue[wdgt->tindx], vwdgt->dstr);
			     wdgt->tindx = commonname;
			     (void) strcpy(vwdgt->dstr,filtvalue[wdgt->tindx]);
		      }
		      *str = c;
	       } 
	} else {
	       (void) strcpy(filtvalue[wdgt->tindx], vwdgt->dstr);
	       wdgt->tindx = countryname;
	       (void) strcpy(vwdgt->dstr, filtvalue[wdgt->tindx]);
	}

        typetoggled = 0;
        printtoggle(wdgt);
        printdialog(vwdgt);
}

/* These are the functions called by the list level widgets */

list_start()
{

struct ds_list_arg list_arg;

struct ds_list_result   result;
struct DSError          error;
struct subordinate      *ptr;
struct list_cache *cptr;
char *str;

   text_state = DN_LIST;
   if (get_default_service (&list_arg.lsa_common) != 0) {
        cleartext();
   	xprint ("Default service error -> check your .quipurc\n");
	return ;
   }

	list_arg.lsa_common.ca_servicecontrol.svc_sizelimit = 50;

        if(*base_path)
	       list_arg.lsa_object = str2dn(base_path);
        else 
	       list_arg.lsa_object = NULLDN;
	
        free_seq(dnseq);
        free_seq(textseq);
        dnseq = textseq = NULLDS;
        display_entry = current_entry = 1;
        entry_number = 0;
        for (str = base_path; *str != '\0'; str++) {}
	if ((cptr = find_list_cache (list_arg.lsa_object,list_arg.lsa_common.ca_servicecontrol.svc_sizelimit)) != NULLCACHE) {
	       for (ptr = cptr->list_subs; ptr != NULLSUBORD; ptr = ptr->sub_next) {
		       entry_number++;
	               rdn2str ((caddr_t)ptr->sub_rdn, goto_path);
		       if (str != base_path) {
	                       *str++ = '@';
			       (void) strcpy(str, goto_path);
			       add_seq (&dnseq, base_path);
			       *--str = '\0';
		       } else
		               add_seq (&dnseq, goto_path);
	       }
	       scrollbar('\0'); 
	       if (cptr->list_problem != LSR_NOLIMITPROBLEM)
	             xprint("(Limit problem)\n");
	       return;
	}
	
#ifndef NO_STATS
	LLOG (log_stat,LLOG_NOTICE,("list +%s",base_path));
#endif
						               
	if (ds_list (&list_arg,&error,&result) != DS_OK) {
 		        cleartext ();
			xprint ("\nService error - Sorry!");
	} else {
		/* use data */
	        free_seq(dnseq);
		free_seq(textseq);
		dnseq = textseq = NULLDS;
		xprint("Result of list operation ...\n");
		if (result.lsr_common.cr_aliasdereferenced) {
			xprint("Alias dereferenced - ");
			(void) dn_decode (result.lsr_object);
			quipu_print (dn_print,(caddr_t)result.lsr_object);
			dn_free (result.lsr_object);
			xprint("\n");
		}
		display_entry = current_entry = 1;
		entry_number = 0;
 	        for (str = base_path; *str != '\0'; str++) {}
		for (ptr = result.lsr_subordinates; ptr != NULLSUBORD; ptr=ptr->sub_next) {
		       entry_number++;
                       (void) rdn_decode (ptr->sub_rdn);
		       rdn2str ((caddr_t)ptr->sub_rdn, goto_path);
		       if (str != base_path) {
		              *str++ = '@';
			      (void) strcpy(str, goto_path);
			      add_seq (&dnseq, base_path);
			      *--str = '\0';
		       } else
			      add_seq (&dnseq, goto_path);
		}
		scrollbar('\0');
		if (result.lsr_limitproblem != LSR_NOLIMITPROBLEM)
			xprint("List too big. Try Search to reduce size.");

		cache_list (result.lsr_subordinates, result.lsr_limitproblem,list_arg.lsa_object,
			    list_arg.lsa_common.ca_servicecontrol.svc_sizelimit);
		subords_free (result.lsr_subordinates);
	}
}

rdn2str(ptr,cptr)
caddr_t ptr;
char * cptr;
{
    PS ps;
    char buffer [RESBUF];

    if ((ps = ps_alloc (str_open)) == NULLPS) {
        return ;
    }
    if (str_setup (ps,buffer,RESBUF,1) == NOTOK) {
        return ;
    }
    rdn_print(ps,(RDN)ptr,READOUT);

    ps_free (ps);
    *ps->ps_ptr = 0;

    (void) strcpy(cptr, buffer);
}


/* search ... */

void filt_substr (substr,at,str)
Filter_Substrings * substr;
AttributeType at;
char *str;
{
char * ptr;
AttributeValue av;

    if ((ptr = index (str,'*')) == NULLCP)
    	ptr = str + strlen (str);

    substr->fi_sub_initial = NULLAV;
    substr->fi_sub_any     = NULLAV;
    substr->fi_sub_final   = NULLAV;
    substr->fi_sub_type    = at;

/* This is the 'initial' section of the string - maybe NULL */
    *ptr = '\0';
    str = TidyString (str);
    if (*str != 0) {
	av = str2AttrV (str, at->at_table->oa_syntax);
	substr->fi_sub_initial = avs_comp_new (av);
    }
    str = ptr + 1;

/* Test for whether there are going to be any 'any' bits */
    if ((ptr = rindex(str, '*')) == NULLCP) {
	str = TidyString (str);
	if (*str != 0) {
		av = str2AttrV (str, at->at_table->oa_syntax);
		substr->fi_sub_final = avs_comp_new (av);
	}
	return;
    }

    *ptr = '\0';
    ptr = TidyString (ptr + 1);
    if ( *ptr != 0) {
	av = str2AttrV (str, at->at_table->oa_syntax);
	substr->fi_sub_final = avs_comp_new (av);
	}

/* There are some internal 'any's to be found */
    do {
	if ((ptr = index(str, '*')) != NULLCP)
	    *ptr = '\0';

	if (*str != 0) {
		str = TidyString (str);
			av = str2AttrV (str, at->at_table->oa_syntax);
		if (substr->fi_sub_any == NULLAV)
			substr->fi_sub_any = avs_comp_new (av);
		else
			substr->fi_sub_any = avs_merge (substr->fi_sub_any,avs_comp_new (av));
	}
	if (ptr != NULLCP)
	    str = ptr + 1;
    } while(ptr != NULLCP);
    

}


srch_start()
{
int    count, loop;
char   c;
char *sptr, *str;
struct ds_search_arg search_arg;
struct ds_search_result result;
struct DSError          error;
WIDGET *wdgt;

   cleartext();
   text_state = DN_LIST;
   wdgt = getwidget(mainwdgts,'t');
   if(*base_path == '\0' && strcmp("countryName",filttype[gettogglindx(wdgt)])) {
         cleartext();
	 xprint("\t   Currently you occupy the uppermost position in the directory. Searches\n at  this  level  can  only  be  performed  on  countries. To  search for\n organizations  contained within countries or people within organizations\n you must set the current address to an appropriate value,e.g. c=gb(other\n possibilities can be shown by (l)isting).\n");
	 return;
   }

   if (*mvalue =='\0') {
        cleartext();
	xprint("   You have not specified an object  to  search for. To specify an object\n press `v' and type the name of the  object  to  search  for. In addition\n specify the type of this object by pressing `t'  until  the correct type\n is found, e.g. organizationName if the object is `Brunel University'.\n");
	return;
   }

   if (get_default_service (&search_arg.sra_common) != 0) {
   	xprint ("Default service error -> check your .quipurc\n");
	return ;
   }

   tprint ("Searching ...");
   search_arg.sra_common.ca_servicecontrol.svc_sizelimit = 50;
   if(*base_path)
          search_arg.sra_baseobject = str2dn (base_path);
   else
          search_arg.sra_baseobject = NULLDN;
   search_arg.sra_eis.eis_allattributes = FALSE;
   search_arg.sra_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES;
   search_arg.sra_eis.eis_select = atseq;

   sptr = str = base_path;
   count = 0;
   while(*str != '\0') {
          str++;
	  if(*str == '@')
	        count++;
   }

   for(loop = 0; loop < count; loop++)
          while (*sptr != '@' && *sptr != '\0')
	        sptr++;

   while(str > base_path && (*sptr == '@' || *sptr == ' ' ))
          sptr++;

   str = sptr;

   while(*base_path != '\0' && (*str != ' ' && *str != '='))
          str++;

   c = *str;
   *str = '\0';
   if(!strcmp(sptr, "countryName") || !strcmp(sptr, "c") || *base_path == '\0')
           count = 0;
   else 
           count = 2;
   *str = c;

   if (count > 1) {
           search_arg.sra_subset = SRA_WHOLESUBTREE ;
   } else {
           search_arg.sra_subset = SRA_ONELEVEL ;
   }
   search_arg.sra_filter = filter_alloc ();
   search_arg.sra_filter->flt_next = NULLFILTER;
   search_arg.sra_filter->flt_type = FILTER_ITEM;
   search_arg.sra_filter->FUITEM.fi_type = gettogglindx(getwidget(mainwdgts,'k'));

   if(search_arg.sra_filter->FUITEM.fi_type != FILTERITEM_EQUALITY) 
        search_arg.sra_filter->FUITEM.fi_type = FILTERITEM_APPROX;

   switch (search_arg.sra_filter->FUITEM.fi_type) {
   case FILTERITEM_PRESENT:
        search_arg.sra_filter->FUITEM.UNTYPE = AttrT_new (filttype[gettogglindx(getwidget(mainwdgts,'t'))]);
	break;
   case FILTERITEM_SUBSTRINGS: {
	AttributeType at;

	at = AttrT_new (filttype[gettogglindx(getwidget(mainwdgts,'t'))]);
	if (!sub_string(at->at_table->oa_syntax)) {
		xprint ("Cant do a substring search if the type is not a string !!!");
		return;
	}
   	filt_substr(&search_arg.sra_filter->FUITEM.UNSUB,at,mvalue);
	break;
   }
   default:
        search_arg.sra_filter->FUITEM.UNAVA.ava_type = AttrT_new (filttype[gettogglindx(getwidget(mainwdgts,'t'))]);
	search_arg.sra_filter->FUITEM.UNAVA.ava_value = str2AttrV (mvalue,search_arg.sra_filter->FUITEM.UNAVA.ava_type->at_table->oa_syntax);
	break;
   }
#ifndef NO_STATS
	LLOG (log_stat,LLOG_NOTICE,("search +%s, extent %d, val %s",base_path,search_arg.sra_subset,mvalue));
#endif
   if (search_arg.sra_filter->FUITEM.UNAVA.ava_value == NULLAttrV) {
        cleartext();
        xprint("Unsuitable value for this search.");
   } else if(ds_search (&search_arg,&error,&result) != DS_OK) {
	/* deal with error */
	/*quipu_error (&error);*/
        cleartext();
	xprint("Search error - Sorry!");
    } else {
	correlate_search_results (&result);
	if (result.CSR_entries != NULLENTRYINFO) {
		 EntryInfo *ptr;
		 xprint ("Result of search ...\n");
		 if (result.CSR_common.cr_aliasdereferenced) {
			 xprint ("(Alias dereferenced - base object is ");
			 (void) dn_decode (result.CSR_object);
			 quipu_print (dn_print ,(caddr_t)result.CSR_object);
			 dn_free (result.CSR_object);
			 xprint (")\n");
		 }
		 free_seq(dnseq);
		 free_seq(textseq);
		 dnseq = textseq = NULLDS;
		 display_entry = current_entry = 1;
		 entry_number = 0;
  		 for (ptr = result.CSR_entries; ptr != NULLENTRYINFO; ptr = ptr->ent_next) {
		        entry_number++;
			(void) dn_decode (ptr->ent_dn);
		        dn2str ((caddr_t)ptr->ent_dn, goto_path);
 		        add_seq (&dnseq, goto_path);
			cache_entry (ptr,TRUE,TRUE);
		 }
		 scrollbar('\0');
	 } else if(result.CSR_limitproblem != LSR_TIMELIMITEXCEEDED)
		 xprint("\n   Nothing found using current search parameters. Try altering the search\n value or changing the type of match to achieve better results.\n");
 	
	 if(result.CSR_limitproblem != LSR_NOLIMITPROBLEM) {
		if(result.CSR_limitproblem == LSR_TIMELIMITEXCEEDED)
			xprint("(Time limit exceeded)");
		else
			xprint("(Size limit exceeded)");
	 }
	 entryinfo_free(result.CSR_entries, 0);
    }
    filter_free(search_arg.sra_filter);
}

dn2str (ptr,cptr)
caddr_t ptr;
char * cptr;
{
    PS ps;
    char buffer [RESBUF];

    if((ps = ps_alloc (str_open)) == NULLPS) {
        return ;
    }
    if(str_setup (ps,buffer,RESBUF,1) == NOTOK) {
        return ;
    }
    dn_print(ps,(DN)ptr,EDBOUT);
    *ps->ps_ptr = 0;

    ps_free (ps);

    (void) strcpy(cptr, buffer);
}


read_print(func,ptr)
int (*func) ();
caddr_t ptr;
{
PS ps;
char buffer [RESBUF];
char save;
int i, size;
char *str, *sptr;

       if ((ps = ps_alloc (str_open)) == NULLPS) {
              return ;
       }
       if (str_setup (ps,buffer,RESBUF,1) == NOTOK) {
	      return ;
       }

       (*func) (ps, ptr, READOUT);
       *ps->ps_ptr = 0;

       ps_free(ps);
       str = buffer ;
       sptr = str;
       size = strlen(buffer);

       free_seq(dnseq);
       dnseq = NULLDS;
       free_seq(textseq);
       textseq = NULLDS;
       display_entry = current_entry = 1;
       entry_number = 0;
		    
       for (i=0; i<= size; i++, sptr++) {
             if (*sptr == '\n' || *sptr == '\0') {
	             entry_number++;
		     save = *sptr ;
		     *sptr = '\0';
		     add_seq(&textseq, str);
		     str = sptr+1;
		     *sptr = save;
	     }
       }
       scrollbar('\0');
}

quipu_print (func,ptr)
int (*func) ();         /* assumes func (PS ,dataptr,(int) format); */
caddr_t ptr;
{
	/* log info to pstream */
PS ps;
char buffer [RESBUF];
int count;
char *str, *sptr;
char save;

    if ((ps = ps_alloc (str_open)) == NULLPS) {
	return ;
    }
    if (str_setup (ps,buffer,RESBUF,1) == NOTOK) {
	return ;
    }

    (*func) (ps,ptr,READOUT);
    *ps->ps_ptr = 0;

    ps_free (ps);

    /* print in blocks of 100 bytes - larger appears to be too much for curses */
    str = buffer;
    do {
             for (count = 0, sptr = str; *sptr != '\0' && count < 100; sptr++, count++) {}
             save = *sptr;
             *sptr = 0;
	     xprint (str);
             *sptr = save;
             str = sptr;

    } while (*sptr != '\0');
}

quipu_error (err)
struct DSError * err;
{
PS ps;
char buffer [RESBUF];

    if ((ps = ps_alloc (str_open)) == NULLPS) {
	return ;
    }
    if (str_setup (ps,buffer,RESBUF,1) == NOTOK) {
	return ;
    }
    ds_error (ps,err);

    *ps->ps_ptr = 0;
    xprint (buffer);
}

returnmain()
{
	QUITFN();
	setwidgets (mainwdgts,-1);
}

/* ARGSUSED */
set_sequence (a)
char * a;
{
;
}

unset_sequence ()
{
;
}

free_all()
{
        free_seq(dnseq);
	free_seq(textseq);
}


get_listed_object(number, wdgt)
char number;
WIDGET *wdgt;
{
int entrynum;
char *sptr;

        *srchvalue = number;
	*(srchvalue+1) = '\0';
        printdialog(wdgt);
	dialog(wdgt);
        cleartext();
	entrynum = atoi(srchvalue);
        sptr = get_from_seq (entrynum, dnseq);
        if (sptr) {
	      (void) strcpy(base_path, sptr);
	      wdgt = getwidget(mainwdgts, 'a');
	      printdialog(wdgt);
              rd_start();
	      typetoggled = 0;
	      set_default_type();
	}
        *srchvalue = '\0';
}

detquit()
{ 
       cleartext();
       killwidgets(currwidgets);
       setwidgets(helpwdgts, -1);
       redraw();
}

help_dtld()
{
       cleartext();
       textfresh();
       killwidgets(currwidgets);
       setwidgets(dethelpwdgts, -1);
}



scrollbar(command)
char command;
{
char *str, *base_rdn;
int lines, base_rdn_count=0, rdn_count=0, count=0;
D_seq thisseq;
      
       if(command == '[') {
	       if(display_entry >= entry_number)
		      return;
               current_entry++;
       } else if(command == ']')
	       if(current_entry > 1)
		      current_entry--;

       if (!entry_number) {
	       cleartext();
               xprint("Nothing to print!");
	       return;
       }

       cleartext();

       switch(text_state) {
	 case(DN_LIST):
	       base_rdn = base_path;
	       while(*base_rdn != '\0') {
		      if(*base_rdn == '@')
			     base_rdn_count++;
		      base_rdn++;
	       }
	       if (*base_path != '\0') base_rdn_count++;
	       thisseq = dnseq;
	       break;
	 case(TEXT):
	       thisseq = textseq;
	       break;
       }
       
       if (current_entry > entry_number) 
                current_entry = 1;

       lines = linec()-2;

       for (display_entry = current_entry; display_entry <= entry_number && gety() < lines; display_entry++) {
	       if(text_state == DN_LIST) xprintint(" %d ", display_entry) ;

	       str = get_from_seq (display_entry, thisseq);

	       if(text_state == DN_LIST && !rdn_count && base_rdn_count) {
		      while(rdn_count < base_rdn_count) {
			     while(*str != '@') {
			       	    str++;
				    count++;
			     }
			     rdn_count++;
			     str++;
			     count++;
		      }
		      while(*str == ' ') {
			     str++;
			     count++;
		      }
	       } else if (count)
		      str +=count;

 	       if(str) {
		      xprint(str);
		      xprint("\n");
	       }
       }
       if (text_state == DN_LIST) {
	       if (current_entry >= entry_number) 
		      xprint("<List finished>");
	       else
		      xprintint("<Total of %d entries>", entry_number);
       }
       printbar(entry_number, current_entry, display_entry-current_entry);
       display_entry--;
}

goto_addr()
{
       set_default_type();
       rd_start();
}