-module(make_index). % 2000-06-26 kent Changed to generate the file "index.inc" instead of % "index.ehtml" because the file generated is to be included % into another HTML file with header and footer etc. % ????-??-?? ?? The function date_string/1 was added and the output format % extended to contain the date. % ????-??-?? ?? Uses gunzip intead of zcat for uncompressing the TAR archvie. -include_lib("kernel/include/file.hrl"). -import(lists, [map/2, reverse/1, sort/1, zf/2]). -export([all/0, date_string/1]). all() -> Files = find:files(".", "*.tgz", false), Files1 = map(fun([$.,$/|T]) -> T end, Files), Info = sort(zf(fun(F) -> read_pub(F) end, Files1)), Summaries = map(fun({_, Tag,Facts,Mdate}) -> Summary = get_fact(summary, Facts), ["", "", Tag, "", "", "",Mdate,"", "", quote(Summary), "", "\n"] end, Info), Desc = map(fun({Name,Tag,Facts,Mdate}) -> Abstract = get_fact(abstract, Facts), Authors = get_authors(Facts), ["", "
",Name,"", " - ",Authors,"", "
",quote(Abstract),"

"] end, Info), Table = ["", "", "", "", "", "", Summaries, "
", "Application", "", "Date modified", "", "Summary", "
"], file:write_file("index.inc", ["\n", "One Line Summaries\n", "

\n", "The Programs\n", "
\n", Desc, "
\n"]), file:set_cwd(".."), ehtml:file("user"), file:set_cwd("contrib"). quote(Str) -> Entity = fun($&) -> "&"; ($<) -> "<"; ($>) -> ">"; (C) -> C end, lists:map(Entity,Str). get_fact(Key, [{Key,Val}|_]) -> Val; get_fact(Key, []) -> ""; get_fact(Key, [_|T]) -> get_fact(Key, T). get_authors([{author, Name, Email,_}]) -> Name ++ "."; get_authors([{author, Name, Email,_}|T]) -> Name ++ ", " ++ get_authors(T); get_authors([_|T]) -> get_authors(T); get_authors([]) -> []. %% read_pub("assoc-1.2.tgz"). %% give the command %% gunzip < assoc-1.2.tgz | tar xvf - assoc-1.2/assoc.pub read_pub(Name) -> BaseName = filename:basename(filename:rootname(Name)), case split_name(BaseName) of {ok, App, Maj, Min} -> File = BaseName ++ "/" ++ App ++ ".pub", Cmd = "gunzip < " ++ Name ++ " | tar xf - " ++ File, io:format("Cmd:~s~n", [Cmd]), os:cmd(Cmd), Ret = case file:consult(File) of {ok, V} -> case file:read_file_info(Name) of {ok, FI} -> Date = date_string(FI#file_info.mtime), {true, {Name, BaseName, V, Date}}; _ -> io:format("** error file_info:~s~n", [File]), false end; _ -> io:format("** error consulting:~s~n", [File]), false end, os:cmd("rm -rf " ++ BaseName), Ret; _ -> io:format("*** Bad name ~s~n", [BaseName]), false end. date_string({{Yr,Mn,Dy},{Hr,Min,Sec}}) -> io_lib:format("~s ~2w, ~w~s", [fun (1) -> "Jan"; (2) -> "Feb"; (3) -> "Mar"; (4) -> "Apr"; (5) -> "May"; (6) -> "Jun"; (7) -> "Jul"; (8) -> "Aug"; (9) -> "Sep"; (10) -> "Oct"; (11) -> "Nov"; (12) -> "Dec" end (Mn), Dy, Yr, new_date({{Yr,Mn,Dy},{Hr,Min,Sec}})]). new_date(Date) -> new_date(Date, calendar:local_time()). new_date({{Yr0,Mn0,Dy0},_}, {{Yr1,Mn1,Dy1},_}) -> Days = calendar:date_to_gregorian_days(Yr1, Mn1, Dy1) - calendar:date_to_gregorian_days(Yr0, Mn0, Dy0), if Days < 60 -> " \"NEW!\""; true -> "" end; new_date(Then, Now) -> "". split_name(Name) -> case (catch begin {App, T1} = get_app(Name, []), {Maj, Min} = get_ints(T1, []), I1 = list_to_integer(Maj), I2 = list_to_integer(Min), {ok, App, I1, I2} end) of {'EXIT', _} -> error; Other -> Other end. get_app([$-|T], L) -> {reverse(L), T}; get_app([H|T], L) -> get_app(T, [H|L]); get_app([], L) -> exit(bad_name). get_ints([$.|T], L) -> {reverse(L), T}; get_ints([H|T], L) -> get_ints(T, [H|L]); get_ints([], L) -> exit(bad_ints). %% go() -> %% R = "/home/super/www/lab/cslab/projects/erlang/earchive", %% F = find:files(R, "*.idx", false), %% lists:foreach(fun(I) -> %% B = filename:basename(filename:rootname(I)), %% {ok, C} = file:read_file(I), %% V = binary_to_term(C), %% [A] = [X || {author,X} <- V], %% [E] = [X || {email,X} <- V], %% V1 = [{A,E,"981127"}|trim(V)], %% io:format("~p~n~p~n",[B,V1]), %% {ok,S} = file:open(B ++ ".pub", write), %% io:format(S, "~p.~n",[V1]), %% file:close(S) %% end, F). %% %% trim([{doc,_}|T]) -> trim(T); %% trim([{files,_}|T]) -> trim(T); %% trim([{author,_}|T]) -> trim(T); %% trim([{email,_}|T]) -> trim(T); %% trim([H|T]) -> [H|trim(T)]; %% trim([]) -> [].