Changeset 192

Show
Ignore:
Timestamp:
12/05/07 15:36:24 (1 year ago)
Author:
conrad
Message:

apply UTF-8 support patch by Sergey Kogan (Debian bug #231413)
This patch adds a -u, --utf8 option for reading utf8 input

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • xsel/trunk/xsel.1x

    r188 r192  
    8181 
    8282.PP 
     83\fBEncoding options\fR 
     84.TP 
     85\fB\-u\fR, \fB\-\-utf8\fR  
     86Request selection in UTF8 if possible. 
     87This option is useful when working with selections in national 
     88(non Latin-1) charsets. If your X-server and target application 
     89support UTF8_STRING exchange, then selection is returned as 
     90UTF8 string. If your X-server doesn't support this extension, 
     91option has no effect. If target application doesn's support 
     92UTF8 selection target, empty selection is returned. 
     93 
     94.PP 
    8395\fBX options\fR 
    8496.TP 
     
    109121debugging level, ie. print more information. 
    110122.TP 
    111 \fB\-v\fR, \fB\-\-version\fR 
     123\fB\-\-version\fR 
    112124output version information and exit 
    113125.PP 
  • xsel/trunk/xsel.c

    r191 r192  
    5757static Atom null_atom; /* The NULL atom */ 
    5858static Atom text_atom; /* The TEXT atom */ 
     59static Atom utf8_atom; /* The UTF8 atom */ 
     60static Atom local_target; /* UTF8_STRING or STRING */ 
    5961 
    6062/* Number of selection targets served by this. 
    61  * (MULTIPLE, INCR, TARGETS, TIMESTAMP, DELETE, TEXT and STRING) */ 
    62 #define NUM_TARGETS 7 
    63 static Atom supported_targets[NUM_TARGETS]; 
     63 * (MULTIPLE, INCR, TARGETS, TIMESTAMP, DELETE, TEXT, UTF8_STRING and STRING) */ 
     64#define MAX_NUM_TARGETS 8 
     65static int NUM_TARGETS; 
     66static Atom supported_targets[MAX_NUM_TARGETS]; 
    6467 
    6568/* do_follow: Follow mode for output */ 
     
    109112  printf ("  -d, --delete          Request that the selection be cleared and that\n"); 
    110113  printf ("                        the application owning it delete its contents\n\n"); 
     114  printf ("Encoding options\n"); 
     115  printf ("  -u, --utf8            Request selection in UTF-8 if possible\n\n"); 
    111116  printf ("Selection options\n"); 
    112117  printf ("  -p, --primary         Operate on the PRIMARY selection (default)\n"); 
     
    226231  if (atom == null_atom) return "NULL"; 
    227232  if (atom == text_atom) return "TEXT"; 
     233  if (utf8_atom!=XA_STRING && atom == utf8_atom) return "UTF8_STRING"; 
    228234  if (atom == XInternAtom (display, "XSEL_DATA", True)) return "XSEL_DATA"; 
    229235 
     
    598604                                        *(int *)value); 
    599605          keep_waiting = False; 
    600         } else if (target != XA_STRING && request_target != delete_atom) { 
     606        } else if (target != utf8_atom && target != XA_STRING && request_target != delete_atom) { 
    601607          /* Report non-TEXT atoms */ 
    602608          print_debug (D_WARN, "Selection (type %s) is not a string.", 
     
    12661272 
    12671273/* 
     1274 * handle_utf8_string (display, requestor, property, sel) 
     1275 * 
     1276 * Handle a UTF8_STRING request; setting 'sel' as the data 
     1277 */ 
     1278static HandleResult 
     1279handle_utf8_string (Display * display, Window requestor, Atom property, 
     1280               unsigned char * sel, Atom selection, Time time, 
     1281               MultTrack * mparent) 
     1282{ 
     1283  return 
     1284    change_property (display, requestor, property, utf8_atom, 8, 
     1285                     PropModeReplace, sel, strlen(sel), 
     1286                     selection, time, mparent); 
     1287} 
     1288 
     1289/* 
    12681290 * handle_delete (display, requestor, property) 
    12691291 * 
     
    13101332    } else if (mt->atoms[i] == XA_STRING || mt->atoms[i] == text_atom) { 
    13111333      retval |= handle_string (mt->display, mt->requestor, mt->atoms[i+1], 
     1334                               mt->sel, mt->selection, mt->time, mt); 
     1335    } else if (mt->atoms[i] == utf8_atom) { 
     1336      retval |= handle_utf8_string (mt->display, mt->requestor, mt->atoms[i+1], 
    13121337                               mt->sel, mt->selection, mt->time, mt); 
    13131338    } else if (mt->atoms[i] == delete_atom) { 
     
    14821507    ev.property = xsr->property; 
    14831508    hr = handle_string (ev.display, ev.requestor, ev.property, sel, 
     1509                        ev.selection, ev.time, NULL); 
     1510  } else if (ev.target == utf8_atom) { 
     1511    /* Received UTF8_STRING request */ 
     1512    ev.property = xsr->property; 
     1513    hr = handle_utf8_string (ev.display, ev.requestor, ev.property, sel, 
    14841514                        ev.selection, ev.time, NULL); 
    14851515  } else if (ev.target == delete_atom) { 
     
    16951725  unsigned char * text1, * text2; 
    16961726 
    1697   text1 = get_selection (XA_PRIMARY, XA_STRING); 
    1698   text2 = get_selection (XA_SECONDARY, XA_STRING); 
     1727  text1 = get_selection (XA_PRIMARY, local_target); 
     1728  text2 = get_selection (XA_SECONDARY, local_target); 
    16991729 
    17001730  set_selection_pair__daemon (text1, text2); 
     
    17131743  unsigned char * text1, * text2; 
    17141744 
    1715   text1 = get_selection (XA_PRIMARY, XA_STRING); 
    1716   text2 = get_selection (XA_SECONDARY, XA_STRING); 
     1745  text1 = get_selection (XA_PRIMARY, local_target); 
     1746  text2 = get_selection (XA_SECONDARY, local_target); 
    17171747 
    17181748  set_selection_pair__daemon (text2, text1); 
     
    17531783  char * display_name = NULL; 
    17541784  long timeout_ms = 0L; 
     1785  int need_utf8 = False; 
    17551786 
    17561787  progname = argv[0]; 
     
    17781809      do_append = True; 
    17791810      dont_output = True; 
     1811    } else if (OPT("--utf8") || OPT("-u")) { 
     1812      need_utf8 = True; 
    17801813    } else if (OPT("--input") || OPT("-i")) { 
    17811814      do_input = True; 
     
    18801913    print_debug (D_WARN, "XA_SECONDARY not named \"SECONDARY\"\n"); 
    18811914 
     1915  NUM_TARGETS=0; 
    18821916  /* Get the TIMESTAMP atom */ 
    18831917  timestamp_atom = XInternAtom (display, "TIMESTAMP", False); 
    18841918  supported_targets[s++] = timestamp_atom; 
     1919  NUM_TARGETS++; 
    18851920 
    18861921  /* Get the MULTIPLE atom */ 
    18871922  multiple_atom = XInternAtom (display, "MULTIPLE", False); 
    18881923  supported_targets[s++] = multiple_atom; 
     1924  NUM_TARGETS++; 
    18891925 
    18901926  /* Get the TARGETS atom */ 
    18911927  targets_atom = XInternAtom (display, "TARGETS", False); 
    18921928  supported_targets[s++] = targets_atom; 
     1929  NUM_TARGETS++; 
    18931930 
    18941931  /* Get the DELETE atom */ 
    18951932  delete_atom = XInternAtom (display, "DELETE", False); 
    18961933  supported_targets[s++] = delete_atom; 
     1934  NUM_TARGETS++; 
    18971935 
    18981936  /* Get the INCR atom */ 
    18991937  incr_atom = XInternAtom (display, "INCR", False); 
    19001938  supported_targets[s++] = incr_atom; 
     1939  NUM_TARGETS++; 
    19011940 
    19021941  /* Get the NULL atom */ 
    19031942  null_atom = XInternAtom (display, "NULL", False); 
     1943  NUM_TARGETS++; 
    19041944 
    19051945  /* Get the TEXT atom */ 
    19061946  text_atom = XInternAtom (display, "TEXT", False); 
    19071947  supported_targets[s++] = text_atom; 
     1948  NUM_TARGETS++; 
     1949 
     1950  /* Get the UTF8_STRING atom */ 
     1951  utf8_atom = XInternAtom (display, "UTF8_STRING", True); 
     1952  if( utf8_atom != None) 
     1953    { 
     1954    supported_targets[s++] = utf8_atom; 
     1955    NUM_TARGETS++; 
     1956    } 
     1957  else 
     1958    { 
     1959    utf8_atom = XA_STRING; 
     1960    } 
    19081961 
    19091962  supported_targets[s++] = XA_STRING; 
    1910  
     1963  NUM_TARGETS++; 
     1964 
     1965  if( need_utf8 == True) 
     1966    { 
     1967    local_target=utf8_atom; 
     1968    } 
     1969  else 
     1970    { 
     1971    local_target=XA_STRING; 
     1972    } 
    19111973  /* handle selection keeping and exit if so */ 
    19121974  if (do_keep) { 
     
    19291991  if (do_output || !dont_output) { 
    19301992    /* Get the current selection */ 
    1931     old_sel = get_selection (selection, XA_STRING); 
     1993    old_sel = get_selection (selection, local_target); 
    19321994    if (old_sel) printf ("%s", old_sel); 
    19331995  } 
     
    19412003  else if (do_input || !dont_input) { 
    19422004    if (do_append) { 
    1943       if (!old_sel) old_sel = get_selection (selection, XA_STRING); 
     2005      if (!old_sel) old_sel = get_selection (selection, local_target); 
    19442006      new_sel = copy_sel (old_sel); 
    19452007    }