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

  1. From mipos3!intelca!oliveb!ames!necntc!ncoast!allbery Sat Jan 23 19:37:05 PST 1988
  2. Article 255 of comp.sources.misc:
  3. Path: td2cad!mipos3!intelca!oliveb!ames!necntc!ncoast!allbery
  4. From: nelson@MCNC.ORG (jim nelson)
  5. Newsgroups: comp.sources.misc
  6. Subject: v02i006: Side-by-side file paginator
  7. Message-ID: <7080@ncoast.UUCP>
  8. Date: 15 Jan 88 00:42:01 GMT
  9. Sender: root@ncoast.UUCP
  10. Lines: 285
  11. Approved: allbery@ncoast.UUCP
  12. X-Archive: comp.sources.misc/8801/6
  13. Comp.Sources.Misc: Volume 2, Issue 6
  14. Submitted-By: jim nelson <nelson%mcnc.org@ecsvax.UUCP>
  15. Archive-Name: sbs
  16.  
  17. Comp.Sources.Misc: Volume 2, Issue 6
  18. Submitted-By: jim nelson <nelson%mcnc.org@ecsvax.UUCP>
  19. Archive-Name: sbs
  20.  
  21. [Whatever happened to "pr -m -w80 file1 file2 | more"?  ++bsa]
  22.  
  23. This is a little thingie I (thought) I had to write myself, because
  24. it warnt available.  Presumably I re-invented some wheel; but I
  25. like it.  Pub Dom.  Take it.  If it belongs in comp.sources.misc,
  26. I'll send it over there... it's short.
  27. #  --- cut here ---
  28. #/bin/sh
  29. #This is a shar file.  To use:
  30. #  1. Remove everything before the /bin/sh line
  31. #  2. Execute with /bin/sh (not csh) to extract the files:
  32. #         Makefile
  33. #         sbs.c
  34. file="${0}"
  35. echo extracting Makefile 1>&2
  36. sed -e 's/^X//'  >Makefile << 'EnD of Makefile'
  37. XCFLAGS=
  38. XLDFLAGS=-lcurses #-ltermlib
  39. Xsbs: sbs.o
  40. X    cc sbs.o -o sbs $(LDFLAGS)
  41. EnD of Makefile
  42. echo extracting sbs.c 1>&2
  43. sed -e 's/^X//'  >sbs.c << 'EnD of sbs.c'
  44. X/*puts two files side-by-side on terminal */
  45. X/*for poor folks who don't have windows and suns and all that
  46. Xother stuff*/
  47. X/*no man page: it's not worth it; but i did make a Makefile
  48. Xof sorts*/
  49. X/*this compiles and works perfectly with no alterations on both
  50. XSysVr2(3b2/300) and BSD4.1-derived-GENIX on a nsc16032(lmc)*/
  51. X/*other systems at own risk ...*/
  52. X/*'taint so hot at 1200 baud, but presumably i'm the only
  53. Xperson on earth who still has to put up with measly 1200 baud*/
  54. X/*no copyright, public domain, not worth the effort*/
  55. X/*author: jim nelson, unc-wilmington, wilmington nc 28403;
  56. X919-395-3300*/
  57. X#include <curses.h>
  58. X#define UNIX
  59. X#include <stdio.h>
  60. X#define MAXLINE 82
  61. X#ifdef UNIX
  62. X#include <ctype.h>
  63. X#endif
  64. X/*global variables: */
  65. Xchar left[20][MAXLINE],rite[20][MAXLINE],lft[MAXLINE],rte[MAXLINE];
  66. Xint efl,efr;
  67. Xchar leader[MAXLINE];
  68. Xchar *fnl,*fnr;
  69. X/*end of global variables */
  70. X
  71. Xmain(argc,argv)
  72. Xint argc;
  73. Xchar *argv[];
  74. X
  75. X{
  76. X    FILE *fp1,*fp2;
  77. X    int jhn,prefix,zork,c,i,k,lp,rp;
  78. X    efl=efr=0;
  79. X    fnl=argv[1]; 
  80. X    fnr=argv[2];
  81. X
  82. X    if(argc!=3){
  83. X        printf("usage: sbs file1 file2\n"); 
  84. X        exit (1); 
  85. X    }
  86. X
  87. X
  88. X    if(  (fp2=fopen(argv[2],"r"))  == NULL)
  89. X    {
  90. X        printf("not found:%s\n",argv[2]);
  91. X        exit (1);
  92. X    }
  93. X
  94. X    if(  (fp1=fopen(argv[1],"r"))  == NULL)
  95. X    {
  96. X        printf("not found:%s\n",argv[1]);
  97. X        exit (1);
  98. X    }
  99. X
  100. X    initscr();
  101. X    clear();
  102. X    nocrmode();
  103. X    noecho();
  104. X    raw();
  105. X    lp = rp = (-1);
  106. X    for (k=0;fnl[k];){
  107. X        leader[k]=fnl[k];
  108. X        k++;
  109. X    }
  110. X    while(k<39)leader[k++]='-';
  111. X    leader[k++]=' ';
  112. X    leader[k++]='|';
  113. X    leader[k++]=' ';
  114. X    for(i=0;fnr[i];)leader[k++]=fnr[i++];
  115. X    while(k<75)leader[k++]='-';
  116. X    leader[k]='\0';
  117. X    for(i=0;i<20;i++){
  118. X
  119. X        if(!efl){
  120. X            lp = (lp+1)%20;
  121. X            if(!efl)if(fgets(left[lp],MAXLINE,fp1)==NULL)efl=1;
  122. X            if(efl)strcpy(left[lp],"[EOF]\n");
  123. X        }
  124. X
  125. X        if(!efr){
  126. X            rp = (rp+1)%20;
  127. X            if(!efr)if(fgets(rite[rp],MAXLINE,fp2)==NULL)efr=1;
  128. X            if(efr)strcpy(rite[rp],"[EOF]\n");
  129. X        }
  130. X    }
  131. X    display(lp,rp,' '); /* display is supposed to be fixed up so that
  132. X                the lpth line from left and the rpth line from rite
  133. X                will be the last ones displayed */
  134. X    while(1)
  135. X    {
  136. X
  137. X        prefix=0;
  138. X        lbl: c=getch()&0177;
  139. X        if(c>='0' && c<='9'){prefix=prefix*10+c-'0';goto lbl;}    
  140. X        if(prefix==0)prefix=1;
  141. X
  142. X        if(c==('c'&037)||c==('y'&037)){
  143. X            endwin();
  144. X            exit();
  145. X        }
  146. X        if(isupper(c))c=tolower(c);
  147. X        if(c=='t')c='y';
  148. X        if(c=='j')c='f';
  149. X
  150. X        if(c==';'||c=='f')
  151. X        for(jhn=0;jhn<prefix;jhn++)
  152. X        {
  153. X            rp = (rp+1) % 20;
  154. X            if(!efr)if(fgets(rite[rp],MAXLINE,fp2)==NULL)efr=1;
  155. X            if(efr)strcpy(rite[rp],"[EOF]\n");
  156. X        }
  157. X
  158. X        if (c=='a'||c=='f')
  159. X        for(jhn=0;jhn<prefix;jhn++)
  160. X        {
  161. X            lp = (lp+1) % 20;
  162. X            if(!efl)if(fgets(left[lp],MAXLINE,fp1)==NULL)efl=1;
  163. X            if(efl)strcpy(left[lp],"[EOF]\n");
  164. X        }
  165. X        if (c=='q'||c=='y'||c=='d')
  166. X        for(jhn=0;jhn<prefix;jhn++)
  167. X        {
  168. X            for(i=0;i<20;i++){
  169. X                lp = (lp+1)%20;
  170. X                if(!efl)if(fgets(left[lp],MAXLINE,fp1)==NULL)efl=1;
  171. X                if(efl)strcpy(left[lp],"[EOF]\n");
  172. X            }
  173. X        }
  174. X
  175. X        if (c=='p'||c=='y'||c=='d')
  176. X        for(jhn=0;jhn<prefix;jhn++)
  177. X        {
  178. X            for(i=0;i<20;i++){
  179. X                rp = (rp+1)%20;
  180. X                if(!efr)if(fgets(rite[rp],MAXLINE,fp2)==NULL)efr=1;
  181. X                if(efr)strcpy(rite[rp],"[EOF]\n");
  182. X            }
  183. X        }
  184. X
  185. X        if (c=='d')
  186. X        for(jhn=0;jhn<prefix;jhn++)
  187. X        { 
  188. X            zork=0;
  189. X
  190. X            for(i=0;i<20;i++){
  191. X                lp = (lp+1)%20;
  192. X                rp = (rp+1)%20;
  193. X                if(!zork)if(jstrcmp(left[lp],rite[rp])!=0)zork=1;
  194. X            }
  195. X            while( !zork ) {
  196. X                if(!efr){
  197. X                    rp = (rp+1)%20;
  198. X                    if(!efr)
  199. X                        if(fgets(rite[rp],MAXLINE,fp2)==NULL)efr=1;
  200. X                    if(efr)strcpy(rite[rp],"[EOF]\n");
  201. X                }
  202. X                if(!efl){
  203. X                    lp = (lp+1)%20;
  204. X                    if(!efl)
  205. X                        if(fgets(left[lp],MAXLINE,fp1)==NULL)efl=1;
  206. X                    if(efl)strcpy(left[lp],"[EOF]\n");
  207. X                }
  208. X                if(efl && efr)break;
  209. X                zork=   jstrcmp(left[lp],rite[rp])   !=0 ;
  210. X            }
  211. X        }
  212. X        display(lp,rp,c);
  213. X    }
  214. X}
  215. X
  216. Xfixline(p) char *p;
  217. X{
  218. X    int j;
  219. X    char *q;
  220. X    q=p;
  221. X    for(j=0;j<37;j++){
  222. X        if(*p=='\n')break; 
  223. X        if(*p=='\t') *p=' '; 
  224. X        p++;
  225. X    }
  226. X    if(q==lft)while(j<37){
  227. X        *p++ = ' ';
  228. X        j++;
  229. X    }
  230. X    else q[37]='\0';
  231. X    *p='\0';
  232. X}
  233. X
  234. Xdisplay(p,q,c) int p,q; 
  235. Xchar c;
  236. X{
  237. X    int i,zork,cnt;
  238. X
  239. X    move(0,0);
  240. X    for(i=0;i<20;i++)
  241. X    {
  242. X
  243. X        p = (p+1) % 20; 
  244. X        q = (q+1) % 20;
  245. X        zork=jstrcmp(left[p],rite[q]);
  246. X        if(c!='-' && c!='='){
  247. X            strcpy(lft,left[p],38);
  248. X            strcpy(rte,rite[q],38);
  249. X        }
  250. X        else {  /*fgets allows the \n in the string, and
  251. X                            appends a \0 after it.  strlen therefore will
  252. X                            count the \n in a string that has it.*/
  253. X            if(c=='-')cnt=37;
  254. X            if(c=='=')cnt=74;
  255. X            if(strlen(left[p])>cnt)
  256. X                strcpy(lft,&(left[p][cnt]),38);
  257. X            else
  258. X                strcpy(lft,"\n",2);
  259. X            if(strlen(rite[q])>cnt)
  260. X                strcpy(rte,&(rite[q][cnt]),38);
  261. X            else
  262. X                strcpy(rte,"\n",2);
  263. X        }/*endelse*/
  264. X
  265. X        fixline(lft); 
  266. X        fixline(rte);
  267. X        printw("%c %s | %s\n",zork?'+':' ',lft,rte);
  268. X
  269. X    }
  270. X
  271. X
  272. X    printw("%s\n",leader);
  273. X    printw(
  274. X    "a:upl, ;:upr, q:pgl, p:pgr, t|y:pgboth, f|j:upboth, d:gotodif, -|=:horiz\n");
  275. X    printw(
  276. X    "---------------------------------------------------------------------------\n"
  277. X        );
  278. X    refresh();
  279. X
  280. X
  281. X}
  282. X#define white(c) ((c)==' ' || (c)=='\t')
  283. Xjstrcmp(s1,s2)
  284. Xchar *s1,*s2;
  285. X{
  286. X    while(*s1&&*s2)
  287. X    {    
  288. X        if(white(*s1)&&white(*s2)){
  289. X            while(white(*s1))s1++;    
  290. X            while(white(*s2))s2++;
  291. X            continue;
  292. X        }
  293. X        if(*s1==*s2){s1++;s2++;continue;}
  294. X        return(*s1 - *s2);
  295. X    }
  296. X    if(*s1=='\0' && *s2!='\0')return(-1);
  297. X    if(*s1!='\0' && *s2=='\0')return(1);
  298. X    if(*s1=='\0' && *s2=='\0')return(0);
  299. X    exit(1);/*disaster*/
  300. X}
  301. EnD of sbs.c
  302.  
  303.  
  304.