home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / e / epmmac2.zip / EPMDBCS.E < prev    next >
Text File  |  1993-01-12  |  3KB  |  96 lines

  1. definit
  2.    universal country
  3.    universal codepage
  4.    universal dbcsvec
  5.    universal ondbcs
  6.  
  7. compile if EPM32
  8.    inp=copies(\0, 8)
  9.    buf=copies(\0, 44)
  10.    ret=\0\0\0\0
  11.    call dynalinkc('NLS', '#5',              -- DOS32QueryCountryInfo
  12.                  atol(length(buf))        ||
  13.                  offset(inp)selector(inp) ||
  14.                  offset(buf)selector(buf) ||
  15.                  offset(ret)selector(ret),
  16.                  2)
  17.    country=ltoa(leftstr(buf,4),10)
  18.  
  19.    codepage = '????'; datalen = '????'
  20.    call dynalinkc('DOSCALLS',            -- dynamic link library name
  21.                  '#291',                -- ordinal value for DOS32QueryCP
  22.                  atol(4)            ||  -- length of code page list
  23.                  offset(codepage)   ||  -- string offset
  24.                  selector(codepage) ||  -- string selector
  25.                  offset(datalen)    ||  -- string offset
  26.                  selector(datalen),2)   -- string selector
  27.    codepage = ltoa(codepage,10)
  28.  
  29.    inp=copies(\0,8)
  30.    dbcsvec=copies(\0, 12)
  31.    call dynalinkc('NLS', '#6',
  32.                  atol(length(dbcsvec)) ||
  33.                  offset(inp)selector(inp) ||
  34.                  offset(dbcsvec)selector(dbcsvec),
  35.                  2)
  36.    ondbcs = leftstr(dbcsvec, 2) <> atoi(0)
  37. compile else
  38.    inp=atol(0)
  39.    buf=copies(\0, 38)
  40.    ret=\0\0
  41.    call dynalink('NLS', 'DOSGETCTRYINFO',
  42.                  atoi(length(buf)) ||
  43.                  selector(inp)offset(inp) ||
  44.                  selector(buf)offset(buf) ||
  45.                  selector(ret)offset(ret),
  46.                  1)
  47.    country=itoa(substr(buf,1,2),10)
  48.    codepage=itoa(substr(buf,3,2),10)
  49.  
  50.    inp=atol(0)
  51.    dbcsvec=copies(\0, 10)
  52.    call dynalink('NLS', 'DOSGETDBCSEV',
  53.                  atoi(length(dbcsvec)) ||
  54.                  selector(inp)offset(inp) ||
  55.                  selector(dbcsvec)offset(dbcsvec),
  56.                   1)
  57.    ondbcs = leftstr(dbcsvec, 2) <> atoi(0)
  58. compile endif  -- EPM32
  59.  
  60. defproc isdbcs(c)
  61.    universal dbcsvec, ondbcs
  62.    if not ondbcs then
  63.       return 0
  64.    endif
  65.    c=leftstr(c,1)
  66.    for i = 1 to length(dbcsvec) by 2
  67.       if substr(dbcsvec,i,2)=atoi(0) then
  68.          leave
  69.       endif
  70.       if substr(dbcsvec, i, 1) <= c and c <= substr(dbcsvec, i + 1, 1) then
  71.          return 1
  72.       endif
  73.    endfor
  74.    return 0
  75.  
  76. defproc whatisit(s, p)
  77.    l = length(s)
  78.    i = 1
  79.    while i <= l do
  80.       if i > p then
  81.          leave
  82.       endif
  83.       if isdbcs(substr(s, i, 1)) then
  84.          if i = p then
  85.             return 1 -- DBCS 1st
  86.          elseif i + 1 = p then
  87.             return 2 -- DBCS 2nd
  88.          else
  89.             i = i + 2
  90.          endif
  91.       else
  92.          i = i + 1
  93.       endif
  94.    endwhile
  95.    return 0 -- SBCS
  96.