Subversion Repositories Kolibri OS

Rev

Rev 9671 | Rev 9708 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9671 Rev 9674
Line 142... Line 142...
142
    RETURN code
142
    RETURN code
143
END getCharUTF8;
143
END getCharUTF8;
Line 144... Line 144...
144
 
144
 
145
 
145
 
146
PROCEDURE getCharW1251 (file: tInput): INTEGER;
146
PROCEDURE getCharW1251 (file: tInput): INTEGER;
Line 147... Line 147...
147
    RETURN E.cpW1251[getByte(file)]
147
    RETURN E.cp1251[getByte(file)]
148
END getCharW1251;
148
END getCharW1251;
Line 342... Line 342...
342
	file.strBuf := Lines.create(TRUE);
342
	file.strBuf := Lines.create(TRUE);
343
	Lines.resize(file.strBuf, MAX(2048, getMaxLength(file) + 1))
343
	Lines.resize(file.strBuf, MAX(2048, getMaxLength(file) + 1))
344
END createStrBuf;
344
END createStrBuf;
Line 345... Line 345...
345
 
345
 
346
 
346
 
347
PROCEDURE load* (name: tFileName; VAR enc, eol: INTEGER): tInput;
347
PROCEDURE _loadFromMem (ptr, size: INTEGER; cp866: BOOLEAN; VAR enc, eol: INTEGER): tInput;
348
VAR
-
 
349
    res: tInput;
348
VAR
350
    fsize: INTEGER;
349
    res: tInput;
351
BEGIN
350
BEGIN
352
    NEW(res);
351
    NEW(res);
353
    res.pos := 0;
352
    res.pos := 0;
354
    res.CR := FALSE;
353
    res.CR := FALSE;
355
    res.getChar := NIL;
-
 
356
    res.clipbrd := FALSE;
-
 
357
    fsize := File.FileSize(name);
354
    res.getChar := NIL;
358
    IF fsize = 0 THEN
355
    res.clipbrd := FALSE;
359
        res.buffer := KOSAPI.malloc(4096);
-
 
360
        res.cnt := 0
-
 
361
    ELSE
-
 
362
        res.buffer := File.Load(name, res.cnt)
356
    res.buffer := ptr;
363
    END;
357
    res.cnt := size;
364
    IF res.buffer = 0 THEN
358
    IF res.buffer = 0 THEN
365
        DISPOSE(res)
359
        DISPOSE(res)
366
    ELSE
360
    ELSE
367
        enc := detectEncoding(res);
361
        enc := detectEncoding(res);
368
        IF enc IN {E.UTF8BOM, E.UTF8} THEN
362
        IF enc IN {E.UTF8BOM, E.UTF8} THEN
369
            res.getChar := getCharUTF8
363
            res.getChar := getCharUTF8
370
        ELSIF enc = E.CP866 THEN
364
        ELSIF enc = E.CP866 THEN
-
 
365
            res.getChar := getCharCP866
-
 
366
        ELSIF enc = E.W1251 THEN
-
 
367
        	IF cp866 THEN
-
 
368
        		enc := E.CP866;
371
            res.getChar := getCharCP866
369
        		res.getChar := getCharCP866
-
 
370
        	ELSE
372
        ELSIF enc = E.W1251 THEN
371
            	res.getChar := getCharW1251
373
            res.getChar := getCharW1251
372
            END
374
        END;
373
        END;
375
        eol := detectEOL(res);
374
        eol := detectEOL(res);
376
        createStrBuf(res)
375
        createStrBuf(res)
-
 
376
    END
-
 
377
    RETURN res
-
 
378
END _loadFromMem;
-
 
379
 
-
 
380
 
377
    END
381
PROCEDURE loadFromMem* (ptr, size: INTEGER; VAR enc, eol: INTEGER): tInput;
-
 
382
    RETURN _loadFromMem(ptr, size, TRUE, enc, eol)
-
 
383
END loadFromMem;
-
 
384
 
-
 
385
 
-
 
386
PROCEDURE loadFromFile* (name: tFileName; VAR enc, eol: INTEGER): tInput;
-
 
387
VAR
-
 
388
    ptr, size: INTEGER;
-
 
389
BEGIN
-
 
390
	size := File.FileSize(name);
-
 
391
    IF size = 0 THEN
-
 
392
    	ptr := KOSAPI.malloc(4096)
-
 
393
    ELSE
-
 
394
    	ptr := File.Load(name, size)
-
 
395
    END
Line 378... Line 396...
378
    RETURN res
396
	RETURN _loadFromMem(ptr, size, FALSE, enc, eol)
379
END load;
397
END loadFromFile;
380
 
398