#!/usr/local/bin/pike //Pike CGI script for Pike-GTK2 documentation //Written Chris Angelico 2011 //Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. //see http://creativecommons.org/licenses/by-nc-sa/3.0/ Sql.Sql m=Sql.Sql("mysql://pike-gtk2:shoulders@localhost/pike-gtk2"); int main(int argc,array(string) argv) { string path=getenv("PATH_INFO"); if (!path) {write("Location: pike-gtk2/\n\n"); return 0;} string footer=#"

These pages copyright Chris Angelico, 2011. Licensed under the LGPL, the GPL v2.0, and the MPL v1.1. Page rendering by a Pike CGI script, licensed under CC-BY-NC-SA, source available here.

"; //Standard footer at the bottom of every page. if (path=="/") { write("Content-type: text/html; charset=UTF-8\n\n"); write(#" Pike GTK2 documentation

Pike GTK2 documentation

The Pike language and the GTK+ libraries are both excellent, and work well together; unfortunately, the documentation is somewhat sparse. The options are (1) use the Pike-provided docs which are skeletal at best, or (2) use the GTK docs, which relate to the original C API, and thus do not accurately reflect the Pike bindings.

This project aims to fill the gap, making it possible to write Pike programs using GTK interfaces, without needing to first know GTK under C (for the simple reason that I, currently, don't). It's not difficult to write a Pike GTK2 program, but it would be great to have some reliable reference material!

Much content has been copied from the official Pike documentation, which is licensed under the GPL, LGPL, and MPL.

Please note: This is a work in progress. The project started 2011-01-24 in response to a personal need, and though I intend for it ultimately to be of value to a new programmer, I cannot promise any sort of time-frame! Keep the official documentation handy as you read this.

How to read this manual; handy cheatsheet

Handy classes: %s

All pages, for spiders.

"+footer,fmt("GTK2.CheckButton, GTK2.ComboBox, GTK2.Label, GTK2.Frame, GTK2.Entry, GTK2.Button, GTK2.TreeView, GTK2.TextView, GTK2.Notebook, GTK2.RadioButton, GTK2.SpinButton, GTK2.Window")); return 0; } if (path=="/pike-gtk2.pike") { //Quine yourself. :) Easiest way to comply with the LGPL requirement to distribute source. write("Content-type: text/plain; charset=UTF-8\n\n%s",Stdio.File(getenv("SCRIPT_FILENAME"))->read()); return 0; } if (path=="/~allpages~") { write("Content-type: text/html; charset=UTF-8\n\n"); write(#" Pike GTK2 documentation

Home

All pages

This is not designed to be useful to a human, it's just a straight link dump so that every page is crawlable.

\n"+footer); return 0; } if (sscanf(path,"/%s/%s",string cls,string attr)) { array data=m->big_query("select class,name,description from attributes where class=%s and name=%s",cls,attr)->fetch_row(); if (!data) {write("Status: 404 Not Found\nContent-type: text/plain\n\nClass attribute not found: "+path[1..]+"\n"); return 0;} if (data[0]!=cls || data[1]!=attr) {write("Location: "+data[0]+"/"+data[1]+"\n\n"); return 0;} //Will happen if there's a case discrepancy write("Content-type: text/html; charset=UTF-8\n\n"); write(#" Pike GTK2 documentation

Home

GTK2.%s->%s

%s

"+footer,data[0],data[1][0]=='$'?data[1][1..]+" (signal)":data[1],fmt(data[2])); } else { array data=m->big_query("select name,inherits,description from classes where name=%s",path[1..])->fetch_row(); if (!data) {write("Status: 404 Not Found\nContent-type: text/plain\n\nClass not found: "+path[1..]+"\n"); return 0;} if (data[0]!=path[1..]) {write("Location: "+data[0]+"\n\n"); return 0;} //Will happen if there's a case discrepancy write("Content-type: text/html; charset=UTF-8\n\n"); write(#" Pike GTK2 documentation

Home

GTK2.%s

%s

", data[0], fmt((data[1]==""?"":sprintf("%{Inherits: GTK2.%s\n%}\n",data[1]/" "))+data[2]) ); multiset inherits=(); gatherinherits(data[1],inherits); array qq=m->query("select class,name from attributes where class in ('"+indices(inherits)*"','"+"') order by name"); if (sizeof(qq)) { write(""); } write(footer); } return 0; } string fmt(string in) { in=replace(replace(Parser.encode_html_entities(in),({" "," "," "}),({" ","\n","\n"})),({"\n\n","\n"}),({"

","
"})); //Translate "GTK2.ClassName" into a link string tmp=""; while (sscanf(in,"%sGTK2.%[A-Za-z0-9_./$]%s",string txt,string tag,in)) { if (in[..1]=="()") {tag+="()"; in=in[2..];} tmp+=txt+"GTK2."+tag+""; } in=tmp+in; return in; } //Parse a space-delimited list of inheritances, and follow the tree up to find every parent void gatherinherits(string lookfor,multiset inherits) { foreach (lookfor/" ",string c) if (c!="" && !inherits[c]) { inherits[c]=1; catch {gatherinherits(m->query("select inherits from classes where name=%s",c)[0]->inherits,inherits);}; } }