var is_ext = {arg u; u.filenameSymbol.asString.find("Extension") != nil};

var is_loc = {arg u; is_ext.(u).not};

var all_subclasses_of = {
    arg o;
    var u = o.subclasses;
    if(u.size == 0, {[]}, {u ++ u.collect({arg e; all_subclasses_of.(e)}).flatten});
};

var uu = all_subclasses_of.(UGen).sort({arg a, b; a.name < b.name});

var uu_ext = uu.removeAllSuchThat(is_ext);

var uu_loc = uu.removeAllSuchThat(is_loc);

var cat_pre =
    [Date.getDate.format("-- AUTOGENERATED: %Y-%m-%dT%H:%M"),
    "module Sound.SC3.UGen.DB.Cat where","",
    "sc3_ugen_cat :: [(String,String)]","sc3_ugen_cat =","    ["].join("\n");

var cat_post = "    ]";

var cat_ugen_pp = {
    arg u;
    ["(\"",u.name.asString,"\",\"",SCDoc.documents["Classes/" ++ u.name].categories.join(","),"\")"].join;
};

var gen_cat = {arg c; cat_pre ++ c.collect(cat_ugen_pp).join("\n    ,") ++ "\n" ++ cat_post};

var loc_cat_fn = "/home/rohan/sw/hsc3-db/Sound/SC3/UGen/DB/Cat.hs";

var ext_cat_fn = "/home/rohan/sw/hsc3-db/Sound/SC3/UGen/DB/External/Cat.hs";

File.use(loc_cat_fn, "w", { |fd| fd.write(gen_cat.(uu_loc))});
File.use(ext_cat_fn, "w", { |fd| fd.write(gen_cat.(uu_ext))});

0.exit;