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

  1. From decwrl!purdue!mailrus!ncar!tank!nic.MR.NET!hal!ncoast!allbery Sun Nov 13 00:43:36 PST 1988
  2. Article 714 of comp.sources.misc:
  3. Path: granite!decwrl!purdue!mailrus!ncar!tank!nic.MR.NET!hal!ncoast!allbery
  4. From: russ%uokmax@uokmax.ecn.uoknor.edu (Russ 'Random' Smith)
  5. Newsgroups: comp.sources.misc
  6. Subject: v05i038: screens - displays randomly selected file
  7. Message-ID: <8811021857.AA20299@uunet.UU.NET>
  8. Date: 9 Nov 88 02:16:38 GMT
  9. Sender: allbery@ncoast.UUCP
  10. Reply-To: russ%uokmax@uokmax.ecn.uoknor.edu (Russ 'Random' Smith)
  11. Lines: 185
  12. Approved: allbery@ncoast.UUCP
  13.  
  14. Posting-number: Volume 5, Issue 38
  15. Submitted-by: "Russ 'Random' Smith" <russ%uokmax@uokmax.ecn.uoknor.edu>
  16. Archive-name: screens
  17.  
  18. [A quick scan reveals one BSDism (random()).  Otherwise only the terminal
  19. dependency should provide a problem.  ++bsa]
  20.  
  21. This is an interesting little "toy" that will dsiplay a randomly selected
  22. file from a directory $HOME/.screens.  I wrote it with .logout files in
  23. mind (I still use it in mine), but some enterprising mind might come up with
  24. another use (a terminal lock, perhaps).
  25.  
  26. There is an interesting feature for Zenith terminal users (check the README
  27. and the man page), which may be expanded for use with ANSI people someday.
  28.  
  29. ---- Cut Here and unpack ----
  30. #!/bin/sh
  31. # shar:    Shell Archiver  (v1.22)
  32. #
  33. #    Run the following text with /bin/sh to create:
  34. #      Makefile
  35. #      README
  36. #      screens.6
  37. #      screens.c
  38. #      screens.sh
  39. #
  40. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  41. XDESTBIN = /usr/local
  42. XDESTMAN = /usr/local/doc
  43. X
  44. X# you will probably want to chown screens to bin or root, but it isn't necessary
  45. X
  46. Xcreate:        screens screens.man
  47. X
  48. Xinstall:    screens screens.man
  49. X        mv screens $(DESTBIN)
  50. X        mv screens.man $(DESTMAN)
  51. X        
  52. Xscreens:    screens.c
  53. X        cc -O -o screens screens.c
  54. X        strip screens
  55. X        chmod 711 screens
  56. X
  57. Xscreens.man:    screens.6
  58. X        nroff -man screens.6 > screens.man
  59. SHAR_EOF
  60. chmod 0640 Makefile || echo "restore of Makefile fails"
  61. sed 's/^X//' << 'SHAR_EOF' > README &&
  62. XScreens is a simple utility to grab a random "screen" from the directory
  63. Xgiven by $HOME/.screens and put it on the terminal screen.  Normally, it's
  64. Xan ascii file, but if you have files in that directory that end in ".g",
  65. Xand have a terminal with Zenith emulation, it will display that file in
  66. XZenith graphics mode.  Naturally, you can always put the graphics escape
  67. Xcodes for whatever terminal in your file.
  68. X
  69. XAny bug reports go to russ@uokmax.UUCP or texsun!uokmax!russ.  Thanks.
  70. X
  71. X
  72. X
  73. SHAR_EOF
  74. chmod 0640 README || echo "restore of README fails"
  75. sed 's/^X//' << 'SHAR_EOF' > screens.6 &&
  76. X.TH SCREENS 6 "Local Manual                 7/19/88"
  77. X.SH NAME
  78. Xscreens \- Random screen displayer
  79. X.SH SYNOPSIS
  80. X.B screens
  81. X.SH DESCRIPTION
  82. X.I Screens 
  83. Xscans your
  84. X.BI $HOME/.screens
  85. Xdirectory, and picks a random file to display
  86. Xon the screen.  If the filename ends with
  87. X.I .g,
  88. Xit turns on z29a graphics
  89. Xmode first.
  90. X.SH FILES
  91. X$HOME/.screens/*
  92. X.SH BUGS
  93. XIf you have some mutant terminal type which starts with z but isn't zenith
  94. Xgraphics compatible,
  95. X.B screens
  96. Xmay select a zenith screen (if you have one).
  97. X.SH AUTHOR
  98. XRuss Smith
  99. SHAR_EOF
  100. chmod 0640 screens.6 || echo "restore of screens.6 fails"
  101. sed 's/^X//' << 'SHAR_EOF' > screens.c &&
  102. X#include <stdio.h>
  103. X#include <strings.h>
  104. X#include <sys/types.h>
  105. X#include <sys/dir.h>
  106. X#include <sys/stat.h>
  107. X
  108. Xmain()
  109. X{
  110. X    int i,q,filno;
  111. X    int graph = 0;
  112. X    struct direct **nlist;
  113. X    int select();
  114. X    char dirname[80],fname[80];
  115. X
  116. X    srandom(time(0));
  117. X    strcpy(dirname,getenv("HOME"));
  118. X    strcat(dirname,"/.screens");
  119. X    if (chdir(dirname)) {
  120. X        fprintf(stderr,"mode: You must have a $HOME/.screens directory.\n");
  121. X        exit(1);
  122. X    }
  123. X    q = scandir(dirname,&nlist,select,NULL);
  124. X    if (q < 1) {
  125. X        fprintf(stderr,"mode: You must have at least one file in ");
  126. X        fprintf(stderr,"your $HOME/.screens directory.\n");
  127. X        exit(1);
  128. X    }
  129. X    filno = ((random()>>4)%q);
  130. X    strcpy(fname,nlist[filno]->d_name);
  131. X    if ((strind(fname,".g") == strlen(fname) - 2) && (!strncmp(getenv("TERM"),"z",1)))
  132. X        graph = 1;
  133. X    if (graph)
  134. X        printf("\033[10m");
  135. X    shofile(fname);
  136. X    if (graph)
  137. X        printf("\033[11m");
  138. X    exit(0);
  139. X}
  140. X
  141. Xint select(dirpt)
  142. Xstruct direct *dirpt;
  143. X{
  144. X    struct stat s;
  145. X
  146. X    stat(dirpt->d_name,&s);
  147. X    if ((s.st_mode & S_IFMT) == S_IFREG)
  148. X        return(1);
  149. X    else
  150. X        return(0);
  151. X}
  152. X
  153. Xint strind(str1,str2)
  154. Xchar *str1,*str2;
  155. X
  156. X{
  157. X    int c,res;
  158. X
  159. X    res = 0;
  160. X    if (str1 != NULL)
  161. X        for (c=0; c<=strlen(str1)-strlen(str2); c++)
  162. X            if (!strncmp(&str1[c],str2,strlen(str2)))
  163. X                return(c);
  164. X}
  165. X
  166. Xnochar(string,c)
  167. Xchar *string,c;
  168. X
  169. X{
  170. X    char *p;
  171. X
  172. X    for (p=string;*p != c && *p != '\0'; ++p)
  173. X        ;
  174. X
  175. X    *p = '\0';
  176. X
  177. X    return;
  178. X}
  179. X
  180. Xshofile(fname)
  181. Xchar *fname;
  182. X
  183. X{
  184. X    FILE *f;
  185. X    int c;
  186. X
  187. X    f = fopen(fname,"r");
  188. X    
  189. X    while ((c=fgetc(f)) != EOF)
  190. X        putchar(c);
  191. X}
  192. X
  193. SHAR_EOF
  194. chmod 0640 screens.c || echo "restore of screens.c fails"
  195. sed 's/^X//' << 'SHAR_EOF' > screens.sh &&
  196. SHAR_EOF
  197. chmod 0640 screens.sh || echo "restore of screens.sh fails"
  198. exit 0
  199.  
  200.  
  201.