home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2512 next >
Encoding:
Internet Message Format  |  1992-11-15  |  9.2 KB

  1. Path: sparky!uunet!psgrain!percy!hfglobe!ichips!iWarp.intel.com|eff!sol.ctr.columbia.edu!ira.uka.de!ira.uka.de!chx400!sicsun!disuns2!lslsun4!chris
  2. From: chris@lslsun4.epfl.ch (Christian Iseli)
  3. Newsgroups: alt.sources
  4. Subject: Unofficial xgopher patch to display images
  5. Keywords: xgopher gopher
  6. Message-ID: <5107@disuns2.epfl.ch>
  7. Date: 15 Nov 92 15:40:30 GMT
  8. Sender: news@disuns2.epfl.ch
  9. Followup-To: alt.sources.d
  10. Organization: Ecole Polytechnique Federale de Lausanne
  11. Lines: 326
  12. Nntp-Posting-Host: lslsun4.epfl.ch
  13.  
  14. Here is a quick hack to add the possibility for xgopher to display
  15. images (for example Meteosat images which can be found on various gopher
  16. servers). It's just a quick hack, but seems to do the trick. It's based
  17. on the sound playing stuff. Here's the diff against the xgopher 1.1
  18. release. This patch is, of course, totally unofficial and utterly
  19. unsupported :-)
  20.  
  21. --------- apply with patch -----------------------
  22.  
  23. *** Xgopher.ad.orig    Sun Nov 15 15:20:16 1992
  24. --- Xgopher.ad    Sun Nov 15 16:09:28 1992
  25. ***************
  26. *** 12,17 ****
  27. --- 12,19 ----
  28.   Xgopher.directoryTime:            600
  29.   Xgopher.hasSound:            True
  30.   Xgopher.soundCommand:            /usr/bin/tr -d '\012\015' | play -v7
  31. + Xgopher.hasImage:            True
  32. + Xgopher.imageCommand:            /usr/local/bin/xv -
  33.   Xgopher.allowTelnet:            True
  34.   Xgopher.telnetCommand:            xterm -e telnet
  35.   Xgopher.itemStart:            500
  36. *** conf.h.orig    Sun Nov 15 15:10:22 1992
  37. --- conf.h    Sun Nov 15 16:09:02 1992
  38. ***************
  39. *** 35,40 ****
  40. --- 35,42 ----
  41.   #define DIRECTORY_TIME    600        /* number of seconds a dir is valid */
  42.   #define HAS_SOUND    TRUE        /* the X server(!) has sound      */
  43.   #define SOUND_COMMAND    "/usr/bin/tr -d '\012\015' | play -v7"    /* command to get sound out        */
  44. + #define HAS_IMAGE    TRUE        /* the X server(!) has image      */
  45. + #define IMAGE_COMMAND    "/usr/local/bin/xv -"    /* command to get image out        */
  46.   #define ALLOW_TELNET    TRUE        /* allow telnet sessions          */
  47.   #define TELNET_COMMAND    "xterm -e telnet"
  48.                       /* command to start telnet        */
  49. ***************
  50. *** 54,59 ****
  51. --- 56,62 ----
  52.   #define PREFIX_INDEX    "<idx> "    /* listing prefix for index search   */
  53.   #define PREFIX_TELNET    "<tel> "    /* listing prefix for telnet session */
  54.   #define PREFIX_SOUND    "<snd> "    /* listing prefix for sound files    */
  55. + #define PREFIX_IMAGE    "<img> "    /* listing prefix for image files    */
  56.   #define PREFIX_UNKNOWN    "<???> "    /* listing prefix for unknown files  */
  57.   
  58.   /* ----- end of application defaults ---- */
  59. *** gopher.h.orig    Sun Nov 15 15:31:00 1992
  60. --- gopher.h    Sun Nov 15 15:31:56 1992
  61. ***************
  62. *** 75,80 ****
  63. --- 75,81 ----
  64.   #define A_CNS        '9'
  65.   #define A_DUP_SERVER    '+'
  66.   #define A_SOUND        's'
  67. + #define A_IMAGE        'I'
  68.   #define A_EVENT        'e'
  69.   #define A_CALENDAR    'c'
  70.   #define A_EOI        '.'
  71. *** options.c.orig    Sun Nov 15 15:14:23 1992
  72. --- options.c    Sun Nov 15 15:18:35 1992
  73. ***************
  74. *** 101,106 ****
  75. --- 101,107 ----
  76.       makePrefix(prefixIndex,  appResources.prefixIndex);
  77.       makePrefix(prefixTelnet, appResources.prefixTelnet);
  78.       makePrefix(prefixSound,  appResources.prefixSound);
  79. +     makePrefix(prefixImage,  appResources.prefixImage);
  80.       makePrefix(prefixUnknown,appResources.prefixUnknown);
  81.   
  82.   #ifdef DEBUG
  83. ***************
  84. *** 127,132 ****
  85. --- 128,137 ----
  86.               appResources.hasSound ? "True" : "False");
  87.       LOG (logFP, "\tsoundCommand:\t%s\n",
  88.               appResources.soundCommand);
  89. +     LOG (logFP, "\thasImage:\t%s\n",
  90. +             appResources.hasImage ? "True" : "False");
  91. +     LOG (logFP, "\timageCommand:\t%s\n",
  92. +             appResources.imageCommand);
  93.       LOG (logFP, "\tallowTelnet:\t%s\n",
  94.               appResources.allowTelnet ? "True" : "False");
  95.       LOG (logFP, "\ttelnetCommand:\t%s\n",
  96. ***************
  97. *** 160,165 ****
  98. --- 165,172 ----
  99.                PREFIX_LEN, appResources.prefixIndex);
  100.       LOG (logFP, "\tprefixSound:\t%.*s\n",
  101.                PREFIX_LEN, appResources.prefixSound);
  102. +     LOG (logFP, "\tprefixImage:\t%.*s\n",
  103. +              PREFIX_LEN, appResources.prefixImage);
  104.       LOG (logFP, "\tprefixUnknown:\t%.*s\n",
  105.                PREFIX_LEN, appResources.prefixUnknown);
  106.   #endif /* DEBUG */
  107. *** options.h.orig    Sun Nov 15 15:23:40 1992
  108. --- options.h    Sun Nov 15 15:28:02 1992
  109. ***************
  110. *** 37,42 ****
  111. --- 37,44 ----
  112.       int        directoryTime;
  113.       Boolean        hasSound;
  114.       String        soundCommand;
  115. +     Boolean        hasImage;
  116. +     String        imageCommand;
  117.       Boolean        allowTelnet;
  118.       String        telnetCommand;
  119.       int        itemStart;
  120. ***************
  121. *** 53,58 ****
  122. --- 55,61 ----
  123.       String        prefixCSO;
  124.       String        prefixIndex;
  125.       String        prefixSound;
  126. +     String        prefixImage;
  127.       String        prefixUnknown;
  128.       } gopherAppResources, *gopherAppResourcesP;
  129.   
  130. ***************
  131. *** 86,91 ****
  132. --- 89,98 ----
  133.           GOffset(hasSound), XtRImmediate, (XPointer) HAS_SOUND},
  134.       {"soundCommand", "SoundCommand", XtRString, sizeof(String),
  135.           GOffset(soundCommand), XtRString, SOUND_COMMAND},
  136. +     {"hasImage", "HasImage", XtRBoolean, sizeof(Boolean),
  137. +         GOffset(hasImage), XtRImmediate, (XPointer) HAS_IMAGE},
  138. +     {"imageCommand", "ImageCommand", XtRString, sizeof(String),
  139. +         GOffset(imageCommand), XtRString, IMAGE_COMMAND},
  140.       {"allowTelnet", "AllowTelnet", XtRBoolean, sizeof(Boolean),
  141.           GOffset(allowTelnet), XtRImmediate, (XPointer) ALLOW_TELNET},
  142.       {"telnetCommand", "TelnetCommand", XtRString, sizeof(String),
  143. ***************
  144. *** 118,123 ****
  145. --- 125,132 ----
  146.           GOffset(prefixIndex), XtRString, PREFIX_INDEX},
  147.       {"prefixSound", "prefixSound", XtRString, sizeof(String),
  148.           GOffset(prefixSound), XtRString, PREFIX_SOUND},
  149. +     {"prefixImage", "prefixImage", XtRString, sizeof(String),
  150. +         GOffset(prefixImage), XtRString, PREFIX_IMAGE},
  151.       {"prefixUnknown", "prefixUnknown", XtRString, sizeof(String),
  152.           GOffset(prefixUnknown), XtRString, PREFIX_UNKNOWN},
  153.       };
  154. *** prefixP.h.orig    Sun Nov 15 15:56:54 1992
  155. --- prefixP.h    Sun Nov 15 15:57:12 1992
  156. ***************
  157. *** 21,24 ****
  158. --- 21,25 ----
  159.       prefixIndex   [PREFIX_LEN],
  160.       prefixTelnet  [PREFIX_LEN],
  161.       prefixSound   [PREFIX_LEN],
  162. +     prefixImage   [PREFIX_LEN],
  163.       prefixUnknown [PREFIX_LEN];
  164. *** util.c.orig    Sun Nov 15 15:09:29 1992
  165. --- util.c    Sun Nov 15 16:07:47 1992
  166. ***************
  167. *** 92,97 ****
  168. --- 92,100 ----
  169.           case A_SOUND:
  170.           PREFIX(gi, prefixSound);
  171.           break;
  172. +         case A_IMAGE:
  173. +         PREFIX(gi, prefixImage);
  174. +         break;
  175.           case A_EOI:
  176.           freeItem(gi);
  177.           return NULL;
  178. ***************
  179. *** 155,161 ****
  180.                   gi->type == A_CSO ||
  181.                   gi->type == A_INDEX ||
  182.                   gi->type == A_TELNET ||
  183. !                 gi->type == A_SOUND) {
  184.                   appendItem(&(d->contents), gi);
  185.   
  186.               } else {
  187. --- 158,165 ----
  188.                   gi->type == A_CSO ||
  189.                   gi->type == A_INDEX ||
  190.                   gi->type == A_TELNET ||
  191. !                 gi->type == A_SOUND ||
  192. !                 gi->type == A_IMAGE) {
  193.                   appendItem(&(d->contents), gi);
  194.   
  195.               } else {
  196. ***************
  197. *** 558,563 ****
  198. --- 562,665 ----
  199.       }
  200.   }
  201.   
  202. + /* getImage
  203. +    get an image file and display it. */
  204. + BOOLEAN
  205. + getImage(gi)
  206. + gopherItemP    gi;
  207. + {
  208. +     static BOOLEAN    firstTime = TRUE;
  209. +     static BOOLEAN    imageCommandOK = TRUE;
  210. +     static char    *imageCmd;
  211. +     char        message[MESSAGE_STRING_LEN];
  212. +     FILE        *imageCmdFile;
  213. +     int        s;
  214. +     static int    childPID = 0;
  215. +     /* see if image command is turned on */
  216. +     if (! appResources->hasImage) {
  217. +         showError("This machine does not support images.");
  218. +         return FALSE;
  219. +     }
  220. +     if (childPID != 0) {    /* image may still be active */
  221. +         union wait    status;
  222. +         int        pid;
  223. +         struct rusage    rusage;
  224. +         pid = wait3(&status, WNOHANG, &rusage);
  225. +         if (pid == 0) {
  226. +             showError("Another image file is still showing. Close it first.");
  227. +             return FALSE;
  228. +         } else if (pid == childPID) {
  229. +             childPID = 0;
  230. +         } else {
  231. +             showError("It doesn't look good for showing any more images.");
  232. +             return FALSE;
  233. +         }
  234. +     }
  235. +     /* see if image command is an executable file */
  236. +     if (firstTime) {
  237. +         firstTime = FALSE;
  238. +         imageCmd = cmdPath(appResources->imageCommand);
  239. +         if (imageCmd == NULL) {
  240. +             imageCommandOK = FALSE;
  241. +         }
  242. +     }
  243. +     if (! imageCommandOK) {
  244. +         sprintf (message,
  245. +             "Unable to execute the image display command: \'%s\'\n",
  246. +             imageCmd);
  247. +         showError(message);
  248. +         return FALSE;
  249. +     }
  250. +     if ((childPID = fork()) < 0) {
  251. +         sprintf(message,
  252. +             "Unable to display the image (error %d)\n",
  253. +             errno);
  254. +         showError(message);
  255. +         return FALSE;
  256. +     } else if (childPID != 0) {
  257. +         return TRUE;
  258. +     } else {
  259. +         s = connectToSocket(gi->host, gi->port);
  260. +         if (s < 0) {
  261. +             networkError(s, gi->host, gi->port);
  262. +             return FALSE;
  263. +         }
  264. +         writeString(s, vStringValue(&(gi->selector)));
  265. +         writeString(s, EOL_STRING);
  266. +         imageCmdFile = popen(imageCmd, "w");
  267. +         if (imageCmdFile == NULL) {
  268. +             sprintf(message,
  269. +             "Unable to start the image command (\'%s\')\n",
  270. +                 imageCmd);
  271. +             showError(message);
  272. +             close (s);
  273. +             exit(-1);
  274. +         }
  275. +         copyNetUntilEOF(s, imageCmdFile);
  276. +         close(s);
  277. +         pclose(imageCmdFile);
  278. +         exit(0);
  279. +     }
  280. + }
  281.   
  282.   #define NET_BUFFER_SIZE    1400
  283.   
  284. ***************
  285. *** 758,763 ****
  286. --- 860,870 ----
  287.              by getSound. */
  288.   
  289.           result = getSound(gi);
  290. +         
  291. +         break;
  292. +     case A_IMAGE:
  293. +         result = getImage(gi);
  294.           
  295.           break;
  296.   
  297. *** util.h.orig    Sun Nov 15 15:51:32 1992
  298. --- util.h    Sun Nov 15 15:52:11 1992
  299. ***************
  300. *** 84,89 ****
  301. --- 84,95 ----
  302.   #endif
  303.   );
  304.   
  305. + BOOLEAN getImage(
  306. + #ifdef PROTO
  307. +     gopherItemP    /* gi */
  308. + #endif
  309. + );
  310.   void    getTempFile(
  311.   #ifdef PROTO
  312.       char *        /* tempName */
  313.  
  314. -- 
  315.  
  316.                     Christian Iseli
  317.                     LSL-DI-EPFL
  318.                     Lausanne, Switzerland
  319.