| 1 | /************************************************************************** | 
|---|
| 2 | * | 
|---|
| 3 | * SOURCE FILE NAME = ECSET.C | 
|---|
| 4 | * | 
|---|
| 5 | * DESCRIPTIVE NAME = eCUPS part, this reads out dialog values | 
|---|
| 6 | * | 
|---|
| 7 | * Copyright : Bart van Leeuwen, netlabs 2006 | 
|---|
| 8 | * | 
|---|
| 9 | ****************************************************************************/ | 
|---|
| 10 |  | 
|---|
| 11 | #define  LINT_ARGS                     /* argument checking enabled          */ | 
|---|
| 12 |  | 
|---|
| 13 | #define  INCL_DOS | 
|---|
| 14 | #define  INCL_GPI | 
|---|
| 15 | #undef   INCL_GPI | 
|---|
| 16 | #define  INCL_DEV | 
|---|
| 17 | #define  INCL_DOSMEMMGR                /* Include standard OS/2 support      */ | 
|---|
| 18 | #define  INCL_DOSMODULEMGR             /* For DosLoadModule                  */ | 
|---|
| 19 | #define  INCL_DOSPROCESS | 
|---|
| 20 | #define  INCL_GPILCIDS | 
|---|
| 21 | #define  INCL_WINCOMMON                /* Include Window Management support  */ | 
|---|
| 22 | #define  INCL_WINDOWMGR | 
|---|
| 23 | #define  INCL_WINSWITCHLIST | 
|---|
| 24 | #define  INCL_WINPROGRAMLIST | 
|---|
| 25 | #define  INCL_WINMENUS | 
|---|
| 26 | #define  INCL_WINWINDOWMGR | 
|---|
| 27 | #define  INCL_WINMESSAGEMGR | 
|---|
| 28 | #define  INCL_WINDIALOGS | 
|---|
| 29 | #define  INCL_WINSTATICS | 
|---|
| 30 | #define  INCL_WINLISTBOXES | 
|---|
| 31 | #define  INCL_WINMENUS | 
|---|
| 32 | #define  INCL_WINSYS | 
|---|
| 33 | #define  INCL_WINFRAMEMGR | 
|---|
| 34 | #define  INCL_INCLWINACCELERATORS | 
|---|
| 35 | #define  INCL_WINPOINTERS | 
|---|
| 36 | #define  INCL_WINERRORS | 
|---|
| 37 | #define  INCL_WINSHELLDATA | 
|---|
| 38 |  | 
|---|
| 39 | #define  INCL_WINTYPES | 
|---|
| 40 | #define  INCL_WINACCELERATORS | 
|---|
| 41 | #define  INCL_WINBUTTONS | 
|---|
| 42 | #define  INCL_WINENTRYFIELDS | 
|---|
| 43 | #define  INCL_WINRECTANGLES | 
|---|
| 44 | #define  INCL_WINTIMER | 
|---|
| 45 | #define  INCL_WINSCROLLBARS | 
|---|
| 46 | #define  INCL_WINHEAP | 
|---|
| 47 | #define  INCL_SHLERRORS | 
|---|
| 48 | #define  INCL_WININPUT | 
|---|
| 49 | #define  INCL_WINHELP | 
|---|
| 50 | #define  INCL_WINSTDSPIN | 
|---|
| 51 | #define  INCL_WINSTDFILE | 
|---|
| 52 |  | 
|---|
| 53 |  | 
|---|
| 54 | #define  INCL_SPL | 
|---|
| 55 | #define  INCL_SPLP | 
|---|
| 56 | #define  INCL_SPLERRORS | 
|---|
| 57 | #define  INCL_SHLERRORS | 
|---|
| 58 | #define  INCL_DOSERRORS | 
|---|
| 59 | #define  INCL_WINHOOKS | 
|---|
| 60 | #define INCL_SPLDOSPRINT | 
|---|
| 61 |  | 
|---|
| 62 |  | 
|---|
| 63 |  | 
|---|
| 64 | #include    <os2.h> | 
|---|
| 65 |  | 
|---|
| 66 | #include    <stdlib.h> | 
|---|
| 67 | #include    <stdio.h> | 
|---|
| 68 | #include    <string.h> | 
|---|
| 69 | #include    <time.h> | 
|---|
| 70 |  | 
|---|
| 71 | #include    "ecups.h" | 
|---|
| 72 | #include    "ecdebug.h" | 
|---|
| 73 |  | 
|---|
| 74 |  | 
|---|
| 75 |  | 
|---|
| 76 | extern ECUPSSESSIONDATA  eCUPSSession; | 
|---|
| 77 |  | 
|---|
| 78 | /* | 
|---|
| 79 | ** If port driver is not defined in INI file yet | 
|---|
| 80 | **   assume it exists in the boot drive's \OS2\DLL directory | 
|---|
| 81 | */ | 
|---|
| 82 | extern PSZ szDefaultPortDrvPath; | 
|---|
| 83 |  | 
|---|
| 84 | // This structure is the base for key data pairs stored in the INI file | 
|---|
| 85 |  | 
|---|
| 86 |  | 
|---|
| 87 |  | 
|---|
| 88 | // in this array we can easely extend the data stored in the INI File | 
|---|
| 89 | // add a key name, pointer to a variable which holds the data, the datatype and the default value | 
|---|
| 90 | // the get and save data functions will do the work for you then | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 |  | 
|---|
| 94 |  | 
|---|
| 95 |  | 
|---|
| 96 |  | 
|---|
| 97 | ECUPSSESSIONDATA  eCUPSSession = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; | 
|---|
| 98 |  | 
|---|
| 99 | /**************************************************************************** | 
|---|
| 100 | * | 
|---|
| 101 | * FUNCTION NAME = SavePortSettings | 
|---|
| 102 | * | 
|---|
| 103 | * DESCRIPTION   = save any changed values for this COM port in INI file | 
|---|
| 104 | * | 
|---|
| 105 | * INPUT         = pSerialData -> this port's information | 
|---|
| 106 | * | 
|---|
| 107 | * OUTPUT        = TRUE          -  successful | 
|---|
| 108 | *                 FALSE         -  PrfWrite failed | 
|---|
| 109 | * | 
|---|
| 110 | * RETURN-NORMAL = TRUE | 
|---|
| 111 | * RETURN-ERROR  = FALSE | 
|---|
| 112 | * | 
|---|
| 113 | ****************************************************************************/ | 
|---|
| 114 |  | 
|---|
| 115 | BOOL SavePortSettings() | 
|---|
| 116 |  | 
|---|
| 117 | { | 
|---|
| 118 | ULONG count,rc; | 
|---|
| 119 | //      /* | 
|---|
| 120 | //      ** Only save settings if they don't match original settings | 
|---|
| 121 | //      ** | 
|---|
| 122 | //      ** Format of comm port initialization string: | 
|---|
| 123 | //      ** "Baudrate;Parity;Wordlength;StopBits;Handshaking" | 
|---|
| 124 | //      ** | 
|---|
| 125 | //      ** Default values are "9600;0;8;1;1;" | 
|---|
| 126 | //      ** | 
|---|
| 127 | //      */ | 
|---|
| 128 |  | 
|---|
| 129 | _PmpfF(("INICount %d",INICount)); | 
|---|
| 130 | for(count = 0; count < INICount; count ++) | 
|---|
| 131 | { | 
|---|
| 132 |  | 
|---|
| 133 | if(INIKeys[count].ulType==2) | 
|---|
| 134 | { | 
|---|
| 135 | _PmpfF(("INKey: %d -> %s - %d -> %s",count,INIKeys[count].pszKeyName,INIKeys[count].ulType,*(PSZ*)INIKeys[count].pData)); | 
|---|
| 136 | PrfWriteProfileString (HINI_SYSTEMPROFILE, | 
|---|
| 137 | APPNAME, | 
|---|
| 138 | INIKeys[count].pszKeyName, | 
|---|
| 139 | *(PSZ*)INIKeys[count].pData); | 
|---|
| 140 | } | 
|---|
| 141 | if(INIKeys[count].ulType==1) | 
|---|
| 142 | { | 
|---|
| 143 | _PmpfF(("INKey: %d -> %s - %d -> %d",count,INIKeys[count].pszKeyName,INIKeys[count].ulType,*(ULONG*)INIKeys[count].pData)); | 
|---|
| 144 | rc = PrfWriteProfileData (HINI_SYSTEMPROFILE, | 
|---|
| 145 | APPNAME, | 
|---|
| 146 | INIKeys[count].pszKeyName, | 
|---|
| 147 | INIKeys[count].pData, | 
|---|
| 148 | sizeof(ULONG)); | 
|---|
| 149 | } | 
|---|
| 150 | } | 
|---|
| 151 | return TRUE; | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 | /**************************************************************************** | 
|---|
| 155 | * | 
|---|
| 156 | * FUNCTION NAME = GetPortSettings | 
|---|
| 157 | * | 
|---|
| 158 | * DESCRIPTION   = Get port Initialization settings from INI file | 
|---|
| 159 | * | 
|---|
| 160 | * INPUT         = pSerialData -> structure containing port name. | 
|---|
| 161 | *                                On return this will have port timeout, | 
|---|
| 162 | *                                baud rate, word length, parity, stop bits | 
|---|
| 163 | *                                and handshake. | 
|---|
| 164 | * | 
|---|
| 165 | * OUTPUT        = TRUE  - if INI information found for port | 
|---|
| 166 | *                 FALSE - if INI info not found | 
|---|
| 167 | * | 
|---|
| 168 | * RETURN-NORMAL = | 
|---|
| 169 | * RETURN-ERROR  = | 
|---|
| 170 | * | 
|---|
| 171 | ****************************************************************************/ | 
|---|
| 172 |  | 
|---|
| 173 | BOOL GetPortSettings() | 
|---|
| 174 | { | 
|---|
| 175 | ULONG ulDataSize,count,rc,temp; | 
|---|
| 176 |  | 
|---|
| 177 | for(count = 0; count < INICount; count ++) | 
|---|
| 178 | { | 
|---|
| 179 | ulDataSize=0; | 
|---|
| 180 | if(INIKeys[count].ulType==2) | 
|---|
| 181 | { | 
|---|
| 182 | _PmpfF(("INKey: %d -> %s - %d rc=%d -> %s",count,INIKeys[count].pszKeyName,INIKeys[count].ulType,rc,*(PSZ*)INIKeys[count].pData)); | 
|---|
| 183 | PrfQueryProfileSize (HINI_SYSTEMPROFILE, | 
|---|
| 184 | APPNAME, | 
|---|
| 185 | INIKeys[count].pszKeyName, | 
|---|
| 186 | &ulDataSize); | 
|---|
| 187 | if(*(PSZ*)INIKeys[count].pData == NULL) | 
|---|
| 188 | { | 
|---|
| 189 | *(PSZ*)INIKeys[count].pData=malloc(ulDataSize); | 
|---|
| 190 | } | 
|---|
| 191 | else | 
|---|
| 192 | { | 
|---|
| 193 | free(*(PSZ*)INIKeys[count].pData); | 
|---|
| 194 | *(PSZ*)INIKeys[count].pData=malloc(ulDataSize); | 
|---|
| 195 | } | 
|---|
| 196 |  | 
|---|
| 197 | if(ulDataSize == 0) | 
|---|
| 198 | { | 
|---|
| 199 | if((PSZ)INIKeys[count].pDefault!=NULL) | 
|---|
| 200 | { | 
|---|
| 201 | _PmpfF(("default : %s",(PSZ)INIKeys[count].pDefault)); | 
|---|
| 202 | *(PSZ*)INIKeys[count].pData=malloc(strlen((PSZ)INIKeys[count].pDefault)); | 
|---|
| 203 | memcpy(*(PSZ*)INIKeys[count].pData,(PSZ)INIKeys[count].pDefault,strlen((PSZ)INIKeys[count].pDefault)); | 
|---|
| 204 | } | 
|---|
| 205 | else | 
|---|
| 206 | *(PSZ*)INIKeys[count].pData=NULL; | 
|---|
| 207 | } | 
|---|
| 208 | else | 
|---|
| 209 | rc = PrfQueryProfileString (HINI_SYSTEMPROFILE, | 
|---|
| 210 | APPNAME, | 
|---|
| 211 | INIKeys[count].pszKeyName, | 
|---|
| 212 | "x", | 
|---|
| 213 | *(PSZ*)INIKeys[count].pData, | 
|---|
| 214 | ulDataSize); | 
|---|
| 215 |  | 
|---|
| 216 | _PmpfF(("INKey: %d -> %s - %d rc=%d -> %s",count,INIKeys[count].pszKeyName,INIKeys[count].ulType,rc,*(PSZ*)INIKeys[count].pData)); | 
|---|
| 217 | } | 
|---|
| 218 | if(INIKeys[count].ulType==1) | 
|---|
| 219 | { | 
|---|
| 220 | _PmpfF(("INKey: %d -> %s",count,INIKeys[count].pszKeyName)); | 
|---|
| 221 | PrfQueryProfileSize (HINI_SYSTEMPROFILE, | 
|---|
| 222 | APPNAME, | 
|---|
| 223 | INIKeys[count].pszKeyName, | 
|---|
| 224 | &ulDataSize); | 
|---|
| 225 | if(ulDataSize == 0) | 
|---|
| 226 | { | 
|---|
| 227 | _PmpfF(("default : %d",(ULONG*)INIKeys[count].pDefault)); | 
|---|
| 228 | *(ULONG*)INIKeys[count].pData=(ULONG*)INIKeys[count].pDefault; | 
|---|
| 229 | } | 
|---|
| 230 | else | 
|---|
| 231 | PrfQueryProfileData (HINI_SYSTEMPROFILE, | 
|---|
| 232 | APPNAME, | 
|---|
| 233 | INIKeys[count].pszKeyName, | 
|---|
| 234 | &temp, | 
|---|
| 235 | &ulDataSize); | 
|---|
| 236 | *(ULONG*)INIKeys[count].pData = temp; | 
|---|
| 237 | _PmpfF(("INKey: %d -> %s - %d size: %d -> %d",count,INIKeys[count].pszKeyName,INIKeys[count].ulType,ulDataSize,*(ULONG*)INIKeys[count].pData)); | 
|---|
| 238 | } | 
|---|
| 239 | } | 
|---|
| 240 |  | 
|---|
| 241 |  | 
|---|
| 242 | return(TRUE); | 
|---|
| 243 | } | 
|---|
| 244 |  | 
|---|
| 245 | /**************************************************************************** | 
|---|
| 246 | * | 
|---|
| 247 | * FUNCTION NAME = GetPortDefaultSettings | 
|---|
| 248 | * | 
|---|
| 249 | * DESCRIPTION   = Get port Initialization settings from INI file | 
|---|
| 250 | * | 
|---|
| 251 | * INPUT         = pszSaveCommSetting - gets default port settings | 
|---|
| 252 | * | 
|---|
| 253 | * OUTPUT        = TRUE  - if INI information found for port | 
|---|
| 254 | *                 FALSE - if INI info not found | 
|---|
| 255 | * | 
|---|
| 256 | * RETURN-NORMAL = | 
|---|
| 257 | * RETURN-ERROR  = | 
|---|
| 258 | * | 
|---|
| 259 | ****************************************************************************/ | 
|---|
| 260 |  | 
|---|
| 261 | VOID GetPortDefaultSettings(PSZ pszSaveCommSetting) | 
|---|
| 262 | { | 
|---|
| 263 | ULONG ulDataSize,count,rc; | 
|---|
| 264 |  | 
|---|
| 265 |  | 
|---|
| 266 | for(count = 0; count < INICount; count ++) | 
|---|
| 267 | { | 
|---|
| 268 |  | 
|---|
| 269 | if(INIKeys[count].ulType==2) | 
|---|
| 270 | { | 
|---|
| 271 | *(PSZ*)INIKeys[count].pData=malloc(strlen((PSZ)INIKeys[count].pDefault)); | 
|---|
| 272 | memcpy(*(PSZ*)INIKeys[count].pData,(PSZ)INIKeys[count].pDefault,strlen((PSZ)INIKeys[count].pDefault)); | 
|---|
| 273 | } | 
|---|
| 274 | if(INIKeys[count].ulType==1) | 
|---|
| 275 | { | 
|---|
| 276 | *(ULONG*)INIKeys[count].pData=malloc(sizeof(ULONG)); | 
|---|
| 277 | memcpy(*(ULONG*)INIKeys[count].pData,(ULONG*)INIKeys[count].pDefault,sizeof(ULONG)); | 
|---|
| 278 | } | 
|---|
| 279 | } | 
|---|
| 280 | } | 
|---|