const char   *default_printer_name = XpuGetDefaultXpPrintername(); int           default_printer_rec_index = -1;
XPPrinterList XpuGetPrinterList( const char *printer, int *res_list_count ){  XPPrinterRec *rec = NULL;  int           rec_count = 1; /* allocate one more XPPrinterRec structure                                * as terminator */  char         *sl;    if( !res_list_count )    return(NULL);    sl = strdup(XpuGetXpServerList());  MAKE_STRING_WRITABLE(printer);      if( sl != NULL )  {    char *display;    char *tok_lasts;        for( display = strtok_r(sl, " ", &tok_lasts) ;          display != NULL ;          display = strtok_r(NULL, " ", &tok_lasts) )    {      Display *pdpy;            if( pdpy = XOpenDisplay(display) )      {        XPPrinterList list;        int           list_count;        size_t        display_len = strlen(display);        /* get list of available printers... */        list = XpGetPrinterList(pdpy, STRING_AS_WRITABLE(printer), &list_count);                      if( list && list_count )        {          int i;                    for( i = 0 ; i < list_count ; i++ )          {            char *s;            rec_count++;                         rec = realloc(rec, sizeof(XPPrinterRec)*rec_count);            if( !rec ) /* failure */              break;                          s = malloc(strlen(list[i].name)+display_len+4);            sprintf(s, "%s@%s", list[i].name, display);            rec[rec_count-2].name = s;            rec[rec_count-2].desc = (list[i].desc)?(strdup(list[i].desc)):(NULL);          }                    XpFreePrinterList(list);        }                         XCloseDisplay(pdpy);      }    }        free(sl);  }    if( rec )  {    /* users: DO NOT COUNT ON THIS DETAIL      * (this is only to make current impl. of XpuFreePrinterList() easier) */    rec[rec_count-1].name = NULL;    rec[rec_count-1].desc = NULL;    rec_count--;  }  else  {    rec_count = 0;  }      *res_list_count = rec_count;  FREE_WRITABLE_STRING(printer);  return(rec);}      