1 /* See LICENSE for licence details. */
3 # define VERSION "0.4.0.beta4"
5 # define VERSION GIT_VERSION
11 #define _XOPEN_SOURCE 600
39 #include <sys/ioctl.h>
40 #include <sys/select.h>
43 #include <sys/types.h>
47 #include <X11/Xatom.h>
49 #include <X11/Xutil.h>
50 #include <X11/cursorfont.h>
51 #include <X11/keysym.h>
53 ////////////////////////////////////////////////////////////////////////////////
54 #include "libk8sterm/k8sterm.h"
57 ////////////////////////////////////////////////////////////////////////////////
61 ////////////////////////////////////////////////////////////////////////////////
62 #define USAGE_VERSION "k8sterm " VERSION "\n(c) 2010-2012 st engineers and Ketmar // Vampire Avalon\n"
64 "usage: sterm [options]\n" \
66 "-v show version and exit\n" \
67 "-h show this help and exit\n" \
69 "-t title set window title\n" \
70 "-c class set window class\n" \
71 "-w windowid embed in window id given id\n" \
72 "-T termname set TERM name\n" \
73 "-C config_file use custom config file\n" \
74 "-l langiconv use given locale\n" \
75 "-R stcmd run this INTERNAL k8sterm command\n" \
76 "-e command... run given command and pass all following args to it\n"
79 ////////////////////////////////////////////////////////////////////////////////
80 /* masks for key translation */
81 #define XK_NO_MOD (UINT_MAX)
82 #define XK_ANY_MOD (0)
85 ////////////////////////////////////////////////////////////////////////////////
86 // internal command line mode
94 // X11 window state flags
96 K8T_WIN_VISIBLE
= 0x01,
97 K8T_WIN_REDRAW
= 0x02,
98 K8T_WIN_FOCUSED
= 0x04
102 ////////////////////////////////////////////////////////////////////////////////
103 /* Purely graphic info */
108 Cursor cursor
; // text cursor
109 Cursor defcursor
; // 'default' cursor
110 Cursor lastcursor
; // last used cursor before blanking
116 int w
; /* window width */
117 int h
; /* window height */
118 int bufw
; /* pixmap width */
119 int bufh
; /* pixmap height */
120 int ch
; /* char height */
121 int cw
; /* char width */
122 char state
; /* focus, redraw, visible */
124 int tch
; /* tab text char height */
129 //struct timeval lastdraw;
133 /* Drawing Context */
135 uint32_t *ncol
; // normal colors
136 uint32_t *bcol
; // b/w colors
137 uint32_t *gcol
; // green colors
151 typedef struct K8TCmdLine K8TCmdLine
;
153 typedef void (*CmdLineExecFn
) (K8Term
*term
, K8TCmdLine
*cmdline
, int cancelled
);
156 int cmdMode
; // K8T_CMDMODE_xxx
157 char cmdline
[K8T_UTF_SIZ
*CMDLINE_SIZE
];
158 int cmdreslen
; // byte length of 'reserved' (read-only) part
159 int cmdofs
; // byte offset of the first visible UTF-8 char in cmdline
160 char cmdc
[K8T_UTF_SIZ
+1]; // buffer to collect UTF-8 char
161 int cmdcl
; // index in cmdc, used to collect UTF-8 chars
162 int cmdtabpos
; // # of bytes (not UTF-8 chars!) used in autocompletion or -1
163 const char *cmdcurtabc
; // current autocompleted command
164 CmdLineExecFn cmdexecfn
;
169 /* internal terminal data */
174 int waitkeypress
; /* child is dead, awaiting for keypress */
175 char *exitmsg
; /* message for waitkeypress */
186 #define K8T_DATA(_term) ((K8TermData *)(_term->udata))
189 ////////////////////////////////////////////////////////////////////////////////
191 #include "getticks.c"
194 ////////////////////////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////////////////////////
200 static void executeCommands (const char *str
);
201 static const char *findCommandCompletion (const char *str
, int slen
, const char *prev
);
203 static void tdrawfatalmsg (K8Term
*term
, const char *msg
);
205 static void tcmdput (K8Term
*term
, K8TCmdLine
*cmdline
, const char *s
, int len
);
207 static void xclearunused (void);
208 static void xseturgency (int add
);
209 static void xfixsel (void);
210 static void xblankPointer (void);
211 static void xunblankPointer (void);
212 static void xdrawTabBar (void);
213 static void xdrawcmdline (K8Term
*term
, K8TCmdLine
*cmdline
, int scry
);
215 static void termCreateXPixmap (K8Term
*term
);
216 static void termSetCallbacks (K8Term
*term
);
217 static void termSetDefaults (K8Term
*term
);
219 static void getButtonInfo (K8Term
*term
, XEvent
*e
, int *b
, int *x
, int *y
);
221 static void fixWindowTitle (const K8Term
*t
);
223 static void scrollHistory (K8Term
*term
, int delta
);
225 static int termsDoIO (int xfd
);
226 //static void doTermWrFlush (K8Term *term);
229 ////////////////////////////////////////////////////////////////////////////////
230 static inline uint32_t getColor (int idx
) {
231 if (globalBW
&& (curterm
== NULL
|| !curterm
->blackandwhite
)) return dc
.clrs
[globalBW
][idx
];
232 if (curterm
!= NULL
) return dc
.clrs
[curterm
->blackandwhite
%3][idx
];
233 return dc
.clrs
[0][idx
];
237 ////////////////////////////////////////////////////////////////////////////////
238 #include "iniparse.c"
242 ////////////////////////////////////////////////////////////////////////////////
243 #include "termswitch.c"
247 ////////////////////////////////////////////////////////////////////////////////
248 #include "tcmdline.c"
249 #include "tfatalbox.c"
252 ////////////////////////////////////////////////////////////////////////////////
255 #include "x11drawtabs.c"
256 #include "x11drawcmdline.c"
259 ////////////////////////////////////////////////////////////////////////////////
260 #include "x11evtvis.c"
261 #include "x11evtkbd.c"
262 #include "x11evtsel.c"
263 #include "x11evtmouse.c"
266 ////////////////////////////////////////////////////////////////////////////////
270 ////////////////////////////////////////////////////////////////////////////////
272 static void xevtcbcmessage (XEvent
*e
) {
273 /* See xembed specs http://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html */
274 if (e
->xclient
.message_type
== xw
.xembed
&& e
->xclient
.format
== 32) {
275 if (e
->xclient
.data
.l
[1] == XEMBED_FOCUS_IN
) {
276 xw
.state
|= K8T_WIN_FOCUSED
;
278 k8t_tmSendFocusEvent(curterm
, 1);
279 } else if (e
->xclient
.data
.l
[1] == XEMBED_FOCUS_OUT
) {
280 xw
.state
&= ~K8T_WIN_FOCUSED
;
281 k8t_tmSendFocusEvent(curterm
, 0);
283 k8t_drawCursor(curterm
, 0);
285 k8t_drawCopy(curterm
, 0, 0, curterm
->col
, curterm
->row
);
289 if (e
->xclient
.data
.l
[0] == XA_WM_DELETE_WINDOW
) {
290 closeRequestComes
= 1;
296 ////////////////////////////////////////////////////////////////////////////////
297 static inline int last_draw_too_old (void) {
298 K8TTimeMSec tt
= mclock_ticks();
300 if (curterm
!= NULL
) {
301 if (curterm
->dead
|| !curterm
->wantRedraw
) return 0;
304 (tt
-curterm
->lastDrawTime
>= opt_drawtimeout
||
305 tt
-lastDrawTime
>= (curterm
->justSwapped
? opt_swapdrawtimeout
: opt_maxdrawtimeout
));
307 return (tt
-lastDrawTime
>= opt_maxdrawtimeout
);
311 static void afterScrollCB (K8Term
*term
) {
313 if (curterm
== term
) {
315 static K8TTimeMSec lastForcedRedraw
= 0;
316 K8TTimeMSec tt
= mclock_ticks();
318 curterm->wantRedraw = 1;
319 curterm->lastDrawTime = 0;
321 k8t_tmWantRedraw(term
, 1); /* force it */
322 if (tt
-lastForcedRedraw
>= 20) {
323 k8t_drawTerm(term
, 1);
324 lastForcedRedraw
= tt
;
331 ////////////////////////////////////////////////////////////////////////////////
333 static void (*handler
[LASTEvent
])(XEvent
*) = {
334 [KeyPress
] = xevtcbkpress
,
335 [ClientMessage
] = xevtcbcmessage
,
336 [ConfigureNotify
] = xevtcbresise
,
337 [VisibilityNotify
] = xevtcbvisibility
,
338 [UnmapNotify
] = xevtcbunmap
,
339 [Expose
] = xevtcbexpose
,
340 [FocusIn
] = xevtcbfocus
,
341 [FocusOut
] = xevtcbfocus
,
342 [MotionNotify
] = xevtcbbmotion
,
343 [ButtonPress
] = xevtcbbpress
,
344 [ButtonRelease
] = xevtcbbrelease
,
345 [SelectionNotify
] = xevtcbselnotify
,
346 [SelectionRequest
] = xevtcbselrequest
,
347 [SelectionClear
] = xevtcbselclear
,
352 static void doTermWrFlush (K8Term *term) {
355 //struct timeval timeout;
357 if (term->dead || term->cmdfd < 0) {
358 // empty write buffer
359 term->wrbufpos = term->wrbufused = 0;
365 FD_SET(term->cmdfd, &rfd);
366 FD_SET(term->cmdfd, &wfd);
367 if (select(term->cmdfd+1, &rfd, &wfd, NULL, NULL) < 0) {
368 if (errno == EINTR) continue;
369 k8t_die("select failed: %s", strerror(errno));
372 if (FD_ISSET(term->cmdfd, &rfd)) {
373 int rd = k8t_ttyRead(term);
375 if (K8T_DATA(term)->waitkeypress && K8T_DATA(term)->exitmsg != NULL && rd < 0) {
376 // there will be no more data
380 tdrawfatalmsg(term, K8T_DATA(term)->exitmsg);
381 free(K8T_DATA(term)->exitmsg);
382 K8T_DATA(term)->exitmsg = NULL;
383 k8t_tmWantRedraw(term, 1);
384 // empty write buffer
385 term->wrbufpos = term->wrbufused = 0;
391 if (term->wrbufpos >= term->wrbufused) {
392 // empty write buffer
393 term->wrbufpos = term->wrbufused = 0;
398 if (K8T_DATA(term)->pid != 0 && FD_ISSET(term->cmdfd, &wfd)) {
399 k8t_ttySendWriteBuf(term);
406 static int termsDoIO (int xfd
) {
411 struct timeval timeout
;
417 if (xfd
>= 0) { FD_SET(xfd
, &rfd
); maxfd
= xfd
; } else { maxfd
= 0; }
418 //FD_SET(curterm->cmdfd, &rfd);
419 // have something to write?
420 for (int f
= 0; f
< term_count
; ++f
) {
421 K8Term
*t
= term_array
[f
];
423 if (!t
->dead
&& t
->cmdfd
>= 0) {
424 checkAndFixWindowTitle(t
, 0);
425 if (t
->cmdfd
> maxfd
) maxfd
= t
->cmdfd
;
426 FD_SET(t
->cmdfd
, &rfd
);
427 if (K8T_DATA(t
)->pid
!= 0 && t
->wrbufpos
< t
->wrbufused
) FD_SET(t
->cmdfd
, &wfd
);
432 timeout
.tv_usec
= (xfd
>= 0 ? (opt_drawtimeout
+2)*1000 : 0);
433 //fprintf(stderr, "before select...\n");
434 sres
= select(maxfd
+1, &rfd
, &wfd
, NULL
, &timeout
);
436 if (errno
== EINTR
) continue;
437 k8t_die("select failed: %s", strerror(errno
));
439 if (xfd
>= 0 && FD_ISSET(xfd
, &rfd
)) {
444 //fprintf(stderr, "after select...\n");
445 // process terminals i/o
446 for (int f
= 0; f
< term_count
; ++f
) {
447 K8Term
*t
= term_array
[f
];
449 if (!t
->dead
&& t
->cmdfd
>= 0) {
452 if (K8T_DATA(t
)->pid
!= 0 && FD_ISSET(t
->cmdfd
, &wfd
)) k8t_ttyFlushWriteBuf(t
);
453 if (FD_ISSET(t
->cmdfd
, &rfd
)) rd
= k8t_ttyRead(t
);
455 if (K8T_DATA(t
)->waitkeypress
&& K8T_DATA(t
)->exitmsg
!= NULL
&& rd
< 0) {
456 // there will be no more data
460 tdrawfatalmsg(t
, K8T_DATA(t
)->exitmsg
);
461 free(K8T_DATA(t
)->exitmsg
);
462 K8T_DATA(t
)->exitmsg
= NULL
;
463 k8t_tmWantRedraw(t
, 1);
473 static void run (void) {
474 //int stuff_to_print = 0;
475 int xfd
= XConnectionNumber(xw
.dpy
);
477 ptrLastMove
= mclock_ticks();
478 while (term_count
> 0) {
482 doX
= termsDoIO(xfd
);
485 if (term_count
== 0) exit(exitcode
);
488 if (curterm
!= NULL
&& curterm
->curblink
> 0) {
489 K8TTimeMSec tt
= mclock_ticks();
491 if (tt
-curterm
->lastBlinkTime
>= curterm
->curblink
) {
492 curterm
->lastBlinkTime
= tt
;
493 if ((xw
.state
&K8T_WIN_FOCUSED
) || curterm
->curblinkinactive
) {
494 curterm
->curbhidden
= (curterm
->curbhidden
? 0 : -1);
497 curterm
->curbhidden
= 0;
501 if (updateTabBar
) xdrawTabBar();
502 if (dodraw
|| last_draw_too_old()) k8t_drawTerm(curterm
, 0);
504 if (doX
|| XPending(xw
.dpy
)) {
505 while (XPending(xw
.dpy
)) {
506 XNextEvent(xw
.dpy
, &ev
);
508 //case VisibilityNotify:
516 ptrLastMove
= mclock_ticks();
520 if (XFilterEvent(&ev
, xw
.win
)) continue;
521 if (handler
[ev
.type
]) (handler
[ev
.type
])(&ev
);
525 if (curterm
!= NULL
) {
526 switch (closeRequestComes
) {
527 case 1: // just comes
528 if (opt_ignoreclose
== 0) {
529 tcmdlinehide(curterm
, &K8T_DATA(curterm
)->cmdline
);
530 tcmdlineinitex(curterm
, &K8T_DATA(curterm
)->cmdline
, "Do you really want to close sterm [n/Y]? ");
531 K8T_DATA(curterm
)->cmdline
.cmdexecfn
= cmdline_closequeryexec
;
532 } else if (opt_ignoreclose
< 0) {
533 //FIXME: kill all clients?
536 closeRequestComes
= 0;
538 case 2: // ok, die now
539 //FIXME: kill all clients?
544 if (!ptrBlanked
&& opt_ptrblank
> 0 && mclock_ticks()-ptrLastMove
>= opt_ptrblank
) {
551 ////////////////////////////////////////////////////////////////////////////////
552 static void termSetDefaults (K8Term
*term
) {
553 term
->deffg
= defaultFG
;
554 term
->defbg
= defaultBG
;
555 term
->defboldfg
= defaultBoldFG
;
556 term
->defunderfg
= defaultUnderlineFG
;
558 term
->defcurfg
= defaultCursorFG
;
559 term
->defcurbg
= defaultCursorBG
;
560 term
->defcurinactivefg
= defaultCursorInactiveFG
;
561 term
->defcurinactivebg
= defaultCursorInactiveBG
;
563 term
->tabsize
= opt_tabsize
;
564 term
->wrapOnCtrlChars
= 0;
565 term
->historyLinesUsed
= 0;
569 static void termSetCallbacks (K8Term
*term
) {
570 K8TermData
*td
= calloc(1, sizeof(K8TermData
));
572 if (td
== NULL
) k8t_die("out of memory!");
575 term
->clockTicks
= clockTicksCB
;
576 term
->setLastDrawTime
= setLastDrawTimeCB
;
578 term
->isConversionNecessary
= isConversionNecessaryCB
;
579 term
->loc2utf
= loc2utfCB
;
580 term
->utf2loc
= utf2locCB
;
582 term
->isFocused
= isFocusedCB
;
583 term
->isVisible
= isVisibleCB
;
585 term
->drawSetFG
= drawSetFGCB
;
586 term
->drawSetBG
= drawSetBGCB
;
587 term
->drawRect
= drawRectCB
;
588 term
->drawFillRect
= drawFillRectCB
;
589 term
->drawCopyArea
= drawCopyAreaCB
;
590 term
->drawString
= drawStringCB
;
591 term
->drawOverlay
= drawOverlayCB
;
593 term
->fixSelection
= fixSelectionCB
;
594 term
->clearSelection
= clearSelectionCB
;
596 term
->titleChanged
= titleChangedCB
;
597 term
->doBell
= doBellCB
;
599 term
->isUnderOverlay
= isUnderOverlayCB
;
600 term
->clipToOverlay
= clipToOverlayCB
;
601 term
->addHistoryLine
= NULL
;
602 //term->doWriteBufferFlush = doTermWrFlush;
603 //term->doWriteBufferFlush = NULL;
604 term
->afterScroll
= afterScrollCB
;
606 term
->unimap
= unimap
;
608 td
->lastpname
= strdup("");
609 td
->lastppath
= strdup("");
614 static void termCreateXPixmap (K8Term
*term
) {
615 int w
= K8T_MAX(1, term
->col
*xw
.cw
);
616 int h
= K8T_MAX(1, term
->row
*xw
.ch
);
619 newbuf
= XCreatePixmap(xw
.dpy
, xw
.win
, w
, h
, XDefaultDepth(xw
.dpy
, xw
.scr
));
622 //XCopyArea(xw.dpy, td->picbuf, newbuf, dc.gc, 0, 0, td->picbufw, td->picbufh, 0, 0);
623 XFreePixmap(xw
.dpy
, xw
.picscr
);
627 term
->drawSetFG(term
, term
->defbg
);
630 if (td->picalloced) {
631 if (td->picbufw > oldw) {
632 XFillRectangle(xw.dpy, newbuf, dc.gc, oldw, 0, td->picbufw-oldw, K8T_MIN(td->picbufh, oldh));
633 } else if (td->picbufw < oldw && xw.w > td->picbufw) {
634 XClearArea(xw.dpy, xw.win, td->picbufw, 0, xw.w-td->picbufh, K8T_MIN(td->picbufh, oldh), False);
637 if (td->picbufh > oldh) {
638 XFillRectangle(xw.dpy, newbuf, dc.gc, 0, oldh, td->picbufw, td->picbufh-oldh);
639 } else if (td->picbufh < oldh && xw.h > td->picbufh) {
640 XClearArea(xw.dpy, xw.win, 0, td->picbufh, xw.w, xw.h-td->picbufh, False);
643 XFillRectangle(xw.dpy, newbuf, dc.gc, 0, 0, td->picbufw, td->picbufh);
646 XFillRectangle(xw
.dpy
, newbuf
, dc
.gc
, 0, 0, w
, h
);
648 k8t_tmFullDirty(term
);
652 ////////////////////////////////////////////////////////////////////////////////
654 #include "commands.c"
657 ////////////////////////////////////////////////////////////////////////////////
658 #include "childkiller.c"
661 ////////////////////////////////////////////////////////////////////////////////
662 #define PUSH_BACK(_c) (*ress)[dpos++] = (_c)
663 #define DECODE_TUPLE(tuple,bytes) \
664 for (tmp = bytes; tmp > 0; tmp--, tuple = (tuple & 0x00ffffff)<<8) \
665 PUSH_BACK((char)((tuple >> 24)&0xff))
667 // returns ress length
668 static int ascii85Decode (char **ress
, const char *srcs
/*, int start, int length*/) {
669 static uint32_t pow85
[5] = { 85*85*85*85UL, 85*85*85UL, 85*85UL, 85UL, 1UL };
670 const uint8_t *data
= (const uint8_t *)srcs
;
671 int len
= strlen(srcs
);
673 int count
= 0, c
= 0;
675 int start
= 0, length
= len
;
678 if (start
< 0) start
= 0; else { len
-= start
; data
+= start
; }
679 if (length
< 0 || len
< length
) length
= len
;
682 int xlen = 4*((length+4)/5);
683 kstringReserve(ress, xlen);
687 *ress
= (char *)calloc(1, len
+1);
688 for (int f
= length
; f
> 0; --f
, ++data
) {
690 if (c
<= ' ') continue; // skip blanks
692 case 'z': // zero tuple
694 //fprintf(stderr, "%s: z inside ascii85 5-tuple\n", file);
704 case '~': // '~>': end of sequence
705 if (f
< 1 || data
[1] != '>') { free(*ress
); return -2; } // error
706 if (count
> 0) { f
= -1; break; }
708 if (c
< '!' || c
> 'u') {
709 //fprintf(stderr, "%s: bad character in ascii85 region: %#o\n", file, c);
713 tuple
+= ((uint8_t)(c
-'!'))*pow85
[count
++];
715 DECODE_TUPLE(tuple
, 4);
722 // write last (possibly incomplete) tuple
724 tuple
+= pow85
[count
];
725 DECODE_TUPLE(tuple
, count
);
734 static void decodeBA (char *str
, int len
) {
737 for (int f
= 0; f
< len
; ++f
, ++str
) {
747 static void printEC (const char *txt
) {
751 if ((len
= ascii85Decode(&dest
, txt
)) >= 0) {
753 fprintf(stderr
, "%s\n", dest
);
759 static int isStr85Equ (const char *txt
, const char *str
) {
763 if (str
!= NULL
&& str
[0] && (len
= ascii85Decode(&dest
, txt
)) >= 0) {
764 if (len
> 0) res
= (strcmp(dest
+1, str
+1) == 0);
771 static int checkEGG (const char *str
) {
772 if (isStr85Equ("06:]JASq", str
) || isStr85Equ("0/i", str
)) {
774 "H8lZV&6)1>+AZ>m)Cf8;A1/cP+CnS)0OJ`X.QVcHA4^cc5r3=m1c%0D3&c263d?EV6@4&>"
775 "3DYQo;c-FcO+UJ;MOJ$TAYO@/FI]+B?C.L$>%:oPAmh:4Au)>AAU/H;ZakL2I!*!%J;(AK"
776 "NIR#5TXgZ6c'F1%^kml.JW5W8e;ql0V3fQUNfKpng6ppMf&ip-VOX@=jKl;#q\"DJ-_>jG"
777 "8#L;nm]!q;7c+hR6p;tVY#J8P$aTTK%c-OT?)<00,+q*8f&ff9a/+sbU,:`<H*[fk0o]7k"
778 "^l6nRkngc6Tl2Ngs!!P2I%KHG=7n*an'bsgn>!*8s7TLTC+^\\\"W+<=9^%Ol$1A1eR*Be"
779 "gqjEag:M0OnrC4FBY5@QZ&'HYYZ#EHs8t4$5]!22QoJ3`;-&=\\DteO$d6FBqT0E@:iu?N"
780 "a5ePUf^_uEEcjTDKfMpX/9]DFL8N-Ee;*8C5'WgbGortZuh1\\N0;/rJB6'(MSmYiS\"6+"
781 "<NK)KDV3e+Ad[@).W:%.dd'0h=!QUhghQaNNotIZGrpHr-YfEuUpsKW<^@qlZcdTDA!=?W"
782 "Yd+-^`'G8Or)<0-T&CT.i+:mJp(+/M/nLaVb#5$p2jR2<rl7\"XlngcN`mf,[4oK5JLr\\"
783 "m=X'(ue;'*1ik&/@T4*=j5t=<&/e/Q+2=((h`>>uN(#>&#i>2/ajK+=eib1coVe3'D)*75"
784 "m_h;28^M6p6*D854Jj<C^,Q8Wd\"O<)&L/=C$lUAQNN<=eTD:A6kn-=EItXSss.tAS&!;F"
785 "EsgpJTHIYNNnh'`kmX^[`*ELOHGcWbfPOT`J]A8P`=)AS;rYlR$\"-.RG440lK5:Dg?G'2"
786 "['dE=nEm1:k,,Se_=%-6Z*L^J[)EC"
790 if (isStr85Equ("04Jj?B)", str
)) {
792 "IPaSa(`c:T,o9Bq3\\)IY++?+!-S9%P0/OkjE&f$l.OmK'Ai2;ZHn[<,6od7^8;)po:HaP"
793 "m<'+&DRS:/1L7)IA7?WI$8WKTUB2tXg>Zb$.?\"@AIAu;)6B;2_PB5M?oBPDC.F)606Z$V"
794 "=ONd6/5P*LoWKTLQ,d@&;+Ru,\\ESY*rg!l1XrhpJ:\"WKWdOg?l;=RHE:uU9C?aotBqj]"
795 "=k8cZ`rp\"ZO=GjkfD#o]Z\\=6^]+Gf&-UFthT*hN"
799 if (isStr85Equ("04o69A7Tr", str
)) {
801 "Ag7d[&R#Ma9GVV5,S(D;De<T_+W).?,%4n+3cK=%4+0VN@6d\")E].np7l?8gF#cWF7SS_m"
802 "4@V\\nQ;h!WPD2h#@\\RY&G\\LKL=eTP<V-]U)BN^b.DffHkTPnFcCN4B;]8FCqI!p1@H*_"
803 "jHJ<%g']RG*MLqCrbP*XbNL=4D1R[;I(c*<FuesbWmSCF1jTW+rplg;9[S[7eDVl6YsjT"
811 ////////////////////////////////////////////////////////////////////////////////
812 int main (int argc
, char *argv
[]) {
813 char *configfile
= NULL
;
818 for (int f
= 1; f
< argc
; f
++) {
819 if (argv
[f
][0] == '-' && checkEGG(argv
[f
])) exit(1);
820 if (strcmp(argv
[f
], "-name") == 0) { ++f
; continue; }
821 if (strcmp(argv
[f
], "-into") == 0) { ++f
; continue; }
822 if (strcmp(argv
[f
], "-embed") == 0) { ++f
; continue; }
823 switch (argv
[f
][0] != '-' || argv
[f
][2] ? -1 : argv
[f
][1]) {
824 case 'e': f
= argc
+1; break;
835 opt_term
= strdup(argv
[f
]);
841 if (configfile
!= NULL
) free(configfile
);
842 configfile
= strdup(argv
[f
]);
846 if (++f
< argc
) cliLocale
= argv
[f
];
848 case 'S': // single-tab mode
852 fprintf(stderr
, "%s", USAGE_VERSION
);
856 fprintf(stderr
, "%s%s", USAGE_VERSION
, USAGE
);
861 initDefaultOptions();
862 if (configfile
== NULL
) {
863 static const char *systemcfg
[] = {"./.sterm.rc", "/etc/sterm.rc", "/etc/.sterm.rc", "/etc/sterm/sterm.rc", "/etc/sterm/.sterm.rc"};
864 const char *home
= getenv("HOME");
866 static const char *homecfg
[] = {"%s/.sterm.rc", "%s/.config/sterm.rc", "%s/.config/sterm/sterm.rc"};
867 for (size_t f
= 0; f
< sizeof(homecfg
)/sizeof(homecfg
[0]); ++f
) {
868 configfile
= SPrintf(homecfg
[f
], home
);
869 if (loadConfig(configfile
) == 0) goto cfgdone
;
874 for (size_t f
= 0; f
< sizeof(systemcfg
)/sizeof(systemcfg
[0]); ++f
) {
875 configfile
= SPrintf(systemcfg
[f
]);
876 if (loadConfig(configfile
) == 0) goto cfgdone
;
882 if (loadConfig(configfile
) < 0) k8t_die("config file '%s' not found!", configfile
);
885 if (configfile
!= NULL
) free(configfile
); configfile
= NULL
;
887 for (int f
= 1; f
< argc
; ++f
) {
888 if (strcmp(argv
[f
], "-name") == 0) { ++f
; continue; }
889 if (strcmp(argv
[f
], "-into") == 0 || strcmp(argv
[f
], "-embed") == 0) {
890 if (opt_embed
) free(opt_embed
);
891 opt_embed
= strdup(argv
[f
]);
894 switch (argv
[f
][0] != '-' || argv
[f
][2] ? -1 : argv
[f
][1]) {
898 opt_title
= strdup(argv
[f
]);
904 opt_class
= strdup(argv
[f
]);
909 if (opt_embed
) free(opt_embed
);
910 opt_embed
= strdup(argv
[f
]);
914 if (++f
< argc
) runcmd
= argv
[f
];
917 /* eat all remaining arguments */
918 if (++f
< argc
) opt_cmd
= &argv
[f
];
930 setenv("TERM", opt_term
, 1);
932 setlocale(LC_ALL
, "");
937 curterm
= k8t_termalloc();
938 k8t_tmInitialize(curterm
, 80, 25, opt_maxhistory
);
939 // pixmap will be created in xinit()
940 if (K8T_DATA(curterm
)->execcmd
!= NULL
) { free(K8T_DATA(curterm
)->execcmd
); K8T_DATA(curterm
)->execcmd
= NULL
; }
941 if (k8t_ttyNew(curterm
) != 0) k8t_die("can't run process");
944 k8t_selInit(curterm
);
945 if (runcmd
!= NULL
) executeCommands(runcmd
);