Пример #1
0
static gchar *symbol_bd_sql_get_symbols_matches (Symbolizable *self, const gchar *symbol_prefix, gint flags)
{
  gphpedit_debug (DEBUG_SYMBOLIZABLE);
  SymbolBdSQLDetails *symbolbddet;
  symbolbddet = SYMBOL_BD_SQL_GET_PRIVATE(self);
  symbolbddet->completion_prefix = (gchar *) symbol_prefix;
  symbolbddet->completion_string = NULL;

  if (symbol_bd_sql_has_cache(symbolbddet->cache_str, symbolbddet->cache_completion, symbolbddet->cache_flags, symbol_prefix, flags)){
    symbolbddet->completion_string = symbol_bd_get_autocomp_from_cache(symbolbddet->cache_str, symbolbddet->cache_completion, symbol_prefix);
  } else {
    symbolbddet->completion_tree = g_tree_new_full ((GCompareDataFunc) g_strcmp0, NULL, NULL,(GDestroyNotify) g_free);

    if (((flags & SYMBOL_ALL) == SYMBOL_ALL) || ((flags & SYMBOL_FUNCTION) == SYMBOL_FUNCTION)) {
      /* add api functions */
      g_tree_foreach (symbolbddet->sql_api_tree, add_api_item, symbolbddet);
    }
    g_tree_foreach (symbolbddet->completion_tree, make_result_string, symbolbddet);
    g_tree_destroy (symbolbddet->completion_tree);
    if (symbolbddet->completion_string) symbol_bd_sql_save_result_in_cache(symbolbddet, symbolbddet->completion_string->str, symbol_prefix);
  }

  if (symbolbddet->completion_string){
    gphpedit_debug_message(DEBUG_CLASSBROWSER, "prefix: %s autocomplete list:%s\n", symbol_prefix, symbolbddet->completion_string->str);
    return g_string_free(symbolbddet->completion_string, FALSE);
  }

  gphpedit_debug_message(DEBUG_CLASSBROWSER, "prefix: %s autocomplete list:%s\n", symbol_prefix, "null");
  return NULL;
}
Пример #2
0
void on_open1_activate(GtkWidget *widget)
{
    GtkWidget *file_selection_box;
    gchar *folder;
    const gchar *last_opened_folder;
    // Create the selector widget
    file_selection_box = gtk_file_chooser_dialog_new("Please select files for editing", GTK_WINDOW(main_window.window),
                         GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);

    gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER(file_selection_box), FALSE);
    gtk_dialog_set_default_response (GTK_DIALOG(file_selection_box), GTK_RESPONSE_ACCEPT);
    //Add filters to the open dialog
    add_file_filters(GTK_FILE_CHOOSER(file_selection_box));
    last_opened_folder = get_preferences_manager_last_opened_folder(main_window.prefmg);
    gphpedit_debug_message(DEBUG_MAIN_WINDOW,"last_opened_folder: %s", last_opened_folder);
    /* opening of multiple files at once */
    gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(file_selection_box), TRUE);
    gchar *filename = (gchar *)document_get_filename(document_manager_get_current_document(main_window.docmg));
    if (filename && !document_get_untitled(document_manager_get_current_document(main_window.docmg))) {
        folder = filename_parent_uri(filename);
        gphpedit_debug_message(DEBUG_MAIN_WINDOW,"folder: %s", folder);
        gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(file_selection_box),  folder);
        g_free(folder);
    }
    else if (last_opened_folder) {
        gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(file_selection_box),  last_opened_folder);
    }

    if (gtk_dialog_run(GTK_DIALOG(file_selection_box)) == GTK_RESPONSE_ACCEPT) {
        open_file_ok(GTK_FILE_CHOOSER(file_selection_box));
    }
    gtk_widget_destroy(file_selection_box);
}
Пример #3
0
void filebrowser_backend_create_dir(FilebrowserBackend *filebackend, gchar *filename, gchar *name, gboolean isdir){
  FilebrowserBackendDetails *directory = FILEBROWSER_BACKEND_GET_PRIVATE(filebackend);
  GFile *config;
  GError *error=NULL;
  gchar *filename_int;
  if (isdir){
      gchar *parent=filename_parent_uri(filename);
      filename_int= g_strdup_printf("%s/%s",parent,name);
      g_free(parent);
      config= g_file_new_for_commandline_arg(filename_int);
  } else {
      gchar *parent;
      if (filename) {
        parent=filename_parent_uri(filename);
      } else {
        parent=g_strdup(directory->current_folder);
      }
      filename_int= g_build_path (G_DIR_SEPARATOR_S, parent, name, NULL);
      g_free(parent);
      config=g_file_new_for_commandline_arg(filename_int);
  }
  gphpedit_debug_message(DEBUG_FILEBROWSER, "New directory:%s",filename_int);

  g_free(filename_int);
  if (!g_file_make_directory (config, directory->cancellable, &error)){
     g_print(_("Error creating folder. GIO error:%s\n"), error->message);
     g_error_free (error);
  }
  g_object_unref(config);
	filebrowser_backend_refresh_folder (filebackend);
}
Пример #4
0
static void autoindent_brace_code (GtkScintilla *sci, PreferencesManager *pref)
{
  gint current_pos;
  gint current_line;
  gint previous_line;
  gint previous_line_indentation;
  gint previous_line_end;

  current_pos = gtk_scintilla_get_current_pos(sci);
  current_line = gtk_scintilla_line_from_position(sci, current_pos);

  gphpedit_debug (DEBUG_DOCUMENT);

  if (current_line>0) {
    gtk_scintilla_begin_undo_action(sci);
    previous_line = current_line-1;
    previous_line_indentation = gtk_scintilla_get_line_indentation(sci, previous_line);

    previous_line_end = gtk_scintilla_get_line_end_position(sci, previous_line);
    indent_line(sci, current_line, previous_line_indentation);
    gphpedit_debug_message (DEBUG_DOCUMENT, "previous_line=%d, previous_indent=%d\n", previous_line, previous_line_indentation);
    gint pos;
    gboolean tabs_instead_spaces;
    g_object_get(pref,"tabs_instead_spaces", &tabs_instead_spaces, NULL);
    if(tabs_instead_spaces){
      pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation/gtk_scintilla_get_tab_width(sci));
    } else {
      pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation);
    }
    gtk_scintilla_goto_pos(sci, pos);
    gtk_scintilla_end_undo_action(sci);
  }
}
Пример #5
0
void register_file_opened(gchar *filename)
{
  gphpedit_debug_message(DEBUG_DOC_MANAGER,"filename: %s\n", filename);
  gchar *folder = filename_parent_uri(filename);
  g_object_set (main_window.prefmg, "last_opened_folder", folder, NULL);
  g_free(folder);
}
Пример #6
0
void reopen_recent(GtkRecentChooser *chooser, gpointer data) {
    gchar *filename = gtk_recent_chooser_get_current_uri  (chooser);
    if (!filename) return;
    gphpedit_debug_message(DEBUG_MAIN_WINDOW,"filename: %s", filename);
    document_manager_switch_to_file_or_open(main_window.docmg, filename, 0);
    g_free(filename);
}
Пример #7
0
/*
* symbol_manager_purge_file
* Remove a file and it's symbols from the DB for the corresponding @ftype.
*/
void symbol_manager_add_file (SymbolManager *symbolmg, gchar *filename, gint ftype)
{
  gphpedit_debug_message (DEBUG_SYMBOLIZABLE, "filename: %s\n", filename);
  if(!symbolmg || !filename) return ;
  Symbolizable *result = symbol_manager_get_symbolizable_for_type(symbolmg, ftype);
  if (!result) return ;
  symbolizable_add_file (result, filename);
}
Пример #8
0
void filebrowser_backend_go_folder_up (FilebrowserBackend *fbback){
  FilebrowserBackendDetails *directory = FILEBROWSER_BACKEND_GET_PRIVATE(fbback);

  gchar *fullfolderpath=filename_parent_uri(directory->current_folder);
  gphpedit_debug_message(DEBUG_FILEBROWSER, "Up dir:%s\n",fullfolderpath);
  filebrowser_backend_update_folder (fbback,fullfolderpath); /*update with new uri */
  if (fullfolderpath) g_free(fullfolderpath);
}
Пример #9
0
static void on_notebook_switch_page (GtkNotebook *notebook, GtkWidget *page,
                gint page_num, gpointer user_data)
{
  MainWindow *main_window = (MainWindow *) user_data;
  if(!document_manager_set_current_document_from_widget (main_window->docmg, page)) {
    gphpedit_debug_message(DEBUG_MAIN_WINDOW,_("Unable to get data for page %d"), page_num);
  }
}
Пример #10
0
void filebrowser_backend_go_folder_home (FilebrowserBackend *fbback, gchar *filename){
//  FilebrowserBackendDetails *directory = FILEBROWSER_BACKEND_GET_PRIVATE(fbback);
  gchar *folderpath=NULL;
  if (filename_is_native(filename)){
    folderpath=filename_parent_uri(filename);
    gphpedit_debug_message(DEBUG_FILEBROWSER, "HOME dir:%s\n",folderpath);
  }
  filebrowser_backend_update_folder (fbback,folderpath);
  if (folderpath) g_free(folderpath);
}
Пример #11
0
gint str_sec_print(gchar *label, gchar *pstart, gchar *pend, guint line_number) {
  gchar *teststring;
  guint length;
  length = pend - pstart + 1;
  teststring = g_malloc(length + 1);
  strncpy(teststring, pstart, length);
  teststring[length]='\0';
  gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%5d:%s: %s", line_number, label, teststring);
  g_free(teststring);
  return 0;
}
Пример #12
0
void filebrowser_backend_update_folder (FilebrowserBackend *fbback, const gchar *newfolder){
  gphpedit_debug_message(DEBUG_FILEBROWSER, "New path:%s\n",newfolder);

  if (newfolder && !IS_DEFAULT_DIR(newfolder)){
    gchar *real_path=filename_get_path((gchar *)newfolder);
    change_current_folder(fbback, real_path);
    init_filebrowser(fbback);
    g_free(real_path);
  } else {
    filebrowser_backend_restore(fbback);
  }
}
Пример #13
0
/*
* init object and start process
*/
gboolean init_filebrowser(FilebrowserBackend *filebackend){
  FilebrowserBackendDetails *directory;
  directory = FILEBROWSER_BACKEND_GET_PRIVATE(filebackend);

  directory->cancellable = g_cancellable_new ();
  gphpedit_debug_message(DEBUG_FILEBROWSER, "init with :%s\n",directory->current_folder);
  GFile *file = g_file_new_for_commandline_arg (directory->current_folder);
  //file don't exist?
  if (!g_file_query_exists (file,directory->cancellable)){
    gphpedit_debug_message(DEBUG_FILEBROWSER, "file '%s' don't exist?\n",directory->current_folder);
    g_object_unref(file);
    filebrowser_backend_restore(filebackend);
    return FALSE;
  }
  GError *error=NULL;
  GFileInfo *info =g_file_query_info (file,G_FILE_ATTRIBUTE_ACCESS_CAN_READ, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,directory->cancellable,&error);
  if (!info){
    g_print("ERROR initing file browser:%s\n",error->message);
    g_error_free(error);
    gphpedit_debug_message(DEBUG_FILEBROWSER, "folder %s\n",directory->current_folder);
    g_object_unref(file);
    filebrowser_backend_restore(filebackend);
    return FALSE;
  }
  if (!g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)){
    gphpedit_debug_message(DEBUG_FILEBROWSER, "Don't have read access for %s.\n", directory->current_folder);
    filebrowser_backend_restore(filebackend);
    return FALSE;
  }
  g_object_unref(info);
  /* clear cache data*/
  clear_filebrowser_backend(directory, FALSE);
  gphpedit_debug_message(DEBUG_FILEBROWSER, "%s","clear tree and cache data\n");
  /* enumerate folder files */
  g_object_unref(file);
  if (g_cancellable_is_cancelled (directory->cancellable)) return FALSE;
  init_enumeration(filebackend);
  return TRUE;
}
Пример #14
0
/*
 *show_hint
 * Show a new menu hint in the statusbar, and set widget state to prelight
*/
static gboolean show_hint(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
{
    MainWindow *main_window = (MainWindow *) user_data;
    gtk_widget_set_state (widget, GTK_STATE_PRELIGHT);
    const gchar *message = (const gchar *) g_hash_table_lookup (main_window->pmenu_hints, widget);
    if (!message)
    {
        gphpedit_debug_message (DEBUG_MAIN_WINDOW,"%s", "Error menu hint is Null, skipping");
        return FALSE;
    }
    main_window->context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR(main_window->appbar), message);
    main_window->message_id= gtk_statusbar_push (GTK_STATUSBAR(main_window->appbar), main_window->context_id, message);
    return FALSE;
}
Пример #15
0
void add_to_search_history(const gchar *current_text) {
    /* add text to search history*/
    GSList *walk;
    gint i=0;
    for (walk = get_preferences_manager_php_search_history(main_window.prefmg); walk!=NULL; walk = g_slist_next(walk)) {
        i++;
        if (g_strcmp0((gchar *) walk->data,current_text)==0) {
            return;  /* already in the list */
        }
    }
    set_preferences_manager_new_search_history_item(main_window.prefmg, i, current_text);
    gphpedit_debug_message(DEBUG_MAIN_WINDOW,"added:%s",current_text);
    toolbar_completion_add_text(TOOLBAR(main_window.toolbar_find), current_text);
}
Пример #16
0
void on_save_as1_activate(GtkWidget *widget)
{
    GtkWidget *file_selection_box;
    gchar *filename;
    const gchar *last_opened_folder;

    if (document_manager_get_current_document(main_window.docmg)) {
        // Create the selector widget
        file_selection_box = gtk_file_chooser_dialog_new (_("Please type the filename to save as..."),
                             GTK_WINDOW(main_window.window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                             GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);

        gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER(file_selection_box), FALSE);
        gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER(file_selection_box), TRUE);
        gtk_dialog_set_default_response (GTK_DIALOG(file_selection_box), GTK_RESPONSE_ACCEPT);

        if (document_manager_get_current_document(main_window.docmg)) { //FIXME: rework this code
            filename = document_get_filename(document_manager_get_current_document(main_window.docmg));
            if (!document_get_untitled(document_manager_get_current_document(main_window.docmg))) {
                gtk_file_chooser_set_uri(GTK_FILE_CHOOSER(file_selection_box), filename);
            }
            else {
                last_opened_folder = get_preferences_manager_last_opened_folder(main_window.prefmg);
                gphpedit_debug_message(DEBUG_MAIN_WINDOW,"last_opened_folder: %s", last_opened_folder);
                if (last_opened_folder) {
                    gphpedit_debug_message(DEBUG_MAIN_WINDOW,"Setting current_folder_uri to %s", last_opened_folder);
                    gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(file_selection_box),  last_opened_folder);
                }
            }
            g_free(filename);
        }
        if (gtk_dialog_run (GTK_DIALOG(file_selection_box)) == GTK_RESPONSE_ACCEPT) {
            save_file_as_ok(GTK_FILE_CHOOSER(file_selection_box));
        }
        gtk_widget_destroy(file_selection_box);
    }
}
Пример #17
0
void on_notebook_switch_page (GtkNotebook *notebook, GtkNotebookPage *page,
                              gint page_num, gpointer user_data)
{
    GtkWidget *child;
    child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(main_window.notebook_editor), page_num);
    if(!document_manager_set_current_document_from_widget (main_window.docmg, child)) {
        gphpedit_debug_message(DEBUG_MAIN_WINDOW,_("Unable to get data for page %d"), page_num);
    }
    if (!is_app_closing) {
        // Change the title of the main application window to the full filename
        update_app_title(document_manager_get_current_document(main_window.docmg));
        on_tab_change_update_classbrowser(main_window.notebook_editor);
    }
    check_externally_modified(document_manager_get_current_document(main_window.docmg));
}
Пример #18
0
void document_manager_save_all(DocumentManager *docmg)
{
  gphpedit_debug(DEBUG_DOC_MANAGER);
  if (!docmg) return ;
  DocumentManagerDetails *docmgdet = DOCUMENT_MANAGER_GET_PRIVATE(docmg);
  GSList *li;
  Document *doc;
  for(li = docmgdet->editors; li!= NULL; li = g_slist_next(li)) {
    doc = li->data;
    gboolean untitled;
    g_object_get(doc, "untitled", &untitled, NULL);
    if (untitled){
      gphpedit_debug_message(DEBUG_MAIN_WINDOW,"%s","Untitled found. Save not implemented"); //FIXME:
    } else {
      documentable_save(DOCUMENTABLE(doc));
    }
  }
}
Пример #19
0
void gtk_syntax_check_window_run_check(GtkSyntax_Check_Window *win, Document *document)
{
  g_return_if_fail(win);
  if (!document){
   syntax_window(win, document, _("You don't have any files open to check\n"));
   return;
  }
  gchar *res = syntax_check_manager_run(document);
  if (res){
     syntax_window(win, document, res);
     g_free(res);
  } else {
      /* try plugins */
      PluginManager *plugmg = plugin_manager_new ();
      if (!run_syntax_plugin_by_ftype(plugmg, document)){
      gphpedit_debug_message(DEBUG_SYNTAX, "syntax check not implement\n");
      }
    g_object_unref(plugmg);
  }
}
Пример #20
0
static void document_webkit_constructed (GObject *object)
{
  Document_WebkitDetails *docdet = DOCUMENT_WEBKIT_GET_PRIVATE(object);
  GString *caption = NULL;
  gchar *filename = documentable_get_filename(DOCUMENTABLE(object));
  if (docdet->type==TAB_HELP){
    caption = g_string_new(_("Help: "));
  } else {
    gchar *disp = filename_get_display_name(filename);
    caption = g_string_new(disp);
    g_free(disp);
    caption = g_string_prepend(caption, _("Preview: "));
  }
  g_object_set(object, "short_filename", caption->str,NULL);
  gtk_label_set_text(GTK_LABEL(docdet->label), caption->str);

  webkit_web_view_load_uri (WEBKIT_WEB_VIEW(docdet->help_view), filename);

  gphpedit_debug_message (DEBUG_DOCUMENT, "WEBKIT FILE: %s\n", caption->str);

  g_string_free(caption,TRUE);

}
Пример #21
0
void document_manager_open_selected(DocumentManager *docmg)
{
  gphpedit_debug(DEBUG_DOC_MANAGER);
  if (!docmg) return ;
  DocumentManagerDetails *docmgdet = DOCUMENT_MANAGER_GET_PRIVATE(docmg);
  GSList *li;
  Document *document;
  gchar *ac_buffer;
  gchar *file;

  ac_buffer = documentable_get_current_selected_text(DOCUMENTABLE(docmgdet->current_document));
  if (!ac_buffer){
    for(li = docmgdet->editors; li!= NULL; li = g_slist_next(li)) {
      document = li->data;
      if (document) {
         gchar *filename = documentable_get_filename(DOCUMENTABLE(document));
         file = filename_parent_uri(filename);
         g_free(filename);
         gphpedit_debug_message(DEBUG_MAIN_WINDOW,"file: %s", filename);
         if (!strstr(ac_buffer, "://") && file) {
          gchar *filetemp= g_strdup_printf("%s/%s",file, ac_buffer);
          g_free(file);
          file=g_strdup(filetemp);
          g_free(filetemp);
        }
        else if (strstr(ac_buffer, "://")) {
            if (file) g_free(file);
            file = g_strdup(ac_buffer);
        }
        if(filename_file_exist(file)) document_manager_switch_to_file_or_open(docmg, file,0);
        if (file) g_free(file);
      }
    }
  }
  g_free(ac_buffer);
}
Пример #22
0
static void autoindent_brace_code (GtkScintilla *sci, PreferencesManager *pref)
{
    gint current_pos;
    gint current_line;
    gint previous_line;
    gint previous_line_indentation;
    gint previous_line_start;
    gint previous_line_end;
    gchar *previous_char_buffer;
    gint previous_char_buffer_length;
    gchar *previous_line_buffer;
    gint previous_line_buffer_length;

    current_pos = gtk_scintilla_get_current_pos(sci);
    current_line = gtk_scintilla_line_from_position(sci, current_pos);

    gphpedit_debug (DEBUG_DOCUMENT);

    if (current_line>0) {
        gtk_scintilla_begin_undo_action(sci);
        previous_line = current_line-1;
        previous_line_indentation = gtk_scintilla_get_line_indentation(sci, previous_line);

        previous_line_end = gtk_scintilla_get_line_end_position(sci, previous_line);
        previous_char_buffer = gtk_scintilla_get_text_range (sci, previous_line_end-1, previous_line_end, &previous_char_buffer_length);
        if (is_css_char_autoindent(*previous_char_buffer)) {
            gint indentation_size;
            g_object_get(pref, "indentation_size", &indentation_size, NULL);
            previous_line_indentation+=indentation_size;
        } else if (is_css_char_autounindent(*previous_char_buffer)) {
            gint indentation_size;
            g_object_get(pref, "indentation_size", &indentation_size, NULL);
            previous_line_indentation-=indentation_size;
            if (previous_line_indentation < 0) previous_line_indentation = 0;
            previous_line_start = gtk_scintilla_position_from_line(sci, previous_line);
            previous_line_buffer = gtk_scintilla_get_text_range (sci, previous_line_start, previous_line_end, &previous_line_buffer_length);
            gboolean unindent = TRUE;
            gint char_act = 0;
            while (char_act <= previous_line_buffer_length)
            {
                char c = previous_line_buffer[char_act];
                if (!(g_ascii_iscntrl(c) || g_ascii_isspace(c) || is_css_char_autounindent(c))) {
                    unindent = FALSE;
                    break;
                }
                char_act++;
            }
            if (unindent) gtk_scintilla_set_line_indentation(sci, previous_line, previous_line_indentation);
            g_free(previous_line_buffer);
        }
        g_free(previous_char_buffer);
        indent_line(sci, current_line, previous_line_indentation);
        gphpedit_debug_message (DEBUG_DOCUMENT, "previous_line=%d, previous_indent=%d\n", previous_line, previous_line_indentation);
        gint pos;
        gboolean tabs_instead_spaces;
        g_object_get(pref,"tabs_instead_spaces", &tabs_instead_spaces, NULL);
        if(tabs_instead_spaces) {
            pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation/gtk_scintilla_get_tab_width(sci));
        } else {
            pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation);
        }
        gtk_scintilla_goto_pos(sci, pos);
        gtk_scintilla_end_undo_action(sci);
    }
}
Пример #23
0
void classbrowser_parse_file(Classbrowser_Backend *classback, gchar *filename)
{
  gchar *file_contents;
  gchar *o; // original pointer to start of contents
  gchar *c; // current position within contents
  #ifdef DEBUG  
    //debug var
    gchar *sss, *dss, *scs, *mcs, *hss;
  #endif  

  gboolean within_php;
  gboolean within_single_line_comment;
  gboolean within_multi_line_comment;
  gboolean within_heredoc;
  //gboolean within_nowdoc;
  gboolean within_single_string;
  gboolean within_double_string;
  guint brace_count;
  guint parenthesis_count;
  guint line_number;

  gchar *heredoc_tag_start;
  gchar *heredoc_closingtag;
  guint heredoctag_length = 0;
  gboolean looking_for_heredocident;

  gchar *within_class;
  guint class_length = 0;
  gboolean looking_for_class_name;
  gboolean within_class_name;
  gchar *start_class_name = NULL;
  gchar *within_function;
  guint function_length = 0;
  gboolean looking_for_function_name;
  gboolean within_function_name;
  gchar *start_function_name = NULL;
  gboolean within_function_param_list;
  gchar *start_param_list;
  gchar *param_list;
  guint param_list_length;
  gboolean function_awaiting_brace_or_parenthesis;

  gboolean posiblevar=FALSE;
  gchar *startvarname=NULL;
  gchar *posvarname=NULL;
  gchar *varname=NULL;
  gchar *beforevarname=NULL;

  within_php = FALSE;
  within_single_line_comment = FALSE;
  within_multi_line_comment = FALSE;
  within_single_string = FALSE;
  within_double_string = FALSE;
  within_heredoc = FALSE;
  looking_for_heredocident = FALSE;
  heredoc_closingtag = NULL;
  heredoc_tag_start = NULL;
  
  brace_count = 0;
  line_number = 1;
  within_class = NULL;
  looking_for_class_name = FALSE;
  within_class_name = FALSE;
  within_function = NULL;
  looking_for_function_name = FALSE;
  within_function_name = FALSE;
  within_function_param_list = FALSE;
  start_param_list = NULL;
  param_list = NULL;
  function_awaiting_brace_or_parenthesis = FALSE;

  g_return_if_fail(filename);
  file_contents = read_text_file(filename);
  g_return_if_fail(file_contents);
  o = file_contents;
  c = o;

  while (*c) {
    if (!within_php) {
      if (check_previous(o, c, "<?")) {
        within_php=TRUE;
      }
    } else {
      if (within_single_line_comment && is_newline(*c)) {
        #ifdef DEBUG
        str_sec_print("SLC", scs, c, line_number);
        #endif
        within_single_line_comment = FALSE;
      }
      else if (within_multi_line_comment && check_previous(o, c, "*/")) {
      #ifdef DEBUG
        str_sec_print("MLC", mcs, c, line_number);
      #endif
        within_multi_line_comment = FALSE;
      }
      //escaped single quote within single quoted string does not end the string 
      //single quote ends single quoted string
      if (within_single_string && *c=='\'' && !check_previous(o, c, "\\'")) {
      #ifdef DEBUG
        str_sec_print("SQS", sss, c, line_number);
      #endif
        within_single_string = FALSE;
      }
      //escaped double quote within double quoted string does not end the string 
      //double quote ends double quoted string
      else if (within_double_string && *c=='"' && !check_previous(o, c, "\\\"")) {
      #ifdef DEBUG
        str_sec_print("DQS", dss, c, line_number);
      #endif
        within_double_string = FALSE;
      }
      ///heredocs have custom closing tags. check it from the opening tag
      else if (within_heredoc && !looking_for_heredocident && *c=='\n' && (check_previous(o, c-1, heredoc_closingtag) || (*(c-1) == ';' && check_previous(o, c-2, heredoc_closingtag)))) {
      #ifdef DEBUG
        gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%s(%d): End Heredoc", filename, line_number);
        str_sec_print("HDS", hss, c, line_number);
      #endif
        g_free(heredoc_closingtag);
        within_heredoc = FALSE;
      }
      else if (within_heredoc && looking_for_heredocident && *c == '\n') {
        //if nowdoc
        if (*heredoc_tag_start == '\'') {
          //-2 for the two single quotes
          heredoctag_length = c - heredoc_tag_start - 2;           
          heredoc_closingtag = g_malloc(heredoctag_length + 1);
          strncpy(heredoc_closingtag, heredoc_tag_start + 1, heredoctag_length);
          heredoc_closingtag[heredoctag_length]='\0';
          #ifdef DEBUG
            gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE,"Expecting Nowdoc closing tag: %s\n", heredoc_closingtag);
          #endif
        }
        else {
          heredoctag_length = c - heredoc_tag_start;           
          heredoc_closingtag = g_malloc(heredoctag_length + 1);
          strncpy(heredoc_closingtag, heredoc_tag_start, heredoctag_length);
          heredoc_closingtag[heredoctag_length]='\0';
          #ifdef DEBUG
          gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "Expecting Heredoc closing tag: %s", heredoc_closingtag);
          #endif
        }
        looking_for_heredocident = FALSE;
      }
      //if not within comments or strings or heredocs
      else if (!within_multi_line_comment && !within_single_line_comment && !within_double_string && !within_single_string && !within_heredoc) {
        if (check_previous(o, c, "?>")) {
          within_php = FALSE;
        }
        //when does the second condition happen?
        //you are already outside a string. you can't have a backslash 
        //just before a new opening single quote
        else if (*c == '\'' && !check_previous(o, c, "\\'")) {
          within_single_string=TRUE;
          #ifdef DEBUG
          sss = c;
          gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE,"Found Single Quoted String: %d", line_number);
          #endif
        }
        //when does the second condition happen?
        else if (*c == '"' && !check_previous(o, c, "\\\"")) {
          within_double_string=TRUE;
          #ifdef DEBUG
          dss = c;
          gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "Found Double Quoted String: %d", line_number);
          #endif
        }
        //more efficient to call function only when needed hence the first check
        else if (*c == '<' && check_previous(o, c, "<<<")) {
          #ifdef DEBUG
          hss = c-2;
          gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%s(%d): Found Heredoc", filename, line_number);
          #endif
          within_heredoc=TRUE;
          heredoc_tag_start = c+1;
          looking_for_heredocident = TRUE;
        }
        //more efficient to call function only when needed hence the first check
        else if (*c == '/' && check_previous(o, c, "//")) {
          #ifdef DEBUG
          scs = c-1;
          gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%s(%d): Found Single Line Comment", filename, line_number);
          #endif
          within_single_line_comment = TRUE;
        }
        //more efficient to call function only when needed hence the first check
        else if (*c == '*' && check_previous(o, c, "/*")) {
          #ifdef DEBUG
          mcs = c-1;
          gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%s(%d): Found Multi Line Comment", filename, line_number);
          #endif
          within_multi_line_comment = TRUE;
        }
        else {
          if (check_previous(o, c, "class ") && non_letter_before(o, c, "class ")) {
            #ifdef DEBUG
            gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%s(%d): Found Class", filename, line_number);
            #endif
            looking_for_class_name = TRUE;
          }
          else if (is_identifier_char(*c) && looking_for_class_name && !within_class_name) {
            start_class_name = c-1;
            looking_for_class_name = FALSE;
            within_class_name = TRUE;
          }
          else if ( (is_whitespace(*c) || is_opening_brace(*c)) && within_class_name) {
            class_length = (c - start_class_name);
            if (within_class) {
              g_free(within_class);
            }
            within_class = g_malloc(class_length+1);
            strncpy(within_class, start_class_name, class_length);
            within_class[class_length]='\0';
            #ifdef DEBUG
              gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%s(%d): Class '%s'", filename, line_number, within_class);
            #endif
            classbrowser_classlist_add(classback, within_class, filename, line_number,TAB_PHP);
            within_class_name = FALSE;
          }
          else if (check_previous(o, c, "function ") && non_letter_before(o, c, "function ")) {
            #ifdef DEBUG
              gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE,"%s","Looking for function name");
            #endif
            looking_for_function_name = TRUE;
          }
          if (is_identifier_char(*c) && looking_for_function_name && !within_function_name) {
            #ifdef DEBUG
              gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE,"%s", "Storing function name");
            #endif
            start_function_name = c;
            function_length = 0;
            looking_for_function_name = FALSE;
            within_function_name = TRUE;
          }
          if ( (is_whitespace(*c) || is_opening_brace(*c) || is_opening_parenthesis(*c)) && within_function_name && function_length==0) {
            #ifdef DEBUG
              gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE,"%s", "Found function");
            #endif
            function_length = (c - start_function_name);
            if (within_function) {
              g_free(within_function);
            }
            within_function = g_malloc(function_length+1);
            strncpy(within_function, start_function_name, function_length);
            within_function[function_length]='\0';
            function_awaiting_brace_or_parenthesis = TRUE;
            within_function_name = FALSE;
          }

          if ( function_awaiting_brace_or_parenthesis && is_opening_brace(*c)) {
            function_awaiting_brace_or_parenthesis = FALSE;
            if (within_class) {
              classbrowser_functionlist_add(classback,within_class, within_function, filename, TAB_PHP, line_number, NULL);
              #ifdef DEBUG
                gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%s(%d): Class method %s::%s", filename, line_number, within_class, within_function);
              #endif
            }
            else {
              classbrowser_functionlist_add(classback,NULL, within_function, filename, TAB_PHP, line_number, NULL);
              #ifdef DEBUG
                gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%s(%d): Function %s", filename, line_number, within_function);
              #endif
            }
          }
          else if (function_awaiting_brace_or_parenthesis && is_opening_parenthesis(*c)) {
            within_function_param_list = TRUE;
            start_param_list = c+1;
            function_awaiting_brace_or_parenthesis = FALSE;
          }
          else if (is_closing_parenthesis(*c) && within_function_param_list) {
            param_list_length = (c - start_param_list);
            if (param_list) {
              g_free(param_list);
            }
            param_list = g_malloc(param_list_length+1);
            strncpy(param_list, start_param_list, param_list_length);
            param_list[param_list_length]='\0';
            if (within_class) {
              classbrowser_functionlist_add(classback, within_class, within_function, filename, TAB_PHP, line_number, param_list);
              #ifdef DEBUG
                gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%s(%d): Class method %s::%s(%s)", filename, line_number, within_class, within_function, param_list);
              #endif
            }
            else {
              classbrowser_functionlist_add(classback, NULL, within_function, filename, TAB_PHP,line_number, param_list);
              #ifdef DEBUG
                gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "%s(%d): Function %s(%s)", filename, line_number, within_function, param_list);
              #endif
            }
            within_function_param_list = FALSE;
          }
          if (posiblevar){
            if (is_identifier_char(*c)){
              posvarname=c;
            } else {
              //g_print("char:%c ret:false\n",*c);
              posiblevar=FALSE;
            int len=posvarname - startvarname +1; /*include initial $*/
              if (len>1){ /*only if we have $ and something more */
                varname = g_malloc(len +1);
                strncpy(varname,startvarname,len);
                varname[len]='\0';
                if (!beforevarname){ beforevarname=g_strdup(varname); /*store last variable name found*/
                } else {
                  if (strcmp(beforevarname,varname)==0){
                    #ifdef DEBUG
                    gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "Duplicate variable: %s",varname);
                    #endif
                  } else {
                    #ifdef DEBUG
                    gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "Classbrowser var added:%s",varname);
                    #endif
                    classbrowser_varlist_add(classback, varname, within_function, filename);
                    g_free(beforevarname);
                    beforevarname=g_strdup(varname);
                  }
                }
                g_free(varname);
              }
            }
          }
          if (*c=='$' && !within_function_param_list && !within_multi_line_comment && !within_single_line_comment){ /* skip params vars */
            posiblevar=TRUE;
            startvarname=c;
          }
          if (is_opening_brace(*c)) {
            brace_count++;
            #ifdef DEBUG
              gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE,"Brace count %d:%c", brace_count, *c);
            #endif
          }
          else if (is_closing_brace(*c)) {
            brace_count--;
            #ifdef DEBUG
              gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE,"Brace count %d:%c", brace_count, *c);
            #endif
            if (brace_count == 0) {
              if (within_class) {
                #ifdef DEBUG
                  gphpedit_debug_message(DEBUG_CLASSBROWSER_PARSE, "Freeing class %s", within_class);
                #endif
                g_free(within_class);
                within_class = NULL;
              }
            }
          }
          else if (is_opening_parenthesis(*c)) {
            parenthesis_count++;
          }
          else if (is_closing_parenthesis(*c)) {
            parenthesis_count--;
          }
        }
      }
    }
    if (is_newline(*c)) {
      line_number++;
    }
    c++;
  }
  if (param_list) g_free(param_list);
  if (within_function) g_free(within_function);
  if (beforevarname) g_free(beforevarname);
  g_free(file_contents);
}