home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume07 / marquis < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  9.1 KB

  1. From decwrl!ucbvax!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!allbery Thu Aug  3 08:50:25 PDT 1989
  2. Article 981 of comp.sources.misc:
  3. Path: decwrl!ucbvax!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v07i089: marquis -- scroll a message on the status line of a terminal
  7. Message-ID: <61152@uunet.UU.NET>
  8. Date: 22 Jul 89 00:51:33 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: falcon@gorn.santa-cruz.ca.us (frederick smythe)
  11. Organization: The Planet Gorn
  12. Lines: 381
  13. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  14.  
  15. Posting-number: Volume 7, Issue 89
  16. Submitted-by: falcon@gorn.santa-cruz.ca.us (frederick smythe)
  17. Archive-name: marquis
  18.  
  19. [[Warning:  when he says "System V", he means Xenix.  If SysV.3.2 has nap(),
  20.   it will work there as well.  ++bsa]]
  21.  
  22. : to unbundle, sh this file -- DO NOT use csh
  23. : This is SHAR archive format.
  24. : Archive created Mon Jul 10 21:45:00 PDT 1989
  25. : Packed by falcon@gorn (frederick smythe)
  26. echo x - makefile
  27. sed 's/^X//' > makefile <<'+FUNKY+STUFF+'
  28. X# for sysv
  29. XCFLAGS = -DSYSV -O
  30. XLDFLAGS = -lx -ltermcap
  31. X
  32. X# for non-sysv
  33. X#CFLAGS = -O
  34. X#LDFLAGS = -ltermcap
  35. X
  36. XBINDIR = /usr/gorn/bin
  37. X
  38. Xall: marquis
  39. X
  40. Xinstall: marquis
  41. X    @mv -f marquis $(BINDIR)/marquis
  42. X    @chmod 711 $(BINDIR)/marquis
  43. X    @l $(BINDIR)/marquis
  44. X
  45. Xmarquis: marquis.o
  46. X    cc marquis.o -s -o marquis $(LDFLAGS)
  47. X    @rm marquis.o
  48. +FUNKY+STUFF+
  49. chmod u=rw,g=,o= makefile
  50. echo x - marquis.1
  51. sed 's/^X//' > marquis.1 <<'+FUNKY+STUFF+'
  52. X.TH MARQUIS 1
  53. X.UC 5
  54. X.SH NAME
  55. Xmarquis \- scroll a message on the status line of a terminal
  56. X.SH SYNOPSIS
  57. Xmarquis { "string" | /filename } [ naptime ]
  58. X.SH DESCRIPTION
  59. X\fIMarquis\fR allows you to take a string or 
  60. Xthe contents of a file and have it scroll across
  61. Xthe status line of your terminal.  It is annoying at times
  62. Xand helpful at other times.  It can be used for displaying
  63. Xuseful reminders or just simple messages.  Upon invocation the pid
  64. Xof the marquis process is printed to stdout so it can be captured
  65. Xwith "set mpid=`marquis /etc/motd`".
  66. X.SH USAGE
  67. XThe first argument to marquis must be present.  If it begins
  68. Xwith a forward slash (/) it is interpreted to be the name of a
  69. Xfile to read the data from.  If it is not led by a slash, it is
  70. Xinterpreted as a string.  An optional second argument may be
  71. Xspecified which will change the naptime between updates from the
  72. Xdefault of 150 ms.
  73. X.SH EXAMPLES
  74. XTo display "YUeYUeyUEyuEyuEyuE":
  75. X.sp
  76. X.br
  77. X% marquis YUeYUeyUEyuEyuEyuE
  78. X.sp
  79. X.br
  80. XTo display "FlaPaFLAppAFlAPFlAP FlaPflAp" using 300ms as the naptime:
  81. X.sp
  82. X.br
  83. X% marquis "FlaPaFLAppAFlAPFlAP  FlaPflAp" 300
  84. X.sp
  85. X.br
  86. XTo display the contents of "madonna.dat" using 100ms as the naptime:
  87. X.sp
  88. X.br
  89. X% marquis /path/to/madonna.dat 100
  90. X.SH BUGS
  91. XThis program was never really finished so it has no _real_
  92. Xargument processing.  Future features might be periodic checking
  93. Xof a file to see if its contents should be reloaded as the data.
  94. X.sp
  95. X.br
  96. XPlease send any problems, questions, or suggestions to the author.
  97. X.SH AUTHOR
  98. Xfrederick smythe, esquire (falcon@gorn.santa-cruz.ca.us)
  99. +FUNKY+STUFF+
  100. chmod u=rw,g=,o= marquis.1
  101. echo x - marquis.c
  102. sed 's/^X//' > marquis.c <<'+FUNKY+STUFF+'
  103. X/********
  104. X * @(#) marquis.c    falcon@gorn.santa-cruz.ca.us    03/28/89
  105. X *
  106. X * marquis is a program to display a string of characters scrolling
  107. X * across the status line of a terminal.  it works best at high baud
  108. X * rate direct terminals, obiviously, but can work ok even at 2400 baud.
  109. X * (i use it at 19.2k myself)
  110. X *
  111. X * Idea blamed on: mikeha@sco.COM
  112. X * 
  113. X * Copyright: feel free to distribute this chunk 'o code freely as long
  114. X *            as this original header is included.  also feel free to modify
  115. X *            to your liking, but modifications from the original must be
  116. X *            noted by means of inline comments. if modifications are made,
  117. X *            please send a copy of the diffs back to me.
  118. X *
  119. X * vi: set ts=4 sw=4 ai
  120. X */
  121. X
  122. X#include    <stdio.h>
  123. X#include    <sgtty.h>
  124. X#include    <signal.h>
  125. X#define        stderR        stderr
  126. X
  127. Xchar    gosl[10],
  128. X        lvsl[10],    /* go status line and leave status line */
  129. X        bp[1024],    /* buffers for tgetent () */
  130. X        buffer[200];/* ^^^^^^^^^^^^^ */
  131. X    
  132. Xextern    char    *malloc (),
  133. X                *getenv ();
  134. Xvoid    rotate (),
  135. X        tinit ();
  136. Xchar    *tget (),
  137. X        *getthatstringfromafilecalled (/*filename would be here*/);
  138. Xint        cleanup ();
  139. X
  140. Xmain ( argc, argv )
  141. Xint        argc;
  142. Xchar    **argv;
  143. X{
  144. X    char    *str,            /* the string to be displayed */
  145. X            buf[BUFSIZ];    /* temporary buffer */
  146. X    long    naptime = 150L;    /* default micro seconds between updates */
  147. X    int        len,
  148. X            pid;
  149. X
  150. X    /*
  151. X     * make sure termcap can handle sysline
  152. X     */
  153. X    tinit ();
  154. X
  155. X    /*
  156. X     * first argument is either the string to be displayed
  157. X     * or the name of a file to be displayed (if it begins with a /)
  158. X     */
  159. X    if ( argv[1][0] == '/' )
  160. X    {
  161. X        str = getthatstringfromafilecalled (argv[1]);
  162. X    }
  163. X    else
  164. X    {
  165. X        len = strlen (argv[1]);
  166. X        len = strlen (argv[1]) < 80 ? 80 : len;
  167. X        str = malloc (len+1);
  168. X        (void) sprintf (str, "%-79s", argv[1]);
  169. X    }
  170. X
  171. X    /*
  172. X     * save these termcap values 
  173. X     */
  174. X    (void) strcpy (gosl, tget ("ts"));
  175. X    (void) strcpy (lvsl, tget ("fs"));
  176. X
  177. X    /*
  178. X     * if they dont have both entries, forget 'em and exit
  179. X     */
  180. X    if ( !gosl[0] || !lvsl[0] )
  181. X    {
  182. X        (void) fputs 
  183. X            ("your terminal doesn't have status line capabilties, you nobk!\n", 
  184. X            stderR);
  185. X        (void) exit (1);
  186. X    }    
  187. X
  188. X    /*
  189. X     * if there is another argument, it is an override
  190. X     * naptime
  191. X     */
  192. X    if ( argc > 2 )
  193. X    {
  194. X        naptime = atol (argv[2]);
  195. X    }
  196. X
  197. X    /*
  198. X     * fork off and die, printing the pid first
  199. X     */
  200. X    if ( (pid = fork ()) )
  201. X    {
  202. X        (void) printf ("%d\r\n", pid);
  203. X        (void) exit (0);
  204. X    }
  205. X
  206. X    /*
  207. X     * ignore sigint/sigquit and catch
  208. X     * sigterm and sighup to clear the status line and exit
  209. X     */
  210. X    (void) signal (SIGINT, SIG_IGN);
  211. X    (void) signal (SIGQUIT, SIG_IGN);
  212. X    (void) signal (SIGTERM, cleanup);
  213. X    (void) signal (SIGHUP, cleanup);
  214. X
  215. X    /*
  216. X     * infinite looooooooooooooop
  217. X     */
  218. X    for ( ; ; )
  219. X    {
  220. X        (void) sprintf (buf, "%s%-79.79s%s", gosl, str, lvsl);
  221. X        (void) write (1, buf, strlen (buf));
  222. X        rotate (str);
  223. X        (void) nap (naptime);
  224. X    }
  225. X}
  226. X
  227. X/*
  228. X * rotate () -- takes a string and shifts it one character to the left, with
  229. X *              wrapping
  230. X */
  231. Xvoid
  232. Xrotate (str)
  233. Xchar    *str;
  234. X{
  235. X    char    p = *str;
  236. X    long    len = strlen (str);
  237. X
  238. X    (void) strncpy (str, str+1, len - 1);
  239. X    str[len] = '\0';
  240. X    str[len-1] = p;
  241. X}
  242. X
  243. X/*
  244. X * tinit () -- makes sure we have a valid termcap 
  245. X */
  246. Xvoid
  247. Xtinit()
  248. X{
  249. X    char    *name;
  250. X
  251. X    switch (tgetent (bp, name = getenv("TERM")) ) 
  252. X    {
  253. X        case -1:
  254. X            (void) printf ("can't open termcap file.\n");
  255. X            (void) exit (-1);
  256. X        case 0:
  257. X            (void) printf ("No termcap entry for %s.\n", name);
  258. X            (void) exit (-1);
  259. X    }
  260. X}
  261. X    
  262. X/*
  263. X * tget () -- returns the termcap entry for the passed code
  264. X */
  265. Xchar *
  266. Xtget (code)
  267. Xchar    *code;
  268. X{
  269. X    char    *area = buffer,
  270. X            *tgetstr();
  271. X
  272. X    return (tgetstr (code, &area));
  273. X}
  274. X
  275. X/*
  276. X * getthatstringfromafilecalled () -- reads in a file into a character buffer, 
  277. X *                                    replacing special characters with spaces
  278. X */
  279. X
  280. X#include    <sys/types.h>
  281. X#include    <sys/stat.h>
  282. X
  283. Xchar *
  284. Xgetthatstringfromafilecalled (filename)
  285. Xchar    *filename;
  286. X{
  287. X    FILE    *fp;            /* file pointer to zis file */
  288. X    struct    stat    sbuf;    /* stat buffer */
  289. X    char    *buf,            /* buffer to hold contents of file */
  290. X            *start;            /* pointer to start of resulting string */
  291. X
  292. X    /*
  293. X     * get the size of the file
  294. X     */
  295. X    if ( stat (filename, &sbuf) < 0 )
  296. X    {
  297. X        (void) perror (filename);
  298. X        (void) exit (2);
  299. X    }
  300. X
  301. X    /*
  302. X     * open the file for reading, if it fails, just exit
  303. X     */
  304. X    if ( (fp = fopen (filename, "r")) == (FILE *) NULL )
  305. X    {
  306. X        (void) perror (filename);
  307. X        (void) exit (2);
  308. X    }
  309. X
  310. X    /*
  311. X     * malloc mr. memory
  312. X     */
  313. X    if ( (buf = malloc (sbuf.st_size)) == (char *) NULL )
  314. X    {
  315. X        (void) fprintf (stderr, "cannot malloc %ld bytes!\n", sbuf.st_size);
  316. X        (void) fclose (fp);
  317. X        (void) exit (2);
  318. X    }
  319. X
  320. X    /*
  321. X     * now read it in and null terminate it
  322. X     */
  323. X    (void) fread (buf, sbuf.st_size, 1, fp);
  324. X    buf[sbuf.st_size] = '\0';
  325. X
  326. X    /*
  327. X     * save the starting position to return,
  328. X     * and then convert all newlines and tabs into spaces
  329. X     */
  330. X    start = buf;
  331. X
  332. X    while ( *buf != '\0' )
  333. X    {
  334. X        if ( *buf == '\n' || *buf == '\t' || *buf == '\r' )
  335. X        {
  336. X            *buf = ' ';
  337. X        }
  338. X
  339. X        ++buf;
  340. X    }
  341. X
  342. X    return (start);
  343. X}
  344. X
  345. X/*
  346. X * cleanup () -- clear the status line and exit
  347. X */
  348. Xint
  349. Xcleanup (sig)
  350. Xint    sig;
  351. X{
  352. X    char    buf[25];
  353. X    
  354. X    (void) sprintf (buf, "%s%s", gosl, lvsl);
  355. X    (void) write (1, buf, strlen (buf));
  356. X    (void) sprintf (buf, "marquis: got signal #%d\n\r", sig);
  357. X    (void) write (1, buf, strlen (buf));
  358. X    (void) exit (0);
  359. X}
  360. X
  361. X#ifndef    SYSV
  362. X
  363. X#include    <sys/time.h>
  364. Xint            nil ();
  365. X
  366. Xnap (usec)
  367. Xlong    usec;
  368. X{
  369. X    (void) timer (usec);
  370. X    (void) pause ();
  371. X}
  372. X
  373. Xint
  374. Xtimer (usec)
  375. Xlong    usec;
  376. X{
  377. X    struct itimerval temptime;
  378. X    struct itimerval uptime;
  379. X
  380. X    uptime.it_interval.tv_sec = 0;
  381. X    uptime.it_interval.tv_usec = usec;
  382. X    uptime.it_value.tv_sec = 1;
  383. X    uptime.it_value.tv_usec = 0;
  384. X
  385. X    signal (SIGALRM, nil);
  386. X    return (setitimer (0, &uptime, &temptime));
  387. X}
  388. X
  389. Xint nil () {}
  390. X
  391. X#endif    /* !SYSV */
  392. +FUNKY+STUFF+
  393. chmod u=rw,g=,o= marquis.c
  394. echo Unpacking complete.
  395. exit 0
  396.  
  397.  
  398.