Beispiel #1
0
static int LoadCTB(char *name) {
	CTB_handle ctbhan;
	uchar CTBdata[CTB_DATA_SIZE];
	welet *wel, *twel;
	int num;
	int i;
	int16_t *pint16;
	uint32_t *pword32;

	// process CTB-file
	if (CTB_open(name, &ctbhan, "r") == FALSE) { // MessageBox(GetActiveWindow(),name,"Error open CTB-base",MB_OK);
		return -41;
	}

	// grey file ?
	if ((ctbhan.signums & CTB_GRAY) == 0) {
		CTB_close(&ctbhan);
		//	 MessageBox(GetActiveWindow(),name,"Not grey base",MB_OK);
		return -42;
	}

	if (CTB_read_global_data(&ctbhan, CTBdata) == 0 || memcmp(&CTBdata[1],
			ParolBase, 5) != 0) {
		CTB_close(&ctbhan);
		//	 MessageBox(GetActiveWindow(),name,"Not cluster CTB-base",MB_OK);
		return -43;
	}

	num = CTB_volume(&ctbhan);

	if ((wel = (welet *) malloc(num * sizeof(welet))) == NULL) {
		CTB_close(&ctbhan);
		return -1;
	}

	for (i = 0, twel = wel; i < num; i++, twel++) {
		if (GetCTBasWelet(&ctbhan, i, twel) == 0) {
			CTB_close(&ctbhan);
			return -2;
		}
	}
	CTB_close(&ctbhan);

	// now to static
	memset(&fonbase, 0, sizeof(FONBASE));
	pint16 = (int16_t *) (CTBdata + 6);
	pword32 = (uint32_t *) (CTBdata + 8);
	fonbase.start = wel;
	fonbase.inBase = num;
	fonbase.ace = NULL;
	fonbase.countFont = *pint16;
	// Информация о шрифтах в полях
	SetFields(fonbase.fontFields[0],pword32);
	SetFields(fonbase.fontFields[1],(pword32+2));
	SetFields(fonbase.fontFields[2],(pword32+4));
	SetFields(fonbase.fontFields[3],(pword32+6));

	return num;
}
Beispiel #2
0
int32_t CTB_copy(char *new_name, char *old_name)
{
    char *p;
    CTB_handle hi, ho;
    int16_t i, n;
    uchar dst[CTB_DATA_SIZE], buffer[256* 128 + 2 + CTB_DATA_SIZE ];
    ctb_err_code = CTB_ERR_NONE;
    p = ctb_last_punct(old_name);

    if (p)
        *p = '\0';

    p = ctb_last_punct(new_name);

    if (p)
        *p = '\0';

    if (!CTB_open(old_name, &hi, "w"))
        return 0;

    CTB_read_global_data(&hi, dst);
    CTB_files_init(new_name, dst, hi.width, hi.height, hi.dpb, hi.signums,
                   hi.attr_size);
    n = (int16_t) CTB_volume(&hi);

    if (!CTB_open(new_name, &ho, "w"))
        return 0;

    for (i = 0; i < n; i++) {
        switch (CTB_read(&hi, i, buffer, dst)) {
            case 1:
                CTB_write_mark(&ho, -1, buffer, dst, FALSE);
                break;
            case 2:
                CTB_write_mark(&ho, -1, buffer, dst, TRUE);
                break;
            default:
                break;
        }
    }

    CTB_close(&ho);
    CTB_close(&hi);
    return n;
}
Beispiel #3
0
int32_t CTB_compress(const char *filename)
{
    char *p, tmp_file[MAXPATH], file_name[MAXPATH];
    CTB_handle hi, ho;
    int32_t i, n, compress;
    uchar dst[CTB_DATA_SIZE], buffer[256* 128 + 2 + CTB_DATA_SIZE ];
    p = ctb_last_punct(file_name);
    strcpy(file_name, filename);
    ctb_err_code = CTB_ERR_NONE;

    if (p)
        *p = '\0';

    STRCPY(tmp_file, file_name);
    p = STRRCHR(tmp_file, '\\');

    if (p) {
        *(p + 1) = '\0';
        STRCAT(tmp_file, "$$$$$$$$");
    }

    else
        STRCPY(tmp_file, "$$$$$$$$");

    if (!CTB_open(file_name, &hi, "w"))
        return FALSE;

    CTB_read_global_data(&hi, dst);
    CTB_files_init(tmp_file, dst, hi.width, hi.height, hi.dpb, hi.signums,
                   hi.attr_size);
    n = CTB_volume(&hi);
    compress = hi.need_compress;

    if (compress) {
        if (!CTB_open(tmp_file, &ho, "w"))
            return 0;

        for (i = 0; i < n; i++) {
            switch (CTB_read(&hi, i, buffer, dst)) {
                case 1:
                    CTB_write_mark(&ho, -1, buffer, dst, FALSE);
                    break;
                case 2:
                    CTB_write_mark(&ho, -1, buffer, dst, TRUE);
                    break;
                default:
                    break;
            }
        }

        ho.need_compress = 0;
        CTB_close(&ho);
    }

    hi.need_compress = 0;
    CTB_close(&hi);

    if (!compress) { // delete tmp file //
        STRCAT(tmp_file, ".CTB");
        UNLINK(tmp_file);
        *ctb_last_punct(tmp_file) = 0;
        STRCAT(tmp_file, ".IND");
        UNLINK(tmp_file);
        return 0;
    }

    STRCAT(file_name, ".CTB");
    STRCAT(tmp_file, ".CTB");
    UNLINK(file_name);
    RENAME(tmp_file, file_name);
    *ctb_last_punct(tmp_file) = 0;
    *ctb_last_punct(file_name) = 0;
    STRCAT(file_name, ".IND");
    STRCAT(tmp_file, ".IND");
    UNLINK(file_name);
    RENAME(tmp_file, file_name);
    return n;
}