Browse files

customizable initfile

  • Loading branch information...
1 parent 9b22757 commit 87ffabb03507963dd4312373d5d791310e37249b yoshihiro503 committed May 15, 2011
Showing with 15 additions and 8 deletions.
  1. +5 −0 .ocamlinit
  2. +6 −1 ocamltter
  3. +3 −6 ocamltter.ml
  4. +1 −1 ocamltter.mli
View
5 .ocamlinit
@@ -11,5 +11,10 @@ let print_tweet p (tw:TwitterApi.tweet) =
#install_printer print_string_literal;;
#install_printer print_tweet;;
+config_file :=
+ match maybe Sys.getenv "HOME" with
+ | Inl home -> home ^ "/.ocamltter"
+ | Inr e -> ".ocamltter";;
+
setup();;
start_polling ();;
View
7 ocamltter
@@ -3,6 +3,11 @@ prevdir=`pwd`
ocamltterhome=`dirname $0`
cd $ocamltterhome
incl='-I +cryptokit -I +site-lib/cryptokit -I +threads -I base -I twitter'
+if [ $# -ne 1 ]; then
+ initfile='.ocamlinit'
+else
+ initfile=$1
+fi
ocamlc -c ${incl} \
base/util.mli base/base64.mli base/utf16.mli base/llist.mli \
base/parserMonad.mli base/json.mli base/xml.mli \
@@ -15,6 +20,6 @@ ocamlmktop -o ocamltter_top ${incl} \
base/parserMonad.ml base/json.ml base/xml.ml base/http.ml base/oauth.ml \
twitter/oauthForTwitter.ml twitter/twitterApi.ml \
config.ml ocamltter.ml
-./ocamltter_top ${incl}
+./ocamltter_top ${incl} -init $initfile
rm -f *.cm[io] base/*.cm[io] twitter/*.cm[io] ocamltter_top
cd $prevdir
View
9 ocamltter.ml
@@ -5,10 +5,7 @@ open Http
module Tw = TwitterApi
let oauth_acc : (string * string * string) option ref = ref None
-let conffile =
- match maybe Sys.getenv "HOME" with
- | Inl home -> home ^ "/.ocamltter"
- | Inr e -> ".ocamltter"
+let config_file = ref "Assign a conf filename."
let authorize () =
let url, req_tok, req_sec = Tw.fetch_request_token () in
@@ -21,7 +18,7 @@ let authorize () =
in
oauth_acc := Some (acc_tok, acc_sec, verif);
print_endline ("Grant Success! Hello, @"^username^" !");
- open_out_with conffile (fun ch ->
+ open_out_with !config_file (fun ch ->
output_string ch (acc_tok^"\n"^acc_sec^"\n"^verif^"\n"));
(acc_tok, acc_sec, verif)
@@ -41,7 +38,7 @@ module Cache = struct
Queue.push tw cache
end
-let load () = open_in_with conffile (fun ch ->
+let load () = open_in_with !config_file (fun ch ->
let tok = input_line ch in let sec=input_line ch in let verif=input_line ch in
let acc=(tok,sec,verif) in
oauth_acc := Some acc; acc)
View
2 ocamltter.mli
@@ -1,6 +1,6 @@
val oauth_acc : (string * string * string) option ref
-val conffile : string
+val config_file : string ref
val authorize : unit -> string * string * string
module Cache :
sig

0 comments on commit 87ffabb

Please sign in to comment.