/* Returns 0 if the printer has been deleted due to a fatal I/O error, 1 otherwise. */ static int sync_printer_with_devmode (struct device* d, DEVMODEW* devmode_in, DEVMODEW* devmode_out, Lisp_Object devname) { /* Change connection if the device changed */ if (!NILP (devname) && lisp_strcasecmp_i18n (devname, DEVICE_MSPRINTER_NAME (d)) != 0) { Lisp_Object new_connection = devname; DEVICE_CONNECTION (d) = Qnil; if (!NILP (Ffind_device (new_connection, Qmsprinter))) { /* We are in trouble - second msprinter for the same device. Nothing wrong on the Windows side, just forge a unique connection name. Use the memory address of d as a unique suffix. */ Ibyte new_connext[20]; qxesprintf (new_connext, ":%X", LISP_OBJECT_UID (wrap_device (d))); new_connection = concat2 (devname, build_istring (new_connext)); } DEVICE_CONNECTION (d) = new_connection; /* Reinitialize printer. The device can pop off in process */ if (!msprinter_reinit_device (d, devname)) { /* Kaboom! */ delete_device_internal (d, 1, 0, 1); return 0; } } { Extbyte *nameext; nameext = LISP_STRING_TO_TSTR (DEVICE_MSPRINTER_NAME (d)); /* Apply the new devmode to the printer */ qxeDocumentProperties (NULL, DEVICE_MSPRINTER_HPRINTER (d), nameext, devmode_out, devmode_in, DM_IN_BUFFER | DM_OUT_BUFFER); /* #### ResetDC fails sometimes, Bill only knows why. The solution below looks more like a workaround to me, although it might be fine. --kkm */ if (qxeResetDC (DEVICE_MSPRINTER_HDC (d), devmode_out) == NULL) { DeleteDC (DEVICE_MSPRINTER_HDC (d)); DEVICE_MSPRINTER_HDC (d) = qxeCreateDC (XETEXT ("WINSPOOL"), nameext, NULL, devmode_out); } } return 1; }
static void msprinter_init_device (struct device *d, Lisp_Object UNUSED (props)) { DEVMODEW *pdm; LONG dm_size; Extbyte *printer_name; #ifdef NEW_GC d->device_data = XMSPRINTER_DEVICE (ALLOC_NORMAL_LISP_OBJECT (msprinter_device)); #else /* not NEW_GC */ d->device_data = xnew_and_zero (struct msprinter_device); #endif /* not NEW_GC */ DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1; DEVICE_MSPRINTER_DEVMODE (d) = Qnil; DEVICE_MSPRINTER_NAME (d) = Qnil; #if 0 /* #### deleted in new ikeyama ws */ /* We do not use printer font list as we do with the display device. Rather, we allow GDI to pick the closest match to the display font. */ DEVICE_MSPRINTER_FONTLIST (d) = Qnil; #endif /* 0 */ CHECK_STRING (DEVICE_CONNECTION (d)); if (!msprinter_init_device_internal (d, DEVICE_CONNECTION (d))) signal_open_printer_error (d); printer_name = LISP_STRING_TO_TSTR (DEVICE_CONNECTION (d)); /* Determine DEVMODE size and store the default DEVMODE */ dm_size = qxeDocumentProperties (NULL, DEVICE_MSPRINTER_HPRINTER (d), printer_name, NULL, NULL, 0); if (dm_size <= 0) signal_open_printer_error (d); pdm = (DEVMODEW *) xmalloc (dm_size); if (qxeDocumentProperties (NULL, DEVICE_MSPRINTER_HPRINTER(d), printer_name, pdm, NULL, DM_OUT_BUFFER) < 0) signal_open_printer_error (d); assert (DEVMODE_SIZE (pdm) <= dm_size); DEVICE_MSPRINTER_DEVMODE (d) = allocate_devmode (pdm, 0, DEVICE_CONNECTION (d), d); }
static ad_device_data * sound_nas_create(Lisp_Object nas_options) { sound_nas_data_t *snd; char *server[6] = {NULL, NULL, NULL, NULL, NULL, NULL}; int i, server_cnt = 0; AuServer *aud = NULL; Lisp_Object opt_server = Qnil; /* parse options */ opt_server = Fplist_get(nas_options, intern(":server"), Qnil); if (!NILP(opt_server) && !STRINGP(opt_server) && !DEVICEP(opt_server)) { wrong_type_argument(Qstringp, opt_server); return NULL; } if (NILP(opt_server)) nas_setup_defaults(server, &server_cnt); else if (STRINGP(opt_server)) server[server_cnt++] = (char*)XSTRING_DATA(opt_server); #ifdef HAVE_X_WINDOWS else if (DEVICEP(opt_server) && DEVICE_X_P(XDEVICE(opt_server))) server[server_cnt++] = (char*)XSTRING_DATA( DEVICE_CONNECTION(XDEVICE(opt_server))); #endif NAS_DEBUG("trying %d connections\n", server_cnt); for (i = 0; i<server_cnt; i++) if ((aud = nas_try_connection(server[i]))) break; if (!aud) { NAS_DEBUG_C("cannot contact any NAS server\n"); warn_when_safe(Qnas, Qwarning, GETTEXT("No NAS servers in sight.\n")); return NULL; /* Could not contact NAS server */ } /* -- initialise -- */ snd = xnew_and_zero(sound_nas_data_t); snd->aud = aud; /* round up SOUND_MAX_AUDIO_FRAME_SIZE to multiple of NAS_FRAG_SIZE * divide by 3 first because of 2:1 split */ snd->proposed_buffer_size = (SOUND_MAX_AUDIO_FRAME_SIZE/3 + NAS_FRAG_SIZE-1) & ~(NAS_FRAG_SIZE-1); NAS_DEBUG_C("proposed buffer size: %u\n", snd->proposed_buffer_size); NAS_DEBUG_C("created: 0x%x\n", (unsigned int)snd); return snd; }
static void print_device (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) { struct device *d = XDEVICE (obj); char buf[256]; if (print_readably) error ("printing unreadable object #<device %s 0x%x>", XSTRING_DATA (d->name), d->header.uid); sprintf (buf, "#<%s-device", !DEVICE_LIVE_P (d) ? "dead" : DEVICE_TYPE_NAME (d)); write_c_string (buf, printcharfun); if (DEVICE_LIVE_P (d) && !NILP (DEVICE_CONNECTION (d))) { write_c_string (" on ", printcharfun); print_internal (DEVICE_CONNECTION (d), printcharfun, 1); } sprintf (buf, " 0x%x>", d->header.uid); write_c_string (buf, printcharfun); }
static void nas_setup_defaults(char **server, int *cnt) { int i; Lisp_Object tmp; /* considering some defaults */ NAS_DEBUG("trying to find some defaults\n"); #ifdef HAVE_X_WINDOWS /* check for the device connection of the currently active frame */ tmp = Fselected_device(Qnil); if (DEVICEP(tmp) && DEVICE_X_P(XDEVICE(tmp))) server[(*cnt)++] = (char*)XSTRING_DATA( DEVICE_CONNECTION(XDEVICE(tmp))); /* tbd: check for conn of the initial frame */ #endif /* try to look for $AUDIOSERVER */ if ((server[(*cnt)] = getenv("AUDIOSERVER"))) { /* only add the stuff, if not already in the try queue */ for (i=0; i < (*cnt); i++) if (strcmp(server[i], server[(*cnt)]) == 0) break; if (i == (*cnt)) (*cnt)++; } /* try to look for $DISPLAY */ if ((server[(*cnt)] = getenv("DISPLAY"))){ /* only add the stuff, if not already in the try queue */ for (i=0; i < (*cnt); i++) if (strcmp(server[i], server[(*cnt)]) == 0) break; if (i == (*cnt)) (*cnt)++; } /* oh, let's try localhost:0.0, if not already there of course */ for (i=0; i < (*cnt); i++) if (strcmp(server[i], "localhost:0.0") == 0) break; if (i == (*cnt)) server[(*cnt)++] = "localhost:0.0"; /* finally we try NULL, too */ server[(*cnt)++] = NULL; return; }
static void signal_open_printer_error (struct device *d) { invalid_operation ("Failed to open printer", DEVICE_CONNECTION (d)); }