Changeset 26 for branches/1.0/src/utils.c
- Timestamp:
- Apr 19, 2010, 5:34:31 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/src/utils.c
r23 r26 1 #include <os2.h>1 #include "uni.h" 2 2 3 3 #include <stdlib.h> … … 100 100 } 101 101 102 /* Alex Taylor's new version of lprtok() that can handle missing fields */ 103 char * lprtok (char *string,char *control) 104 { 105 char *c; 106 static char *next; 107 108 if ( control == NULL ) return string; 109 if ( string == NULL ) string = next; 110 if ( string == NULL ) return NULL; 111 112 if (( c = strpbrk( string, control )) == NULL ) { 113 next = NULL; 114 } 115 else { 116 next = c+1; 117 *c = '\0'; 118 } 119 120 return ( string ); 121 } 122 123 ULONG CalcStructLength ( HAB hab, HMODULE hModule, USHORT usID ) 124 { 125 ULONG cbRequired; 126 CHAR chString[STR_LEN_PORTDESC]; 127 128 cbRequired = 0; 129 130 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chString); 131 cbRequired += strlen (chString) + 1; 132 WinLoadString(hab, hModule, (USHORT)(usID + 1), STR_LEN_PORTDESC, chString); 133 cbRequired += strlen (chString) + 1; 134 cbRequired += sizeof (PORTNAMES); 135 return(cbRequired); 136 } 137 138 ULONG CalcBufLength ( HAB hab, HMODULE hModule ) 139 { 140 ULONG cbRequired; 141 USHORT usID; 142 143 cbRequired = 0; 144 145 /* 146 ** calculate length required to fit all the port info. 147 */ 148 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 149 { 150 cbRequired += CalcStructLength (hab, hModule, usID); 151 } 152 153 return(cbRequired); 154 } 155 156 ULONG NumPortsCanFit ( HAB hab, HMODULE hModule, ULONG cbBuf ) 157 { 158 ULONG cbRequired; 159 USHORT usID; 160 ULONG ulNumPort; 161 162 cbRequired = 0; 163 ulNumPort = 0; 164 165 /* 166 ** calculate how many ports we can fit in buf. 167 */ 168 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 169 { 170 cbRequired += CalcStructLength (hab, hModule, usID); 171 if (cbRequired > cbBuf) 172 { 173 return(ulNumPort); 174 } 175 ulNumPort++; 176 } 177 178 return(ulNumPort); 179 } 180 VOID CopyStruct ( HAB hab, HMODULE hModule, USHORT usID, PCH pBuf, PULONG pulBeginStruct, PULONG pulBeginText ) 181 { 182 PPORTNAMES pPortNames; 183 184 pPortNames = (PPORTNAMES)(pBuf + *pulBeginStruct); 185 *pulBeginStruct += sizeof (PORTNAMES); 186 187 /* 188 ** copy port name in the structure 189 */ 190 pPortNames->pszPortName = pBuf + *pulBeginText; 191 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName); 192 *pulBeginText += strlen (pPortNames->pszPortName) + 1; 193 194 /* 195 ** copy port description to the structure 196 */ 197 pPortNames->pszPortDesc = pBuf + *pulBeginText; 198 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortDesc); 199 *pulBeginText += strlen (pPortNames->pszPortDesc) + 1; 200 } 201 VOID CopyNPorts ( HAB hab, HMODULE hModule, PCH pBuf, ULONG ulReturned ) 202 { 203 USHORT usID; 204 ULONG ulBeginText; 205 ULONG ulBeginStruct; 206 207 ulBeginText = ulReturned * sizeof (PORTNAMES); 208 ulBeginStruct = 0; 209 210 for (usID = PORT_ID_FIRST; 211 usID <= PORT_ID_LAST && ulReturned; 212 usID += 2, --ulReturned) 213 { 214 CopyStruct (hab, hModule, usID, pBuf, &ulBeginStruct, &ulBeginText); 215 } 216 } 217 218 BOOL GetPortDescription ( HAB hab, HMODULE hModule, PSZ pszPortName, PSZ pszPortDesc ) 219 { 220 USHORT usID; 221 CHAR chBuf[STR_LEN_PORTDESC] = {0}; 222 223 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 224 { 225 WinLoadString(hab, hModule, usID, STR_LEN_PORTNAME, chBuf); 226 if (!strcmp (pszPortName, chBuf)) 227 { 228 if ( WinLoadString(hab, hModule, usID+1, STR_LEN_PORTDESC, chBuf) ) { 229 strcpy (pszPortDesc, chBuf); 230 return(TRUE); 231 } 232 break; 233 } 234 } 235 return(FALSE); 236 } 237 238 BOOL GenerateUniquePortName( PSZ pszPortName ) 239 { 240 BOOL fPortExists; 241 PSZ pszEndPortName; 242 USHORT i; 243 CHAR chPortData[STR_LEN_PORTNAME]; 244 245 /* 246 ** Generate a unique port name by adding numbers to the 247 ** end of pszPortName 248 */ 249 pszEndPortName = pszPortName + strlen( pszPortName ); 250 i = 1; 251 fPortExists = TRUE; 252 while ( (i < MAX_PORTS) && fPortExists ) 253 { 254 _itoa( i, pszEndPortName, 4); 255 fPortExists = PrfQueryProfileString (HINI_SYSTEMPROFILE, 256 APPNAME_PM_SPOOLER_PORT, 257 pszPortName, 258 NULL, 259 chPortData, 260 sizeof(chPortData) - 1); 261 i++; 262 } 263 return(!fPortExists); 264 } 265
Note:
See TracChangeset
for help on using the changeset viewer.