home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / editor / tvx_edit.arc / TVX_UNIX.C < prev    next >
C/C++ Source or Header  |  1986-03-17  |  18KB  |  772 lines

  1. /* -------------------------- tvx_unix.c ------------------------------ */
  2. #include "tvx_defs.ic"
  3. #include "tvx_glbl.ic"
  4.  
  5. #ifdef SYSV
  6. #undef VQUIT            /* name conflict with sys V - irrelevant
  7.                 name in tvx_unix.c */
  8. #include <termio.h>
  9. #endif
  10.  
  11. #define TEMPEXT ".$$1"        /* temporary file */
  12. #define BACKEXT ".B"        /* backup file */
  13. #define SWITCH '-'
  14. #define FILESEP '.'
  15.  
  16. /* define USETMP if you want intermediate workfiles built on
  17.    /tmp.  Otherwise, they will be built on the same directory as
  18.    the original file.  This latter method is often a bit faster,
  19.    especially when exiting if /tmp is on a different volume than
  20.    the destination file (which makes mv COPY the file rather than
  21.    just renameing. */
  22.  
  23. /* #define USETMP */            /* define if create temp files on /tmp */
  24.  
  25. #include <ctype.h>
  26. #include <sys/ioctl.h>
  27. #include <sys/types.h>
  28.  
  29. #ifdef ULTRIX11
  30. #include <sgtty.h>
  31. #endif
  32.  
  33. #ifdef SCR_BUF
  34. char *Scrbuf;                   /* Base address of screen buffer. */
  35. char *Scrptr;                   /* Dynamic screen buffer pointer. */
  36. #endif
  37. /* --------------  terminal I/O stuff --------------- */
  38.  
  39. #ifdef SYSV
  40. static struct termio sgb;
  41. #else
  42. static struct sgttyb sgb;
  43. static struct tchars tch;
  44. static struct ltchars ltc;
  45. #endif
  46.  
  47. #define Ioctl ioctl
  48. #define Read read
  49. #define Write write
  50.  
  51. /* ------------- file mode stuff ---------------------- */
  52. #include <sys/stat.h>
  53.   static struct stat info;        /* structure to get info */
  54.  
  55. /* ------------- misc stuff ---------------------- */
  56.  
  57.   extern int errno;
  58.   extern char **environ;
  59.  
  60.  
  61. #ifdef TERMCAP            /* routines needed for termcap */
  62. /* ------------- termcap stuff ---------------------- */
  63.   char PC;
  64.   char *BC;
  65.   char *UP;
  66.   char TERM[40];
  67.   short ospeed;
  68.  
  69.   static char Tcm[80];        /* special entry for cm */
  70.   static char empty[2];
  71.   static char Tbc[20];
  72.   static char Tup[20];
  73.  
  74.   static int    Tco,            /* number of columns per line */
  75.         Tli;            /* number of lines */
  76.  
  77.   static char tcbuff[1024];        /* buffer to hold termcap entry */
  78.  
  79.  
  80. /* ==========================>>> gettermcap  <<<========================= */
  81.   gettermcap()
  82.   {
  83.     char *tp;
  84.     char *getenv();
  85.     char entry[80];        /* scratch buffer for entry */
  86.  
  87.     empty[0] = 0;
  88.  
  89. #ifdef SYSV
  90.     ospeed = sgb.c_cflag & CBAUD;
  91. #else
  92.     ospeed = sgb.sg_ospeed;    /* get the speed */
  93. #endif
  94.  
  95.     if ((tp = getenv("TERM")) == NULL)
  96.       {
  97.     goto FORCETTY;
  98.       }
  99.     strcpy(TERM,tp);        /* copy to our TERM */
  100.  
  101.     if (tgetent(tcbuff,TERM) < 1)
  102.       {
  103.     goto FORCETTY;
  104.       }
  105.  
  106. /*    read required termcap entries, save in appropriate TVX arrays */
  107.  
  108.     if (!gettcap("cm",Tcm))
  109.       {
  110.     goto FORCETTY;
  111.       }
  112.  
  113.     if (!gettcap("ce",entry))
  114.       {
  115.     goto FORCETTY;
  116.       }
  117.     if (!capcpy(celin,entry,7))    /* copy entry to end of line */
  118.       {
  119.     goto FORCETTY;
  120.       }
  121.     
  122.     if (tgetflag("da"))
  123.     dsp_mem = TRUE;            /* display has memory */
  124.     else if (tgetflag("db"))
  125.     dsp_mem = TRUE;
  126.  
  127.     gettcap("cd",entry);        /* clear to end of display */
  128.     capcpy(cescr,entry,7);
  129.  
  130.     gettcap("al",entry);        /* insert a line (add line) */
  131.     capcpy(ciline,entry,7);
  132.  
  133.     gettcap("dl",entry);    /* delete a line */
  134.     capcpy(ckline,entry,7);
  135.  
  136.     if (!gettcap("sr",entry))    /* reverse scroll */
  137.       {
  138.     strcpy(ctopb,ciline);    /* add line works the same */
  139.       }
  140.     else
  141.     capcpy(ctopb,entry,7);
  142.  
  143.     gettcap("dc",entry);        /* delete character */
  144.     capcpy(cdelchr,entry,7);
  145.     gettcap("cl",entry);        /* clear screen */
  146.     capcpy(cclears,entry,7);
  147.  
  148.  
  149.     gettcap("ve",entry);        /* stand cursor changer end */
  150.     capcpy(ccsrcm,entry,7);
  151.     gettcap("vs",entry);        /* stand cursor changer begin */
  152.     capcpy(ccsrin,entry,7);
  153.  
  154.     gettcap("se",entry);        /* stand out end */
  155.     capcpy(cbolde,entry,7);
  156.  
  157.     gettcap("so",entry);        /* begin standout */
  158.     capcpy(cboldb,entry,7);
  159.  
  160.     cerred[0] = 7;                /* bell for sure */
  161.     gettcap("vb",entry);        /* visual bell? */
  162.     if (*entry)
  163.     capcpy(cerred,entry,7);
  164.  
  165.     if (!capcpy(&cversn[1],TERM,10))        /* copy name to version */
  166.     strcpy(cversn,"TERMCAP");
  167.  
  168.     if ((Tco = tgetnum("co")) < 0)    /* # of cols */
  169.     Tco = 79;        /* assume 80 x 24 */
  170.     if ((Tli = tgetnum("li")) < 0)    /* # of lines */
  171.     Tli = 24;        /* assume 80 x 24 */
  172.  
  173.     tvhardlines = tvlins = Tli;    /* number of lines */
  174.     tvcols = Tco - 1; /* set col val (-1 avoids all the line wrap crap )*/
  175.     if (tvhardlines != 24 || tvhardlines != 25)    /* strange terminal */
  176.       {
  177.     ddline = (tvlins / 2) + 1;
  178.     setdscrl();        /* calculate scroll */
  179.       }
  180.  
  181.     gettcap("bc",entry);        /* get backspace character */
  182.     if (!*entry)
  183.       {
  184.     Tbc[0] = 8; Tbc[1] = 0;
  185.       }
  186.     else
  187.     capcpy(Tbc,entry,19);
  188.     BC = Tbc;
  189.     gettcap("up",entry);        /* get backspace character */
  190.     if (!*entry)
  191.       {
  192.     Tup[0] = 0;
  193.       }
  194.     else
  195.     capcpy(Tup,entry,19);
  196.     UP = Tup;
  197.     gettcap("pc",entry);        /* get the pad character */
  198.     PC = *entry;
  199.  
  200. #ifdef USE_TC_is
  201.     gettcap("is",entry);        /* initialization string */
  202.     tcapcs(entry);            /* send the intialization string */
  203. #endif
  204.  
  205.     gettcap("ti",entry);        /* cm initialization string */
  206.     tcapcs(entry);            /* send the intialization string */
  207.  
  208.     return;
  209.  
  210. FORCETTY:
  211.    reset();
  212.    remark("");
  213.    remark("Unable to set up for video terminal, try again with -t switch.");
  214.    exit(999);
  215.   }
  216.  
  217. /* =============================>>> capcpy  <<<============================= */
  218.   capcpy(to,from,len)
  219.   char *to, *from;
  220.   int len;
  221.   {        /* copy a capability, checking length */
  222.     if (strlen(from) > len)
  223.       {
  224.     *to = 0;
  225.     return (FALSE);
  226.       }
  227.     else
  228.     strcpy(to,from);
  229.     return (TRUE);
  230.   }
  231.  
  232. /* =============================>>> gettcap  <<<============================= */
  233.   gettcap(cap,area)
  234.   char *cap, *area;
  235.   {
  236.     char **cpp, *cp;
  237.  
  238.     cpp = &cp;        /* I think */
  239.     cp = area;
  240.     *area = 0;        /* assume null entry */
  241.  
  242.     tgetstr(cap,cpp);    /* get the capability */
  243.     return (*area);        /* return 1st char */
  244.     
  245.   }
  246.  
  247. /* =============================>>> tcapcs  <<<============================= */
  248.   tcapcs(str)
  249.   char *str;
  250.   {
  251.      /* send a termcap generated control string to terminal */
  252.  
  253.     register char *cp;
  254.     int ttwt();
  255.  
  256.     if (!(echof && !bakflg && !ttymode))
  257.     return;
  258.     if (!*str)        /* don't send null strings */
  259.     return;
  260.     cp = str;
  261.     tputs(cp,1,ttwt);
  262.  
  263.   }
  264.  
  265. /* =============================>>> tcapxy  <<<============================= */
  266.   tcapxy(x,y)
  267.   int x,y;
  268.   {
  269.     /* move cursor to x,y */
  270.  
  271.    char *tgoto();
  272.  
  273.    tcapcs(tgoto(Tcm,x-1,y-1));    /* send the string, adjusting x,y */
  274.  
  275.   }
  276. #endif   /* termcap */
  277.  
  278.  
  279. /* =============================>>> ttinit  <<<============================= */
  280.   ttinit()
  281.   {
  282. #ifdef SYSV
  283.     struct termio nsgb;
  284. #else
  285.     struct sgttyb nsgb;
  286.     struct tchars ntch;
  287.     struct ltchars nltc;
  288. #endif
  289.  
  290. #ifdef SCR_BUF
  291.     char *malloc();
  292.  
  293.     /* malloc the screen buffer */
  294.     if ((Scrbuf = malloc(S_BUFSIZE)) == NULL)
  295.       {
  296.     reset();
  297.     remark("");
  298.     remark("tvx: cannot allocate screen buffer, aborting");
  299.     exit(999);
  300.       }
  301.     Scrptr = Scrbuf;
  302. #endif
  303.  
  304. #ifdef SYSV
  305.     (void) Ioctl(0, TCGETA, &sgb);
  306.     (void) Ioctl(0, TCGETA, &nsgb);
  307. #else
  308.     (void) Ioctl(0, TIOCGETP, &sgb);
  309.     (void) Ioctl(0, TIOCGETP, &nsgb);
  310.     (void) Ioctl(0, TIOCGETC, &tch);
  311.     (void) Ioctl(0, TIOCGETC, &ntch);
  312.     (void) Ioctl(0, TIOCGLTC, <c);
  313. #endif
  314.  
  315. #ifdef SYSV
  316.     nsgb.c_lflag &= ~(ECHO | ICANON);
  317.     nsgb.c_iflag &= ~(ICRNL | IXOFF);
  318. #else
  319.     nsgb.sg_flags |= CBREAK;
  320.     nsgb.sg_flags &= ~(CRMOD|ECHO|LCASE|TANDEM);
  321. #endif
  322.  
  323. #ifdef SYSV
  324.     nsgb.c_cc[VMIN] = 1;    /* minimum characters */
  325.     nsgb.c_cc[VTIME] = -1;    /* time before read returns */
  326. #else
  327.     ntch.t_intrc = -1;  /* interrupt */
  328.     ntch.t_quitc = -1;  /* quit */
  329.     ntch.t_eofc = -1;   /* end-of-file */
  330.     ntch.t_brkc = -1;   /* input delimiter (like nl) */
  331. #endif
  332.  
  333. /* the following two lines control flow control */
  334.  
  335. #ifndef FLOWCONTROL
  336. #ifdef SYSV
  337.     nsgb.c_iflag &= ~(IXON | IXOFF);
  338. #else
  339.     ntch.t_startc = -1; /* start output */
  340.     ntch.t_stopc = -1;  /* stop output */
  341. #endif
  342. #endif
  343.  
  344. #ifndef SYSV
  345.     nltc.t_suspc = -1;  /* stop process signal */
  346.     nltc.t_dsuspc = -1; /* delayed stop process signal */
  347.     nltc.t_rprntc = -1; /* reprint line */
  348.     nltc.t_flushc = -1; /* flush output (toggles) */
  349.     nltc.t_werasc = -1; /* word erase */
  350.     nltc.t_lnextc = -1; /* literal next character */
  351. #endif
  352.  
  353. #ifdef SYSV
  354.     (void) Ioctl(0, TCSETA, &nsgb);
  355. #else
  356.     (void) Ioctl(0, TIOCSETP, &nsgb);
  357.     (void) Ioctl(0, TIOCSETC, &ntch);
  358.     (void) Ioctl(0, TIOCSLTC, &nltc);
  359. #endif
  360.  
  361. #ifdef TERMCAP
  362.     gettermcap();            /* set up terminal characteristics */
  363. #endif
  364.  
  365.     info.st_mode = -1;            /* no mode stuff yet */
  366.  }
  367.  
  368.  
  369. #ifdef SCR_BUF
  370. /* =============================>>> ttflush  <<<============================= */
  371.   ttflush()
  372.   {
  373.     if (Scrptr != Scrbuf)
  374.     write(1, Scrbuf, Scrptr - Scrbuf);
  375.     Scrptr = Scrbuf;
  376.   }
  377. #endif
  378.  
  379. /* =============================>>> ttrd_unix  <<<============================= */
  380.   ttrd_unix()
  381.   {
  382.            char c;
  383.  
  384.     Read(0, &c, 1);
  385.     return(c);
  386.   }
  387.  
  388. /* =============================>>> ttwtln  <<<============================= */
  389.   ttwtln(cbuf,cnt)
  390.   char *cbuf;
  391.   int cnt;
  392.   {
  393. #ifndef SCR_BUF
  394.     if (echof && !bakflg && !ttymode)
  395.     Write(1, cbuf, cnt);
  396. #else
  397.     if (echof && !bakflg && !ttymode)
  398.       {
  399.     while(cnt-- > 0)
  400.       {
  401.             if (Scrptr < Scrbuf + S_BUFSIZE)
  402.                 *Scrptr++ = *cbuf++;
  403.             else
  404.           {
  405.                 ttflush();
  406.                 *Scrptr++ = *cbuf++;
  407.           }
  408.       }
  409.       }
  410. #endif
  411.   }
  412.  
  413. /* =============================>>> ttwt  <<<============================= */
  414.   ttwt(c)
  415.   char c;
  416.   {
  417.     if (ttymode)
  418.     return;
  419. #ifndef SCR_BUF
  420.     Write(1, &c, 1);
  421. #else
  422.     if (Scrptr < Scrbuf + S_BUFSIZE)
  423.         *Scrptr++ = c;
  424.     else
  425.       {
  426.         ttflush();
  427.         *Scrptr++ = c;
  428.       }
  429. #endif
  430.   }
  431.  
  432. /* =============================>>> ttclos  <<<============================= */
  433.   ttclos()
  434.   {
  435.  
  436. #ifdef TERMCAP
  437.     char entry[80];
  438.  
  439.     gettcap("te",entry);        /* cm end up string */
  440.     tcapcs(entry);            /* send it */
  441. #endif
  442.  
  443. #ifdef SYSV
  444.     (void) Ioctl(0, TCSETA, &sgb);
  445. #else
  446.     (void) Ioctl(0, TIOCSETP, &sgb);
  447.     (void) Ioctl(0, TIOCSETC, &tch);
  448.     (void) Ioctl(0, TIOCSLTC, <c);
  449. #endif
  450.   }
  451.  
  452. /* =============================>>> ttosinit  <<<============================= */
  453.   ttosinit()
  454.   {            /* need a special version for not doing termcap */
  455. #ifdef SYSV
  456.     struct termio nsgb;
  457. #else
  458.     struct sgttyb nsgb;
  459.     struct tchars ntch;
  460.     struct ltchars nltc;
  461. #endif
  462.  
  463.     char entry[80];        /* scratch buffer for entry */
  464.  
  465. #ifdef SYSV
  466.     (void) Ioctl(0, TCGETA, &sgb);
  467.     (void) Ioctl(0, TCGETA, &nsgb);
  468. #else
  469.     (void) Ioctl(0, TIOCGETP, &sgb);
  470.     (void) Ioctl(0, TIOCGETP, &nsgb);
  471.     (void) Ioctl(0, TIOCGETC, &tch);
  472.     (void) Ioctl(0, TIOCGETC, &ntch);
  473.     (void) Ioctl(0, TIOCGLTC, <c);
  474. #endif
  475.  
  476. #ifdef SYSV
  477.     nsgb.c_lflag &= ~(ECHO | ICANON);
  478.     nsgb.c_iflag &= ~(ICRNL | IXOFF);
  479. #else
  480.     nsgb.sg_flags |= CBREAK;
  481.     nsgb.sg_flags &= ~(CRMOD|ECHO|LCASE|TANDEM);
  482. #endif
  483.  
  484. #ifdef SYSV
  485.     nsgb.c_cc[VMIN] = 1;    /* minimum characters */
  486.     nsgb.c_cc[VTIME] = -1;    /* time before read returns */
  487. #else
  488.     ntch.t_intrc = -1;  /* interrupt */
  489.     ntch.t_quitc = -1;  /* quit */
  490.     ntch.t_eofc = -1;   /* end-of-file */
  491.     ntch.t_brkc = -1;   /* input delimiter (like nl) */
  492. #endif
  493.  
  494. /* the following two lines control flow control */
  495.  
  496. #ifndef FLOWCONTROL
  497. #ifdef SYSV
  498.     nsgb.c_iflag &= ~(IXON | IXOFF);
  499. #else
  500.     ntch.t_startc = -1; /* start output */
  501.     ntch.t_stopc = -1;  /* stop output */
  502. #endif
  503. #endif
  504.  
  505. #ifndef SYSV
  506.     nltc.t_suspc = -1;  /* stop process signal */
  507.     nltc.t_dsuspc = -1; /* delayed stop process signal */
  508.     nltc.t_rprntc = -1; /* reprint line */
  509.     nltc.t_flushc = -1; /* flush output (toggles) */
  510.     nltc.t_werasc = -1; /* word erase */
  511.     nltc.t_lnextc = -1; /* literal next character */
  512. #endif
  513.  
  514. #ifdef SYSV
  515.     (void) Ioctl(0, TCSETA, &nsgb);
  516. #else
  517.     (void) Ioctl(0, TIOCSETP, &nsgb);
  518.     (void) Ioctl(0, TIOCSETC, &ntch);
  519.     (void) Ioctl(0, TIOCSLTC, &nltc);
  520. #endif
  521.  
  522. #ifdef TERMCAP
  523. #ifdef USE_TC_is
  524.     gettcap("is",entry);        /* initialization string */
  525.     tcapcs(entry);            /* send the intialization string */
  526. #endif
  527.  
  528.     gettcap("ti",entry);        /* cm initialization string */
  529.     tcapcs(entry);            /* send the intialization string */
  530. #endif
  531.  }
  532.  
  533. /* ==========================>>> unix_sys  <<<============================= */
  534.   unix_sys()
  535.   {
  536.     char rp[150];
  537.     int oldtty;
  538.  
  539.     tvclr();            /* clear the screen */
  540.     oldtty = ttymode; ttymode = FALSE;
  541. DO_UNIX:
  542.     remark("Unix command interface"); remark("");
  543.     remark("Enter Unix command line: ");
  544.     reply(rp,149);
  545.     reset();        /* reset terminal to unix mode */
  546.  
  547.     system(rp);
  548.  
  549.     ttosinit();        /* reset terinal to our mode */
  550.  
  551.     remark("");
  552.     remark("");
  553.  
  554.     prompt("Any key to continue with edit (! for another Unix command): ");
  555.     reply(rp,1);
  556.  
  557.     trmini();        /* this has to be here or screen is cleared! */
  558.     if (*rp == '!')
  559.     goto DO_UNIX;
  560.  
  561.     ttymode = oldtty;
  562.     verify(1);
  563.   }
  564.  
  565. /* =============================>>> get_mode <<<============================= */
  566.   get_mode(f)
  567.   FILE *f;
  568.   {        /* gets access mode of open file f */
  569.  
  570.     char rp[10];
  571.  
  572.     info.st_mode = -1;    /* assume no mode */
  573.  
  574.     if (newfil)
  575.     return;
  576.     if (fstat(fileno(f),&info) != 0)
  577.       {
  578.     info.st_mode = -1;    /* assume no mode */
  579.     return;
  580.       }
  581.     info.st_mode &= 07777;    /* zap extraneous stuff*/
  582.     if (((info.st_mode & 0222) == 0) || rdonly)    /* no write permission */
  583.       {
  584.     prompt("No write permission for file, edit R/O? (y/n) ");
  585.     ureply(rp,1);
  586.     if (*rp == 'Y')
  587.         rdonly = TRUE;
  588.     else
  589.       {
  590.         reset();
  591.         exit(999);
  592.       }
  593.       }
  594.   }
  595.  
  596. /* =============================>>> set_mode <<<============================= */
  597.   set_mode(f)
  598.   FILE *f;
  599.   {        /* sets access mode of open file f */
  600. #ifdef SYSV
  601.     if (newfil)
  602.     return;
  603.     else
  604.     tverrb("Unable to set file mode, umask will be used.");
  605.     return;    /* The person doing the port to System V removed the
  606.     fchmod code.  It may not apply to System V, but was needed on
  607.     the BSD version to keep executable shell scripts executable.
  608.     (among other things - that is the most obvious reason)
  609.     Maybe someone knows if this is needed on System V.  BEW 2/11/86 */
  610. #else
  611.     if (newfil || info.st_mode == -1)
  612.     return;
  613. #ifndef ULTRIX11
  614.     if (fchmod(fileno(f),info.st_mode) != 0)
  615. #endif
  616.     tverrb("Unable to set file mode, umask will be used.");
  617. #endif
  618.   }
  619.  
  620. /* ==========================>>> expand_name <<<============================ */
  621.   expand_name(n)
  622.   char *n;
  623.   {        /* expands unix file names */
  624.     char tmp[FNAMESIZE+1];
  625.  
  626.     if ((*n == '~') && (n[1] == '/'))
  627.       {
  628.     strcpy(tmp,getenv("HOME"));
  629.     scopy(n,1,tmp,strlen(tmp));
  630.     strcpy(n,tmp);
  631.       }
  632.   }
  633.  
  634. /* =============================>>> ren_file <<<=========================== */
  635.   ren_file(old,new)
  636.   char *old, *new;
  637.   {
  638.     int pid;
  639.     static char *mvarg[4];
  640.     static int status;
  641.  
  642.     if (rename(old,new) != 0)
  643.       {
  644.     mvarg[0] = "/bin/mv";
  645.     mvarg[1] = old;
  646.     mvarg[2] = new;
  647.     mvarg[3]=0;
  648.     pid=fork();
  649.     if (pid == 0)
  650.       {
  651.         execve("/bin/mv",mvarg,environ);
  652.             tverrb("Error trying to start mv utility");
  653.         _exit(999);
  654.       }
  655.     wait(&status);
  656.     if (status > 255)        /* error return */
  657.       {
  658.         prompt(old) ; prompt(" not renamed to "); remark(new);
  659.         prompt("Edited file found as: "); remark(old);
  660.       }
  661.       }
  662.   }
  663.  
  664. /* =============================>>> temp_name <<<=========================== */
  665.   temp_name(n,first)
  666.   char *n;
  667.   int first;
  668.   {
  669.     /* generates a temporary name from n.  Depending on value of
  670.        first, it will either add a 1 or 2 to name */
  671.     SLOW int i;
  672.  
  673. #ifdef USETMP
  674.     SLOW char pidno[20];
  675.     long pidint;
  676.  
  677.     if (first)            /* create full temp name */
  678.       {
  679.     *n = 0;
  680.     pidint=getpid();
  681.     itoa(pidint,pidno);
  682.     strcpy(n,"/tmp/tvx1");
  683.     scopy(pidno,0,n,9);
  684.       }
  685.     else            /* alternate between 1 and 2 */
  686.       {
  687.     if (n[8] == '1')
  688.         n[8] = '2';
  689.     else
  690.         n[8] = '1';
  691.       }
  692. #else
  693.     if (first)
  694.       {
  695.     if ((i = rindx(n,FILESEP)) > 0)    /* see if extenstion */
  696.         scopy(TEMPEXT,0,n,i);        /* make .bak */
  697.     else
  698.       {
  699.         scopy(TEMPEXT,0,n,strlen(n));    /* just add on */
  700.       }
  701.       }
  702.     else
  703.       {
  704.     i = strlen(n);
  705.     if (n[i-1] == '1')
  706.         n[i-1] = '2';
  707.     else
  708.         n[i-1] = '1';
  709.       }
  710. #endif
  711.   }
  712.  
  713. #ifndef SUN
  714. /* =============================>>> USER_1 <<<============================= */
  715.   user_1(knt)
  716.   int knt;
  717.   {
  718.     knt = 0;
  719.     return (TRUE);
  720.   }
  721.  
  722. #else
  723. /* =============================>>> USER_1 <<<============================= */
  724.   user_1(knt)
  725.   int knt;
  726.   {
  727.     /* for suns, re-initialize window */
  728. #ifdef TERMCAP
  729.     gettermcap();        /* set up terminal characteristics */
  730.     tvidefs();        /* and reset defs */
  731. #endif
  732.     verify(1);
  733.     return (TRUE);
  734.   }
  735. #endif
  736.  
  737. /* =============================>>> USER_2 <<<============================= */
  738.   user_2(knt)
  739.   int knt;
  740.   {
  741.     knt = 0;
  742.     return (TRUE);
  743.   }
  744.  
  745. #ifdef SYSV
  746. /* ============================>>> RENAME <<<============================ */
  747.   rename(from, to)
  748.   char *from, *to;
  749.   {
  750.     if (access(from, 00) != 0 || access(to, 02) != 0)
  751.     return(-1);
  752.     unlink(to);
  753.     return(link(from, to));
  754.   }
  755. #endif
  756. #ifdef PRO350
  757. /* =============================>>> rename <<<============================= */
  758.   rename(old, new)
  759.   char *old;
  760.   char *new;
  761.   {
  762.     int res;
  763.  
  764.     if ((res = link(old, new)) < 0)
  765.     return (res);
  766.     else
  767.     unlink(old);
  768.     return (0);
  769.   }
  770. #endif
  771. /* -------------------------- tvx_unix.c ------------------------------ */
  772.