⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nls.c

📁 用C语言实现的DOS操作系统的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
                mov     ax,uSegTable
                mov     dx,uOffTable
                mov     ds,ax
                mov     ax,1404h
                int     2Fh
                pop     ds
                mov     CntryCode,bx
                mov     nLclRet,al
        }
        *nRetCode = nLclRet;
        return CntryCode;
} 


UWORD GetCtryInfo(UBYTE FAR *lpShrtCode, UWORD FAR *lpLongCode,
        BYTE FAR *lpTable)
{
        UWORD CntryCode;

        if(0xff != *lpShrtCode)
                CntryCode = *lpShrtCode;
        else
                CntryCode = *lpLongCode;

        fbcopy((BYTE FAR *)&nlsInfo.nlsExtCtryInfo.nlsCtryInfo,
          lpTable, sizeof(struct ctryInfo));
        return nlsInfo.nlsExtCtryInfo.countryCode;
} 


BOOL
ExtCtryInfo(UBYTE nOpCode, UWORD CodePageID, UWORD InfoSize, VOID FAR *Information)
{
        VOID FAR *lpSource;
        COUNT nIdx;

        if(0xffff != CodePageID)
        {
                UBYTE nNlsEntry;

                if(NlsFuncInst() >= 0)
                        return FALSE;

                asm {
                        mov     bp,word ptr nOpCode
                        mov     bx,CodePageID
                        mov     si,word ptr Information+2
                        mov     ds,si
                        mov     si,word ptr Information
                        mov     ax,1402h
                        int     2Fh
                        cmp     al,0
                        mov     nNlsEntry,al
                }

                if(0 != nNlsEntry)
                        return FALSE;

                return  TRUE;
        }

        CodePageID = nlsInfo.nlsExtCtryInfo.codePage;

        for(nIdx = 0; nIdx < nlsInfo.nlsExtCtryInfo.nFnEntries; nIdx++)
        {
                if(nlsInfo.nlsExtCtryInfo.VectorTable[nIdx].FnCode == nOpCode)
                {
                        BYTE FAR *bp = Information;
                        lpSource = nlsInfo.nlsExtCtryInfo.VectorTable[nIdx].Table;

                        if (nOpCode == 1)
                        {
                            bp++;     // first byte unused    
                            *bp = (BYTE)(sizeof(struct ctryInfo) + 4);
                            bp += 2;

                            fbcopy(lpSource, bp, InfoSize > 3? InfoSize - 3 : 0);
                        } else {
                            *bp++ = nOpCode;
                            *((VOID FAR **)bp) = lpSource;
                        }
                        return TRUE;
                }
        }

        return FALSE;
}

UWORD internalUpcase(UWORD c)
{            
        if (!(c & 0x80)) return c;

        return (c & 0xff00) | (nlsInfo.upNormCh[c & 0x7f] & 0xff);
}

char upMChar(UPMAP map, char ch)
/* upcase character ch according to the map */
{       return (ch >= 'a' && ch <= 'z')? ch + 'A' - 'a':
                        ((unsigned)ch > 0x7f? map[ch & 0x7f]: ch);
}

VOID upMMem(UPMAP map, char FAR *str, unsigned len)
{       REG unsigned c;

        if(len) do {
                if((c = *str) >= 'a' && c <= 'z')
                        *str += 'A' - 'a';
                else if(c > 0x7f)
                        *str = map[c & 0x7f];
                ++str;
        } while(--len);
}

BYTE yesNo(char ch)     /* returns: 0: ch == "No", 1: ch == "Yes", 2: ch crap */
{
        ch = upMChar(normalCh, ch);
        if(ch == noChar)
                return 0;
        if(ch == yesChar)
                return 1;
        return 2;
}


char upChar(char ch) /* upcase a single character */
{
        return upMChar(normalCh, ch);
}


VOID upString(char FAR *str)    /* upcase a string */
{
        upMMem(normalCh, str, fstrlen(str));
}


VOID upMem(char FAR *str, unsigned len) /* upcase a memory area */
{
        upMMem(normalCh, str, len);
}

char upFChar(char ch) /* upcase a single character for file names */
{
        return upMChar(fileCh, ch);
}


VOID upFString(char FAR *str)   /* upcase a string for file names */
{
        upMMem(fileCh, str, fstrlen(str));
}


VOID upFMem(char FAR *str, unsigned len)        /* upcase a memory area for file names */
{
        upMMem(fileCh, str, len);
}

/*      LoadCountryInfo():
 *
 *      Searches a file in the COUNTRY.SYS format for an entry 
 *      matching the specified code page and country code, and loads 
 *      the corresponding information into memory. If code page is 0, 
 *      the default code page for the country will be used.
 *
 *      Returns TRUE if successful, FALSE if not.
 */
 
BOOL    LoadCountryInfo(char FAR *filename, WORD ctryCode, WORD codePage)
{
        struct CpiHeader hdr;
        struct CountryRecord ctry;
        struct CountryTableDescr ct;
        COUNT i, nCountries, nSubEntries;
        ULONG currpos;
        int rc = FALSE;
        COUNT file;

        if ((file = dos_open(filename, 0)) < 0)
                return rc;
        
        if (dos_read(file, &hdr, sizeof hdr) == sizeof hdr)
        {
            /* check signature */
            if (!fstrncmp(hdr.name, "\377COUNTRY", 8))
            {    
                dos_lseek(file, hdr.pointer[0].offset, 0);
                dos_read(file, &nCountries, sizeof nCountries);

                /* search for matching country record */
                for (i = 0; i < nCountries; i++)
                {
                   if (dos_read(file, &ctry, sizeof ctry) != sizeof ctry)
                       break;

                   if (ctry.country == ctryCode && (!codePage || ctry.codePage == codePage))
                   {    
                        /* found country - now load the tables */
                        dos_lseek(file, ctry.subCountryOffset, 0);
                        dos_read(file, &nSubEntries, sizeof nSubEntries);
                        currpos = ctry.subCountryOffset + sizeof nSubEntries;

                        for (i = 0; i < nSubEntries; i++)
                        {
                            dos_lseek(file, currpos, 0);
                            if (dos_read(file, &ct, sizeof ct) != sizeof ct)
                                break;

                            currpos += ct.length + sizeof ct.length;
                            ReadCountryTable(file, ct.id, ct.offset + 8);
                        }
                        
                        if (i == nSubEntries) rc = TRUE;

                        break;
                   }
                }
            }
        }
        dos_close(file);
        return rc;
}

/*      ReadCountryTable():
 *
 *      Loads a country information table. 
 */

static  BOOL ReadCountryTable(COUNT file, WORD id, ULONG offset)
{
        VOID    *buf;           /* where to load the information */
        UWORD   maxSize;        /* max number of bytes to read   */
        UWORD   length;         /* length of table in file       */
        BOOL    rc = TRUE;

        switch (id)
        {
            case 1:     /* extended country information */
                buf = &nlsInfo.nlsExtCtryInfo.countryCode;
                maxSize = sizeof(struct ctryInfo) + sizeof(WORD) * 2;
                break;

            case 2:     /* uppercase table              */
                buf = &normalCh[0];
                maxSize = sizeof normalCh;
                break;

            case 4:     /* filename uppercase table     */
                buf = &fileCh[0];
                maxSize = sizeof fileCh;
                break;

            case 5:     /* filename terminator table    */
                buf = &nlsInfo.nlsFn.dummy1;
                maxSize = sizeof(struct chFileNames) - sizeof(WORD);
                break;

            case 6:     /* collating sequence table     */
                buf = &nlsInfo.collSeq[0];
                maxSize = sizeof nlsInfo.collSeq;
                break;

            default:    /* unknown or unsupported table - ignore  */
                buf = 0;
                break;
        }

        if (buf)
        {
            dos_lseek(file, offset, 0);
            dos_read(file, &length, sizeof length);
            
            if (length > maxSize) length = maxSize;
            
            if (dos_read(file, buf, length) != length)
                rc = FALSE;

            if (id == 1)  
                nlsInfo.nlsExtCtryInfo.nlsCtryInfo.upCaseFct = CharMapSrvc;
        }

        return rc;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -