home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / ASE / SAMPLE / ASESMP.C next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  175.5 KB  |  4,599 lines

  1. /*****************************************************************************
  2.     Name: asesmp.c                                   
  3.  
  4.     Description:    ASE API C sample application
  5.  
  6.     Author: Volodya Sirotinin
  7.             Autodesk, Inc.
  8.             Moscow, Russia.
  9.  
  10.    Copyright (C) 1992, 1993, 1994 by Autodesk, Inc.
  11.  
  12.    Permission to use, copy, modify, and distribute this software in 
  13.    object code form for any purpose and without fee is hereby granted, 
  14.    provided that the above copyright notice appears in all copies and 
  15.    that both that copyright notice and the limited warranty and 
  16.    restricted rights notice below appear in all supporting 
  17.    documentation.
  18.  
  19.    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  
  20.    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF 
  21.    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  22.    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE 
  23.    UNINTERRUPTED OR ERROR FREE.
  24.  
  25.    Use, duplication, or disclosure by the U.S. Government is subject to 
  26.    restrictions set forth in FAR 52.227-19 (Commercial Computer 
  27.    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  28.    (Rights in Technical Data and Computer Software), as applicable.
  29.  
  30.     Entry Points:
  31.  
  32.     Modification History:
  33.     June 15 1994 - volodyas - original written
  34.  
  35.     Bugs and restriction on use:
  36.  
  37.     Notes:
  38.  
  39. *****************************************************************************/
  40. #ifndef ASE_ASESMP_C
  41. #define ASE_ASESMP_C asesmpc
  42.  
  43. /****************************************************************************/
  44. /* INCLUDES */
  45. /****************************************************************************/
  46. #include <adslib.h>
  47. #include <string.h>
  48. #include <stdio.h>
  49. #include <asiappl.h>
  50. #include <ase.h>
  51. #include <malloc.h>
  52.  
  53. /****************************************************************************/
  54. /* TYPEDEFS */
  55. /****************************************************************************/
  56.  
  57. /****************************************************************************/
  58. /* DEFINES */
  59. /****************************************************************************/
  60. #define BUFLEN           128           /* The local buffer length */
  61. #define STMSIZE          BUFLEN*4      /* The SQL statement buffer size */
  62. #define DEFSTMSIZE BUFLEN              /* default size of statement */
  63. #define DEFSTMINC  BUFLEN              /* value for increment block size */
  64. #define MAXSTMSIZE (BUFLEN*64)         /* maximum statement size */
  65. #define FREE_TOKENBUF    ((void*)(-1)) /* Pointer value for ase_addtoken() */
  66.                                        /* free static buffer */
  67. #define NEW_TOKENBUF     NULL          /* Pointer value for ase_addtoken(),*/
  68.  
  69. /****************************************************************************/
  70. /* LOCAL FUNCTIONS */
  71. /****************************************************************************/
  72.  
  73. /* Command processing functions */
  74. static int asesmp_do() ;
  75. static int asesmp_lpn() ;
  76. static int asesmp_sel() ;
  77. static int asesmp_stat() ;
  78. static int asesmp_row() ;
  79. static int asesmp_link() ; 
  80. static int asesmp_err() ; 
  81.  
  82. /* Link Paths manipulation */
  83. static EAsiBoolean lp_view(ASE_LPDSC lp) ;
  84. static EAsiBoolean lp_erase(ASE_LPDSC lp) ;
  85. static EAsiBoolean lp_new(ASE_LPDSC lp) ;
  86. static EAsiBoolean lp_rename(ASE_LPDSC lp) ; 
  87. static char       *lp_getName(ASE_LPDSC lp, char *pPrompt) ;
  88. static ASE_LPDSC   lp_getDOR(char *pPrompt, 
  89.                              EAsiBoolean needConnect, 
  90.                              EAsiBoolean needAseConnect) ;
  91. static EAsiBoolean lp_getTabCols(ASE_LPDSC lp, 
  92.                               ASICOLDSC *pPack[], 
  93.                               int *pColQty) ;
  94. static EAsiBoolean lp_getRow(ASE_LPDSC lp,
  95.                              ASICOLDSC *pKey, int pKeyColQty,
  96.                              ASICOLDSC **pRow, int *pColQty) ;
  97. static void        lp_print(ASE_LPDSC lp) ;
  98. static void        lp_printPath(ASE_LPDSC lp) ;
  99. static void        lp_printStat(ASE_LPDSC lp) ;
  100.  
  101. /* Cursor manipulations */
  102. static EAsiBoolean csr_scroll(ASICURSOR csr, ASE_LPDSC lp) ;
  103. static EAsiBoolean csr_viewLinks(ASICURSOR csr, ASE_LPDSC lp) ;
  104. static EAsiBoolean csr_eraseLinks(ASICURSOR csr, ASE_LPDSC lp) ;
  105. static EAsiBoolean csr_makeLink(ASICURSOR csr, ASE_LPDSC lp) ;
  106. static EAsiBoolean csr_reloadDA(ASICURSOR csr, ASE_LPDSC lp) ;
  107. static EAsiBoolean csr_getVals(ASICURSOR csr, 
  108.                                ASICOLDSC *pVals[],
  109.                                int *pColQty) ;
  110. static ASE_LSDSC   csr_getLinks(ASICURSOR csr,
  111.                                 ASE_LPDSC lp) ;
  112. static void        csr_printRow(ASICURSOR csr) ;
  113.  
  114. /* Link Selection manipulation */
  115. static EAsiBoolean ls_scan(ASE_LSDSC ls) ;
  116. static ASE_LSDSC   ls_create() ;
  117. static EAsiBoolean ls_filter(ASE_LSDSC ls) ;
  118. static void        ls_print(ASE_LSDSC ls,
  119.                             ASE_LPDSC lp,
  120.                             ASICOLDSC KeyBuf[],
  121.                             int ColQty) ;
  122. static void        ls_printLp(ASE_LSDSC ls, 
  123.                               const char *pName,
  124.                               ASICOLDSC KeyBuf[],
  125.                               int ColQty) ;
  126. static void        ls_printStat(ASE_LSDSC ls, ASE_LPDSC lp) ;
  127. static void        ls_printTypeStat(ASE_LSDSC ls, 
  128.                                   ASE_LPDSC lp,
  129.                                   char *pName,
  130.                                   char *pXName,
  131.                                   EAseLinkType Type) ;
  132. static void        ls_printLPNsStat(ASE_LSDSC ls) ;
  133. static void        ls_printXsStat(ASE_LSDSC ls) ;
  134.  
  135. /* Link Manipulations */
  136. static EAsiBoolean link_edit(ASE_LINKDSC link, 
  137.                             ASE_LPDSC lp, 
  138.                             ASICOLDSC Key[], 
  139.                             int ColQty) ;
  140. static EAsiBoolean link_entMake(ASICURSOR csr, ASE_LPDSC lp) ;
  141. static EAsiBoolean link_daMake(ASICURSOR csr, ASE_LPDSC lp) ;
  142. static void        link_print(ASE_LINKDSC link, ASICOLDSC Key[], int ColQty) ;
  143.  
  144. /* Packet manipulations */
  145. static void        pack_print(ASICOLDSC Pack[], int ColQty) ;
  146. static void        pack_printCols(ASICOLDSC Pack[], int ColQty) ;
  147. static void        pack_printVals(ASICOLDSC Pack[], int ColQty) ;
  148. static EAsiBoolean pack_edit(ASICOLDSC Pack[], int ColQty) ;
  149. static EAsiBoolean pack_getCols(ASICOLDSC ColList[], int ColQty, 
  150.                                ASICOLDSC *pCols[], int *pColQty) ;
  151.  
  152. /* Sessions management */
  153. static EAsiBoolean connect(ASE_LPDSC lp) ;
  154. static EAsiBoolean connectAse(ASE_LPDSC lp) ;
  155. static ASISESSION  getSession() ;
  156. static EAsiBoolean isConnected(ASE_LPDSC lp) ;
  157. static void        disconnect() ;
  158.  
  159. /* Error printing */
  160. static void        printAseErr(ASE_DSC dsc) ;   
  161. static void        printAsiErr(ASIHANDLE handle) ;
  162.  
  163. /* Utilities */
  164. static EAsiBoolean testDsc(ASE_DSC dsc) ;
  165. static void        printColDsc(ASICOLDSC col) ;
  166. static void        printBufNames(const struct resbuf *pBuf) ;
  167. static void        pauseInput(const char* pPrompt) ;
  168. static int         callCmd(char *pCmdName, struct resbuf *pParms) ;
  169. static char       *addtoken(char *newtoken) ;
  170.  
  171. /* Initializing/terminating of APIs */
  172. static EAsiBoolean smpinit() ;
  173. static void        smpterm() ;
  174. static EAsiBoolean isInit() ;
  175.  
  176. /* ADS Utility functions */
  177. static int loadfunc () ;
  178. static int unloadfunc () ;
  179. static int execfunc () ;
  180.  
  181. typedef struct {
  182.     char *cmdname;
  183.     int (*cmdfunc)();
  184. } CMDADS;                              /* Typedef for command definition */
  185.  
  186. /****************************************************************************/
  187. /* GLOBAL VARIABLES */
  188. /****************************************************************************/
  189.  
  190. static CMDADS cmd[] =  {
  191.                        {"C:ASESMPDO",  asesmp_do},
  192.                        {"C:ASESMPLPN", asesmp_lpn},
  193.                        {"C:ASESMPSEL", asesmp_sel},
  194.                        {"C:ASESMPSTAT", asesmp_stat},
  195.                        {"C:ASESMPROW", asesmp_row},
  196.                        {"C:ASESMPLINK", asesmp_link},
  197.                        {"C:ASESMPERR", asesmp_err}
  198.                       };
  199.  
  200. ASE_APPLDSC AseAppl=ASE_DSC_NULL ;  /* The global ASE application desc */
  201. ASE_LPDSC   AseEnv=ASE_DSC_NULL ;   /* The global ENvironment reference desc */
  202. ASIENV      AsiAppl=0L ;            /* The global ASI application desc */
  203. ASISESSION  AsiSes=0L ;             /* The global ASI session desc */   
  204. /****************************************************************************/
  205. /* FUNCTIONS */
  206. /****************************************************************************/
  207.  
  208. /****************************************************************************/
  209. /*.doc asesmp_do (internal) */
  210. /*+
  211. ASESMPDO     - Database Object Reference statistic
  212.                This command demostrates how to get the
  213.                information by the given Database Object Reference.
  214. Command: ASESMPDO        
  215. -*/
  216. /****************************************************************************/
  217. static int 
  218. /*FCN*/asesmp_do() 
  219. {
  220.     ASE_LPDSC lp ;                     /* The DOR descriptor */
  221.     struct resbuf *pBuf ;              /* For subordinate DO paths */
  222.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  223.     do {
  224.           /* Check, whether appls were initialized */
  225.         if ( ! isInit() ) 
  226.             break ;
  227.           /* Get the Database Object Reference */
  228.         if ( (lp=lp_getDOR(NULL, kAsiFalse, kAsiTrue)) == ASE_DSC_NULL ) {
  229.             break ;
  230.         }
  231.           /* Test the DO */
  232.         if ( testDsc(lp) != kAsiGood ) {
  233.             break ;
  234.         }
  235.           /* Print the DO path attributes */
  236.         lp_printPath(lp) ;
  237.           /* Print the existing subordinate DO paths */
  238.           /* for Database Object reference */
  239.         if ( ase_lp_getPathCode(lp) != kAseTableCode &&
  240.              ase_lp_getPathCode(lp) != kAseLpnCode ) {
  241.             if ( (pBuf = ase_lp_getPaths(lp, 
  242.                        ASE_DO_EXIST|ASE_DO_UNKNOWN)) 
  243.                        != NULL ) {
  244.                 pauseInput("\nPress key for printing subordinate DOs") ;
  245.                 printBufNames(pBuf) ;
  246.                 ads_relrb(pBuf) ;
  247.             } else {
  248.                 ads_printf("\nNo subordinate existing DOs") ;
  249.                 printAseErr(lp) ;
  250.             }
  251.         }
  252.         pauseInput("\nPress any key for the related link information...") ;
  253.           /* Print the DO related information */
  254.         lp_printStat(lp) ;
  255.         retCode = kAsiGood ;
  256.     } while(0) ;
  257.     ase_dsc_free(&lp) ;
  258.     return retCode ;
  259. } /* end of asesmp_do() */
  260.  
  261. /****************************************************************************/
  262. /*.doc asesmp_lpn(internal) */
  263. /*+
  264. ASESMPLPN    - Creating, Erasing, Renaming of LPN(s)
  265.                This command  demonstrates how to create, erase, rename,
  266.                and get the structure of the LPN(s).
  267. Command: ASESMPLPN
  268. -*/
  269. /****************************************************************************/
  270. static int 
  271. /*FCN*/asesmp_lpn() 
  272. {
  273.     ASE_LPDSC lp=ASE_DSC_NULL ;        /* Link Path descriptor */
  274.     char buf[BUFLEN] ;               /* The buffer for entering */
  275.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  276.     int retword ;                      /* ads_getkword() returning value */
  277.  
  278.     do {
  279.           /* Check, whether appls were initialized */
  280.         if ( ! isInit() ) 
  281.             break ;
  282.           /* Ask for the DO entering */
  283.         if ( (lp=lp_getDOR(NULL, kAsiFalse, kAsiFalse)) == ASE_DSC_NULL ) {
  284.             break ;
  285.         }
  286.               /* Loop for the asking LPN options */
  287.         do {
  288.               /* Erase/Rename/Create/View/<eXit> */
  289.             if ( ads_initget(0, "E R C V X") != RTNORM ) {
  290.                 break ;
  291.             }
  292.             retword=ads_getkword(
  293.                        "\nErase/Rename/Create/View/<eXit>:", 
  294.                        buf);
  295.  
  296.             if ( retword != RTNORM && retword != RTNONE ) {
  297.                 break ;
  298.             }
  299.             if ( retword == RTNONE || buf[0] == '\0' || buf[0] == 'X' ) {
  300.                 retCode = kAsiGood ;
  301.                 break ;
  302.             }
  303.             switch(buf[0]) {
  304.             case 'E':                  /* ERASE */ 
  305.                 retCode = lp_erase(lp) ;
  306.                 break ;
  307.             case 'R':                  /* RENAME */
  308.                 retCode = lp_rename(lp) ;
  309.                 break ;
  310.             case 'C':                  /* CREATE */
  311.                 retCode = lp_new(lp) ;
  312.                 break ;
  313.             case 'V':                  /* VIEW */
  314.                 retCode = lp_view(lp) ;
  315.                 break ;
  316.             }
  317.         } while(0) ;
  318.     } while(0) ;
  319.     ase_dsc_free(&lp) ;
  320.     return retCode ;
  321. } /* end of asesmp_lpn() */
  322.  
  323. /****************************************************************************/
  324. /*.doc asesmp_stat(internal) */
  325. /*+
  326. ASESMPSTAT   - Links Statistic
  327.                This command demonstrates how to get the link information
  328.                for the selected drawing objects.
  329. Command: ASESMPSTAT
  330.   per each Xref/Block
  331. -*/
  332. /****************************************************************************/
  333. static int 
  334. /*FCN*/asesmp_stat() 
  335. {
  336.     ASE_LSDSC ls=ASE_DSC_NULL ;   /* Link selection desc */
  337.     ads_name ssname ;                  /* Entity selection set name */
  338.     ASE_LPDSC lp=ASE_DSC_NULL ;     /* The DOR descriptor */
  339.     long slen ;                     /* Selection set length */
  340.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  341.  
  342.     do {
  343.           /* Check, whether appls were initialized */
  344.         if ( ! isInit() ) 
  345.             break ;
  346.           /* Allocate the Link Selection Descriptor */
  347.         if ( (ls=ase_dsc_alloc(AseAppl, kAseApiLinkSel)) == ASE_DSC_NULL ) {
  348.             ads_abort("\nCan't allocate Link Selection descriptor") ;
  349.             break ;
  350.         }
  351.           /* Ask for the entities selection */
  352.           /* Check the selection length */
  353.         if ( ads_ssget(NULL, NULL, NULL, NULL, ssname) != RTNORM ||
  354.              ads_sslength(ssname, &slen) != RTNORM ||
  355.              slen <= 0L ) {
  356.             ads_printf("\nWrong entity selection") ;
  357.             break ;
  358.         }
  359.           /* Init the link selection by the selected entities */
  360.         if ( ase_ls_initSel(ls, ssname) != kAsiGood ) {
  361.             if ( ase_dsc_errDsc(ls, 0) != eAseEDscApi ||
  362.                  ase_dsc_errCode(ls, 0) != eAseApiErrSelEmpty ) {
  363.                 ads_printf("\nLink Selection creating problem") ;
  364.                 printAseErr(ls) ;
  365.             } else {
  366.                   /* No related links */
  367.                 ads_printf("\nNo Links are specified") ;
  368.                 retCode = kAsiGood ;
  369.             }
  370.             break ;
  371.         }
  372.           /* Test the Link Selection */
  373.         if ( testDsc(ls) != kAsiGood ) {
  374.             break ;
  375.         }
  376.           /* Get the Database Object Reference */
  377.         if ( (lp=lp_getDOR(
  378.         "\nEnter the registered DOR or <.> for empty one:", 
  379.              kAsiFalse,
  380.              kAsiFalse)) == ASE_DSC_NULL ) {
  381.             break ;
  382.         }
  383.           /* Test, whether the Database Object Reference is registered */
  384.         if ( ! (ase_lp_getStatus(lp) & ASE_DO_REG) ) {
  385.             ads_printf("\nThe DOR isn't registered") ;
  386.             printAseErr(lp) ;
  387.             break ;
  388.         }
  389.           /* Print Link Selection statistic */
  390.         ls_printStat(ls, lp) ;
  391.         retCode = kAsiGood ;
  392.     } while(0) ;
  393.     ase_dsc_free(&ls) ;
  394.     ase_dsc_free(&lp) ;
  395.     return retCode ;
  396. } /* end of asesmp_stat() */
  397.  
  398. /****************************************************************************/
  399. /*.doc asesmp_sel(internal) */
  400. /*+
  401. ASESMPSEL    - Links Selection manipulations
  402.                This command demonstrates how to manipulate with the
  403.                Link Selections.
  404. Command: ASESMPSEL
  405. -*/
  406. /****************************************************************************/
  407. static int 
  408. /*FCN*/asesmp_sel() 
  409. {
  410.     ASE_LSDSC lsCurrent=ASE_DSC_NULL ;   /* The current Link Selection */
  411.     ASE_LSDSC lsNew=ASE_DSC_NULL ;       /* The second Link Selection */
  412.     char buf[BUFLEN] ;               /* The buffer for entering */
  413.     int retword ;                      /* ads_getkword() returning value */
  414.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  415.  
  416.     do {
  417.           /* Check, whether appls were initialized */
  418.         if ( ! isInit() ) 
  419.             break ;
  420.           /* Create the current link selection */
  421.         if ( (lsCurrent=ls_create()) == ASE_DSC_NULL ) {
  422.             break ;
  423.         }
  424.           /* Loop for Link Selection processing */
  425.         do {
  426.               /* Print the links quantity in current selection */
  427.             ads_printf("\nSelected links #%ld", ase_ls_getQty(lsCurrent)) ;
  428.               /* Print/Unite/Intersect/Subtract/Filter/<eXit> */
  429.             if ( ads_initget(0, "P U I S F X") != RTNORM ) {
  430.                 break ;
  431.             }
  432.               /* Ask for the entering */
  433.             retword=ads_getkword(
  434.                       "\nPrint/Unite/Intersect/Subtract/Filter/<eXit>:",
  435.                       buf);
  436.             if ( retword != RTNORM && retword != RTNONE ) {
  437.                 break ;
  438.             }
  439.             retCode = kAsiGood ;
  440.             if ( retword == RTNONE || buf[0] == '\0' || buf[0] == 'X' ) {
  441.                 break ;
  442.             }
  443.             switch(buf[0]) {
  444.             case 'P':                  /* PRINT */
  445.                 ls_print(lsCurrent, 
  446.                              ASE_DSC_NULL,
  447.                              (ASICOLDSC*)NULL, 
  448.                              0) ;
  449.                 break ;
  450.             case 'U':                  /* UNITE */ 
  451.                   /* Ask for the new Link Selection */
  452.                 if ( (lsNew=ls_create()) == ASE_DSC_NULL ) {
  453.                     break ;
  454.                 }
  455.                   /* Unite the link selections */
  456.                 retCode = ase_ls_unite(lsCurrent, lsNew) ;
  457.                 break ;
  458.             case 'I':                  /* INTERSECT */
  459.                   /* Ask for the new Link Selection */
  460.                 if ( (lsNew=ls_create()) == ASE_DSC_NULL ) {
  461.                     break ;
  462.                 }
  463.                   /* Intersect the link selections */
  464.                 retCode = ase_ls_intersect(lsCurrent, lsNew) ;
  465.                 break ;
  466.             case 'S':                  /* SUBTRACT */
  467.                   /* Ask for the new Link Selection */
  468.                 if ( (lsNew=ls_create()) == ASE_DSC_NULL ) {
  469.                     break ;
  470.                 }
  471.                   /* Subtract the link selections */
  472.                 retCode = ase_ls_subtract(lsCurrent, lsNew) ;
  473.                 break ;
  474.             case 'F':                  /* FILTER */
  475.                 retCode = ls_filter(lsCurrent) ;
  476.                 break ;
  477.             }
  478.               /* Free the Link Selection */
  479.             ase_dsc_free(&lsNew) ;
  480.             if ( retCode != kAsiGood ) {
  481.                 break ;
  482.             }
  483.         } while(1) ;
  484.     } while(0) ;
  485.     ase_dsc_free(&lsCurrent) ;
  486.     return retCode ;
  487. } /* end of asesmp_sel() */
  488.  
  489. /****************************************************************************/
  490. /*.doc asesmp_row(internal) */
  491. /*+
  492. ASESMPROW    - This command demonstrates how to get, create and view links
  493.                for the given table row.
  494. Command: ASESMPROW
  495. -*/
  496. /****************************************************************************/
  497. static int 
  498. /*FCN*/asesmp_row() 
  499. {
  500.     ASE_LPDSC lp=ASE_DSC_NULL ;     /* The DOR descriptor */
  501.     ASICURSOR csr=0L ;              /* The cursor descriptor */
  502.     ASISTATEMENT stm=0L ;           /* The statement desc */
  503.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  504.     char stmstrbuf[STMSIZE] ;      /* The buffer length */
  505.     char buf[BUFLEN] ;            /* The buffer */
  506.  
  507.     do {
  508.           /* Check, whether appls were initialized */
  509.         if ( ! isInit() ) 
  510.             break ;
  511.           /* Get the Database Object Reference */
  512.         if ( (lp=lp_getDOR("\nEnter the Table Reference:",
  513.                         kAsiTrue,
  514.                         kAsiFalse)) == ASE_DSC_NULL ) {
  515.             break ;
  516.         }
  517.           /* Test, whether it is the Table Reference */
  518.         if ( ase_lp_getPathCode(lp) != kAseTableCode &&
  519.              ase_lp_getPathCode(lp) != kAseLpnCode ) {
  520.             ads_printf("\nNot the Table Reference was entered") ;
  521.             printAseErr(lp) ;
  522.             break ;
  523.         }
  524.           /* Create statement descriptor */
  525.         if ( asi_constr_stm (&stm) != kAsiGood ) {
  526.             ads_printf("\nCan't construct ASI statement") ;
  527.         }
  528.           /* Get the SQL path to the table */
  529.         if ( ase_lp_getName(lp, buf, BUFLEN, kAseSQLCode) != kAsiGood ) {
  530.             ads_printf("\nCan't get the SQL table name") ;
  531.             printAseErr(lp) ;
  532.             break ;
  533.         }
  534.           /* Get the statement string */
  535.         sprintf(stmstrbuf, "SELECT * FROM %s", buf) ;
  536.           /* Prepare the statement */
  537.         if ( asi_prepare (stm, 
  538.                           getSession(),  
  539.                           stmstrbuf) != kAsiGood ) {
  540.             ads_printf("\nCan't prepare the statement \n[%s]", stmstrbuf) ;
  541.             printAsiErr(stm) ;
  542.             break ;
  543.         }
  544.         if ( asi_constr_csr(&csr) != kAsiGood ) {
  545.             ads_printf("\nCan't construct the cursor") ;
  546.             printAsiErr(csr) ;
  547.             break ;
  548.         }
  549.         if ( asi_alloc_csr(csr, stm, "XXX", 
  550.                            kAsiScroll, kAsiSnsUndef) != kAsiGood ) {
  551.             ads_printf("\nCan't allocate the cursor") ;
  552.             printAsiErr(csr) ;
  553.             break ;
  554.         }                   
  555.         if ( asi_open(csr) != kAsiGood ) {
  556.             ads_printf("\nCan't open the cursor") ;
  557.             printAsiErr(csr) ;
  558.             break ;
  559.         }   
  560.         if ( csr_scroll(csr, lp) == kAsiGood ) {
  561.             retCode = kAsiGood ;
  562.         }
  563.     } while(0) ;
  564.     if ( csr != 0L ) {
  565.           /* Close the cursor */
  566.         asi_close(csr) ;
  567.           /* Destroy the cursir descriptor */
  568.         asi_destroy_csr(&csr) ;
  569.     }
  570.     if ( stm != 0L ) {
  571.           /* Deallocate the statement desc */
  572.         asi_dealloc_stm (stm);
  573.           /* Free the statement dsc */
  574.         asi_destroy_stm(&stm) ;
  575.     }
  576.     return retCode ;
  577. } /* end of asesmp_row() */
  578.  
  579. /****************************************************************************/
  580. /*.doc asesmp_link(internal) */
  581. /*+
  582. ASESMPLINK   - This command demonstrates how to manipulate with the
  583.                links.
  584. Command:ASESMPLINK
  585. -*/
  586. /****************************************************************************/
  587. static int 
  588. /*FCN*/asesmp_link() 
  589. {
  590.     ASE_LPDSC lp=ASE_DSC_NULL ;        /* The Link Path descriptor */
  591.     ASE_LSDSC ls=ASE_DSC_NULL ;        /* The Link Selection descriptor */
  592.     ads_name ename ;                   /* The entity name */
  593.     ads_point pt ;                         /* the point */
  594.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  595.     do {
  596.           /* Check, whether appls were initialized */
  597.         if ( ! isInit() ) 
  598.             break ;
  599.           /* Get the DOR */
  600.         if ( (lp=lp_getDOR(NULL, kAsiFalse, kAsiFalse)) == ASE_DSC_NULL ) {
  601.             break ;
  602.         }
  603.           /* Check, whether it is registered */
  604.         if ( !(ase_lp_getStatus(lp) & ASE_DO_REG) ) {
  605.               /* The DO isn't registsred */
  606.             ads_printf("\nDOR isn't registered") ;
  607.             break ;
  608.         }
  609.         /* Ask for the entity name */
  610.         if ( ads_entsel("\nSelect object:", ename, pt) != RTNORM ) {
  611.             ads_printf("\nWrong entity name input") ;
  612.             break ;
  613.         }
  614.         /* Allocate the Link Sel */
  615.         if ( (ls=ase_dsc_alloc(AseAppl, kAseApiLinkSel)) == ASE_DSC_NULL ) {
  616.             ads_abort("\nCan't allocate the Link Selection descriptor") ;
  617.             break ;
  618.         }
  619.           /* Create the link selection for the Entity */
  620.         if ( ase_ls_initEnt(ls, ename) != kAsiGood ) {
  621.             if ( ase_dsc_errDsc(ls, 0) != eAseEDscApi ||
  622.                  ase_dsc_errCode(ls, 0) != eAseApiErrSelEmpty ) {
  623.                 ads_printf("\nLink Selection creating problem") ;
  624.                 printAseErr(ls) ;
  625.             } else {
  626.                   /* No related links */
  627.                 ads_printf("\nNo Links are specified") ;
  628.                 retCode = kAsiGood ;
  629.             }
  630.             break ;
  631.         }
  632.           /* Check the Link Selection length */
  633.         if ( ase_ls_getQty(ls) == 0L ) {
  634.             ads_printf("\nWrong Link Selection") ;
  635.             printAseErr(ls) ;
  636.             break ;
  637.         }
  638.           /* Filter the links to the specified DOR */
  639.         if ( ase_ls_intersectLpDsc(ls, lp) != kAsiGood ) {
  640.             ads_printf("\nLink Selection intersecting problem") ;
  641.             printAseErr(ls) ;
  642.             break ;
  643.         }
  644.           /* Check the resulting Link Selection length */
  645.         if ( ase_ls_getQty(ls) == 0L ) {
  646.             ads_printf("\nNo Links to the specified DOR") ;
  647.             break ;
  648.         }
  649.           /* Process the links */
  650.         retCode = ls_scan(ls) ;
  651.     } while(0) ;
  652.     ase_dsc_free(&ls) ;
  653.     ase_dsc_free(&lp) ;
  654.     return retCode ;
  655. } /* end of asesmp_link() */
  656.  
  657. /****************************************************************************/
  658. /*.doc asesmp_err(internal) */
  659. /*+
  660. ASESMPERR    - Global Error          
  661.                This command prints the last ASE global error data.
  662. Command:ASESMPERR
  663. -*/
  664. /****************************************************************************/
  665. static int 
  666. /*FCN*/asesmp_err() 
  667. {
  668.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  669.     do {
  670.           /* Check, whether appls were initialized */
  671.         if ( ! isInit() ) 
  672.             break ;
  673.         if ( ase_appl_getAseErr(AseAppl) != kAsiGood ) {
  674.             ads_printf("\nCan't get the global ASE error") ;      
  675.         } else {
  676.             ads_printf("\nThe Global ASE error data are:") ;
  677.             retCode = kAsiGood ;
  678.         }
  679.         printAseErr(AseAppl) ;
  680.     } while(0) ;
  681.     return retCode ;
  682. } /* end of asesmp_err() */
  683.  
  684. /****************************************************************************/
  685. /*.doc lp_view(internal) */
  686. /*+
  687.   This function prints the structure of the Link Path Key for the
  688.   Table Reference. 
  689. -*/
  690. /****************************************************************************/
  691. static EAsiBoolean
  692. /*FCN*/lp_view(ASE_LPDSC lp) 
  693. {
  694.     char *pLPN=NULL ;                  /* LPN buffer */
  695.     EAsiBoolean retCode=kAsiBad ;      /* The returning code */
  696.  
  697.     do {
  698.           /* Get the LPN */
  699.         if ( (pLPN=lp_getName(lp, "\nEnter existing LPN or <?> LPNs list:")) == NULL ) {
  700.             break ;
  701.         }
  702.           /* Check it */
  703.         if ( ase_lp_initName(lp, pLPN) != kAsiGood ) {
  704.             ads_printf("\nWrong LPN was entered") ;
  705.             printAseErr(lp) ;
  706.             break ;
  707.         }
  708.           /* Print the Key Description */
  709.         lp_print(lp) ;
  710.         retCode = kAsiGood ;
  711.     } while(0) ;
  712.     if ( pLPN != NULL ) {
  713.         free (pLPN) ;
  714.     }
  715.     return retCode ;
  716. } /* end of lp_view() */
  717.  
  718. /****************************************************************************/
  719. /*.doc lp_erase(internal) */
  720. /*+
  721.   This function erases all of the Link Paths related with the
  722.   Database Object Reference
  723. -*/
  724. /****************************************************************************/
  725. static EAsiBoolean
  726. /*FCN*/lp_erase(ASE_LPDSC lp) 
  727. {
  728.     EAsiBoolean retCode =kAsiBad ;    /* The returning code */
  729.     do {
  730.           /* Test, whether it is registered */
  731.         if ( ! (ase_lp_getStatus(lp) & ASE_DO_REG) ) {
  732.             ads_printf("\nThe DOR isn't registered") ;
  733.             printAseErr(lp) ;
  734.             break ;
  735.         }
  736.           /* Test, whether DOR's links are updatable */
  737.         if ( ase_lp_isUpdatable(lp) != kAsiTrue ) {
  738.             ads_printf("\nThe related link information can't be updatable") ;
  739.             printAseErr(lp) ;
  740.             break ;
  741.         }
  742.           /* Do erase of the Link Path registration */
  743.           /* and all the related links */
  744.         if ( ase_lp_erase(lp)  != kAsiGood ) {
  745.             ads_printf("\nCan't erase the related link information") ;
  746.             printAseErr(lp) ;
  747.         }
  748.         retCode = kAsiGood ;
  749.     } while(0) ;
  750.     return retCode ;
  751. } /* end of lp_erase() */
  752.  
  753. /****************************************************************************/
  754. /*.doc lp_new(internal) */
  755. /*+
  756.   This function creates the new Link Path Name.
  757. -*/
  758. /****************************************************************************/
  759. static EAsiBoolean
  760. /*FCN*/lp_new(ASE_LPDSC lp) 
  761. {
  762.     ASICOLDSC *pTabCols=NULL ;          /* The Table Column Descriptors */
  763.     ASICOLDSC *pKey=NULL ;              /* The Key Column Descriptors */
  764.     char *pLPN=NULL ;                   /* new LPN buffer */
  765.     int TabColQty=0 ;                   /* The table column quantity */
  766.     int ColQty=0 ;                      /* The key column quantity */
  767.     EAsiBoolean retCode=kAsiBad ;       /* The returning code */
  768.  
  769.     do {
  770.           /* Check whether or not Env is connected */
  771.           /* and connect in application */
  772.         if ( connect(lp) != kAsiGood ||
  773.              isConnected(lp) != kAsiTrue ) {
  774.             break ;
  775.         }
  776.           /* Ask for the new LPN */
  777.         if ( (pLPN=lp_getName(lp, "\nEnter the new LPN:")) == NULL ) {
  778.             break ;
  779.         }
  780.           /* Set the new LPN */
  781.         if ( ase_lp_setName(lp, pLPN, kAseLpnCode) != kAsiGood ) {
  782.             ads_printf("\nWrong LPN was entered") ;
  783.             printAseErr(lp) ;
  784.             break ;
  785.         }
  786.           /* Get the column description */
  787.         if ( lp_getTabCols(lp, &pTabCols, &TabColQty) != kAsiGood ) {
  788.            break ;
  789.         }
  790.           /* Ask for the key columns desc */
  791.         if ( pack_getCols(pTabCols, TabColQty, &pKey, &ColQty) != kAsiGood ) {
  792.             ads_printf("\nNo Key Columns") ;
  793.             break ;
  794.         }
  795.           /* Do the LPN creating */
  796.         if ( ase_lp_create(lp, pKey, ColQty) != kAsiGood ) {
  797.             ads_printf("\nCan't create LPN") ;
  798.             printAseErr(lp) ;
  799.             break ;
  800.         }
  801.           /* Make that LPN as the current for ASE */
  802.         if ( ase_lp_setCurrent(lp) != kAsiGood ) {
  803.             ads_printf("\nCan't set the LPN as the current for ASE") ;
  804.             printAseErr(lp) ;
  805.         }
  806.         retCode = kAsiGood ;
  807.     } while(0) ;
  808.       /* Free the allocated column descriptors */
  809.     asei_destroy_cdscpack(&pKey, ColQty) ;
  810.       /* Free the allocated column descriptors */
  811.     asei_destroy_cdscpack(&pTabCols, TabColQty) ;
  812.     if ( pLPN != NULL ) {
  813.         free (pLPN) ;
  814.     }
  815.     return retCode ;
  816. } /* end of lp_new() */
  817.  
  818. /****************************************************************************/
  819. /*.doc lp_rename(internal) */
  820. /*+
  821.   This function renames the Link Path in accordance with the
  822.   LPN that is asked.
  823. -*/
  824. /****************************************************************************/
  825. static EAsiBoolean
  826. /*FCN*/lp_rename(ASE_LPDSC lp) 
  827. {
  828.     char *pLPN=NULL ;                  /* LPN buffer */
  829.     char buf[BUFLEN] ;                 /* The buffer for existing LPN */
  830.     EAsiBoolean retCode=kAsiBad ;      /* The returning code */
  831.  
  832.     do {
  833.           /* Check the LPN existance */
  834.         if ( ase_lp_getPathCode(lp) != kAseLpnCode ||
  835.              ase_lp_getName(lp, buf, BUFLEN, kAseLpnCode) != kAsiGood ) {
  836.             ads_printf("\nLPN isn't set") ;
  837.             break ;
  838.         }
  839.           /* Print the existing LPN */
  840.         ads_printf("\nOld LPN: %s", buf) ;
  841.           /* Ask for the new LPN */
  842.         if ( (pLPN=lp_getName(lp,"\nEnter the new LPN:")) == NULL ) {
  843.             break ;
  844.         }
  845.           /* Do rename of the Link Path and */
  846.           /* all the related links */
  847.         if ( ase_lp_rename(lp, pLPN) != kAsiGood ) {
  848.             ads_printf("\nCan't rename the LPN") ;
  849.             printAseErr(lp) ;
  850.         }
  851.         retCode = kAsiGood ;
  852.     } while(0) ;
  853.     if ( pLPN != NULL ) {
  854.         free (pLPN) ;
  855.     }
  856.     return retCode ;
  857. } /* end of lp_rename() */
  858.  
  859. /****************************************************************************/
  860. /*.doc lp_getName(internal) */
  861. /*+
  862.   This function asks for the LPN entering.
  863.   The entering of <?> causes the printing of the list with the
  864.   all existing LPNs, related with the specified Database Object Reference.
  865.   If the lp == ASE_DSC_NULL, then all the existing LPNs
  866.   are printed.
  867.   Prints the default prompt if pPrompt is NULL.
  868.   Returns the pointer to the allocated LPN in success, 
  869.   NULL otherwise. The space allocated by retruning pointer should
  870.   be released with the aid of free() function.
  871. -*/
  872. /****************************************************************************/
  873. static char*
  874. /*FCN*/lp_getName(ASE_LPDSC lp, char *pPrompt) 
  875. {
  876.     ASE_LPDSC lpbuf=ASE_DSC_NULL ;     /* The DOR descriptor */
  877.     struct resbuf *pBuf ;              /* LPNs list pointer */ 
  878.     char buf[BUFLEN] ;               /* The buffer for LPN entering */
  879.     char *pRetPtr=NULL ;               /* The returning LPN name buffer */
  880.  
  881.  
  882.     if ( pPrompt == NULL ) {
  883.         pPrompt = "\nEnter LPN or <?> for LPNs list:" ;
  884.     }
  885.     do {
  886.         if ( lp == ASE_DSC_NULL ) {
  887.               /* Allocate the descriptor */
  888.             if ( (lpbuf=ase_dsc_alloc(AseAppl, kAseApiLinkPath)) == ASE_DSC_NULL ) {
  889.                 ads_abort("\nCan't allocate Link Path descriptor") ;
  890.                 break ;
  891.             }
  892.         } else {
  893.             lpbuf = ase_dsc_clone(lp) ;
  894.         }
  895.         do {
  896.               /* Ask for the LPN entering */
  897.             if ( ads_getstring(0, pPrompt, buf) != RTNORM ) {
  898.                 ads_printf("\nNo input") ;
  899.                 break ;
  900.             }
  901.             if ( buf[0] == '?' ) {
  902.                   /* Fast check, wheter at least one LPN exist */
  903.                 if ( ! (ase_lp_getStatus(lpbuf) & ASE_DO_REG) ) {
  904.                     ads_printf("\nNo Link Information exist in drawing") ;
  905.                     printAseErr(lpbuf) ;
  906.                     continue ;
  907.                 }
  908.                   /* Print the list of the LPNs,  */
  909.                   /* related with the Databaser Object Reference */
  910.                 if ( (pBuf=ase_lp_getLinkNames(lpbuf)) == NULL ) {
  911.                     ads_printf("\nNo LPNs are available") ;
  912.                     printAseErr(lpbuf) ;
  913.                     continue ;
  914.                 } else {
  915.                     printBufNames(pBuf) ;
  916.                     ads_relrb(pBuf) ;
  917.                 }
  918.                 continue ;
  919.             } else {
  920.                 if ( (pRetPtr=(char*)calloc(1, strlen(buf)+1)) == NULL ) {
  921.                     ads_abort("\nNo Memory") ;
  922.                     break ;
  923.                 }
  924.                 strcpy(pRetPtr, buf) ;
  925.                 break ;
  926.             }
  927.         } while (1) ;
  928.     } while(0) ;
  929.     ase_dsc_free(&lpbuf) ;
  930.     return pRetPtr ;
  931. } /* end of lp_getName() */
  932.  
  933. /****************************************************************************/
  934. /*.doc lp_getDOR(internal) */
  935. /*+
  936.   This function prints the current setting and asks for 
  937.   accepting of it or for the entering an another one.
  938.   Prints the default prompt if pPrompt is NULL.
  939.   Connects to the specified Environment if the
  940.   needConnect argument equals to kAsiTrue.
  941.   Connects ASE to the specified environment is the
  942.   needAseConnect equals to kAsiTrue.
  943.   Returns the descriptor of the resulting link path.
  944. -*/
  945. /****************************************************************************/
  946. static ASE_LPDSC   
  947. /*FCN*/lp_getDOR(char *pPrompt, 
  948.               EAsiBoolean needConnect, 
  949.               EAsiBoolean needAseConnect) 
  950. {
  951.     ASE_LPDSC lp=ASE_DSC_NULL ;       /* The DOR descriptor */
  952.     char buf[BUFLEN] ;              /* The buffer for DO path */
  953.     EAsiBoolean retCode=kAsiBad ;     /* The exit condition code */ 
  954.  
  955.     if ( pPrompt == NULL ) {
  956.         pPrompt = "\nEnter DOR or <.> for empty one:" ;
  957.     }
  958.     do {
  959.           /* Allocate the descriptor */
  960.         if ( (lp=ase_dsc_alloc(AseAppl, kAseApiLinkPath)) == ASE_DSC_NULL ) {
  961.             ads_abort("\nCan't allocate Link Path descriptor") ;
  962.             break ;
  963.         }
  964.           /* Get the current settings */
  965.         if ( ase_lp_initCurrent(lp) != kAsiGood ) {
  966.             ads_printf("\nCan't get the current ASE settings") ;
  967.             printAseErr(lp) ;
  968.             break ;
  969.         } else {
  970.             ase_lp_getName(lp, buf, BUFLEN, kAsePathCode) ;
  971.               /* Print the current settings */
  972.             ads_printf("\nCurrent Settings [%s]", buf) ;
  973.         }
  974.           /* Ask for the DO path entering */
  975.         if ( ads_getstring(0, pPrompt, buf) != RTNORM ) {
  976.             ads_printf("\nNo input") ;
  977.             ase_dsc_free(&lp) ;
  978.             break ;
  979.         }
  980.         if ( buf[0] != '\0' ) {
  981.               /* Correct an empty path */
  982.             if ( buf[0] == '.' ) {
  983.                 buf[0] = '\0' ;
  984.             }
  985.               /* Compare with the current settings */
  986.               /* to still use the already initialized */
  987.               /* Link Path descriptor */
  988.             if ( ! ase_lp_cmpName(lp, buf, kAsePathCode) ) {
  989.                   /* Initialize the descriptor */
  990.                 if ( ase_lp_initPath(lp, buf) != kAsiGood ) {
  991.                     ads_printf("\nThe wrong DOR was entered") ;
  992.                     printAseErr(lp) ;
  993.                     break ;
  994.                 }
  995.             }
  996.         }
  997.           /* Connect application to the Environment */
  998.         if ( needConnect == kAsiTrue ) {
  999.             if ( connect(lp) != kAsiGood ) {
  1000.                 break ;
  1001.             }
  1002.         }
  1003.           /* Connect ASE to the Environment */
  1004.         if ( needAseConnect == kAsiTrue ) {
  1005.             if ( connectAse(lp) != kAsiGood ) {
  1006.                 break ;
  1007.             }
  1008.         }
  1009.           /* Make the Database Object Reference as the current for ASE */
  1010.         if ( ase_lp_setCurrent(lp) != kAsiGood ) {
  1011.             ads_printf("\nCan't set the DOR as the current for ASE") ;
  1012.             printAseErr(lp) ;
  1013.         }
  1014.         retCode = kAsiGood ;
  1015.     } while(0) ;
  1016.     if ( retCode != kAsiGood ) {
  1017.         ase_dsc_free(&lp) ;
  1018.     }
  1019.     return lp ;
  1020. } /* end of lp_getDOR() */
  1021.  
  1022. /****************************************************************************/
  1023. /*.doc lp_getTabCols(internal) */
  1024. /*+
  1025.   Gets the description of the table columns
  1026.   Returns kAsiBad if something is wrong.
  1027. -*/
  1028. /****************************************************************************/
  1029. static EAsiBoolean 
  1030. /*FCN*/lp_getTabCols(ASE_LPDSC lp, 
  1031.                      ASICOLDSC *pPack[], 
  1032.                      int *pColQty) 
  1033. {
  1034.     ASISTATEMENT stm=0L ;            /* The statement desc */
  1035.     ASICOLDSC col;                   /* column description */
  1036.     int colcount ;                   /* The table columns quatity */
  1037.     int index ;                      /* The scanning index */
  1038.     char buf[BUFLEN] ;               /* The general buffer */
  1039.     char stmstrbuf[STMSIZE] ;         /* char stm str buffer */
  1040.     EAsiBoolean retCode=kAsiBad ;    /* The returning code */
  1041.  
  1042.     do {
  1043.           /* Test, whether it is the Table Reference */
  1044.         if ( ase_lp_getPathCode(lp) != kAseTableCode &&
  1045.              ase_lp_getPathCode(lp) != kAseLpnCode ) {
  1046.             ads_printf("\nNot the Table Reference was entered") ;
  1047.             printAseErr(lp) ;
  1048.             break ;
  1049.         }
  1050.           /* Create statement descriptor */
  1051.         asi_constr_stm (&stm);
  1052.           /* Get the SQL path to the table */
  1053.         if ( ase_lp_getName(lp, buf, BUFLEN, kAseSQLCode) != kAsiGood ) {
  1054.             ads_printf("\nCan't get the SQL table name") ;
  1055.             break ;
  1056.         }
  1057.           /* Get the statement string */
  1058.         sprintf(stmstrbuf, "SELECT * FROM %s", buf) ;
  1059.           /* Prepare the statement */
  1060.         if ( asi_prepare (stm, 
  1061.                           getSession(),  
  1062.                           stmstrbuf) != kAsiGood ) {
  1063.             ads_printf("\nCan't prepare the statement \n[%s]", stmstrbuf) ;
  1064.             break ;
  1065.         }
  1066.           /* Ask for the columns quantity */
  1067.         colcount = asi_colcount(stm) ;
  1068.           /* Allocate the packet */
  1069.         if ( (*pPack=asei_constr_cdscpack(colcount)) == (ASICOLDSC*)NULL ) {
  1070.             ads_abort("\nCan't allocate the columns packet") ;
  1071.             break ;
  1072.         }
  1073.           /* Fill it with the column descrption */
  1074.         for ( index = 0, *pColQty = 0 ; 
  1075.               index < colcount ; 
  1076.               ++index, ++*pColQty ) {
  1077.             if ( asi_cds(stm, index, &col) != kAsiGood ) {
  1078.                 ads_printf("\nCan't get the column description") ;
  1079.                 break ;
  1080.             }
  1081.               /* Duplicate it and add to the Key dsc array */
  1082.             (*pPack)[index] = asei_dupl_cdsc(col) ;
  1083.         }
  1084.         retCode = kAsiGood ;
  1085.     } while(0) ;
  1086.     if ( retCode != kAsiGood ) {
  1087.           /* Free the allocated column descriptors */
  1088.         asei_destroy_cdscpack(pPack, *pColQty) ;
  1089.     }
  1090.     if ( stm != 0L ) {
  1091.           /* Deallocate the statement desc */
  1092.         asi_dealloc_stm (stm);
  1093.           /* Free the statement dsc */
  1094.         asi_destroy_stm(&stm) ;
  1095.     }
  1096.     return retCode ;
  1097. } /* end of lp_getTabCols() */
  1098.  
  1099. /****************************************************************************/
  1100. /*.doc lp_getRow(internal) */
  1101. /*+
  1102.   Gets the values of the row, specified by the key values.
  1103.   Puts the values into the pRow packet, which is allocated here.
  1104. -*/
  1105. /****************************************************************************/
  1106. static EAsiBoolean 
  1107. /*FCN*/lp_getRow(ASE_LPDSC lp,
  1108.                  ASICOLDSC *pKey, int KeyColQty,
  1109.                  ASICOLDSC **pRow, int *pColQty) 
  1110. {
  1111.     ASIIDENT ident ;                   /* Column identifier */
  1112.     ASISTATEMENT stm=0L ;              /* The statement desc */
  1113.     ASICURSOR csr=0L ;                 /* The cursor descriptor */
  1114.     char buf[BUFLEN] ;                 /* The general buffer */
  1115.     char *pstmbuf ;                    /* statement buffer pointer */
  1116.     int index ;                        /* scanning index */
  1117.     EAsiBoolean retCode=kAsiBad ;      /* The returning code */
  1118.  
  1119.     do {
  1120.           /* Check, whether Environment is connected */
  1121.         if ( isConnected(lp) != kAsiTrue ) {
  1122.             ads_printf("\nEnvironment isn't connected") ;
  1123.             break ;
  1124.         }
  1125.           /* Create statement descriptor */
  1126.         if ( asi_constr_stm (&stm) != kAsiGood ) {
  1127.             ads_printf("\nCan't construct ASI statement") ;
  1128.         }
  1129.           /* Get the SQL path to the table */
  1130.         if ( ase_lp_getName(lp, buf, BUFLEN, kAseSQLCode) != kAsiGood ) {
  1131.             ads_printf("\nCan't get the SQL table name") ;
  1132.             printAseErr(lp) ;
  1133.             break ;
  1134.         }
  1135.           /* Allocate the statement buffer */
  1136.         if ( (pstmbuf=addtoken(NEW_TOKENBUF)) == NULL ) {
  1137.             break ;
  1138.         }
  1139.         if ( addtoken("SELECT * FROM ") == NULL )
  1140.             break ;
  1141.           /* Add table name */
  1142.         if ( addtoken(buf) == NULL )
  1143.             break ;
  1144.         if ( addtoken(" WHERE ") == NULL )
  1145.             break ;
  1146.         for ( index=0 ; index < KeyColQty ; index++ ) {
  1147.               /* Add delimiter */
  1148.             if ( index ) {
  1149.                if ( addtoken(" AND ") == NULL )
  1150.                    break ;
  1151.             }
  1152.               /* Get the column identifier */
  1153.             if ( asi_cdsc_name(pKey[index], &ident) != kAsiGood ) {
  1154.                 ads_printf("\nCan't get the column identifier") ;
  1155.             }
  1156.               /* Get the ident name */
  1157.             if ( asi_get_ident(ident, buf, BUFLEN) == NULL ) {
  1158.                 ads_printf("\nCan't get the identifier name") ;
  1159.                 asi_destroy_ident(&ident) ;
  1160.                 break ;
  1161.             }
  1162.               /* Destroy the identifier */
  1163.             asi_destroy_ident(&ident) ;
  1164.               /* Add the column name */
  1165.             if ( addtoken(buf) == NULL ) 
  1166.                 break ;
  1167.               /* Add the binding symbol */
  1168.             if ( addtoken("=?") == NULL )
  1169.                 break ;
  1170.         }
  1171.           /* Check exit condition */
  1172.         if ( index < KeyColQty )
  1173.             break ;
  1174.           /* Prepare the statement */
  1175.         if ( asi_prepare (stm, 
  1176.                           getSession(),  
  1177.                           pstmbuf) != kAsiGood ) {
  1178.             ads_printf("\nCan't prepare the statement \n[%s]", pstmbuf) ;
  1179.             printAsiErr(stm) ;
  1180.             break ;
  1181.         }
  1182.           /* Construct the cursor */
  1183.         if ( asi_constr_csr(&csr) != kAsiGood ) {
  1184.             ads_printf("\nCan't construct the cursor") ;
  1185.             printAsiErr(csr) ;
  1186.             break ;
  1187.         }
  1188.           /* Allocate the cursor */
  1189.         if ( asi_alloc_csr(csr, stm, "XXX", 
  1190.                            kAsiScroll, kAsiSnsUndef) != kAsiGood ) {
  1191.             ads_printf("\nCan't allocate the cursor") ;
  1192.             printAsiErr(csr) ;
  1193.             break ;
  1194.         }                   
  1195.           /* Bind the input variables */
  1196.         for ( index = 0 ; index < KeyColQty ; index++ ) {
  1197.             if ( asei_bnd(csr, index, pKey[index]) != kAsiGood ) {
  1198.                 ads_printf("\nCan't bind the input parameter %d", index) ;
  1199.                 printAsiErr(csr) ;
  1200.                 break ;
  1201.             }
  1202.         }
  1203.           /* Check exit condition */
  1204.         if ( index < KeyColQty )
  1205.             break ;
  1206.           /* Open the cursor */
  1207.         if ( asi_open(csr) != kAsiGood ) {
  1208.             ads_printf("\nCan't open the cursor") ;
  1209.             printAsiErr(csr) ;
  1210.             break ;
  1211.         }   
  1212.           /* Fetch */
  1213.         if ( asi_fetch(csr) != kAsiGood ) {
  1214.             ads_printf("\nCan't fetch for the first row") ;
  1215.             printAsiErr(csr) ;
  1216.             break ;
  1217.         }
  1218.           /* Get the current row values */
  1219.         if ( csr_getVals(csr, pRow, pColQty) != kAsiGood ) {
  1220.             ads_printf("\nCan't get the row values") ;
  1221.             printAsiErr(csr) ;
  1222.             break ;
  1223.         }
  1224.         retCode = kAsiGood ;
  1225.     } while(0) ;
  1226.     if ( csr != 0L ) {
  1227.           /* Close the cursor */
  1228.         asi_close(csr) ;
  1229.           /* Destroy the cursor descriptor */
  1230.         asi_destroy_csr(&csr) ;
  1231.     }
  1232.     if ( stm != 0L ) {
  1233.           /* Deallocate the statement desc */
  1234.         asi_dealloc_stm (stm);
  1235.           /* Free the statement dsc */
  1236.         asi_destroy_stm(&stm) ;
  1237.     }
  1238.       /* Free the ro values */
  1239.     if ( retCode != kAsiGood ) {
  1240.         asei_destroy_cdscpack(pRow, *pColQty) ;
  1241.     }
  1242.       /* Free the allocated static buffer */
  1243.     addtoken(FREE_TOKENBUF) ;   
  1244.     return retCode ;
  1245. } /* end of lp_getRow() */
  1246.  
  1247. /****************************************************************************/
  1248. /*.doc lp_print(internal) */
  1249. /*+
  1250.   Prints the Link Path Structure
  1251. -*/
  1252. /****************************************************************************/
  1253. static void                               
  1254. /*FCN*/lp_print (ASE_LPDSC lp) 
  1255. {
  1256.     char buf[BUFLEN] ;        /* The buffer for printing */
  1257.     ASICOLDSC *pKey=NULL ; /* The key column desc. array */
  1258.     int ColQty ;                /* The key columns quantity */         
  1259.  
  1260.       /* Print the Table Path */
  1261.     ase_lp_getName(lp, buf, BUFLEN, kAseDOCode) ;
  1262.     ads_printf("\nDO: [%s]", buf) ;
  1263.       /* Print the LPN */
  1264.     ase_lp_getName(lp, buf, BUFLEN, kAseLpnCode) ;
  1265.     ads_printf("\nLPN: [%s]", buf) ;
  1266.       /* Get the key description */
  1267.     if ( ase_lp_getKeyDsc(lp, &pKey, &ColQty) == kAsiGood ) {
  1268.           /* Print the key desc */
  1269.         pack_printCols(pKey, ColQty) ;
  1270.         /* Free the key descriptors */
  1271.         asei_destroy_cdscpack(&pKey, ColQty) ;
  1272.     } else {
  1273.         ads_printf("\nCan't get the Key Description") ;
  1274.         printAseErr(lp) ;
  1275.     }
  1276. } /* end of lp_print() */
  1277.  
  1278. /****************************************************************************/
  1279. /*.doc lp_printPath(internal) */
  1280. /*+
  1281.   Analyzes the link path descriptor and prints its attributes
  1282. -*/
  1283. /****************************************************************************/
  1284. static void                               
  1285. /*FCN*/lp_printPath (ASE_LPDSC lp) 
  1286. {
  1287.     char buf[BUFLEN] ;      /* The buffer for printing */
  1288.     char *pBuf=NULL ;         /* The pointer to the buffer */
  1289.     int BufLen ;              /* The buffer length */
  1290.     int Status ;              /* The DO status */
  1291.  
  1292.       /* Print the Link Path Code value */
  1293.     ads_printf("\nPath Code: %d", ase_lp_getPathCode(lp)) ;
  1294.  
  1295.       /* Demonstrates the buffer dynamical allocating */
  1296.     if ( (BufLen=ase_lp_getNameSize(lp, kAsePathCode)) > 0 ) {
  1297.           /* Allocate the dynamical buffer */
  1298.         if ( (pBuf=(char*)calloc(1, BufLen)) == NULL ) {
  1299.             ads_abort("No memory") ;
  1300.             return ;
  1301.         }
  1302.           /* Fill the buffer with the Full Path */
  1303.         ase_lp_getName(lp, pBuf, BufLen, kAsePathCode) ;
  1304.           /* Print the Database Object Reference */
  1305.         ads_printf("\nEntered DOR: [%s]", pBuf) ;
  1306.           /* Free the  dynamical buffer */
  1307.         free (pBuf) ;
  1308.     } else {
  1309.         ads_printf("\nAnonymous Reference") ;
  1310.     }
  1311.  
  1312.       /* Other DO Path names are get into the 'static' buffer */
  1313.       /* Get Environment name */
  1314.     if ( ase_lp_getName(lp, buf, BUFLEN, kAseEnvCode) != kAsiGood ) {
  1315.         buf[0] = '\0' ;
  1316.     }
  1317.     ads_printf("\nEnvironment: %s", buf) ;
  1318.       /* Get Catalog name */
  1319.     if ( ase_lp_getName(lp, buf, BUFLEN, kAseCatCode) != kAsiGood ) {
  1320.         buf[0] = '\0' ;
  1321.     }
  1322.     ads_printf("\nCatalog: %s", buf) ;
  1323.       /* Get Schema name */
  1324.     if ( ase_lp_getName(lp, buf, BUFLEN, kAseSchemaCode) != kAsiGood ) {
  1325.         buf[0] = '\0' ;
  1326.     }
  1327.     ads_printf("\nSchema: %s", buf) ;
  1328.       /* Get Table Name */
  1329.     if ( ase_lp_getName(lp, buf, BUFLEN, kAseTableCode) != kAsiGood ) {
  1330.         buf[0] = '\0' ;
  1331.     }
  1332.     ads_printf("\nTable: %s", buf) ;
  1333.       /* Get LPN */
  1334.     if ( ase_lp_getName(lp, buf, BUFLEN, kAseLpnCode) != kAsiGood ) {
  1335.         buf[0] = '\0' ;
  1336.     }
  1337.     ads_printf("\nLink Path Name: %s", buf) ;
  1338.       /* Get the DO path without LPN */
  1339.     if ( ase_lp_getName(lp, buf, BUFLEN, kAseDOCode) != kAsiGood ) {
  1340.         buf[0] = '\0' ;
  1341.     }
  1342.     ads_printf("\nDO Path: %s", buf) ;
  1343.       /* Get the SQL path */
  1344.     if ( ase_lp_getName(lp, buf, BUFLEN, kAseSQLCode) != kAsiGood ) {
  1345.         buf[0] = '\0' ;
  1346.     }
  1347.     ads_printf("\nSQL Path: %s", buf) ;
  1348.  
  1349.     pauseInput("\nPress any key for the status information...") ;
  1350.       /* Analyze the status masks */
  1351.     Status = ase_lp_getStatus(lp) ;
  1352.     if ( Status & ASE_DO_CURRENT ) {
  1353.         ads_printf("\nDO is the current") ;
  1354.     }
  1355.     if ( Status & ASE_DO_REG ) {
  1356.         ads_printf("\nDO is registered") ;
  1357.         if ( ase_lp_isUpdatable(lp) == kAsiGood ) {
  1358.             ads_printf("\nThe subordinate LPN(s) and its links can be modified") ;
  1359.         } else {
  1360.             /* Clear the non-updatability reasons data */
  1361.             ase_dsc_errClear(lp) ;
  1362.         }
  1363.     }
  1364.     if ( Status & ASE_DO_CON ) {
  1365.         ads_printf("\nEnvironment is connected") ;
  1366.     } else {
  1367.         ads_printf("\nEnvironment is not connected") ;
  1368.     }
  1369.     if ( Status & ASE_DO_EXIST ) {
  1370.         ads_printf("\nDO exist in the database") ;
  1371.     } 
  1372.     if ( Status & ASE_DO_UNKNOWN ) {
  1373.         ads_printf("\nCan't check whether the DO exist in the database") ;
  1374.     } 
  1375.     if ( !(Status & ASE_DO_EXIST) && ! (Status & ASE_DO_UNKNOWN) ) {
  1376.       /* DO definitely doesn't exist */
  1377.         ads_printf("\nDo doesn't exist in the database") ;
  1378.     }
  1379.     if ( Status & ASE_DO_WRONGKEY ) {
  1380.         ads_printf("\nWrong registered key column names for table") ;
  1381.     } 
  1382.     if ( Status & ASE_DO_WRONGKEYTYPE ) {
  1383.         ads_printf("\nWrong registered key column types for table") ;
  1384.     } 
  1385. } /* end of lp_printPath() */
  1386.  
  1387. /****************************************************************************/
  1388. /*.doc lp_printStat(internal) */
  1389. /*+
  1390.   Analyzes the link path descriptor and prints the related information
  1391. -*/
  1392. /****************************************************************************/
  1393. static void                               
  1394. /*FCN*/lp_printStat (ASE_LPDSC lp) 
  1395. {
  1396.     ASE_LSDSC   ls=ASE_DSC_NULL ;  /* The link selection descriptor */
  1397.     ads_name      ssname ;              /* The Entity Selection Name */
  1398.     struct resbuf *pBuf=NULL ;          /* The result buffer for names */
  1399.     long          Len=0L ;              /* Selection set length */
  1400.  
  1401.     ads_name_clear(ssname) ;         /* Clear the ent sel name */
  1402.  
  1403.       /* Get the related links quantity */
  1404.     if ( ase_lp_getStatus(lp) & ASE_DO_REG ) {
  1405.           /* Print the related link path names */
  1406.         if ( (pBuf = ase_lp_getLinkNames(lp)) != NULL ) {
  1407.             pauseInput("\nPress key for printing related LPNs") ;
  1408.             printBufNames(pBuf) ;
  1409.         } else {
  1410.             ads_printf("\nCan't get the LPNs list") ;
  1411.             printAseErr(lp) ;
  1412.         }
  1413.         ads_relrb(pBuf) ;
  1414.         if ( (ls = ase_dsc_alloc(AseAppl, kAseApiLinkSel)) == ASE_DSC_NULL ) {
  1415.             ads_abort("\nCan't allocate the Link Selection descriptor") ;
  1416.             return ;
  1417.         }
  1418.           /* Init by the given Link Path Descriptor */
  1419.         if ( ase_ls_initLpDsc(ls, lp) != kAsiGood ) {
  1420.             if ( ase_dsc_errDsc(ls, 0) != eAseEDscApi ||
  1421.                  ase_dsc_errCode(ls, 0) != eAseApiErrSelEmpty ) {
  1422.                 ads_printf("\nLink Selection creating problem") ;
  1423.                 printAseErr(ls) ;
  1424.             } else {
  1425.                 /* No related links */
  1426.                 ads_printf("\nNo Links for the DO exist") ;
  1427.             }
  1428.             ase_dsc_free(&ls) ;
  1429.             return ;
  1430.         }
  1431.           /* Get the links quantity */
  1432.         ads_printf("\nRelated links #%ld", ase_ls_getQty(ls)) ;
  1433.           /* Get the entity selection set name */
  1434.         if ( ase_ls_getEntSel(ls, ssname) == kAsiGood ) {
  1435.               /* Get the entities quantity */
  1436.             if ( ads_sslength(ssname, &Len) == RTNORM ) {
  1437.                 ads_printf("\nRelated entities #%ld", Len) ;
  1438.             } else {
  1439.                 ads_printf("\nWrong entity selection is returned") ;
  1440.             }
  1441.               /* Free the allocated selection */
  1442.             ads_ssfree(ssname) ;
  1443.         } else {
  1444.             ads_printf("\nCan't get the links selection for DO") ;
  1445.             printAseErr(ls) ;
  1446.         }
  1447.           /* Get the related Xref/Block names */
  1448.         if ( (pBuf=ase_ls_getXNames(ls)) != NULL ) {
  1449.             pauseInput("\nPress key for Xref/Block names printing...") ;
  1450.             printBufNames(pBuf) ;
  1451.             ads_relrb(pBuf) ;
  1452.         } else {
  1453.             ads_printf("\nNo related Xref(s)/Block(s) are available") ;
  1454.             printAseErr(ls) ;
  1455.         }
  1456.           /* Free the link selection descriptor */
  1457.         ase_dsc_free(&ls) ;
  1458.     }
  1459. } /* end of lp_printStat() */
  1460.  
  1461. /****************************************************************************/
  1462. /*.doc csr_scroll(internal) */
  1463. /*+
  1464.   This function scans the opened cursor and
  1465.   supports the link manipulation.
  1466. -*/
  1467. /****************************************************************************/
  1468. static EAsiBoolean 
  1469. /*FCN*/csr_scroll(
  1470.            ASICURSOR csr,   /* The cursor descriptor */
  1471.            ASE_LPDSC lp     /* The Link Path descriptor */
  1472.            ) 
  1473. {
  1474.     char buf[BUFLEN] ;                 /* The buffer for entering */
  1475.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  1476.     EAsiBoolean rCode=kAsiGood ;       /* The fetching resulting code */
  1477.     int retword ;                      /* ads_getkword() returning value */
  1478.  
  1479.     /* The initial checking fetch */
  1480.     if ( asi_fetch(csr) != kAsiGood ) {
  1481.         printAsiErr(csr) ;
  1482.         return kAsiBad ;
  1483.     }
  1484.     do {
  1485.           /* Loop for the asking LPN options */
  1486.         do {
  1487.             if ( rCode == kAsiGood ) {
  1488.                 csr_printRow(csr) ;
  1489.             } else {
  1490.                 printAsiErr(csr) ;
  1491.             }
  1492.             if ( ads_initget(0, "N P F L V E M R X") != RTNORM ) {
  1493.                 break ;
  1494.             }
  1495.               /* Next/Previous/First/Last/View/Erase/Make/Reload DA/<eXit> */
  1496.             retword=ads_getkword(
  1497.                       "\nNext/Previous/First/Last/View/Erase/Make/Reload DA/<eXit>:", 
  1498.                       buf) ;
  1499.             if ( retword != RTNORM && retword != RTNONE ) {
  1500.                 break ;
  1501.             }
  1502.             if ( retword == RTNONE || buf[0] == '\0' || buf[0] == 'X' ) {
  1503.                 retCode = kAsiGood ;
  1504.                 break ;
  1505.             }
  1506.             switch(buf[0]) {
  1507.             case 'N':                  /* NEXT */
  1508.                 rCode = asi_fetch (csr);
  1509.                 break ;
  1510.             case 'P':                  /* PREVIOUS */
  1511.                 rCode = asi_fetchPrior (csr);
  1512.                 break ;
  1513.             case 'F':                  /* FIRST */
  1514.                 rCode = asi_fetchFirst (csr);
  1515.                 break ;
  1516.             case 'L':                  /* LAST */
  1517.                 rCode = asi_fetchLast (csr);
  1518.                 break ;
  1519.             case 'V':                  /* VIEW */
  1520.                 csr_viewLinks(csr, lp) ;
  1521.                 break ;
  1522.             case 'E':                  /* ERASE */
  1523.                 csr_eraseLinks(csr, lp) ;
  1524.                 break ;
  1525.             case 'M':                 /* MAKE */
  1526.                 csr_makeLink(csr, lp) ;
  1527.                 break ;
  1528.             case 'R':                /* RELOAD DA */
  1529.                 csr_reloadDA(csr, lp) ;
  1530.                 break ;
  1531.             }
  1532.         } while(1) ;
  1533.     } while(0) ;
  1534.     return retCode ;
  1535. } /* end of csr_scroll() */
  1536.  
  1537. /****************************************************************************/
  1538. /*.doc csr_viewLinks(internal) */
  1539. /*+
  1540.   This function prints the links related with the curren cursor row
  1541.   and the specified Link Path 
  1542. -*/
  1543. /****************************************************************************/
  1544. static EAsiBoolean 
  1545. /*FCN*/csr_viewLinks(ASICURSOR csr, ASE_LPDSC lp) 
  1546. {
  1547.     ASE_LSDSC ls=ASE_DSC_NULL ;       /* The link selection buffer */
  1548.     EAsiBoolean retCode = kAsiBad ;   /* The returning code */
  1549.  
  1550.     do {
  1551.           /* Get the link selection */
  1552.         if ( (ls=csr_getLinks(csr, lp)) == ASE_DSC_NULL ) {
  1553.             break ;
  1554.         }
  1555.           /* Check the length of the link Selection */
  1556.         if ( ase_ls_getQty(ls) == 0L ) {
  1557.             ads_printf("\nNo Links") ;
  1558.             retCode = kAsiGood ;
  1559.             break ;
  1560.         }
  1561.           /* Print the Link Selection */
  1562.         ls_print(ls, ASE_DSC_NULL, (ASICOLDSC*)NULL, 0) ;
  1563.         retCode = kAsiGood ;
  1564.     } while(0) ;
  1565.     ase_dsc_free(&ls) ;
  1566.     return retCode ;
  1567. } /* end of csr_viewLinks() */
  1568.  
  1569. /****************************************************************************/
  1570. /*.doc csr_eraseLinks(internal) */
  1571. /*+
  1572.   This function erases the links related with the curren cursor row
  1573.   and the specified Link Path 
  1574. -*/
  1575. /****************************************************************************/
  1576. static EAsiBoolean 
  1577. /*FCN*/csr_eraseLinks(ASICURSOR csr, ASE_LPDSC lp) 
  1578. {
  1579.     ASE_LSDSC ls=ASE_DSC_NULL ;       /* The link selection buffer */
  1580.     EAsiBoolean retCode = kAsiBad ;   /* The returning code */
  1581.  
  1582.     do {
  1583.           /* Get the link selection */
  1584.         if ( (ls=csr_getLinks(csr, lp)) == ASE_DSC_NULL ) {
  1585.             break ;
  1586.         }
  1587.           /* Check the length of the link Selection */
  1588.         if ( ase_ls_getQty(ls) == 0L ) {
  1589.             ads_printf("\nNo Links") ;
  1590.             retCode = kAsiGood ;
  1591.             break ;
  1592.         }
  1593.           /* Check, whether the links are updatable */
  1594.         if ( ase_ls_isUpdatable(ls) != kAsiGood ) {
  1595.             ads_printf("\nThe Link Selection isn't updatable") ;
  1596.             printAseErr(ls) ;
  1597.             retCode = kAsiGood ;
  1598.             break ;
  1599.         }
  1600.           /* Erase the links */
  1601.         if ( ase_ls_erase(ls) != kAsiGood ) {
  1602.             ads_printf("\nCan't erase the links from Link Selection") ;
  1603.             printAseErr(ls) ;
  1604.             break ;
  1605.         }
  1606.           /* Remove the LPN from LP */
  1607.         if ( ase_lp_setName(lp, "", kAseLpnCode) != kAsiGood ) {
  1608.             ads_printf("\nCan't nullify the LPN") ;
  1609.             printAseErr(lp); 
  1610.             break ;
  1611.         }
  1612.         retCode = kAsiGood ;
  1613.     } while(0) ;
  1614.     ase_dsc_free(&ls) ;
  1615.     return retCode ;
  1616. } /* end of csr_eraseLinks() */
  1617.  
  1618. /****************************************************************************/
  1619. /*.doc csr_makeLink(internal) */
  1620. /*+
  1621.   This function makes the links to the current row of the specified cursor
  1622.   The link type - Entity Link or DA Link is asked.
  1623. -*/
  1624. /****************************************************************************/
  1625. static EAsiBoolean 
  1626. /*FCN*/csr_makeLink(ASICURSOR csr, ASE_LPDSC lp) 
  1627. {
  1628.     char  buf[BUFLEN] ;             /* The buffer */
  1629.     EAsiBoolean retCode = kAsiBad ;   /* The returning code */
  1630.  
  1631.     do {
  1632.           /* Ask for the DO path entering */
  1633.         if ( ads_getstring(0, "Da/<Entity>:", buf) != RTNORM ) {
  1634.             ads_printf("\nNo input") ;
  1635.             ase_dsc_free(&lp) ;
  1636.             break ;
  1637.         }
  1638.         if ( buf[0] == '\0' || buf[0] == 'e' || buf[0] == 'E' ) {
  1639.             retCode = link_entMake(csr, lp) ;
  1640.         } else if ( buf[0] == 'd' || buf[0] == 'D' ) {
  1641.             retCode = link_daMake(csr, lp) ;
  1642.         } else {
  1643.             ads_printf("\nWrong input");
  1644.             continue ;
  1645.         }
  1646.     } while(0) ;
  1647.     return retCode ;
  1648. } /* end of csr_makeLink() */
  1649.  
  1650. /****************************************************************************/
  1651. /*.doc csr_reloadDA(internal) */
  1652. /*+
  1653.   Reloads the DA, related with the current row of the specified cursor.
  1654.   If DA are relaoded succesfully or there is no DAs related
  1655.   with the specified Link Path and the current row,
  1656.   returns kAsiGood. 
  1657.   Returns kAsiBad if somethign is wrong.
  1658. -*/
  1659. /****************************************************************************/
  1660. static EAsiBoolean 
  1661. /*FCN*/csr_reloadDA(ASICURSOR csr, ASE_LPDSC lp) 
  1662. {
  1663.     ASE_LSDSC ls=ASE_DSC_NULL ;      /* The set of the related DA links */
  1664.     ASE_LINKDSC link=ASE_DSC_NULL;   /* The Link Descriptor */
  1665.     ASICOLDSC *pDACols=NULL ;        /* The DA values */
  1666.     LinkID ID ;                      /* The link identifier */
  1667.     long linkQty ;                   /* The DA links quantity */
  1668.     long index ;                     /* scanning index */
  1669.     int DAColQty=0 ;                 /* DA values quantity */
  1670.     EAsiBoolean retCode = kAsiBad ;  /* The returning code */
  1671.  
  1672.     do {
  1673.           /* Get the link selection */
  1674.         if ( (ls=csr_getLinks(csr, lp)) == ASE_DSC_NULL ) {
  1675.             break ;
  1676.         }
  1677.           /* Check the length of the link Selection */
  1678.         if ( ase_ls_getQty(ls) == 0L ) {
  1679.             ads_printf("\nNo Links") ;
  1680.             retCode = kAsiGood ;
  1681.             break ;
  1682.         }
  1683.           /* Filter the links */
  1684.         if ( ase_ls_intersectType(ls, kAseDALink) != kAsiGood ) {
  1685.             ads_printf("\nError in the link selection filtering") ;
  1686.             printAseErr(ls) ;
  1687.             break ;
  1688.         }
  1689.           /* Check the length of the link Selection now */
  1690.         if ( (linkQty=ase_ls_getQty(ls)) == 0L ) {
  1691.             ads_printf("\nNo DA Links") ;
  1692.             retCode = kAsiGood ;
  1693.             break ;
  1694.         }
  1695.           /* Allocate the Link Descripotor */
  1696.         if ( (link=ase_dsc_alloc(AseAppl, kAseApiLink)) == ASE_DSC_NULL ) {
  1697.             ads_abort("\nCan't allocate the Link Descriptor") ;
  1698.             break ;
  1699.         }
  1700.           /* Scan the links */
  1701.         for ( index = 0L ; 
  1702.               index < linkQty ;
  1703.               index++ ) {
  1704.               /* Get the Link descriptor */
  1705.             if ( (ID=ase_ls_getId(ls, index)) == LINKID_NULL ) {
  1706.                 ads_printf("\nWrong Link ID was got") ;
  1707.                 printAseErr(ls) ;
  1708.                 break ;
  1709.             }
  1710.               /* Init the Link by the ID */
  1711.             if ( ase_link_initId(link, ID) != kAsiGood ) {
  1712.                 ads_printf("\nCan't init the link by the ID %ld", ID) ;
  1713.                 printAseErr(link) ;
  1714.                 break ;
  1715.             }
  1716.               /* Check the Link Updatability */
  1717.             if ( ase_link_isUpdatable(link) != kAsiTrue ) {
  1718.                 ads_printf("\nLink %ld is unupdatable", ID) ;
  1719.                 continue ;
  1720.             }
  1721.               /* Get the DA columns */
  1722.             if ( ase_link_getDACols(link, &pDACols, &DAColQty) != kAsiGood ) {
  1723.                 ads_printf("\nCan't get the DA columns") ;
  1724.                 printAseErr(link) ;
  1725.                 break ;
  1726.             }
  1727.               /* Extract the new DA column values */
  1728.             if ( csr_getVals(csr, &pDACols, &DAColQty) != kAsiGood ) {
  1729.                 ads_printf("\nCan't get the new DA column values") ;
  1730.                 break ;
  1731.             }
  1732.               /* Update the new DA column values */
  1733.             if ( ase_link_setDAValues(link, pDACols, DAColQty) != kAsiGood ) {
  1734.                 ads_printf("\nCan't update the new DA column values") ;
  1735.                 printAseErr(link) ;
  1736.                 break ;
  1737.             }
  1738.               /* Update the DA link */
  1739.             if ( ase_link_update(link) != kAsiGood ) {
  1740.                 ads_printf("\nCan't update the DA link") ;
  1741.                 printAseErr(link) ;
  1742.                 break ;
  1743.             }
  1744.               /* Desctroy the DA column values */
  1745.             asei_destroy_cdscpack(&pDACols, DAColQty) ;
  1746.         }
  1747.           /* Check the loop exit condition */
  1748.         if ( index < linkQty ) {
  1749.             break ;
  1750.         }
  1751.         retCode = kAsiGood ;
  1752.     } while(0) ;
  1753.       /* Destroy DA column values */
  1754.     asei_destroy_cdscpack(&pDACols, DAColQty) ;
  1755.       /* Free the Link Selection */
  1756.     ase_dsc_free(&ls) ;
  1757.     return retCode ;
  1758. } /* end of csr_reloadDA() */
  1759.  
  1760. /****************************************************************************/
  1761. /*.doc csr_getVals(internal) */
  1762. /*+
  1763.   Extracts the values from the cursor in accordance
  1764.   with the columns description. If *pVals==(ASICOLDSC*)NULL, 
  1765.   then this function allocates the
  1766.   packet of the ASICOLDSC and retreives all columns descriptions.
  1767. -*/
  1768. /****************************************************************************/
  1769. static EAsiBoolean 
  1770. /*FCN*/csr_getVals(ASICURSOR csr, 
  1771.                   ASICOLDSC *pVals[],
  1772.                   int *pColQty) 
  1773. {
  1774.     ASICOLDSC cds ;    /* The column descriptor */
  1775.     EAsiBoolean retCode=kAsiBad ; /* The returning code */
  1776.     int index ;        /* main scanning index */
  1777.     int jndex ;        /* second scanning index */
  1778.  
  1779.     do {
  1780.         if ( *pVals == (ASICOLDSC*)NULL ) {
  1781.             *pColQty = asi_colcount(csr) ;
  1782.               /* Allocate the packet */
  1783.             if ( (*pVals=asei_constr_cdscpack(*pColQty)) ==
  1784.                   (ASICOLDSC*)NULL ) {
  1785.                 ads_abort("\nCan't allocate the packet") ;
  1786.                 break ;
  1787.             }
  1788.             for ( index = 0 ; index < *pColQty ; index++ ) {
  1789.                   /* Get the column & data desc and */
  1790.                 if ( asei_cds(csr, index, &cds) != kAsiGood ) {
  1791.                     ads_abort("\nCan't get the column descriptor") ;
  1792.                     break ;
  1793.                 }
  1794.                   /* insert it into the packet */
  1795.                 if ( ((*pVals)[index]=cds) == 0L ) {
  1796.                     ads_abort("\nCan't duplicatre column description") ;
  1797.                     break ;
  1798.                 }
  1799.             }
  1800.             if ( index >= *pColQty ) {
  1801.                 retCode = kAsiGood ;
  1802.             }
  1803.             break ;
  1804.         }
  1805.         retCode = kAsiGood ;
  1806.         for ( index = 0 ; index < *pColQty ; index++ ) {
  1807.             for ( jndex = 0 ; jndex < asi_colcount(csr) ; jndex++ ) {
  1808.                   /* Get the column & data desc and */
  1809.                 if ( asei_cds(csr, jndex, &cds) != kAsiGood ) {
  1810.                     ads_abort("\nCan't get the column descriptor") ;
  1811.                     retCode = kAsiBad ;
  1812.                     break ;
  1813.                 }
  1814.                   /* Compare two column desc */
  1815.                 if ( asei_cdsc_cmpname((*pVals)[index], cds) ) {
  1816.                       /* insert it into the packet */
  1817.                     if ( ((*pVals)[index]=cds) == 0L ) {
  1818.                         ads_abort("\nCan't duplicatre column description") ;
  1819.                         retCode = kAsiBad ;
  1820.                         break ;
  1821.                     }
  1822.                     break ;
  1823.                 }
  1824.                 asei_destroy_cdsc(&cds) ;
  1825.             }
  1826.             if ( retCode != kAsiGood ) {
  1827.                 break ;
  1828.             }
  1829.         }
  1830.     } while(0) ;
  1831.     return retCode ;
  1832. } /* end of csr_getVals() */
  1833.  
  1834. /****************************************************************************/
  1835. /*.doc csr_getLinks(internal) */
  1836. /*+
  1837.   Gets the link selection for the links related with the
  1838.   current row of the specified cursor and related with the
  1839.   specified Link Path. The links quantity should be checked 
  1840.   with the ase_ls_getQty().
  1841.   Return ASE_DSC_NULL if something is wrong.
  1842. -*/
  1843. /****************************************************************************/
  1844. static ASE_LSDSC   
  1845. /*FCN*/csr_getLinks(ASICURSOR csr,
  1846.                     ASE_LPDSC lp) 
  1847. {
  1848.     ASE_LSDSC lsret=ASE_DSC_NULL ;   /* The returning Link Selection */
  1849.     ASICOLDSC *pKey=NULL ;           /* The Key values buffer */
  1850.     int ColQty ;                     /* The columns quantity */
  1851.     EAsiBoolean retCode=kAsiBad ;    /* The exit condition */
  1852.  
  1853.     do {
  1854.           /* Allocate the link selection */
  1855.         if ( (lsret=ase_dsc_alloc(AseAppl, kAseApiLinkSel)) == ASE_DSC_NULL ) {
  1856.             ads_abort("\nCan't allocate the Link Sel descriptor") ;
  1857.             break ;
  1858.         }
  1859.           /* Check the Link Path */
  1860.         if ( ase_lp_getPathCode(lp) == kAseLpnCode ) {
  1861.               /* LPN is set - get the Key Description */
  1862.             if ( ase_lp_getKeyDsc(lp, &pKey, &ColQty) != kAsiGood ) {
  1863.                 ads_printf("\nCan't get the Key Description") ;
  1864.                 printAseErr(lp) ;
  1865.                 break ;
  1866.             }
  1867.         }
  1868.           /* Get the Key Values of the current row */
  1869.           /* If the Link Path doesn't have the LPN */
  1870.           /* specified - ask for the all row values */
  1871.         if ( csr_getVals(csr, &pKey, &ColQty) != kAsiGood ) {
  1872.             ads_printf("\nCan't get the key values from row") ;
  1873.             break ;
  1874.         }
  1875.           /* Init the link selection by the Link Path */
  1876.           /* and the row values */
  1877.         if ( ase_ls_initLpDscKey(lsret, lp, pKey, ColQty) != kAsiGood ) {
  1878.             if ( ase_dsc_errDsc(lsret, 0) != eAseEDscApi ||
  1879.                 ase_dsc_errCode(lsret, 0) != eAseApiErrSelEmpty ) {
  1880.                 ads_printf("\nLink Selection creating problem") ;
  1881.                 printAseErr(lsret) ;
  1882.             } else {
  1883.                   /* No related links */
  1884.                 retCode = kAsiGood ;
  1885.             }
  1886.             break ;
  1887.         }
  1888.           /* Check the length of the link Selection */
  1889.         if ( ase_ls_getQty(lsret) == 0L ) {
  1890.             ads_printf("\nWrong Link Selection length") ;
  1891.             printAseErr(lsret) ;
  1892.             break ;
  1893.         }
  1894.         retCode = kAsiGood ;
  1895.     } while(0) ;
  1896.     asei_destroy_cdscpack(&pKey, ColQty) ;
  1897.     if ( retCode != kAsiGood ) {
  1898.         ase_dsc_free(&lsret) ;
  1899.     }
  1900.     return lsret ;
  1901. } /* end of csr_getLinks() */
  1902.  
  1903. /****************************************************************************/
  1904. /*.doc csr_printRow(internal) */
  1905. /*+
  1906.   Prints the current row of the specified cursor
  1907. -*/
  1908. /****************************************************************************/
  1909. static void        
  1910. /*FCN*/csr_printRow(ASICURSOR csr) 
  1911. {
  1912.     ASICOLDSC col ;           /* The column descriptor with the data */
  1913.     ASIIDENT ident ;          /* Column identifier */
  1914.     char buf[BUFLEN] ;        /* The buffer for printing values */
  1915.     EAsiBoolean isNull ;      /* Null value indicator */
  1916.     int index ;               /* The row column scanning index */
  1917.  
  1918.     for ( index = 0 ; index < asi_colcount(csr) ; index++ ) {
  1919.           /* Get the column descriptor with the data */
  1920.         if ( asei_cds(csr, index, &col) != kAsiGood ) {
  1921.             ads_printf("\nCan't get the column descriptor") ;
  1922.             printAsiErr(csr) ;
  1923.             break ;
  1924.         }
  1925.           /* Get the ident */
  1926.         if ( asi_cdsc_name(col, &ident) != kAsiGood ) {
  1927.             ads_printf("\nCan't get the column identifier") ;
  1928.         }
  1929.           /* Get the ident name */
  1930.         if ( asi_get_ident(ident, buf, BUFLEN) == NULL ) {
  1931.             ads_printf("\nCan't get the identifier name") ;
  1932.             asi_destroy_ident(&ident) ;
  1933.             asei_destroy_cdsc(&col) ;
  1934.             break ;
  1935.         }
  1936.         asi_destroy_ident(&ident) ;
  1937.           /* Print the ident name */
  1938.         ads_printf("\n %s: ", buf) ;
  1939.         asei_cdsc_rtype(col, &isNull)  ;
  1940.         if ( isNull == kAsiTrue ) {
  1941.               /* Null value */
  1942.             buf[0] = '.' ;
  1943.             buf[1] = '\0' ;
  1944.         } else {
  1945.               /* Get the column value as the string */
  1946.             if ( asei_cdsc_getstr(col, buf, BUFLEN) != kAsiGood ) {
  1947.                 ads_printf("\nCan't get the value") ;
  1948.                 asei_destroy_cdsc(&col) ;
  1949.                 break ;
  1950.             }
  1951.         }
  1952.         ads_printf("%s", buf) ;
  1953.         asei_destroy_cdsc(&col) ;
  1954.     }
  1955. } /* end of csr_printRow() */
  1956.  
  1957. /****************************************************************************/
  1958. /*.doc ls_scan(internal) */
  1959. /*+
  1960.   Scans and manipulates with the links for the specified Link Selection.
  1961. -*/
  1962. /****************************************************************************/
  1963. static EAsiBoolean 
  1964. /*FCN*/ls_scan(ASE_LSDSC ls) 
  1965. {
  1966.     ASE_LINKDSC link=ASE_DSC_NULL ;    /* The current link buffer */
  1967.     ASE_LPDSC lp=ASE_DSC_NULL ;        /* Link Path of the current link */
  1968.     ASICOLDSC *pKey=(ASICOLDSC*)NULL ; /* Key buffer */
  1969.     ASICOLDSC *pRow=(ASICOLDSC*)NULL ; /* Row values buffer */
  1970.     char buf[BUFLEN] ;                 /* The buffer for entering */
  1971.     long pos=0L ;                      /* The current position in Link Sel */
  1972.     long length=ase_ls_getQty(ls) ;    /* The Link Selection length */
  1973.     LinkID ID=LINKID_NULL;             /* The current Link Identifier */
  1974.     long newID ;                       /* For the new Link Identifier */
  1975.     int ColQty ;                       /* Table columns quantity */
  1976.     int KeyColQty ;                    /* Key columns quantity */
  1977.     int retword ;                      /* ads_getkword() returning value */
  1978.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  1979.  
  1980.       /* Allocate the Link Descriptor */
  1981.     if ( (link=ase_dsc_alloc(AseAppl, kAseApiLink)) == ASE_DSC_NULL ) {
  1982.         ads_abort("\nCan't allocate the Link Descriptor") ;
  1983.         return kAsiBad ;
  1984.     }
  1985.       /* Allocate the Link Path Descriptor */
  1986.     if ( (lp=ase_dsc_alloc(AseAppl, kAseApiLinkPath)) == ASE_DSC_NULL ) {
  1987.         ads_abort("\nCan't allocate the Link Path Descriptor") ;
  1988.         return kAsiBad ;
  1989.     }
  1990.     do {
  1991.           /* Check the Link Selection length */
  1992.         if ( length <= 0L ) {
  1993.             ads_printf("\nNo Links") ;
  1994.             break ;
  1995.         }
  1996.           /* Get the Link Identifier */
  1997.         if ( ase_ls_getId(ls, pos) != ID ) {
  1998.               /* Check the Link Identifier */
  1999.             if ( (ID = ase_ls_getId(ls, pos)) == LINKID_NULL ) {
  2000.                 ads_printf("\nWrong ID is got") ;
  2001.                 printAseErr(ls) ;
  2002.                 break ;
  2003.             }
  2004.               /* Initialize the Link Descriptor */
  2005.               /* by the Link Identifier */
  2006.             if ( ase_link_initId(link, ID) != kAsiGood ) {
  2007.                 ads_printf("\nCan't get the data for the link %ld", ID) ;
  2008.                 break ;
  2009.             }
  2010.               /* Get the Link Path name */
  2011.             if ( ase_link_getName(link, buf, BUFLEN) != kAsiGood ) {
  2012.                 ads_printf("\nCan't get the Link Path Name") ;
  2013.                 printAseErr(link) ;
  2014.                 break ;
  2015.             }
  2016.               /* Check whether the same Link Path */
  2017.               /* already exist */
  2018.             if ( ! ase_lp_cmpName(lp, buf, kAseLpnCode) ) {
  2019.                   /* Init the Link Path by the new LPN */
  2020.                 if ( ase_lp_initName(lp, buf) != kAsiGood ) {
  2021.                     ads_printf("\nWrong LPN is got") ;
  2022.                     printAseErr(lp) ;
  2023.                     break ;
  2024.                 }
  2025.                   /* Get the key buffer */
  2026.                 if ( ase_lp_getKeyDsc(lp, &pKey, &KeyColQty) != kAsiGood ) {
  2027.                     ads_printf("\nCan't get the Key description") ;
  2028.                     printAseErr(lp) ;
  2029.                     break ;
  2030.                 }
  2031.             }
  2032.         }
  2033.           /* Print the Link Data */
  2034.         link_print(link, pKey, KeyColQty) ;
  2035.           /* Print the Link Quatity */
  2036.         ads_printf("\nPosition:#%ld   Links Quantity: #%ld", pos, length) ;
  2037.           /* Next/Previous/First/Last/Add/Delete/Edit/Row/<eXit> */
  2038.         if ( ads_initget(0, "N P F L A D E R X") != RTNORM ) {
  2039.             break ;
  2040.         }
  2041.         retword=ads_getkword(
  2042.                    "\nNext/Previous/First/Last/Add/Delete/Edit/Row/<eXit>:", 
  2043.                    buf) ;
  2044.         if ( retword != RTNORM && retword != RTNONE ) {
  2045.             break ;
  2046.         }
  2047.         if ( retword == RTNONE || buf[0] == '\0' || buf[0] == 'X' ) {
  2048.             retCode = kAsiGood ;
  2049.             break ;
  2050.         }
  2051.         switch(buf[0]) {
  2052.         case 'N':                      /* NEXT */
  2053.             if ( pos < ase_ls_getQty(ls)-1 )
  2054.                 pos++ ;
  2055.             break ;
  2056.         case 'P':                      /* PREVIOUS */
  2057.             if ( pos > 0L ) {
  2058.                 pos-- ;
  2059.             }
  2060.             break ;
  2061.         case 'F':                      /* FIRST */
  2062.             pos = 0L ;
  2063.             break ;
  2064.         case 'L':                      /* LAST */
  2065.             pos = length-1 ;
  2066.             break ;
  2067.         case 'A':                      /* ADD */
  2068.               /* Ask for the new identifier number */
  2069.             if ( ads_getstring(0, "\nEnter the Link ID:", buf) != RTNORM ) {
  2070.                 ads_printf("\nNo input") ;
  2071.                 break ;
  2072.             }
  2073.               /* Check the number */
  2074.             if ( (newID=(long)atol(buf)) == 0L && buf[0] != '0' ) {
  2075.                 ads_printf("\nThe number is required") ;
  2076.                 continue ;
  2077.             }
  2078.               /* Check whether or not the new */
  2079.               /* Link Identifier already */
  2080.               /* exist in the Link Selection */
  2081.             if ( ase_ls_membId(ls, (LinkID)newID) != -1L ) {
  2082.                 ads_printf("\nSuch a ID already exist") ;
  2083.                 continue ;
  2084.             }
  2085.               /* Add the identifier */
  2086.               /* to the Link Selection */
  2087.             if ( ase_ls_addId(ls, (LinkID)newID) != kAsiGood ) {
  2088.                 ads_printf("\nCan't add the link identifier") ;
  2089.                 printAseErr(ls) ;
  2090.                 break ;
  2091.             }
  2092.               /* Get the new position */
  2093.             if ( (pos=ase_ls_membId(ls, (LinkID)newID)) != -1L ) {
  2094.                 ads_printf("\nSuch a ID already exist") ;
  2095.                 break ;
  2096.             }
  2097.               /* Assign the new current identifier value */
  2098.             ID = (LinkID)newID ;
  2099.             break ;
  2100.         case 'D':                      /* DELETE */
  2101.             /* Check the Link Updatability */
  2102.             if ( ase_link_isUpdatable(link) != kAsiTrue ) {
  2103.                 ads_printf("\nThe link isn't updatable") ;
  2104.                 printAseErr(link) ;
  2105.                 break ;
  2106.             }
  2107.               /* Remove the link */
  2108.             if ( ase_link_remove(link) != kAsiGood ) {
  2109.                 ads_printf("\nCan't delete the link") ;
  2110.                 printAseErr(link) ;
  2111.                 break ;
  2112.             }
  2113.               /* Erase the link ID from the Link Selection */
  2114.             if ( ase_ls_delId(ls, pos) != kAsiGood ) {
  2115.                 ads_printf("\nCan't remove the Link Id") ;
  2116.                 printAseErr(ls) ;
  2117.             }
  2118.               /* Recalculate the new position */
  2119.             if ( pos == length-1 ) {
  2120.                 pos-- ;
  2121.             }
  2122.             length-- ;
  2123.             break ;
  2124.         case 'E':                      /* EDIT */ 
  2125.             link_edit(link, lp, pKey, KeyColQty) ;
  2126.             break ;
  2127.         case 'R':                      /* ROW */
  2128.               /* Connect to the Env */
  2129.             if ( isConnected(lp) != kAsiTrue ) {
  2130.                 if ( connect(lp) != kAsiGood ) {
  2131.                     break ;
  2132.                 }
  2133.             }
  2134.               /* Get the row values */
  2135.             if ( lp_getRow(lp, pKey, KeyColQty,
  2136.                            &pRow, &ColQty) != kAsiGood ) {
  2137.                 ads_printf("\nCan't get the row values for link") ;
  2138.                 break ;
  2139.             }
  2140.               /* Print the values */
  2141.             pack_printVals(pRow, ColQty) ;
  2142.               /* Free the values */
  2143.             asei_destroy_cdscpack(&pRow, ColQty) ;
  2144.         }
  2145.     } while(1) ;
  2146.     ase_dsc_free(&link) ;
  2147.     ase_dsc_free(&lp) ;
  2148.     asei_destroy_cdscpack(&pKey, KeyColQty) ;
  2149.     return retCode ;
  2150. } /* end of ls_scan() */
  2151.  
  2152. /****************************************************************************/
  2153. /*.doc ls_create(internal) */
  2154. /*+
  2155.   Creates the Link Selection asking the user
  2156.   with the criterias. Returns ASE_DSCNULL in the
  2157.   case of the error.
  2158. -*/
  2159. /****************************************************************************/
  2160. static ASE_LSDSC
  2161. /*FCN*/ls_create() 
  2162. {
  2163.     ASE_LPDSC lp=ASE_DSC_NULL ;        /* The Link Path Descriptor */
  2164.     ASE_LSDSC ls=ASE_DSC_NULL ;        /* Returning Link Selection desc */
  2165.     ASICOLDSC *pKey=(ASICOLDSC*)NULL ; /* The Key packet */
  2166.     ads_point pt ;                     /* The point to entity picking */
  2167.     ads_name EntName ;                 /* The Entity Name */
  2168.     ads_name EntSelName ;              /* Entity Selection name */
  2169.     char buf[BUFLEN] ;               /* The input buffer */
  2170.     char sqlbuf[BUFLEN] ;            /* The SQL condition buffer */
  2171.     EAseLinkType Type ;                /* The Link Type */
  2172.     int ColQty ;                       /* The Key Columns Quantity */
  2173.     int i ;                            /* The option number */
  2174.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  2175.  
  2176.     do {
  2177.           /* Print the menu */
  2178.         ads_printf("\nLink Selection Creating") ;
  2179.         ads_printf("\n  0 - Exit") ;
  2180.         ads_printf("\n  1 - Link Type") ;
  2181.         ads_printf("\n  2 - Entity") ;
  2182.         ads_printf("\n  3 - Entity Selection") ;
  2183.         ads_printf("\n  4 - Xref/Block Name") ;
  2184.         ads_printf("\n  5 - Link Path Name") ;
  2185.         ads_printf("\n  6 - Database Object Reference") ;
  2186.         ads_printf("\n  7 - Link Path Name & Entity") ;
  2187.         ads_printf("\n  8 - Database Object Reference & Entity") ;
  2188.         ads_printf("\n  9 - Link Path Name & Entity Selection") ;
  2189.         ads_printf("\n 10 - Database Object Reference & Entity Selection") ;
  2190.         ads_printf("\n 11 - Link Path Name & SQL Condition") ;
  2191.         ads_printf("\n 12 - Database Object Reference & SQL Condition") ;
  2192.         ads_printf("\n 13 - Link Path Name & Key Values") ;
  2193.         ads_printf("\n 14 - Database Object Reference & Key Values") ;
  2194.           /* Ask for the option number */
  2195.         if ( ads_getstring(0, "\nEnter the option number <0>:", buf) 
  2196.              != RTNORM ) {
  2197.             ads_printf("\nNo input") ;
  2198.             break ;
  2199.         }
  2200.           /* Defautl input check */
  2201.         if ( buf[0] == '\0' ) {
  2202.             break ;
  2203.         }
  2204.           /* Number test */
  2205.         if ( (i=atoi(buf)) == 0 && buf[0] != '0' ) {
  2206.             ads_printf("\nThe number is required") ;
  2207.             continue ;
  2208.         }
  2209.           /* Check the upper limit */
  2210.         if ( i > 14 || i < 0 ) {
  2211.             ads_printf("\nWrong option number") ;
  2212.             continue ;
  2213.         }
  2214.           /* Allocate the Link Selection descriptor */
  2215.         if ( (ls=ase_dsc_alloc(AseAppl, kAseApiLinkSel)) 
  2216.              == ASE_DSC_NULL ) {
  2217.             ads_abort("\nCan't allocate the Link Selection descriptor") ;
  2218.             break ;
  2219.         }
  2220.         switch(i) {
  2221.         case 1:                        /* Link Type */
  2222.               /* Ask for the Link Type */
  2223.             if ( ads_getstring(0, "\nDA Link/<Entity Link>:", buf) 
  2224.                  != RTNORM ) {
  2225.                 ads_printf("\nNo input") ;
  2226.                 break ;
  2227.             }
  2228.               /* Set the link type */
  2229.             if ( buf[0] == '\0' || buf[0] == 'E' || buf[0] == 'e' ) {
  2230.                 Type = kAseEntityLink ;
  2231.             } else {
  2232.                 Type = kAseDALink ;
  2233.             }
  2234.               /* Initialize the Link Selection by the */
  2235.               /* link type */
  2236.             retCode = ase_ls_initType(ls, Type) ;
  2237.             break ;
  2238.         case 2:                        /* Entity */
  2239.               /* Ask for the entity picking */
  2240.             if ( ads_entsel("\nSelect object:", EntName, pt) != RTNORM ) {
  2241.                 ads_printf("\nWrong entity name input") ;
  2242.                 break ;
  2243.             }
  2244.               /* Initialize the Link Selection by the */
  2245.               /* entity name */
  2246.             retCode = ase_ls_initEnt(ls, EntName) ;
  2247.             break ;
  2248.         case 3:                        /* Entity Selection */
  2249.               /* Ask for the entity selection */
  2250.             if ( ads_ssget(NULL, NULL, NULL, NULL, EntSelName) != RTNORM ) {
  2251.                 ads_printf("\nWrong entity selection") ;
  2252.                 break ;
  2253.             }
  2254.               /* Initialize the Link Selection by the */
  2255.               /* entity selection set name */
  2256.             retCode = ase_ls_initSel(ls, EntSelName) ;
  2257.               /* Free the entity selection */
  2258.             ads_ssfree(EntSelName) ;
  2259.             break ;
  2260.         case 4:                        /* Xref/Block Name */
  2261.               /* Ask for the Xref/Block name */
  2262.             if ( ads_getstring(0, "\nXref/Block name:", buf) != RTNORM ) {
  2263.                 ads_printf("\nNo input") ;
  2264.                 break ;
  2265.             }
  2266.               /* Initialize the Link Selection by the */
  2267.               /* Xref/Block name */
  2268.             retCode = ase_ls_initXName(ls, buf) ;
  2269.             break ;
  2270.         case 5:                        /* Link Path Name */
  2271.               /* Ask for the Link Path Name */
  2272.             if ( ads_getstring(0, "\nEnter LPN:", buf) != RTNORM ) {
  2273.                 ads_printf("\nNo input") ;
  2274.                 break ;
  2275.             }
  2276.               /* Initialize the Link Selection by the */
  2277.               /* Link Path Name */
  2278.             retCode = ase_ls_initLp(ls, buf) ;
  2279.             break ;
  2280.         case 6:                        /* Database Object Reference */
  2281.               /* Ask for the Database Object Reference entering */
  2282.             if ( (lp=lp_getDOR(NULL, kAsiFalse, kAsiFalse)) == ASE_DSC_NULL ) {
  2283.                 break ;
  2284.             }
  2285.               /* Initialize the Link Selection by the */
  2286.               /* Link Path Descriptor */
  2287.             retCode = ase_ls_initLpDsc(ls, lp) ;
  2288.             break ;
  2289.         case 7:                        /* Link Path Name & Entity */
  2290.               /* Ask for the Link Path Name */
  2291.             if ( ads_getstring(0, "\nEnter LPN:", buf) != RTNORM ) {
  2292.                 ads_printf("\nNo input") ;
  2293.                 break ;
  2294.             }
  2295.               /* Ask for the entity picking */
  2296.             if ( ads_entsel("\nSelect object:", EntName, pt) != RTNORM ) {
  2297.                 ads_printf("\nWrong entity name input") ;
  2298.                 break ;
  2299.             }
  2300.               /* Initialize the Link Selection by the */
  2301.               /* Link Path Name and entity name */
  2302.             retCode = ase_ls_initLpEnt(ls, buf, EntName) ;
  2303.             break ;
  2304.         case 8:                        /* Database Object Reference & Entity */
  2305.               /* Ask for the Database Object Reference entering */
  2306.             if ( (lp=lp_getDOR(NULL, kAsiFalse, kAsiFalse)) == ASE_DSC_NULL ) {
  2307.                 break ;
  2308.             }
  2309.               /* Ask for the entity picking */
  2310.             if ( ads_entsel("\nSelect object:", EntName, pt) != RTNORM ) {
  2311.                 ads_printf("\nWrong entity name input") ;
  2312.                 break ;
  2313.             }
  2314.               /* Initialize the Link Selection by the */
  2315.               /* Link Path Descriptor and entity name */
  2316.             retCode = ase_ls_initLpDscEnt(ls, lp, EntName) ;
  2317.             break ;
  2318.         case 9:                        /* Link Path Name & Entity Selection */
  2319.               /* Ask for the Link Path Name */
  2320.             if ( ads_getstring(0, "\nEnter LPN:", buf) != RTNORM ) {
  2321.                 ads_printf("\nNo input") ;
  2322.                 break ;
  2323.             }
  2324.               /* Ask for the entity selection */
  2325.             if ( ads_ssget(NULL, NULL, NULL, NULL, EntSelName) != RTNORM ) {
  2326.                 ads_printf("\nWrong entity selection") ;
  2327.                 break ;
  2328.             }
  2329.               /* Initialize the Link Selection by the */
  2330.               /* Link Path Name and entity selection set name */
  2331.             retCode = ase_ls_initLpSel(ls, buf, EntSelName) ;
  2332.               /* Free the entity selection */
  2333.             ads_ssfree(EntSelName) ;
  2334.             break ;
  2335.         case 10:                       /* Database Object Reference & Entity Selection */
  2336.               /* Ask for the Database Object Reference entering */
  2337.             if ( (lp=lp_getDOR(NULL, kAsiFalse, kAsiFalse)) == ASE_DSC_NULL ) {
  2338.                 break ;
  2339.             }
  2340.               /* Ask for the entity selection */
  2341.             if ( ads_ssget(NULL, NULL, NULL, NULL, EntSelName) != RTNORM ) {
  2342.                 ads_printf("\nWrong entity selection") ;
  2343.                 break ;
  2344.             }
  2345.               /* Initialize the Link Selection by the */
  2346.               /* Link Path Descriptor and entity selection set name */
  2347.             retCode = ase_ls_initLpDscSel(ls, lp, EntSelName) ;
  2348.               /* Free the entity selection */
  2349.             ads_ssfree(EntSelName) ;
  2350.             break ;
  2351.         case 11:                       /* Link Path Name & SQL Condition */
  2352.               /* Ask for the Link Path Name */
  2353.             if ( ads_getstring(0, "\nEnter LPN:", buf) != RTNORM ) {
  2354.                 ads_printf("\nNo input") ;
  2355.                 break ;
  2356.             }
  2357.               /* Ask for the SQL condition */
  2358.             if ( ads_getstring(0, "\n<WHERE> condition:", sqlbuf) != RTNORM ) {
  2359.                 ads_printf("\nNo input") ;
  2360.                 break ;
  2361.             }
  2362.               /* Initialize the Link Selection by the */
  2363.               /* Link Path Name and SQL condition */
  2364.             retCode = ase_ls_initLpCond(ls, buf, sqlbuf) ;
  2365.             break ;
  2366.         case 12:                       /* Database Object Reference & SQL Condition */
  2367.               /* Ask for the Database Object Reference entering */
  2368.             if ( (lp=lp_getDOR(NULL, kAsiFalse, kAsiTrue)) == ASE_DSC_NULL ) {
  2369.                 break ;
  2370.             }
  2371.               /* Ask for the SQL condition */
  2372.             if ( ads_getstring(0, "\n<WHERE> condition:", sqlbuf) != RTNORM ) {
  2373.                 ads_printf("\nNo input") ;
  2374.                 break ;
  2375.             }
  2376.               /* Initialize the Link Selection by the */
  2377.               /* Link Path Descriptor and SQL condition */
  2378.             retCode = ase_ls_initLpDscCond(ls, lp, sqlbuf) ;
  2379.             break ;
  2380.         case 13:                       /* Link Path Name & Key Values */
  2381.               /* Ask for the Link Path Name */
  2382.             if ( ads_getstring(0, "\nEnter LPN:", buf) != RTNORM ) {
  2383.                 ads_printf("\nNo input") ;
  2384.                 break ;
  2385.             }
  2386.               /* Allocate the Link Path descriptor */
  2387.             if ( (lp=ase_dsc_alloc(AseAppl, kAseApiLinkPath)) == ASE_DSC_NULL ) {
  2388.                 ads_abort("\nCan't allocate the Link Path descriptor") ;
  2389.                 break ;
  2390.             }
  2391.               /* Init the Link Path descriptor by the LPN */
  2392.             if ( ase_lp_initName(lp, buf) != kAsiGood ) {
  2393.                 ads_printf("\nWrong LPN is entered") ;
  2394.                 printAseErr(lp) ;
  2395.                 break ;
  2396.             }
  2397.               /* Get the key column description */
  2398.             if ( ase_lp_getKeyDsc(lp, &pKey, &ColQty) != kAsiGood ) {
  2399.                 ads_printf("\nCan't get the key column description") ;
  2400.                 printAseErr(lp) ;
  2401.                 break ;
  2402.             }
  2403.               /* Ask for the key values entering */
  2404.             ads_printf("\nEnter the key values") ;
  2405.             if ( pack_edit(pKey, ColQty) != kAsiGood ) {
  2406.                 ads_printf("\nWrong key input") ;
  2407.                 break ;
  2408.             }
  2409.               /* Initialize the Link Selection by the */
  2410.               /* Link Path Name and Key Values */
  2411.             retCode = ase_ls_initLpKey(ls, buf, pKey, ColQty) ;
  2412.             break ;
  2413.         case 14:                       /* Database Object Reference & Key Values */
  2414.               /* Ask for the Database Object Reference entering */
  2415.             if ( (lp=lp_getDOR(NULL, kAsiFalse, kAsiFalse)) == ASE_DSC_NULL ) {
  2416.                 break ;
  2417.             }
  2418.               /* Check the DOR */
  2419.             if ( ase_lp_getPathCode(lp) != kAseLpnCode &&
  2420.                  ase_lp_getPathCode(lp) != kAseTableCode ) {
  2421.                 ads_printf("\nNot the Table Reference is entered") ;
  2422.                 break ;
  2423.             }
  2424.               /* Get the description of the columns */
  2425.             if ( ase_lp_getPathCode(lp) == kAseLpnCode ) {
  2426.                   /* Get the key column description */
  2427.                 if ( ase_lp_getKeyDsc(lp, &pKey, &ColQty) != kAsiGood ) {
  2428.                     ads_printf("\nCan't get the key column description") ;
  2429.                     printAseErr(lp) ;
  2430.                     break ;
  2431.                 }
  2432.                 ads_printf("\nEnter the key values") ;
  2433.             } else {
  2434.                   /* Check whether or not Env is connected */
  2435.                   /* and connect in application */
  2436.                 if ( isConnected(lp) != kAsiTrue &&
  2437.                      connect(lp) != kAsiGood ) {
  2438.                     break ;
  2439.                 }
  2440.                   /* Get the description of the all table columns */
  2441.                 if ( lp_getTabCols(lp, &pKey, &ColQty) != kAsiGood ) {
  2442.                     ads_printf("\nCan't get the table column desc") ;
  2443.                     break ;
  2444.                 }
  2445.                 ads_printf("\nEnter the row values") ;
  2446.             }
  2447.               /* Ask for the values entering */
  2448.             if ( pack_edit(pKey, ColQty) != kAsiGood ) {
  2449.                 ads_printf("\nWrong key input") ;
  2450.                 break ;
  2451.             }
  2452.               /* Initialize the Link Selection by the */
  2453.               /* Link Path Descriptor and Key Values */
  2454.             retCode = ase_ls_initLpDscKey(ls, lp, pKey, ColQty) ;
  2455.             break ;
  2456.         }
  2457.     } while(0) ;
  2458.     if ( retCode == kAsiGood ) {
  2459.         ads_printf("\nThe Links Quantity #%ld", ase_ls_getQty(ls)) ;
  2460.     } else {
  2461.           /* Check the Link Selection errors */
  2462.         if ( ase_dsc_errQty(ls) ) {
  2463.               /* Check if no Link are satisfyed to condition */
  2464.             if ( ase_dsc_errDsc(ls, 0) != eAseEDscApi ||
  2465.                  ase_dsc_errCode(ls, 0) != eAseApiErrSelEmpty ) {
  2466.                 ads_printf("\nLink Selection creating problem") ;
  2467.                 printAseErr(ls) ;
  2468.             } else {
  2469.                 /* No related links */
  2470.                 ads_printf("\nNo Links correspond to the specified option") ;
  2471.             }
  2472.         } else {
  2473.             ads_printf("\nNo link selection is created") ;
  2474.         }
  2475.         ase_dsc_free(&ls) ;
  2476.     }
  2477.       /* Free the Link Path descriptor */
  2478.     ase_dsc_free(&lp) ;
  2479.       /* Destroy the key packet */
  2480.     asei_destroy_cdscpack(&pKey, ColQty) ;
  2481.     return ls ;
  2482. } /* end of ls_create() */
  2483.  
  2484. /****************************************************************************/
  2485. /*.doc ls_filter(internal) */
  2486. /*+
  2487.   This function filters the specified Link Selection.
  2488. -*/
  2489. /****************************************************************************/
  2490. static EAsiBoolean 
  2491. /*FCN*/ls_filter(ASE_LSDSC ls) 
  2492. {
  2493.     ASE_LPDSC lp=ASE_DSC_NULL ;        /* The Link Path Descriptor */
  2494.     ASICOLDSC *pKey=(ASICOLDSC*)NULL ; /* The Key packet */
  2495.     ads_point pt ;                     /* The point to entity picking */
  2496.     ads_name EntName ;                 /* The Entity Name */
  2497.     ads_name EntSelName ;              /* Entity Selection name */
  2498.     char buf[BUFLEN] ;               /* The input buffer */
  2499.     char sqlbuf[BUFLEN] ;            /* The SQL condition buffer */
  2500.     EAseLinkType Type ;                /* The Link Type */
  2501.     int ColQty ;                       /* The Key Columns Quantity */
  2502.     int i ;                            /* The option number */
  2503.     EAsiBoolean retCode = kAsiBad ;    /* The returning code */
  2504.  
  2505.     do {
  2506.           /* Clear the Link Selection errors */
  2507.         ase_dsc_errClear(ls) ;
  2508.           /* Print the menu */
  2509.         ads_printf("\nLink Selection Filtering") ;
  2510.         ads_printf("\n  1 - Link Type") ;
  2511.         ads_printf("\n  2 - Entity") ;
  2512.         ads_printf("\n  3 - Entity Selection") ;
  2513.         ads_printf("\n  4 - Xref/Block Name") ;
  2514.         ads_printf("\n  5 - Link Path Name") ;
  2515.         ads_printf("\n  6 - Database Object Reference") ;
  2516.         ads_printf("\n  7 - Link Path Name & SQL Condition") ;
  2517.         ads_printf("\n  8 - Database Object Reference & SQL Condition") ;
  2518.         ads_printf("\n  9 - Link Path Name & Key Values") ;
  2519.         ads_printf("\n 10 - Database Object Reference & Key Values") ;
  2520.         if ( ads_getstring(0, "\nEnter the option number <0>:", buf) 
  2521.              != RTNORM ) {
  2522.             ads_printf("\nNo input") ;
  2523.             break ;
  2524.         }
  2525.         if ( buf[0] == '\0' ) {
  2526.             retCode = kAsiBad ;
  2527.             break ;
  2528.         }
  2529.           /* Number test */
  2530.         if ( (i=atoi(buf)) == 0 && buf[0] != '0' ) {
  2531.             ads_printf("\nThe number is required") ;
  2532.             continue ;
  2533.         }
  2534.           /* Check the upper limit */
  2535.         if ( i >= 10 || i < 0 ) {
  2536.             ads_printf("\nWrong option number") ;
  2537.             continue ;
  2538.         }
  2539.         switch(i) {
  2540.         case 1:                        /* Link Type */
  2541.               /* Ask for the Link Type */
  2542.             if ( ads_getstring(0, "\nDA Link/<Entity Link>:", buf) 
  2543.                  != RTNORM ) {
  2544.                 ads_printf("\nNo input") ;
  2545.                 break ;
  2546.             }
  2547.               /* Set the link type */
  2548.             if ( buf[0] == '\0' || buf[0] == 'E' || buf[0] == 'e' ) {
  2549.                 Type = kAseEntityLink ;
  2550.             } else {
  2551.                 Type = kAseDALink ;
  2552.             }
  2553.               /* Filter the Link Selection by the */
  2554.               /* link type */
  2555.             retCode = ase_ls_intersectType(ls, Type) ;
  2556.             break ;
  2557.         case 2:                        /* Entity */
  2558.               /* Ask for the entity picking */
  2559.             if ( ads_entsel("\nSelect object:", EntName, pt) != RTNORM ) {
  2560.                 ads_printf("\nWrong entity name input") ;
  2561.                 break ;
  2562.             }
  2563.               /* Filter the Link Selection by the */
  2564.               /* entity name */
  2565.             retCode = ase_ls_intersectEnt(ls, EntName) ;
  2566.             break ;
  2567.         case 3:                        /* Entity Selection */
  2568.               /* Ask for the entity selection */
  2569.             if ( ads_ssget(NULL, NULL, NULL, NULL, EntSelName) != RTNORM ) {
  2570.                 ads_printf("\nWrong entity selection") ;
  2571.                 break ;
  2572.             }
  2573.               /* Filter the Link Selection by the */
  2574.               /* entity selection set name */
  2575.             retCode = ase_ls_intersectSel(ls, EntSelName) ;
  2576.               /* Free the entity selection */
  2577.             ads_ssfree(EntSelName) ;
  2578.             break ;
  2579.         case 4:                        /* Xref/Block Name */
  2580.               /* Ask for the Xref/Block name */
  2581.             if ( ads_getstring(0, "\nXref/Block name:", buf) != RTNORM ) {
  2582.                 ads_printf("\nNo input") ;
  2583.                 break ;
  2584.             }
  2585.               /* Filter the Link Selection by the */
  2586.               /* Xref/Block name */
  2587.             retCode = ase_ls_intersectXName(ls, buf) ;
  2588.             break ;
  2589.         case 5:                        /* Link Path Name */
  2590.               /* Ask for the Link Path Name */
  2591.             if ( ads_getstring(0, "\nEnter LPN:", buf) != RTNORM ) {
  2592.                 ads_printf("\nNo input") ;
  2593.                 break ;
  2594.             }
  2595.               /* Filter the Link Selection by the */
  2596.               /* Link Path Name */
  2597.             retCode = ase_ls_intersectLp(ls, buf) ;
  2598.             break ;
  2599.         case 6:                        /* Database Object Reference */
  2600.               /* Ask for the Database Object Reference entering */
  2601.             if ( (lp=lp_getDOR(NULL, kAsiFalse, kAsiFalse)) == ASE_DSC_NULL ) {
  2602.                 break ;
  2603.             }
  2604.               /* Filter the Link Selection by the */
  2605.               /* Link Path Descriptor */
  2606.             retCode = ase_ls_intersectLpDsc(ls, lp) ;
  2607.             break ;
  2608.         case  7:                       /* Link Path Name & SQL Condition */
  2609.               /* Ask for the Link Path Name */
  2610.             if ( ads_getstring(0, "\nEnter LPN:", buf) != RTNORM ) {
  2611.                 ads_printf("\nNo input") ;
  2612.                 break ;
  2613.             }
  2614.               /* Ask for the SQL condition */
  2615.             if ( ads_getstring(0, "\n<WHERE> condition:", sqlbuf) != RTNORM ) {
  2616.                 ads_printf("\nNo input") ;
  2617.                 break ;
  2618.             }
  2619.               /* Filter the Link Selection by the */
  2620.               /* Link Path Name and SQL condition */
  2621.             retCode = ase_ls_intersectLpCond(ls, buf, sqlbuf) ;
  2622.             break ;
  2623.         case  8:                       /* Database Object Reference & SQL Condition */
  2624.               /* Ask for the Database Object Reference entering */
  2625.             if ( (lp=lp_getDOR(NULL, kAsiFalse, kAsiTrue)) == ASE_DSC_NULL ) {
  2626.                 break ;
  2627.             }
  2628.               /* Ask for the SQL condition */
  2629.             if ( ads_getstring(0, "\n<WHERE> condition:", sqlbuf) != RTNORM ) {
  2630.                 ads_printf("\nNo input") ;
  2631.                 break ;
  2632.             }
  2633.               /* Filter the Link Selection by the */
  2634.               /* Link Path Descriptor and SQL condition */
  2635.             retCode = ase_ls_intersectLpDscCond(ls, lp, sqlbuf) ;
  2636.             break ;
  2637.         case  9:                       /* Link Path Name & Key Values */
  2638.               /* Ask for the Link Path Name */
  2639.             if ( ads_getstring(0, "\nEnter LPN:", buf) != RTNORM ) {
  2640.                 ads_printf("\nNo input") ;
  2641.                 break ;
  2642.             }
  2643.               /* Allocate the Link Path descriptor */
  2644.             if ( (lp=ase_dsc_alloc(AseAppl, kAseApiLinkPath)) == ASE_DSC_NULL ) {
  2645.                 ads_abort("\nCan't allocate the Link Path descriptor") ;
  2646.                 break ;
  2647.             }
  2648.               /* Init the Link Path descriptor by the LPN */
  2649.             if ( ase_lp_initName(lp, buf) != kAsiGood ) {
  2650.                 ads_printf("\nWrong LPN is entered") ;
  2651.                 printAseErr(lp) ;
  2652.                 break ;
  2653.             }
  2654.               /* Get the key column description */
  2655.             if ( ase_lp_getKeyDsc(lp, &pKey, &ColQty) != kAsiGood ) {
  2656.                 ads_printf("\nCan't get the key column description") ;
  2657.                 printAseErr(lp) ;
  2658.                 break ;
  2659.             }
  2660.               /* Ask for the key values entering */
  2661.             ads_printf("\nEnter the key values") ;
  2662.             if ( pack_edit(pKey, ColQty) != kAsiGood ) {
  2663.                 ads_printf("\nWrong key input") ;
  2664.                 break ;
  2665.             }
  2666.               /* Filter the Link Selection by the */
  2667.               /* Link Path Name and Key Values */
  2668.             retCode = ase_ls_intersectLpKey(ls, buf, pKey, ColQty) ;
  2669.             break ;
  2670.         case 10:                       /* Database Object Reference & Key Values */
  2671.               /* Ask for the Database Object Reference entering */
  2672.             if ( (lp=lp_getDOR(NULL, kAsiTrue, kAsiFalse)) == ASE_DSC_NULL ) {
  2673.                 break ;
  2674.             }
  2675.               /* Check the DOR */
  2676.             if ( ase_lp_getPathCode(lp) != kAseLpnCode &&
  2677.                  ase_lp_getPathCode(lp) != kAseTableCode ) {
  2678.                 ads_printf("\nNot the Table Reference is entered") ;
  2679.                 break ;
  2680.             }
  2681.               /* Get the description of the columns */
  2682.             if ( ase_lp_getPathCode(lp) == kAseLpnCode ) {
  2683.                   /* Get the key column description */
  2684.                 if ( ase_lp_getKeyDsc(lp, &pKey, &ColQty) != kAsiGood ) {
  2685.                     ads_printf("\nCan't get the key column description") ;
  2686.                     printAseErr(lp) ;
  2687.                     break ;
  2688.                 }
  2689.                 ads_printf("\nEnter the key values") ;
  2690.             } else {
  2691.                   /* Get the description of the all table columns */
  2692.                 ads_printf("\nEnter the row values") ;
  2693.                 if ( lp_getTabCols(lp, &pKey, &ColQty) != kAsiGood ) {
  2694.                     ads_printf("\nCan't get the table column desc") ;
  2695.                     break ;
  2696.                 }
  2697.                   /* Get the description of the all table columns */
  2698.                 ads_printf("\nEnter the row values") ;
  2699.             }
  2700.               /* Ask for the values entering */
  2701.             if ( pack_edit(pKey, ColQty) != kAsiGood ) {
  2702.                 ads_printf("\nWrong key input") ;
  2703.                 break ;
  2704.             }
  2705.               /* Filter the Link Selection by the */
  2706.               /* Link Path Descriptor and Key Values */
  2707.             retCode = ase_ls_intersectLpDscKey(ls, lp, pKey, ColQty) ;
  2708.             break ;
  2709.         }
  2710.     } while(0) ;
  2711.     if ( retCode == kAsiGood ) {
  2712.         ads_printf("\nThe New Links Quantity #%ld", ase_ls_getQty(ls)) ;
  2713.     } else {
  2714.         ads_printf("\nLink Selection isn't filtered") ;
  2715.         printAseErr(ls) ;
  2716.     }
  2717.       /* Free the Link Path descriptor */
  2718.     ase_dsc_free(&lp) ;
  2719.       /* Destroy the key packet */
  2720.     asei_destroy_cdscpack(&pKey, ColQty) ;
  2721.     return retCode ;
  2722. } /* ls_filter() */
  2723.  
  2724. /****************************************************************************/
  2725. /*.doc ls_print(internal) */
  2726. /*+
  2727.     Prints all of the links from the Link Selection related with the
  2728.     specified Link Path.
  2729.     The Link Path descriptor may be not specified (ASE_DEC_NULL).
  2730.     In this case this function prints all the links from link selection.
  2731.     KeyBuf specifies the key buffer. If it is not NULL,
  2732.     then the key buffer already exists and the
  2733.     link selection contains the links to one LPN.
  2734.     Otherwise, this function has to get key buffers
  2735.     for each LPN. If KeyBuf is specified, lp have to have the LPN.
  2736. -*/
  2737. /****************************************************************************/
  2738. static void        
  2739. /*FCN*/ls_print(ASE_LSDSC ls, 
  2740.                     ASE_LPDSC lp, 
  2741.                     ASICOLDSC KeyBuf[], 
  2742.                     int ColQty) 
  2743. {
  2744.     ASE_LPDSC lpbuf=ASE_DSC_NULL ;   /* The Link Path buffer */
  2745.     ASICOLDSC *pKey=NULL ;           /* The key column description */
  2746.     struct resbuf *pNames=NULL ;     /* The Link Path Names */
  2747.     struct resbuf *ptr ;             /* Scanning pointer */
  2748.     int colQty ;                     /* The key columns quantity */
  2749.  
  2750.     do {
  2751.         if ( lp != ASE_DSC_NULL ) {
  2752.               /* Filter the links to the DOR */
  2753.             if ( ase_ls_intersectLpDsc(ls, lp) != kAsiGood ) {
  2754.                 ads_printf("\nLink Selection intersecting problem") ;
  2755.                 printAseErr(ls) ;
  2756.                 break ;
  2757.             }
  2758.         } 
  2759.         /* Check the link selection length */
  2760.         if ( ase_ls_getQty(ls) == 0L ) {
  2761.             ads_printf("\nLink Selection is empty") ;
  2762.             printAseErr(ls) ;
  2763.             break ;
  2764.         }
  2765.         /* Get the Link Path Names */
  2766.         if ( (pNames=ase_ls_getLinkNames(ls)) == NULL ) {
  2767.             ads_printf("\nCan't get the LPN list") ;
  2768.             printAseErr(ls) ;
  2769.             break ;
  2770.         }
  2771.         if ( KeyBuf == (ASICOLDSC*)NULL ) {
  2772.             /* Prepare to print the non-homogenity links */
  2773.             if ( (lpbuf=ase_dsc_alloc(AseAppl, kAseApiLinkPath)) 
  2774.                  == ASE_DSC_NULL ) {
  2775.                 ads_abort("\nCan't allocate the Link Path descriptor") ;
  2776.                 break ;
  2777.             }
  2778.         }
  2779.         for ( ptr=pNames; ptr != NULL; ptr = ptr->rbnext ) {
  2780.             if ( KeyBuf != (ASICOLDSC*)NULL ) {
  2781.                 ls_printLp(ls, ptr->resval.rstring, KeyBuf, ColQty) ;
  2782.             } else {
  2783.                   /* Init the link Path */
  2784.                 if ( ase_lp_initName(lpbuf, ptr->resval.rstring) 
  2785.                      != kAsiGood ) {
  2786.                       ads_printf("\nWrong LPN %s is met", ptr->resval.rstring) ;
  2787.                       printAseErr(lpbuf) ;
  2788.                       break ;
  2789.                 }
  2790.                   /* Get the Key buffer */
  2791.                 if ( ase_lp_getKeyDsc(lpbuf, &pKey, &colQty) != kAsiGood ) {
  2792.                     ads_printf("\nCan't get the key desc for LPN %s", 
  2793.                     ptr->resval.rstring) ;
  2794.                     printAseErr(lpbuf) ;
  2795.                     break ;
  2796.                 }
  2797.                   /* Print the links for the LPN */
  2798.                 ls_printLp(ls, ptr->resval.rstring, pKey, colQty) ;
  2799.                 asei_destroy_cdscpack(&pKey, colQty) ;
  2800.             }
  2801.         }
  2802.     } while(0) ;
  2803.     if ( pNames != NULL )
  2804.         ads_relrb(pNames) ;
  2805.     ase_dsc_free(&lpbuf) ;
  2806. } /* end of ls_print() */
  2807.  
  2808. /****************************************************************************/
  2809. /*.doc ls_printLp(internal) */
  2810. /*+
  2811.   Prints the homogenity links from the Link Selection, having
  2812.   the specified Link Path Name.
  2813.   The key buffer has to be specified.
  2814. -*/
  2815. /****************************************************************************/
  2816. static void        
  2817. /*FCN*/ls_printLp(ASE_LSDSC ls, 
  2818.                       const char *pName,
  2819.                       ASICOLDSC KeyBuf[],
  2820.                       int ColQty) 
  2821. {
  2822.     ASE_LSDSC lsbuf=ASE_DSC_NULL ;   /* The link selection buffer */
  2823.     ASE_LINKDSC link=ASE_DSC_NULL ;  /* The Link descriptor */
  2824.     LinkID ID ;                      /* The link identifier */
  2825.     long index ;                     /* The scanning index */
  2826.     long length ;                    /* The Link Selection length */
  2827.  
  2828.     do {
  2829.           /* Copy */
  2830.         if ( (lsbuf=ase_dsc_clone(ls)) == ASE_DSC_NULL ) {
  2831.             ads_abort("\nCan't copy the link selection") ;
  2832.             printAseErr(ls) ;
  2833.             break ;
  2834.         }
  2835.           /* Filter the link selection */
  2836.         if ( ase_ls_intersectLp(lsbuf, pName) != kAsiGood ) {
  2837.             ads_printf("\nLink Selection intersecting problem") ;
  2838.             printAseErr(lsbuf) ;
  2839.             break ;
  2840.         }
  2841.           /* Check the link selection length */
  2842.         if ( (length = ase_ls_getQty(lsbuf)) == 0L ) {
  2843.             ads_printf("\nLink Selection is empty") ;
  2844.             printAseErr(lsbuf) ;
  2845.             break ;
  2846.         }
  2847.           /* Allocate the Link Descriptor */
  2848.         if ( (link=ase_dsc_alloc(AseAppl, kAseApiLink)) == ASE_DSC_NULL ) {
  2849.             ads_abort("\nCan't allocate the Link Descriptor") ;
  2850.             break ;
  2851.         }
  2852.           /* Scan the link selection */
  2853.         for ( index=0L ; index < length ; index++ ) {
  2854.               /* Get the identifier for the specified position */
  2855.             if ( (ID=ase_ls_getId(lsbuf, index)) == LINKID_NULL ) {
  2856.                 ads_printf("\nWrong Link Identifier in Link Sel") ;
  2857.                 printAseErr(lsbuf) ;
  2858.                 break ;
  2859.             }
  2860.               /* Init the attributes of the Link Descriptor */
  2861.             if ( ase_link_initId(link, ID) != kAsiGood ) {
  2862.                 ads_printf("\nCan't get the identifier of the Link %ld", ID) ;
  2863.                 printAseErr(link) ;
  2864.                 break ;
  2865.             }
  2866.               /* Print the Link Data */
  2867.             link_print(link, KeyBuf, ColQty) ;
  2868.         }
  2869.     } while(0) ;
  2870.     ase_dsc_free(&link) ;
  2871.     ase_dsc_free(&lsbuf) ;
  2872. } /* end of ls_printLp() */
  2873.  
  2874. /****************************************************************************/
  2875. /*.doc ls_printStat(internal) */
  2876. /*+
  2877.   This function prints the Link Selection statistic,
  2878.   using the specified Link Path descriptor.
  2879. -*/
  2880. /****************************************************************************/
  2881. static void        
  2882. /*FCN*/ls_printStat(ASE_LSDSC ls, ASE_LPDSC lp) 
  2883. {
  2884.     ASE_LSDSC lsbuf=ASE_DSC_NULL ; /* Link selection buffer */
  2885.     char buf[BUFLEN] ;               /* The buffer */
  2886.  
  2887.     do {
  2888.           /* Get the DOR */
  2889.         ase_lp_getName(lp, buf, BUFLEN, kAsePathCode) ;
  2890.           /* Copy the original link sel */
  2891.         if ( (lsbuf=ase_dsc_clone(ls)) == ASE_DSC_NULL ) {
  2892.             ads_abort("\nCan't copy the link selection") ;
  2893.             printAseErr(ls) ;
  2894.             break ;
  2895.         }
  2896.           /* Filter the links to the specified Link Path */
  2897.         if ( ase_ls_intersectLpDsc(lsbuf, lp) != kAsiGood ) {
  2898.             ads_printf("\nLink Selection intersecting problem") ;
  2899.             printAseErr(lsbuf) ;
  2900.             break ;
  2901.         }
  2902.         if ( ase_ls_getQty(lsbuf) == 0L ) {
  2903.             ads_printf("\nNo Links to DOR [%s]", buf) ;
  2904.             break ;
  2905.         }
  2906.           /* Statistic for All link types */
  2907.         ls_printTypeStat(lsbuf, lp, (char*)NULL, (char*)NULL, kAseUnknownLinkType) ;
  2908.           /* Statistic for Entity Links */
  2909.         ls_printTypeStat(lsbuf, lp, (char*)NULL, (char*)NULL, kAseEntityLink) ;
  2910.           /* Statistic for DA Links */
  2911.         ls_printTypeStat(lsbuf, lp, (char*)NULL, (char*)NULL, kAseDALink) ;
  2912.           /* Print the statistic for LPNs */
  2913.         ls_printLPNsStat(lsbuf) ;
  2914.           /* Print the statistic for Xref/Blocks */
  2915.         ls_printXsStat(lsbuf) ;
  2916.     } while(0) ;
  2917.     ase_dsc_free(&lsbuf) ;
  2918. } /* end of ls_printStat() */
  2919.  
  2920. /****************************************************************************/
  2921. /*.doc ls_printTypeStat(internal) */
  2922. /*+
  2923.   This function prints the information related with the
  2924.   specified link selection, Link Path and the type.
  2925. -*/
  2926. /****************************************************************************/
  2927. static void        
  2928. /*FCN*/ls_printTypeStat(ASE_LSDSC ls, 
  2929.                       ASE_LPDSC lp,
  2930.                       char *pName,
  2931.                       char *pXName,
  2932.                       EAseLinkType Type) 
  2933. {
  2934.    ASE_LSDSC lsbuf=ASE_DSC_NULL ;   /* The Link Selection for filtering */
  2935.    char buf[BUFLEN] ;               /* The buffer */
  2936.    ads_name ssbuf ;                 /* The entity selection buffer */
  2937.    long          Len=0L ;           /* Selection set length */
  2938.  
  2939.    do {
  2940.        if ( lp != ASE_DSC_NULL ) {
  2941.              /* Get the DOR */
  2942.            ase_lp_getName(lp, buf, BUFLEN, kAsePathCode) ;
  2943.        } else if ( pName != NULL ) {
  2944.            strcpy(buf, pName) ;
  2945.        } else if ( pXName != NULL ) {
  2946.            strcpy(buf, pXName) ;
  2947.        } else {
  2948.            break ;
  2949.        }
  2950.          /* Print the staticstic type */
  2951.        switch(Type) {
  2952.        case kAseEntityLink:            /* ENTITY LINK */
  2953.            ads_printf("\nEntity Links Statistic for %s [%s]", 
  2954.                  (lp!=ASE_DSC_NULL?"DOR":(pName!=NULL?"LPN":"Xref/Block")),
  2955.                  buf) ;
  2956.            break ;
  2957.        case kAseDALink:                /* DA LINK */
  2958.            ads_printf("\nDA Links Statistic for %s [%s]", 
  2959.                  (lp!=ASE_DSC_NULL?"DOR":(pName!=NULL?"LPN":"Xref/Block")),
  2960.                  buf) ;
  2961.            break ;
  2962.        case kAseUnknownLinkType:       /* ALL LINKS */
  2963.            ads_printf("\nLink Statistic for %s [%s]", 
  2964.                  (lp!=ASE_DSC_NULL?"DOR":(pName!=NULL?"LPN":"Xref/Block")),
  2965.                  buf) ;
  2966.        }
  2967.          /* Copy the original link sel */
  2968.        if ( (lsbuf=ase_dsc_clone(ls)) == ASE_DSC_NULL ) {
  2969.            ads_abort("\nCan't copy the link selection") ;
  2970.            printAseErr(ls) ;
  2971.            break ;
  2972.        }
  2973.          /* Filter the Link type */
  2974.        if ( Type != kAseUnknownLinkType ) {
  2975.            if ( ase_ls_intersectType(lsbuf, Type) != kAsiGood ) {
  2976.                ads_printf("\nLink Selection intersecting problem") ;
  2977.                printAseErr(lsbuf) ;
  2978.                break ;
  2979.            }
  2980.        }
  2981.        if ( ase_ls_getQty(lsbuf) == 0L ) {
  2982.            ads_printf("\nNo Links of the specified type") ;
  2983.        } else {
  2984.            ads_printf("\nLinks #%ld", ase_ls_getQty(lsbuf)) ;
  2985.              /* Get the entity selection */
  2986.            if ( ase_ls_getEntSel(lsbuf, ssbuf) != kAsiGood ) {
  2987.                ads_printf("\nCan't get the entity selection for Entity Links") ;
  2988.                printAseErr(lsbuf) ;
  2989.                break ;
  2990.            }
  2991.              /* Print the quantity of the entities */
  2992.            if ( ads_sslength(ssbuf, &Len) == RTNORM ) {
  2993.                ads_printf("\nEntities #%ld", Len) ;
  2994.            } else {
  2995.                ads_printf("\nWrong Entity selection name was got") ;
  2996.            }
  2997.              /* Free the entity selection */
  2998.            ads_ssfree(ssbuf) ;
  2999.        }
  3000.    } while(0) ;
  3001.    ase_dsc_free(&lsbuf) ;
  3002. } /* end of ls_printTypeStat() */
  3003.  
  3004. /****************************************************************************/
  3005. /*.doc ls_printLPNsStat(internal) */
  3006. /*+
  3007.   Gets the list of the LPNs for specified link selection and
  3008.   prints the links statistic for each LPN
  3009. -*/
  3010. /****************************************************************************/
  3011. static void        
  3012. /*FCN*/ls_printLPNsStat(ASE_LSDSC ls)
  3013. {
  3014.    ASE_LSDSC lsbuf=ASE_DSC_NULL ; /* Link selection buffer */
  3015.    struct resbuf *pBuf=NULL ;       /* Buffer for related names */
  3016.    struct resbuf *ptr ;             /* Scanning result buffer pointer */
  3017.      /* Get related LPNs */
  3018.    if ( (pBuf=ase_ls_getLinkNames(ls)) == NULL ) {
  3019.        ads_printf("\nNo related LPNs") ;
  3020.        return ;
  3021.    }
  3022.    for ( ptr=pBuf ; ptr != NULL ; ptr = ptr->rbnext ) {
  3023.          /* Copy the original link sel */
  3024.        if ( (lsbuf=ase_dsc_clone(ls)) == ASE_DSC_NULL ) {
  3025.            ads_abort("\nCan't copy the link selection") ;
  3026.            printAseErr(ls) ;
  3027.            break ;
  3028.        }
  3029.          /* Filter by the LPN */
  3030.        if ( ase_ls_intersectLp(lsbuf, ptr->resval.rstring) != kAsiGood ) {
  3031.            ads_printf("\nLink Selection intersecting problem") ;
  3032.            printAseErr(lsbuf) ;
  3033.            break ;
  3034.        }
  3035.          /* Print the statistic for that LPN */
  3036.        ls_printTypeStat(lsbuf, ASE_DSC_NULL, ptr->resval.rstring, 
  3037.                        (char*)NULL, kAseUnknownLinkType) ;
  3038.        ase_dsc_free(&lsbuf) ;
  3039.    }
  3040.    if ( pBuf != NULL ) {
  3041.        ads_relrb(pBuf) ;
  3042.    }
  3043. } /* end of ls_printLPNsStat() */
  3044.  
  3045. /****************************************************************************/
  3046. /*.doc ls_printXsStat(internal) */
  3047. /*+
  3048.   Gets the list of the Xref/Block names for specified link selection and
  3049.   prints the links statistic for each Xref/Block
  3050. -*/
  3051. /****************************************************************************/
  3052. static void        
  3053. /*FCN*/ls_printXsStat(ASE_LSDSC ls)
  3054. {
  3055.    ASE_LSDSC lsbuf=ASE_DSC_NULL ; /* Link selection buffer */
  3056.    struct resbuf *pBuf=NULL ;       /* Buffer for related names */
  3057.    struct resbuf *ptr ;             /* Scanning result buffer pointer */
  3058.      /* Get related LPNs */
  3059.    if ( (pBuf=ase_ls_getXNames(ls)) == NULL ) {
  3060.        ads_printf("\nNo related Xrefs/Blocks") ;
  3061.        return ;
  3062.    }
  3063.    for ( ptr=pBuf ; ptr != NULL ; ptr = ptr->rbnext ) {
  3064.          /* Copy the original link sel */
  3065.        if ( (lsbuf=ase_dsc_clone(ls)) == ASE_DSC_NULL ) {
  3066.            ads_abort("\nCan't copy the link selection") ;
  3067.            printAseErr(ls) ;
  3068.            break ;
  3069.        }
  3070.          /* Filter by the Xref/Block */
  3071.        if ( ase_ls_intersectXName(lsbuf, ptr->resval.rstring) != kAsiGood ) {
  3072.            ads_printf("\nLink Selection intersecting problem") ;
  3073.            printAseErr(lsbuf) ;
  3074.            break ;
  3075.        }
  3076.          /* Print the statistic for that Xref/Block */
  3077.        ls_printTypeStat(lsbuf, ASE_DSC_NULL, (char*)NULL,
  3078.                        ptr->resval.rstring, 
  3079.                        kAseUnknownLinkType) ;
  3080.        ase_dsc_free(&lsbuf) ;
  3081.    }
  3082.    if ( pBuf != NULL ) {
  3083.        ads_relrb(pBuf) ;
  3084.    }
  3085. } /* end of ls_printXsStat() */
  3086.  
  3087. /****************************************************************************/
  3088. /*.doc link_edit(internal) */
  3089. /*+
  3090.   Asks for the Link modification.
  3091.   After the succesfull updating, refreshes the link data
  3092.   in the specified link descriptor.
  3093. -*/
  3094. /****************************************************************************/
  3095. static EAsiBoolean 
  3096. /*FCN*/link_edit(ASE_LINKDSC link,
  3097.                 ASE_LPDSC lp, 
  3098.                 ASICOLDSC Key[], 
  3099.                 int ColQty) 
  3100. {
  3101.     ASE_LPDSC newlp=ASE_DSC_NULL ;        /* The new Link Path Descriptor */
  3102.     ASICOLDSC *pNewKey=(ASICOLDSC*)NULL ; /* New Key buffer */
  3103.     ASICOLDSC *pNewDAVals=(ASICOLDSC*)NULL ; /* New DA values buffer */
  3104.     ASE_LINKDSC newlink=ASE_DSC_NULL ;    /* The link buffer */
  3105.     ads_name ename ;                      /* New Entity Name */
  3106.     ads_point pt ;                         /* the point */
  3107.     char buf[BUFLEN] ;                  /* The buffer for entering */
  3108.     int DAColQty ;                        /* DA columns quantity */
  3109.     int newColQty ;                       /* New column quantity */
  3110.     int retword ;                      /* ads_getkword() returning value */
  3111.     EAsiBoolean retCode = kAsiBad ;       /* The returning flag */
  3112.  
  3113.       /* Make the link copy */
  3114.     if ( (newlink=ase_dsc_clone(link)) == ASE_DSC_NULL ) {
  3115.         ads_abort("\nCan't clone the Link Descriptor") ;
  3116.         return kAsiBad ;
  3117.     }
  3118.       /* Make the Link Path copy */
  3119.     if ( (newlp=ase_dsc_clone(lp)) == ASE_DSC_NULL ) {
  3120.         ads_abort("\nCan't clone the Link Path Descriptor") ;
  3121.         return kAsiBad ;
  3122.     }
  3123.       /* Make the Key Buffer copy */
  3124.     if ( (pNewKey=asei_dupl_cdscpack(Key, ColQty)) == (ASICOLDSC*)NULL ) {
  3125.         ads_abort("\nCan't clone the Key buffer") ;
  3126.         return kAsiBad ;
  3127.     }
  3128.     newColQty = ColQty ;
  3129.     do {
  3130.           /* Print the Link Data */
  3131.         link_print(newlink, pNewKey, newColQty) ;
  3132.           /*Lpn/Key/Entity/DAValues/Update/<eXit>*/
  3133.         if ( ads_initget(0, "L K E D U X") != RTNORM ) {
  3134.             break ;
  3135.         }
  3136.         retword=ads_getkword(
  3137.              "\nLpn/Key/Entity/DAValues/Update/<eXit>:", 
  3138.               buf) ;
  3139.         if ( retword != RTNORM && retword != RTNONE ) {
  3140.             break ;
  3141.         }
  3142.         if ( retword == RTNONE || buf[0] == '\0' || buf[0] == 'X' ) {
  3143.             retCode = kAsiGood ;
  3144.             break ;
  3145.         }
  3146.         switch(buf[0]) {
  3147.         case 'L':                      /* LPN */
  3148.             if ( ads_getstring(0, "\nEnter new LPN<>:", buf) != RTNORM ) {
  3149.                 ads_printf("\nNo input") ;
  3150.                 ase_dsc_free(&lp) ;
  3151.                 break ;
  3152.             }
  3153.             /* Check the new entered LPN */
  3154.             if ( ! ase_lp_cmpName(newlp, buf, kAseLpnCode) ) {
  3155.                   /* new LPN has entered */
  3156.                 if ( ase_lp_initName(newlp, buf) != kAsiGood ) {
  3157.                     ads_printf("\nWrong LPN was entered") ;
  3158.                     printAseErr(newlp) ;
  3159.                     break ;
  3160.                 }
  3161.                   /* Free the old key buffer */
  3162.                 asei_destroy_cdscpack(&pNewKey, newColQty) ;
  3163.                   /* Get the new Key buffer */
  3164.                 if ( ase_lp_getKeyDsc(newlp, &pNewKey, &newColQty)
  3165.                      != kAsiGood ) {
  3166.                     ads_printf("\nCan't get the Key Description") ;
  3167.                     printAseErr(newlp) ;
  3168.                     break ;
  3169.                 }
  3170.                   /* Update the new LPN */
  3171.                 if ( ase_link_setName(newlink, buf) != kAsiGood ) {
  3172.                     ads_printf("\nCan't update the LPN") ;
  3173.                     printAseErr(newlink) ;
  3174.                     break ;
  3175.                 }
  3176.             }
  3177.               /* Ask for the new Key column values now */
  3178.             if ( pack_edit(pNewKey, newColQty) != kAsiGood ) {
  3179.                 ads_printf("\nWrong Key input") ;
  3180.                 break ;
  3181.             }
  3182.               /* Update the new Key */
  3183.             if ( ase_link_setKey(newlink, pNewKey, newColQty) 
  3184.                  != kAsiGood ) {
  3185.                 ads_printf("\nCan't update the key") ;
  3186.                 printAseErr(newlink) ;
  3187.                 break ;
  3188.             }
  3189.             break ;
  3190.         case 'K':                      /* KEY */
  3191.               /* Ask for the new Key column values now */
  3192.             if ( pack_edit(pNewKey, newColQty) != kAsiGood ) {
  3193.                 ads_printf("\nWrong Key input") ;
  3194.                 break ;
  3195.             }
  3196.             if ( ase_link_setKey(newlink, pNewKey, newColQty) 
  3197.                  != kAsiGood ) {
  3198.                 ads_printf("\nCan't update the key") ;
  3199.                 printAseErr(newlink) ;
  3200.                 break ;
  3201.             }
  3202.             break ;
  3203.         case 'E':                      /* ENTITY */
  3204.               /* Ask for the entity name */
  3205.             if ( ads_entsel("\nSelect object:", ename, pt) != RTNORM ) {
  3206.                 ads_printf("\nWrong entity name input") ;
  3207.                 break ;
  3208.             }
  3209.               /* Set the new Entity Name */
  3210.             if ( ase_link_setEntity(newlink, ename) != kAsiGood ) {
  3211.                 ads_printf("\nCan't update the Entity") ;
  3212.                 printAseErr(newlink) ;
  3213.                 break ;
  3214.             }
  3215.             break ;
  3216.         case 'D':                      /* DA VALUES */
  3217.             if ( ase_link_getType(newlink) != kAseDALink ) {
  3218.                 ads_printf("\nNo DA Link") ;
  3219.                 break ;
  3220.             }
  3221.               /* Get the DA columns */
  3222.             if ( ase_link_getDACols(newlink, &pNewDAVals, &DAColQty) 
  3223.                  != kAsiGood ) {
  3224.                 ads_printf("\nCan't get the DA columns") ;
  3225.                 printAseErr(newlink) ;
  3226.                 break ;
  3227.             }
  3228.               /* Ask for the new DA values entering */
  3229.             if ( pack_edit(pNewDAVals, DAColQty) != kAsiGood ) {
  3230.                 ads_printf("\nWrong DA Columns input") ;
  3231.                 break ;
  3232.             }
  3233.               /* Update the new DA values */
  3234.             if ( ase_link_setDAValues(newlink, pNewDAVals, DAColQty) 
  3235.                  != kAsiGood ) {
  3236.                 ads_printf("\nCan't update the DA Column values") ;
  3237.                 printAseErr(newlink) ;
  3238.                 break ;
  3239.             }
  3240.             break ;
  3241.         case 'U':                      /* UPDATE */
  3242.               /* Real link updating */
  3243.             if ( ase_link_update(newlink) != kAsiGood ) {
  3244.                 ads_printf("\nCan't update the link") ;
  3245.                 printAseErr(newlink) ;
  3246.                 break ;
  3247.             }
  3248.               /* Refresh the input Link Descriptor */
  3249.             if ( ase_dsc_copyFrom(link, newlink) != kAsiGood ) {
  3250.                 ads_printf("\nCan't copy the Link Descriptor") ;
  3251.                 break ;
  3252.             }
  3253.             break ;
  3254.         }
  3255.     } while(1) ;
  3256.     asei_destroy_cdscpack(&pNewKey, newColQty) ;
  3257.     asei_destroy_cdscpack(&pNewDAVals, DAColQty) ;
  3258.     ase_dsc_free(&newlink) ;
  3259.     ase_dsc_free(&newlp) ;
  3260.     return retCode ;
  3261. } /* end of link_edit() */
  3262.  
  3263. /****************************************************************************/
  3264. /*.doc link_entMake(internal) */
  3265. /*+
  3266.   Makes an Entity link to the current row of the specified cursor 
  3267.   in accordance with the Link Path.
  3268. -*/
  3269. /****************************************************************************/
  3270. static EAsiBoolean 
  3271. /*FCN*/link_entMake(
  3272.                     ASICURSOR csr,      /* The cursor descriptor */
  3273.                     ASE_LPDSC lp        /* Link Path Descriptor */
  3274.                     ) 
  3275. {
  3276.     ASE_LINKDSC link=ASE_DSC_NULL ;     /* The link descriptor */
  3277.     ASICOLDSC *pKeyVal=(ASICOLDSC*)NULL ;  /* The key values */
  3278.     ads_point pt ;                         /* the point */
  3279.     ads_name ename ;                       /* Entity Name to be linked */
  3280.     char LPN[BUFLEN] ;                   /* The Link Path Name */
  3281.     int ColQty ;                           /* The key values quantity */
  3282.     EAsiBoolean retCode=kAsiBad ;          /* The returning code */
  3283.  
  3284.     do {
  3285.           /* Allocate the Link Descriptor */
  3286.         if ( (link=ase_dsc_alloc(AseAppl, kAseApiLink)) == ASE_DSC_NULL) {
  3287.             ads_abort("\nCan't allocate Link Descriptor") ;
  3288.             break ;
  3289.         }
  3290.           /* Test the Link Type Initialization function */
  3291.         if ( ase_link_initType(link, kAseEntityLink) != kAsiGood ) {
  3292.             ads_printf("\nCan't initialize an Entity Link Descriptor") ;
  3293.             printAseErr(link) ;
  3294.             break ;
  3295.         }
  3296.           /* Get the LPN */
  3297.         if ( ase_lp_getName(lp, LPN, BUFLEN, kAseLpnCode) != kAsiGood ) {
  3298.             ads_printf("\nCan't get the LPN") ;
  3299.             break ;
  3300.         }
  3301.           /* Get the key column description */
  3302.         if ( ase_lp_getKeyDsc(lp, &pKeyVal, &ColQty) != kAsiGood ) {
  3303.             ads_printf("\nCan't get the key column description") ;
  3304.             break ;
  3305.         }
  3306.           /* Get the key values */
  3307.         if ( csr_getVals(csr, &pKeyVal, &ColQty) != kAsiGood ) {
  3308.             ads_printf("\nCan't extract the key values") ;
  3309.             break ;
  3310.         }
  3311.           /* Ask for the entity name */
  3312.         if ( ads_entsel("\nSelect object:", ename, pt) != RTNORM ) {
  3313.             ads_printf("\nWrong entity name input") ;
  3314.             break ;
  3315.         }
  3316.           /* Init the Entity Link */
  3317.         if ( ase_link_initEntityLink(link, LPN, 
  3318.                                      pKeyVal, ColQty, ename) != kAsiGood ) {
  3319.             ads_printf("\nCan't initilize the Entity Link") ;
  3320.             printAseErr(link) ;
  3321.             break ;
  3322.         }
  3323.           /* Create the initialized link */
  3324.         if ( ase_link_create(link) != kAsiGood ) {
  3325.             ads_printf("\nCan't create the link") ;    
  3326.             printAseErr(link) ;
  3327.             break ;
  3328.         }
  3329.         retCode = kAsiGood ;
  3330.     } while(0) ;
  3331.     ase_dsc_free(&link) ;
  3332.     asei_destroy_cdscpack(&pKeyVal, ColQty) ;
  3333.     return retCode ;
  3334. } /* end of link_entMake() */
  3335.  
  3336. /****************************************************************************/
  3337. /*.doc link_daMake(internal) */
  3338. /*+
  3339.   Makes an DA link to the current row of the specified cursor 
  3340.   in accordance with the Link Path.
  3341. -*/
  3342. /****************************************************************************/
  3343. static EAsiBoolean 
  3344. /*FCN*/link_daMake(
  3345.                    ASICURSOR csr,      /* The cursor descriptor */
  3346.                    ASE_LPDSC lp        /* Link Path Descriptor */
  3347.                   )
  3348. {
  3349.     ASE_LINKDSC link=ASE_DSC_NULL ;     /* The link descriptor */
  3350.     ASICOLDSC *pKeyVal=(ASICOLDSC*)NULL ;  /* The key values */
  3351.     ASICOLDSC *pDACols=(ASICOLDSC*)NULL ;  /* The DA columns */
  3352.     ASICOLDSC *pTabCols=(ASICOLDSC*)NULL;  /* The table columns */
  3353.     ASICOLDSC col ;                        /* For cursor column getting */
  3354.     ads_point point ;         /* The DA insertion point */
  3355.     ads_real  angle ;         /* The DA rotation angle */
  3356.     ads_real  high ;          /* The DA text high */
  3357.     struct resbuf *pParms=NULL ;           /* DA Entity parameters */
  3358.     char LPN[BUFLEN] ;                   /* The Link Path Name */
  3359.     int ColQty ;                           /* The key values quantity */
  3360.     int DAColQty ;                         /* DA columns */
  3361.     int TabColQty ;                        /* The table columns */
  3362.     int index ;                            /* scanning index */
  3363.     EAsiBoolean retCode=kAsiBad ;          /* The returning code */
  3364.  
  3365.     do {
  3366.           /* Allocate the Link Descriptor */
  3367.         if ( (link=ase_dsc_alloc(AseAppl, kAseApiLink)) == ASE_DSC_NULL) {
  3368.             ads_abort("\nCan't allocate Link Descriptor") ;
  3369.             break ;
  3370.         }
  3371.           /* Test the Link Type Initialization function */
  3372.         if ( ase_link_initType(link, kAseDALink) != kAsiGood ) {
  3373.             ads_printf("\nCan't initialize an DA Link Descriptor") ;
  3374.             printAseErr(link) ;
  3375.             break ;
  3376.         }
  3377.           /* Get the LPN */
  3378.         if ( ase_lp_getName(lp, LPN, BUFLEN, kAseLpnCode) != kAsiGood ) {
  3379.             ads_printf("\nCan't get the LPN") ;
  3380.             break ;
  3381.         }
  3382.           /* Get the key column description */
  3383.         if ( ase_lp_getKeyDsc(lp, &pKeyVal, &ColQty) != kAsiGood ) {
  3384.             ads_printf("\nCan't get the key column description") ;
  3385.             break ;
  3386.         }
  3387.           /* Get the key values */
  3388.         if ( csr_getVals(csr, &pKeyVal, &ColQty) != kAsiGood ) {
  3389.             ads_printf("\nCan't extract the key values") ;
  3390.             break ;
  3391.         }
  3392.           /* Get the table columns */
  3393.         TabColQty = asi_colcount(csr) ;
  3394.           /* Allocate the description of table columns */
  3395.         if ( (pTabCols=asei_constr_cdscpack(TabColQty)) 
  3396.             == (ASICOLDSC*)NULL ) {
  3397.             ads_abort("\nCan't allocate the column packet") ;
  3398.             break ;
  3399.         }
  3400.           /* Copy the column description */
  3401.         for ( index=0 ; index < TabColQty ; index++ ) {
  3402.               /* Get the column description */
  3403.             if ( asi_cds(csr, index, &col) != kAsiGood ) {
  3404.                 ads_printf("\nCan't get the column description") ;
  3405.                 break ;
  3406.             }
  3407.               /* Copy the description */
  3408.             if ( (pTabCols[index]=asei_dupl_cdsc(col)) == 0L ) {
  3409.                 ads_abort("\nCan't duplicate the column description") ;
  3410.                 break ;
  3411.             }
  3412.         }
  3413.           /* Check the exit condition */
  3414.         if ( index < TabColQty ) {
  3415.             break ;
  3416.         }
  3417.           /* Ask for the DA column description */
  3418.         if ( pack_getCols(pTabCols, TabColQty,
  3419.                        &pDACols, &DAColQty) != kAsiGood ) {
  3420.             break ;
  3421.         }
  3422.           /* Ask for the DA column values */
  3423.         if ( csr_getVals(csr, &pDACols, &DAColQty) != kAsiGood ) {
  3424.             ads_printf("\nCan't extract the DA values") ;
  3425.             break ;
  3426.         }
  3427.           /* Ask for the insertion pointe*/
  3428.         if ( ads_getpoint(NULL, "\nDA insertion point:", point) != RTNORM ) {
  3429.             ads_printf("\nNo input") ;
  3430.             break ;
  3431.         }
  3432.           /* Ask for the text high */
  3433.         if ( ads_getdist(point, "\nDA text high:", &high) != RTNORM ) {
  3434.             ads_printf("\nNo input") ;
  3435.             break ;
  3436.         }
  3437.           /* Ask for the angle */
  3438.         if ( ads_getangle(point, "\nDA rotation angle:", &angle) != RTNORM ) {
  3439.             ads_printf("\nNo input") ;
  3440.             break ;
  3441.         }
  3442.           /* Build the parameters list */
  3443.         if ( (pParms=ads_buildlist(10, point, 
  3444.                                    40, high, 
  3445.                                    50, angle, 
  3446.                                    RTNONE)) == NULL ) {
  3447.             ads_abort("\nCan't build the resbuf list") ;
  3448.             break ;
  3449.         }
  3450.           /* Init the DA link */
  3451.         if ( ase_link_initDALink(link, LPN,
  3452.                                  pKeyVal, ColQty,
  3453.                                  pDACols, DAColQty,
  3454.                                  pParms) != kAsiGood ) {
  3455.             ads_printf("\nCan't initialize the DA link") ;
  3456.             printAseErr(link) ;
  3457.             break ;
  3458.         }
  3459.           /* Create the already initialized DA link */
  3460.         if ( ase_link_create(link) != kAsiGood ) {
  3461.             ads_printf("\nCan't create the DA link") ;
  3462.             printAseErr(link) ;
  3463.             break ;
  3464.         }
  3465.         retCode = kAsiGood ;
  3466.     } while(0) ;
  3467.     if ( pParms != NULL ) {
  3468.         ads_relrb(pParms) ;
  3469.     }
  3470.     ase_dsc_free(&link) ;
  3471.     asei_destroy_cdscpack(&pKeyVal, ColQty) ;
  3472.     asei_destroy_cdscpack(&pTabCols, DAColQty) ;
  3473.     asei_destroy_cdscpack(&pDACols, TabColQty) ;
  3474.     return retCode ;
  3475. } /* end of link_daMake() */
  3476.  
  3477. /****************************************************************************/
  3478. /*.doc link_print(internal) */
  3479. /*+
  3480.     Prints the data of the specified Link.
  3481.     This function uses the specified key column
  3482.     description as the buffer for getting the key values
  3483.     of the link. If Key is (ASICOLDSC*)NULL, then this 
  3484.     function tries to get the it allocating the 
  3485.     correspondent Link Path.
  3486. -*/
  3487. /****************************************************************************/
  3488. static void        
  3489. /*FCN*/link_print(
  3490.                  ASE_LINKDSC link,    /* The link descriptor */
  3491.                  ASICOLDSC Key[],     /* The key buffer */
  3492.                  int ColQty           /* The key columns quantity */
  3493.                 ) 
  3494. {
  3495.     ASE_LPDSC   lp=ASE_DSC_NULL ; /* Link Path Descriptor */
  3496.     ASICOLDSC  *pKey=NULL ;       /* The key buffer */
  3497.     ASICOLDSC  *pDACols=NULL ;    /* The DA column buffer */
  3498.     char       *pName=NULL;       /* The LPN buffer pointer */
  3499.     ads_name    ename ;           /* The entity name */
  3500.     int         colNum ;          /* The key columns quantity */
  3501.     int         DAColNum ;        /* The DA columns quantity */
  3502.     int         len ;             /* The LPN size */       
  3503.  
  3504.     do {
  3505.         /* Print the link type */
  3506.         if ( ase_link_getType(link) == kAseEntityLink ) {
  3507.             ads_printf("\nEntity Link") ;
  3508.         } else if ( ase_link_getType(link) == kAseDALink ) {
  3509.             ads_printf("\nDisplayble Attribute") ;
  3510.         } else {
  3511.             ads_printf("\nUnknown Link Type") ;
  3512.         }
  3513.         /* Print the link identifier */
  3514.         ads_printf("  ID: %ld", ase_link_getId(link)) ;
  3515.           /* Get the Link Path Name size */
  3516.         if ( (len=ase_link_getNameSize(link)) <= 0 ) {
  3517.             ads_printf("\nWrong LPN size") ;
  3518.             printAseErr(link) ;
  3519.             break ;
  3520.         }
  3521.           /* Allocate LPN buffer */
  3522.         if ( (pName=(char*)calloc(1, len)) == NULL ) {
  3523.             ads_abort("\nNo memory") ;
  3524.             break ;
  3525.         }
  3526.           /* Get the LPN */
  3527.         if ( ase_link_getName(link, pName, len) != kAsiGood ) {
  3528.             ads_printf("\nCan't get th link path name") ;
  3529.             printAseErr(link) ;
  3530.             break ;
  3531.         }
  3532.         ads_printf("\nLPN: %s", pName) ;
  3533.           /* Check the key buffer */
  3534.         if ( Key == (ASICOLDSC*)NULL ) {
  3535.               /* Get the Link Path Name */
  3536.             if ( (lp=ase_dsc_alloc(AseAppl, kAseApiLinkPath))
  3537.                  == ASE_DSC_NULL ) {
  3538.                 ads_abort("Can't allocate the Link Path descriptor") ;
  3539.                 break ;
  3540.             }
  3541.               /* Init the Link Path descriptor by the LPN */
  3542.             if ( ase_lp_initName(lp, pName) != kAsiGood ) {
  3543.                 ads_printf("\nInvalid LPN") ;
  3544.                 printAseErr(lp) ;
  3545.                 break ;
  3546.             }
  3547.               /* Get the key buffer */
  3548.             if ( ase_lp_getKeyDsc(lp, &pKey, &colNum) != kAsiGood ) {
  3549.                 ads_printf("\nCan't get the Key Description") ;
  3550.                 printAseErr(lp) ;
  3551.                 break ;
  3552.             }
  3553.         } else {
  3554.             /* The key buffer is specified */
  3555.             pKey = Key ;
  3556.             colNum = ColQty ;
  3557.         }
  3558.           /* Get the link key value */
  3559.         if ( ase_link_getKey(link, pKey, colNum) != kAsiGood ) {
  3560.             ads_printf("\nCan't get the Key Values") ;
  3561.             printAseErr(link) ;
  3562.             break ;
  3563.         }
  3564.           /* Print the key values */
  3565.         pack_print(pKey, colNum) ;
  3566.           /* Get the entity name */
  3567.         if ( ase_link_getEntity(link, ename) != kAsiGood ) {
  3568.             ads_printf("\nCan't get the Entity Name") ;
  3569.             printAseErr(link) ;
  3570.             break ;
  3571.         }
  3572.         ads_printf("\nEntity [%ld, %ld]", ename[0], ename[1]) ;
  3573.           /* Get the Xref/Block name */
  3574.         if ( pName != NULL )
  3575.             free (pName) ;
  3576.         if ( (pName=(char*)calloc(1, 33)) == NULL ) {
  3577.             ads_abort("\nNo Memory") ;
  3578.             break ;
  3579.         }
  3580.           /* Get the Xref/Block name */
  3581.         if ( ase_link_getXName(link, pName, 33) != kAsiGood ) {
  3582.             ads_printf("\nCan't get the Xref/Block name") ;
  3583.             printAseErr(link) ;
  3584.             break ;
  3585.         }
  3586.           /* Print Xref/Block name */
  3587.         if ( *pName != '\0' ) {
  3588.             ads_printf("\nXref/Block: %s", pName) ;
  3589.         }
  3590.         if ( ase_link_isUpdatable(link) == kAsiTrue ) {
  3591.             ads_printf("\nLink is updatable") ;
  3592.         } else {
  3593.             ads_printf("\nLink isn't updatable") ;
  3594.             /* Clear the non-updatability reasons data */
  3595.             ase_dsc_errClear(link) ;
  3596.         }
  3597.           /* Process DA Link */
  3598.         if ( ase_link_getType(link) == kAseDALink ) {
  3599.             /* Get the DA column names for the DA link */
  3600.             if ( ase_link_getDACols(link, &pDACols, &DAColNum) != kAsiGood ) {
  3601.                 ads_printf("\nCan't get the DA column names") ;
  3602.                 printAseErr(link) ;
  3603.                 break ;
  3604.             }
  3605.               /* Print the DA column values */
  3606.             pack_printVals(pDACols, DAColNum) ;
  3607.         }
  3608.     } while(0) ;
  3609.       /* Free LPN buffer */
  3610.     if ( pName != NULL ) {
  3611.         free(pName) ;
  3612.     }
  3613.     ase_dsc_free(&lp) ;
  3614.     if ( Key == (ASICOLDSC*)NULL ) {
  3615.         asei_destroy_cdscpack(&pKey, colNum) ;
  3616.     }
  3617.     asei_destroy_cdscpack(&pDACols, DAColNum) ;
  3618. } /* end of link_print() */
  3619.  
  3620. /****************************************************************************/
  3621. /*.doc pack_print(internal) */
  3622. /*+
  3623.   Prints the full column descriptions of the specified packet
  3624. -*/
  3625. /****************************************************************************/
  3626. static void        
  3627. /*FCN*/pack_print(ASICOLDSC Pack[],
  3628.                  int ColQty) 
  3629. {
  3630.     ASIDATADSC    datadsc=0L;
  3631.     ASIIDENT ident ;      /* Column identifier */
  3632.     char buf[BUFLEN] ;  /* The buffer for printing values */
  3633.     int index ;           /* The row column scanning index */
  3634.     EAsiBoolean isNull ;  /* Null value indicator */
  3635.  
  3636.     for ( index = 0 ; index < ColQty ; index++ ) {
  3637.         if ( asi_cdsc_name(Pack[index], &ident) != kAsiGood ) {
  3638.             ads_printf("\nCan't get the column identifier") ;
  3639.         }
  3640.         /* Get the ident name */
  3641.         if ( asi_get_ident(ident, buf, BUFLEN) == NULL ) {
  3642.             ads_printf("\nCan't get the identifier name") ;
  3643.             asi_destroy_ident(&ident) ;
  3644.             break ;
  3645.         }
  3646.         asi_destroy_ident(&ident) ;
  3647.         /* Print the ident name */
  3648.         ads_printf("\n%s, ", buf) ;
  3649.           /* Print column type */
  3650.         if (asi_cdsc_ddsc (Pack[index], &datadsc) == kAsiGood) {
  3651.             ads_printf(" %s : ", asi_ddsc_sqltype (datadsc, buf, 256));
  3652.             asi_destroy_ddsc (&datadsc);
  3653.         }
  3654.         asei_cdsc_rtype(Pack[index], &isNull)  ;
  3655.         if ( isNull == kAsiTrue ) {
  3656.             /* Null value */
  3657.             buf[0] = '.' ;
  3658.             buf[1] = '\0' ;
  3659.         } else {
  3660.             if ( asei_cdsc_getstr(Pack[index], buf, BUFLEN) != kAsiGood ) {
  3661.                 ads_printf("\nCan't get the value") ;
  3662.                 break ;
  3663.             }
  3664.         }
  3665.         ads_printf("%s", buf) ;
  3666.     }
  3667. } /* end of pack_print() */
  3668.  
  3669. /****************************************************************************/
  3670. /*.doc pack_printCols(internal) */
  3671. /*+
  3672.   Prints the column descriptions of the specified packet
  3673. -*/
  3674. /****************************************************************************/
  3675. static void        
  3676. /*FCN*/pack_printCols(ASICOLDSC Pack[],
  3677.                     int ColQty) 
  3678. {
  3679.     int index ;
  3680.     for (index=0 ; index < ColQty && Pack[index] != 0L ; index++ ) {
  3681.         ads_printf("\n") ;
  3682.         printColDsc(Pack[index]) ;
  3683.     }
  3684. } /* end of pack_printCols() */
  3685.  
  3686. /****************************************************************************/
  3687. /*.doc pack_printVals(internal) */
  3688. /*+
  3689.     This function prints the values of the specifeid packet
  3690. -*/
  3691. /****************************************************************************/
  3692. static void        
  3693. /*FCN*/pack_printVals(ASICOLDSC Pack[], int ColQty) 
  3694. {
  3695.     ASIIDENT ident ;      /* Column identifier */
  3696.     char buf[BUFLEN] ;  /* The buffer for printing values */
  3697.     int index ;           /* The row column scanning index */
  3698.     EAsiBoolean isNull ;  /* Null value indicator */
  3699.  
  3700.     for ( index = 0 ; index < ColQty ; index++ ) {
  3701.         if ( asi_cdsc_name(Pack[index], &ident) != kAsiGood ) {
  3702.             ads_printf("\nCan't get the column identifier") ;
  3703.         }
  3704.         /* Get the ident name */
  3705.         if ( asi_get_ident(ident, buf, BUFLEN) == NULL ) {
  3706.             ads_printf("\nCan't get the identifier name") ;
  3707.             asi_destroy_ident(&ident) ;
  3708.             break ;
  3709.         }
  3710.         asi_destroy_ident(&ident) ;
  3711.         /* Print the ident name */
  3712.         ads_printf("\n%s : ", buf) ;
  3713.         asei_cdsc_rtype(Pack[index], &isNull)  ;
  3714.         if ( isNull == kAsiTrue ) {
  3715.             /* Null value */
  3716.             buf[0] = '.' ;
  3717.             buf[1] = '\0' ;
  3718.         } else {
  3719.             if ( asei_cdsc_getstr(Pack[index], buf, BUFLEN) != kAsiGood ) {
  3720.                 ads_printf("\nCan't get the value") ;
  3721.                 break ;
  3722.             }
  3723.         }
  3724.         ads_printf("%s", buf) ;
  3725.     }
  3726. } /* end of pack_printVals() */
  3727.  
  3728. /****************************************************************************/
  3729. /*.doc pack_edit(internal) */
  3730. /*+
  3731.     This function edits the values of the specifeid packet
  3732. -*/
  3733. /****************************************************************************/
  3734. static EAsiBoolean 
  3735. /*FCN*/pack_edit(ASICOLDSC Pack[], int ColQty) 
  3736. {
  3737.     ASIIDENT ident ;      /* Column identifier */
  3738.     char buf[BUFLEN] ;  /* The buffer for printing values */
  3739.     int index ;           /* The row column scanning index */
  3740.     EAsiBoolean isNull ;  /* Null value indicator */
  3741.  
  3742.     for ( index = 0 ; index < ColQty ; index++ ) {
  3743.         if ( asi_cdsc_name(Pack[index], &ident) != kAsiGood ) {
  3744.             ads_printf("\nCan't get the column identifier") ;
  3745.         }
  3746.         /* Get the ident name */
  3747.         if ( asi_get_ident(ident, buf, BUFLEN) == NULL ) {
  3748.             ads_printf("\nCan't get the identifier name") ;
  3749.             asi_destroy_ident(&ident) ;
  3750.             break ;
  3751.         }
  3752.         asi_destroy_ident(&ident) ;
  3753.         /* Print the ident name */
  3754.         ads_printf("\n%s <", buf) ;
  3755.         asei_cdsc_rtype(Pack[index], &isNull)  ;
  3756.         if ( isNull == kAsiTrue ) {
  3757.             /* Null value */
  3758.             buf[0] = '.' ;
  3759.             buf[1] = '\0' ;
  3760.         } else {
  3761.             if ( asei_cdsc_getstr(Pack[index], buf, BUFLEN) != kAsiGood ) {
  3762.                 ads_printf("\nCan't get the value") ;
  3763.                 break ;
  3764.             }
  3765.         }
  3766.         ads_printf("%s", buf) ;
  3767.         if ( ads_getstring(0, "> : ", buf) != RTNORM ) {
  3768.             ads_printf("\nNo input") ;
  3769.             break ;
  3770.         }
  3771.         if ( buf[0] == '.' ) {
  3772.             if ( asei_cdsc_setnull(Pack[index]) != kAsiGood ) {
  3773.                 ads_printf("\nCan't nullify the value") ;
  3774.                 break ;
  3775.             }
  3776.         } else if ( buf[0] != '\0' ) {
  3777.             if ( asei_cdsc_setstr(Pack[index], buf) != kAsiGood ) {
  3778.                 ads_printf("\nNon-appropriate value is entered") ;
  3779.                 break ;
  3780.             }
  3781.         }
  3782.     }
  3783.     if ( index < ColQty ) {
  3784.         return kAsiBad ;
  3785.     }
  3786.     return kAsiGood ;
  3787. } /* end of pack_edit() */
  3788.  
  3789. /****************************************************************************/
  3790. /*.doc pack_getCols(internal) */
  3791. /*+
  3792.   Printf the desc of the packet columns and asks for the
  3793.   column names entering.
  3794.   The ColList, ColQty have to specify the base columns description.
  3795.   The selected column description is retreived in the
  3796.   pCols, pColQty arguments.
  3797.   Returns kAsiBad if something is wrong or if no one
  3798.   column was selected.
  3799. -*/
  3800. /****************************************************************************/
  3801. static EAsiBoolean 
  3802. /*FCN*/pack_getCols(ASICOLDSC ColList[],
  3803.                  int ColQty, 
  3804.                  ASICOLDSC *pCols[],
  3805.                  int *pColQty) 
  3806. {
  3807.     ASICOLDSC *pRetdsc = NULL ;     /* The returning columns packet */
  3808.     ASIIDENT newident=0L ;          /* New Column identifier */
  3809.     ASIIDENT ident=0L ;             /* Existing column identifier */        
  3810.     ASICOLDSC coldsc=0L ;           /* Column description */
  3811.     char buf[BUFLEN] ;              /* The buffer for dialogue asking */
  3812.     int RetQty=0 ;                  /* The returning columns quantity */
  3813.     int i ;
  3814.  
  3815.       /* Allocate the pointers array */
  3816.     if ( (pRetdsc=asei_constr_cdscpack(ColQty)) == (ASICOLDSC*)NULL ||
  3817.          asi_constr_ident(&newident) != kAsiGood ||
  3818.          asi_constr_ident(&ident) != kAsiGood ) {
  3819.         ads_abort("\nNo memory") ;
  3820.         return kAsiBad ;
  3821.     }
  3822.     while(1) {
  3823.         ads_printf("\nSelected Columns:") ;
  3824.         if ( RetQty > 0 ) {
  3825.               /* Print the key columns */
  3826.             pack_printCols(pRetdsc, RetQty) ;
  3827.         } else {
  3828.             ads_printf("\nNo") ;
  3829.         }
  3830.         if ( ads_getstring(0, "\nEnter the column name"
  3831.                               "or <?> for the available names: ", 
  3832.                               buf) != RTNORM ) {
  3833.             ads_printf("\nNo input") ;
  3834.             continue ;
  3835.         }
  3836.         if ( buf[0] == '\0' ) {
  3837.             break ;
  3838.         }
  3839.         if ( buf[0] == '?' ) {
  3840.               /* Print the table column */
  3841.             pack_printCols(ColList, ColQty) ;
  3842.             continue ;
  3843.         } 
  3844.           /* Initialize the identifier */
  3845.         if ( asei_ident_init(newident, buf) != kAsiGood ) {
  3846.             ads_printf("\nWrong column name") ;
  3847.             continue ;
  3848.         }
  3849.           /* Find the correspondent column description */
  3850.         for ( i=0 ; i < ColQty ; i++ ) {
  3851.               /* Get the ident of the available column */
  3852.             if ( asi_cdsc_name(ColList[i], &ident) == kAsiGood ) {
  3853.                 if ( asei_ident_cmp(newident, ident) ) {
  3854.                     break ;
  3855.                 }
  3856.             }
  3857.         }
  3858.         if ( i >= ColQty ) {
  3859.             ads_printf("\nNon-available column name") ;
  3860.             continue ;
  3861.         }
  3862.           /* Duplicate it and add to the Key dsc array */
  3863.         pRetdsc[RetQty] = asei_dupl_cdsc(ColList[i]) ;
  3864.         RetQty++ ;
  3865.         
  3866.           /* Check the top limit */
  3867.         if ( RetQty >= ColQty ) {
  3868.             ads_printf("\nThe max column quantity is exceeded") ;
  3869.             break ;
  3870.         }
  3871.     }
  3872.     asi_destroy_ident(&ident) ;
  3873.     asi_destroy_ident(&newident) ;
  3874.     if ( RetQty ) {
  3875.         *pCols = pRetdsc ;
  3876.         *pColQty = RetQty ;
  3877.         return kAsiGood ;
  3878.     } else {
  3879.         asei_destroy_cdscpack(&pRetdsc, ColQty) ;
  3880.         return kAsiBad ;
  3881.     }
  3882. }  /* end of pack_getCols() */
  3883.  
  3884. /****************************************************************************/
  3885. /*.doc connect(internal) */
  3886. /*+
  3887.   This function asks for the user name & password
  3888.   and connects application to the environment, which name has to
  3889.   be specified in the Link Path descriptor.
  3890. -*/
  3891. /****************************************************************************/
  3892. static EAsiBoolean
  3893. /*FCN*/connect(ASE_LPDSC lp) 
  3894. {
  3895.     EAsiBoolean retCode=kAsiBad ;   /* The error sign */
  3896.     char envbuf [BUFLEN] ;          /* Env name */
  3897.     char usrbuf [BUFLEN] ;          /* user name */
  3898.     char pswbuf [BUFLEN] ;          /* password */
  3899.  
  3900.     do {
  3901.         if ( isConnected(lp) == kAsiTrue ) {
  3902.                 /* The Environment is already connected */
  3903.               retCode = kAsiGood ;
  3904.               break ;
  3905.         }
  3906.           /* Disconnect from the another Environment */
  3907.         disconnect() ;
  3908.           /* Get the Env Name */
  3909.         ase_lp_getName(lp, envbuf, BUFLEN, kAseEnvCode) ;
  3910.         ads_printf("\nEnvironment %s", envbuf) ;
  3911.         /* Check the Environment */
  3912.         if ( envbuf[0] == '\0' ) {
  3913.             ads_printf("\nEnvironment isn't specified - no connections") ;
  3914.             retCode = kAsiGood ;
  3915.             break ;
  3916.         }
  3917.         ads_getstring(0, "\nUsername:", usrbuf) ;
  3918.         ads_getstring(0, "\nPassword:", pswbuf) ;
  3919.           /* Construct the session */
  3920.         if ( asi_constr_session  (&AsiSes, AsiAppl) != kAsiGood ) {
  3921.             ads_printf("\nCan't construct ASI session desc") ;
  3922.             break ;
  3923.         }
  3924.           /* Connect to the Env */
  3925.         if ( asi_connect (AsiSes, envbuf, usrbuf, pswbuf) != kAsiGood ) {
  3926.             ads_printf("\nCan't connect") ;
  3927.             break ;
  3928.         }
  3929.         if ( (AseEnv=ase_dsc_clone(lp)) == ASE_DSC_NULL ) {
  3930.             ads_abort("\nCan't clone Link Path descriptor") ;
  3931.             break ;
  3932.         }
  3933.         retCode = kAsiGood ;
  3934.     } while(0) ;
  3935.     if ( retCode != kAsiGood ) {
  3936.         asi_destroy_session(&AsiSes, AsiAppl) ;
  3937.         ase_dsc_free(&AseEnv) ;
  3938.     }
  3939.     return retCode ;
  3940. } /* end of connect() */
  3941.  
  3942. /****************************************************************************/
  3943. /*.doc connectAse(internal) */
  3944. /*+
  3945.   Connects ASE to the environment, which name has to
  3946.   be specified in the Link Path descriptor.
  3947.   Returns kAsiGood in the case of success, kAsiBad otherwise.
  3948. -*/
  3949. /****************************************************************************/
  3950. static EAsiBoolean 
  3951. /*FCN*/connectAse(ASE_LPDSC lp) 
  3952. {
  3953.     struct resbuf *pParms=NULL ;    /* The calling parameters list */
  3954.     char envbuf[BUFLEN] ;           /* The buffer for Env name */
  3955.     char usrbuf [BUFLEN] ;          /* user name */
  3956.     char pswbuf [BUFLEN] ;          /* password */
  3957.     EAsiBoolean retCode=kAsiBad ;   /* The returning code */
  3958.  
  3959.     do {
  3960.           /* Check, whether or not ASE is connected to Env */
  3961.         if ( ase_lp_getStatus(lp) & ASE_DO_CON ) {
  3962.             retCode = kAsiGood ;     /* connection exists */
  3963.             break ;
  3964.         }
  3965.           /* Get the Env name */
  3966.         if ( ase_lp_getName(lp, envbuf, BUFLEN, kAseEnvCode) != kAsiGood ) {
  3967.             ads_printf("\nCan't get the Env name") ;
  3968.             printAseErr(lp) ; 
  3969.             break ;
  3970.         }
  3971.         ads_printf("\nConnecting ASE to environment %s", envbuf) ;
  3972.         if ( envbuf[0] == '\0' ) {
  3973.             retCode = kAsiGood ;     /* don't need connection */
  3974.             ads_printf("\nEnvironment name isn't specified") ;
  3975.             break ;
  3976.         }
  3977.         ads_getstring(0, "\nUsername:", usrbuf) ;
  3978.         ads_getstring(0, "\nPassword:", pswbuf) ;
  3979.           /* Build the calling parameters list */
  3980.         if ( (pParms=
  3981.               ads_buildlist(RTSTR, "E",
  3982.                             RTSTR, envbuf,
  3983.                             RTSTR, "O",
  3984.                             RTSTR, "C",
  3985.                             RTSTR, usrbuf,
  3986.                             RTSTR, pswbuf,
  3987.                             RTSTR, "",
  3988.                             RTSTR, "",
  3989.                             RTNONE)) == NULL ) {
  3990.             ads_abort("\nCan't build resbuf") ;
  3991.             break ;
  3992.         }
  3993.           /* Call ASE */
  3994.         if ( callCmd("_ASEADMIN", pParms)!= RTNORM ) {
  3995.             ads_printf("\nError in call of ASEADMIN command") ;
  3996.               /* Print the global ASE error */
  3997.             asesmp_err() ;
  3998.             break ;
  3999.         }
  4000.           /* Print the global ASE error */
  4001.         asesmp_err() ;
  4002.           /* Check whether ASE has connected to Env indeed */
  4003.         if ( ase_lp_getStatus(lp) & ASE_DO_CON ) {
  4004.             retCode = kAsiGood ;
  4005.         } else {
  4006.             ads_printf("\nError in connecting ASE to environment %s", envbuf) ;
  4007.         }
  4008.     } while(0) ;
  4009.     if ( pParms != NULL ) {
  4010.         ads_relrb(pParms) ;
  4011.     }
  4012.     return retCode ;
  4013. } /* end of connectAse() */
  4014.  
  4015. /****************************************************************************/
  4016. /*.doc getSession(internal) */
  4017. /*+
  4018.     Returns the global connected ASI session descriptor
  4019. -*/
  4020. /****************************************************************************/
  4021. static ASISESSION  
  4022. /*FCN*/getSession() 
  4023. {
  4024.     return AsiSes ;
  4025. } /* end of getSession() */
  4026.  
  4027. /****************************************************************************/
  4028. /*.doc isConnected(internal) */
  4029. /*+
  4030.     This function checks, whether the Environment,
  4031.     specified in the Link Path descriptor, is connected.
  4032.     The global variable AsiSes is responsible for the global
  4033.     connection support. AseEnv global variable is responsible
  4034.     for the keeping the connected Environment name.
  4035.     If the lp == ASE_DSC_NULL, then this function
  4036.     gets whether or not the global environment is connected.
  4037. -*/
  4038. /****************************************************************************/
  4039. static EAsiBoolean 
  4040. /*FCN*/isConnected(ASE_LPDSC lp) 
  4041. {
  4042.     if ( lp == ASE_DSC_NULL ) {
  4043.         if ( AsiSes != 0L ) {
  4044.             return kAsiTrue ;
  4045.         }
  4046.     } else {
  4047.         if ( AsiSes != 0L &&
  4048.              AseEnv != ASE_DSC_NULL && 
  4049.              ase_lp_cmpDscName(AseEnv, lp, kAseEnvCode) ) {
  4050.             return kAsiTrue ;
  4051.         }
  4052.     }
  4053.     return kAsiFalse ;
  4054. } /* end of isConnected() */
  4055.  
  4056. /****************************************************************************/
  4057. /*.doc disconnect(internal) */
  4058. /*+
  4059.   This function disconnects the from connected Environment
  4060. -*/
  4061. /****************************************************************************/
  4062. static void 
  4063. /*FCN*/disconnect() 
  4064. {
  4065.     if ( isConnected(ASE_DSC_NULL) == kAsiTrue ) {
  4066.         ase_dsc_free(&AseEnv) ;
  4067.         asi_destroy_session(&AsiSes, AsiAppl) ;
  4068.     }
  4069. } /* end of disconnect() */
  4070.  
  4071. /****************************************************************************/
  4072. /*.doc printAseErr(internal) */
  4073. /*+
  4074.     This function prints the error data for the given
  4075.     ASE descriptor
  4076. -*/
  4077. /****************************************************************************/
  4078. static void                               
  4079. /*FCN*/printAseErr (ASE_DSC dsc) 
  4080. {
  4081.     char buf[BUFLEN] ;/* The error message buffer */
  4082.     char *ptr ;         /* The Diagnostic parameter name pointer */
  4083.     int parcode ;       /* The diagnostic parameter code */
  4084.     int isstr ;         /* The diagnostic parameter type */
  4085.     int intpar ;        /* Integer parameter value */
  4086.  
  4087.     int index ;         /* Error index */
  4088.     int pindex ;        /* Error parameters index */
  4089.  
  4090.     if ( ase_dsc_errQty(dsc) ) {
  4091.         ads_printf("\nASE Errors #%d", ase_dsc_errQty(dsc)) ;
  4092.     }
  4093.     for ( index=0 ; index < ase_dsc_errQty(dsc) ; index++ ) {
  4094.         ads_printf("\nError N%d\n----------", index) ;
  4095.         ads_printf("\nDescription Code: %d", ase_dsc_errDsc(dsc, index)) ;
  4096.         ads_printf("\nCode: %d", ase_dsc_errCode(dsc, index)) ;
  4097.           // Get the error message
  4098.         ase_dsc_errMsg(dsc, index, buf, BUFLEN) ;
  4099.         ads_printf("\nMessage: %s", buf) ;
  4100.           /* Scan all of the diagnostic parameters(ASE & ASI), */
  4101.           /* that ASE supports */
  4102.         ads_printf("\nDiagnostic Parameters are:") ;
  4103.         for ( pindex=0 ; 
  4104.               (ptr=(char*)ase_dsc_errDiagParNameCode(dsc, pindex, 
  4105.                                             &parcode, &isstr)) != NULL ;
  4106.               pindex++ ) {
  4107.             /* Get the parameter values */
  4108.             if ( isstr ) {
  4109.                 /* Get the string parameter value */
  4110.                 if ( ase_dsc_errDiagParStr(dsc, index, parcode, buf, BUFLEN) 
  4111.                      == kAsiGood ) {
  4112.                     ads_printf("\n%s: [%s]", ptr, buf) ;
  4113.                 }
  4114.             } else {
  4115.                 /* Get the integer parameter value */
  4116.                 if ( ase_dsc_errDiagParInt(dsc, index, parcode, &intpar) ) {
  4117.                     ads_printf("\n%s: [%d]", ptr, intpar) ;
  4118.                 }
  4119.             }
  4120.         }
  4121.     }
  4122. } /* end of printAseErr() */
  4123.  
  4124. /****************************************************************************/
  4125. /*.doc printAsiErr(internal) */
  4126. /*+
  4127.     Gets the errors from the specified ASI handle, put it into the
  4128.     AseAppl global descriptor and prints on the screen.
  4129.     Clear the descriptor then.
  4130. -*/
  4131. /****************************************************************************/
  4132. static void 
  4133. /*FCN*/printAsiErr(ASIHANDLE handle)
  4134. {
  4135.     if ( handle != 0L && ase_dsc_errInitAsi(AseAppl, handle) == kAsiGood ) {
  4136.         printAseErr(AseAppl) ;    
  4137.         ase_dsc_errClear(AseAppl) ;
  4138.     }
  4139. } /* printAsiErr() */
  4140.  
  4141. /****************************************************************************/
  4142. /*.doc testDsc(internal) */
  4143. /*+
  4144.   This function demonstrates the functions processing the
  4145.   general ASE descriptors. Returns kAsiBad if something is wrong.
  4146. -*/
  4147. /****************************************************************************/
  4148. static EAsiBoolean 
  4149. /*FCN*/testDsc(ASE_DSC dsc) 
  4150. {
  4151.     ASE_DSC forCopy=ASE_DSC_NULL ;   /* To test ase_dsc_copyFrom() */
  4152.     ASE_DSC forClone=ASE_DSC_NULL ;  /* To test ase_dsc_clone() */
  4153.     EAsiBoolean retCode=kAsiBad ;    /* The returning code */
  4154.     do {
  4155.         if ( dsc == ASE_DSC_NULL ) {
  4156.             break ;
  4157.         }
  4158.           /* Check the descriptor validity */
  4159.         if ( ase_dsc_isInit(dsc) != kAsiTrue ) {
  4160.             switch(ase_dsc_isA(dsc)) {
  4161.             case kAseApiAppl:          /* Application descriptor */
  4162.                ads_printf("\nTest:: interface to ASE isn't established") ;
  4163.                break ;
  4164.             case kAseApiLinkPath:      /* Link Path descriptor */
  4165.                ads_printf("\nTest:: Link Path is invalid") ;
  4166.                break ;
  4167.             case kAseApiLink:          /* Link descriptor */
  4168.                ads_printf("\nTest:: Link is invalid") ;
  4169.                break ;
  4170.             case kAseApiLinkSel:       /* Link Selection descriptor */
  4171.                ads_printf("\nTest:: Link Selection isn't initialized") ;
  4172.                break ;
  4173.             }
  4174.             break ;
  4175.         }
  4176.           /* Clone the descriptor */
  4177.         if ( (forClone=ase_dsc_clone(dsc)) == ASE_DSC_NULL ) {
  4178.             ads_abort("\nCan't clone the descriptor") ;
  4179.             printAseErr(dsc) ;
  4180.             break ;
  4181.         }
  4182.           /* Check the validity of the cloned descriptor */
  4183.         if ( ase_dsc_isInit(forClone) != kAsiGood ) {
  4184.             break ;
  4185.         }
  4186.           /* Allocate the descriptor of the same type */
  4187.         if ( (forCopy=ase_dsc_alloc(AseAppl, ase_dsc_isA(dsc))) 
  4188.              == ASE_DSC_NULL ) {
  4189.             ads_abort("\nCan't allocate the descriptor") ;
  4190.             break ;
  4191.         }
  4192.           /* Check the allocated descriptor in accordance with the spec */
  4193.         if ( ase_dsc_isInit(forCopy) != kAsiGood ) {
  4194.             if ( ase_dsc_isA(dsc) == kAseApiLinkPath ) {
  4195.                ads_printf("\nTest:: Link Path is invalid") ;
  4196.                break ;
  4197.             } else if ( ase_dsc_isA(dsc) == kAseApiLink) {
  4198.                ads_printf("\nTest:: Link is invalid") ;
  4199.                break ;
  4200.             }
  4201.         }
  4202.           /* Execute the default init */
  4203.         if ( ase_dsc_init(forCopy) != kAsiGood ) {
  4204.             ads_printf("\nCan't execute the default init") ;
  4205.             printAseErr(forCopy) ;
  4206.             break ;
  4207.         }
  4208.           /* Check the validity now */
  4209.         if ( ase_dsc_isInit(forCopy) != kAsiGood ) {
  4210.            ads_printf("\nVoid descriptor is invalid") ;
  4211.            printAseErr(forCopy) ;
  4212.            break ;
  4213.         }
  4214.           /* Copy descripor data */
  4215.         if ( ase_dsc_copyFrom(forCopy, dsc) != kAsiGood ) {
  4216.             ads_printf("\nCan't copy the descriptor") ;
  4217.             printAseErr(dsc) ;
  4218.             break ;
  4219.         }
  4220.           /* Compare the descriptors in accordance with the spec */
  4221.         if ( ! ase_dsc_cmp(forClone, forCopy) ) {
  4222.             if ( ase_dsc_isA(dsc) != kAseApiAppl ) {
  4223.                 ads_printf("\nWrong comparision") ;
  4224.                 printAseErr(forClone) ;
  4225.                 break ;
  4226.             }
  4227.         }
  4228.         retCode = kAsiGood ;
  4229.     } while(0) ;
  4230.     ase_dsc_free(&forClone) ;
  4231.     ase_dsc_free(&forCopy) ;
  4232.     if ( retCode != kAsiGood ) {
  4233.         ads_printf("\nDescriptor test -> BAD") ;
  4234.     }
  4235.     return retCode ;
  4236. } /* end of testDsc() */
  4237.  
  4238. /****************************************************************************/
  4239. /*.doc printColDsc(internal) */
  4240. /*+
  4241.   Prints the column description
  4242. -*/
  4243. /****************************************************************************/
  4244. static void                               
  4245. /*FCN*/printColDsc(ASICOLDSC col) 
  4246. {
  4247.    ASIDATADSC    datadsc=0L;
  4248.    ASIIDENT      name=0L;
  4249.    char          buff [128];
  4250.  
  4251.      /* Print column name */
  4252.    asi_cdsc_name (col, &name);
  4253.    ads_printf("%s", asi_get_ident (name, buff, 128));
  4254.    asi_destroy_ident (&name);
  4255.  
  4256.      /* Print column type */
  4257.    if (asi_cdsc_ddsc (col, &datadsc) == kAsiGood) {
  4258.        ads_printf("  %s", asi_ddsc_sqltype (datadsc, buff, 256));
  4259.        asi_destroy_ddsc (&datadsc);
  4260.    }
  4261. } /* end of printColDsc() */
  4262.  
  4263.  
  4264. /****************************************************************************/
  4265. /*.doc printBufNames(internal) */
  4266. /*+
  4267.   This function prints just the string values from the specified buffer
  4268. -*/
  4269. /****************************************************************************/
  4270. static void        
  4271. /*FCN*/printBufNames(const struct resbuf *pBuf) 
  4272. {
  4273.     struct resbuf *ptr ;    /* scanning buffer pointer */
  4274.     for ( ptr = (struct resbuf*)pBuf ; ptr != NULL ; ptr = ptr->rbnext ) {
  4275.         if ( ptr->restype == RTSTR &&
  4276.              ptr->resval.rstring != NULL ) {
  4277.             ads_printf("\n%s", ptr->resval.rstring) ;
  4278.         }
  4279.     }
  4280. } /* end of printBufNames() */
  4281.  
  4282. /****************************************************************************/
  4283. /*.doc pauseInput(internal) */
  4284. /*+
  4285.   This function asks the user to press the key
  4286. -*/
  4287. /****************************************************************************/
  4288. static void
  4289. /*FCN*/pauseInput(const char* pPrompt)
  4290. {
  4291.     int ii ;
  4292.     if ( pPrompt != NULL ) {
  4293.         ads_getint(pPrompt, &ii) ;
  4294.     } else {
  4295.         ads_getint("\nPress any key...", &ii) ;
  4296.     }
  4297. } /* End of pauseInput() */
  4298.  
  4299. /****************************************************************************/
  4300. /*.doc callCmd(internal) */
  4301. /*+
  4302.   Calls AutoCAD command with the specified parameters.
  4303. -*/
  4304. /****************************************************************************/
  4305. static int
  4306. /*FCN*/callCmd(char *pCmdName, struct resbuf *pParms) 
  4307. {
  4308.     struct resbuf ocmdecho;           /* Current CMDECHO setting */
  4309.     struct resbuf tcmdecho;           /* Temporary CMDECHO setting */
  4310.     struct resbuf ocmddia;            /* Current CMDDIA setting */
  4311.     struct resbuf tcmddia;            /* Temporary CMDDIA setting */
  4312.     struct resbuf AseFunc ;           /* The ASE command item */
  4313.     int status;                       /* Command status */
  4314.  
  4315.     tcmdecho.restype = RTSHORT;       /* Temporary CMDECHO setting (OFF) */
  4316.     tcmdecho.resval.rint = 0;
  4317.  
  4318.     ads_getvar ("CMDECHO", &ocmdecho);  /* Read current setting */
  4319.     ads_setvar ("CMDECHO", &tcmdecho);  /* Temporary setting */
  4320.  
  4321.     tcmddia.restype = RTSHORT;       /* Temporary CMDDIA setting (OFF) */
  4322.     tcmddia.resval.rint = 0;
  4323.  
  4324.     ads_getvar ("CMDDIA", &ocmddia);  /* Read current setting */
  4325.     ads_setvar ("CMDDIA", &tcmddia);  /* Temporary setting */
  4326.  
  4327.       /* Chain the calling parameters */
  4328.     AseFunc.restype = RTSTR ;
  4329.     AseFunc.resval.rstring = pCmdName ;
  4330.     AseFunc.rbnext = pParms ;
  4331.  
  4332.     status = ads_cmd (&AseFunc);            /* Execute command */
  4333.  
  4334.     ads_setvar ("CMDECHO", &ocmdecho);  /* Reset CMDECHO */
  4335.  
  4336.     ads_setvar ("CMDDIA", &ocmdecho);  /* Reset CMDDIA */
  4337.  
  4338.     return status;
  4339. } /* end of callCmd() */
  4340.  
  4341. /****************************************************************************/
  4342. /*.doc  addtoken (internal) */
  4343. /*+
  4344.   This function adds new token to the static buffer.
  4345.   Serves to construct the SQL statements.
  4346.   Action depends on newtoken value:
  4347.     NEW_TOKENBUF    - free previous static buffer and allocate new one
  4348.     FREE_TOKENBUF   - free current pointer
  4349.     any other       - add string to the static buffer
  4350.   Return values:
  4351.     pointer to the static buffer. If error, returns NULL.
  4352. -*/
  4353. /****************************************************************************/
  4354. static char*
  4355. /*FCN*/addtoken (char *newtoken)             
  4356. {
  4357.     static char *curptr = NULL ;      /* default value */
  4358.     static int maxsize = 0 ;          /* maximun size of statement */
  4359.     int curpos = 0 ;                  /* current position in the buffer */
  4360.     int cursize;                      /* variable for checking */
  4361.  
  4362.       /* You need new list */
  4363.     if ( newtoken == NEW_TOKENBUF ) { 
  4364.           /* Check pointer */
  4365.         if ( curptr != NULL ) {   
  4366.               /* Free old memory block */
  4367.             free(curptr) ;        
  4368.             curptr = NULL ;
  4369.         }
  4370.         if ( (curptr = (char*)calloc(1, DEFSTMSIZE)) == NULL ) {
  4371.             ads_abort("\nNo memory") ;
  4372.             return NULL ;
  4373.         }
  4374.           /* Set default size of statement */
  4375.         maxsize = DEFSTMSIZE ;        
  4376.     } else if ( newtoken == FREE_TOKENBUF ) {
  4377.         if ( curptr != NULL ) {
  4378.             free(curptr) ;
  4379.             curptr = NULL ;
  4380.         }
  4381.     } else {
  4382.         if ( curptr != NULL ) {
  4383.             cursize = strlen (newtoken) ;
  4384.             if ( cursize ) {
  4385.                 curpos = strlen(curptr) ;
  4386.                 if ( curpos+cursize >= maxsize ) {
  4387.                     char *tmpptr;     /* temporary pointer */
  4388.                       /* new block size */
  4389.                     maxsize += cursize + DEFSTMINC ;       
  4390.                     if ( maxsize > MAXSTMSIZE ||
  4391.                          (tmpptr = (char*)calloc (1,  maxsize)) == NULL ) {
  4392.                         ads_abort("\nToo big statement size") ;
  4393.                           /* Free old buffer */
  4394.                         free(curptr) ;             
  4395.                         curptr = NULL ;
  4396.                         return NULL ;
  4397.                     }
  4398.                       /* Copy old data */
  4399.                     strcpy ( tmpptr, curptr) ;   
  4400.                       /* Free old block */
  4401.                     free (curptr) ;              
  4402.                       /* Set new pointer */
  4403.                     curptr = tmpptr ;                
  4404.                 }
  4405.                 strcpy (curptr+curpos, newtoken) ;
  4406.             }
  4407.         }
  4408.     }
  4409.       /* Return pointer to the buffer */
  4410.     return curptr ;                   
  4411. }  /* end of addtoken () */
  4412.  
  4413. /****************************************************************************/
  4414. /*.doc smpinit(internal) */
  4415. /*+
  4416.   This function initializes the ASI and ASE interfaces
  4417. -*/
  4418. /****************************************************************************/
  4419. static EAsiBoolean 
  4420. /*FCN*/smpinit() 
  4421. {
  4422.     char *ptr ;     /* ASE version string pointer */
  4423.       /* Init ASI interface */
  4424.     if ( asi_initasi(&AsiAppl) != kAsiGood ) {
  4425.         ads_abort("\nCan't initialize ASI interface") ;
  4426.         return kAsiBad ;
  4427.     }
  4428.       /* Init ASE interface */
  4429.     if ( (AseAppl = ase_appl_init()) == ASE_DSC_NULL ) {
  4430.         ads_abort("\nCan't initialize ASE interface") ;
  4431.         asi_termasi(&AsiAppl) ;
  4432.         return kAsiBad ;
  4433.     }
  4434.       /* Get ASE version */
  4435.     if ( (ptr=(char*)ase_dsc_version(AseAppl)) != NULL ) {
  4436.         ads_printf("\nASE version [%s] is detected", ptr) ;
  4437.     }
  4438.       /* Test ASE APPL */
  4439.     if ( testDsc(AseAppl) != kAsiGood ) {
  4440.         smpterm() ;
  4441.         return kAsiBad ;
  4442.     }
  4443.     return kAsiGood ;
  4444. } /* end of smpinit() */
  4445.  
  4446. /****************************************************************************/
  4447. /*.doc smpterm(internal) */
  4448. /*+
  4449.   This function terminates the ASI and ASE interfaces
  4450. -*/
  4451. /****************************************************************************/
  4452. static void
  4453. /*FCN*/smpterm() 
  4454. {
  4455.       /* Disconnect from the global Env */
  4456.     disconnect() ;
  4457.       /* Terminate ASE interface */
  4458.     ase_appl_term(&AseAppl) ;
  4459.       /* Terminate ASI interface */
  4460.     asi_termasi(&AsiAppl) ;
  4461. } /* end of smpterm() */
  4462.  
  4463. /****************************************************************************/
  4464. /*.doc isInit(internal) */
  4465. /*+
  4466.   This function checks whether or not ASE and ASI interfaces
  4467.   were initialized.
  4468. -*/
  4469. /****************************************************************************/
  4470. static EAsiBoolean 
  4471. /*FCN*/isInit() 
  4472. {
  4473.     if ( AsiAppl == 0L || AseAppl == ASE_DSC_NULL ) {
  4474.         ads_printf("\nASE or ASI interfaces wasn't initialized") ;
  4475.         return kAsiBad ;
  4476.     }
  4477.     return kAsiGood ;
  4478. } /* end of isInit() */
  4479.  
  4480. /****************************************************************************/
  4481. /*.doc loadfunc(internal) */
  4482. /*+
  4483.     This function is called to load external functions into AutoLISP.
  4484. -*/
  4485. /****************************************************************************/
  4486. static int
  4487. /*FCN*/loadfunc ()
  4488. {
  4489.     short i = sizeof(cmd) /
  4490.               sizeof(CMDADS);          /* Number of functions */
  4491.  
  4492.     while (i-- > 0)  {                     /* For every function from cmd */
  4493.         if (ads_defun(cmd[i].cmdname, i) != RTNORM) {
  4494.             return RSERR;                 /* Wrong function definition */
  4495.         }
  4496.     }
  4497.  
  4498.     if ( ! smpinit() ) {
  4499.         return RSERR ;
  4500.     }
  4501.     return RSRSLT;                    /* All functions were defined right */
  4502. }                                     /* End of loadfunc () */
  4503.  
  4504. /****************************************************************************/
  4505. /*.doc unloadfunc(internal) */
  4506. /*+
  4507.     This function is called to unload external functions into AutoLISP.
  4508. -*/
  4509. /****************************************************************************/
  4510. static int
  4511. /*FCN*/unloadfunc ()
  4512. {
  4513.     short i = sizeof(cmd) /
  4514.               sizeof(CMDADS);          /* Number of functions */
  4515.  
  4516.     while (i-- > 0) {                      /* For every function from cmd */
  4517.         if (ads_undef(cmd[i].cmdname, i) != RTNORM) {
  4518.             return RSERR;                 /* Wrong function definition */
  4519.         }
  4520.     }
  4521.     smpterm() ;
  4522.     return RTNORM ;                    /* All functions were defined right */
  4523. }                                     /* End of unloadfunc () */
  4524.  
  4525. /****************************************************************************/
  4526. /*.doc execfunc(internal) */
  4527. /*+
  4528.     This function is called to start external function.
  4529. -*/
  4530. /****************************************************************************/
  4531. static int
  4532. /*FCN*/execfunc ()
  4533. {
  4534.     int i = ads_getfuncode ();        /* Function number */
  4535.  
  4536.     if (i == RTERROR)
  4537.         return RSERR;                 /* Error */
  4538.  
  4539.     /* Call function */
  4540.     if ( (cmd[i].cmdfunc)() != kAsiGood ) {
  4541.         ads_printf("\nSample command %s failed", cmd[i].cmdname) ;
  4542.     }
  4543.  
  4544.     ads_retvoid() ;
  4545.     return RSRSLT;                    /* OK */
  4546. }                                     /* End of execfunc () */
  4547.  
  4548. /****************************************************************************/
  4549. /*.doc main(external) */
  4550. /*+
  4551.     Main entry point.
  4552. -*/
  4553. /****************************************************************************/
  4554. void
  4555. /*FCN*/main (
  4556.   int argc,                           /* Argument count */
  4557.   char *argv[]                        /* Argument vector */
  4558. ){
  4559.     short scode = RSRSLT;             /* Default result code */
  4560.     int stat;                         /* Return value from ads_link */
  4561.  
  4562.     ads_init(argc, argv);             /* Initialize the interface */
  4563.  
  4564.     for (;;) {                        /* Main loop */
  4565.                                       /* Link with AutoCAD */
  4566.         if ((stat = ads_link (scode)) < 0) {  
  4567.                                       /* AutoCAD error */
  4568.                                       /* Print error message */
  4569.             printf("\nBad status from ads_link() = %d\n", stat);
  4570.             fflush (stdout);          /* Fflush the print buffer */
  4571.             exit (1);                 /* Exit */
  4572.         }
  4573.  
  4574.         scode = RSRSLT;                /* Default result value */
  4575.  
  4576.         switch (stat) {         
  4577.  
  4578.         case RQXLOAD:                 /* Load function by (xload) command */
  4579.             scode = loadfunc ();       /* Register ADS external functions */
  4580.            break;
  4581.  
  4582.         case RQSUBR:                  /* Invoke function */
  4583.            scode = execfunc ();       /* Call function */
  4584.            break;
  4585.  
  4586.         case RQXUNLD:                 /* Unload application */
  4587.         case RQEND:                   /* End AutoCAD */
  4588.         case RQQUIT:                  /* Quit AutoCAD */
  4589.             unloadfunc() ;            /* Unload the commands */
  4590.             break ;
  4591.         }
  4592.     }
  4593. }                                     /* End of main () */
  4594.  
  4595. #endif /* ASE_ASESMP_C */
  4596. /*EOF*/
  4597.  
  4598.  
  4599.