print.c revision 299355
143809Sjkh/* 243809Sjkh * Copyright (c) 1987, 1993, 1994 343809Sjkh * The Regents of the University of California. All rights reserved. 443809Sjkh * 543809Sjkh * Redistribution and use in source and binary forms, with or without 643809Sjkh * modification, are permitted provided that the following conditions 743809Sjkh * are met: 843809Sjkh * 1. Redistributions of source code must retain the above copyright 943809Sjkh * notice, this list of conditions and the following disclaimer. 1043809Sjkh * 2. Redistributions in binary form must reproduce the above copyright 1143809Sjkh * notice, this list of conditions and the following disclaimer in the 1250472Speter * documentation and/or other materials provided with the distribution. 1343809Sjkh * 4. Neither the name of the University nor the names of its contributors 1443809Sjkh * may be used to endorse or promote products derived from this software 1548290Sjseger * without specific prior written permission. 1643809Sjkh * 1743809Sjkh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1843809Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1948785Siwasaki * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2048785Siwasaki * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2148785Siwasaki * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2243809Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2343809Sjkh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2443809Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2548554Shosokawa * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2648648Shosokawa * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2743809Sjkh * SUCH DAMAGE. 2843809Sjkh */ 2943809Sjkh 3051174Sache#if 0 3143809Sjkh#ifndef lint 3243809Sjkhstatic char sccsid[] = "@(#)print.c 8.3 (Berkeley) 4/2/94"; 3343809Sjkh#endif 3443809Sjkh#endif 3543809Sjkh 3643809Sjkh#include <sys/cdefs.h> 3748880Sjkh__FBSDID("$FreeBSD: head/usr.bin/ctags/print.c 299355 2016-05-10 11:11:23Z bapt $"); 3843809Sjkh 3948842Sjkh#include <limits.h> 4048842Sjkh#include <stdio.h> 4143809Sjkh#include <unistd.h> 4245542Sdes 4343809Sjkh#include "ctags.h" 4443809Sjkh 4544990Sbrian/* 4643809Sjkh * get_line -- 4744990Sbrian * get the line the token of interest occurred on, 4843809Sjkh * prepare it for printing. 4949785Sobrien */ 5049783Sobrienvoid 5149704Sobrienget_line(void) 5251209Sdes{ 5351209Sdes long saveftell; 5451224Sdes int c; 5549603Sdes int cnt; 5649603Sdes char *cp; 5748687Speter 5843809Sjkh saveftell = ftell(inf); 5943809Sjkh (void)fseek(inf, lineftell, L_SET); 6043809Sjkh if (xflag) 6143809Sjkh for (cp = lbuf; GETC(!=, EOF) && c != '\n'; *cp++ = c) 6243809Sjkh continue; 6343809Sjkh /* 6443809Sjkh * do all processing here, so we don't step through the 6543809Sjkh * line more than once; means you don't call this routine 6643809Sjkh * unless you're sure you've got a keeper. 6749110Sbrian */ 6849110Sbrian else for (cnt = 0, cp = lbuf; GETC(!=, EOF) && cnt < ENDLINE; ++cnt) { 6949110Sbrian if (c == '\\') { /* backslashes */ 7049110Sbrian if (cnt > ENDLINE - 2) 7150193Sbrian break; 7249110Sbrian *cp++ = '\\'; *cp++ = '\\'; 7349110Sbrian ++cnt; 7443809Sjkh } 7543809Sjkh else if (c == (int)searchar) { /* search character */ 7643809Sjkh if (cnt > ENDLINE - 2) 7743809Sjkh break; 7848697Ssheldonh *cp++ = '\\'; *cp++ = c; 7943809Sjkh ++cnt; 8043809Sjkh } 8143809Sjkh else if (c == '\n') { /* end of keep */ 8243809Sjkh *cp++ = '$'; /* can find whole line */ 8343809Sjkh break; 8443809Sjkh } 8543809Sjkh else 8643809Sjkh *cp++ = c; 8743809Sjkh } 8843809Sjkh *cp = EOS; 8943809Sjkh (void)fseek(inf, saveftell, L_SET); 9043809Sjkh} 9143809Sjkh 9243809Sjkh/* 9343809Sjkh * put_entries -- 9443809Sjkh * write out the tags 9548296Sobrien */ 9643809Sjkhvoid 9743809Sjkhput_entries(NODE *node) 9843809Sjkh{ 9943809Sjkh 10043809Sjkh if (node->left) 10143809Sjkh put_entries(node->left); 10243809Sjkh if (vflag) 10343809Sjkh printf("%s %s %d\n", 10443809Sjkh node->entry, node->file, (node->lno + 63) / 64); 10543809Sjkh else if (xflag) 10643809Sjkh printf("%-16s %4d %-16s %s\n", 10744668Sjfitz node->entry, node->lno, node->file, node->pat); 10843809Sjkh else 10943809Sjkh fprintf(outf, "%s\t%s\t%c^%s%c\n", 11043809Sjkh node->entry, node->file, searchar, node->pat, searchar); 11143809Sjkh if (node->right) 11243809Sjkh put_entries(node->right); 11343809Sjkh} 11443809Sjkh