Esempio n. 1
0
static void GoToLine (text_file_data_t *tptr, uint index)
{
    uint ix;
    debug_message("go to line %u", index);
    if (tptr->m_line_offset_tail != NULL) {
        debug_message("tail index %u", index);
    }
    if (tptr->m_line_offset_tail != NULL &&
            tptr->m_line_offset_tail->index >= index) {
        debug_message("Looking for tail");
        text_line_offset_t *tlptr;
        for (ix = 0, tlptr = tptr->m_line_offset_head; ix < index; ix++) {
            tlptr = tlptr->next_line;
        }
        if (tlptr->index != index) {
            error_message("Seek not right %u %u", tlptr->index, index);
        }
        GoToLine(tptr, tlptr);
        return;
    }
    uint start_index = 0;
    if (tptr->m_line_offset_tail) {
        start_index = tptr->m_line_offset_tail->index;
        GoToLine(tptr, tptr->m_line_offset_tail);
    }
    for (ix = start_index; ix < index; ix++) {
        if (ReadNextLine(tptr) == false)
            return;
    }
}
Esempio n. 2
0
static void
on_SendButton_clicked                  (GtkButton       *button,
                                        gpointer         user_data)
{
    GtkWidget *dialog = GTK_WIDGET(user_data);
    GtkWidget *wid = lookup_widget(dialog, "LineEntry");
    const char *line = gtk_entry_get_text(GTK_ENTRY(wid));
    if (AVFlow->GetTextSource() == NULL) {
        error_message("no text source");
        return;
    }
    AVFlow->GetTextSource()->SourceString(line);

    char buffer[60];
    snprintf(buffer, sizeof(buffer),"Wrote: %.25s...", line);
    wid = lookup_widget(dialog, "statusbar2");
    gtk_statusbar_pop(GTK_STATUSBAR(wid), 0);
    gtk_statusbar_push(GTK_STATUSBAR(wid), 0, buffer);
    if (timer_id != 0) {
        gtk_timeout_remove(timer_id);
    }
    timer_id = gtk_timeout_add(3 * 1000,
                               on_TextDialog_timeout,
                               user_data);
    text_file_data_t *tptr = GetTextFileDataFromUserData(user_data);
    if (tptr != NULL) {
        ReadNextLine(tptr);
        DisplayLineInBuffer(user_data, tptr);
    }
}
Esempio n. 3
0
const uint8_t* CCodec_ScanlineDecoder::GetScanline(int line) {
  if (m_NextLine == line + 1)
    return m_pLastScanline;

  if (m_NextLine < 0 || m_NextLine > line) {
    if (!v_Rewind())
      return nullptr;
    m_NextLine = 0;
  }
  while (m_NextLine < line) {
    ReadNextLine();
    m_NextLine++;
  }
  m_pLastScanline = ReadNextLine();
  m_NextLine++;
  return m_pLastScanline;
}
Esempio n. 4
0
static void
on_NextButton_clicked                  (GtkButton       *button,
                                        gpointer         user_data)
{
    text_file_data_t *tptr = GetTextFileDataFromUserData(user_data);
    ReadNextLine(tptr);
    DisplayLineInBuffer(user_data, tptr);
}
Esempio n. 5
0
static void GoToLine (text_file_data_t *tptr, text_line_offset_t *tlptr)
{
    debug_message("Go to line - %u offset "U64,
                  tlptr->index, tlptr->offset);
    fseeko(tptr->m_file, tlptr->offset, SEEK_SET);
    tptr->m_index = tlptr->index;
    ReadNextLine(tptr);
}
Esempio n. 6
0
int GPSDataReader::ReadAllData(vector<GPSBasicData>& data_list)
{
	data_list.clear();
	GPSBasicData data;
	int count = 0;
	while(ReadNextLine(data))
	{
		data_list.push_back(data);
		count++;
	}
	return count;
}
Esempio n. 7
0
int AisanDataConnFileReader::ReadAllData(vector<DataConn>& data_list)
{
	data_list.clear();
	DataConn data;
	//double logTime = 0;
	int count = 0;
	while(ReadNextLine(data))
	{
		data_list.push_back(data);
		count++;
	}
	return count;
}
Esempio n. 8
0
int AisanCenterLinesFileReader::ReadAllData(vector<AisanCenterLine>& data_list)
{
	data_list.clear();
	AisanCenterLine data;
	//double logTime = 0;
	int count = 0;
	while(ReadNextLine(data))
	{
		data_list.push_back(data);
		count++;
	}
	return count;
}
Esempio n. 9
0
int LocalizationPathReader::ReadAllData(vector<LocalizationWayPoint>& data_list)
{
	data_list.clear();
	LocalizationWayPoint data;
	//double logTime = 0;
	int count = 0;
	while(ReadNextLine(data))
	{
		data_list.push_back(data);
		count++;
	}
	return count;
}
Esempio n. 10
0
uint8_t* CCodec_ScanlineDecoder::GetScanline(int line)
{
    if (m_pDataCache && line < m_pDataCache->m_nCachedLines) {
        return &m_pDataCache->m_Data + line * m_Pitch;
    }
    if (m_NextLine == line + 1) {
        return m_pLastScanline;
    }
    if (m_NextLine < 0 || m_NextLine > line) {
        if (!v_Rewind()) {
            return NULL;
        }
        m_NextLine = 0;
    }
    while (m_NextLine < line) {
        ReadNextLine();
        m_NextLine ++;
    }
    m_pLastScanline = ReadNextLine();
    m_NextLine ++;
    return m_pLastScanline;
}
Esempio n. 11
0
static void
on_EndButton_clicked                   (GtkButton       *button,
                                        gpointer         user_data)
{
    text_file_data_t *tptr = GetTextFileDataFromUserData(user_data);
    if (tptr->m_line_offset_tail != NULL) {
        if (tptr->m_index < tptr->m_line_offset_tail->index) {
            GoToLine(tptr, tptr->m_line_offset_tail);
        }
    }
    while (ReadNextLine(tptr));
    DisplayLineInBuffer(user_data, tptr);
}
Esempio n. 12
0
bool CCodec_ScanlineDecoder::SkipToScanline(int line, IFX_Pause* pPause) {
  if (m_NextLine == line || m_NextLine == line + 1)
    return false;

  if (m_NextLine < 0 || m_NextLine > line) {
    v_Rewind();
    m_NextLine = 0;
  }
  m_pLastScanline = nullptr;
  while (m_NextLine < line) {
    m_pLastScanline = ReadNextLine();
    m_NextLine++;
    if (pPause && pPause->NeedToPauseNow()) {
      return true;
    }
  }
  return false;
}
Esempio n. 13
0
int SimulationFileReader::ReadAllData(SimulationData& data_list)
{
	data_list.simuCars.clear();
	SimulationPoint data;
	//double logTime = 0;
	int count = 0;
	while(ReadNextLine(data))
	{
		if(count == 0)
			data_list.startPoint = data;
		else if(count == 1)
			data_list.goalPoint = data;
		else
			data_list.simuCars.push_back(data);

		count++;
	}

	return count;
}
Esempio n. 14
0
FX_BOOL CCodec_ScanlineDecoder::SkipToScanline(int line, IFX_Pause* pPause) {
  if (m_pDataCache && line < m_pDataCache->NumLines())
    return FALSE;

  if (m_NextLine == line || m_NextLine == line + 1)
    return FALSE;

  if (m_NextLine < 0 || m_NextLine > line) {
    v_Rewind();
    m_NextLine = 0;
  }
  m_pLastScanline = nullptr;
  while (m_NextLine < line) {
    m_pLastScanline = ReadNextLine();
    m_NextLine++;
    if (pPause && pPause->NeedToPauseNow()) {
      return TRUE;
    }
  }
  return FALSE;
}
Esempio n. 15
0
int L1PacketReaderProcessFile( sL1PacketReader *PR, sL0PacketWriter *PW )
{
	Dprintf( DLVerbose, "Started PR process whole file" );
	while( ReadNextLine( PR ) == 0 )
	{
		Dprintf( DLVerbose, "\t PR read line at %d : %s", PR->LineCounter, PR->LineBuffer );

		//try to build a packet that packet writer can write to file
		BYTE	*OutData = NULL;
		int		OutDataLen = 0;
		int		SymbolDefIndex = IsValidL1Symbol( PR->LineBuffer );
		L1SymbolList[SymbolDefIndex]->PacketBuilder( &OutData, &OutDataLen, PR->LineBuffer );

		if( OutDataLen > 0 )
		{
			L1L0ProcessLine( PW, OutData, OutDataLen );
			EmbededFree( OutData );
		}
	}
	Dprintf( DLVerbose, "\t Finished PR process whole file" );
	return 0;
}
DataType* LineDataReader::GetNextData() {
	return new StringDataType(ReadNextLine());
}
Esempio n. 17
0
GtkWidget *create_TextFileDialog (bool do_file)
{
    GtkWidget *TextFileDialog;
    GtkWidget *vbox42;
    GtkWidget *hbox105 = NULL;
    GtkWidget *label196 = NULL;
    GtkWidget *FileNameLabel = NULL;
    GtkWidget *LineEntry;
    GtkWidget *hbox111;
    GtkWidget *vbox43;
    GtkWidget *StartButton;
    GtkWidget *alignment32;
    GtkWidget *hbox112;
    GtkWidget *image38;
    GtkWidget *label204;
    GtkWidget *vbox44;
    GtkWidget *vbox45;
    GtkWidget *PrevButton;
    GtkWidget *alignment33;
    GtkWidget *hbox113;
    GtkWidget *image39;
    GtkWidget *label205;
    GtkWidget *label206;
    GtkWidget *vbox46;
    GtkWidget *NextButton;
    GtkWidget *alignment34;
    GtkWidget *hbox114;
    GtkWidget *label207;
    GtkWidget *image40;
    GtkWidget *vbox47;
    GtkWidget *EndButton;
    GtkWidget *alignment35;
    GtkWidget *hbox115;
    GtkWidget *label208;
    GtkWidget *image41;
    GtkWidget *label209;
    GtkWidget *vbox48;
    GtkWidget *SendButton;
    GtkWidget *alignment36;
    GtkWidget *hbox116;
    GtkWidget *label210;
    GtkWidget *image42;
    GtkWidget *statusbar2;
    GtkTooltips *tooltips;

    tooltips = gtk_tooltips_new();

    TextFileDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(TextFileDialog), _("Text File Transmission"));
    gtk_window_set_position(GTK_WINDOW(TextFileDialog), GTK_WIN_POS_CENTER);

    vbox42 = gtk_vbox_new(FALSE, 13);
    gtk_widget_show(vbox42);
    gtk_container_add(GTK_CONTAINER(TextFileDialog), vbox42);

    if (do_file) {
        hbox105 = gtk_hbox_new(FALSE, 0);
        gtk_widget_show(hbox105);
        gtk_box_pack_start(GTK_BOX(vbox42), hbox105, FALSE, FALSE, 0);

        label196 = gtk_label_new(_("File Name:"));
        gtk_widget_show(label196);
        gtk_box_pack_start(GTK_BOX(hbox105), label196, TRUE, TRUE, 0);
        gtk_misc_set_padding(GTK_MISC(label196), 0, 9);


        FileNameLabel = gtk_label_new("");
        gtk_widget_show(FileNameLabel);
        gtk_box_pack_start(GTK_BOX(hbox105), FileNameLabel, TRUE, TRUE, 0);
    }
    LineEntry = gtk_entry_new();
    gtk_widget_show(LineEntry);
    gtk_box_pack_start(GTK_BOX(vbox42), LineEntry, FALSE, FALSE, 0);

    hbox111 = gtk_hbox_new(FALSE, 0);
    gtk_widget_show(hbox111);
    gtk_box_pack_start(GTK_BOX(vbox42), hbox111, TRUE, TRUE, 0);

    vbox43 = gtk_vbox_new(FALSE, 0);
    gtk_widget_show(vbox43);
    gtk_box_pack_start(GTK_BOX(hbox111), vbox43, FALSE, TRUE, 0);

    StartButton = gtk_button_new();
    gtk_widget_show(StartButton);
    gtk_box_pack_start(GTK_BOX(vbox43), StartButton, TRUE, FALSE, 0);
    gtk_tooltips_set_tip(tooltips, StartButton, _("Move to beginning of file"), NULL);

    alignment32 = gtk_alignment_new(0.5, 0.5, 0, 0);
    gtk_widget_show(alignment32);
    gtk_container_add(GTK_CONTAINER(StartButton), alignment32);

    hbox112 = gtk_hbox_new(FALSE, 2);
    gtk_widget_show(hbox112);
    gtk_container_add(GTK_CONTAINER(alignment32), hbox112);

    image38 = gtk_image_new_from_stock("gtk-goto-first", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show(image38);
    gtk_box_pack_start(GTK_BOX(hbox112), image38, FALSE, FALSE, 0);

    label204 = gtk_label_new_with_mnemonic(_("Start"));
    gtk_widget_show(label204);
    gtk_box_pack_start(GTK_BOX(hbox112), label204, FALSE, FALSE, 0);

    vbox44 = gtk_vbox_new(FALSE, 0);
    gtk_widget_show(vbox44);
    gtk_box_pack_start(GTK_BOX(hbox111), vbox44, FALSE, TRUE, 0);

    vbox45 = gtk_vbox_new(FALSE, 0);
    gtk_widget_show(vbox45);
    gtk_box_pack_start(GTK_BOX(vbox44), vbox45, TRUE, FALSE, 0);

    PrevButton = gtk_button_new();
    gtk_widget_show(PrevButton);
    gtk_box_pack_start(GTK_BOX(vbox45), PrevButton, TRUE, FALSE, 0);
    gtk_tooltips_set_tip(tooltips, PrevButton, _("Move to previous entry"), NULL);

    alignment33 = gtk_alignment_new(0.5, 0.5, 0, 0);
    gtk_widget_show(alignment33);
    gtk_container_add(GTK_CONTAINER(PrevButton), alignment33);

    hbox113 = gtk_hbox_new(FALSE, 2);
    gtk_widget_show(hbox113);
    gtk_container_add(GTK_CONTAINER(alignment33), hbox113);

    image39 = gtk_image_new_from_stock("gtk-go-back", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show(image39);
    gtk_box_pack_start(GTK_BOX(hbox113), image39, FALSE, FALSE, 0);

    label205 = gtk_label_new_with_mnemonic(_("Previous"));
    gtk_widget_show(label205);
    gtk_box_pack_start(GTK_BOX(hbox113), label205, FALSE, FALSE, 0);

    label206 = gtk_label_new("");
    gtk_widget_show(label206);
    gtk_box_pack_start(GTK_BOX(hbox111), label206, TRUE, TRUE, 11);

    vbox46 = gtk_vbox_new(FALSE, 0);
    gtk_widget_show(vbox46);
    gtk_box_pack_start(GTK_BOX(hbox111), vbox46, TRUE, TRUE, 0);

    NextButton = gtk_button_new();
    gtk_widget_show(NextButton);
    gtk_box_pack_start(GTK_BOX(vbox46), NextButton, TRUE, FALSE, 0);
    gtk_tooltips_set_tip(tooltips, NextButton, _("Move to next entry"), NULL);

    alignment34 = gtk_alignment_new(0.5, 0.5, 0, 0);
    gtk_widget_show(alignment34);
    gtk_container_add(GTK_CONTAINER(NextButton), alignment34);

    hbox114 = gtk_hbox_new(FALSE, 2);
    gtk_widget_show(hbox114);
    gtk_container_add(GTK_CONTAINER(alignment34), hbox114);

    label207 = gtk_label_new_with_mnemonic(_("Next"));
    gtk_widget_show(label207);
    gtk_box_pack_start(GTK_BOX(hbox114), label207, FALSE, FALSE, 0);

    image40 = gtk_image_new_from_stock("gtk-go-forward", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show(image40);
    gtk_box_pack_start(GTK_BOX(hbox114), image40, FALSE, FALSE, 0);

    vbox47 = gtk_vbox_new(FALSE, 0);
    gtk_widget_show(vbox47);
    gtk_box_pack_start(GTK_BOX(hbox111), vbox47, TRUE, TRUE, 0);

    EndButton = gtk_button_new();
    gtk_widget_show(EndButton);
    gtk_box_pack_start(GTK_BOX(vbox47), EndButton, TRUE, FALSE, 0);
    gtk_tooltips_set_tip(tooltips, EndButton, _("Move to last entry in file"), NULL);

    alignment35 = gtk_alignment_new(0.5, 0.5, 0, 0);
    gtk_widget_show(alignment35);
    gtk_container_add(GTK_CONTAINER(EndButton), alignment35);

    hbox115 = gtk_hbox_new(FALSE, 2);
    gtk_widget_show(hbox115);
    gtk_container_add(GTK_CONTAINER(alignment35), hbox115);

    label208 = gtk_label_new_with_mnemonic(_("End"));
    gtk_widget_show(label208);
    gtk_box_pack_start(GTK_BOX(hbox115), label208, FALSE, FALSE, 0);

    image41 = gtk_image_new_from_stock("gtk-goto-last", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show(image41);
    gtk_box_pack_start(GTK_BOX(hbox115), image41, FALSE, FALSE, 0);

    label209 = gtk_label_new("");
    gtk_widget_show(label209);
    gtk_box_pack_start(GTK_BOX(hbox111), label209, TRUE, TRUE, 26);

    vbox48 = gtk_vbox_new(FALSE, 0);
    gtk_widget_show(vbox48);
    gtk_box_pack_start(GTK_BOX(hbox111), vbox48, TRUE, FALSE, 0);

    SendButton = gtk_button_new();
    gtk_widget_show(SendButton);
    gtk_box_pack_start(GTK_BOX(vbox48), SendButton, TRUE, FALSE, 0);
    gtk_tooltips_set_tip(tooltips, SendButton, _("Transmit file"), NULL);

    alignment36 = gtk_alignment_new(0.5, 0.5, 0, 0);
    gtk_widget_show(alignment36);
    gtk_container_add(GTK_CONTAINER(SendButton), alignment36);

    hbox116 = gtk_hbox_new(FALSE, 2);
    gtk_widget_show(hbox116);
    gtk_container_add(GTK_CONTAINER(alignment36), hbox116);

    label210 = gtk_label_new_with_mnemonic(_("Send"));
    gtk_widget_show(label210);
    gtk_box_pack_start(GTK_BOX(hbox116), label210, FALSE, FALSE, 0);

    image42 = gtk_image_new_from_stock("gtk-ok", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show(image42);
    gtk_box_pack_start(GTK_BOX(hbox116), image42, FALSE, FALSE, 0);

    statusbar2 = gtk_statusbar_new ();
    gtk_widget_show (statusbar2);
    gtk_box_pack_start (GTK_BOX (vbox42), statusbar2, FALSE, FALSE, 0);

    g_signal_connect((gpointer) TextFileDialog, "delete_event",
                     G_CALLBACK(on_TextFileDialog_delete_event),
                     NULL);
    g_signal_connect((gpointer) TextFileDialog, "destroy",
                     G_CALLBACK(on_TextFileDialog_destroy),
                     NULL);
    if (do_file) {
        g_signal_connect((gpointer) StartButton, "clicked",
                         G_CALLBACK(on_StartButton_clicked),
                         TextFileDialog);
        g_signal_connect((gpointer) PrevButton, "clicked",
                         G_CALLBACK(on_PrevButton_clicked),
                         TextFileDialog);
        g_signal_connect((gpointer) NextButton, "clicked",
                         G_CALLBACK(on_NextButton_clicked),
                         TextFileDialog);
        g_signal_connect((gpointer) EndButton, "clicked",
                         G_CALLBACK(on_EndButton_clicked),
                         TextFileDialog);
    }
    g_signal_connect((gpointer) SendButton, "clicked",
                     G_CALLBACK(on_SendButton_clicked),
                     TextFileDialog);
    g_signal_connect((gpointer)LineEntry, "activate",
                     G_CALLBACK(on_LineEntry_activate),
                     TextFileDialog);

    /* Store pointers to all widgets, for use by lookup_widget(). */
    GLADE_HOOKUP_OBJECT_NO_REF(TextFileDialog, TextFileDialog, "TextFileDialog");
    GLADE_HOOKUP_OBJECT(TextFileDialog, vbox42, "vbox42");
    if (hbox105 != NULL) {
        GLADE_HOOKUP_OBJECT(TextFileDialog, hbox105, "hbox105");
        GLADE_HOOKUP_OBJECT(TextFileDialog, label196, "label196");
        GLADE_HOOKUP_OBJECT(TextFileDialog, FileNameLabel, "FileNameLabel");
    }
    GLADE_HOOKUP_OBJECT(TextFileDialog, LineEntry, "LineEntry");
    GLADE_HOOKUP_OBJECT(TextFileDialog, hbox111, "hbox111");
    GLADE_HOOKUP_OBJECT(TextFileDialog, vbox43, "vbox43");
    GLADE_HOOKUP_OBJECT(TextFileDialog, StartButton, "StartButton");
    GLADE_HOOKUP_OBJECT(TextFileDialog, alignment32, "alignment32");
    GLADE_HOOKUP_OBJECT(TextFileDialog, hbox112, "hbox112");
    GLADE_HOOKUP_OBJECT(TextFileDialog, image38, "image38");
    GLADE_HOOKUP_OBJECT(TextFileDialog, label204, "label204");
    GLADE_HOOKUP_OBJECT(TextFileDialog, vbox44, "vbox44");
    GLADE_HOOKUP_OBJECT(TextFileDialog, vbox45, "vbox45");
    GLADE_HOOKUP_OBJECT(TextFileDialog, PrevButton, "PrevButton");
    GLADE_HOOKUP_OBJECT(TextFileDialog, alignment33, "alignment33");
    GLADE_HOOKUP_OBJECT(TextFileDialog, hbox113, "hbox113");
    GLADE_HOOKUP_OBJECT(TextFileDialog, image39, "image39");
    GLADE_HOOKUP_OBJECT(TextFileDialog, label205, "label205");
    GLADE_HOOKUP_OBJECT(TextFileDialog, label206, "label206");
    GLADE_HOOKUP_OBJECT(TextFileDialog, vbox46, "vbox46");
    GLADE_HOOKUP_OBJECT(TextFileDialog, NextButton, "NextButton");
    GLADE_HOOKUP_OBJECT(TextFileDialog, alignment34, "alignment34");
    GLADE_HOOKUP_OBJECT(TextFileDialog, hbox114, "hbox114");
    GLADE_HOOKUP_OBJECT(TextFileDialog, label207, "label207");
    GLADE_HOOKUP_OBJECT(TextFileDialog, image40, "image40");
    GLADE_HOOKUP_OBJECT(TextFileDialog, vbox47, "vbox47");
    GLADE_HOOKUP_OBJECT(TextFileDialog, EndButton, "EndButton");
    GLADE_HOOKUP_OBJECT(TextFileDialog, alignment35, "alignment35");
    GLADE_HOOKUP_OBJECT(TextFileDialog, hbox115, "hbox115");
    GLADE_HOOKUP_OBJECT(TextFileDialog, label208, "label208");
    GLADE_HOOKUP_OBJECT(TextFileDialog, image41, "image41");
    GLADE_HOOKUP_OBJECT(TextFileDialog, label209, "label209");
    GLADE_HOOKUP_OBJECT(TextFileDialog, vbox48, "vbox48");
    GLADE_HOOKUP_OBJECT(TextFileDialog, SendButton, "SendButton");
    GLADE_HOOKUP_OBJECT(TextFileDialog, alignment36, "alignment36");
    GLADE_HOOKUP_OBJECT(TextFileDialog, hbox116, "hbox116");
    GLADE_HOOKUP_OBJECT(TextFileDialog, label210, "label210");
    GLADE_HOOKUP_OBJECT(TextFileDialog, image42, "image42");
    GLADE_HOOKUP_OBJECT_NO_REF(TextFileDialog, tooltips, "tooltips");
    GLADE_HOOKUP_OBJECT (TextFileDialog, statusbar2, "statusbar2");

    if (do_file) {
        text_file_data_t *tptr = MALLOC_STRUCTURE(text_file_data_t);
        memset(tptr, 0, sizeof(*tptr));
        const char *fname =
            MyConfig->GetStringValue(CONFIG_TEXT_SOURCE_FILE_NAME);

        tptr->m_file = fopen(fname, "r");
        if (tptr->m_file == NULL) {
            char buffer[PATH_MAX];
            snprintf(buffer, PATH_MAX, "Can't open file %s", fname);
            ShowMessage("Can't open file",buffer);
            gtk_widget_destroy(TextFileDialog);
            return NULL;
        }
        gtk_label_set_text(GTK_LABEL(FileNameLabel), fname);
        ReadNextLine(tptr);
        DisplayLineInBuffer(TextFileDialog, tptr);
        GLADE_HOOKUP_OBJECT_NO_REF(TextFileDialog, tptr, "TextFileData");
    } else {
        gtk_widget_set_sensitive(StartButton, false);
        gtk_widget_set_sensitive(PrevButton, false);
        gtk_widget_set_sensitive(NextButton, false);
        gtk_widget_set_sensitive(EndButton, false);
        GLADE_HOOKUP_OBJECT_NO_REF(TextFileDialog, NULL, "TextFileData");
    }

    gtk_drag_dest_set(TextFileDialog,
                      GTK_DEST_DEFAULT_ALL,
                      drop_types,
                      NUM_ELEMENTS_IN_ARRAY(drop_types),
                      GDK_ACTION_COPY);
    gtk_drag_dest_set(LineEntry,
                      GTK_DEST_DEFAULT_ALL,
                      drop_types,
                      NUM_ELEMENTS_IN_ARRAY(drop_types),
                      GDK_ACTION_COPY);

    g_signal_connect((gpointer)TextFileDialog, "drag_data_received",
                     G_CALLBACK(on_drag_data_received),
                     TextFileDialog);

    g_signal_connect((gpointer)LineEntry, "drag_data_received",
                     G_CALLBACK(on_drag_data_received_entry),
                     TextFileDialog);

    gtk_widget_show(TextFileDialog);

    if (do_file) {
        gtk_widget_grab_focus(SendButton);
        on_SendButton_clicked(GTK_BUTTON(SendButton), TextFileDialog);
    } else {
        gtk_widget_grab_focus(LineEntry);
    }
    return TextFileDialog;
}
Esempio n. 18
0
int CNscContext::yylex (YYSTYPE* yylval)
{

	//
	// Initialize lvalue
	//

	*yylval = NULL;

	//
	// If we have no stream, return nothing
	//

	if (m_pStreamTop == NULL)
		return EOF;

	//
	// If we need to read a line
	//

try_again:;
	if (m_pStreamTop ->pszNextTokenPos == NULL || 
		*m_pStreamTop ->pszNextTokenPos == 0)
	{
read_another_line:;
		if (!ReadNextLine (false))
			return EOF;
	}

	//
	// Skip the white space
	//

	char c;
	for (;;)
	{
		c = *m_pStreamTop ->pszNextTokenPos;
		if (c == 0)
			goto read_another_line;
		else if (c <= ' ' || c > 126)
			m_pStreamTop ->pszNextTokenPos++;
		else
			break;
	}

	//
	// If we have an identifier
	//

	if (isalpha (c) || c == '_')
	{
		char *pszStart = m_pStreamTop ->pszNextTokenPos;
		m_pStreamTop ->pszNextTokenPos++;
		for (;;)
		{
			c = *m_pStreamTop ->pszNextTokenPos;
			if (isalnum (c) || c == '_')
				m_pStreamTop ->pszNextTokenPos++;
			else
				break;
		}

		//
		// Get the hash value for the ID
		//

		int nCount = (int) (m_pStreamTop ->pszNextTokenPos - pszStart);
		UINT32 ulHash = CNscSymbolTable::GetHash (pszStart, nCount);
		
		//
		// See if it is a reserved word
		//

		NscSymbol *pSymbol = g_sNscReservedWords .Find (pszStart, nCount, ulHash);

		//
		// If so, return that word
		//

		if (pSymbol != NULL)
		{
			assert (pSymbol ->nSymType == NscSymType_Token);
			if (pSymbol ->nToken == ENGINE_TYPE)
			{
				CNscPStackEntry *pEntry = GetPStackEntry (__FILE__, __LINE__);
				pEntry ->SetType ((NscType) (
					NscType_Engine_0 + pSymbol ->nEngineObject));
				*yylval = pEntry;
				return pSymbol ->nToken;
			}
			else
                return pSymbol ->nToken;
		}
		else 
		{
			CNscPStackEntry *pEntry = GetPStackEntry (__FILE__, __LINE__);
			pEntry ->SetIdentifier (pszStart, nCount);
			*yylval = pEntry;
			return IDENTIFIER;
		}
	}

	//
	// If we have a number.
	//
	// The bioware compiler doesn't like a number starting
	// with a '.'
	//

	else if (isdigit (c))
	{

		// 
		// If this is a hex value
		//

		if (c == '0' && 
			(m_pStreamTop ->pszNextTokenPos [1] == 'x' ||
			m_pStreamTop ->pszNextTokenPos [1] == 'X'))
		{

			//
			// Parse the number
			//

			m_pStreamTop ->pszNextTokenPos += 2;
			int nValue = 0;
			for (;;)
			{
				c = *m_pStreamTop ->pszNextTokenPos;
				if (isdigit (c))
				{
					nValue = nValue * 16 + (c - '0');
					m_pStreamTop ->pszNextTokenPos++;
				}
				else if (c >= 'A' && c <= 'F')
				{
					nValue = nValue * 16 + (c - 'A' + 10);
					m_pStreamTop ->pszNextTokenPos++;
				}
				else if (c >= 'a' && c <= 'f')
				{
					nValue = nValue * 16 + (c - 'a' + 10);
					m_pStreamTop ->pszNextTokenPos++;
				}
				else
					break;
			}

			//
			// Return results
			//

			CNscPStackEntry *pEntry = GetPStackEntry (__FILE__, __LINE__);
			pEntry ->SetType (NscType_Integer);
			pEntry ->PushConstantInteger (nValue);
			*yylval = pEntry;
			return INTEGER_CONST; 
		}

		//
		// Otherwise, treat as a normal number
		//

		else
		{

			//
			// Parse the number
			//

			bool fHasDecimal = false;
			char *pszStart = m_pStreamTop ->pszNextTokenPos;
			for (;;)
			{
				c = *m_pStreamTop ->pszNextTokenPos;
				if (isdigit (c))
					m_pStreamTop ->pszNextTokenPos++;
				else if (c == '.' && !fHasDecimal)
				{
					fHasDecimal = true;
					m_pStreamTop ->pszNextTokenPos++;
				}
				else
					break;
			}

			//
			// Test for 'F' extension
			//

			int nCharacter = (int) (m_pStreamTop ->pszNextTokenPos - pszStart);
			if (c == 'f' || c == 'F')
			{
				fHasDecimal = true;
				m_pStreamTop ->pszNextTokenPos++;
			}

			//
			// Convert the value
			//

			char *psz = (char *) alloca (nCharacter + 1);
			memcpy (psz, pszStart, nCharacter);
			psz [nCharacter] = 0;
			CNscPStackEntry *pEntry = GetPStackEntry (__FILE__, __LINE__);
			*yylval = pEntry;
			if (fHasDecimal)
			{
				pEntry ->SetType (NscType_Float);
				pEntry ->PushConstantFloat ((float) atof (psz));
				return FLOAT_CONST;
			}
			else
			{
				pEntry ->SetType (NscType_Integer);
				pEntry ->PushConstantInteger (atol (psz));
				return INTEGER_CONST;
			}
		}
	}

	//
	// Otherwise, we have a symbol (hopefully)
	//

	else
	{
		m_pStreamTop ->pszNextTokenPos++;
		switch (c)
		{
			case '/':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '*')
				{
					m_pStreamTop ->pszNextTokenPos++;
					for (;;)
					{
						if (m_pStreamTop ->pszNextTokenPos [0] == '*' &&
							m_pStreamTop ->pszNextTokenPos [1] == '/')
						{
							m_pStreamTop ->pszNextTokenPos += 2;
							goto try_again;
						}
						else if (m_pStreamTop ->pszNextTokenPos [0] == 0)
						{
							if (!ReadNextLine (true))
							{
								//GenerateError ("End of file reached while processing comment");
								if (!IsPhase2 ())
                                    GenerateWarning ("End of file reached while processing comment");
								return EOF;
							}
						}
						else
							m_pStreamTop ->pszNextTokenPos++;
					}
				}
				else if (c == '/')
				{
					m_pStreamTop ->pszNextTokenPos++;
					goto read_another_line;
				}
				else if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return DIVEQ;
				}
				else 
				{
					return '/';
				}
				break;

			case '{':
			case '}':
			case '[':
			case ']':
			case '(':
			case ')':
			case ';':
			case ':':
			case '?':
			case ',':
			case '~':
			case '.':
				return c;

			case '+':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return ADDEQ;
				}
				else if (c == '+')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return PLUSPLUS;
				}
				else
					return '+';
				break;

			case '-':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return SUBEQ;
				}
				else if (c == '-')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return MINUSMINUS;
				}
				else
					return '-';
				break;

			case '*':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return MULEQ;
				}
				else
					return '*';
				break;

			case '%':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return MODEQ;
				}
				else
					return '%';
				break;

			case '^':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return XOREQ;
				}
				else
					return '^';
				break;

			case '&':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return ANDEQ;
				}
				else if (c == '&')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return ANDAND;
				}
				else
					return '&';
				break;

			case '|':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return OREQ;
				}
				else if (c == '|')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return OROR;
				}
				else
					return '|';
				break;

			case '!':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return NOTEQ;
				}
				else
					return '!';
				break;

			case '=':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return EQ;
				}
				else
					return '=';
				break;

			case '<':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return LTEQ;
				}
				else if (c == '<')
				{
					m_pStreamTop ->pszNextTokenPos++;
					c = *m_pStreamTop ->pszNextTokenPos;
					if (c == '=')
					{
						m_pStreamTop ->pszNextTokenPos++;
						return SLEQ;
					}
					else
						return SL;
				}
				else
					return '<';
				break;

			case '>':
				c = *m_pStreamTop ->pszNextTokenPos;
				if (c == '=')
				{
					m_pStreamTop ->pszNextTokenPos++;
					return GTEQ;
				}
				else if (c == '>')
				{
					m_pStreamTop ->pszNextTokenPos++;
					c = *m_pStreamTop ->pszNextTokenPos;
					if (c == '=')
					{
						m_pStreamTop ->pszNextTokenPos++;
						return SREQ;
					}
					else if (c == '>')
					{
						m_pStreamTop ->pszNextTokenPos++;
						c = *m_pStreamTop ->pszNextTokenPos;
						if (c == '=')
						{
							m_pStreamTop ->pszNextTokenPos++;
							return USREQ;
						}
						else
							return USR;
					}
					else
						return SR;
				}
				else
					return '>';
				break;

			case '"':
				{
					char *pszStart = m_pStreamTop ->pszNextTokenPos;
					char *pszOut = pszStart;
					for (;;)
					{
						c = *m_pStreamTop ->pszNextTokenPos++;
						if (c == '"')
						{
							CNscPStackEntry *pEntry = GetPStackEntry (__FILE__, __LINE__);
							pEntry ->SetType (NscType_String);
							pEntry ->PushConstantString (pszStart, (int) (pszOut - pszStart));
							*yylval = pEntry;
							return STRING_CONST;
						}
						else if (c == '\\')
						{
							c = *m_pStreamTop ->pszNextTokenPos;
							if (c == 'n')
							{
								*pszOut++ = '\n';
								m_pStreamTop ->pszNextTokenPos++;
							}
							else
								;
						}
						else if (c == 0)
						{
							CNscPStackEntry *pEntry = GetPStackEntry (__FILE__, __LINE__);
							pEntry ->SetType (NscType_String);
							pEntry ->PushConstantString (pszStart, (int) (pszOut - pszStart));
							*yylval = pEntry;
							GenerateError ("Unterminated string");
							return STRING_CONST; 
						}
						else
							*pszOut++ = c;
					}
				}
				break;

			default:
				if (!IsPhase2 ())
				{
					GenerateWarning ("Invalid character '%c' (0x%02X) "
						"found in source, ignored", c, c);
				}
				goto try_again;
		}
	}
}
Esempio n. 19
0
DWORD
LWParseConfigFile(
    PCSTR pszFilePath,
    PCFGSECTION* ppCfgSectionList,
    BOOLEAN bWindowsDoubleByteFormat
    )
{
    DWORD dwError = 0;
    PCFGSECTION pSectionList = NULL;
    PCFGSECTION pSection = NULL;
    PNVPAIR pNVPair = NULL;
    FILE* fp = NULL;
    CHAR staticBuffer[1024+1];
    PSTR szBuf = NULL;
    DWORD dwLen = 0;
    PSTR pszTmp = NULL;
    PSTR pszName = NULL;
    PSTR pszValue = NULL;
    DWORD dwSignature = 0;
    /*DWORD nRead = 0;*/
    BOOLEAN bEOF = FALSE;

    if ((fp = fopen(pszFilePath, "r")) == NULL) {
        dwError = errno;
        goto error;
    }

    if (fcntl(fileno(fp), F_SETFD, FD_CLOEXEC) < 0) {
        dwError = errno;
        BAIL_ON_MAC_ERROR(dwError);
    }

    if (bWindowsDoubleByteFormat) {
        dwError = ParseHeader(fp, &dwSignature);
        BAIL_ON_MAC_ERROR(dwError);

        if (dwSignature != 0xFEFF) {
            dwError = MAC_AD_ERROR_INVALID_TAG;
            BAIL_ON_MAC_ERROR(dwError);
        }
    }

    while (!bEOF) {
        LW_SAFE_FREE_STRING(szBuf);

        if (bWindowsDoubleByteFormat) {

            staticBuffer[0] = '\0';
            dwError = ReadNextDoubleByteLine(fp, staticBuffer, 1024, &bEOF);
            BAIL_ON_MAC_ERROR(dwError);
            dwError = LwAllocateString(staticBuffer, &szBuf);
            BAIL_ON_MAC_ERROR(dwError);

        } else {

            dwError = ReadNextLine(fp, &szBuf, &bEOF);
            BAIL_ON_MAC_ERROR(dwError);

        }

        LwStripWhitespace(szBuf, TRUE, TRUE);

        if (!(dwLen=strlen(szBuf)))
            continue;

        /* Skip comments for now */
        if (szBuf[0] == '#' ||
            szBuf[0] == ';')
            continue;

        if (szBuf[0]       == '[' &&
            szBuf[dwLen-1] == ']') {

            if (pSection) {
                pSection->pNext = pSectionList;
                pSectionList = pSection;
                pSection = NULL;
            }

            dwError = LwAllocateMemory(sizeof(CFGSECTION), (PVOID*)&pSection);
            BAIL_ON_MAC_ERROR(dwError);

            szBuf[dwLen-1] = '\0';

            dwError = LwAllocateString(szBuf+1, &pSection->pszName);
            BAIL_ON_MAC_ERROR(dwError);

            LwStripWhitespace(pSection->pszName, TRUE, TRUE);

        } else {

            if (!pSection) {
                dwError = MAC_AD_ERROR_NO_SUCH_ATTRIBUTE;
                BAIL_ON_MAC_ERROR(dwError);
            }

            if ((pszTmp = strchr(szBuf, '=')) == NULL) {
                continue;
            }

            if (pszTmp == szBuf) {
                dwError = MAC_AD_ERROR_INVALID_TAG;
                BAIL_ON_MAC_ERROR(dwError);
            }

            dwError = LwAllocateMemory(pszTmp-szBuf+1, (PVOID*)&pszName);
            BAIL_ON_MAC_ERROR(dwError);

            strncpy(pszName, szBuf, pszTmp-szBuf);

            pszTmp++;
            while (*pszTmp != '\0' && isspace((int)*pszTmp))
                pszTmp++;

            if (*pszTmp != '\0') {
                dwError = LwAllocateString(pszTmp, &pszValue);
                BAIL_ON_MAC_ERROR(dwError);
            }

            dwError = LwAllocateMemory(sizeof(NVPAIR), (PVOID*)&pNVPair);
            BAIL_ON_MAC_ERROR(dwError);

            LwStripWhitespace(pszName, TRUE, TRUE);
            LwStripWhitespace(pszValue, TRUE, TRUE);

            pNVPair->pszName = pszName; pszName = NULL;
            pNVPair->pszValue = pszValue; pszValue = NULL;

            pNVPair->pNext = pSection->pNVPairList;
            pSection->pNVPairList = pNVPair;
            pNVPair = NULL;

        }
    }

    if (pSection) {
        pSection->pNext = pSectionList;
        pSectionList = pSection;
        pSection = NULL;
    }

    pSectionList = ReverseSectionsAndNVPairs(pSectionList);

    *ppCfgSectionList = pSectionList;

    fclose(fp); fp = NULL;

cleanup:

    LW_SAFE_FREE_STRING(szBuf);

    if (fp) {
        fclose(fp);
    }

    LW_SAFE_FREE_STRING(pszName);
    LW_SAFE_FREE_STRING(pszValue);

    return dwError;

error:

    *ppCfgSectionList = NULL;

    if (pSectionList)
    {
       LWFreeConfigSectionList(pSectionList);
    }

    if (pSection)
    {
        LWFreeSection(pSection);
    }

    if (pNVPair)
    {
        LWFreeNVPair(pNVPair);
    }

    goto cleanup;
}
Esempio n. 20
0
static void Get_Sequence (FILE *f, SeqRecPtr seqrp)

{
  Char      ch;
  CharPtr   chptr;
  Boolean   goOn;
  IdRecPtr  last;
  Int4      len;
  Char      str [256];
  IdRecPtr  this;
  Int4      total;

  if (f != NULL && seqrp != NULL) {
    if (seqrp->rawSeq == NULL) {
      seqrp->rawSeq = BSNew (1000);
    }
    if (seqrp->segLens == NULL) {
      seqrp->segLens = BSNew (10);
    }
    len = 0;
    total = 0;
    goOn = TRUE;
    while (goOn && ReadNextLine (f, str, sizeof (str))) {
      if (str [0] == '&') {
        goOn = FALSE;
      } else if (str [0] == '!') {
        goOn = FALSE;
      } else if (str [0] == '>') {
        if (len > 0) {
          if (seqrp->lookForStop) {
            BSPutByte (seqrp->rawSeq, (Int2) '*');
            len++;
          }
          BSWrite (seqrp->segLens, &len, sizeof (Int4));
          total += len;
          len = 0;
        }
        chptr = StringChr (str, ' ');
        if (chptr != NULL) {
          *chptr = '\0';
        }
        if (seqrp->ids != NULL) {
          last = seqrp->ids;
          while (last->next != NULL) {
            last = last->next;
          }
          this = MemNew (sizeof (IdRec));
          if (this != NULL) {
            this->id.accn = StringSave (str + 1);
          }
          last->next = this;
        } else {
          last = MemNew (sizeof (IdRec));
          if (last != NULL) {
            last->id.accn = StringSave (str + 1);
          }
          seqrp->ids = last;
        }
      } else if (str [0] != '\0') {
        chptr = str;
        while (*chptr != '\0') {
          ch = TO_UPPER (*chptr);
          if (ch >= 'A' && ch <= 'Z') {
            if (seqrp->nuc) {
              if (ch == 'U') {
                ch = 'T';
              }
              if (StringChr ("BDEFHIJKLMOPQRSUVWXYZ", ch) == NULL) {
                BSPutByte (seqrp->rawSeq, (Int2) ch);
                len++;
              }
            } else {
              if (StringChr ("JOU", ch) == NULL) {
                BSPutByte (seqrp->rawSeq, (Int2) ch);
                len++;
              }
            }
          }
          chptr++;
        }
      }
    }
    if (seqrp->nuc) {
      BSPutByte (seqrp->rawSeq, (Int2) 'N');
      BSPutByte (seqrp->rawSeq, (Int2) 'N');
      BSPutByte (seqrp->rawSeq, (Int2) 'N');
      len += 3;
    }
    if (len > 0) {
      if (seqrp->lookForStop) {
        BSPutByte (seqrp->rawSeq, (Int2) '*');
        len++;
      }
      BSWrite (seqrp->segLens, &len, sizeof (Int4));
      total += len;
      len = 0;
    }
    if (total > 0) {
      seqrp->sequence = BSMerge (seqrp->rawSeq, NULL);
      seqrp->length = total;
    } else {
      seqrp->sequence = NULL;
      seqrp->length = 0;
    }
  }
}