SDL  2.0
os2cp.c File Reference
#include <os2.h>
#include <string.h>
#include <ctype.h>
#include "os2cp.h"
+ Include dependency graph for os2cp.c:

Go to the source code of this file.

Data Structures

struct  CP2NAME
 
struct  NAME2CP
 

Macros

#define INCL_DOSNLS
 
#define INCL_DOSERRORS
 

Functions

char * os2cpToName (unsigned long cp)
 
unsigned long os2cpFromName (char *cp)
 

Variables

static CP2NAME aCP2Name []
 
static NAME2CP aName2CP []
 

Macro Definition Documentation

◆ INCL_DOSERRORS

#define INCL_DOSERRORS

Definition at line 23 of file os2cp.c.

◆ INCL_DOSNLS

#define INCL_DOSNLS

Definition at line 22 of file os2cp.c.

Function Documentation

◆ os2cpFromName()

unsigned long os2cpFromName ( char *  cp)

Definition at line 340 of file os2cp.c.

341 {
342  ULONG ulLo = 0;
343  ULONG ulHi = (sizeof(aName2CP) / sizeof(struct _NAME2CP)) - 1;
344  ULONG ulNext;
345  LONG lFound = -1;
346  LONG lCmp;
347  PCHAR pcEnd;
348  CHAR acBuf[64];
349 
350  if (cp == NULL) {
351  ULONG aulCP[3];
352  ULONG cCP;
353 
354  return (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)? 0 : aulCP[0];
355  }
356 
357  while (isspace(*cp))
358  cp++;
359 
360  pcEnd = strchr(cp, ' ');
361  if (pcEnd == NULL)
362  pcEnd = strchr(cp, '\0');
363 
364  ulNext = pcEnd - cp;
365  if (ulNext >= sizeof(acBuf))
366  return 0;
367 
368  memcpy(acBuf, cp, ulNext);
369  acBuf[ulNext] = '\0';
370  strupr(acBuf);
371 
372  lCmp = strcmp(aName2CP[0].pszName, acBuf);
373  if (lCmp > 0)
374  return 0;
375  else if (lCmp == 0)
376  return aName2CP[0].ulCode;
377 
378  lCmp = strcmp(aName2CP[ulHi].pszName, acBuf);
379  if (lCmp < 0)
380  return 0;
381  else if (lCmp == 0)
382  return aName2CP[ulHi].ulCode;
383 
384  while ((ulHi - ulLo) > 1) {
385  ulNext = (ulLo + ulHi) / 2;
386 
387  lCmp = strcmp(aName2CP[ulNext].pszName, acBuf);
388  if (lCmp < 0)
389  ulLo = ulNext;
390  else if (lCmp > 0)
391  ulHi = ulNext;
392  else {
393  lFound = ulNext;
394  break;
395  }
396  }
397 
398  return (lFound == -1)? 0 : aName2CP[lFound].ulCode;
399 }
#define memcpy
Definition: SDL_malloc.c:630
#define NULL
Definition: begin_code.h:163
static const double cp
Definition: e_pow.c:96
static NAME2CP aName2CP[]
Definition: os2cp.c:87
ULONG ulCode
Definition: os2cp.c:37

References aName2CP, cp, memcpy, NULL, and NAME2CP::ulCode.

Referenced by uconv_open().

◆ os2cpToName()

char* os2cpToName ( unsigned long  cp)

Definition at line 298 of file os2cp.c.

299 {
300  ULONG ulLo = 0;
301  ULONG ulHi = (sizeof(aCP2Name) / sizeof(struct _CP2NAME)) - 1;
302  ULONG ulNext;
303  LONG lFound = -1;
304 
305  if (cp == SYSTEM_CP) {
306  ULONG aulCP[3];
307  ULONG cCP;
308 
309  if (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)
310  return NULL;
311 
312  cp = aulCP[0];
313  }
314 
315  if (aCP2Name[0].ulCode > cp || aCP2Name[ulHi].ulCode < cp)
316  return NULL;
317 
318  if (aCP2Name[0].ulCode == cp)
319  return aCP2Name[0].pszName;
320 
321  if (aCP2Name[ulHi].ulCode == cp)
322  return aCP2Name[ulHi].pszName;
323 
324  while ((ulHi - ulLo) > 1) {
325  ulNext = (ulLo + ulHi) / 2;
326 
327  if (aCP2Name[ulNext].ulCode < cp)
328  ulLo = ulNext;
329  else if (aCP2Name[ulNext].ulCode > cp)
330  ulHi = ulNext;
331  else {
332  lFound = ulNext;
333  break;
334  }
335  }
336 
337  return (lFound == -1)? NULL : aCP2Name[lFound].pszName;
338 }
static CP2NAME aCP2Name[]
Definition: os2cp.c:40
#define SYSTEM_CP
Definition: os2cp.h:25
PSZ pszName
Definition: os2cp.c:32

References aCP2Name, cp, NULL, CP2NAME::pszName, and SYSTEM_CP.

Variable Documentation

◆ aCP2Name

CP2NAME aCP2Name[]
static

Definition at line 40 of file os2cp.c.

Referenced by os2cpToName().

◆ aName2CP

NAME2CP aName2CP[]
static

Definition at line 87 of file os2cp.c.

Referenced by os2cpFromName().