home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / wpstools.lzh / ENUMAPP.C < prev    next >
C/C++ Source or Header  |  1992-03-14  |  2KB  |  82 lines

  1. /*******************************************/
  2. /* This call retrieves a string from the   */
  3. /* specified profile.                      */
  4. /*******************************************/
  5.  
  6. #define SPIT_DATA 0
  7. #define DEBUG     0
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. #define INCL_WINSHELLDATA   /* Or use INCL_WIN or INCL_PM */
  13. #include <os2.h>
  14.  
  15. #define APP_BUFFER_SIZE     10000
  16. #define KEY_BUFFER_SIZE     40000
  17. #define VAL_BUFFER_SIZE     10000
  18.  
  19. int main(int argc, char *argv[])
  20. {
  21.     ULONG  pulLength;      /*String length returned */
  22.     ULONG  max_length = 0UL;      /*String length returned */
  23.  
  24.     PSZ    appnames = malloc( APP_BUFFER_SIZE );
  25.     PSZ    keynames = malloc( KEY_BUFFER_SIZE );
  26. #if SPIT_DATA
  27.     PSZ    values   = malloc( VAL_BUFFER_SIZE );
  28. #endif
  29.     PSZ    papp;
  30.     ULONG  app_buffer_size = APP_BUFFER_SIZE;
  31.  
  32.     /* get all app names into appnames */
  33.     app_buffer_size = APP_BUFFER_SIZE;
  34.     pulLength = PrfQueryProfileData(HINI_PROFILE,
  35.                     NULL, NULL, appnames, &app_buffer_size);
  36.  
  37.     for (papp = appnames; *papp; papp += strlen(papp)+1) {
  38.         PSZ   pkey;
  39.         ULONG length = KEY_BUFFER_SIZE;
  40.         if (! PrfQueryProfileData(HINI_PROFILE,
  41.                     papp, NULL, keynames, &length))
  42.             break;
  43.  
  44.         if (length > max_length)
  45.             max_length = length;
  46.  
  47.         for (pkey = keynames; *pkey;  pkey += strlen(pkey)+1) {
  48. #if SPIT_DATA
  49.             ULONG length = VAL_BUFFER_SIZE;
  50.             if ( !PrfQueryProfileData(HINI_PROFILE,
  51.                     papp, pkey, values, &length))
  52.                         break;
  53.             printf("%06lu\t",
  54.                 strlen(pkey) + strlen(papp) + 11 + (unsigned long)length);
  55. #endif
  56.             fputs(papp, stdout);
  57.             fputs("\t", stdout);
  58.             fputs(pkey, stdout);
  59.             fputs("\t", stdout);
  60.  
  61. #if SPIT_DATA
  62.             fwrite(values, 1, length, stdout);
  63. #endif
  64.             fputs("\n", stdout);
  65.         }
  66.     }
  67.  
  68. #if SPIT_DATA
  69.     free(values);
  70. #endif
  71.     free(keynames);
  72.     free(appnames);
  73.  
  74. #if DEBUG
  75.     printf("%lu bytes of app names\n", (unsigned long) pulLength);
  76.     printf("%lu bytes max of key names\n", (unsigned long) max_length);
  77. #endif
  78.  
  79.     return 0;
  80. }
  81.  
  82.