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