240 lines
11 KiB
HTML
240 lines
11 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="reference" />
|
||
|
<meta name="DC.Title" content="Example: Creating your own telephone directory" />
|
||
|
<meta name="abstract" content="This program creates a user index named 'TESTIDX' in the library 'QGPL'." />
|
||
|
<meta name="description" content="This program creates a user index named 'TESTIDX' in the library 'QGPL'." />
|
||
|
<meta name="DC.Relation" scheme="URI" content="apiexmp.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="apiexcreind.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="apiexcredir" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Example: Creating your own telephone directory</title>
|
||
|
</head>
|
||
|
<body id="apiexcredir"><a name="apiexcredir"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Example: Creating your own telephone directory</h1>
|
||
|
<div><p>This program creates a user index named 'TESTIDX' in the library
|
||
|
'QGPL'.</p>
|
||
|
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm">Code license and disclaimer information</a> for important
|
||
|
legal information.</div>
|
||
|
<p>To create a telephone directory, you must use
|
||
|
the following $USIDXCRT ILE C program to create a user index, and you must
|
||
|
use the $USIDXEX ILE C program to insert the entries into a telephone directory.</p>
|
||
|
<p>To
|
||
|
set up the program to create a user index, specify the following:</p>
|
||
|
<pre>/********************************************************************/
|
||
|
/* PROGRAM: $USIDXCRT */
|
||
|
/* */
|
||
|
/* LANGUAGE: ILE C */
|
||
|
/* */
|
||
|
/* DESCRIPTION: THIS PROGRAM CREATES A USER INDEX NAMED "TESTIDX" */
|
||
|
/* IN THE LIBRARY "QGPL". */
|
||
|
/* */
|
||
|
/* APIs USED: QUSCRTUI */
|
||
|
/* */
|
||
|
/********************************************************************/
|
||
|
#include <quscrtui.h>
|
||
|
main()
|
||
|
{
|
||
|
/********************************************************************/
|
||
|
/* Set up the parameters to be used in the call to 'QUSCRTUI' */
|
||
|
/********************************************************************/
|
||
|
char idx_name[]= "TESTIDX QGPL ";
|
||
|
char ext_atr[]= "TESTER ";
|
||
|
char entry_lgth_att[] = "F";
|
||
|
int entry_lngth = 50;
|
||
|
char key_insert[] = "1";
|
||
|
int key_lngth = 15;
|
||
|
char imm_update[] = "0";
|
||
|
char optim[] = "0";
|
||
|
char auth[] = "*CHANGE ";
|
||
|
char desc[] = "Description ..... ";
|
||
|
/********************************************************************/
|
||
|
/* Call the 'QUSCRTUI' program to create the user index. */
|
||
|
/********************************************************************/
|
||
|
QUSCRTUI(idx_name,ext_atr,entry_lgth_att,entry_lngth,key_insert,
|
||
|
key_lngth,imm_update,optim,auth,desc);
|
||
|
}</pre>
|
||
|
<p>To compile the program that creates the user index, specify
|
||
|
the following:</p>
|
||
|
<pre>CRTBNDC PGM(QGPL/$USIDXCRT) SRCFILE(QGPL/QCSRC)</pre>
|
||
|
<p>To
|
||
|
insert entries into the user index, use the following ILE C program:</p>
|
||
|
<pre>/********************************************************************/
|
||
|
/* PROGRAM: $USIDXEX */
|
||
|
/* */
|
||
|
/* LANGUAGE: ILE C */
|
||
|
/* */
|
||
|
/* DESCRIPTION: THIS PROGRAM USES A USER INDEX TO KEEP TRACK OF */
|
||
|
/* NAMES AND PHONE NUMBERS. THERE ARE TWO OPERATIONS THAT ARE */
|
||
|
/* DEMONSTRATED IN THIS EXAMPLE. THE FIRST IS THE INSERTION OF */
|
||
|
/* AN ENTRY INTO THE INDEX, AND SECONDLY THE FINDING OF A GIVEN */
|
||
|
/* INDEX ENTRY. */
|
||
|
/* THE INDEX IS KEYED ON THE LAST NAME, THEREFORE ENTER AS MUCH */
|
||
|
/* OF THE NAME AS YOU KNOW AND THE PROGRAM WILL LIST ALL ENTRIES */
|
||
|
/* MATCHING YOUR STRING (IN ALPHABETICAL ORDER). */
|
||
|
/* */
|
||
|
/* APIs USED: NONE */
|
||
|
/* */
|
||
|
/********************************************************************/
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <miindex.h>
|
||
|
#include <miptrnam.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <ctype.h>
|
||
|
|
||
|
_SYSPTR index;
|
||
|
_IIX_Opt_List_T ins_option_list;
|
||
|
_IIX_Opt_List_T *fnd_option_list;
|
||
|
char Name_And_Num[50];
|
||
|
char In_Name[50];
|
||
|
char Out_Num[5000];
|
||
|
char response[1];
|
||
|
char name[35];
|
||
|
char number[15];
|
||
|
int Ent_Found,count,start,length_of_entry;
|
||
|
|
||
|
|
||
|
/********************************************************************/
|
||
|
/* Procedure to copy 'cpylngth' elements of 'string2' into the */
|
||
|
/* new string, 'string1'; starting at position 'strpos'. */
|
||
|
/********************************************************************/
|
||
|
|
||
|
void strncpyn(string1,string2,strpos,cpylngth)
|
||
|
char string1[],string2[];
|
||
|
int strpos,cpylngth;
|
||
|
{
|
||
|
int x = 0;
|
||
|
while (x < cpylngth)
|
||
|
string1[x++]=string2[strpos++];
|
||
|
} /*strncpyn*/
|
||
|
|
||
|
|
||
|
/********************************************************************/
|
||
|
/* Procedure to convert any string into uppercase, where applicable */
|
||
|
/********************************************************************/
|
||
|
|
||
|
void convert_case(string1)
|
||
|
char string1[];
|
||
|
{
|
||
|
int x = 0;
|
||
|
while (x < (strlen(string1))) {
|
||
|
string1[x] = toupper(string1[x]);
|
||
|
x++;
|
||
|
} /*while*/
|
||
|
} /*convert_case*/
|
||
|
|
||
|
|
||
|
main()
|
||
|
{
|
||
|
fnd_option_list = malloc(sizeof(_IIX_Opt_List_T)
|
||
|
+99*sizeof(_IIX_Entry_T));
|
||
|
|
||
|
/********************************************************************/
|
||
|
/* Resolve to the index created in $USIDXCRT. */
|
||
|
/********************************************************************/
|
||
|
|
||
|
index = rslvsp(_Usridx,"TESTIDX","QGPL",_AUTH_ALL);
|
||
|
|
||
|
/********************************************************************/
|
||
|
/* Set up the insert option list */
|
||
|
/********************************************************************/
|
||
|
|
||
|
ins_option_list.Rule = _INSERT_REPLACE;
|
||
|
ins_option_list.Arg_Length = 50;
|
||
|
ins_option_list.Occ_Count = 1;
|
||
|
ins_option_list.Entry[0].Entry_Length = 50;
|
||
|
ins_option_list.Entry[0].Entry_Offset = 0;
|
||
|
|
||
|
/********************************************************************/
|
||
|
/* Set up the find option list */
|
||
|
/********************************************************************/
|
||
|
|
||
|
fnd_option_list->Rule = _FIND_EQUALS;
|
||
|
fnd_option_list->Occ_Count = 100;
|
||
|
|
||
|
/********************************************************************/
|
||
|
/* Loop until the choice 'Q' is entered at the menu */
|
||
|
/********************************************************************/
|
||
|
|
||
|
while (1==1) {
|
||
|
printf("\n\n***********************\n");
|
||
|
printf("* TELEPHONE INDEX *\n");
|
||
|
printf("***********************\n");
|
||
|
printf("* 'A' Add name & num *\n");
|
||
|
printf("* 'L' List a number *\n");
|
||
|
printf("* 'Q' Quit index *\n");
|
||
|
printf("***********************\n");
|
||
|
gets(response);
|
||
|
if ((strncmp(response,"A",1)==0)||(strncmp(response,"a",1)==0))
|
||
|
{ printf("\nEnter name to add. ex(Last, First)\n");
|
||
|
gets(name);
|
||
|
convert_case(name);
|
||
|
printf("\nEnter number to add. ex(999-9999)\n");
|
||
|
gets(number);
|
||
|
strcpy(name,strcat(name," "));
|
||
|
strcpy(Name_And_Num,strcat(name,number));
|
||
|
printf("\nName and number to add is => %s\n",Name_And_Num);
|
||
|
insinxen(index,Name_And_Num,Integrated Netfinity Server_option_list);
|
||
|
} /* if 'a'*/
|
||
|
if ((strncmp(response,"L",1)==0)||(strncmp(response,"l",1)==0))
|
||
|
{
|
||
|
printf("\nEnter name to find. ex(Last, First)\n");
|
||
|
gets(In_Name);
|
||
|
convert_case(In_Name);
|
||
|
fnd_option_list->Arg_Length = strlen(In_Name);
|
||
|
fndinxen(Out_Num,index,fnd_option_list,In_Name);
|
||
|
length_of_entry = fnd_option_list->Entry[0].Entry_Length;
|
||
|
Ent_Found = fnd_option_list->Ret_Count;
|
||
|
if (Ent_Found == 0)
|
||
|
printf("\nName not found in index => %s\n",In_Name);
|
||
|
else {
|
||
|
if (Ent_Found > 1) {
|
||
|
printf("\n%d occurences found,\n",Ent_Found);
|
||
|
count = 0;
|
||
|
start = 0;
|
||
|
while (count++ < Ent_Found) {
|
||
|
printf("Name and number is => %s\n",Out_Num);
|
||
|
start = start + length_of_entry;
|
||
|
strncpyn(Out_Num,Out_Num,start,length_of_entry);
|
||
|
} /* while */
|
||
|
}else
|
||
|
printf("\nName and number is => %s\n",Out_Num);
|
||
|
} /*else*/
|
||
|
} /*if 'l'*/
|
||
|
if ((strncmp(response,"Q",1)==0)||(strncmp(response,"q",1)==0))
|
||
|
{ break; }
|
||
|
} /*while*/
|
||
|
} /*$USIDXEX*/</pre>
|
||
|
<p>To create the ILE C program to insert entries into the user
|
||
|
index, specify the following:</p>
|
||
|
<pre>CRTBNDC PGM(QGPL/$USIDXEX) SRCFILE(QGPL/QCSRC)</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="apiexmp.htm" title="Contains example programs that use APIs and exit programs.">Examples: APIs</a></div>
|
||
|
</div>
|
||
|
<div class="relref"><strong>Related reference</strong><br />
|
||
|
<div><a href="apiexcreind.htm" title="This example shows how to create and manipulate a user index with a call from an MI program. For another example using the QUSCRTUI API, see Creating Your Own Telephone Directory.">Example: Creating and manipulating a user index</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|