int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, int) { int argc = __argc; char** argv = __argv; void* pInstance = (void*)hInst; CHECK_MEMORY(); //_CrtSetBreakAlloc(30565); COgreApplication app; try { if (true == app.ApplicationInit()) app.Run(); } catch(Ogre::Exception err) { MessageBoxA(NULL, err.what(), "An exception has occurred!", MB_ICONERROR | MB_TASKMODAL); } app.ApplicationTerminate(); return 0; }
//******************************************************************** Bool PutSpaces(long lth) { // Запись пробелов в ответ. if ( lth <= 0 ) return TRUE; CHECK_MEMORY(lth+10); // С запасом memset (gMemCur,' ', lth); gMemCur += lth; return TRUE; }
//******************************************************************** Bool NewLine() { // Записать конец строки CHECK_MEMORY(10); // Для модуля Words.cpp gCharBack = gMemCur; Byte *p = (Byte*)gEOL; while(*p) *gMemCur++ = *p++; return TRUE; }
*/ void Bind_Values_Core(REBVAL value[], REBSER *frame, REBCNT mode) /* ** Bind words in an array of values terminated with REB_END ** to a specified frame. See warnings on the functions like ** Bind_Values_Deep() about not passing just a singular REBVAL. ** ** Different modes may be applied: ** ** BIND_ONLY - Only bind words found in the frame. ** BIND_ALL - Add words to the frame during the bind. ** BIND_SET - Add set-words to the frame during the bind. ** (note: word must not occur before the SET) ** BIND_DEEP - Recurse into sub-blocks. ** ** NOTE: BIND_SET must be used carefully, because it does not ** bind prior instances of the word before the set-word. That is ** to say that forward references are not allowed. ** ***********************************************************************/ { REBVAL *words; REBCNT index; REBINT *binds = WORDS_HEAD(Bind_Table); // GC safe to do here CHECK_MEMORY(4); CHECK_BIND_TABLE; // Note about optimization: it's not a big win to avoid the // binding table for short blocks (size < 4), because testing // every block for the rare case adds up. // Setup binding table for (index = 1; index < frame->tail; index++) { words = FRM_WORD(frame, index); if (!VAL_GET_OPT(words, EXT_WORD_HIDE)) binds[VAL_BIND_CANON(words)] = index; } Bind_Values_Inner_Loop(binds, &value[0], frame, mode); // Reset binding table: for (words = FRM_WORDS(frame) + 1; NOT_END(words); words++) binds[VAL_BIND_CANON(words)] = 0; CHECK_BIND_TABLE; }
//******************************************************************** Bool PutString(char *s) { // Запись строки в ответ. // Желательно избегать концов строк, для этого // рекомендуется использовать NEW_LINE ulong lth = strlen(s); if ( !lth ) return TRUE; CHECK_MEMORY(lth+10); // С запасом strcpy((char*)gMemCur,s); gMemCur += lth; return TRUE; }
*/ void Bind_Block(REBSER *frame, REBVAL *block, REBCNT mode) /* ** Bind the words of a block to a specified frame. ** Different modes may be applied: ** BIND_ONLY - Only bind words found in the frame. ** BIND_ALL - Add words to the frame during the bind. ** BIND_SET - Add set-words to the frame during the bind. ** (note: word must not occur before the SET) ** BIND_DEEP - Recurse into sub-blocks. ** ***********************************************************************/ { REBVAL *words; REBCNT index; REBINT *binds = WORDS_HEAD(Bind_Table); // GC safe to do here CHECK_MEMORY(4); CHECK_BIND_TABLE; // for (index = 0; index < Bind_Table->tail; index++) // if (binds[index] != 0) Crash(1333); // Note about optimization: it's not a big win to avoid the // binding table for short blocks (size < 4), because testing // every block for the rare case adds up. // Setup binding table: index = 1; for (index = 1; index < frame->tail; index++) { words = FRM_WORD(frame, index); if (!VAL_GET_OPT(words, OPTS_HIDE)) binds[VAL_BIND_CANON(words)] = index; } Bind_Block_Words(frame, block, mode); // Reset binding table: for (words = FRM_WORDS(frame)+1; NOT_END(words); words++) binds[VAL_BIND_CANON(words)] = 0; }
*/ void Remove_Series(REBSER *series, REBCNT index, REBINT len) /* ** Remove a series of values (bytes, longs, reb-vals) from the ** series at the given index. ** ***********************************************************************/ { REBCNT start; REBCNT length; REBYTE *data; if (len <= 0) return; // Optimized case of head removal: if (index == 0) { if ((REBCNT)len > series->tail) len = series->tail; SERIES_TAIL(series) -= len; if (SERIES_TAIL(series) == 0) { // Reset bias to zero: len = SERIES_BIAS(series); SERIES_SET_BIAS(series, 0); SERIES_REST(series) += len; series->data -= SERIES_WIDE(series) * len; CLEAR(series->data, SERIES_WIDE(series)); // terminate } else { // Add bias to head: REBCNT bias = SERIES_BIAS(series); if (REB_U32_ADD_OF(bias, len, &bias)) raise Error_0(RE_OVERFLOW); if (bias > 0xffff) { //bias is 16-bit, so a simple SERIES_ADD_BIAS could overflow it REBYTE *data = series->data; data += SERIES_WIDE(series) * len; series->data -= SERIES_WIDE(series) * SERIES_BIAS(series); SERIES_REST(series) += SERIES_BIAS(series); SERIES_SET_BIAS(series, 0); memmove(series->data, data, SERIES_USED(series)); } else { SERIES_SET_BIAS(series, bias); SERIES_REST(series) -= len; series->data += SERIES_WIDE(series) * len; if ((start = SERIES_BIAS(series))) { // If more than half biased: if (start >= MAX_SERIES_BIAS || start > SERIES_REST(series)) Reset_Bias(series); } } } return; } if (index >= series->tail) return; start = index * SERIES_WIDE(series); // Clip if past end and optimize the remove operation: if (len + index >= series->tail) { series->tail = index; CLEAR(series->data + start, SERIES_WIDE(series)); return; } length = (SERIES_LEN(series) + 1) * SERIES_WIDE(series); // include term. series->tail -= (REBCNT)len; len *= SERIES_WIDE(series); data = series->data + start; memmove(data, data + len, length - (start + len)); CHECK_MEMORY(5); }
//******************************************************************** static Bool MakeDbfHeader() { // Создать заголовок DBF-файла включая дескрипторы полей CHECK_MEMORY(sizeof(DBF_HEADER) + gTableCols * sizeof(DBF_FIELD) + 10); dbf_header = (DBF_HEADER*) gMemCur; gMemCur += sizeof(DBF_HEADER); // Приготовить дату и время struct tm *today = 0; time_t aclock={0}; time( &aclock ); // Get time in seconds today = localtime( &aclock ); // Convert time to struct // Заполнение заголовка dbf_header->tag = 3; // Версия файла dbf_header->year = today->tm_year;// Год минус 1900 (до 255) dbf_header->month = today->tm_mon+1; dbf_header->day = today->tm_mday; dbf_header->header_size = sizeof(DBF_HEADER) + gTableCols * sizeof(DBF_FIELD) + 1; dbf_header->record_size = 1; // Пробел в начале записи // Язык dbf_header->language = DbfLanguage(); // Создать дескрипторы полей dbf_fields = (DBF_FIELD*) gMemCur; for(gIndexTableCol = 0; gIndexTableCol < gTableCols; gIndexTableCol++, gMemCur += sizeof(DBF_FIELD) ) { // Дескриптор поля DBF_FIELD *f = &dbf_fields[gIndexTableCol]; // Имя поля "col_n" sprintf(f->name,"col_%ld",gIndexTableCol+1); // Тип поля всегда текстовый f->type = 'C'; // Ширина колонки long w = gTableColWidths[gIndexTableCol]; if (w > 254) POSSIBLE_LOSS_OF_DATA; // Ширина поля f->length = MIN(w,254); // Смещение поля от начала записи f->offset = dbf_header->record_size; dbf_header->record_size += f->length; } // Признак конца заголовка *gMemCur++ = DBF_TERM_BYTE; return TRUE; }
//******************************************************************** Bool OneChar(Handle charHandle) { // write one symbol char sCodePageName[200]={0}; CHECK_MEMORY(10); struct letterEx *alt = CED_GetAlternatives(charHandle); ASSERT(alt); long codePage = GetCodePage(); // source symbol Byte c1 = alt->alternative; Byte c2 = gActiveCodeTable[c1]; // remember for the Words.cpp module gCharHandle = charHandle; gAlt = alt; gCharCode = c1; gCharBack = gMemCur; // Пробелы, вставленные для выравнивания SmartText, // имеют оценку 253; их следует пропускать // для всех остальных форматов if (c1 == ' ' && alt->probability == 253 && gFormat != ROUT_FMT_SmartText ) return TRUE; // Специальные случаи перекодировки switch(c1) { // unknows symbol case bad_char: c2 = gBadChar; break; case 0x97: // long dash -> double hyphen // except SmartText и HTML // 29.02.2000 if (gFormat == ROUT_FMT_HTML || gFormat == ROUT_FMT_HOCR || gActiveCode==ROUT_CODE_UTF8) { // there is long dash in html and unicode c2 = c1; } else { c2 = '-'; if (gFormat != ROUT_FMT_SmartText) *gMemCur++ = '-'; } break; // Угловые скобки в HTML заменяются на круглые case '<': case '>': if (gFormat == ROUT_FMT_HTML || gFormat == ROUT_FMT_HOCR) { *gMemCur++ = '&'; *gMemCur++ = (c1 == '<' ? 'l' : 'g'); *gMemCur++ = 't'; *gMemCur++ = ';'; return TRUE; } break; case '&': if(gFormat == ROUT_FMT_HTML || gFormat == ROUT_FMT_HOCR) { *gMemCur++ = '&'; *gMemCur++ = 'a'; *gMemCur++ = 'm'; *gMemCur++ = 'p'; *gMemCur++ = ';'; return TRUE; } break; // Дифтонг oe / OE case oe_deaf_sound: if( FALSE == ( gLanguage==PUMA_LANG_RUSSIAN || langKaz || // 18.08.98 E.P. gLanguage==PUMA_LANG_FRENCH && gActiveCode==ROUT_CODE_ANSI ) || gFormat == ROUT_FMT_HTML || gFormat == ROUT_FMT_HOCR ) { *gMemCur++ = 'o'; c2='e'; } break; case OE_cap_deaf_sound: if( FALSE == ( gLanguage==PUMA_LANG_RUSSIAN || langKaz || // 18.08.98 E.P. gLanguage==PUMA_LANG_FRENCH && gActiveCode==ROUT_CODE_ANSI ) || gFormat == ROUT_FMT_HTML || gFormat == ROUT_FMT_HOCR ) { *gMemCur++ = 'O'; c2='E'; } break; // 0xA9 © -> (C), // 0xAE ® -> (R) case 0xA9: case 0xAE: if(gActiveCode == ROUT_CODE_UTF8) break; if( gActiveCode==ROUT_CODE_ASCII || gActiveCode==ROUT_CODE_ISO ) *gMemCur++ = '('; *gMemCur++ = c2; if( gActiveCode==ROUT_CODE_ASCII || gActiveCode==ROUT_CODE_ISO ) *gMemCur++ = ')'; return TRUE; break; // 0x99 ™ -> (TM) except ANSI and UTF8 case 0x99: if( gActiveCode!=ROUT_CODE_ANSI && gActiveCode!=ROUT_CODE_UTF8) { *gMemCur++ = '('; *gMemCur++ = c2; // 'T' *gMemCur++ = 'M'; *gMemCur++ = ')'; return TRUE; } break; } // switch(c1) if(gActiveCode!=ROUT_CODE_UTF8){ *gMemCur++ = c2; } else { const char *utfchar; utfchar = getUTF8Str((char )c2, GetCodePage()); int i; for(i=0; utfchar[i] != '\0' ;i++){ *gMemCur++ = utfchar[i]; } } return TRUE; }