#!./ginsbasic001ok
include "wxbasicscript/basefunctions.inc"

//gtkdocdir = "/mnt/sda7/gtk/gtk/share/gtk-doc/html/"
gtkdocdir = "/mnt/home/gtk/gtk/share/gtk-doc/html/"

workingfiles = {
"gtk/gtk-General.html",
"gtk/gtk-Keyboard-Accelerators.html",
"gtk/gtk-Accelerator-Maps.html",
"gtk/gtk-Clipboards.html",
"gtk/gtk-Drag-and-Drop.html",
"gtk/GtkIconTheme.html",
"gtk-Stock-Items.html",
"gtk/gtk-Themeable-Stock-Images.html",
"gtk/gtk-Resource-Files.html",
"gtk/GtkSettings.html",
"gtk/gtk-Bindings.html",
"gtk/gtk-Standard-Enumerations.html",
"gtk/gtk-Graphics-Contexts.html",
"gtk/GtkStyle.html",
"gtk/gtk-Selections.html",
"gtk/gtk-Feature-Test-Macros.html",
"gtk/gtk-Signals.html",
"--gtk/gtk-Types.html", //deprecheated and throws error
"gtk/GtkDialog.html",
"gtk/GtkInvisible.html",
"gtk/GtkMessageDialog.html",
"gtk/GtkWindow.html",
"gtk/GtkWindowGroup.html",
"gtk/GtkAboutDialog.html",
"gtk/GtkAssistant.html",
"gtk/GtkAccelLabel.html",
"gtk/GtkImage.html",
"gtk/GtkLabel.html",
"gtk/GtkProgressBar.html",
"gtk/GtkStatusbar.html",
"gtk/GtkStatusIcon.html",
"gtk/GtkButton.html",
"gtk/GtkCheckButton.html",
"gtk/GtkRadioButton.html",
"gtk/GtkToggleButton.html",
"gtk/GtkLinkButton.html",
"gtk/GtkEntry.html",
"gtk/GtkEntryCompletion.html",
"gtk/GtkHScale.html",
"gtk/GtkVScale.html",
"gtk/GtkSpinButton.html",
"gtk/GtkEditable.html",
"gtk/gtk-GtkTextIter.html",
"gtk/GtkTextMark.html",
"gtk/GtkTextBuffer.html",
"gtk/GtkTextTag.html",
"gtk/GtkTextTagTable.html",
"gtk/GtkTextView.html",
"gtk/GtkTreeModel.html",
"gtk/GtkTreeSelection.html",
"gtk/GtkTreeViewColumn.html",
"gtk/GtkTreeView.html",
"gtk-GtkTreeView-drag-and-drop.html",
"gtk/GtkCellView.html",
"gtk/GtkIconView.html",
"gtk/GtkTreeSortable.html",
"gtk/GtkTreeModelSort.html",
"gtk/GtkTreeModelFilter.html",
"gtk/GtkCellLayout.html",
"gtk/GtkCellRenderer.html",
"gtk/GtkCellEditable.html",
"gtk/GtkCellRendererAccel.html",
"gtk/GtkCellRendererCombo.html",
"gtk/GtkCellRendererPixbuf.html",
"gtk/GtkCellRendererProgress.html",
"gtk/GtkCellRendererSpin.html",
"gtk/GtkCellRendererText.html",
"gtk/GtkCellRendererToggle.html",
"gtk/GtkListStore.html",
"gtk/GtkTreeStore.html",
"gtk/GtkComboBox.html",
"gtk/GtkComboBoxEntry.html",
"gtk/GtkMenu.html",
"gtk/GtkMenuBar.html",
"gtk/GtkMenuItem.html",
"gtk/GtkMenuShell.html",
"gtk/GtkImageMenuItem.html",
"gtk/GtkRadioMenuItem.html",
"gtk/GtkCheckMenuItem.html",
"gtk/GtkSeparatorMenuItem.html",
"gtk/GtkTearoffMenuItem.html",
"gtk/GtkToolbar.html",
"gtk/GtkToolItem.html",
"gtk/GtkSeparatorToolItem.html",
"gtk/GtkToolButton.html",
"gtk/GtkMenuToolButton.html",
"gtk/GtkToggleToolButton.html",
"gtk/GtkRadioToolButton.html",
"gtk/GtkUIManager.html",
"gtk/GtkActionGroup.html",
"gtk/GtkAction.html",
"gtk/GtkToggleAction.html",
"gtk/GtkRadioAction.html",
"gtk/GtkColorButton.html",
"gtk/GtkColorSelection.html",
"gtk/GtkColorSelectionDialog.html",
"gtk/GtkFileSelection.html",
"gtk/GtkFileChooser.html",
"gtk/GtkFileChooserButton.html",
"gtk/GtkFileChooserDialog.html",
"gtk/GtkFileChooserWidget.html",
"gtk/gtk-gtkfilefilter.html",
"gtk/GtkFontButton.html",
"gtk/GtkFontSelection.html",
"gtk/GtkFontSelectionDialog.html",
"gtk/GtkInputDialog.html",
"gtk/GtkAlignment.html",
"gtk/GtkAspectFrame.html",
"gtk/GtkHBox.html",
"gtk/GtkVBox.html",
"gtk/GtkHButtonBox.html",
"gtk/GtkVButtonBox.html",
"gtk/GtkFixed.html",
"gtk/GtkHPaned.html",
"gtk/GtkVPaned.html",
"gtk/GtkLayout.html",
"gtk/GtkNotebook.html",
"gtk/GtkTable.html",
"gtk/GtkExpander.html",
"gtk/GtkFrame.html",
"gtk/GtkHSeparator.html",
"gtk/GtkVSeparator.html",
"gtk/GtkHScrollbar.html",
"gtk/GtkVScrollbar.html",
"gtk/GtkScrolledWindow.html",
"gtk/gtk-High-level-Printing-API.html",
"gtk/GtkPrintContext.html",
"gtk/GtkPrintSettings.html",
"gtk/GtkPageSetup.html",
"gtk/gtk-GtkPaperSize.html",
"gtk/GtkPrinter.html",
"gtk/GtkPrintJob.html",
"gtk/GtkPrintUnixDialog.html",
"gtk/GtkPageSetupUnixDialog.html",
"gtk/GtkAdjustment.html",
"gtk/GtkArrow.html",
"gtk/GtkCalendar.html",
"gtk/GtkDrawingArea.html",
"gtk/GtkEventBox.html",
"gtk/GtkHandleBox.html",
"gtk/GtkIMContextSimple.html",
"gtk/GtkIMMulticontext.html",
"gtk/GtkSizeGroup.html",
"gtk/GtkTooltips.html",
"gtk/GtkViewport.html",
"gtk/GtkAccessible.html",
"gtk/GtkBin.html",
"gtk/GtkBox.html",
"gtk/GtkButtonBox.html",
"gtk/GtkContainer.html",
"gtk/GtkItem.html",
"gtk/GtkMisc.html",
"gtk/GtkObject.html",
"gtk/GtkPaned.html",
"gtk/GtkRange.html",
"gtk/GtkScale.html",
"gtk/GtkScrollbar.html",
"gtk/GtkSeparator.html",
"gtk/GtkWidget.html",
"gtk/GtkIMContext.html",
"gtk/GtkCList.html",
"gtk/GtkPixmap.html",
"gtk/GtkPlug.html",
"gtk/GtkSocket.html",
"gtk/GtkCurve.html",
"gtk/GtkGammaCurve.html",
"gtk/GtkRuler.html",
"gtk/GtkHRuler.html",
"gtk/GtkVRuler.html",
"gtk/GtkRecentManager.html",
"gtk/GtkRecentChooser.html",
"gtk/GtkRecentChooserDialog.html",
"gtk/GtkRecentChooserMenu.html",
"gtk/GtkRecentChooserWidget.html",
"gtk/GtkRecentFilter.html",
"gdk/gdk-General.html",
"gdk/GdkDisplay.html",
"gdk/GdkDisplayManager.html",
"gdk/GdkScreen.html",
"gdk/gdk-Graphics-Contexts.html",
"gdk/gdk-Drawing-Primitives.html",
"gdk/gdk-Bitmaps-and-Pixmaps.html",
"gdk/gdk-GdkRGB.html",
"gdk/gdk-Images.html",
"gdk/gdk-Pixbufs.html",
"gdk/gdk-Colormaps-and-Colors.html",
"gdk/gdk-Visuals.html",
"gdk/gdk-Fonts.html",
"gdk/gdk-Cursors.html",
"gdk/gdk-Windows.html",
"gdk/gdk-Events.html",
"gdk/gdk-Event-Structures.html",
"gdk/gdk-Keyboard-Handling.html",
"gdk/gdk-Selections.html",
"gdk/gdk-Drag-and-Drop.html",
"gdk/gdk-Properties-and-Atoms.html",
"gdk/gdk-Points-Rectangles-and-Regions.html",
"gdk/gdk-Input-Devices.html",
"gdk/gdk-Threads.html",
"gdk/gdk-Input.html",
"gdk/gdk-Input-Devices.html",
"gdk/gdk-Pango-Interaction.html",
"--gdk/gdk-Cairo-Interaction.html", //requires cairo, maybe later. Not so important
"gdk/gdk-X-Window-System-Interaction.html"
}

//-IMPORTANT: if you add new functions, you might have to add values
// in _createfunctions.pb after the line: 
    //-- some types for first arg must be removed from type(obj) to only (obj)-
// Do that, if you get such errors during compilation:
// main.c:(.text+0x70390): undefined reference to `GDK_FONT'


//-- these function do not work yet

droppedfunctions = {
"gtk_link_button_set_uri_hook",
"*GtkNotebookWindowCreationFunc",
"gtk_file_filter_get_needed",	//typedef struct _GtkFileFilter GtkFileFilter;
"gdk_window_invalidate_maybe_recurse",
"gtk_print_operation_get_error", // gerror **
"gtk_print_context_set_cairo_context",  // cairo
"gtk_curve_get_vector", //gfloat vector[]); - is that an array? no idea.
"gtk_curve_set_vector"  //gfloat vector[]);
}


//-- here you can add junk that appears in gtkfunctions.txt

mydroppedleft = {
"#define",
"href",
"void gdk_window_invalidate_maybe_recurse"
}


writestringtofile("gtkfunctions.txt" , "")

//are these really enums? Must check later...
writestringtofile("gins-enums.txt" , "PangoRenderPart")
appendstringtofile("gins-enums.txt" , "PangoEllipsizeMode")
appendstringtofile("gins-enums.txt" , "PangoWrapMode")


functionlist = {}
fc = 0
for each thefile in workingfiles

thefile = gtkdocdir & thefile
print "----------------------------------" & thefile

html = {}
html = readfiletolist(thefile)

print count(html)
c=0
done = 0
//for each theline in html

for l=0 to count(html)-1
theline = html[l]

	if instr(theline , "</a>enum") then
		enum = cutleft(theline , "</a>")
		enum = cutleft(enum , " ")
		enum = cutright(enum , "<")
		appendstringtofile("gins-enums.txt" , enum)

	end if
	if instr(theline , "</a>union") then
		enum = cutleft(theline , "</a>")
		enum = cutleft(enum , " ")
		enum = cutright(enum , "<")
		appendstringtofile("gins-enums.txt" , enum)

	end if


  if instr(theline , "<pre") then
    start = 1
  end if

  if done = 0 then
  if start = 1 then
  if left(theline , 1) != " " then

//if instr(theline , "gtk_text_view_get_buffer") then print "    ---" & theline

  for n = 1 to 20
    nextline = html[c+n]
    if left(nextline , 1) = " " or left(nextline , 4)="href" or left(nextline , 1) = ">" then
      nextline = trim(nextline)
      theline &= nextline
    else
      'n=21
      break
    end if
  next
  newline = removehtml( theline )
  //if instr(newline , "gtk_text_view_get_buffer") then print "    -----" & newline
  newline = replace (newline , " * " , "* ")
  'print newline



  check = trim(newline)
  check = replace(check , "*" , "")
  check = cutrightfromleft(check , " ")



  //if instr(newline , "gtk_text_view_get_buffer") then print "    -------" & newline

    while instr(newline , "  ")
      newline = replace(newline , "  " , " ")
    wend

    // remove functions that are pointers
    acheck = cutleft(newline , check)
    if left(acheck , 1) != "(" then

	if instr(newline , "(") then
	if instr(newline , ")") then


		lfunc = cutright(newline , "(")
		lfunc = trim(lfunc)
		lfunc = cutleftfromright(lfunc , " ")
		useit = 1

		for n = 1 to count (droppedfunctions) 
			if droppedfunctions[n] = lfunc then
				useit = 0
			end if
		next

		for n = 1 to count(mydroppedleft) 

			dl=mydroppedleft[n]
			lend = len(dl)
			if left(newline , lend) = dl then
				useit = 0
			end if

		next
// e.g. this does not work: void ( *GtkLinkButtonUriFunc ) 
		if instr( newline , "( *") then
			useit = 0
		end if

		if useit = 1 then
			print "ok: " & newline
			'appendstringtofile("gtkfunctions.txt" , newline)
			functionlist[fc] = newline
			fc += 1
		else
			print "no: " & newline
		end if
	end if
	end if
    end if

  end if
  end if
  end if

  if instr(theline , "</pre>") then
    start = 0
    done = 1
  end if
  c+=1
next

next

writelisttofile("gtkfunctions.txt" , functionlist)
functionslist = {}

enums = readfiletolist("gins-enums.txt")
natsort(enums)
newenums = reducelist(enums)
writelisttofile("gins-enums.txt" , newenums)

