home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume7 / marquis < prev    next >
Text File  |  1989-07-21  |  9KB  |  389 lines

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