home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / src / vg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-28  |  17.9 KB  |  803 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.3 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/src/RCS/vg.c,v 1.3 1992/10/23 00:14:11 koziol beta koziol $
  30.  
  31. $Log: vg.c,v $
  32.  * Revision 1.3  1992/10/23  00:14:11  koziol
  33.  * Changed all DFIstr*() and DFImem*() calls to HDstr*() and HDmem*() calls
  34.  * #ifdef'd out the macros Jason defined for Hopen, Hclose, etc. for Vsets
  35.  * Replaced Vset VFREESPACE and VGETSPACE calls with actual calls to HDfreespace
  36.  * and HDgetspace
  37.  * Added a MS-Windows lower lower for file I/O (which may not be completely working
  38.  *
  39.  * Revision 1.2  1992/10/12  18:11:51  koziol
  40.  * Updated for v3.2r2 release
  41.  *
  42.  * Revision 1.1  1992/08/25  21:40:44  koziol
  43.  * Initial revision
  44.  *
  45. */
  46. /*
  47. *
  48. * vg.c
  49. * Part of the HDF VSet interface
  50. * This file contains routine to handle VDATAs.
  51. *
  52. * Most routines return -1 (FAIL) on error.  Some must return 0 on error.
  53. * VSattach returns NULL on error.
  54. *
  55. * PRIVATE functions manipulate vsdir and are used only within this file.
  56. * PRIVATE data structures in here pertain to vdata in vsdir only.
  57. *
  58. **************************************************************************/
  59.  
  60. #include "vg.h"
  61.  
  62. /* ------------------------------------------------------------------
  63. *    Vnewref
  64. *    utility routine. returns a unique reference number.
  65. *
  66. *    RETURNS a unique ref (+ve unsigned 16-bit integer) ,
  67. *    RETURNS 0 if error
  68. *
  69. *  undocumented
  70. *
  71. */
  72.  
  73. #ifdef PROTOTYPE
  74. uint16 vnewref (HFILEID f)        
  75. #else
  76. uint16 vnewref (f)        
  77.  
  78.     HFILEID    f;
  79. #endif
  80.  
  81. {
  82.     uint16 r;
  83.     char * FUNC = "vnewref";
  84.  
  85.     r = (uint16) QQnewref (f);
  86.     if (r == 0)  HERROR(DFE_NOFREEDD);
  87.  
  88.     return (r);
  89.  
  90. } /* vnewref */
  91.  
  92. /* ================================================================== */
  93.  
  94. /* matchnocase -  (PRIVATE) compares 2 strings, ignoring case 
  95. *                   returns TRUE if match, else FALSE
  96. */
  97.  
  98. #ifdef PROTOTYPE
  99. int32 matchnocase (char *strx, char *stry)   
  100. #else
  101. int32 matchnocase (strx, stry) 
  102.  
  103.     char *strx,*stry;
  104. #endif
  105.  
  106. {
  107.     int32     i,nx,ny;
  108.     int16        tx,ty;
  109.     char         *sx, *sy;
  110.  
  111.     nx = HDstrlen(strx);
  112.     ny = HDstrlen(stry);
  113.     if (nx != ny) return(FALSE);  /* different lengths */
  114.  
  115.     for (sx=strx, sy=stry, i=0;i<nx;i++,sx++,sy++) {
  116.         tx= *sx; 
  117.         ty= *sy;
  118.         if (islower(tx)) tx=toupper(tx);
  119.         if (islower(ty)) ty=toupper(ty);
  120.         if (tx != ty)       return (FALSE);
  121.     }
  122.  
  123.     return (TRUE);
  124.  
  125. } /* matchnocase */
  126.  
  127.  
  128. /* ------------------------------------------------------------------
  129. * VSelts
  130. * returns the number of elements in the VDATA vs 
  131. * returns FAIL  on error.
  132. *
  133. * undocumented
  134. * 28-MAR-91 Jason NG NCSA
  135. *
  136. */
  137.  
  138. #ifdef PROTOTYPE
  139. PUBLIC int32 VSelts (VDATA *vs)  
  140. #else
  141. PUBLIC int32 VSelts (vs)  
  142.  
  143.     VDATA * vs;
  144. #endif
  145. {
  146.     char * FUNC = "VSelts";
  147.  
  148.     return( (vs->otag==VSDESCTAG) ?  vs->nvertices : FAIL);
  149.  
  150. } /* VSelts */
  151.  
  152.  
  153. /* ------------------------------------------------------------------
  154. *    VSgetinterlace 
  155. *  returns the interlace (in the file) of the vdata vs.
  156. *  returns FAIL on error.
  157. *
  158. *  undocumented
  159. *
  160. */
  161.  
  162. #ifdef PROTOTYPE
  163. PUBLIC int32 VSgetinterlace (VDATA *vs) 
  164. #else
  165. PUBLIC int32 VSgetinterlace (vs) 
  166.  
  167.     VDATA * vs;
  168. #endif
  169.  
  170. {
  171.     char * FUNC = "VSgetinterlace";
  172.  
  173.     return( (vs==NULL) ? (int32)FAIL : (int32) vs->interlace );
  174.  
  175. } /* VSgetinterlace */
  176.  
  177. /* ------------------------------------------------------------------
  178. *    VSsetinterlace 
  179. *     sets the vdata's interlace to full or none.
  180. *    returns FAIL on error.
  181. */
  182.  
  183. #ifdef PROTOTYPE
  184. PUBLIC int32 VSsetinterlace (VDATA *vs, int32 interlace)
  185. #else
  186. PUBLIC int32 VSsetinterlace (vs, interlace)
  187.  
  188.     VDATA * vs;
  189.     int32 interlace;
  190. #endif
  191.  
  192. {
  193.     char * FUNC = "VSsetinterlace";
  194.  
  195.     if(vs == NULL)        {HERROR(DFE_BADPTR);  return(FAIL);}
  196.     if(vs->access == 'r') {HERROR(DFE_RDONLY);  return(FAIL);}
  197.    if(vs->nvertices > 0) {HERROR(DFE_NORESET); return(FAIL);}
  198.  
  199.     /* currently only 2 kinds allowed */
  200.  
  201.     if ( interlace == FULL_INTERLACE || 
  202.         interlace == NO_INTERLACE ) {
  203.                 vs->interlace = (int16)interlace;
  204.                 return (TRUE); /* ok */
  205.     } 
  206.     else  return (FAIL);        
  207.  
  208. } /* VSsetinterlace */
  209.  
  210.  
  211. /* ------------------------------------------------------------------
  212. *    VSgetfields 
  213. *  returns the fieldnames in a vdata.
  214. *  RETURNS  -1 on error, else the no of fields in the vdata.
  215. *
  216. *    undocumented
  217. *
  218. */
  219.  
  220. #ifdef PROTOTYPE
  221. PUBLIC int32 VSgetfields (VDATA *vs, char *fields)        
  222. #else
  223. PUBLIC int32 VSgetfields (vs, fields)        
  224.  
  225.     VDATA * vs;
  226.     char  * fields;            /* fieldnames are returned in this var */
  227. #endif
  228.  
  229. {
  230.     int32 i;
  231.     char * FUNC = "VSgetfields";
  232.  
  233.     if (vs==NULL) {
  234.        HERROR(DFE_BADPTR);
  235.        return(FAIL);
  236.        }
  237.  
  238.     fields[0] = '\0';
  239.     for (i=0;i<vs->wlist.n;i++) { /* build the comma-separated string */
  240.         HDstrcat(fields,vs->wlist.name[i]);
  241.         if ( i < vs->wlist.n - 1 )
  242.             HDstrcat(fields,",");
  243.     }
  244.  
  245.     return ((int32) vs->wlist.n);
  246.  
  247. } /* VSgetfields */
  248.  
  249. /* ------------------------------------------------------------------
  250. *    VSfexist
  251. *     tests for existence of 1 or more fields in a vdata.
  252. *
  253. *    RETURNS -1 if false, or error
  254. *    RETURNS 1 if true
  255. */
  256.  
  257. #ifdef PROTOTYPE
  258. PUBLIC int32 VSfexist (VDATA *vs, char *fields)
  259. #else
  260. PUBLIC int32 VSfexist (vs, fields)      
  261.  
  262.     VDATA * vs;
  263.     char    * fields;
  264. #endif
  265.  
  266. {
  267.     char           **av, *s;
  268.     int32            ac,i,j,found;
  269.     VWRITELIST    *w;
  270.     char * FUNC = "VSfexist";
  271.  
  272.     /* call scanattrs to parse the string */
  273.  
  274.     if (scanattrs(fields,&ac,&av) < 0) {
  275.           HERROR(DFE_BADFIELDS);
  276.           return (FAIL);
  277.         }
  278.  
  279.     if ((vs == NULL) || (ac<1)) {
  280.           HERROR(DFE_ARGS);
  281.           return (FAIL);     
  282.         }
  283.  
  284.     /* now check in vs's field table */
  285.  
  286.     w = &vs->wlist;
  287.     for (i=0;i<ac;i++) {
  288.         for (found=0,s=av[i],j=0;j<w->n;j++) {
  289.             if ( matchnocase(s,w->name[j]) ) {
  290.                 found = 1;
  291.                 break;
  292.             }
  293.         }
  294.         if (!found) return (FAIL);
  295.     }
  296.  
  297.     return (1);
  298.  
  299. } /* VSfexist */
  300.  
  301.  
  302. /* ================================================================== */
  303. /*
  304. *    VSsizeof - computes the byte size of the field(s) of a vdata.
  305. *             - Note that the size is the actual size for the local machine.
  306. *
  307. *         - RETURNS FAIL on error, else the field(s) size (+ve integer).
  308. */
  309.  
  310. #ifdef PROTOTYPE
  311. PUBLIC int32 VSsizeof (VDATA *vs, char *fields) 
  312. #else
  313. PUBLIC int32 VSsizeof (vs, fields) 
  314.  
  315.     VDATA *vs;
  316.     char  *fields;
  317. #endif
  318.  
  319. {
  320.     int32     totalsize, ac, i,j,found;
  321.     char       **av;
  322.     char * FUNC = "VSsizeof";
  323.  
  324.     if((vs==NULL) || (scanattrs(fields,&ac,&av) < 0) || (ac<1)) {
  325.           HERROR(DFE_ARGS);
  326.           return(FAIL);
  327.         }
  328.  
  329.     if (vjv) { 
  330.         sprintf(sjs,"#VSsizeof: fields are [%s]\n",fields);
  331.         zj; 
  332.     }
  333.  
  334.     totalsize=0;
  335.     for (i=0;i<ac;i++) {
  336.         for (found=0,j=0;j<vs->wlist.n;j++)
  337.                   /* check fields in vs */
  338.             if (!HDstrcmp(av[i], vs->wlist.name[j])) {
  339.                 totalsize += vs->wlist.esize[j];
  340.                 found=1;
  341.                 break;
  342.             }
  343.  
  344.         if (!found) {
  345.                         HERROR(DFE_ARGS);
  346.                         HEreport("VSsizeof:[%s] not in vs", av[i]);
  347.             return(FAIL);
  348.         }
  349.     }
  350.  
  351.     return(totalsize);
  352.  
  353. } /* VSsizeof */
  354.  
  355. /* ================================================================== */
  356.  
  357. /*
  358. *    VSdump - prints contents of a vdata (for debugging) 
  359. *                no return codes.
  360. */
  361.  
  362. #ifdef PROTOTYPE
  363. void VSdump (VDATA *vs)                       
  364. #else
  365. void VSdump (vs)                       
  366.  
  367.     VDATA *vs;
  368. #endif
  369.  
  370. {
  371.     VWRITELIST    *w;
  372.     int32         i;
  373.     char * FUNC = "VSdump";
  374.  
  375.     if (!vs) { 
  376.           sprintf(sjs,"@VSdump: vs is null\n"); zj; 
  377.           return; 
  378.         }
  379.  
  380.     sprintf(sjs,"@tag=%d ref=%d i=%d ",vs->otag, vs->oref,vs->interlace); zj;
  381.     sprintf(sjs,"@nv=%ld\n ",vs->nvertices); zj;
  382.  
  383.     w = (VWRITELIST*) &vs->wlist;
  384.     sprintf(sjs,"@vsize(hdf)=%d fields=%d [%s]\n",w->ivsize,w->n,vs->vsname); zj;
  385.  
  386.     for (i=0;i<w->n;i++) { 
  387.         sprintf(sjs,"@<%s>      type:%d esize=%d isize=%d off=%d\n",
  388.             w->name[i], w->type[i], w->esize[i],w->isize[i],w->off[i]);
  389.         zj;
  390.     }
  391.  
  392.     sprintf(sjs,"\n"); zj;
  393.  
  394. } /* VSdump */
  395.  
  396.  
  397. /* ======================================================= */
  398. /*
  399. *    VSsetname - give a name to a vdata.
  400. *              - NO RETURN VALUES
  401. *              - truncates name to max length of VSNAMELENMAX
  402. *      
  403. */
  404.  
  405. #ifdef PROTOTYPE
  406. PUBLIC void VSsetname (VDATA *vs, char *vsname)
  407. #else
  408. PUBLIC void VSsetname (vs, vsname)
  409.  
  410.     VDATA *vs;
  411.     char    *vsname;
  412. #endif
  413.  
  414. {
  415.     char * FUNC = "VSsetname";
  416.  
  417.     if (vs == NULL) return;
  418.     if ( HDstrlen(vsname) > VSNAMELENMAX) {
  419.         HDstrncpy(vs->vsname, vsname,VSNAMELENMAX);
  420.         vs->vsname[VSNAMELENMAX]='\0';
  421.     }
  422.     else 
  423.         HDstrcpy(vs->vsname, vsname);
  424.     vs->marked = TRUE;
  425.     return;
  426.  
  427. } /* VSsetname */
  428.  
  429. /* ======================================================= */
  430. /*
  431. *    VSsetclass- assigns a class name to a vdata.
  432. *              - NO RETURN VALUES
  433. *              - truncates to max length of VSNAMELENMAX
  434. *      
  435. */
  436.  
  437. #ifdef PROTOTYPE
  438. PUBLIC void VSsetclass (VDATA *vs, char *vsclass)
  439. #else
  440.  
  441. PUBLIC void VSsetclass (vs, vsclass)
  442.  
  443.     VDATA *vs;
  444.     char    *vsclass;
  445. #endif
  446.  
  447. {
  448.     char * FUNC = "VSsetclass";
  449.  
  450.     if (vs == NULL) return;
  451.     if ( HDstrlen(vsclass) > VSNAMELENMAX) {
  452.         HDstrncpy(vs->vsclass, vsclass,VSNAMELENMAX);
  453.         vs->vsclass[VSNAMELENMAX]='\0';
  454.     }
  455.     else 
  456.         HDstrcpy(vs->vsclass, vsclass);
  457.     vs->marked = TRUE;
  458.     return;
  459.  
  460. } /* VSsetclass*/
  461.  
  462. /* ======================================================= */
  463.  
  464. /*
  465. *    VSgetname - gets the vdata's name.
  466. *                 - NO RETURN VALUES
  467. */
  468.  
  469. #ifdef PROTOTYPE
  470. PUBLIC void VSgetname (VDATA *vs, char *vsname)      
  471. #else
  472.  
  473. PUBLIC void VSgetname (vs, vsname)      
  474.  
  475.     VDATA *vs;
  476.     char    *vsname;
  477. #endif
  478.  
  479. {
  480.     char * FUNC = "VSgetname";
  481.  
  482.     if (vs != NULL) HDstrcpy(vsname, vs->vsname);
  483.     return;
  484.  
  485. } /* VSgetname */
  486.  
  487. /* ======================================================= */
  488.  
  489. /*
  490. *    VSgetclass - gets the vdata's class name.
  491. *                 - NO RETURN VALUES
  492. */
  493.  
  494. #ifdef PROTOTYPE
  495. PUBLIC void VSgetclass (VDATA *vs, char *vsclass)   
  496. #else
  497.  
  498. PUBLIC void VSgetclass (vs, vsclass)   
  499.  
  500.     VDATA *vs;
  501.     char    *vsclass;
  502. #endif
  503.  
  504. {
  505.     char * FUNC = "VSgetclass";
  506.  
  507.     if (vs != NULL) HDstrcpy(vsclass, vs->vsclass);
  508.     return;
  509.  
  510. } /* VSgetclass */
  511.  
  512.  
  513. /* ================================================================== */
  514. /*
  515. *    VSinquire - gets info about a vdata vs:
  516. *
  517. *          nvertices:     no of vertices in it.
  518. *          interlace:     its interlcae
  519. *          fields :     a comma separated string listing the field(s). 
  520. *                                                 (eg "PX,PY")
  521. *          eltsize:     size of elmt (all field(s)) on local machine.
  522. *          vsname:     vdata's name, if any.
  523. *
  524. *    RETURNS FAIL if error
  525. *    RETURNS 1 if ok
  526. *
  527. */
  528.  
  529.  
  530. #ifdef PROTOTYPE
  531. PUBLIC int32 VSinquire (VDATA *vs, int32 *nelt, int32 *interlace,
  532.         char *fields, int32 *eltsize, char *vsname)
  533. #else
  534.  
  535. PUBLIC int32 VSinquire (vs, nelt, interlace, fields, eltsize, vsname)   
  536.  
  537.     VDATA     *vs;
  538.     char      *fields, *vsname;
  539.     int32     *nelt, *interlace, *eltsize;
  540. #endif
  541.  
  542. {
  543.     char * FUNC = "VSinquire";
  544.  
  545.     if (!vs) {
  546.           HERROR(DFE_BADPTR);
  547.           return(FAIL);
  548.         }
  549.     
  550.     if(fields)
  551.       VSgetfields (vs,fields);
  552.     if(nelt) 
  553.       *nelt       = (int32) vs->nvertices;
  554.     if(interlace)
  555.       *interlace  = (int32) vs->interlace;
  556.     if(eltsize)
  557.       *eltsize    =  (int32) VSsizeof (vs,fields);
  558.     if(vsname)
  559.       HDstrcpy(vsname,vs->vsname);
  560.  
  561.     return (SUCCEED); /* ok */
  562.  
  563. } /* VSinquire */
  564.  
  565. /* ================================================================== */
  566. /*
  567. * VSlone - returns an array of refs of all lone vdatas in the file.
  568. *      - returns -1 if error
  569. *      - otherwise returns the total number of lone vdatas in the file 
  570. *
  571. *        If idarray is too small, routine will only fill idarray with up
  572. *         to asize worth of refs.
  573. *
  574. *        INPUT idarray: user supplies  an int array.
  575. *       INPUT asize: integer specifying how many ints in idarray[];
  576. *        INPUT f: HDF file pointer.
  577. *
  578. */
  579.  
  580. #ifdef PROTOTYPE
  581. PUBLIC int32 VSlone(HFILEID f, int32 idarray[], int32 asize) 
  582. #else
  583.  
  584. PUBLIC int32 VSlone(f, idarray, asize) 
  585.  
  586.     HFILEID    f;
  587.     int32      idarray[];         /* array to contain the refs */
  588.     int32     asize;            /* input: size of idarray */
  589. #endif
  590.  
  591. {
  592.     int16     *lonevdata; /* lcl wrk area: stores flags of vdatas */
  593.     int32     i,vgid, vsid, vstag;
  594.     VGROUP     * vg;
  595.     int32     nlone; /* total number of lone vdatas */
  596.     char * FUNC = "VSlone";
  597.  
  598.  
  599. /* -- allocate space for vdata refs, init to zeroes -- */
  600.     if (NULL == (lonevdata = (int16*) HDgetspace ( 65000 * sizeof(int16))))
  601.       { HERROR(DFE_NOSPACE); return(FAIL); }
  602.     for(i=0;i<65000;i++) lonevdata[i] = 0;
  603.  
  604. /* -- look for all vdatas in the file, and flag (1) each -- */
  605.     vsid = -1;
  606.     while( -1L != (vsid = VSgetid (f, vsid)))   /* until no more vdatas */
  607.         lonevdata[vsid ] = 1;
  608.  
  609. /* -- Look through all vgs, searching for vdatas -- */
  610. /* -- increment its index in lonevdata if found -- */
  611.     vgid = -1;
  612.     while( -1L != (vgid = Vgetid (f, vgid))) { /* until no more vgroups */
  613.         vg = (VGROUP*) Vattach(f,vgid,"r");
  614.         for (i=0; i< Vntagrefs(vg); i++) {
  615.             Vgettagref (vg, i, &vstag, &vsid);
  616.             if (vstag==VSDESCTAG)
  617.                 { lonevdata[vsid]++;  }
  618.             }
  619.         Vdetach(vg);
  620.         }
  621.  
  622. /* -- check in lonevdata: it's a lone vdata if its flag is still 1 -- */
  623.     nlone = 0;
  624.     for(i=0;i<65000;i++) {
  625.         if (1 == lonevdata[i]) {
  626.             if (nlone < asize) { /* insert into idarray up till asize */
  627.                 idarray[nlone] = i;
  628.                 }
  629.             nlone ++;
  630.             }
  631.        }
  632.     HDfreespace (lonevdata);
  633.  
  634.     return (nlone); /* return the TOTAL # of lone vdatas */
  635.  
  636. } /* VSlone */
  637.  
  638. /* ================================================================== */
  639. /*
  640. * Vlone  - returns an array of refs of all lone vgroups in the file.
  641. *           - returns -1 if error
  642. *          - otherwise returns the total number of lone vgroups in the file 
  643. *
  644. *            If idarray is too small, routine will only fill idarray with up
  645. *             to asize worth of refs.
  646. *
  647. *            INPUT idarray: user supplies  an int array.
  648. *           INPUT asize: integer specifying how many ints in idarray[];
  649. *            INPUT f: HDF file pointer.
  650. *
  651. */
  652.  
  653. #ifdef PROTOTYPE
  654. PUBLIC int32 Vlone (HFILEID f, int32 idarray[], int32 asize) 
  655. #else
  656.  
  657. PUBLIC int32 Vlone (f, idarray, asize) 
  658.  
  659.     HFILEID    f;
  660.     int32     idarray[];         /* array to contain the refs */
  661.     int32   asize;            /* input: size of idarray */
  662. #endif
  663.  
  664. {
  665.     int16        *lonevg; /* local wrk area: stores flags of vgroups */
  666.     int32        i;
  667.     int32     vgid, vstag, id;
  668.     VGROUP     * vg;
  669.     int32     nlone; /* total number of lone vgroups */
  670.     char * FUNC = "Vlone";
  671.  
  672. /* -- allocate space for vgroup refs, init to zeroes -- */
  673.     if (NULL == (lonevg = (int16*) HDgetspace ( 65000 * sizeof(int16))))
  674.       { HERROR(DFE_NOSPACE); return(FAIL); }
  675.     for(i=0;i<65000;i++) lonevg[i] = 0;
  676.  
  677. /* -- look for all vgroups in the file, and flag (1) each -- */
  678.     id = -1;
  679.     while( -1L != (id = Vgetid (f, id)))   /* until no more vgroups */
  680.         lonevg[ id ] = 1;
  681.  
  682. /* -- Look through all vgs, searching for vgroups -- */
  683. /* -- increment its index in lonevg if found -- */
  684.     vgid = -1;
  685.     while( -1L != (vgid = Vgetid (f, vgid))) {  /* until no more vgroups */
  686.        printf("Vlone: vgid=%ld..attach",vgid);
  687.         vg = (VGROUP*) Vattach(f,vgid,"r");
  688.        printf("..attach done\n");
  689.         id = -1;
  690.         for (i=0; i< Vntagrefs(vg); i++) {
  691.             Vgettagref (vg, i, &vstag, &id);
  692.             if (vstag==VGDESCTAG) { lonevg[id]++;  }
  693.             }
  694.         Vdetach(vg);
  695.         }
  696.  
  697. /* -- check in lonevg: it's a lone vgroup if its flag is still 1 -- */
  698. nlone = 0;
  699. for(i=0;i<65000;i++) {
  700.     if (1 == lonevg[i]) {
  701.          if (nlone < asize) { /* insert into idarray up till asize */
  702.             idarray[nlone] = i;
  703.             }
  704.         nlone ++;
  705.         }
  706.    }
  707. HDfreespace (lonevg);
  708.  
  709. return (nlone); /* return the TOTAL # of lone vgroups */
  710.  
  711. } /* Vlone */
  712.  
  713.  
  714. /* ================================================================== */
  715. /* new jan 3 1991 */
  716. /* looks in the file and returns the ref of the vgroup with name vgname */
  717. /* 
  718. * returns 0 if not found, or error.
  719. * otherwise, returns the vgroup's ref (a +ve integer).
  720. */
  721.  
  722. #ifdef PROTOTYPE
  723. int32 Vfind (HFILEID f, char *vgname)
  724. #else
  725.  
  726. int32 Vfind (f, vgname)
  727.  
  728.     HFILEID    f;
  729.     char     * vgname;
  730. #endif
  731.  
  732. {
  733.       int32     vgid = -1;
  734.      VGROUP*     vg;
  735.       char         name[512];
  736.     char *     FUNC = "Vfind";
  737.  
  738.     while ( -1L != (vgid=Vgetid(f, vgid)) ) {
  739.         vg = (VGROUP*) Vattach(f,vgid,"r");
  740.         if (vg==NULL) return(0);             /* error */
  741.         Vgetname(vg, name);
  742.         Vdetach (vg);
  743.         if (!HDstrcmp(vgname,name))
  744.                   return ((int32) vg->oref);  /* found the vgroup */
  745.       }
  746.       return(0); /* not found */
  747.  
  748. } /* Vfind */
  749.  
  750. /* ================================================================== */
  751. /* new jan 3 1991 */
  752. /* looks in the file and returns the ref of the vdata with name vsname */
  753. /* 
  754. * returns 0 if not found, or error.
  755. * otherwise, returns the vdata's ref (a +ve integer).
  756. */
  757.  
  758. #ifdef PROTOTYPE
  759. int32 VSfind (HFILEID f, char *vsname)
  760. #else
  761.  
  762. int32 VSfind (f, vsname)
  763.     HFILEID    f;
  764.     char * vsname;
  765. #endif
  766.  
  767. {
  768.       int32     vsid = -1;
  769.       VDATA *     vs;
  770.       char         name[512];
  771.     char *     FUNC = "VSfind";
  772.  
  773.     while ( -1L != (vsid=VSgetid(f, vsid)) ) {
  774.         vs = (VDATA*) VSattach(f,vsid,"r");
  775.         if (vs==NULL) return(0);             /* error */
  776.         VSgetname(vs, name);
  777.         VSdetach (vs);
  778.         if (!HDstrcmp(vsname, name))
  779.                   return ((int32) vs->oref);  /* found the vdata */
  780.       }
  781.       return(0); /* not found */
  782.  
  783. } /* VSfind */
  784.  
  785. /* ================================================================== */
  786.  
  787. /*
  788. * Vsetzap: Useless now. Maintained for back compatibility.
  789. */
  790.  
  791. #ifdef PROTOTYPE
  792. PUBLIC void Vsetzap(void) 
  793. #else
  794.  
  795. PUBLIC void Vsetzap() 
  796. #endif
  797.  
  798. {
  799.  
  800.     if (vjv) { sprintf(sjs,"Vsetzap: defunct\n"); zj; }
  801. }
  802. /* ================================================================== */
  803.