1 /* See LICENSE for licence details. */
3 # define VERSION "0.4.0.beta4"
5 # define VERSION GIT_VERSION
11 #define _XOPEN_SOURCE 600
34 #include <sys/ioctl.h>
35 #include <sys/select.h>
38 #include <sys/types.h>
42 #include <X11/Xatom.h>
44 #include <X11/Xutil.h>
45 #include <X11/cursorfont.h>
46 #include <X11/keysym.h>
48 ////////////////////////////////////////////////////////////////////////////////
49 #include "libk8sterm/k8sterm.h"
52 ////////////////////////////////////////////////////////////////////////////////
56 ////////////////////////////////////////////////////////////////////////////////
57 #define USAGE_VERSION "k8sterm " VERSION "\n(c) 2010-2012 st engineers and Ketmar // Vampire Avalon\n"
59 "usage: sterm [options]\n" \
61 "-v show version and exit\n" \
62 "-h show this help and exit\n" \
64 "-t title set window title\n" \
65 "-c class set window class\n" \
66 "-w windowid embed in window id given id\n" \
67 "-T termname set TERM name\n" \
68 "-C config_file use custom config file\n" \
69 "-l langiconv use given locale\n" \
70 "-R stcmd run this INTERNAL k8sterm command\n" \
71 "-e command... run given command and pass all following args to it\n"
74 ////////////////////////////////////////////////////////////////////////////////
75 /* masks for key translation */
76 #define XK_NO_MOD (UINT_MAX)
77 #define XK_ANY_MOD (0)
80 ////////////////////////////////////////////////////////////////////////////////
81 // internal command line mode
89 // X11 window state flags
91 K8T_WIN_VISIBLE
= 0x01,
92 K8T_WIN_REDRAW
= 0x02,
93 K8T_WIN_FOCUSED
= 0x04
97 ////////////////////////////////////////////////////////////////////////////////
98 /* Purely graphic info */
103 Cursor cursor
; // text cursor
104 Cursor defcursor
; // 'default' cursor
105 Cursor lastcursor
; // last used cursor before blanking
111 int w
; /* window width */
112 int h
; /* window height */
113 int bufw
; /* pixmap width */
114 int bufh
; /* pixmap height */
115 int ch
; /* char height */
116 int cw
; /* char width */
117 char state
; /* focus, redraw, visible */
119 int tch
; /* tab text char height */
124 //struct timeval lastdraw;
128 /* Drawing Context */
130 uint32_t *ncol
; // normal colors
131 uint32_t *bcol
; // b/w colors
132 uint32_t *gcol
; // green colors
146 typedef struct K8TCmdLine K8TCmdLine
;
148 typedef void (*CmdLineExecFn
) (K8Term
*term
, K8TCmdLine
*cmdline
, int cancelled
);
151 int cmdMode
; // K8T_CMDMODE_xxx
152 char cmdline
[K8T_UTF_SIZ
*CMDLINE_SIZE
];
153 int cmdreslen
; // byte length of 'reserved' (read-only) part
154 int cmdofs
; // byte offset of the first visible UTF-8 char in cmdline
155 char cmdc
[K8T_UTF_SIZ
+1]; // buffer to collect UTF-8 char
156 int cmdcl
; // index in cmdc, used to collect UTF-8 chars
157 int cmdtabpos
; // # of bytes (not UTF-8 chars!) used in autocompletion or -1
158 const char *cmdcurtabc
; // current autocompleted command
159 CmdLineExecFn cmdexecfn
;
164 /* internal terminal data */
169 int waitkeypress
; /* child is dead, awaiting for keypress */
170 char *exitmsg
; /* message for waitkeypress */
177 #define K8T_DATA(_term) ((K8TermData *)(_term->udata))
180 ////////////////////////////////////////////////////////////////////////////////
182 #include "getticks.c"
185 ////////////////////////////////////////////////////////////////////////////////
190 ////////////////////////////////////////////////////////////////////////////////
191 static void executeCommands (const char *str
);
192 static const char *findCommandCompletion (const char *str
, int slen
, const char *prev
);
194 static void tdrawfatalmsg (K8Term
*term
, const char *msg
);
196 static void tcmdput (K8Term
*term
, K8TCmdLine
*cmdline
, const char *s
, int len
);
198 static void xclearunused (void);
199 static void xseturgency (int add
);
200 static void xfixsel (void);
201 static void xblankPointer (void);
202 static void xunblankPointer (void);
203 static void xdrawTabBar (void);
204 static void xdrawcmdline (K8Term
*term
, K8TCmdLine
*cmdline
, int scry
);
206 static void termCreateXPixmap (K8Term
*term
);
207 static void termSetCallbacks (K8Term
*term
);
208 static void termSetDefaults (K8Term
*term
);
210 static void getButtonInfo (K8Term
*term
, XEvent
*e
, int *b
, int *x
, int *y
);
212 static void fixWindowTitle (const K8Term
*t
);
214 static void scrollHistory (K8Term
*term
, int delta
);
217 ////////////////////////////////////////////////////////////////////////////////
218 static inline uint32_t getColor (int idx
) {
219 if (globalBW
&& (curterm
== NULL
|| !curterm
->blackandwhite
)) return dc
.clrs
[globalBW
][idx
];
220 if (curterm
!= NULL
) return dc
.clrs
[curterm
->blackandwhite
%3][idx
];
221 return dc
.clrs
[0][idx
];
225 ////////////////////////////////////////////////////////////////////////////////
226 #include "iniparse.c"
230 ////////////////////////////////////////////////////////////////////////////////
231 #include "termswitch.c"
235 ////////////////////////////////////////////////////////////////////////////////
236 #include "tcmdline.c"
237 #include "tfatalbox.c"
240 ////////////////////////////////////////////////////////////////////////////////
243 #include "x11drawtabs.c"
244 #include "x11drawcmdline.c"
247 ////////////////////////////////////////////////////////////////////////////////
248 #include "x11evtvis.c"
249 #include "x11evtkbd.c"
250 #include "x11evtsel.c"
251 #include "x11evtmouse.c"
254 ////////////////////////////////////////////////////////////////////////////////
258 ////////////////////////////////////////////////////////////////////////////////
260 static void xevtcbcmessage (XEvent
*e
) {
261 /* See xembed specs http://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html */
262 if (e
->xclient
.message_type
== xw
.xembed
&& e
->xclient
.format
== 32) {
263 if (e
->xclient
.data
.l
[1] == XEMBED_FOCUS_IN
) {
264 xw
.state
|= K8T_WIN_FOCUSED
;
266 k8t_tmSendFocusEvent(curterm
, 1);
267 } else if (e
->xclient
.data
.l
[1] == XEMBED_FOCUS_OUT
) {
268 xw
.state
&= ~K8T_WIN_FOCUSED
;
269 k8t_tmSendFocusEvent(curterm
, 0);
271 k8t_drawCursor(curterm
, 0);
273 k8t_drawCopy(curterm
, 0, 0, curterm
->col
, curterm
->row
);
277 if (e
->xclient
.data
.l
[0] == XA_WM_DELETE_WINDOW
) {
278 closeRequestComes
= 1;
284 ////////////////////////////////////////////////////////////////////////////////
285 static inline int last_draw_too_old (void) {
286 K8TTimeMSec tt
= mclock_ticks();
288 if (curterm
!= NULL
) {
289 if (curterm
->dead
|| !curterm
->wantRedraw
) return 0;
292 (tt
-curterm
->lastDrawTime
>= opt_drawtimeout
||
293 tt
-lastDrawTime
>= (curterm
->justSwapped
? opt_swapdrawtimeout
: opt_maxdrawtimeout
));
295 return (tt
-lastDrawTime
>= opt_maxdrawtimeout
);
299 ////////////////////////////////////////////////////////////////////////////////
301 static void (*handler
[LASTEvent
])(XEvent
*) = {
302 [KeyPress
] = xevtcbkpress
,
303 [ClientMessage
] = xevtcbcmessage
,
304 [ConfigureNotify
] = xevtcbresise
,
305 [VisibilityNotify
] = xevtcbvisibility
,
306 [UnmapNotify
] = xevtcbunmap
,
307 [Expose
] = xevtcbexpose
,
308 [FocusIn
] = xevtcbfocus
,
309 [FocusOut
] = xevtcbfocus
,
310 [MotionNotify
] = xevtcbbmotion
,
311 [ButtonPress
] = xevtcbbpress
,
312 [ButtonRelease
] = xevtcbbrelease
,
313 [SelectionNotify
] = xevtcbselnotify
,
314 [SelectionRequest
] = xevtcbselrequest
,
315 [SelectionClear
] = xevtcbselclear
,
319 static void run (void) {
320 //int stuff_to_print = 0;
321 int xfd
= XConnectionNumber(xw
.dpy
);
323 ptrLastMove
= mclock_ticks();
324 while (term_count
> 0) {
327 struct timeval timeout
;
334 //FD_SET(curterm->cmdfd, &rfd);
335 // have something to write?
336 for (int f
= 0; f
< term_count
; ++f
) {
337 K8Term
*t
= term_array
[f
];
339 if (!t
->dead
&& t
->cmdfd
>= 0) {
340 if (t
->cmdfd
> maxfd
) maxfd
= t
->cmdfd
;
341 FD_SET(t
->cmdfd
, &rfd
);
342 if (K8T_DATA(t
)->pid
!= 0 && t
->wrbufpos
< t
->wrbufused
) FD_SET(t
->cmdfd
, &wfd
);
347 timeout
.tv_usec
= (opt_drawtimeout
+2)*1000;
348 //fprintf(stderr, "before select...\n");
349 if (select(maxfd
+1, &rfd
, &wfd
, NULL
, &timeout
) < 0) {
350 if (errno
== EINTR
) continue;
351 k8t_die("select failed: %s", strerror(errno
));
353 //fprintf(stderr, "after select...\n");
354 // process terminals i/o
355 for (int f
= 0; f
< term_count
; ++f
) {
356 K8Term
*t
= term_array
[f
];
358 if (!t
->dead
&& t
->cmdfd
>= 0) {
361 if (K8T_DATA(t
)->pid
!= 0 && FD_ISSET(t
->cmdfd
, &wfd
)) k8t_ttyFlushWriteBuf(t
);
362 if (FD_ISSET(t
->cmdfd
, &rfd
)) rd
= k8t_ttyRead(t
);
364 if (K8T_DATA(t
)->waitkeypress
&& K8T_DATA(t
)->exitmsg
!= NULL
&& rd
< 0) {
365 // there will be no more data
369 tdrawfatalmsg(t
, K8T_DATA(t
)->exitmsg
);
370 free(K8T_DATA(t
)->exitmsg
);
371 K8T_DATA(t
)->exitmsg
= NULL
;
372 k8t_tmWantRedraw(t
, 1);
378 if (term_count
== 0) exit(exitcode
);
381 if (curterm
!= NULL
&& curterm
->curblink
> 0) {
382 K8TTimeMSec tt
= mclock_ticks();
384 if (tt
-curterm
->lastBlinkTime
>= curterm
->curblink
) {
385 curterm
->lastBlinkTime
= tt
;
386 if ((xw
.state
&K8T_WIN_FOCUSED
) || curterm
->curblinkinactive
) {
387 curterm
->curbhidden
= (curterm
->curbhidden
? 0 : -1);
390 curterm
->curbhidden
= 0;
394 if (updateTabBar
) xdrawTabBar();
395 if (dodraw
|| last_draw_too_old()) k8t_drawTerm(curterm
, 0);
397 if (XPending(xw
.dpy
)) {
398 while (XPending(xw
.dpy
)) {
399 XNextEvent(xw
.dpy
, &ev
);
401 //case VisibilityNotify:
409 ptrLastMove
= mclock_ticks();
413 if (XFilterEvent(&ev
, xw
.win
)) continue;
414 if (handler
[ev
.type
]) (handler
[ev
.type
])(&ev
);
418 if (curterm
!= NULL
) {
419 switch (closeRequestComes
) {
420 case 1: // just comes
421 if (opt_ignoreclose
== 0) {
422 tcmdlinehide(curterm
, &K8T_DATA(curterm
)->cmdline
);
423 tcmdlineinitex(curterm
, &K8T_DATA(curterm
)->cmdline
, "Do you really want to close sterm [Y/n]? ");
424 K8T_DATA(curterm
)->cmdline
.cmdexecfn
= cmdline_closequeryexec
;
425 } else if (opt_ignoreclose
< 0) {
426 //FIXME: kill all clients?
429 closeRequestComes
= 0;
431 case 2: // ok, die now
432 //FIXME: kill all clients?
437 if (!ptrBlanked
&& opt_ptrblank
> 0 && mclock_ticks()-ptrLastMove
>= opt_ptrblank
) {
444 ////////////////////////////////////////////////////////////////////////////////
445 static void termSetDefaults (K8Term
*term
) {
446 term
->deffg
= defaultFG
;
447 term
->defbg
= defaultBG
;
448 term
->defboldfg
= defaultBoldFG
;
449 term
->defunderfg
= defaultUnderlineFG
;
451 term
->defcurfg
= defaultCursorFG
;
452 term
->defcurbg
= defaultCursorBG
;
453 term
->defcurinactivefg
= defaultCursorInactiveFG
;
454 term
->defcurinactivebg
= defaultCursorInactiveBG
;
456 term
->tabsize
= opt_tabsize
;
457 term
->wrapOnCtrlChars
= 0;
458 term
->historyLinesUsed
= 0;
462 static void termSetCallbacks (K8Term
*term
) {
463 K8TermData
*td
= calloc(1, sizeof(K8TermData
));
465 if (td
== NULL
) k8t_die("out of memory!");
468 term
->clockTicks
= clockTicksCB
;
469 term
->setLastDrawTime
= setLastDrawTimeCB
;
471 term
->isConversionNecessary
= isConversionNecessaryCB
;
472 term
->loc2utf
= loc2utfCB
;
473 term
->utf2loc
= utf2locCB
;
475 term
->isFocused
= isFocusedCB
;
476 term
->isVisible
= isVisibleCB
;
478 term
->drawSetFG
= drawSetFGCB
;
479 term
->drawSetBG
= drawSetBGCB
;
480 term
->drawRect
= drawRectCB
;
481 term
->drawFillRect
= drawFillRectCB
;
482 term
->drawCopyArea
= drawCopyAreaCB
;
483 term
->drawString
= drawStringCB
;
484 term
->drawOverlay
= drawOverlayCB
;
486 term
->fixSelection
= fixSelectionCB
;
487 term
->clearSelection
= clearSelectionCB
;
489 term
->titleChanged
= titleChangedCB
;
490 term
->doBell
= doBellCB
;
492 term
->isUnderOverlay
= isUnderOverlayCB
;
493 term
->clipToOverlay
= clipToOverlayCB
;
494 term
->addHistoryLine
= NULL
;
496 term
->unimap
= unimap
;
501 static void termCreateXPixmap (K8Term
*term
) {
502 int w
= K8T_MAX(1, term
->col
*xw
.cw
);
503 int h
= K8T_MAX(1, term
->row
*xw
.ch
);
506 newbuf
= XCreatePixmap(xw
.dpy
, xw
.win
, w
, h
, XDefaultDepth(xw
.dpy
, xw
.scr
));
509 //XCopyArea(xw.dpy, td->picbuf, newbuf, dc.gc, 0, 0, td->picbufw, td->picbufh, 0, 0);
510 XFreePixmap(xw
.dpy
, xw
.picscr
);
514 term
->drawSetFG(term
, term
->defbg
);
517 if (td->picalloced) {
518 if (td->picbufw > oldw) {
519 XFillRectangle(xw.dpy, newbuf, dc.gc, oldw, 0, td->picbufw-oldw, K8T_MIN(td->picbufh, oldh));
520 } else if (td->picbufw < oldw && xw.w > td->picbufw) {
521 XClearArea(xw.dpy, xw.win, td->picbufw, 0, xw.w-td->picbufh, K8T_MIN(td->picbufh, oldh), False);
524 if (td->picbufh > oldh) {
525 XFillRectangle(xw.dpy, newbuf, dc.gc, 0, oldh, td->picbufw, td->picbufh-oldh);
526 } else if (td->picbufh < oldh && xw.h > td->picbufh) {
527 XClearArea(xw.dpy, xw.win, 0, td->picbufh, xw.w, xw.h-td->picbufh, False);
530 XFillRectangle(xw.dpy, newbuf, dc.gc, 0, 0, td->picbufw, td->picbufh);
533 XFillRectangle(xw
.dpy
, newbuf
, dc
.gc
, 0, 0, w
, h
);
535 k8t_tmFullDirty(term
);
539 ////////////////////////////////////////////////////////////////////////////////
541 #include "commands.c"
544 ////////////////////////////////////////////////////////////////////////////////
545 #include "childkiller.c"
548 ////////////////////////////////////////////////////////////////////////////////
549 #define PUSH_BACK(_c) (*ress)[dpos++] = (_c)
550 #define DECODE_TUPLE(tuple,bytes) \
551 for (tmp = bytes; tmp > 0; tmp--, tuple = (tuple & 0x00ffffff)<<8) \
552 PUSH_BACK((char)((tuple >> 24)&0xff))
554 // returns ress length
555 static int ascii85Decode (char **ress
, const char *srcs
/*, int start, int length*/) {
556 static uint32_t pow85
[5] = { 85*85*85*85UL, 85*85*85UL, 85*85UL, 85UL, 1UL };
557 const uint8_t *data
= (const uint8_t *)srcs
;
558 int len
= strlen(srcs
);
560 int count
= 0, c
= 0;
562 int start
= 0, length
= len
;
565 if (start
< 0) start
= 0; else { len
-= start
; data
+= start
; }
566 if (length
< 0 || len
< length
) length
= len
;
569 int xlen = 4*((length+4)/5);
570 kstringReserve(ress, xlen);
574 *ress
= (char *)calloc(1, len
+1);
575 for (int f
= length
; f
> 0; --f
, ++data
) {
577 if (c
<= ' ') continue; // skip blanks
579 case 'z': // zero tuple
581 //fprintf(stderr, "%s: z inside ascii85 5-tuple\n", file);
591 case '~': // '~>': end of sequence
592 if (f
< 1 || data
[1] != '>') { free(*ress
); return -2; } // error
593 if (count
> 0) { f
= -1; break; }
595 if (c
< '!' || c
> 'u') {
596 //fprintf(stderr, "%s: bad character in ascii85 region: %#o\n", file, c);
600 tuple
+= ((uint8_t)(c
-'!'))*pow85
[count
++];
602 DECODE_TUPLE(tuple
, 4);
609 // write last (possibly incomplete) tuple
611 tuple
+= pow85
[count
];
612 DECODE_TUPLE(tuple
, count
);
621 static void decodeBA (char *str
, int len
) {
624 for (int f
= 0; f
< len
; ++f
, ++str
) {
634 static void printEC (const char *txt
) {
638 if ((len
= ascii85Decode(&dest
, txt
)) >= 0) {
640 fprintf(stderr
, "%s\n", dest
);
646 static int isStr85Equ (const char *txt
, const char *str
) {
650 if (str
!= NULL
&& str
[0] && (len
= ascii85Decode(&dest
, txt
)) >= 0) {
651 if (len
> 0) res
= (strcmp(dest
+1, str
+1) == 0);
658 static int checkEGG (const char *str
) {
659 if (isStr85Equ("06:]JASq", str
) || isStr85Equ("0/i", str
)) {
661 "H8lZV&6)1>+AZ>m)Cf8;A1/cP+CnS)0OJ`X.QVcHA4^cc5r3=m1c%0D3&c263d?EV6@4&>"
662 "3DYQo;c-FcO+UJ;MOJ$TAYO@/FI]+B?C.L$>%:oPAmh:4Au)>AAU/H;ZakL2I!*!%J;(AK"
663 "NIR#5TXgZ6c'F1%^kml.JW5W8e;ql0V3fQUNfKpng6ppMf&ip-VOX@=jKl;#q\"DJ-_>jG"
664 "8#L;nm]!q;7c+hR6p;tVY#J8P$aTTK%c-OT?)<00,+q*8f&ff9a/+sbU,:`<H*[fk0o]7k"
665 "^l6nRkngc6Tl2Ngs!!P2I%KHG=7n*an'bsgn>!*8s7TLTC+^\\\"W+<=9^%Ol$1A1eR*Be"
666 "gqjEag:M0OnrC4FBY5@QZ&'HYYZ#EHs8t4$5]!22QoJ3`;-&=\\DteO$d6FBqT0E@:iu?N"
667 "a5ePUf^_uEEcjTDKfMpX/9]DFL8N-Ee;*8C5'WgbGortZuh1\\N0;/rJB6'(MSmYiS\"6+"
668 "<NK)KDV3e+Ad[@).W:%.dd'0h=!QUhghQaNNotIZGrpHr-YfEuUpsKW<^@qlZcdTDA!=?W"
669 "Yd+-^`'G8Or)<0-T&CT.i+:mJp(+/M/nLaVb#5$p2jR2<rl7\"XlngcN`mf,[4oK5JLr\\"
670 "m=X'(ue;'*1ik&/@T4*=j5t=<&/e/Q+2=((h`>>uN(#>&#i>2/ajK+=eib1coVe3'D)*75"
671 "m_h;28^M6p6*D854Jj<C^,Q8Wd\"O<)&L/=C$lUAQNN<=eTD:A6kn-=EItXSss.tAS&!;F"
672 "EsgpJTHIYNNnh'`kmX^[`*ELOHGcWbfPOT`J]A8P`=)AS;rYlR$\"-.RG440lK5:Dg?G'2"
673 "['dE=nEm1:k,,Se_=%-6Z*L^J[)EC"
677 if (isStr85Equ("04Jj?B)", str
)) {
679 "IPaSa(`c:T,o9Bq3\\)IY++?+!-S9%P0/OkjE&f$l.OmK'Ai2;ZHn[<,6od7^8;)po:HaP"
680 "m<'+&DRS:/1L7)IA7?WI$8WKTUB2tXg>Zb$.?\"@AIAu;)6B;2_PB5M?oBPDC.F)606Z$V"
681 "=ONd6/5P*LoWKTLQ,d@&;+Ru,\\ESY*rg!l1XrhpJ:\"WKWdOg?l;=RHE:uU9C?aotBqj]"
682 "=k8cZ`rp\"ZO=GjkfD#o]Z\\=6^]+Gf&-UFthT*hN"
686 if (isStr85Equ("04o69A7Tr", str
)) {
688 "Ag7d[&R#Ma9GVV5,S(D;De<T_+W).?,%4n+3cK=%4+0VN@6d\")E].np7l?8gF#cWF7SS_m"
689 "4@V\\nQ;h!WPD2h#@\\RY&G\\LKL=eTP<V-]U)BN^b.DffHkTPnFcCN4B;]8FCqI!p1@H*_"
690 "jHJ<%g']RG*MLqCrbP*XbNL=4D1R[;I(c*<FuesbWmSCF1jTW+rplg;9[S[7eDVl6YsjT"
698 ////////////////////////////////////////////////////////////////////////////////
699 int main (int argc
, char *argv
[]) {
700 char *configfile
= NULL
;
705 for (int f
= 1; f
< argc
; f
++) {
706 if (argv
[f
][0] == '-' && checkEGG(argv
[f
])) exit(1);
707 if (strcmp(argv
[f
], "-name") == 0) { ++f
; continue; }
708 if (strcmp(argv
[f
], "-into") == 0) { ++f
; continue; }
709 if (strcmp(argv
[f
], "-embed") == 0) { ++f
; continue; }
710 switch (argv
[f
][0] != '-' || argv
[f
][2] ? -1 : argv
[f
][1]) {
711 case 'e': f
= argc
+1; break;
722 opt_term
= strdup(argv
[f
]);
728 if (configfile
!= NULL
) free(configfile
);
729 configfile
= strdup(argv
[f
]);
733 if (++f
< argc
) cliLocale
= argv
[f
];
735 case 'S': // single-tab mode
739 fprintf(stderr
, "%s", USAGE_VERSION
);
743 fprintf(stderr
, "%s%s", USAGE_VERSION
, USAGE
);
748 initDefaultOptions();
749 if (configfile
== NULL
) {
750 const char *home
= getenv("HOME");
753 configfile
= SPrintf("%s/.sterm.rc", home
);
754 if (loadConfig(configfile
) == 0) goto cfgdone
;
755 free(configfile
); configfile
= NULL
;
757 configfile
= SPrintf("%s/.config/sterm.rc", home
);
758 if (loadConfig(configfile
) == 0) goto cfgdone
;
759 free(configfile
); configfile
= NULL
;
762 configfile
= SPrintf("/etc/sterm.rc");
763 if (loadConfig(configfile
) == 0) goto cfgdone
;
764 free(configfile
); configfile
= NULL
;
766 configfile
= SPrintf("/etc/sterm/sterm.rc");
767 if (loadConfig(configfile
) == 0) goto cfgdone
;
768 free(configfile
); configfile
= NULL
;
770 configfile
= SPrintf("./.sterm.rc");
771 if (loadConfig(configfile
) == 0) goto cfgdone
;
772 free(configfile
); configfile
= NULL
;
775 if (loadConfig(configfile
) < 0) k8t_die("config file '%s' not found!", configfile
);
778 if (configfile
!= NULL
) free(configfile
); configfile
= NULL
;
780 for (int f
= 1; f
< argc
; f
++) {
781 if (strcmp(argv
[f
], "-name") == 0) { ++f
; continue; }
782 if (strcmp(argv
[f
], "-into") == 0 || strcmp(argv
[f
], "-embed") == 0) {
783 if (opt_embed
) free(opt_embed
);
784 opt_embed
= strdup(argv
[f
]);
787 switch (argv
[f
][0] != '-' || argv
[f
][2] ? -1 : argv
[f
][1]) {
791 opt_title
= strdup(argv
[f
]);
797 opt_class
= strdup(argv
[f
]);
802 if (opt_embed
) free(opt_embed
);
803 opt_embed
= strdup(argv
[f
]);
807 if (++f
< argc
) runcmd
= argv
[f
];
810 /* eat all remaining arguments */
811 if (++f
< argc
) opt_cmd
= &argv
[f
];
823 setenv("TERM", opt_term
, 1);
825 setlocale(LC_ALL
, "");
830 curterm
= k8t_termalloc();
831 k8t_tmInitialize(curterm
, 80, 25, opt_maxhistory
);
832 // pixmap will be created in xinit()
833 if (K8T_DATA(curterm
)->execcmd
!= NULL
) { free(K8T_DATA(curterm
)->execcmd
); K8T_DATA(curterm
)->execcmd
= NULL
; }
834 if (k8t_ttyNew(curterm
) != 0) k8t_die("can't run process");
837 k8t_selInit(curterm
);
838 if (runcmd
!= NULL
) executeCommands(runcmd
);