home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / src / vparse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-28  |  4.1 KB  |  143 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/vparse.c,v 1.3 1992/10/23 00:14:11 koziol beta koziol $
  30.  
  31. $Log: vparse.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.1  1992/08/25  21:40:44  koziol
  40.  * Initial revision
  41.  *
  42. */
  43. /*****************************************************************************
  44. *
  45. * vparse.c
  46. * Part of the HDF VSet interface.
  47. *
  48. ************************************************************************/
  49.  
  50. #include "vg.h"
  51.  
  52. #define ISCOMMA(c) ( (c==',') ? 1:0 )
  53.  
  54. /* ------------------------------------------------------------------ */
  55.  
  56. /*
  57. ** Given a string (attrs) , the routine parses it into token strings,
  58. ** and returns a ptr (attrv) to an array of ptrs where the tokens 
  59. ** are stored.  The no of tokens are returned in attrc.
  60. **
  61. ** Currently used only by routines that manipulate field names.
  62. ** As such each field string is truncated to a max length of
  63. ** FIELDNAMELENMAX (as defined in vg.h). For most cases, this
  64. ** truncation doesn't happen because FIELDNAMELENMAX is a big number.
  65. **
  66. ** RETURN -1 if error.
  67. ** RETURN 1 if ok.
  68. **
  69. ** Current implementation: all strings inputs converted to uppercase.    
  70. ** tokens must be separated by COMMAs.
  71. **
  72. ** Tokens are stored in static area sym , and pointers are returned
  73. ** to calling routine. Hence, tokens must be used before next call 
  74. ** to scanattrs.
  75. **
  76. */
  77.  
  78. PRIVATE char*     symptr[50];
  79. PRIVATE char    sym[50][FIELDNAMELENMAX+1];
  80. PRIVATE    intn     nsym;
  81.  
  82. #ifdef PROTOTYPE
  83. int32 scanattrs (char *attrs, int32 *attrc, char ***attrv)
  84. #else
  85. int32 scanattrs (attrs,attrc,attrv)
  86.  
  87.     char    *attrs;        /* field string (input) */
  88.     int32    *attrc;        /* # of fields (output) */
  89.     char    ***attrv;    /* array of char ptrs to fields (output) */
  90. #endif
  91.  
  92. {
  93.   register char   *s, *s0, *ss;
  94.   register intn   i, slen, len;
  95.   char * FUNC = "scanattrs";
  96.   
  97.   s = attrs;
  98.   slen = HDstrlen(s);
  99.   nsym = 0;
  100.   
  101.   s0 = s;
  102.   for (i = 0; i < slen; i++, s++)
  103.     if ( ISCOMMA(*s) ) {
  104.       len = s - s0; 
  105.       if (len <= 0) return(FAIL);
  106.  
  107.       /* save that token */
  108.       ss = symptr[nsym] = sym[nsym]; 
  109.       nsym++;
  110.       
  111.       if ( len > FIELDNAMELENMAX) len = FIELDNAMELENMAX;
  112.       HIstrncpy(ss, s0, len + 1);
  113.       s0 = s+1;
  114.     }
  115.   
  116.   /* save the last token */
  117.   len = s - s0; 
  118.   if (len <= 0) return(FAIL);
  119.   ss = symptr[nsym] = sym[nsym]; 
  120.   nsym++;
  121.   
  122.   if ( len > FIELDNAMELENMAX) len = FIELDNAMELENMAX;
  123.   HIstrncpy(ss, s0, len + 1);
  124.   
  125.   /* convert all fields tokens to uppercase */
  126.   for (i = 0; i < nsym; i++) {
  127.     s = symptr[i];
  128.     while(*s != '\0') {
  129.       if (*s >= 'a' && *s <= 'z') *s=(char)toupper(*s);
  130.       s++;
  131.     }
  132.   }
  133.   
  134.   symptr[nsym] = NULL;
  135.   *attrc = nsym;
  136.   *attrv = (char**) symptr;
  137.   
  138.   return(SUCCEED); /* ok */
  139.   
  140. } /* scanattrs */
  141.  
  142. /* ------------------------------------------------------------------ */
  143.