root/gtags-cscope/edit.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. editref
  2. editall
  3. edit
  4. filepath

   1 /*===========================================================================
   2  Copyright (c) 1998-2000, The Santa Cruz Operation 
   3  All rights reserved.
   4  
   5  Redistribution and use in source and binary forms, with or without
   6  modification, are permitted provided that the following conditions are met:
   7 
   8  *Redistributions of source code must retain the above copyright notice,
   9  this list of conditions and the following disclaimer.
  10 
  11  *Redistributions in binary form must reproduce the above copyright notice,
  12  this list of conditions and the following disclaimer in the documentation
  13  and/or other materials provided with the distribution.
  14 
  15  *Neither name of The Santa Cruz Operation nor the names of its contributors
  16  may be used to endorse or promote products derived from this software
  17  without specific prior written permission. 
  18 
  19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
  20  IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
  23  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26  INTERRUPTION)
  27  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  30  DAMAGE. 
  31  =========================================================================*/
  32 
  33 /** @file
  34  *      file editing functions
  35  *
  36  *      cscope - interactive C symbol cross-reference
  37  */
  38 
  39 #include "global-cscope.h"
  40 #if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
  41 #include <ncurses.h>
  42 #else
  43 #include <curses.h>
  44 #endif
  45 #include "path.h"
  46 #include "pathconvert.h"
  47 
  48 static char const rcsid[] = "$Id: edit.c,v 1.5 2012/10/13 07:02:00 shigio Exp $";
  49 
  50 /** edit this displayed reference */
  51 
  52 void
  53 editref(int i)
  54 {
  55         char    file[PATHLEN + 1];      /* file name */
  56         char    linenum[NUMLEN + 1];    /* line number */
  57 
  58         /* verify that there is a references found file */
  59         if (refsfound == NULL) {
  60                 return;
  61         }
  62         /* get the selected line */
  63         seekline(i + topline);
  64         
  65         /* get the file name and line number */
  66         if (fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s", file, linenum) == 2) {
  67                 edit(decode_path(file), linenum);       /* edit it */
  68         }
  69         seekline(topline);      /* restore the line pointer */
  70 }
  71 
  72 /** edit all references */
  73 
  74 void
  75 editall(void)
  76 {
  77         char    file[PATHLEN + 1];      /* file name */
  78         char    linenum[NUMLEN + 1];    /* line number */
  79         int     c;
  80 
  81         /* verify that there is a references found file */
  82         if (refsfound == NULL) {
  83                 return;
  84         }
  85         /* get the first line */
  86         seekline(1);
  87         
  88         /* get each file name and line number */
  89         while (fscanf(refsfound, "%" PATHLEN_STR "s%*s%" NUMLEN_STR "s%*[^\n]", file, linenum) == 2) {
  90                 edit(decode_path(file), linenum);       /* edit it */
  91                 if (editallprompt == YES) {
  92                         addstr("Type ^D to stop editing all lines, or any other character to continue: ");
  93                         if ((c = mygetch()) == EOF || c == ctrl('D') || c == ctrl('Z')) {
  94                                 break;
  95                         }
  96                 }
  97         }
  98         seekline(topline);
  99 }
 100         
 101 /** call the editor */
 102 
 103 void
 104 edit(char *file, char *linenum)
 105 {
 106         char    com[PATHLEN + 81];
 107         char    msg[MSGLEN + 1];        /* message */
 108         char    plusnum[NUMLEN + 20];   /* line number option: allow space for wordy line# flag */
 109         char    *s;
 110 
 111         file = filepath(file);
 112         (void) snprintf(msg, sizeof(msg), "%s +%s %s", mybasename(editor), linenum, file);
 113         postmsg(msg);
 114         (void) snprintf(plusnum, sizeof(plusnum), lineflag, linenum);
 115         /* if this is the more or page commands */
 116         if (strcmp(s = mybasename(editor), "more") == 0 || strcmp(s, "page") == 0) {
 117                 
 118                 /* get it to pause after displaying a file smaller than the screen
 119                    length */
 120                 (void) execute(editor, editor, plusnum, file, NULL_DEVICE, NULL);
 121         }
 122         else if (lineflagafterfile) {
 123                 (void) snprintf(com, sizeof(com), "%s %s \"%s\"", editor, file, plusnum);
 124                 system(com);
 125         }
 126         else {
 127                 (void) snprintf(com, sizeof(com), "%s %s \"%s\"", editor, plusnum, file);
 128                 system(com);
 129         }
 130         clear();        /* redisplay screen */
 131 }
 132 
 133 /** if requested, prepend a path to a relative file name */
 134 
 135 char *
 136 filepath(char *file)
 137 {
 138         static  char    path[PATHLEN + 1];
 139         
 140         if (prependpath != NULL && *file != '/') {
 141                 (void) snprintf(path, sizeof(path), "%s/%s", prependpath, file);
 142                 file = path;
 143         }
 144         return(file);
 145 }

/* [previous][next][first][last][top][bottom][index][help] */