"Fossies" - the Fresh Open Source Software Archive

Member "xtermcontrol-3.8/src/xtermcontrol.c" (30 Mar 2019, 71354 Bytes) of package /linux/privat/xtermcontrol-3.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "xtermcontrol.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.7_vs_3.8.

    1 /****************************************************************************
    2 ** $Id: xtermcontrol.c,v 1.33 2002/10/26 17:20:36 jet Exp $
    3 **
    4 ** Copyright (C) 2002-2013 Jess Thrysoee <jess@thrysoee.dk>
    5 **
    6 ** This program is free software; you can redistribute it and/or modify
    7 ** it under the terms of the GNU General Public License as published by
    8 ** the Free Software Foundation; either version 2 of the License, or
    9 ** (at your option) any later version.
   10 **
   11 ***************************************************************************  */
   12 
   13 #include <config.h>
   14 
   15 #include <assert.h>
   16 #include <errno.h>
   17 #include <stdio.h>
   18 #include <stdlib.h>
   19 #include <string.h>
   20 #include <termios.h>
   21 #include <unistd.h>
   22 
   23 #include "configuration.h"
   24 #include "controlseq.h"
   25 #include "getopt.h"
   26 #include "xtermcontrol.h"
   27 
   28 /* The name the program was run with, stripped of any leading path. */
   29 static char *program_name;
   30 
   31 static char temp[BUFSIZ];
   32 
   33 /* controlling terminal fps and descriptor */
   34 static FILE *ctty;
   35 static FILE *tty_in;
   36 static FILE *tty_out;
   37 static int TTY_FILENO;
   38 
   39 /* termios settings */
   40 static struct termios tty_ts;
   41 static struct termios tty_ts_orig;
   42 static struct termios *tty_ts_orig_pt = NULL;
   43 
   44 /*=****************************************************************************
   45 **
   46 ** DESCRIPTION :
   47 **
   48 ** RETURN VALUE:
   49 **                                                                           */
   50 /*=***************************************************************************/
   51 int main(int argc, char **argv)
   52 {
   53     unsigned i;
   54     int c,
   55         ctl1,
   56         ctl2,
   57         type;
   58     int has_options = 0;
   59     int force = 0;
   60     int verbose = 0;
   61     int configuration_missing = 0;
   62     char *text = NULL;
   63     char configuration_file[BUFSIZ];
   64 
   65     configuration list;              /* configuration linked list                 */
   66     const configuration_element *lp; /* configuration linked list element     */
   67 
   68     program_name = argv[0];
   69     if (program_name && strrchr(program_name, '/'))
   70     {
   71         program_name = strrchr(program_name, '/') + 1;
   72     }
   73 
   74     configuration_file[0] = '\0';
   75 
   76     while (1)
   77     {
   78         static int a = -1;
   79         int longindex = 0;
   80 
   81         static struct option longopts[] =
   82             {
   83                 {"fg", 1, &a, FG},
   84                 {"bg", 1, &a, BG},
   85                 {"color0", 1, &a, COLOR_0},
   86                 {"color1", 1, &a, COLOR_1},
   87                 {"color2", 1, &a, COLOR_2},
   88                 {"color3", 1, &a, COLOR_3},
   89                 {"color4", 1, &a, COLOR_4},
   90                 {"color5", 1, &a, COLOR_5},
   91                 {"color6", 1, &a, COLOR_6},
   92                 {"color7", 1, &a, COLOR_7},
   93                 {"color8", 1, &a, COLOR_8},
   94                 {"color9", 1, &a, COLOR_9},
   95                 {"color10", 1, &a, COLOR_10},
   96                 {"color11", 1, &a, COLOR_11},
   97                 {"color12", 1, &a, COLOR_12},
   98                 {"color13", 1, &a, COLOR_13},
   99                 {"color14", 1, &a, COLOR_14},
  100                 {"color15", 1, &a, COLOR_15},
  101                 {"color16", 1, &a, COLOR_16},
  102                 {"color17", 1, &a, COLOR_17},
  103                 {"color18", 1, &a, COLOR_18},
  104                 {"color19", 1, &a, COLOR_19},
  105                 {"color20", 1, &a, COLOR_20},
  106                 {"color21", 1, &a, COLOR_21},
  107                 {"color22", 1, &a, COLOR_22},
  108                 {"color23", 1, &a, COLOR_23},
  109                 {"color24", 1, &a, COLOR_24},
  110                 {"color25", 1, &a, COLOR_25},
  111                 {"color26", 1, &a, COLOR_26},
  112                 {"color27", 1, &a, COLOR_27},
  113                 {"color28", 1, &a, COLOR_28},
  114                 {"color29", 1, &a, COLOR_29},
  115                 {"color30", 1, &a, COLOR_30},
  116                 {"color31", 1, &a, COLOR_31},
  117                 {"color32", 1, &a, COLOR_32},
  118                 {"color33", 1, &a, COLOR_33},
  119                 {"color34", 1, &a, COLOR_34},
  120                 {"color35", 1, &a, COLOR_35},
  121                 {"color36", 1, &a, COLOR_36},
  122                 {"color37", 1, &a, COLOR_37},
  123                 {"color38", 1, &a, COLOR_38},
  124                 {"color39", 1, &a, COLOR_39},
  125                 {"color40", 1, &a, COLOR_40},
  126                 {"color41", 1, &a, COLOR_41},
  127                 {"color42", 1, &a, COLOR_42},
  128                 {"color43", 1, &a, COLOR_43},
  129                 {"color44", 1, &a, COLOR_44},
  130                 {"color45", 1, &a, COLOR_45},
  131                 {"color46", 1, &a, COLOR_46},
  132                 {"color47", 1, &a, COLOR_47},
  133                 {"color48", 1, &a, COLOR_48},
  134                 {"color49", 1, &a, COLOR_49},
  135                 {"color50", 1, &a, COLOR_50},
  136                 {"color51", 1, &a, COLOR_51},
  137                 {"color52", 1, &a, COLOR_52},
  138                 {"color53", 1, &a, COLOR_53},
  139                 {"color54", 1, &a, COLOR_54},
  140                 {"color55", 1, &a, COLOR_55},
  141                 {"color56", 1, &a, COLOR_56},
  142                 {"color57", 1, &a, COLOR_57},
  143                 {"color58", 1, &a, COLOR_58},
  144                 {"color59", 1, &a, COLOR_59},
  145                 {"color60", 1, &a, COLOR_60},
  146                 {"color61", 1, &a, COLOR_61},
  147                 {"color62", 1, &a, COLOR_62},
  148                 {"color63", 1, &a, COLOR_63},
  149                 {"color64", 1, &a, COLOR_64},
  150                 {"color65", 1, &a, COLOR_65},
  151                 {"color66", 1, &a, COLOR_66},
  152                 {"color67", 1, &a, COLOR_67},
  153                 {"color68", 1, &a, COLOR_68},
  154                 {"color69", 1, &a, COLOR_69},
  155                 {"color70", 1, &a, COLOR_70},
  156                 {"color71", 1, &a, COLOR_71},
  157                 {"color72", 1, &a, COLOR_72},
  158                 {"color73", 1, &a, COLOR_73},
  159                 {"color74", 1, &a, COLOR_74},
  160                 {"color75", 1, &a, COLOR_75},
  161                 {"color76", 1, &a, COLOR_76},
  162                 {"color77", 1, &a, COLOR_77},
  163                 {"color78", 1, &a, COLOR_78},
  164                 {"color79", 1, &a, COLOR_79},
  165                 {"color80", 1, &a, COLOR_80},
  166                 {"color81", 1, &a, COLOR_81},
  167                 {"color82", 1, &a, COLOR_82},
  168                 {"color83", 1, &a, COLOR_83},
  169                 {"color84", 1, &a, COLOR_84},
  170                 {"color85", 1, &a, COLOR_85},
  171                 {"color86", 1, &a, COLOR_86},
  172                 {"color87", 1, &a, COLOR_87},
  173                 {"color88", 1, &a, COLOR_88},
  174                 {"color89", 1, &a, COLOR_89},
  175                 {"color90", 1, &a, COLOR_90},
  176                 {"color91", 1, &a, COLOR_91},
  177                 {"color92", 1, &a, COLOR_92},
  178                 {"color93", 1, &a, COLOR_93},
  179                 {"color94", 1, &a, COLOR_94},
  180                 {"color95", 1, &a, COLOR_95},
  181                 {"color96", 1, &a, COLOR_96},
  182                 {"color97", 1, &a, COLOR_97},
  183                 {"color98", 1, &a, COLOR_98},
  184                 {"color99", 1, &a, COLOR_99},
  185                 {"color100", 1, &a, COLOR_100},
  186                 {"color101", 1, &a, COLOR_101},
  187                 {"color102", 1, &a, COLOR_102},
  188                 {"color103", 1, &a, COLOR_103},
  189                 {"color104", 1, &a, COLOR_104},
  190                 {"color105", 1, &a, COLOR_105},
  191                 {"color106", 1, &a, COLOR_106},
  192                 {"color107", 1, &a, COLOR_107},
  193                 {"color108", 1, &a, COLOR_108},
  194                 {"color109", 1, &a, COLOR_109},
  195                 {"color110", 1, &a, COLOR_110},
  196                 {"color111", 1, &a, COLOR_111},
  197                 {"color112", 1, &a, COLOR_112},
  198                 {"color113", 1, &a, COLOR_113},
  199                 {"color114", 1, &a, COLOR_114},
  200                 {"color115", 1, &a, COLOR_115},
  201                 {"color116", 1, &a, COLOR_116},
  202                 {"color117", 1, &a, COLOR_117},
  203                 {"color118", 1, &a, COLOR_118},
  204                 {"color119", 1, &a, COLOR_119},
  205                 {"color120", 1, &a, COLOR_120},
  206                 {"color121", 1, &a, COLOR_121},
  207                 {"color122", 1, &a, COLOR_122},
  208                 {"color123", 1, &a, COLOR_123},
  209                 {"color124", 1, &a, COLOR_124},
  210                 {"color125", 1, &a, COLOR_125},
  211                 {"color126", 1, &a, COLOR_126},
  212                 {"color127", 1, &a, COLOR_127},
  213                 {"color128", 1, &a, COLOR_128},
  214                 {"color129", 1, &a, COLOR_129},
  215                 {"color130", 1, &a, COLOR_130},
  216                 {"color131", 1, &a, COLOR_131},
  217                 {"color132", 1, &a, COLOR_132},
  218                 {"color133", 1, &a, COLOR_133},
  219                 {"color134", 1, &a, COLOR_134},
  220                 {"color135", 1, &a, COLOR_135},
  221                 {"color136", 1, &a, COLOR_136},
  222                 {"color137", 1, &a, COLOR_137},
  223                 {"color138", 1, &a, COLOR_138},
  224                 {"color139", 1, &a, COLOR_139},
  225                 {"color140", 1, &a, COLOR_140},
  226                 {"color141", 1, &a, COLOR_141},
  227                 {"color142", 1, &a, COLOR_142},
  228                 {"color143", 1, &a, COLOR_143},
  229                 {"color144", 1, &a, COLOR_144},
  230                 {"color145", 1, &a, COLOR_145},
  231                 {"color146", 1, &a, COLOR_146},
  232                 {"color147", 1, &a, COLOR_147},
  233                 {"color148", 1, &a, COLOR_148},
  234                 {"color149", 1, &a, COLOR_149},
  235                 {"color150", 1, &a, COLOR_150},
  236                 {"color151", 1, &a, COLOR_151},
  237                 {"color152", 1, &a, COLOR_152},
  238                 {"color153", 1, &a, COLOR_153},
  239                 {"color154", 1, &a, COLOR_154},
  240                 {"color155", 1, &a, COLOR_155},
  241                 {"color156", 1, &a, COLOR_156},
  242                 {"color157", 1, &a, COLOR_157},
  243                 {"color158", 1, &a, COLOR_158},
  244                 {"color159", 1, &a, COLOR_159},
  245                 {"color160", 1, &a, COLOR_160},
  246                 {"color161", 1, &a, COLOR_161},
  247                 {"color162", 1, &a, COLOR_162},
  248                 {"color163", 1, &a, COLOR_163},
  249                 {"color164", 1, &a, COLOR_164},
  250                 {"color165", 1, &a, COLOR_165},
  251                 {"color166", 1, &a, COLOR_166},
  252                 {"color167", 1, &a, COLOR_167},
  253                 {"color168", 1, &a, COLOR_168},
  254                 {"color169", 1, &a, COLOR_169},
  255                 {"color170", 1, &a, COLOR_170},
  256                 {"color171", 1, &a, COLOR_171},
  257                 {"color172", 1, &a, COLOR_172},
  258                 {"color173", 1, &a, COLOR_173},
  259                 {"color174", 1, &a, COLOR_174},
  260                 {"color175", 1, &a, COLOR_175},
  261                 {"color176", 1, &a, COLOR_176},
  262                 {"color177", 1, &a, COLOR_177},
  263                 {"color178", 1, &a, COLOR_178},
  264                 {"color179", 1, &a, COLOR_179},
  265                 {"color180", 1, &a, COLOR_180},
  266                 {"color181", 1, &a, COLOR_181},
  267                 {"color182", 1, &a, COLOR_182},
  268                 {"color183", 1, &a, COLOR_183},
  269                 {"color184", 1, &a, COLOR_184},
  270                 {"color185", 1, &a, COLOR_185},
  271                 {"color186", 1, &a, COLOR_186},
  272                 {"color187", 1, &a, COLOR_187},
  273                 {"color188", 1, &a, COLOR_188},
  274                 {"color189", 1, &a, COLOR_189},
  275                 {"color190", 1, &a, COLOR_190},
  276                 {"color191", 1, &a, COLOR_191},
  277                 {"color192", 1, &a, COLOR_192},
  278                 {"color193", 1, &a, COLOR_193},
  279                 {"color194", 1, &a, COLOR_194},
  280                 {"color195", 1, &a, COLOR_195},
  281                 {"color196", 1, &a, COLOR_196},
  282                 {"color197", 1, &a, COLOR_197},
  283                 {"color198", 1, &a, COLOR_198},
  284                 {"color199", 1, &a, COLOR_199},
  285                 {"color200", 1, &a, COLOR_200},
  286                 {"color201", 1, &a, COLOR_201},
  287                 {"color202", 1, &a, COLOR_202},
  288                 {"color203", 1, &a, COLOR_203},
  289                 {"color204", 1, &a, COLOR_204},
  290                 {"color205", 1, &a, COLOR_205},
  291                 {"color206", 1, &a, COLOR_206},
  292                 {"color207", 1, &a, COLOR_207},
  293                 {"color208", 1, &a, COLOR_208},
  294                 {"color209", 1, &a, COLOR_209},
  295                 {"color210", 1, &a, COLOR_210},
  296                 {"color211", 1, &a, COLOR_211},
  297                 {"color212", 1, &a, COLOR_212},
  298                 {"color213", 1, &a, COLOR_213},
  299                 {"color214", 1, &a, COLOR_214},
  300                 {"color215", 1, &a, COLOR_215},
  301                 {"color216", 1, &a, COLOR_216},
  302                 {"color217", 1, &a, COLOR_217},
  303                 {"color218", 1, &a, COLOR_218},
  304                 {"color219", 1, &a, COLOR_219},
  305                 {"color220", 1, &a, COLOR_220},
  306                 {"color221", 1, &a, COLOR_221},
  307                 {"color222", 1, &a, COLOR_222},
  308                 {"color223", 1, &a, COLOR_223},
  309                 {"color224", 1, &a, COLOR_224},
  310                 {"color225", 1, &a, COLOR_225},
  311                 {"color226", 1, &a, COLOR_226},
  312                 {"color227", 1, &a, COLOR_227},
  313                 {"color228", 1, &a, COLOR_228},
  314                 {"color229", 1, &a, COLOR_229},
  315                 {"color230", 1, &a, COLOR_230},
  316                 {"color231", 1, &a, COLOR_231},
  317                 {"color232", 1, &a, COLOR_232},
  318                 {"color233", 1, &a, COLOR_233},
  319                 {"color234", 1, &a, COLOR_234},
  320                 {"color235", 1, &a, COLOR_235},
  321                 {"color236", 1, &a, COLOR_236},
  322                 {"color237", 1, &a, COLOR_237},
  323                 {"color238", 1, &a, COLOR_238},
  324                 {"color239", 1, &a, COLOR_239},
  325                 {"color240", 1, &a, COLOR_240},
  326                 {"color241", 1, &a, COLOR_241},
  327                 {"color242", 1, &a, COLOR_242},
  328                 {"color243", 1, &a, COLOR_243},
  329                 {"color244", 1, &a, COLOR_244},
  330                 {"color245", 1, &a, COLOR_245},
  331                 {"color246", 1, &a, COLOR_246},
  332                 {"color247", 1, &a, COLOR_247},
  333                 {"color248", 1, &a, COLOR_248},
  334                 {"color249", 1, &a, COLOR_249},
  335                 {"color250", 1, &a, COLOR_250},
  336                 {"color251", 1, &a, COLOR_251},
  337                 {"color252", 1, &a, COLOR_252},
  338                 {"color253", 1, &a, COLOR_253},
  339                 {"color254", 1, &a, COLOR_254},
  340                 {"color255", 1, &a, COLOR_255},
  341                 {"highlight", 1, &a, COLOR_HL},
  342                 {"cursor", 1, &a, CURSOR},
  343                 {"mouse-fg", 1, &a, MOUSE_FG},
  344                 {"mouse-bg", 1, &a, MOUSE_BG},
  345                 {"font", 1, &a, FONT},
  346                 {"title", 1, &a, TITLE},
  347                 {"geometry", 1, &a, GEOMETRY},
  348                 {"get-fg", 0, &a, GET_FG},
  349                 {"get-bg", 0, &a, GET_BG},
  350                 {"get-color0", 0, &a, GET_COLOR_0},
  351                 {"get-color1", 0, &a, GET_COLOR_1},
  352                 {"get-color2", 0, &a, GET_COLOR_2},
  353                 {"get-color3", 0, &a, GET_COLOR_3},
  354                 {"get-color4", 0, &a, GET_COLOR_4},
  355                 {"get-color5", 0, &a, GET_COLOR_5},
  356                 {"get-color6", 0, &a, GET_COLOR_6},
  357                 {"get-color7", 0, &a, GET_COLOR_7},
  358                 {"get-color8", 0, &a, GET_COLOR_8},
  359                 {"get-color9", 0, &a, GET_COLOR_9},
  360                 {"get-color10", 0, &a, GET_COLOR_10},
  361                 {"get-color11", 0, &a, GET_COLOR_11},
  362                 {"get-color12", 0, &a, GET_COLOR_12},
  363                 {"get-color13", 0, &a, GET_COLOR_13},
  364                 {"get-color14", 0, &a, GET_COLOR_14},
  365                 {"get-color15", 0, &a, GET_COLOR_15},
  366                 {"get-color16", 0, &a, GET_COLOR_16},
  367                 {"get-color17", 0, &a, GET_COLOR_17},
  368                 {"get-color18", 0, &a, GET_COLOR_18},
  369                 {"get-color19", 0, &a, GET_COLOR_19},
  370                 {"get-color20", 0, &a, GET_COLOR_20},
  371                 {"get-color21", 0, &a, GET_COLOR_21},
  372                 {"get-color22", 0, &a, GET_COLOR_22},
  373                 {"get-color23", 0, &a, GET_COLOR_23},
  374                 {"get-color24", 0, &a, GET_COLOR_24},
  375                 {"get-color25", 0, &a, GET_COLOR_25},
  376                 {"get-color26", 0, &a, GET_COLOR_26},
  377                 {"get-color27", 0, &a, GET_COLOR_27},
  378                 {"get-color28", 0, &a, GET_COLOR_28},
  379                 {"get-color29", 0, &a, GET_COLOR_29},
  380                 {"get-color30", 0, &a, GET_COLOR_30},
  381                 {"get-color31", 0, &a, GET_COLOR_31},
  382                 {"get-color32", 0, &a, GET_COLOR_32},
  383                 {"get-color33", 0, &a, GET_COLOR_33},
  384                 {"get-color34", 0, &a, GET_COLOR_34},
  385                 {"get-color35", 0, &a, GET_COLOR_35},
  386                 {"get-color36", 0, &a, GET_COLOR_36},
  387                 {"get-color37", 0, &a, GET_COLOR_37},
  388                 {"get-color38", 0, &a, GET_COLOR_38},
  389                 {"get-color39", 0, &a, GET_COLOR_39},
  390                 {"get-color40", 0, &a, GET_COLOR_40},
  391                 {"get-color41", 0, &a, GET_COLOR_41},
  392                 {"get-color42", 0, &a, GET_COLOR_42},
  393                 {"get-color43", 0, &a, GET_COLOR_43},
  394                 {"get-color44", 0, &a, GET_COLOR_44},
  395                 {"get-color45", 0, &a, GET_COLOR_45},
  396                 {"get-color46", 0, &a, GET_COLOR_46},
  397                 {"get-color47", 0, &a, GET_COLOR_47},
  398                 {"get-color48", 0, &a, GET_COLOR_48},
  399                 {"get-color49", 0, &a, GET_COLOR_49},
  400                 {"get-color50", 0, &a, GET_COLOR_50},
  401                 {"get-color51", 0, &a, GET_COLOR_51},
  402                 {"get-color52", 0, &a, GET_COLOR_52},
  403                 {"get-color53", 0, &a, GET_COLOR_53},
  404                 {"get-color54", 0, &a, GET_COLOR_54},
  405                 {"get-color55", 0, &a, GET_COLOR_55},
  406                 {"get-color56", 0, &a, GET_COLOR_56},
  407                 {"get-color57", 0, &a, GET_COLOR_57},
  408                 {"get-color58", 0, &a, GET_COLOR_58},
  409                 {"get-color59", 0, &a, GET_COLOR_59},
  410                 {"get-color60", 0, &a, GET_COLOR_60},
  411                 {"get-color61", 0, &a, GET_COLOR_61},
  412                 {"get-color62", 0, &a, GET_COLOR_62},
  413                 {"get-color63", 0, &a, GET_COLOR_63},
  414                 {"get-color64", 0, &a, GET_COLOR_64},
  415                 {"get-color65", 0, &a, GET_COLOR_65},
  416                 {"get-color66", 0, &a, GET_COLOR_66},
  417                 {"get-color67", 0, &a, GET_COLOR_67},
  418                 {"get-color68", 0, &a, GET_COLOR_68},
  419                 {"get-color69", 0, &a, GET_COLOR_69},
  420                 {"get-color70", 0, &a, GET_COLOR_70},
  421                 {"get-color71", 0, &a, GET_COLOR_71},
  422                 {"get-color72", 0, &a, GET_COLOR_72},
  423                 {"get-color73", 0, &a, GET_COLOR_73},
  424                 {"get-color74", 0, &a, GET_COLOR_74},
  425                 {"get-color75", 0, &a, GET_COLOR_75},
  426                 {"get-color76", 0, &a, GET_COLOR_76},
  427                 {"get-color77", 0, &a, GET_COLOR_77},
  428                 {"get-color78", 0, &a, GET_COLOR_78},
  429                 {"get-color79", 0, &a, GET_COLOR_79},
  430                 {"get-color80", 0, &a, GET_COLOR_80},
  431                 {"get-color81", 0, &a, GET_COLOR_81},
  432                 {"get-color82", 0, &a, GET_COLOR_82},
  433                 {"get-color83", 0, &a, GET_COLOR_83},
  434                 {"get-color84", 0, &a, GET_COLOR_84},
  435                 {"get-color85", 0, &a, GET_COLOR_85},
  436                 {"get-color86", 0, &a, GET_COLOR_86},
  437                 {"get-color87", 0, &a, GET_COLOR_87},
  438                 {"get-color88", 0, &a, GET_COLOR_88},
  439                 {"get-color89", 0, &a, GET_COLOR_89},
  440                 {"get-color90", 0, &a, GET_COLOR_90},
  441                 {"get-color91", 0, &a, GET_COLOR_91},
  442                 {"get-color92", 0, &a, GET_COLOR_92},
  443                 {"get-color93", 0, &a, GET_COLOR_93},
  444                 {"get-color94", 0, &a, GET_COLOR_94},
  445                 {"get-color95", 0, &a, GET_COLOR_95},
  446                 {"get-color96", 0, &a, GET_COLOR_96},
  447                 {"get-color97", 0, &a, GET_COLOR_97},
  448                 {"get-color98", 0, &a, GET_COLOR_98},
  449                 {"get-color99", 0, &a, GET_COLOR_99},
  450                 {"get-color100", 0, &a, GET_COLOR_100},
  451                 {"get-color101", 0, &a, GET_COLOR_101},
  452                 {"get-color102", 0, &a, GET_COLOR_102},
  453                 {"get-color103", 0, &a, GET_COLOR_103},
  454                 {"get-color104", 0, &a, GET_COLOR_104},
  455                 {"get-color105", 0, &a, GET_COLOR_105},
  456                 {"get-color106", 0, &a, GET_COLOR_106},
  457                 {"get-color107", 0, &a, GET_COLOR_107},
  458                 {"get-color108", 0, &a, GET_COLOR_108},
  459                 {"get-color109", 0, &a, GET_COLOR_109},
  460                 {"get-color110", 0, &a, GET_COLOR_110},
  461                 {"get-color111", 0, &a, GET_COLOR_111},
  462                 {"get-color112", 0, &a, GET_COLOR_112},
  463                 {"get-color113", 0, &a, GET_COLOR_113},
  464                 {"get-color114", 0, &a, GET_COLOR_114},
  465                 {"get-color115", 0, &a, GET_COLOR_115},
  466                 {"get-color116", 0, &a, GET_COLOR_116},
  467                 {"get-color117", 0, &a, GET_COLOR_117},
  468                 {"get-color118", 0, &a, GET_COLOR_118},
  469                 {"get-color119", 0, &a, GET_COLOR_119},
  470                 {"get-color120", 0, &a, GET_COLOR_120},
  471                 {"get-color121", 0, &a, GET_COLOR_121},
  472                 {"get-color122", 0, &a, GET_COLOR_122},
  473                 {"get-color123", 0, &a, GET_COLOR_123},
  474                 {"get-color124", 0, &a, GET_COLOR_124},
  475                 {"get-color125", 0, &a, GET_COLOR_125},
  476                 {"get-color126", 0, &a, GET_COLOR_126},
  477                 {"get-color127", 0, &a, GET_COLOR_127},
  478                 {"get-color128", 0, &a, GET_COLOR_128},
  479                 {"get-color129", 0, &a, GET_COLOR_129},
  480                 {"get-color130", 0, &a, GET_COLOR_130},
  481                 {"get-color131", 0, &a, GET_COLOR_131},
  482                 {"get-color132", 0, &a, GET_COLOR_132},
  483                 {"get-color133", 0, &a, GET_COLOR_133},
  484                 {"get-color134", 0, &a, GET_COLOR_134},
  485                 {"get-color135", 0, &a, GET_COLOR_135},
  486                 {"get-color136", 0, &a, GET_COLOR_136},
  487                 {"get-color137", 0, &a, GET_COLOR_137},
  488                 {"get-color138", 0, &a, GET_COLOR_138},
  489                 {"get-color139", 0, &a, GET_COLOR_139},
  490                 {"get-color140", 0, &a, GET_COLOR_140},
  491                 {"get-color141", 0, &a, GET_COLOR_141},
  492                 {"get-color142", 0, &a, GET_COLOR_142},
  493                 {"get-color143", 0, &a, GET_COLOR_143},
  494                 {"get-color144", 0, &a, GET_COLOR_144},
  495                 {"get-color145", 0, &a, GET_COLOR_145},
  496                 {"get-color146", 0, &a, GET_COLOR_146},
  497                 {"get-color147", 0, &a, GET_COLOR_147},
  498                 {"get-color148", 0, &a, GET_COLOR_148},
  499                 {"get-color149", 0, &a, GET_COLOR_149},
  500                 {"get-color150", 0, &a, GET_COLOR_150},
  501                 {"get-color151", 0, &a, GET_COLOR_151},
  502                 {"get-color152", 0, &a, GET_COLOR_152},
  503                 {"get-color153", 0, &a, GET_COLOR_153},
  504                 {"get-color154", 0, &a, GET_COLOR_154},
  505                 {"get-color155", 0, &a, GET_COLOR_155},
  506                 {"get-color156", 0, &a, GET_COLOR_156},
  507                 {"get-color157", 0, &a, GET_COLOR_157},
  508                 {"get-color158", 0, &a, GET_COLOR_158},
  509                 {"get-color159", 0, &a, GET_COLOR_159},
  510                 {"get-color160", 0, &a, GET_COLOR_160},
  511                 {"get-color161", 0, &a, GET_COLOR_161},
  512                 {"get-color162", 0, &a, GET_COLOR_162},
  513                 {"get-color163", 0, &a, GET_COLOR_163},
  514                 {"get-color164", 0, &a, GET_COLOR_164},
  515                 {"get-color165", 0, &a, GET_COLOR_165},
  516                 {"get-color166", 0, &a, GET_COLOR_166},
  517                 {"get-color167", 0, &a, GET_COLOR_167},
  518                 {"get-color168", 0, &a, GET_COLOR_168},
  519                 {"get-color169", 0, &a, GET_COLOR_169},
  520                 {"get-color170", 0, &a, GET_COLOR_170},
  521                 {"get-color171", 0, &a, GET_COLOR_171},
  522                 {"get-color172", 0, &a, GET_COLOR_172},
  523                 {"get-color173", 0, &a, GET_COLOR_173},
  524                 {"get-color174", 0, &a, GET_COLOR_174},
  525                 {"get-color175", 0, &a, GET_COLOR_175},
  526                 {"get-color176", 0, &a, GET_COLOR_176},
  527                 {"get-color177", 0, &a, GET_COLOR_177},
  528                 {"get-color178", 0, &a, GET_COLOR_178},
  529                 {"get-color179", 0, &a, GET_COLOR_179},
  530                 {"get-color180", 0, &a, GET_COLOR_180},
  531                 {"get-color181", 0, &a, GET_COLOR_181},
  532                 {"get-color182", 0, &a, GET_COLOR_182},
  533                 {"get-color183", 0, &a, GET_COLOR_183},
  534                 {"get-color184", 0, &a, GET_COLOR_184},
  535                 {"get-color185", 0, &a, GET_COLOR_185},
  536                 {"get-color186", 0, &a, GET_COLOR_186},
  537                 {"get-color187", 0, &a, GET_COLOR_187},
  538                 {"get-color188", 0, &a, GET_COLOR_188},
  539                 {"get-color189", 0, &a, GET_COLOR_189},
  540                 {"get-color190", 0, &a, GET_COLOR_190},
  541                 {"get-color191", 0, &a, GET_COLOR_191},
  542                 {"get-color192", 0, &a, GET_COLOR_192},
  543                 {"get-color193", 0, &a, GET_COLOR_193},
  544                 {"get-color194", 0, &a, GET_COLOR_194},
  545                 {"get-color195", 0, &a, GET_COLOR_195},
  546                 {"get-color196", 0, &a, GET_COLOR_196},
  547                 {"get-color197", 0, &a, GET_COLOR_197},
  548                 {"get-color198", 0, &a, GET_COLOR_198},
  549                 {"get-color199", 0, &a, GET_COLOR_199},
  550                 {"get-color200", 0, &a, GET_COLOR_200},
  551                 {"get-color201", 0, &a, GET_COLOR_201},
  552                 {"get-color202", 0, &a, GET_COLOR_202},
  553                 {"get-color203", 0, &a, GET_COLOR_203},
  554                 {"get-color204", 0, &a, GET_COLOR_204},
  555                 {"get-color205", 0, &a, GET_COLOR_205},
  556                 {"get-color206", 0, &a, GET_COLOR_206},
  557                 {"get-color207", 0, &a, GET_COLOR_207},
  558                 {"get-color208", 0, &a, GET_COLOR_208},
  559                 {"get-color209", 0, &a, GET_COLOR_209},
  560                 {"get-color210", 0, &a, GET_COLOR_210},
  561                 {"get-color211", 0, &a, GET_COLOR_211},
  562                 {"get-color212", 0, &a, GET_COLOR_212},
  563                 {"get-color213", 0, &a, GET_COLOR_213},
  564                 {"get-color214", 0, &a, GET_COLOR_214},
  565                 {"get-color215", 0, &a, GET_COLOR_215},
  566                 {"get-color216", 0, &a, GET_COLOR_216},
  567                 {"get-color217", 0, &a, GET_COLOR_217},
  568                 {"get-color218", 0, &a, GET_COLOR_218},
  569                 {"get-color219", 0, &a, GET_COLOR_219},
  570                 {"get-color220", 0, &a, GET_COLOR_220},
  571                 {"get-color221", 0, &a, GET_COLOR_221},
  572                 {"get-color222", 0, &a, GET_COLOR_222},
  573                 {"get-color223", 0, &a, GET_COLOR_223},
  574                 {"get-color224", 0, &a, GET_COLOR_224},
  575                 {"get-color225", 0, &a, GET_COLOR_225},
  576                 {"get-color226", 0, &a, GET_COLOR_226},
  577                 {"get-color227", 0, &a, GET_COLOR_227},
  578                 {"get-color228", 0, &a, GET_COLOR_228},
  579                 {"get-color229", 0, &a, GET_COLOR_229},
  580                 {"get-color230", 0, &a, GET_COLOR_230},
  581                 {"get-color231", 0, &a, GET_COLOR_231},
  582                 {"get-color232", 0, &a, GET_COLOR_232},
  583                 {"get-color233", 0, &a, GET_COLOR_233},
  584                 {"get-color234", 0, &a, GET_COLOR_234},
  585                 {"get-color235", 0, &a, GET_COLOR_235},
  586                 {"get-color236", 0, &a, GET_COLOR_236},
  587                 {"get-color237", 0, &a, GET_COLOR_237},
  588                 {"get-color238", 0, &a, GET_COLOR_238},
  589                 {"get-color239", 0, &a, GET_COLOR_239},
  590                 {"get-color240", 0, &a, GET_COLOR_240},
  591                 {"get-color241", 0, &a, GET_COLOR_241},
  592                 {"get-color242", 0, &a, GET_COLOR_242},
  593                 {"get-color243", 0, &a, GET_COLOR_243},
  594                 {"get-color244", 0, &a, GET_COLOR_244},
  595                 {"get-color245", 0, &a, GET_COLOR_245},
  596                 {"get-color246", 0, &a, GET_COLOR_246},
  597                 {"get-color247", 0, &a, GET_COLOR_247},
  598                 {"get-color248", 0, &a, GET_COLOR_248},
  599                 {"get-color249", 0, &a, GET_COLOR_249},
  600                 {"get-color250", 0, &a, GET_COLOR_250},
  601                 {"get-color251", 0, &a, GET_COLOR_251},
  602                 {"get-color252", 0, &a, GET_COLOR_252},
  603                 {"get-color253", 0, &a, GET_COLOR_253},
  604                 {"get-color254", 0, &a, GET_COLOR_254},
  605                 {"get-color255", 0, &a, GET_COLOR_255},
  606                 {"get-highlight", 0, &a, GET_COLOR_HL},
  607                 {"get-cursor", 0, &a, GET_CURSOR},
  608                 {"get-mouse-fg", 0, &a, GET_MOUSE_FG},
  609                 {"get-mouse-bg", 0, &a, GET_MOUSE_BG},
  610                 {"get-font", 0, &a, GET_FONT},
  611                 {"get-title", 0, &a, GET_TITLE},
  612                 {"get-geometry", 0, &a, GET_GEOMETRY},
  613                 {"maximize", 0, &a, MAXIMIZE},
  614                 {"restore", 0, &a, RESTORE},
  615                 {"iconify", 0, &a, ICONIFY},
  616                 {"de-iconify", 0, &a, DE_ICONIFY},
  617                 {"raise", 0, &a, RAISE},
  618                 {"lower", 0, &a, LOWER},
  619                 {"reset", 0, &a, RESET},
  620                 {"raw", 1, &a, RAW},
  621                 {"file", 1, &a, FILE_CONF},
  622                 {"force", 0, 0, 'f'},
  623                 {"verbose", 0, 0, 'v'},
  624                 {"version", 0, 0, 'u'},
  625                 {"help", 0, 0, 'h'},
  626                 {0, 0, 0, 0}};
  627 
  628         c = getopt_long(argc, argv, "+fvh", longopts, &longindex);
  629         if (c == -1)
  630         {
  631             break;
  632         }
  633 
  634         has_options = 1;
  635 
  636         switch (c)
  637         {
  638         case 'u':
  639             version();
  640 
  641         case 'h':
  642             usage(EXIT_SUCCESS);
  643 
  644         case 'v':
  645             verbose = 1;
  646             break;
  647 
  648         case 'f':
  649             force = 1;
  650             break;
  651 
  652         case 0:
  653             switch (a)
  654             {
  655             case FG:
  656             case BG:
  657             case COLOR_0:
  658             case COLOR_1:
  659             case COLOR_2:
  660             case COLOR_3:
  661             case COLOR_4:
  662             case COLOR_5:
  663             case COLOR_6:
  664             case COLOR_7:
  665             case COLOR_8:
  666             case COLOR_9:
  667             case COLOR_10:
  668             case COLOR_11:
  669             case COLOR_12:
  670             case COLOR_13:
  671             case COLOR_14:
  672             case COLOR_15:
  673             case COLOR_16:
  674             case COLOR_17:
  675             case COLOR_18:
  676             case COLOR_19:
  677             case COLOR_20:
  678             case COLOR_21:
  679             case COLOR_22:
  680             case COLOR_23:
  681             case COLOR_24:
  682             case COLOR_25:
  683             case COLOR_26:
  684             case COLOR_27:
  685             case COLOR_28:
  686             case COLOR_29:
  687             case COLOR_30:
  688             case COLOR_31:
  689             case COLOR_32:
  690             case COLOR_33:
  691             case COLOR_34:
  692             case COLOR_35:
  693             case COLOR_36:
  694             case COLOR_37:
  695             case COLOR_38:
  696             case COLOR_39:
  697             case COLOR_40:
  698             case COLOR_41:
  699             case COLOR_42:
  700             case COLOR_43:
  701             case COLOR_44:
  702             case COLOR_45:
  703             case COLOR_46:
  704             case COLOR_47:
  705             case COLOR_48:
  706             case COLOR_49:
  707             case COLOR_50:
  708             case COLOR_51:
  709             case COLOR_52:
  710             case COLOR_53:
  711             case COLOR_54:
  712             case COLOR_55:
  713             case COLOR_56:
  714             case COLOR_57:
  715             case COLOR_58:
  716             case COLOR_59:
  717             case COLOR_60:
  718             case COLOR_61:
  719             case COLOR_62:
  720             case COLOR_63:
  721             case COLOR_64:
  722             case COLOR_65:
  723             case COLOR_66:
  724             case COLOR_67:
  725             case COLOR_68:
  726             case COLOR_69:
  727             case COLOR_70:
  728             case COLOR_71:
  729             case COLOR_72:
  730             case COLOR_73:
  731             case COLOR_74:
  732             case COLOR_75:
  733             case COLOR_76:
  734             case COLOR_77:
  735             case COLOR_78:
  736             case COLOR_79:
  737             case COLOR_80:
  738             case COLOR_81:
  739             case COLOR_82:
  740             case COLOR_83:
  741             case COLOR_84:
  742             case COLOR_85:
  743             case COLOR_86:
  744             case COLOR_87:
  745             case COLOR_88:
  746             case COLOR_89:
  747             case COLOR_90:
  748             case COLOR_91:
  749             case COLOR_92:
  750             case COLOR_93:
  751             case COLOR_94:
  752             case COLOR_95:
  753             case COLOR_96:
  754             case COLOR_97:
  755             case COLOR_98:
  756             case COLOR_99:
  757             case COLOR_100:
  758             case COLOR_101:
  759             case COLOR_102:
  760             case COLOR_103:
  761             case COLOR_104:
  762             case COLOR_105:
  763             case COLOR_106:
  764             case COLOR_107:
  765             case COLOR_108:
  766             case COLOR_109:
  767             case COLOR_110:
  768             case COLOR_111:
  769             case COLOR_112:
  770             case COLOR_113:
  771             case COLOR_114:
  772             case COLOR_115:
  773             case COLOR_116:
  774             case COLOR_117:
  775             case COLOR_118:
  776             case COLOR_119:
  777             case COLOR_120:
  778             case COLOR_121:
  779             case COLOR_122:
  780             case COLOR_123:
  781             case COLOR_124:
  782             case COLOR_125:
  783             case COLOR_126:
  784             case COLOR_127:
  785             case COLOR_128:
  786             case COLOR_129:
  787             case COLOR_130:
  788             case COLOR_131:
  789             case COLOR_132:
  790             case COLOR_133:
  791             case COLOR_134:
  792             case COLOR_135:
  793             case COLOR_136:
  794             case COLOR_137:
  795             case COLOR_138:
  796             case COLOR_139:
  797             case COLOR_140:
  798             case COLOR_141:
  799             case COLOR_142:
  800             case COLOR_143:
  801             case COLOR_144:
  802             case COLOR_145:
  803             case COLOR_146:
  804             case COLOR_147:
  805             case COLOR_148:
  806             case COLOR_149:
  807             case COLOR_150:
  808             case COLOR_151:
  809             case COLOR_152:
  810             case COLOR_153:
  811             case COLOR_154:
  812             case COLOR_155:
  813             case COLOR_156:
  814             case COLOR_157:
  815             case COLOR_158:
  816             case COLOR_159:
  817             case COLOR_160:
  818             case COLOR_161:
  819             case COLOR_162:
  820             case COLOR_163:
  821             case COLOR_164:
  822             case COLOR_165:
  823             case COLOR_166:
  824             case COLOR_167:
  825             case COLOR_168:
  826             case COLOR_169:
  827             case COLOR_170:
  828             case COLOR_171:
  829             case COLOR_172:
  830             case COLOR_173:
  831             case COLOR_174:
  832             case COLOR_175:
  833             case COLOR_176:
  834             case COLOR_177:
  835             case COLOR_178:
  836             case COLOR_179:
  837             case COLOR_180:
  838             case COLOR_181:
  839             case COLOR_182:
  840             case COLOR_183:
  841             case COLOR_184:
  842             case COLOR_185:
  843             case COLOR_186:
  844             case COLOR_187:
  845             case COLOR_188:
  846             case COLOR_189:
  847             case COLOR_190:
  848             case COLOR_191:
  849             case COLOR_192:
  850             case COLOR_193:
  851             case COLOR_194:
  852             case COLOR_195:
  853             case COLOR_196:
  854             case COLOR_197:
  855             case COLOR_198:
  856             case COLOR_199:
  857             case COLOR_200:
  858             case COLOR_201:
  859             case COLOR_202:
  860             case COLOR_203:
  861             case COLOR_204:
  862             case COLOR_205:
  863             case COLOR_206:
  864             case COLOR_207:
  865             case COLOR_208:
  866             case COLOR_209:
  867             case COLOR_210:
  868             case COLOR_211:
  869             case COLOR_212:
  870             case COLOR_213:
  871             case COLOR_214:
  872             case COLOR_215:
  873             case COLOR_216:
  874             case COLOR_217:
  875             case COLOR_218:
  876             case COLOR_219:
  877             case COLOR_220:
  878             case COLOR_221:
  879             case COLOR_222:
  880             case COLOR_223:
  881             case COLOR_224:
  882             case COLOR_225:
  883             case COLOR_226:
  884             case COLOR_227:
  885             case COLOR_228:
  886             case COLOR_229:
  887             case COLOR_230:
  888             case COLOR_231:
  889             case COLOR_232:
  890             case COLOR_233:
  891             case COLOR_234:
  892             case COLOR_235:
  893             case COLOR_236:
  894             case COLOR_237:
  895             case COLOR_238:
  896             case COLOR_239:
  897             case COLOR_240:
  898             case COLOR_241:
  899             case COLOR_242:
  900             case COLOR_243:
  901             case COLOR_244:
  902             case COLOR_245:
  903             case COLOR_246:
  904             case COLOR_247:
  905             case COLOR_248:
  906             case COLOR_249:
  907             case COLOR_250:
  908             case COLOR_251:
  909             case COLOR_252:
  910             case COLOR_253:
  911             case COLOR_254:
  912             case COLOR_255:
  913             case COLOR_HL:
  914             case CURSOR:
  915             case MOUSE_FG:
  916             case MOUSE_BG:
  917             case FONT:
  918             case TITLE:
  919             case RAW:
  920                 ctlseqstab[a].text = optarg;
  921                 break;
  922             case GET_FG:
  923             case GET_BG:
  924             case GET_COLOR_0:
  925             case GET_COLOR_1:
  926             case GET_COLOR_2:
  927             case GET_COLOR_3:
  928             case GET_COLOR_4:
  929             case GET_COLOR_5:
  930             case GET_COLOR_6:
  931             case GET_COLOR_7:
  932             case GET_COLOR_8:
  933             case GET_COLOR_9:
  934             case GET_COLOR_10:
  935             case GET_COLOR_11:
  936             case GET_COLOR_12:
  937             case GET_COLOR_13:
  938             case GET_COLOR_14:
  939             case GET_COLOR_15:
  940             case GET_COLOR_16:
  941             case GET_COLOR_17:
  942             case GET_COLOR_18:
  943             case GET_COLOR_19:
  944             case GET_COLOR_20:
  945             case GET_COLOR_21:
  946             case GET_COLOR_22:
  947             case GET_COLOR_23:
  948             case GET_COLOR_24:
  949             case GET_COLOR_25:
  950             case GET_COLOR_26:
  951             case GET_COLOR_27:
  952             case GET_COLOR_28:
  953             case GET_COLOR_29:
  954             case GET_COLOR_30:
  955             case GET_COLOR_31:
  956             case GET_COLOR_32:
  957             case GET_COLOR_33:
  958             case GET_COLOR_34:
  959             case GET_COLOR_35:
  960             case GET_COLOR_36:
  961             case GET_COLOR_37:
  962             case GET_COLOR_38:
  963             case GET_COLOR_39:
  964             case GET_COLOR_40:
  965             case GET_COLOR_41:
  966             case GET_COLOR_42:
  967             case GET_COLOR_43:
  968             case GET_COLOR_44:
  969             case GET_COLOR_45:
  970             case GET_COLOR_46:
  971             case GET_COLOR_47:
  972             case GET_COLOR_48:
  973             case GET_COLOR_49:
  974             case GET_COLOR_50:
  975             case GET_COLOR_51:
  976             case GET_COLOR_52:
  977             case GET_COLOR_53:
  978             case GET_COLOR_54:
  979             case GET_COLOR_55:
  980             case GET_COLOR_56:
  981             case GET_COLOR_57:
  982             case GET_COLOR_58:
  983             case GET_COLOR_59:
  984             case GET_COLOR_60:
  985             case GET_COLOR_61:
  986             case GET_COLOR_62:
  987             case GET_COLOR_63:
  988             case GET_COLOR_64:
  989             case GET_COLOR_65:
  990             case GET_COLOR_66:
  991             case GET_COLOR_67:
  992             case GET_COLOR_68:
  993             case GET_COLOR_69:
  994             case GET_COLOR_70:
  995             case GET_COLOR_71:
  996             case GET_COLOR_72:
  997             case GET_COLOR_73:
  998             case GET_COLOR_74:
  999             case GET_COLOR_75:
 1000             case GET_COLOR_76:
 1001             case GET_COLOR_77:
 1002             case GET_COLOR_78:
 1003             case GET_COLOR_79:
 1004             case GET_COLOR_80:
 1005             case GET_COLOR_81:
 1006             case GET_COLOR_82:
 1007             case GET_COLOR_83:
 1008             case GET_COLOR_84:
 1009             case GET_COLOR_85:
 1010             case GET_COLOR_86:
 1011             case GET_COLOR_87:
 1012             case GET_COLOR_88:
 1013             case GET_COLOR_89:
 1014             case GET_COLOR_90:
 1015             case GET_COLOR_91:
 1016             case GET_COLOR_92:
 1017             case GET_COLOR_93:
 1018             case GET_COLOR_94:
 1019             case GET_COLOR_95:
 1020             case GET_COLOR_96:
 1021             case GET_COLOR_97:
 1022             case GET_COLOR_98:
 1023             case GET_COLOR_99:
 1024             case GET_COLOR_100:
 1025             case GET_COLOR_101:
 1026             case GET_COLOR_102:
 1027             case GET_COLOR_103:
 1028             case GET_COLOR_104:
 1029             case GET_COLOR_105:
 1030             case GET_COLOR_106:
 1031             case GET_COLOR_107:
 1032             case GET_COLOR_108:
 1033             case GET_COLOR_109:
 1034             case GET_COLOR_110:
 1035             case GET_COLOR_111:
 1036             case GET_COLOR_112:
 1037             case GET_COLOR_113:
 1038             case GET_COLOR_114:
 1039             case GET_COLOR_115:
 1040             case GET_COLOR_116:
 1041             case GET_COLOR_117:
 1042             case GET_COLOR_118:
 1043             case GET_COLOR_119:
 1044             case GET_COLOR_120:
 1045             case GET_COLOR_121:
 1046             case GET_COLOR_122:
 1047             case GET_COLOR_123:
 1048             case GET_COLOR_124:
 1049             case GET_COLOR_125:
 1050             case GET_COLOR_126:
 1051             case GET_COLOR_127:
 1052             case GET_COLOR_128:
 1053             case GET_COLOR_129:
 1054             case GET_COLOR_130:
 1055             case GET_COLOR_131:
 1056             case GET_COLOR_132:
 1057             case GET_COLOR_133:
 1058             case GET_COLOR_134:
 1059             case GET_COLOR_135:
 1060             case GET_COLOR_136:
 1061             case GET_COLOR_137:
 1062             case GET_COLOR_138:
 1063             case GET_COLOR_139:
 1064             case GET_COLOR_140:
 1065             case GET_COLOR_141:
 1066             case GET_COLOR_142:
 1067             case GET_COLOR_143:
 1068             case GET_COLOR_144:
 1069             case GET_COLOR_145:
 1070             case GET_COLOR_146:
 1071             case GET_COLOR_147:
 1072             case GET_COLOR_148:
 1073             case GET_COLOR_149:
 1074             case GET_COLOR_150:
 1075             case GET_COLOR_151:
 1076             case GET_COLOR_152:
 1077             case GET_COLOR_153:
 1078             case GET_COLOR_154:
 1079             case GET_COLOR_155:
 1080             case GET_COLOR_156:
 1081             case GET_COLOR_157:
 1082             case GET_COLOR_158:
 1083             case GET_COLOR_159:
 1084             case GET_COLOR_160:
 1085             case GET_COLOR_161:
 1086             case GET_COLOR_162:
 1087             case GET_COLOR_163:
 1088             case GET_COLOR_164:
 1089             case GET_COLOR_165:
 1090             case GET_COLOR_166:
 1091             case GET_COLOR_167:
 1092             case GET_COLOR_168:
 1093             case GET_COLOR_169:
 1094             case GET_COLOR_170:
 1095             case GET_COLOR_171:
 1096             case GET_COLOR_172:
 1097             case GET_COLOR_173:
 1098             case GET_COLOR_174:
 1099             case GET_COLOR_175:
 1100             case GET_COLOR_176:
 1101             case GET_COLOR_177:
 1102             case GET_COLOR_178:
 1103             case GET_COLOR_179:
 1104             case GET_COLOR_180:
 1105             case GET_COLOR_181:
 1106             case GET_COLOR_182:
 1107             case GET_COLOR_183:
 1108             case GET_COLOR_184:
 1109             case GET_COLOR_185:
 1110             case GET_COLOR_186:
 1111             case GET_COLOR_187:
 1112             case GET_COLOR_188:
 1113             case GET_COLOR_189:
 1114             case GET_COLOR_190:
 1115             case GET_COLOR_191:
 1116             case GET_COLOR_192:
 1117             case GET_COLOR_193:
 1118             case GET_COLOR_194:
 1119             case GET_COLOR_195:
 1120             case GET_COLOR_196:
 1121             case GET_COLOR_197:
 1122             case GET_COLOR_198:
 1123             case GET_COLOR_199:
 1124             case GET_COLOR_200:
 1125             case GET_COLOR_201:
 1126             case GET_COLOR_202:
 1127             case GET_COLOR_203:
 1128             case GET_COLOR_204:
 1129             case GET_COLOR_205:
 1130             case GET_COLOR_206:
 1131             case GET_COLOR_207:
 1132             case GET_COLOR_208:
 1133             case GET_COLOR_209:
 1134             case GET_COLOR_210:
 1135             case GET_COLOR_211:
 1136             case GET_COLOR_212:
 1137             case GET_COLOR_213:
 1138             case GET_COLOR_214:
 1139             case GET_COLOR_215:
 1140             case GET_COLOR_216:
 1141             case GET_COLOR_217:
 1142             case GET_COLOR_218:
 1143             case GET_COLOR_219:
 1144             case GET_COLOR_220:
 1145             case GET_COLOR_221:
 1146             case GET_COLOR_222:
 1147             case GET_COLOR_223:
 1148             case GET_COLOR_224:
 1149             case GET_COLOR_225:
 1150             case GET_COLOR_226:
 1151             case GET_COLOR_227:
 1152             case GET_COLOR_228:
 1153             case GET_COLOR_229:
 1154             case GET_COLOR_230:
 1155             case GET_COLOR_231:
 1156             case GET_COLOR_232:
 1157             case GET_COLOR_233:
 1158             case GET_COLOR_234:
 1159             case GET_COLOR_235:
 1160             case GET_COLOR_236:
 1161             case GET_COLOR_237:
 1162             case GET_COLOR_238:
 1163             case GET_COLOR_239:
 1164             case GET_COLOR_240:
 1165             case GET_COLOR_241:
 1166             case GET_COLOR_242:
 1167             case GET_COLOR_243:
 1168             case GET_COLOR_244:
 1169             case GET_COLOR_245:
 1170             case GET_COLOR_246:
 1171             case GET_COLOR_247:
 1172             case GET_COLOR_248:
 1173             case GET_COLOR_249:
 1174             case GET_COLOR_250:
 1175             case GET_COLOR_251:
 1176             case GET_COLOR_252:
 1177             case GET_COLOR_253:
 1178             case GET_COLOR_254:
 1179             case GET_COLOR_255:
 1180             case GET_COLOR_HL:
 1181             case GET_CURSOR:
 1182             case GET_MOUSE_FG:
 1183             case GET_MOUSE_BG:
 1184             case GET_FONT:
 1185             case GET_TITLE:
 1186             case GET_GEOMETRY:
 1187             case MAXIMIZE:
 1188             case RESTORE:
 1189             case ICONIFY:
 1190             case DE_ICONIFY:
 1191             case RAISE:
 1192             case LOWER:
 1193                 ctlseqstab[a].text = "";
 1194                 break;
 1195             case RESET:
 1196                 ctlseqstab[a].text = "\\ec";
 1197                 break;
 1198             case GEOMETRY:
 1199                 ctlseqstab[GEOMETRY].text = optarg;
 1200                 break;
 1201             case FILE_CONF:
 1202                 if (*optarg == '~')
 1203                 {
 1204                     snprintf(configuration_file, sizeof(configuration_file), "%s%s", getenv("HOME"), optarg + 1);
 1205                 }
 1206                 else
 1207                 {
 1208                     snprintf(configuration_file, sizeof(configuration_file), "%s", optarg);
 1209                 }
 1210                 break;
 1211             default:
 1212                 usage(EXIT_FAILURE);
 1213             }
 1214             break;
 1215 
 1216         case '?':
 1217         case ':':
 1218         default:
 1219             usage(EXIT_FAILURE);
 1220         }
 1221     }
 1222 
 1223     /* check if environment variable TERM is XFree86 variant */
 1224     if (!force)
 1225     {
 1226         check_term_variable();
 1227     }
 1228 
 1229     configuration_init(&list);
 1230 
 1231     /* only apply configurations if no options are specified or if a
 1232       configuration is specifically specified by the --file option */
 1233     if (!has_options || configuration_file[0])
 1234     {
 1235 
 1236         /* read configuration file */
 1237         if (!configuration_file[0])
 1238         {
 1239             /* default ~/.program_name configuration file */
 1240             snprintf(configuration_file, sizeof(configuration_file), "%s/.%s", getenv("HOME"), program_name);
 1241             if (configuration_read(&list, configuration_file) == -1)
 1242             {
 1243                 configuration_missing = 1;
 1244             }
 1245         }
 1246         else
 1247         {
 1248             /* user specified configuration file */
 1249             if (configuration_read(&list, configuration_file) == -1)
 1250             {
 1251                 fprintf(stderr, "%s: %s: No such file or directory\n", program_name, configuration_file);
 1252                 do_exit(EXIT_FAILURE);
 1253             }
 1254         }
 1255     }
 1256 
 1257     tty_control();
 1258 
 1259     for (i = 0; i < NSEQ; i++)
 1260     {
 1261         type = ctlseqstab[i].type;
 1262         text = ctlseqstab[i].text;
 1263 
 1264         temp[0] = '\0';
 1265 
 1266         /* check if configuration exists */
 1267         if (!text && (type == OSC || type == CSI))
 1268         {
 1269             lp = configuration_find(&list, ctlseqstab[i].conf_title);
 1270             if (lp)
 1271             {
 1272                 text = lp->value;
 1273             }
 1274         }
 1275 
 1276         if (text)
 1277         {
 1278             ctl1 = ctlseqstab[i].ctl1;
 1279             ctl2 = ctlseqstab[i].ctl2;
 1280 
 1281             switch (type)
 1282             {
 1283             case CSI:
 1284                 switch (i)
 1285                 {
 1286                 case RESTORE:
 1287                 case MAXIMIZE:
 1288                     csi_print2(ctl1, ctl2);
 1289                     break;
 1290                 case GEOMETRY:
 1291                     set_geometry(ctl1, ctl2, text);
 1292                     break;
 1293                 default:
 1294                     csi_print1(ctl1);
 1295                     break;
 1296                 }
 1297                 break;
 1298 
 1299             case GET_CSI:
 1300                 switch (i)
 1301                 {
 1302                 case GET_GEOMETRY:
 1303                     if (get_geometry(temp, sizeof(temp), verbose, ctl1, ctl2) < 0)
 1304                     {
 1305                         report_error(ctlseqstab[i].synopsis);
 1306                     }
 1307                     else if (*temp)
 1308                     {
 1309                         fprintf(stdout, "%s\n", temp);
 1310                     }
 1311                     break;
 1312                 case GET_TITLE:
 1313                     if (get_title(temp, sizeof(temp), verbose, ctl1) < 0)
 1314                     {
 1315                         report_error(ctlseqstab[i].synopsis);
 1316                     }
 1317                     else if (*temp)
 1318                     {
 1319                         fprintf(stdout, "%s\n", temp);
 1320                     }
 1321                     break;
 1322                 default:
 1323                     /* NOTREACHED */
 1324                     assert(0);
 1325                     break;
 1326                 }
 1327                 break;
 1328 
 1329             case OSC:
 1330                 osc_print(ctl1, ctl2, text);
 1331                 break;
 1332 
 1333             case GET_OSC:
 1334                 if (get_osc(temp, sizeof(temp), verbose, i, ctl1, ctl2) < 0)
 1335                 {
 1336                     report_error(ctlseqstab[i].synopsis);
 1337                 }
 1338                 else if (*temp)
 1339                 {
 1340                     fprintf(stdout, "%s\n", temp);
 1341                 }
 1342                 break;
 1343 
 1344             case ANY:
 1345                 raw_print(text);
 1346                 break;
 1347 
 1348             default:
 1349                 fprintf(stderr, "unknown type: %d\n", type);
 1350                 exit(EXIT_FAILURE);
 1351             }
 1352         }
 1353     }
 1354     configuration_free(&list);
 1355 
 1356     if (configuration_missing)
 1357     {
 1358         if (configuration_write(configuration_file) < 0)
 1359         {
 1360             do_exit(EXIT_FAILURE);
 1361         }
 1362     }
 1363 
 1364     do_exit(EXIT_SUCCESS);
 1365 
 1366     /* NOTREACHED */
 1367     assert(0);
 1368 
 1369     return 0; /* shut up the compiler */
 1370 }
 1371 
 1372 /*=****************************************************************************
 1373 **
 1374 ** DESCRIPTION :
 1375 **
 1376 ** RETURN VALUE:
 1377 **                                                                           */
 1378 /*=***************************************************************************/
 1379 void check_term_variable(void)
 1380 {
 1381     char *term;
 1382 
 1383     if ((term = getenv("TERM")) == NULL)
 1384     {
 1385         fprintf(stderr, "%s: failed to read TERM environment variable\n", program_name);
 1386         do_exit(EXIT_FAILURE);
 1387     }
 1388 
 1389     if (strstr(term, "xterm") == NULL)
 1390     {
 1391         fprintf(stderr, "%s: TERM=%s: probably not xterm variant\n", program_name, term);
 1392         do_exit(EXIT_FAILURE);
 1393     }
 1394 }
 1395 
 1396 /*=****************************************************************************
 1397 **
 1398 ** DESCRIPTION :
 1399 **
 1400 ** RETURN VALUE:
 1401 **                                                                           */
 1402 /*=***************************************************************************/
 1403 void tty_control()
 1404 {
 1405     ctty = NULL;
 1406 
 1407     if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO))
 1408     {
 1409         /* get controlling terminal */
 1410         if ((ctty = fopen(ctty_path(), "r+")) == NULL)
 1411         {
 1412             fprintf(stderr, "%s: failed to get controlling terminal\n", program_name);
 1413             exit(EXIT_FAILURE);
 1414         }
 1415     }
 1416 
 1417     if (!isatty(STDIN_FILENO) && ctty)
 1418     {
 1419         tty_in = ctty;
 1420         TTY_FILENO = fileno(tty_in);
 1421     }
 1422     else
 1423     {
 1424         tty_in = stdin;
 1425         TTY_FILENO = STDIN_FILENO;
 1426     }
 1427 
 1428     if (!isatty(STDOUT_FILENO) && ctty)
 1429     {
 1430         tty_out = ctty;
 1431     }
 1432     else
 1433     {
 1434         tty_out = stdout;
 1435     }
 1436 
 1437     set_tty_raw();
 1438 }
 1439 
 1440 /*=****************************************************************************
 1441 **
 1442 ** DESCRIPTION : find path to controlling terminal
 1443 **
 1444 ** RETURN VALUE:
 1445 **                                                                           */
 1446 /*=***************************************************************************/
 1447 char *ctty_path(void)
 1448 {
 1449     int i;
 1450     char *tty_path = NULL;
 1451 
 1452     for (i = 0; i <= 2; i++)
 1453     {
 1454         if ((tty_path = ttyname(i)))
 1455         {
 1456             break;
 1457         }
 1458     }
 1459 
 1460     return tty_path;
 1461 }
 1462 
 1463 /*=****************************************************************************
 1464 **
 1465 ** DESCRIPTION :
 1466 **
 1467 ** RETURN VALUE:
 1468 **                                                                           */
 1469 /*=***************************************************************************/
 1470 void set_tty_raw()
 1471 {
 1472     /* get and backup tty_in termios */
 1473     tcgetattr(TTY_FILENO, &tty_ts);
 1474     tty_ts_orig = tty_ts;
 1475     tty_ts_orig_pt = &tty_ts_orig;
 1476 
 1477     /* set tty raw */
 1478     tty_ts.c_iflag = 0;
 1479     tty_ts.c_lflag = 0;
 1480 
 1481     tty_ts.c_cc[VMIN] = 0;
 1482     tty_ts.c_cc[VTIME] = 1;
 1483     tty_ts.c_lflag &= ~(ICANON | ECHO);
 1484     tcsetattr(TTY_FILENO, TCSANOW, &tty_ts);
 1485 }
 1486 
 1487 /*=****************************************************************************
 1488 **
 1489 ** DESCRIPTION :
 1490 **
 1491 ** RETURN VALUE:
 1492 **                                                                           */
 1493 /*=***************************************************************************/
 1494 void set_tty_restore(void)
 1495 {
 1496     /* restore tty mode */
 1497     if (tty_ts_orig_pt)
 1498     {
 1499         tcsetattr(TTY_FILENO, TCSAFLUSH, tty_ts_orig_pt);
 1500     }
 1501 }
 1502 
 1503 /*=****************************************************************************
 1504 **
 1505 ** DESCRIPTION : In tmux, use DCS with a "tmux;" prefix to pass escape
 1506 ** sequences through to the underlying terminal.
 1507 **
 1508 ** Escape characters in the sequences must be doubled.
 1509 **
 1510 ** RETURN VALUE:
 1511 **                                                                           */
 1512 /*=***************************************************************************/
 1513 char *tmux_dcs_passthrough(char *ctlseq)
 1514 {
 1515     static char s[BUFSIZ];
 1516 
 1517     if (getenv("TMUX"))
 1518     {
 1519         snprintf(s, sizeof(s), "\033Ptmux;\033%s\033\\", ctlseq);
 1520         return s;
 1521     }
 1522 
 1523     return ctlseq;
 1524 }
 1525 
 1526 /*=****************************************************************************
 1527 **
 1528 ** DESCRIPTION : issue raw escape sequence.
 1529 **
 1530 ** RETURN VALUE:
 1531 **                                                                           */
 1532 /*=***************************************************************************/
 1533 void raw_print(char *ctlseq)
 1534 {
 1535     int c;
 1536 
 1537     ctlseq = tmux_dcs_passthrough(ctlseq);
 1538 
 1539     while ((c = *ctlseq++))
 1540     {
 1541         if (c == '\\' && *ctlseq)
 1542         {
 1543             switch (c = *ctlseq++)
 1544             {
 1545             case 'e':
 1546                 c = '\033';
 1547                 break;
 1548             case 'a':
 1549                 c = '\007';
 1550                 break;
 1551             case 'b':
 1552                 c = '\b';
 1553                 break;
 1554             case 'f':
 1555                 c = '\f';
 1556                 break;
 1557             case 'n':
 1558                 c = '\n';
 1559                 break;
 1560             case 'r':
 1561                 c = '\r';
 1562                 break;
 1563             case 't':
 1564                 c = '\t';
 1565                 break;
 1566             case 'v':
 1567                 c = (int)0x0B;
 1568                 break;
 1569             case '0':
 1570             case '1':
 1571             case '2':
 1572             case '3':
 1573             case '4':
 1574             case '5':
 1575             case '6':
 1576             case '7':
 1577                 c -= '0';
 1578 
 1579                 if (*ctlseq >= '0' && *ctlseq <= '7')
 1580                 {
 1581                     c = (c * 8) + (*ctlseq++ - '0');
 1582                 }
 1583 
 1584                 if (*ctlseq >= '0' && *ctlseq <= '7')
 1585                 {
 1586                     c = (c * 8) + (*ctlseq++ - '0');
 1587                 }
 1588                 break;
 1589             case '\\':
 1590                 break;
 1591             default:
 1592                 fputc('\\', tty_out);
 1593                 break;
 1594             }
 1595         }
 1596         fputc(c, tty_out);
 1597     }
 1598 
 1599     fflush(tty_out);
 1600 }
 1601 
 1602 /*=****************************************************************************
 1603 **
 1604 ** DESCRIPTION : read raw terminal output, not '\0' terminated!
 1605 **
 1606 ** RETURN VALUE: number of bytes read, or 0 on VTIME timeout
 1607 **                                                                           */
 1608 /*=***************************************************************************/
 1609 ssize_t tty_read(char *output, size_t size)
 1610 {
 1611     ssize_t res,
 1612         n;
 1613     char *p;
 1614 
 1615     res = 0;
 1616     p = output;
 1617 
 1618     while (p < output + size)
 1619     {
 1620         n = read(TTY_FILENO, p, 1);
 1621 
 1622         if (n > 0)
 1623         {
 1624             p += n;
 1625             res += n;
 1626         }
 1627         else if (n == 0 || (n == -1 && EAGAIN == errno))
 1628         {
 1629             /* VTIME timeout. Nothing more to read, or nothing read. */
 1630 
 1631             /* tcsetattr(3). If no data is available, POSIX permits a read(2)
 1632              * in noncanonical mode to return either 0, or -1 with errno set
 1633              * to EAGAIN. */
 1634             break;
 1635         }
 1636         else if (n < 0)
 1637         {
 1638             perror("read");
 1639             do_exit(EXIT_FAILURE);
 1640         }
 1641     }
 1642 
 1643     return res;
 1644 }
 1645 
 1646 /*=****************************************************************************
 1647 **
 1648 ** DESCRIPTION : issue CSI (Control Sequence Introducer) escape sequence
 1649 **
 1650 ** RETURN VALUE:
 1651 **                                                                           */
 1652 /*=***************************************************************************/
 1653 void csi_print1(int ctl1)
 1654 {
 1655     snprintf(temp, sizeof(temp), "\033[%dt", ctl1);
 1656     raw_print(temp);
 1657 }
 1658 
 1659 /*=****************************************************************************
 1660 **
 1661 ** DESCRIPTION :
 1662 **
 1663 ** RETURN VALUE:
 1664 **                                                                           */
 1665 /*=***************************************************************************/
 1666 void csi_print2(int ctl1, int ctl2)
 1667 {
 1668     snprintf(temp, sizeof(temp), "\033[%d;%dt", ctl1, ctl2);
 1669     raw_print(temp);
 1670 }
 1671 
 1672 /*=****************************************************************************
 1673 **
 1674 ** DESCRIPTION :
 1675 **
 1676 ** RETURN VALUE:
 1677 **                                                                           */
 1678 /*=***************************************************************************/
 1679 void csi_print3(int ctl1, int ctl2, int ctl3)
 1680 {
 1681     snprintf(temp, sizeof(temp), "\033[%d;%d;%dt", ctl1, ctl2, ctl3);
 1682     raw_print(temp);
 1683 }
 1684 
 1685 /*=****************************************************************************
 1686 **
 1687 ** DESCRIPTION :
 1688 **
 1689 ** RETURN VALUE:
 1690 **                                                                           */
 1691 /*=***************************************************************************/
 1692 int get_title(char *title, size_t size, int verbose, int ctl1)
 1693 {
 1694     /* OSC  l title ST */
 1695     ssize_t n;
 1696     static char s[BUFSIZ];
 1697 
 1698     csi_print1(ctl1);
 1699 
 1700     n = tty_read(s, sizeof(s));
 1701 
 1702     if (n == 0)
 1703     {
 1704         /* unsupported or disallowed */
 1705         return -1;
 1706     }
 1707 
 1708     /* get at least the OSC */
 1709     if (n == 1)
 1710     {
 1711         n += tty_read(s + 1, sizeof(s) - 1);
 1712     }
 1713 
 1714     while (!(s[n - 2] == '\033' && s[n - 1] == '\\'))
 1715     {
 1716         n += tty_read(s + n, sizeof(s) - n);
 1717     }
 1718 
 1719     /* n-2: discard ST */
 1720     s[n - 2] = '\0';
 1721 
 1722     /* s+3: discard OSC l */
 1723     if (!verbose)
 1724     {
 1725         snprintf(title, size, "%s", s + 3);
 1726     }
 1727     else
 1728     {
 1729         snprintf(title, size, "%s=\"%s\"", ctlseqstab[GET_TITLE].conf_title, s + 3);
 1730     }
 1731 
 1732     return 0;
 1733 }
 1734 
 1735 /*=****************************************************************************
 1736 **
 1737 ** DESCRIPTION : issue OSC (Operating System Controls) escape sequence
 1738 **
 1739 ** RETURN VALUE:
 1740 **                                                                           */
 1741 /*=***************************************************************************/
 1742 void osc_print(int ps1, int ps2, char *pt)
 1743 {
 1744 
 1745     if (pt && *pt)
 1746     {
 1747         if (ps1 == 4)
 1748         {
 1749             /* colorN */
 1750             snprintf(temp, sizeof(temp), "\033]%d;%d;%s\033\\", ps1, ps2, pt);
 1751         }
 1752         else
 1753         {
 1754             snprintf(temp, sizeof(temp), "\033]%d;%s\033\\", ps1, pt);
 1755         }
 1756     }
 1757     else if (ps1 == 4)
 1758     {
 1759         /* colorN */
 1760         snprintf(temp, sizeof(temp), "\033]%d;%d;?\033\\", ps1, ps2);
 1761     }
 1762     else
 1763     {
 1764         snprintf(temp, sizeof(temp), "\033]%d;?\033\\", ps1);
 1765     }
 1766 
 1767     raw_print(temp);
 1768 }
 1769 
 1770 /*=****************************************************************************
 1771 **
 1772 ** DESCRIPTION :
 1773 **
 1774 ** RETURN VALUE:
 1775 **                                                                           */
 1776 /*=***************************************************************************/
 1777 int get_osc(char *osc, size_t size, int verbose, unsigned int option, int ctl1, int ctl2)
 1778 {
 1779     ssize_t n;
 1780     char *p;
 1781     static char s[BUFSIZ];
 1782 
 1783     char *conf_title = ctlseqstab[option].conf_title;
 1784 
 1785     if (ctl1 == 4)
 1786     {
 1787         osc_print(ctl1, ctl2, NULL);
 1788     }
 1789     else
 1790     {
 1791         osc_print(ctl1, 0, NULL);
 1792     }
 1793 
 1794     n = tty_read(s, sizeof(s));
 1795 
 1796     if (n == 0)
 1797     {
 1798         /* unsupported or disallowed */
 1799         return -1;
 1800     }
 1801 
 1802     /* get at least the OSC */
 1803     if (n == 1)
 1804     {
 1805         n += tty_read(s + 1, sizeof(s) - 1);
 1806     }
 1807 
 1808     while ((s[n - 1] != '\007') && !(n - 2 >= 0 && s[n - 2] == '\033' && s[n - 1] == '\\'))
 1809     {
 1810         n += tty_read(s + n, sizeof(s) - n);
 1811     }
 1812 
 1813     if (s[n - 1] == '\007')
 1814     {
 1815         /* n-1: discard BEL */
 1816         s[n - 1] = '\0';
 1817     }
 1818     else if (n - 2 >= 0 && s[n - 2] == '\033' && s[n - 1] == '\\')
 1819     {
 1820         /* n-2: discard ST */
 1821         s[n - 2] = '\0';
 1822     }
 1823     else
 1824     {
 1825         return -1;
 1826     }
 1827 
 1828     /* discard OSC Ps ; */
 1829     p = strchr(s, ';');
 1830     if (ctl1 == 4)
 1831     {
 1832         p = strchr(p + 1, ';');
 1833     }
 1834 
 1835     ++p;
 1836 
 1837     if (!verbose)
 1838     {
 1839         snprintf(osc, size, "%s", p);
 1840     }
 1841     else
 1842     {
 1843         snprintf(osc, size, "%s=\"%s\"", conf_title, p);
 1844     }
 1845 
 1846     return 0;
 1847 }
 1848 
 1849 /*=****************************************************************************
 1850 **
 1851 ** DESCRIPTION :
 1852 **
 1853 ** RETURN VALUE:
 1854 **                                                                           */
 1855 /*=***************************************************************************/
 1856 void set_geometry(int ctl1, int ctl2, char *geometry)
 1857 {
 1858     int w,
 1859         h,
 1860         x,
 1861         y;
 1862     int set_pos,
 1863         set_size;
 1864 
 1865     set_pos = set_size = 0;
 1866     if (sscanf(geometry, "%d%*[xX]%d%d%d", &w, &h, &x, &y) == 4)
 1867     {
 1868         set_pos = set_size = 1;
 1869     }
 1870     else if (sscanf(geometry, "%d%d", &x, &y) == 2)
 1871     {
 1872         set_pos = 1;
 1873     }
 1874     else if (sscanf(geometry, "%d%*[xX]%d", &w, &h) == 2)
 1875     {
 1876         set_size = 1;
 1877     }
 1878 
 1879     if (set_size)
 1880     {
 1881         csi_print3(ctl1, h, w);
 1882     }
 1883 
 1884     /* negative positions are truncated to origo */
 1885     if (set_pos)
 1886     {
 1887         x = x < 0 ? 0 : x;
 1888         y = y < 0 ? 0 : y;
 1889         csi_print3(ctl2, x, y);
 1890     }
 1891 }
 1892 
 1893 /*=****************************************************************************
 1894 **
 1895 ** DESCRIPTION :
 1896 **
 1897 ** RETURN VALUE:
 1898 **                                                                           */
 1899 /*=***************************************************************************/
 1900 int get_geometry(char *geometry, size_t size, int verbose, int ctl1, int ctl2)
 1901 {
 1902     ssize_t n;
 1903     int w,
 1904         h,
 1905         x,
 1906         y;
 1907     char local_temp[BUFSIZ];
 1908 
 1909     /* get height, width - CSI 8 ; height ; width t */
 1910     csi_print1(ctl1);
 1911     n = tty_read(local_temp, sizeof(local_temp));
 1912 
 1913     if (n == 0)
 1914     {
 1915         /* unsupported or disallowed */
 1916         return -1;
 1917     }
 1918 
 1919     /* get at least the CSI */
 1920     if (n == 1)
 1921     {
 1922         n += tty_read(local_temp + 1, sizeof(local_temp) - 1);
 1923     }
 1924 
 1925     while (local_temp[n - 1] != 't')
 1926     {
 1927         n += tty_read(local_temp + n, sizeof(local_temp) - n);
 1928     }
 1929 
 1930     /* n-1: discard t */
 1931     local_temp[n - 1] = '\0';
 1932 
 1933     /* local_temp+4: discard CSI 8 ; */
 1934     if (sscanf(local_temp + 4, "%d;%d", &h, &w) != 2)
 1935     {
 1936         fprintf(stderr, "%s: failed to read xterm size\n", program_name);
 1937         do_exit(EXIT_FAILURE);
 1938     }
 1939 
 1940     /* get x,y  - CSI 3 ; x; yt */
 1941     csi_print1(ctl2);
 1942     n = tty_read(local_temp, sizeof(local_temp));
 1943 
 1944     /* get at least the CSI */
 1945     if (n == 1)
 1946     {
 1947         n += tty_read(local_temp + 1, sizeof(local_temp) - 1);
 1948     }
 1949 
 1950     while (local_temp[n - 1] != 't')
 1951     {
 1952         n += tty_read(local_temp + n, sizeof(local_temp) - n);
 1953     }
 1954 
 1955     /* n-1: discard t */
 1956     local_temp[n - 1] = '\0';
 1957 
 1958     /* local_temp+4: discard CSI 3 ; */
 1959     if (sscanf(local_temp + 4, "%d;%dt", &x, &y) != 2)
 1960     {
 1961         fprintf(stderr, "%s: failed to read xterm position\n", program_name);
 1962         do_exit(EXIT_FAILURE);
 1963     }
 1964 
 1965     if (!verbose)
 1966     {
 1967         snprintf(geometry, size, "%dx%d%+d%+d", w, h, x, y);
 1968     }
 1969     else
 1970     {
 1971         snprintf(geometry, size, "%s=\"%dx%d%+d%+d\"", ctlseqstab[GET_GEOMETRY].conf_title, w, h, x, y);
 1972     }
 1973 
 1974     return 0;
 1975 }
 1976 
 1977 /*=****************************************************************************
 1978 **
 1979 ** DESCRIPTION :
 1980 **
 1981 ** RETURN VALUE:
 1982 **                                                                           */
 1983 /*=***************************************************************************/
 1984 void usage(int status)
 1985 {
 1986     unsigned int i;
 1987 
 1988     if (status)
 1989     {
 1990         fprintf(stderr, "Usage: %s [OPTIONS]...\n", program_name);
 1991         fprintf(stderr, "Try `%s --help' for more information.\n", program_name);
 1992     }
 1993     else
 1994     {
 1995         printf("Usage: %s [OPTIONS]...\n", program_name);
 1996         printf("\n");
 1997         printf("Purpose:\n");
 1998         printf("  This program enables dynamic control of XFree86 xterm properties.\n");
 1999         printf("\n");
 2000         printf("Options:\n");
 2001 
 2002         for (i = 0; i < NSEQ; i++)
 2003         {
 2004             if (ctlseqstab[i].synopsis)
 2005             {
 2006                 printf("  %-35s %s\n", ctlseqstab[i].synopsis, ctlseqstab[i].description);
 2007             }
 2008         }
 2009         printf("  %-35s %s\n", "--force, -f", "skip TERM check");
 2010         printf("  %-35s %s\n", "--verbose, -v", "print verbose reports");
 2011         printf("  %-35s %s\n", "--help, -h", "print this help and exit");
 2012         printf("  %-35s %s\n", "--version", "print the version number and exit");
 2013         printf("\n");
 2014         printf("See xtermcontrol(1) manpage for more information.\n");
 2015     }
 2016 
 2017     do_exit(status);
 2018 }
 2019 
 2020 /*=****************************************************************************
 2021 **
 2022 ** DESCRIPTION :
 2023 **
 2024 ** RETURN VALUE:
 2025 **                                                                           */
 2026 /*=***************************************************************************/
 2027 void version(void)
 2028 {
 2029     printf("%s %s\n", program_name, VERSION);
 2030     printf("\n");
 2031     printf("Copyright (C) 2002-2013 Jess Thrysoee.\n");
 2032     printf("This is free software; see the source for copying conditions. There is NO\n");
 2033     printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
 2034 
 2035     do_exit(EXIT_SUCCESS);
 2036 }
 2037 
 2038 /*=****************************************************************************
 2039 **
 2040 ** DESCRIPTION :
 2041 **
 2042 ** RETURN VALUE:
 2043 **                                                                           */
 2044 /*=***************************************************************************/
 2045 int configuration_write(const char *filepath)
 2046 {
 2047     FILE *fp;
 2048 
 2049     fp = fopen(filepath, "w");
 2050     if (fp == NULL)
 2051     {
 2052         perror("configuration_write");
 2053         return -1;
 2054     }
 2055 
 2056     fprintf(fp, "#\n");
 2057     fprintf(fp, "# This is the configuration file for xtermcontrol.\n");
 2058     fprintf(fp, "#\n");
 2059     fprintf(fp, "# Each line in the file is either a comment or contains an attribute.\n");
 2060     fprintf(fp, "# Attributes consist of a keyword and an associated value:\n");
 2061     fprintf(fp, "#\n");
 2062     fprintf(fp, "# keyword = value # comment\n");
 2063     fprintf(fp, "#\n");
 2064     fprintf(fp, "# Whitespace is ignored in attributes unless within a quoted value. The\n");
 2065     fprintf(fp, "# character '#' is taken to begin a comment. Each '#' and all remaining\n");
 2066     fprintf(fp, "# characters on that line is ignored.\n");
 2067     fprintf(fp, "#\n");
 2068     fprintf(fp, "\n");
 2069     fprintf(fp, "# foreground color\n");
 2070     fprintf(fp, "#foreground=\"black\"\n");
 2071     fprintf(fp, "\n");
 2072     fprintf(fp, "# background color\n");
 2073     fprintf(fp, "#background=\"white\"\n");
 2074     fprintf(fp, "\n");
 2075     fprintf(fp, "# highlight color\n");
 2076     fprintf(fp, "#highlight=\"yellow\"\n");
 2077     fprintf(fp, "\n");
 2078     fprintf(fp, "# cursor color\n");
 2079     fprintf(fp, "#cursor=\"black\"\n");
 2080     fprintf(fp, "\n");
 2081     fprintf(fp, "# mouse pointer foreground color\n");
 2082     fprintf(fp, "#mouse-foreground=\"black\"\n");
 2083     fprintf(fp, "\n");
 2084     fprintf(fp, "# mouse pointer background color\n");
 2085     fprintf(fp, "#mouse-background=\"white\"\n");
 2086     fprintf(fp, "\n");
 2087     fprintf(fp, "# size and/or position\n");
 2088     fprintf(fp, "#geometry=\"80x24\"\n");
 2089     fprintf(fp, "\n");
 2090     fprintf(fp, "# font\n");
 2091     fprintf(fp, "#font=\"fixed\"\n");
 2092     fprintf(fp, "\n");
 2093     fprintf(fp, "# color definitions\n");
 2094     fprintf(fp, "#color0=\"#000000\"\n");
 2095     fprintf(fp, "#color1=\"#c00000\"\n");
 2096     fprintf(fp, "#color2=\"#008000\"\n");
 2097     fprintf(fp, "#color3=\"#808000\"\n");
 2098     fprintf(fp, "#color4=\"#0000c0\"\n");
 2099     fprintf(fp, "#color5=\"#c000c0\"\n");
 2100     fprintf(fp, "#color6=\"#008080\"\n");
 2101     fprintf(fp, "#color7=\"#c0c0c0\"\n");
 2102     fprintf(fp, "#color8=\"#808080\"\n");
 2103     fprintf(fp, "#color9=\"#ff6060\"\n");
 2104     fprintf(fp, "#color10=\"#00ff00\"\n");
 2105     fprintf(fp, "#color11=\"#ffff00\"\n");
 2106     fprintf(fp, "#color12=\"#8080ff\"\n");
 2107     fprintf(fp, "#color13=\"#ff40ff\"\n");
 2108     fprintf(fp, "#color14=\"#00ffff\"\n");
 2109     fprintf(fp, "#color15=\"#ffffff\"\n");
 2110     fprintf(fp, "\n");
 2111 
 2112     fclose(fp);
 2113 
 2114     return 0;
 2115 }
 2116 
 2117 /*=****************************************************************************
 2118 **
 2119 ** DESCRIPTION :
 2120 **
 2121 ** RETURN VALUE:
 2122 **                                                                           */
 2123 /*=***************************************************************************/
 2124 void report_error(const char *synopsis)
 2125 {
 2126     fprintf(stderr, "%s: %s is unsupported or disallowed by this terminal. "
 2127                     "See also, TROUBLESHOOTING section of xtermcontrol(1) manpage.\n",
 2128             program_name, synopsis);
 2129 }
 2130 
 2131 /*=****************************************************************************
 2132 **
 2133 ** DESCRIPTION :
 2134 **
 2135 ** RETURN VALUE:
 2136 **                                                                           */
 2137 /*=***************************************************************************/
 2138 void do_exit(int status)
 2139 {
 2140     set_tty_restore();
 2141     if (ctty)
 2142     {
 2143         fclose(ctty);
 2144     }
 2145     exit(status);
 2146 }