home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / PRF100.LZH / PRFSRC.LZH / WRITEPRF.C < prev   
C/C++ Source or Header  |  1991-01-29  |  4KB  |  143 lines

  1. #define INCL_WIN
  2. #define INCL_WINERRORS
  3. #define INCL_WINSHELLDATA
  4. #define INCL_WINPROGRAMLIST
  5. #define INCL_SHLERRORS
  6. #include <os2.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "prf.h"
  11.  
  12.  
  13. /* must compile in far data model !!! */
  14.  
  15. static  FILE *inf;
  16.  
  17. static PVOID makep(SEL sel, PVOID p)
  18. {
  19.     PBYTE ret;
  20.     if(!p)
  21.         return(NULL);
  22.     ret = MAKEP(sel, OFFSETOF(p));
  23.     if(!*ret)
  24.         return(NULL);
  25.     return(ret);
  26. }
  27.  
  28. static void prog(HPROGRAM gr)
  29. {
  30.     PROGDETAILS *pd;
  31.     PROGDETAILS *pd2;
  32.     ULONG l;
  33.     ERRORID err;
  34.  
  35.     fread(&l, sizeof(l), 1, inf);
  36.     pd = zalloc((size_t)l);
  37.     pd2 = zalloc((size_t)l);
  38.     fread(pd, (size_t)l, 1, inf);
  39.  
  40.     memcpy(pd2, pd, (size_t)l);
  41.     pd2->pszTitle       = makep(SELECTOROF(pd2), pd->pszTitle      );
  42.     pd2->pszExecutable  = makep(SELECTOROF(pd2), pd->pszExecutable );
  43.     pd2->pszParameters  = makep(SELECTOROF(pd2), pd->pszParameters );
  44.     pd2->pszStartupDir  = makep(SELECTOROF(pd2), pd->pszStartupDir );
  45.     pd2->pszIcon        = makep(SELECTOROF(pd2), pd->pszIcon       );
  46.     pd2->pszEnvironment = makep(SELECTOROF(pd2), pd->pszEnvironment);
  47. #if 0
  48.     printf("\t\tLength        : %lu\n",  pd2->Length);
  49.     printf("\t\tCategory      : %u\n",   pd2->progt.progc);
  50.     printf("\t\tVisibility    : %u\n",   pd2->progt.fbVisible);
  51.     printf("\t\tpszTitle      : %Fs\n",  pd2->pszTitle      );
  52.     printf("\t\tpszExecutable : %Fs\n",  pd2->pszExecutable );
  53.     printf("\t\tpszParameters : %Fs\n",  pd2->pszParameters );
  54.     printf("\t\tpszStartupDir : %Fs\n",  pd2->pszStartupDir );
  55.     printf("\t\tpszIcon       : %Fs\n",  pd2->pszIcon       );
  56.     printf("\t\tpszEnvironment: %Fs\n",  pd2->pszEnvironment);
  57. #endif
  58.     if(pd2->progt.progc == PROG_GROUP){
  59. #if 0
  60.         if(!PrfChangeProgram(HINI_USERPROFILE, pd2, gr)){
  61.             printf("Error setting group info. %04lx\n", WinGetLastError(0));
  62.             exit(3);
  63.         }
  64. #endif
  65.     }
  66.     else if(!PrfAddProgram(HINI_USERPROFILE, pd2, gr)){
  67.         err = WinGetLastError(0);
  68.         if( ERRORIDERROR(err) == PMERR_DUPLICATE_TITLE )
  69.             printf("skipped.");
  70.         else{
  71.             printf("Error adding program. %04x\n", ERRORIDERROR(err));
  72.             exit(3);
  73.         }
  74.     }
  75.     else  printf("added.");
  76.     puts("");
  77.     Zree(pd2);
  78.     Zree(pd);
  79. }
  80.  
  81. static void group(PROGTITLE *ppt)
  82. {
  83.     PROGTITLE *pt;
  84.     ULONG cnt, l;
  85.     HPROGRAM gr;
  86.  
  87.     gr = PrfCreateGroup(HINI_USERPROFILE,
  88.                         MAKEP(SELECTOROF(ppt), OFFSETOF(ppt->pszTitle)),
  89.                         ppt->progt.fbVisible);
  90.     if(!gr){
  91.         printf("Error creating group\n");
  92.         exit(3);
  93.     }
  94.     prog(gr);       /* set group info */
  95.  
  96.     fread(&l, sizeof(l), 1, inf);
  97.     if(l){
  98.         fread(&cnt, sizeof(cnt), 1, inf);
  99.         pt = zalloc((size_t)l);
  100.         fread(pt, (size_t)l, 1, inf);
  101.  
  102.         for(l=0; l<cnt; l++){
  103.             printf("\tProgram:%-25Fs ", MAKEP(SELECTOROF(pt), OFFSETOF(pt[l].pszTitle)));
  104.             prog(gr);
  105.         }
  106.         Zree(pt);
  107.     }
  108. }
  109.  
  110.  
  111. static void showuse(void)
  112. {
  113.     printf("USAGE: yctiwy <inf>\n");
  114. }
  115.  
  116. void WRITEmain(char *fname)
  117. {
  118.     PROGTITLE *pt;
  119.     ULONG cnt, l;
  120.  
  121.     inf = fopen(fname, "rb");
  122.     if(!inf){
  123.         perror(fname);
  124.         exit(1);
  125.     }
  126.  
  127.     fread(&l, sizeof(l), 1, inf);
  128.     fread(&cnt, sizeof(cnt), 1, inf);
  129.  
  130.     pt = zalloc((size_t)l);
  131.  
  132.     fread(pt, (size_t)l, 1, inf);
  133.  
  134.     for(l=0; l<cnt; l++){
  135.         printf("Group:%s\n", MAKEP(SELECTOROF(pt), OFFSETOF(pt[l].pszTitle)));
  136.         group(&pt[l]);
  137.     }
  138.     Zree(pt);
  139.     fclose(inf);
  140.     exit(0);
  141. }
  142.  
  143.