00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <time.h>
00030 #include <errno.h>
00031 #include <string.h>
00032 #include <unistd.h>
00033 #include <inttypes.h>
00034
00035 #include <getopt.h>
00036
00037 #include <sys/types.h>
00038 #include <sys/param.h>
00039 #include <sys/time.h>
00040
00041 #include <assert.h>
00042
00043
00045
00046
00047 #include <slw_console.h>
00048 #include <slw_text.h>
00049
00050
00051 #include <tbt.h>
00052
00053 #include <jutils.h>
00054 void set_status(SLangWidget *s);
00055
00056 static const char *help =
00057 "Usage: rectext [options] [file]\n"
00058 "\n"
00059 " -h print this help\n"
00060 " -v version information\n"
00061 " -D debug verbosity level - default 1\n"
00062 " -t include plain text in the mail\n";
00063
00064 static const char *short_options = "-hvD:r:";
00065
00066 int debug;
00067 char filename[512];
00068 bool plaintext = false;
00069
00070 void cmdline(int argc, char **argv) {
00071 int res;
00072
00073 debug = 1;
00074 filename[0] = 0x0;
00075
00076 fprintf(stderr, "TBT - Time Based Text - recorder\n");
00077 fprintf(stderr, " %s\n", VERSION);
00078
00079 do {
00080 res = getopt(argc, argv, short_options);
00081 switch(res) {
00082 case 'h':
00083 fprintf(stderr, "%s", help);
00084 exit(0);
00085 break;
00086
00087 case 'v':
00088 fprintf(stderr,"\n");
00089 exit(0);
00090 break;
00091
00092 case 'D':
00093 debug = atoi(optarg);
00094 if(debug>3) {
00095 warning("debug verbosity ranges from 1 to 3\n");
00096 debug = 3;
00097 }
00098 break;
00099
00100 case 't':
00101 plaintext = true;
00102 break;
00103
00104
00105 case 1:
00106 {
00107 FILE *fd;
00108 snprintf(filename,511,"%s", optarg);
00109 fd = fopen(filename, "r+");
00110 if(!fd) {
00111 error("can't write in %s: %s", filename, strerror(errno));
00112 exit(1);
00113 } else fclose(fd);
00114 }
00115
00116 default: break;
00117
00118 }
00119 } while (res != -1);
00120
00121 for(;optind<argc;optind++)
00122 snprintf(filename, 511, "%s", argv[optind]);
00123
00124 set_debug(debug);
00125
00126 }
00127
00128
00129 SLangConsole con;
00130
00131
00132 SLW_Text txt;
00133 SLW_Text status;
00134
00135
00136
00137 TBT tbt;
00138
00139 int main(int argc, char** argv)
00140 {
00141 int key;
00142 bool quit = false;
00143 FILE *mailfd;
00144 char tbtfile[512];
00145
00146 cmdline(argc, argv);
00147
00148 if(!filename[0]) {
00149 error("no file supplied on the commandline, see usage instructions");
00150 exit(0);
00151 }
00152
00153 func("composing mail in %s",filename);
00154
00155
00156 if(! con.init() ) exit(-1);
00157
00158
00159 status.border = false;
00160 status.set_name("status box");
00161 if(! con.place(&status, 0, con.h-10, con.w, con.h) ) {
00162 error("error placing the status widget");
00163 exit(-1);
00164 }
00165 assert ( status.init() );
00166
00167
00168 set_status(&status);
00169
00170
00171
00172 txt.set_name("editor");
00173
00174 if(! con.place(&txt, 0, 0, con.w, con.h-11) ) {
00175 error("error placing the text widget");
00176 exit(-1);
00177 }
00178 assert ( txt.init() );
00179
00180
00181 con.focused = &txt;
00182
00183
00184
00185 if(! tbt.init() ) {
00186 con.close();
00187 error("fatal error: can't start the TBT engine");
00188 exit(0);
00189 }
00190
00191
00192 notice("TBT - console recording - press Ctrl-c when done ");
00193
00194
00195
00196
00197 mailfd = fopen(filename,"r+");
00198 if(!mailfd)
00199 error("can't open file %s: %s", filename, strerror(errno) );
00200 else {
00201
00202
00203 char hdrp[1024];
00204 long pos;
00205
00206
00207 while( fgets(hdrp, 1024, mailfd) ) {
00208 if(hdrp[0] == '\n') {
00209
00210 pos = ftell(mailfd);
00211 fseek(mailfd, pos-1, SEEK_SET);
00212 break;
00213 }
00214 func("parsed header - %s", hdrp);
00215 }
00216
00217
00218 snprintf(tbtfile,511,"Attach: %s.tbt\n",filename);
00219 fputs(tbtfile, mailfd);
00220 fclose(mailfd);
00221
00222
00223 snprintf(tbtfile,511,"%s.tbt", filename);
00224 }
00225
00226 while(!quit) {
00227
00228 key = con.getkey();
00229
00230 if(key) {
00231
00232
00233 tbt.append(key);
00234
00235
00236 con.feed(key);
00237
00238 }
00239
00240 if( ! con.refresh() ) quit = true;
00241
00242 jsleep(0,1);
00243
00244 }
00245
00246 notice("Save and quit");
00247
00248 act("rendering %s in binary format", tbtfile);
00249 tbt.save_bin( tbtfile );
00250
00251 con.refresh();
00252
00253 con.close();
00254
00255 exit(0);
00256 }