home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / rvi / part2 / rv_edit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.9 KB  |  129 lines

  1. #include "rv.h"
  2. #include <ctype.h>
  3.  
  4. char *nextfile;  /* Ptr to name of next file to edit */
  5.  
  6. extern     char editlist[256]; /* List of files to edit */
  7.  
  8. void
  9. edit(name)
  10. /*
  11.  * Edit named file
  12.  * If null, edit next file in editlist[]
  13.  */
  14. char *name;
  15. {
  16.     register char *s;
  17.     register INT c;
  18.     char buf[256];
  19.     extern alarmring();
  20.  
  21.     xmit_curline();
  22.  
  23.     if (nextfile == NULL)
  24.         nextfile = editlist;
  25.  
  26.     if (name != NULL && *name != '\0') {
  27.         strncpy(editlist, name, 255);
  28.         nextfile = editlist;
  29.     }
  30.  
  31.     s = nextfile;
  32.     while (isspace(*s) && *s != '\0')
  33.         ++s;
  34.     name = s;
  35.     while (!isspace(*s) && *s != '\0')
  36.         ++s;
  37.     if (*s != '\0') {
  38.         *s++ = '\0';
  39.         while (isspace(*s) && s != '\0')
  40.             ++s;
  41.     }
  42.     nextfile = s;
  43.  
  44.     if (name == NULL || *name == '\0')
  45.         name = file.fi_name;
  46.  
  47.     if (name == NULL || *name == '\0' || strcmp(name, "/dev/null") == 0) {
  48.         botprint(TRUE, "Missing file name");
  49.         hitcr_continue();
  50.         refresh();
  51.         fetch_window(1, TRUE);
  52.         move_abs_cursor(1, 0);
  53.         return;
  54.     }
  55.  
  56.     s = name+strlen(name)-1;
  57.     if (*(s-1) == '.' && *s == 'f')
  58.         set_fortran = TRUE;
  59.     clear();
  60.     botprint(FALSE, "\"%s\" %s", name, set_fortran ? "[fortran mode]" : "");
  61.     hitcr_continue();
  62.     refresh();
  63.     xmit_sync();
  64.     xmit_ed("e %s\n", name);
  65.     (void) recv_sync(FALSE);
  66.     alarm(RV_TIMEOUT);
  67.     fgets(buf, 255, file.fi_fpin);
  68.     if (buf[0] == '?' && (buf[1] == '\n' || buf[1] == ' ')) {
  69.         /*
  70.          * Ed is complaining about something, but we don't
  71.          * know what it is.  It could be trying to edit a
  72.          * directory, or the old file may have been modified
  73.          * without saving the changes.
  74.          */
  75.         /* Get err message from ed, if possible */
  76.         if (file.fi_sysv && (!file.fi_cray || buf[1] != ' '))
  77.             fgets(buf, 255, file.fi_fpin);
  78.         alarm(0);
  79.         if (!file.fi_modified && file.fi_numlines > 1) {
  80.             if (file.fi_sysv)
  81.                 botprint(TRUE, "%s", buf);
  82.             botprint(FALSE, "Are you sure?");
  83.             refresh();
  84.             while ((c = getch()) != 'y' && c != 'Y'
  85.                     && c != 'n' && c != 'N')
  86.                 ;
  87.             hitcr_continue();
  88.             if (c == 'n' || c == 'N') {
  89.                 if (file.fi_name[0] == '\0')
  90.                     strcpy(file.fi_name, ".");
  91.                 xmit_ed("f %s\n", file.fi_name);
  92.                 redraw_screen((struct li_line *)0);
  93.                 botprint(FALSE, "Continue editing \"%s\"",
  94.                     file.fi_name);
  95.                 return;
  96.             }
  97.         }
  98.         alarm(RV_TIMEOUT);
  99.         xmit_ed("e %s\n", name);
  100.         fflush(file.fi_fpout);
  101.         fgets(buf, 255, file.fi_fpin);
  102.     }
  103.  
  104.     xmit_ed("f %s\n", name);
  105.     if (name != file.fi_name)
  106.         strncpy(file.fi_name, name, 126);
  107.     if (buf[0] == '?') { /* If error */
  108.         if (file.fi_sysv) {  /* Get err msg */
  109.             if (!file.fi_cray || buf[1] != ' ')
  110.                 fgets(buf, 255, file.fi_fpin);
  111.         } else
  112.             strcpy(buf, "File not found");
  113.         alarm(0);
  114.         refresh();
  115.         hitcr_continue();
  116.         fetch_window(1, TRUE);
  117.         botprint(TRUE, "%s", buf);
  118.     } else {
  119.         alarm(0);
  120.         fetch_window(1, TRUE);
  121.         file.fi_modified = FALSE;
  122.         move_abs_cursor(1, 0);
  123.         botprint(FALSE, "\"%s\"%s %d lines, %d characters", name,
  124.             set_fortran ? " [fortran mode]" : "",
  125.             file.fi_numlines, atoi(buf));
  126.     } 
  127.     move_abs_cursor(1, 0);
  128. }
  129.