1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
#define INCL_WINSHELLDATA /* Or use INCL_WIN, INCL_PM, */
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <os2.h>
#ifdef __cplusplus
}
#endif
#define Prf_Open(pszFileName) SaveWinError(pPrfOpenProfile(Perl_hab, (pszFileName)))
#define Prf_Close(hini) (!CheckWinError(pPrfCloseProfile(hini)))
BOOL (*pPrfCloseProfile) (HINI hini);
HINI (*pPrfOpenProfile) (HAB hab, PCSZ pszFileName);
BOOL (*pPrfQueryProfile) (HAB hab, PPRFPROFILE pPrfProfile);
BOOL (*pPrfQueryProfileData) (HINI hini, PCSZ pszApp, PCSZ pszKey, PVOID pBuffer,
PULONG pulBufferLength);
/*
LONG (*pPrfQueryProfileInt) (HINI hini, PCSZ pszApp, PCSZ pszKey, LONG sDefault);
*/
BOOL (*pPrfQueryProfileSize) (HINI hini, PCSZ pszApp, PCSZ pszKey,
PULONG pulReqLen);
/*
ULONG (*pPrfQueryProfileString) (HINI hini, PCSZ pszApp, PCSZ pszKey,
PCSZ pszDefault, PVOID pBuffer, ULONG ulBufferLength);
*/
BOOL (*pPrfReset) (HAB hab, __const__ PRFPROFILE *pPrfProfile);
BOOL (*pPrfWriteProfileData) (HINI hini, PCSZ pszApp, PCSZ pszKey,
CPVOID pData, ULONG ulDataLength);
/*
BOOL (*pPrfWriteProfileString) (HINI hini, PCSZ pszApp, PCSZ pszKey,
PCSZ pszData);
*/
SV *
Prf_Get(pTHX_ HINI hini, PSZ app, PSZ key) {
ULONG len;
BOOL rc;
SV *sv;
if (CheckWinError(pPrfQueryProfileSize(hini, app, key, &len))) return &PL_sv_undef;
sv = newSVpv("", 0);
SvGROW(sv, len + 1);
if (CheckWinError(pPrfQueryProfileData(hini, app, key, SvPVX(sv), &len))
|| (len == 0 && (app == NULL || key == NULL))) { /* Somewhy needed. */
SvREFCNT_dec(sv);
return &PL_sv_undef;
}
SvCUR_set(sv, len);
*SvEND(sv) = 0;
return sv;
}
I32
Prf_GetLength(HINI hini, PSZ app, PSZ key) {
U32 len;
if (CheckWinError(pPrfQueryProfileSize(hini, app, key, &len))) return -1;
return len;
}
#define Prf_Set(hini, app, key, s, l) \
(!(CheckWinError(pPrfWriteProfileData(hini, app, key, s, l))))
#define Prf_System(key) \
( (key) ? ( (key) == 1 ? HINI_USERPROFILE \
: ( (key) == 2 ? HINI_SYSTEMPROFILE \
: (die("Wrong profile id %i", key), 0) )) \
: HINI_PROFILE)
SV*
Prf_Profiles(pTHX)
{
AV *av = newAV();
SV *rv;
char user[257];
char system[257];
PRFPROFILE info = { 257, user, 257, system};
if (CheckWinError(pPrfQueryProfile(Perl_hab, &info))) return &PL_sv_undef;
if (info.cchUserName > 257 || info.cchSysName > 257)
die("Panic: Profile names too long");
av_push(av, newSVpv(user, info.cchUserName - 1));
av_push(av, newSVpv(system, info.cchSysName - 1));
rv = newRV((SV*)av);
SvREFCNT_dec(av);
return rv;
}
BOOL
Prf_SetUser(pTHX_ SV *sv)
{
char user[257];
char system[257];
PRFPROFILE info = { 257, user, 257, system};
if (!SvPOK(sv)) die("User profile name not defined");
if (SvCUR(sv) > 256) die("User profile name too long");
if (CheckWinError(pPrfQueryProfile(Perl_hab, &info))) return 0;
if (info.cchSysName > 257)
die("Panic: System profile name too long");
info.cchUserName = SvCUR(sv) + 1;
info.pszUserName = SvPVX(sv);
return !CheckWinError(pPrfReset(Perl_hab, &info));
}
MODULE = OS2::PrfDB PACKAGE = OS2::Prf PREFIX = Prf_
HINI
Prf_Open(pszFileName)
PSZ pszFileName;
BOOL
Prf_Close(hini)
HINI hini;
SV *
Prf_Get(hini, app, key)
HINI hini;
PSZ app;
PSZ key;
CODE:
RETVAL = Prf_Get(aTHX_ hini, app, key);
OUTPUT:
RETVAL
int
Prf_Set(hini, app, key, s, l = (SvPOK(ST(3)) ? SvCUR(ST(3)): -1))
HINI hini;
PSZ app;
PSZ key;
PSZ s;
ULONG l;
I32
Prf_GetLength(hini, app, key)
HINI hini;
PSZ app;
PSZ key;
HINI
Prf_System(key)
int key;
SV*
Prf_Profiles()
CODE:
RETVAL = Prf_Profiles(aTHX);
OUTPUT:
RETVAL
BOOL
Prf_SetUser(sv)
SV *sv
CODE:
RETVAL = Prf_SetUser(aTHX_ sv);
OUTPUT:
RETVAL
BOOT:
Acquire_hab();
AssignFuncPByORD(pPrfQueryProfileSize, ORD_PRF32QUERYPROFILESIZE);
AssignFuncPByORD(pPrfOpenProfile, ORD_PRF32OPENPROFILE);
AssignFuncPByORD(pPrfCloseProfile, ORD_PRF32CLOSEPROFILE);
AssignFuncPByORD(pPrfQueryProfile, ORD_PRF32QUERYPROFILE);
AssignFuncPByORD(pPrfReset, ORD_PRF32RESET);
AssignFuncPByORD(pPrfQueryProfileData, ORD_PRF32QUERYPROFILEDATA);
AssignFuncPByORD(pPrfWriteProfileData, ORD_PRF32WRITEPROFILEDATA);
|