home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
PRF100.LZH
/
PRFSRC.LZH
/
WRITEPRF.C
< prev
Wrap
C/C++ Source or Header
|
1991-01-29
|
4KB
|
143 lines
#define INCL_WIN
#define INCL_WINERRORS
#define INCL_WINSHELLDATA
#define INCL_WINPROGRAMLIST
#define INCL_SHLERRORS
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "prf.h"
/* must compile in far data model !!! */
static FILE *inf;
static PVOID makep(SEL sel, PVOID p)
{
PBYTE ret;
if(!p)
return(NULL);
ret = MAKEP(sel, OFFSETOF(p));
if(!*ret)
return(NULL);
return(ret);
}
static void prog(HPROGRAM gr)
{
PROGDETAILS *pd;
PROGDETAILS *pd2;
ULONG l;
ERRORID err;
fread(&l, sizeof(l), 1, inf);
pd = zalloc((size_t)l);
pd2 = zalloc((size_t)l);
fread(pd, (size_t)l, 1, inf);
memcpy(pd2, pd, (size_t)l);
pd2->pszTitle = makep(SELECTOROF(pd2), pd->pszTitle );
pd2->pszExecutable = makep(SELECTOROF(pd2), pd->pszExecutable );
pd2->pszParameters = makep(SELECTOROF(pd2), pd->pszParameters );
pd2->pszStartupDir = makep(SELECTOROF(pd2), pd->pszStartupDir );
pd2->pszIcon = makep(SELECTOROF(pd2), pd->pszIcon );
pd2->pszEnvironment = makep(SELECTOROF(pd2), pd->pszEnvironment);
#if 0
printf("\t\tLength : %lu\n", pd2->Length);
printf("\t\tCategory : %u\n", pd2->progt.progc);
printf("\t\tVisibility : %u\n", pd2->progt.fbVisible);
printf("\t\tpszTitle : %Fs\n", pd2->pszTitle );
printf("\t\tpszExecutable : %Fs\n", pd2->pszExecutable );
printf("\t\tpszParameters : %Fs\n", pd2->pszParameters );
printf("\t\tpszStartupDir : %Fs\n", pd2->pszStartupDir );
printf("\t\tpszIcon : %Fs\n", pd2->pszIcon );
printf("\t\tpszEnvironment: %Fs\n", pd2->pszEnvironment);
#endif
if(pd2->progt.progc == PROG_GROUP){
#if 0
if(!PrfChangeProgram(HINI_USERPROFILE, pd2, gr)){
printf("Error setting group info. %04lx\n", WinGetLastError(0));
exit(3);
}
#endif
}
else if(!PrfAddProgram(HINI_USERPROFILE, pd2, gr)){
err = WinGetLastError(0);
if( ERRORIDERROR(err) == PMERR_DUPLICATE_TITLE )
printf("skipped.");
else{
printf("Error adding program. %04x\n", ERRORIDERROR(err));
exit(3);
}
}
else printf("added.");
puts("");
Zree(pd2);
Zree(pd);
}
static void group(PROGTITLE *ppt)
{
PROGTITLE *pt;
ULONG cnt, l;
HPROGRAM gr;
gr = PrfCreateGroup(HINI_USERPROFILE,
MAKEP(SELECTOROF(ppt), OFFSETOF(ppt->pszTitle)),
ppt->progt.fbVisible);
if(!gr){
printf("Error creating group\n");
exit(3);
}
prog(gr); /* set group info */
fread(&l, sizeof(l), 1, inf);
if(l){
fread(&cnt, sizeof(cnt), 1, inf);
pt = zalloc((size_t)l);
fread(pt, (size_t)l, 1, inf);
for(l=0; l<cnt; l++){
printf("\tProgram:%-25Fs ", MAKEP(SELECTOROF(pt), OFFSETOF(pt[l].pszTitle)));
prog(gr);
}
Zree(pt);
}
}
static void showuse(void)
{
printf("USAGE: yctiwy <inf>\n");
}
void WRITEmain(char *fname)
{
PROGTITLE *pt;
ULONG cnt, l;
inf = fopen(fname, "rb");
if(!inf){
perror(fname);
exit(1);
}
fread(&l, sizeof(l), 1, inf);
fread(&cnt, sizeof(cnt), 1, inf);
pt = zalloc((size_t)l);
fread(pt, (size_t)l, 1, inf);
for(l=0; l<cnt; l++){
printf("Group:%s\n", MAKEP(SELECTOROF(pt), OFFSETOF(pt[l].pszTitle)));
group(&pt[l]);
}
Zree(pt);
fclose(inf);
exit(0);
}