home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / rvi / part3 / rv_misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-09  |  2.9 KB  |  154 lines

  1. #include "rv.h"
  2.  
  3. /*
  4.  * Miscellaneous subroutines
  5.  */
  6.  
  7. char *xalloc(n)
  8. /*
  9.  * Allocate and zero n bytes
  10.  */
  11. {
  12.     char *s;
  13.     char *malloc();
  14.  
  15.     if ((s = malloc(n)) == NULL) {
  16.         write(2, "Out of memory", 13);
  17.         endwin();
  18.         exit(1);
  19.     }
  20.     zero(s, n);
  21.     return s;
  22. }
  23.  
  24.  
  25. boolean did_botprint;  /* True if botprint() was already called */
  26. boolean scrolled;      /* True if screen scrolled from a call */
  27.  
  28. /*VARARGS1*/
  29. void
  30. botprint(standout_flag, txt, arg1, arg2, arg3, arg4, arg5)
  31. /*
  32.  * Printf line(s) on bottom of screen with the given attribute(s).
  33.  */
  34. INT  standout_flag;
  35. char *txt, *arg1, *arg2, *arg3, *arg4, *arg5;
  36. {
  37.     char buf[512];
  38.     INT  oldrow, oldcol, l;
  39.  
  40.     oldrow = CURLINE;
  41.     oldcol = CURCOLUMN;
  42.  
  43.     sprintf(buf, txt, arg1, arg2, arg3, arg4, arg5);
  44.     l = strlen(buf);
  45.     if (l > 0 && buf[l-1] == '\n') /* Remove trailing \n */
  46.         buf[--l] = '\0';
  47.     move(LINES-1, 0);
  48.     if (did_botprint) {
  49.         rv_fscroll(1);
  50.         move(LINES-1, 0);
  51.         scrolled = TRUE;
  52.     }
  53.     else
  54.         clrtoeol();
  55.  
  56.     if (standout_flag)
  57.         standout();
  58.     addstr(buf);
  59.     if (standout_flag)
  60.         standend();
  61.     while (l > 0 && buf[l-1] == '\n') {
  62.         buf[--l] = '\0';
  63.         /* scroll(stdscr); */
  64.         scrolled = TRUE;
  65.     }
  66.  
  67.     did_botprint = TRUE;
  68.  
  69.     if (l >= COLS || l > CURCOLUMN)
  70.         scrolled = TRUE;
  71.  
  72.     move(oldrow, oldcol);
  73. }
  74.  
  75.  
  76. hitcr_continue()
  77. {
  78.     INT oldrow, oldcol;
  79.     INT c;
  80.  
  81.     if (scrolled) {
  82.         /*
  83.          * Screen scrolled.  Redraw
  84.          */
  85.         oldrow = CURLINE;
  86.         oldcol = CURCOLUMN;
  87.         move(LINES-1,0);
  88.         rv_fscroll(1);
  89.         move(LINES-1, 0);
  90.         standout();
  91.         addstr("[Hit return to continue]");
  92.         standend();
  93.         refresh();
  94.         while ((c = getch()) != '\r' && c != '\n' && c != ' ')
  95.             ;
  96.         redraw_screen((struct li_line *) 0);
  97.         move(oldrow, oldcol);
  98.         scrolled = FALSE;
  99.     }
  100.     did_botprint = FALSE;
  101. }
  102.  
  103.  
  104. void
  105. panic(msg)
  106. /*
  107.  * Print msg and abort
  108.  */
  109. char *msg;
  110. {
  111.     botprint(TRUE, "Fatal error: %s\n", msg);
  112.     move(LINES-1, 0);
  113.     rv_fscroll(1);
  114.     move(LINES-1, 0);
  115.     refresh();
  116.     endwin();
  117.     exit(1);
  118. }
  119.  
  120. void
  121. sizemsg()
  122. {
  123.     if (file.fi_name[0] == '\0' || strcmp(file.fi_name, "/dev/null") == 0)
  124.         botprint(0, "No file  line %d of %d --%d%%--", 
  125.             screen.sc_lineno, file.fi_numlines, 
  126.             (screen.sc_lineno*100) / file.fi_numlines);
  127.     else
  128.         botprint(0, "\"%s\" %sline %d of %d --%d%%--", file.fi_name,
  129.             file.fi_modified ? "[modified] " : "",
  130.             screen.sc_lineno, file.fi_numlines, 
  131.             (screen.sc_lineno*100) / file.fi_numlines);
  132. }
  133.  
  134.  
  135. void
  136. rv_debug()
  137. {
  138.     botprint(FALSE, "Absolute:\n");
  139.     botprint(FALSE, "wi_topline=%d, wi_botline=%d\n",
  140.         window.wi_topline - &line_array[0],
  141.         window.wi_botline - &line_array[0]);
  142.     botprint(FALSE, "sc_topline=%d, sc_botline=%d, sc_curline=%d\n",
  143.         screen.sc_topline - &line_array[0],
  144.         screen.sc_botline - &line_array[0],
  145.         screen.sc_curline - &line_array[0]);
  146.     botprint(FALSE, "sc_lineno=%d, fi_numlines=%d\n",
  147.         screen.sc_lineno, file.fi_numlines);
  148.     botprint(FALSE, "Relative to window:\n");
  149.     botprint(FALSE, "sc_topline=%d, sc_botline=%d, sc_curline=%d\n",
  150.         screen.sc_topline - window.wi_topline,
  151.         screen.sc_botline - window.wi_topline,
  152.         screen.sc_curline - window.wi_topline);
  153. }
  154.