Exemple #1
0
void MainWindow::LoadContest(const QString& path)
{
    if (!QDir(path).exists())
    {
        QMessageBox::critical(this, "无法打开竞赛", QString("%1\n路径不存在或已被移除。").arg(path));
        QSettings set("ccr.ini", QSettings::IniFormat);
        QStringList list = set.value("RecentContestList").toStringList();
        list.removeAll(path);
        set.setValue("RecentContestList", list);
        UpdateRecentContest(true);
        return;
    }

    QDir dir1(path + "/src"), dir2(path + "/data");
    if (!dir1.exists() || !dir2.exists())
        if (QMessageBox::question(this, "找不到试题或选手目录", "是否继续打开并创建子目录?") == QMessageBox::No) return;

    if (!dir1.exists() && !QDir(path).mkdir("src"))
    {
        QMessageBox::critical(this, "无法创建子目录", "创建子目录失败!");
        return;
    }
    if (!dir2.exists() && !QDir(path).mkdir("data"))
    {
        QMessageBox::critical(this, "无法创建子目录", "创建子目录失败!");
        return;
    }

    if (!Global::g_is_contest_closed) CloseContest();
    lastContest = path;
    Global::g_contest.SetPath(path);

    QSettings set("ccr.ini", QSettings::IniFormat);
    QStringList list = set.value("RecentContestList").toStringList();
    if (!list.count(path)) list.prepend(path);
    set.setValue("RecentContestList", list);
    set.setValue("LastContest", lastContest);
    UpdateRecentContest(false);

    ui->label_top->hide();
    ui->label_bottom->hide();
    ui->listWidget_recent->hide();
    close_button->show();

    this->setWindowTitle(path + " - CCR Plus 测评器");
    ui->action_close->setEnabled(true);
    ui->action_configure->setEnabled(true);
    ui->action_set_list->setEnabled(true);
    ui->action_export->setEnabled(true);
    ui->action_refresh->setEnabled(true);
    ui->action_judge_selected->setEnabled(true);
    ui->action_judge_unjudged->setEnabled(true);
    ui->action_judge_all->setEnabled(true);
    ui->action_stop->setEnabled(false);

    Global::g_is_judge_stoped = false;
    Global::g_is_contest_closed = false;

    LoadTable();
}
Exemple #2
0
std::vector< vtkSmartPointer<vtkTable> > LoadTableSeries(std::string filename)
{
	/*!
	* Loads multiple tables into a vector to access
	* Ie. Time series data tables
	*/
	std::vector< vtkSmartPointer<vtkTable> > tableVector;
	tableVector.clear();

	TiXmlDocument doc;
	if ( !doc.LoadFile( filename.c_str() ) )
		return tableVector;

	TiXmlElement* rootElement = doc.FirstChildElement();
	const char* docname = rootElement->Value();
	if ( strcmp( docname, "Table" ) != 0 )
		return tableVector;

	//Parents we know of: datafilename,resultfilename,object,parameter
	TiXmlElement* parentElement = rootElement->FirstChildElement();

	while (parentElement)
	{
		const char * parent = parentElement->Value();
		if ( strcmp( parent, "file" ) == 0 )
		{
			tableVector.push_back(LoadTable(std::string(reinterpret_cast<const char*>(parentElement->GetText()))));
		}
		parentElement = parentElement->NextSiblingElement();
	} // end while(parentElement)
	//doc.close();
	
	return tableVector;
}
void CreateAndLoadTable(LayoutType layout_type) {
  // Initialize settings
  peloton_layout_mode = layout_type;

  CreateTable();

  LoadTable();
}
Exemple #4
0
// Initialization of string table routine
void InitTable()
{
	LIST *o;
	char tmp[MAX_SIZE];
	LANGLIST *e = NULL;
	LANGLIST *os_lang = NULL;
	char table_name[MAX_SIZE];
	if (MayaquaIsMinimalMode())
	{
		// Not to load in case of minimum mode
		return;
	}

	o = LoadLangList();
	if (o == NULL)
	{
LABEL_FATAL_ERROR:
		Alert("Fatal Error: The file \"hamcore.se2\" is missing or broken.\r\nPlease check hamcore.se2.\r\n\r\n(First, reboot the computer. If this problem occurs again, please reinstall VPN software files.)", NULL);
		exit(-1);
		return;
	}

	// Read the lang.config
	if (LoadLangConfigCurrentDir(tmp, sizeof(tmp)))
	{
		e = GetBestLangByName(o, tmp);
	}

	os_lang = GetBestLangForCurrentEnvironment(o);

	if (e == NULL)
	{
		e = os_lang;
	}

	if (e == NULL)
	{
		goto LABEL_FATAL_ERROR;
	}

	SaveLangConfigCurrentDir(e->Name);

	Copy(&current_lang, e, sizeof(LANGLIST));
	Copy(&current_os_lang, os_lang, sizeof(LANGLIST));

	current_lang.LangList = current_lang.LcidList = NULL;
	current_os_lang.LangList = current_os_lang.LcidList = NULL;

	// Read the corresponding string table
	Format(table_name, sizeof(table_name), "|strtable_%s.stb", current_lang.Name);
	if (LoadTable(table_name) == false)
	{
		goto LABEL_FATAL_ERROR;
	}

	FreeLangList(o);
}
Exemple #5
0
TEST_F(HybridIndexTests, IndexScanTest) {
  std::unique_ptr<storage::DataTable> hyadapt_table;
  CreateTable(hyadapt_table, true);
  LoadTable(hyadapt_table);

  for (size_t query_itr = 0; query_itr < query_count; query_itr++) {
    LaunchIndexScan(hyadapt_table);
  }
}
Exemple #6
0
	bool TablePaser::LoadTableFile(const char* fileName)
	{
		std::ifstream in_put;
		in_put.open(fileName);
		//FEAssert(in_put);
		bool ret = LoadTable(in_put);
		in_put.close();
		return ret;
	}
BOOL CSelectFeatureToCopyDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_strFeatures=L"";
	LoadTable();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CEditCategoryNamesDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	LoadTable();
	m_bAlwaysUseSyntacticNames=m_pDoc->m_bAlwaysUseSyntacticNames;
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
Exemple #9
0
PersonalityTree::PersonalityTree(PersonalityTable *persTable, vector<Subnet>& subnetsToUse)
{
	m_hdconfig = new HoneydConfiguration();

	m_root = PersonalityNode("default");
	m_root.m_count = persTable->m_num_of_hosts;
	m_root.m_distribution = 100;
	m_hdconfig->LoadAllTemplates();

	m_hdconfig->AddGroup("HaystackAutoConfig");
	Config::Inst()->SetGroup("HaystackAutoConfig");
	Config::Inst()->SaveUserConfig();
	m_hdconfig->SaveAllTemplates();
	m_hdconfig->LoadAllTemplates();

	vector<string> nodesToDelete;
	for(NodeTable::iterator it = m_hdconfig->m_nodes.begin(); it != m_hdconfig->m_nodes.end(); it++)
	{
		if(it->first.compare("Doppelganger"))
		{
			nodesToDelete.push_back(it->first);
		}
	}
	for (vector<string>::iterator it = nodesToDelete.begin(); it != nodesToDelete.end(); it++)
	{
		m_hdconfig->DeleteNode(*it);
	}

	vector<string> profilesToDelete;
	for(ProfileTable::iterator it = m_hdconfig->m_profiles.begin(); it != m_hdconfig->m_profiles.end(); it++)
	{
		if(it->second.m_generated)
		{
			profilesToDelete.push_back(it->first);
		}
	}
	for (vector<string>::iterator it = profilesToDelete.begin(); it != profilesToDelete.end(); it++)
	{
		m_hdconfig->DeleteProfile(*it);
	}



	m_hdconfig->SaveAllTemplates();
	m_hdconfig->LoadAllTemplates();
	m_profiles = &m_hdconfig->m_profiles;
	m_serviceMap = ServiceToScriptMap(&m_hdconfig->GetScriptTable());

	if(persTable != NULL)
	{
		LoadTable(persTable);
	}
}
Exemple #10
0
void MainWindow::onRemoveDir()
{
    QString t1, t2;
    if (dirByAction == Global::g_contest.src_path + fileByAction + "/")
        t1 = "删除选手", t2 = QString("确实要删除选手 \"%1\" 及其目录中的所有文件吗?").arg(fileByAction);
    else if (dirByAction == Global::g_contest.data_path + fileByAction + "/")
        t1 = "删除试题", t2 = QString("确实要删除试题 \"%1\" 及其目录中的所有文件吗?").arg(fileByAction);
    if (QMessageBox::question(this, t1, t2) == QMessageBox::Yes)
    {
        QDir(dirByAction).removeRecursively();
        if (t1 == "删除试题") QDir(Global::g_contest.result_path + fileByAction).removeRecursively();
        LoadTable();
    }
}
Exemple #11
0
void MainWindow::on_action_configure_triggered()
{
    QStringList list;
    for (auto i : Global::g_contest.problem_order) list.append(Global::g_contest.problems[i]->Name());
    QStringList tmp = QDir(Global::g_contest.data_path).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
    for (auto i : tmp)
        if (!list.count(i) && Problem::CheckFileNameValid(i).isEmpty()) list.append(i);

    ConfigureDialog dialog(list, this);
    connect(&dialog, &ConfigureDialog::applied, this, [this]()
    {
        LoadTable();
        detail_table->onShowConfigurationDetail();
    });
    dialog.exec();
}
void VDDialogEditAccelerators::OnDataExchange(bool write) {
	if (write) {
		size_t n = mBoundCommands.size();

		VDAccelTableDefinition newTable;
		
		for(size_t i=0; i<n; ++i) {
			const BoundCommand& ent = *mBoundCommands[i];

			newTable.Add(ent);
		}

		mBoundCommandsResult.Swap(newTable);
	} else {
		LoadTable(mBoundCommandsResult);
	}
}
Exemple #13
0
void MainWindow::onConfigure()
{
    if (fileByAction.isEmpty())
        on_action_configure_triggered();
    else
    {
        QList<const Problem*> probs;
        for (auto i : Global::g_contest.problems) probs.append(i);

        AdvancedConfigureDialog dialog(probs, this, fileByAction);
        connect(&dialog, &AdvancedConfigureDialog::applied, this, [this]()
        {
            LoadTable();
            detail_table->onShowConfigurationDetail();
        });
        dialog.exec();
    }
}
void CPreview::Update(const char *fpath)
{
	cmpack_preview_set_model(CMPACK_PREVIEW(m_Preview), NULL);
	cmpack_preview_set_text(CMPACK_PREVIEW(m_Preview), NULL);
	gtk_text_buffer_set_text(m_Buffer, "", -1);
	if (m_Data) {
		g_object_unref(m_Data);
		m_Data = NULL;
	}
	m_FileType = TYPE_UNKNOWN;
	if (fpath) {
		SetPath(fpath);
		switch (FileType(fpath))
		{
		case TYPE_IMAGE:
			LoadImage(fpath);
			break;
		case TYPE_PHOT:
			LoadChart(fpath);
			break;
		case TYPE_CAT:
			LoadCatalog(fpath);
			break;
		case TYPE_TABLE:
			LoadTable(fpath);
			break;
		case TYPE_VARFIND:
			LoadVarFind(fpath);
			break;
		case TYPE_PROJECT:
			LoadProject(fpath);
			break;
		case TYPE_PROFILE:
			LoadProfile(fpath);
			break;
		default:
			break;
		}
		if (m_Data)
			cmpack_preview_set_model(CMPACK_PREVIEW(m_Preview), m_Data);
	}
}
Exemple #15
0
pid_t ForkStoreManager() {

	pid_t sm_pid;

	int quit = 0;

	switch ((sm_pid = fork())) {
	case 0:

		logFilePointer = OpenLogFile();

		//allocate shared memory
		AllocateMemory();

		LoadTable();

		while (quit == 0) {

			if (pipe1Done == 0)
				GetThreadedMessages(1, pipe1, pipe3);

			if (pipe2Done == 0)
				GetThreadedMessages(2, pipe2, pipe4);

			if (pipe1Done != 0 && pipe2Done != 0) {
				printf("quitting app\n");
				quit = 1;
			}

			usleep(100);
		}

		exit(1);

		break;

	}
	return sm_pid;

}
Exemple #16
0
TEST_F(HybridIndexTests, HybridScanTest) {
  std::unique_ptr<storage::DataTable> hyadapt_table;
  CreateTable(hyadapt_table, false);
  LoadTable(hyadapt_table);

  std::vector<oid_t> key_attrs;

  auto tuple_schema = hyadapt_table->GetSchema();
  catalog::Schema *key_schema;
  index::IndexMetadata *index_metadata;
  bool unique;

  key_attrs = {0};
  key_schema = catalog::Schema::CopySchema(tuple_schema, key_attrs);
  key_schema->SetIndexedColumns(key_attrs);

  unique = true;

  index_metadata = new index::IndexMetadata(
      "primary_index", 123, INVALID_OID, INVALID_OID, IndexType::BWTREE,
      IndexConstraintType::PRIMARY_KEY, tuple_schema, key_schema, key_attrs,
      unique);

  std::shared_ptr<index::Index> pkey_index(
      index::IndexFactory::GetIndex(index_metadata));

  hyadapt_table->AddIndex(pkey_index);

  std::thread index_builder =
      std::thread(BuildIndex, pkey_index, hyadapt_table.get());

  for (size_t query_itr = 0; query_itr < query_count; query_itr++) {
    LaunchHybridScan(hyadapt_table);
  }

  index_builder.join();
}
BOOL CUnspecifiedCharacter::OnInitDialog() 
{
	int nRow=0,j,nRowHeight,nTargetFontSize,nScreenWidth,nScreenHeight;
	CString R,S,T,strTargetFontName;
	CWnd* pWnd;
	BOOL b;
	CDTData RowData;                 //create a special grid variable
	RowData.CreateArray(1); //create a special array to hold a row of data
	CString strSequence;
	CDC* pDC;
	IDispatch* pFontDisp;

	CDialog::OnInitDialog();
	
	CTA1Doc* pDoc=(CTA1Doc*)m_pDocument;
	pWnd=this;
	pDoc->GetScreenResolution(&nScreenWidth,&nScreenHeight);
	pWnd->MoveWindow((nScreenWidth-360)/2,80,360,580);
	pWnd=GetDlgItem(IDCANCEL);
	if (m_bCancelEnabled) pWnd->EnableWindow(TRUE);
	else pWnd->EnableWindow(FALSE);
	if (m_bTarget)         //if checking a target character
	{
		nRowHeight=pDoc->GetTargetRowHeight();
		pFontDisp=pDoc->GetPointerToTargetLanguageFont();
		m_nUnicodeFont=pDoc->m_nUnicodeFont;
	}
	else                   //checking a source character
	{
		nRowHeight=pDoc->GetSourceRowHeight(m_nSourceText);
		pFontDisp=pDoc->GetPointerToSourceLanguageFont(m_nSourceText);
		m_nUnicodeFont=0;
	}
	m_datatblWord.GetRowSet().SetHeight((float)nRowHeight);
	m_datatblCharacter.GetRowSet().SetHeight((float)nRowHeight);
	m_datatblList.GetRowSet().SetHeight((float)nRowHeight);
	m_datatblWord.GetColumnSet().GetItem(0).SetFont(pFontDisp);
	m_datatblCharacter.GetColumnSet().GetItem(0).SetFont(pFontDisp);
	m_datatblList.GetColumnSet().GetItem(0).SetFont(pFontDisp);
//	i=1;                //assume non-Unicode
//	if (m_nUnicodeFont>0) i=2;
	m_datatblCharacter.GetColumnSet().GetItem(0).SetDataType(dttString);
	m_datatblCharacter.GetColumnSet().GetItem(0).SetDataLen(2);
	m_datatblCharacter.SetHorzGridLines(FALSE);
	strTargetFontName=pDoc->GetTargetLanguageFontName();
	nTargetFontSize=pDoc->GetTargetLanguageFontSize();
	pDC=m_datatblWord.GetDC();
	m_fontTarget.DeleteObject();
	b=m_fontTarget.CreatePointFont(nTargetFontSize*10,strTargetFontName,pDC);
	if (b==FALSE) AfxMessageBox(L"Unable to create target font.",MB_OK);
	pDoc->GetSortingSequence(&m_strSequence, &T, &j, m_bTarget);   //get the sorting sequence
	LoadTable();   //initialize the number of rows
//	R=m_strWord;
//	RowData.PutItem(R, 0);     //enter a string for the first column
//	m_datatblWord.GetRowSet().GetItem(0).SetValue(RowData);
	R=m_strCharacter;
//	if (m_nUnicodeFont==0) R=L" "+R;   //add a space
	if (R==L" ")                    //if unrecognized character is a space
	{
		m_datatblCharacter.GetColumnSet().GetItem(0).SetDataLen(5);
		m_strCharacter=L"space";
		pFontDisp=pDoc->GetPointerToSourceLanguageFont(-1);  //small Arial
		m_datatblCharacter.GetColumnSet().GetItem(0).SetFont(pFontDisp);
	}
	if (R==L"")
	{
		m_datatblCharacter.GetColumnSet().GetItem(0).SetDataLen(12);
		m_strCharacter=L"no character";
		pFontDisp=pDoc->GetPointerToSourceLanguageFont(-1);  //small Arial
		m_datatblCharacter.GetColumnSet().GetItem(0).SetFont(pFontDisp);
	}
//	RowData.PutItem(R, 0);     //enter a string for the first column
//	m_datatblCharacter.GetRowSet().GetItem(0).SetValue(RowData);
	m_bIgnore=FALSE;            //default to not ignoring this character
	m_bNewCharacter=FALSE;     //default to no new character
	m_nSelectedRow=-1;         //default to no equivalent character selected
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
bool VDDialogEditAccelerators::OnCommand(uint32 id, uint32 extcode) {
	if (id == IDC_FILTER) {
		if (extcode == EN_CHANGE) {
			VDStringA s("*");
			s += VDTextWToA(GetControlValueString(id)).c_str();
			s += '*';

			RefilterCommands(s.c_str());
			return true;
		}
	} else if (id == IDC_ADD) {
		VDUIAccelerator accel;

		int selIdx = LBGetSelectedIndex(IDC_AVAILCOMMANDS);

		if ((size_t)selIdx < mFilteredCommands.size()) {
			const VDAccelToCommandEntry *ace = mFilteredCommands[selIdx];

			if (mpHotKeyControl) {
				mpHotKeyControl->GetAccelerator(accel);

				// Look for a conflicting command.
				for(BoundCommands::iterator it(mBoundCommands.begin()), itEnd(mBoundCommands.end()); it != itEnd; ++it) {
					BoundCommand *obc = *it;

					if (obc->mAccel == accel) {
						VDStringW keyName;
						VDUIGetAcceleratorString(accel, keyName);

						VDStringA msg;
						msg.sprintf("The key %ls is already bound to %hs. Rebind it to %hs?", keyName.c_str(), obc->mpCommand, ace->mpName);

						if (IDOK != MessageBox(mhdlg, msg.c_str(), g_szWarning, MB_OKCANCEL | MB_ICONEXCLAMATION))
							return true;

						mBoundCommands.erase(it);
						obc->Release();
					}
				}

				vdrefptr<BoundCommand> bc(new_nothrow BoundCommand);
				
				if (bc) {
					bc->mpCommand = ace->mpName;
					bc->mCommandId = ace->mId;
					bc->mAccel = accel;

					mBoundCommands.push_back(bc.release());
					RefreshBoundList();
				}
			}
		}

		return true;
	} else if (id == IDC_REMOVE) {
		int selIdx = mListViewBoundCommands.GetSelectedIndex();

		if ((unsigned)selIdx < mBoundCommands.size()) {
			BoundCommand *bc = mBoundCommands[selIdx];

			mBoundCommands.erase(mBoundCommands.begin() + selIdx);

			bc->Release();

			RefreshBoundList();
		}

		return true;
	} else if (id == IDC_RESET) {
		if (IDOK == MessageBox(mhdlg, "Really reset?", g_szWarning, MB_OKCANCEL | MB_ICONEXCLAMATION))
			LoadTable(mBoundCommandsDefault);

		return true;
	}

	return false;
}
void CEditCategoryNamesDlg::OnButtonrestoreoriginalvalues() 
{
	m_pDoc->LoadSyntacticNames(TRUE);        //load the original values
	LoadTable();
	m_bSave=TRUE;
}
Exemple #20
0
TYPE42 *T42_download_header(PSDRV_PDEVICE *physDev, char *ps_name,
                            RECT *bbox, UINT emsize)
{
    DWORD i, j, tablepos, nb_blocks, glyf_off = 0, loca_off = 0, cur_off;
    WORD num_of_tables = sizeof(tables_templ) / sizeof(tables_templ[0]) - 1;
    char *buf;
    TYPE42 *t42;
    static const char start[] = /* name, fontbbox */
            "25 dict begin\n"
	    " /FontName /%s def\n"
	    " /Encoding 256 array 0 1 255{1 index exch /.notdef put} for\n"
	    " def\n"
	    " /PaintType 0 def\n"
	    " /FontMatrix [1 0 0 1 0 0] def\n"
	    " /FontBBox [%f %f %f %f] def\n"
	    " /FontType 42 def\n"
	    " /CharStrings 256 dict begin\n"
	    "  /.notdef 0 def\n"
            " currentdict end def\n"
	    " /sfnts [\n";
    static const char TT_offset_table[] = "<00010000%04x%04x%04x%04x\n";
    static const char TT_table_dir_entry[] = "%08x%08x%08x%08x\n";
    static const char storage[] ="]\nhavetype42gdir{pop}{{string} forall}ifelse\n";
    static const char end[] = "] def\n"
      "havetype42gdir{/GlyphDirectory 256 dict def\n"
      " sfnts 0 get dup\n"
      "  %d <6c6f6378000000000000000000000000> putinterval\n" /* replace loca entry with dummy locx */
      "  %d <676c6678000000000000000000000000> putinterval\n" /* replace glyf entry with dummy glfx */
      " }if\n"
      "currentdict end dup /FontName get exch definefont pop\n";


    t42 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*t42));
    memcpy(t42->tables, tables_templ, sizeof(tables_templ));
    t42->loca_tab = t42->glyf_tab = t42->head_tab = t42->hmtx_tab = -1;
    t42->emsize = emsize;
    t42->num_of_written_tables = 0;

    for(i = 0; i < num_of_tables; i++) {
        LoadTable(physDev->hdc, t42->tables + i);
	if(t42->tables[i].len > 0xffff && t42->tables[i].write) break;
	if(t42->tables[i].write) t42->num_of_written_tables++;
	if(t42->tables[i].MS_tag == MS_MAKE_TAG('l','o','c','a'))
	    t42->loca_tab = i;
	else if(t42->tables[i].MS_tag == MS_MAKE_TAG('g','l','y','f'))
	    t42->glyf_tab = i;
	else if(t42->tables[i].MS_tag == MS_MAKE_TAG('h','e','a','d'))
	    t42->head_tab = i;
	else if(t42->tables[i].MS_tag == MS_MAKE_TAG('h','m','t','x'))
	    t42->hmtx_tab = i;
	else if(t42->tables[i].MS_tag == MS_MAKE_TAG('m','a','x','p'))
	    t42->maxp_tab = i;
    }
    if(i < num_of_tables) {
        TRACE("Table %d has length %d.  Will use Type 1 font instead.\n", i, t42->tables[i].len);
        T42_free(t42);
	return NULL;
    }

    t42->glyph_sent_size = GLYPH_SENT_INC;
    t42->glyph_sent = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
				t42->glyph_sent_size *
				sizeof(*(t42->glyph_sent)));

    buf = HeapAlloc(GetProcessHeap(), 0, sizeof(start) + strlen(ps_name) +
		    100);

    push_lc_numeric("C");
    sprintf(buf, start, ps_name,
	    (float)bbox->left / emsize, (float)bbox->bottom / emsize,
	    (float)bbox->right / emsize, (float)bbox->top / emsize);
    pop_lc_numeric();

    PSDRV_WriteSpool(physDev, buf, strlen(buf));

    t42->num_of_written_tables++; /* explicitly add glyf */
    sprintf(buf, TT_offset_table, t42->num_of_written_tables,
	    t42->num_of_written_tables, t42->num_of_written_tables, t42->num_of_written_tables);

    PSDRV_WriteSpool(physDev, buf, strlen(buf));

    tablepos = 12 + t42->num_of_written_tables * 16;
    cur_off = 12;
    for(i = 0; i < num_of_tables; i++) {
        if(!t42->tables[i].write) continue;
        sprintf(buf, TT_table_dir_entry, FLIP_ORDER(t42->tables[i].MS_tag),
		t42->tables[i].check, t42->tables[i].len ? tablepos : 0,
		t42->tables[i].len);
	PSDRV_WriteSpool(physDev, buf, strlen(buf));
	tablepos += ((t42->tables[i].len + 3) & ~3);
        if(t42->tables[i].MS_tag == MS_MAKE_TAG('l','o','c','a'))
            loca_off = cur_off;
        cur_off += 16;
    }
    sprintf(buf, TT_table_dir_entry, FLIP_ORDER(t42->tables[t42->glyf_tab].MS_tag),
            t42->tables[t42->glyf_tab].check, tablepos, t42->tables[t42->glyf_tab].len);
    PSDRV_WriteSpool(physDev, buf, strlen(buf));
    PSDRV_WriteSpool(physDev, "00>\n", 4); /* add an extra byte for old PostScript rips */
    glyf_off = cur_off;

    for(i = 0; i < num_of_tables; i++) {
        if(t42->tables[i].len == 0 || !t42->tables[i].write) continue;
	PSDRV_WriteSpool(physDev, "<", 1);
	for(j = 0; j < ((t42->tables[i].len + 3) & ~3); j++) {
	    sprintf(buf, "%02x", t42->tables[i].data[j]);
	    PSDRV_WriteSpool(physDev, buf, strlen(buf));
	    if(j % 16 == 15) PSDRV_WriteSpool(physDev, "\n", 1);
	}
	PSDRV_WriteSpool(physDev, "00>\n", 4); /* add an extra byte for old PostScript rips */
    }
    
    /* glyf_blocks is a 0 terminated list, holding the start offset of each block.  For simplicity
       glyf_blocks[0] is 0 */
    nb_blocks = 2;
    t42->glyf_blocks = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nb_blocks + 1) * sizeof(DWORD));
    for(i = 0; i < GET_BE_WORD(t42->tables[t42->maxp_tab].data + 4); i++) {
        DWORD start, end, size;
        get_glyf_pos(t42, i, &start, &end);
        size = end - t42->glyf_blocks[nb_blocks-2];
        if(size > 0x2000 && t42->glyf_blocks[nb_blocks-1] % 4 == 0) {
            nb_blocks++;
            t42->glyf_blocks = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
                                           t42->glyf_blocks, (nb_blocks + 1) * sizeof(DWORD));
        }
        t42->glyf_blocks[nb_blocks-1] = end;
    }

    PSDRV_WriteSpool(physDev, "[ ", 2);
    for(i = 1; t42->glyf_blocks[i]; i++) {
        sprintf(buf,"%d ", t42->glyf_blocks[i] - t42->glyf_blocks[i-1] + 1);
        /* again add one byte for old PostScript rips */
        PSDRV_WriteSpool(physDev, buf, strlen(buf));
        if(i % 8 == 0)
            PSDRV_WriteSpool(physDev, "\n", 1);
    }
    PSDRV_WriteSpool(physDev, storage, sizeof(storage) - 1);
    sprintf(buf, end, loca_off, glyf_off);
    PSDRV_WriteSpool(physDev, buf, strlen(buf));
    HeapFree(GetProcessHeap(), 0, buf);
    return t42;
}
int OGRPDSDataSource::Open( const char * pszFilename )

{
    pszName = CPLStrdup( pszFilename );

// --------------------------------------------------------------------
//      Does this appear to be a .PDS table file?
// --------------------------------------------------------------------

    VSILFILE* fp = VSIFOpenL(pszFilename, "rb");
    if (fp == NULL)
        return FALSE;

    char szBuffer[512];
    int nbRead = (int)VSIFReadL(szBuffer, 1, sizeof(szBuffer) - 1, fp);
    szBuffer[nbRead] = '\0';

    const char* pszPos = strstr(szBuffer, "PDS_VERSION_ID");
    int bIsPDS = (pszPos != NULL);

    if (!bIsPDS)
    {
        VSIFCloseL(fp);
        return FALSE;
    }

    if (!oKeywords.Ingest(fp, pszPos - szBuffer))
    {
        VSIFCloseL(fp);
        return FALSE;
    }

    VSIFCloseL(fp);
    CPLString osRecordType = oKeywords.GetKeyword( "RECORD_TYPE", "" );
    CPLString osFileRecords = oKeywords.GetKeyword( "FILE_RECORDS", "" );
    CPLString osRecordBytes = oKeywords.GetKeyword( "RECORD_BYTES", "" );
    int nRecordSize = atoi(osRecordBytes);
    if (osRecordType.size() == 0 || osFileRecords.size() == 0 ||
        osRecordBytes.size() == 0 || nRecordSize <= 0)
    {
        CPLError(CE_Failure, CPLE_NotSupported,
                 "One of RECORD_TYPE, FILE_RECORDS or RECORD_BYTES is missing");
        return FALSE;
    }
    CleanString(osRecordType);
    if (osRecordType.compare("FIXED_LENGTH") != 0)
    {
        CPLError(CE_Failure, CPLE_NotSupported,
                 "Only RECORD_TYPE=FIXED_LENGTH is supported");
        return FALSE;
    }

    CPLString osTable = oKeywords.GetKeyword( "^TABLE", "" );
    if (osTable.size() != 0)
        LoadTable(pszFilename, nRecordSize, "TABLE");
    else
    {
        VSILFILE* fp = VSIFOpenL(pszFilename, "rb");
        if (fp == NULL)
            return FALSE;

        while(TRUE)
        {
            CPLPushErrorHandler(CPLQuietErrorHandler);
            const char* pszLine = CPLReadLine2L(fp, 256, NULL);
            CPLPopErrorHandler();
            CPLErrorReset();
            if (pszLine == NULL)
                break;
            char** papszTokens =
                CSLTokenizeString2( pszLine, " =", CSLT_HONOURSTRINGS );
            int nTokens = CSLCount(papszTokens);
            if (nTokens == 2 &&
                papszTokens[0][0] == '^' &&
                strstr(papszTokens[0], "TABLE") != NULL)
            {
                LoadTable(pszFilename, nRecordSize, papszTokens[0] + 1);
            }
            CSLDestroy(papszTokens);
            papszTokens = NULL;
        }
        VSIFCloseL(fp);
    }

    return nLayers != 0;
}
Exemple #22
0
void MainWindow::on_action_refresh_triggered()
{
    LoadTable();
}
Exemple #23
0
int CUG_HTML_DataSource::Open(LPCTSTR name,LPCTSTR option)
{

	// close the current table
	Close();
	CWaitCursor wait;
	char* buff=NULL;
	long length=0;
	int number=1;


	// retrieve the table number
	if(option!=NULL)
		number = _ttoi(option);

	// if this is an URL it *must* have http:// in front of it.
	if(_tcsstr(name,_T("http://"))==NULL)
	{
		// open the file and read it into memory 
		try 
		{
			CFile file(name, CFile::modeRead);
			length = file.GetLength();
			buff = new char[length+1];
			file.Read(buff, length);
		}
		catch(CFileException* e)
		{
			e->ReportError();
			e->Delete();
		}
	}
	else
	{	
		// try to open the given URL and read it into memory
		CInternetSession session;
		CHttpConnection* pServer=NULL;
		CHttpFile* pHttpFile=NULL;
		try
		{
			// check to see if this is a reasonable URL
			CString strServerName;
			CString strObject;
			INTERNET_PORT nPort;
			DWORD dwServiceType;

			if (!AfxParseURL(name, dwServiceType, strServerName, strObject, nPort) ||
				dwServiceType != INTERNET_SERVICE_HTTP)
			{
				AfxMessageBox(_T("Error: can only use URLs beginning with http://\n"));
				TRACE ( _T("Error: can only use URLs beginning with http://\n"));
				return UG_ERROR;
			}
			// open the connection and request
			pServer = session.GetHttpConnection(strServerName, nPort);
			ASSERT(pServer);
			pHttpFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
				strObject, NULL, 1, NULL, NULL);
			ASSERT (pHttpFile);

			// get the http stream
			pHttpFile->SendRequest();
			DWORD dwRet;
			pHttpFile->QueryInfoStatusCode(dwRet);
			if(dwRet>=200 && dwRet <300)
			{
				length = pHttpFile->GetLength();
				buff = new char[length+1];
				pHttpFile->SetReadBufferSize(length+1);
				pHttpFile->Read(buff, length);
			}
//#ifdef _DEBUG
			else {
				AfxMessageBox(_T("HTTP Query Failed"));
				TRACE (_T("HTTP Query Failed\n"));
			}
//#endif
		}
		catch(CException* e)
		{
			e->ReportError();
			e->Delete();
		}

		// do some clean up
		if(pHttpFile)
		{
			pHttpFile->Close();
			delete pHttpFile;
		}
		if(pServer)
		{
			pServer->Close();
			delete pServer;
		}

	}

	// buff should hold the "file" information
	if(buff)
	{
		int res = LoadTable(buff,buff+length,number);
		TRACE(_T("Result of LoadTable == %d\n"), res);
		if(res == 0)
			AfxMessageBox(_T("No tables found in file!"));
		// update control info
		if(m_ctrl!=NULL)
		{
			m_ctrl->SetNumberRows(m_rows);
			m_ctrl->SetNumberCols(m_cols);
			m_ctrl->RedrawAll();
		}
	}
	else
		return UG_ERROR;


	// delete the temporary mem buffer
	if(buff)
		delete [] buff;

	
	return UG_SUCCESS;
}