Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfddc57b

Browse files
committed
Add PGINDENT and support program.
1 parent448332a commitfddc57b

File tree

5 files changed

+359
-0
lines changed

5 files changed

+359
-0
lines changed

‎src/tools/PGINDENT

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
trap"rm -f /tmp/$$" 0 1 2 3 15
3+
entab</dev/null>/dev/null
4+
if ["$?"-ne 0 ]
5+
thenecho"Go to the src/tools/entab directory and do a 'make' and 'make install'.">&2
6+
echo"This will put the 'entab' command in your path.">&2
7+
echo"Then run$0 again."
8+
exit 1
9+
fi
10+
indent -st</dev/null>/dev/null
11+
if ["$?"-ne 0 ]
12+
thenecho"You do not appear to have 'indent' installed on your system.">&2
13+
exit 1
14+
fi
15+
for FILE
16+
do
17+
cat$FILE|
18+
sed's;/\* *---;/*---;g'|
19+
indent -bad -bap -bbb -bc -bl -d0 -ncdb -nce -cli1 -di16 -nfc1 \
20+
-lp -nip -nbc -psl -di1 -i4 -st|
21+
detab -t8|
22+
entab -qc -t4|
23+
sed's;/\*---;/* ---;g'>/tmp/$$&& cat /tmp/$$>$FILE
24+
done

‎src/tools/entab/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# Makefile
3+
#
4+
#
5+
TARGET = entab
6+
BINDIR = /usr/local/bin
7+
XFLAGS =
8+
CFLAGS = -O
9+
LIBS =
10+
11+
$(TARGET) : entab.o halt.o
12+
$(CC) -o$(TARGET)$(XFLAGS)$(CFLAGS) entab.o halt.o$(LIBS)
13+
14+
entab.o: entab.c
15+
$(CC) -c$(XFLAGS)$(CFLAGS) entab.c
16+
17+
halt.o: halt.c
18+
$(CC) -c$(XFLAGS)$(CFLAGS) halt.c
19+
20+
clean:
21+
rm -f*.o$(TARGET) log core
22+
23+
install:
24+
make clean
25+
make CFLAGS=-O
26+
install -s -o bin -g bin$(TARGET)$(BINDIR)
27+
rm -f$(BINDIR)/detab
28+
ln /usr/local/bin/$(TARGET)$(BINDIR)/detab
29+

‎src/tools/entab/entab.c

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*
2+
**entab.c- add tabs to a text file
3+
**by Bruce Momjian (root@candle.pha.pa.us)
4+
**
5+
** version 1.0
6+
**
7+
**tabsize = 4
8+
**
9+
*/
10+
11+
#include<stdio.h>
12+
#include<stdlib.h>
13+
#include<string.h>
14+
15+
#defineNUL'\0'
16+
17+
#ifndefTRUE
18+
#defineTRUE 1
19+
#endif
20+
#ifndefFALSE
21+
#defineFALSE0
22+
#endif
23+
24+
voidhalt();
25+
26+
externchar*optarg;
27+
externintoptind;
28+
29+
intmain(argc,argv)
30+
intargc;
31+
char**argv;
32+
{
33+
inttab_size=8,
34+
min_spaces=2,
35+
protect_quotes= FALSE,
36+
del_tabs= FALSE,
37+
clip_lines= FALSE,
38+
prv_spaces,
39+
col_in_tab,
40+
escaped,
41+
nxt_spaces;
42+
charin_line[BUFSIZ],
43+
out_line[BUFSIZ],
44+
*src,
45+
*dst,
46+
quote_char,
47+
ch,
48+
*cp;
49+
FILE*in_file;
50+
51+
if ((cp=strrchr(argv[0],'/'))!=NULL)
52+
++cp;
53+
else
54+
cp=argv[0];
55+
if (strcmp(cp,"detab")==0)
56+
del_tabs=1;
57+
58+
while ((ch=getopt(argc,argv,"cdhqs:t:"))!=-1)
59+
switch (ch)
60+
{
61+
case'c' :clip_lines= TRUE;break;
62+
case'd' :del_tabs= TRUE;break;
63+
case'q' :protect_quotes= TRUE;break;
64+
case's' :min_spaces=atoi(optarg);break;
65+
case't' :tab_size=atoi(optarg);break;
66+
case'h' :
67+
case'?' :
68+
halt("USAGE: %s [ -cdqst ] [file ...]\n\
69+
-c (clip trailing whitespace)\n\
70+
-d (delete tabs)\n\
71+
-q (protect quotes)\n\
72+
-s minimum_spaces\n\
73+
-t tab_width\n",
74+
cp);
75+
}
76+
77+
argv+=optind;
78+
argc-=optind;
79+
80+
do {
81+
if (argc<1)
82+
in_file=stdin;
83+
else
84+
{
85+
if ( (in_file=fopen(*argv,"r"))==NULL)
86+
halt("PERROR: Can not open file %s\n",argv[0]);
87+
argv++;
88+
}
89+
90+
escaped= FALSE;
91+
92+
while (fgets(in_line,BUFSIZ,in_file)!=NULL)
93+
{
94+
col_in_tab=0;
95+
prv_spaces=0;
96+
src=in_line;/* points to current processed char */
97+
dst=out_line;/* points to next unallocated char */
98+
if (escaped== FALSE)
99+
quote_char=' ';
100+
escaped= FALSE;
101+
while (*src!=NUL)
102+
{
103+
col_in_tab++;
104+
if (*src==' '||*src=='\t')
105+
{
106+
if (*src=='\t')
107+
{
108+
prv_spaces=prv_spaces+tab_size-col_in_tab+1;
109+
col_in_tab=tab_size;
110+
}
111+
else
112+
prv_spaces++;
113+
114+
if (col_in_tab==tab_size)
115+
{
116+
/* Is the next character going to be a tab?
117+
Needed to do tab replacement in current spot if
118+
next char is going to be a tab, ignoring
119+
min_spaces */
120+
nxt_spaces=0;
121+
while (1)
122+
{
123+
if (*(src+nxt_spaces+1)==NUL||
124+
(*(src+nxt_spaces+1)!=' '&&
125+
*(src+nxt_spaces+1)!='\t'))
126+
break;
127+
if (*(src+nxt_spaces+1)==' ')
128+
++nxt_spaces;
129+
if (*(src+nxt_spaces+1)=='\t'||
130+
nxt_spaces==tab_size)
131+
{
132+
nxt_spaces=tab_size;
133+
break;
134+
}
135+
}
136+
if ((prv_spaces >=min_spaces||nxt_spaces==tab_size)&&
137+
quote_char==' '&&
138+
del_tabs== FALSE )
139+
{
140+
*(dst++)='\t';
141+
prv_spaces=0;
142+
}
143+
else
144+
{
145+
for (;prv_spaces>0;prv_spaces--)
146+
*(dst++)=' ';
147+
}
148+
}
149+
}
150+
else
151+
{
152+
for (;prv_spaces>0;prv_spaces--)
153+
*(dst++)=' ';
154+
if (*src=='\b')
155+
col_in_tab-=2;
156+
if (escaped== FALSE&&protect_quotes== TRUE)
157+
{
158+
if (*src=='\\')
159+
escaped= TRUE;
160+
if (*src=='"'||*src=='\'')
161+
if (quote_char==' ')
162+
quote_char=*src;
163+
elseif (*src==quote_char)
164+
quote_char=' ';
165+
}
166+
else
167+
if (*src!='\r'&&*src!='\n')
168+
escaped= FALSE;
169+
170+
if ((*src=='\r'||*src=='\n')&&
171+
clip_lines== TRUE&&escaped== FALSE)
172+
{
173+
while (dst>out_line&&
174+
(*(dst-1)==' '||*(dst-1)=='\t'))
175+
dst--;
176+
prv_spaces=0;
177+
}
178+
*(dst++)=*src;
179+
}
180+
col_in_tab %=tab_size;
181+
++src;
182+
}
183+
/* for cases where the last line of file has no newline */
184+
if (clip_lines== TRUE&&escaped== FALSE)
185+
{
186+
while (dst>out_line&&
187+
(*(dst-1)==' '||*(dst-1)=='\t'))
188+
dst--;
189+
prv_spaces=0;
190+
}
191+
for (;prv_spaces>0;prv_spaces--)
192+
*(dst++)=' ';
193+
*dst=NUL;
194+
if (fputs(out_line,stdout)==EOF)
195+
halt("PERROR: Error writing output.\n");
196+
}
197+
}while (--argc>0);
198+
return0;
199+
}

‎src/tools/entab/entab.man

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.TH ENTAB 1 local
2+
.SH NAME
3+
entab - tab processor
4+
.SH SYNOPSIS
5+
.nf
6+
entab [-cdq] [-s min_spaces] [-t tab_width] [file ... ]
7+
detab [-cq] [-s min_spaces] [-t tab_width] [file ... ]
8+
.fi
9+
.SH DESCRIPTION
10+
Entab is a program designed to selectively add or remove tabs
11+
from a file based on user-supplied criteria.
12+
In default mode, entab prints the specified files to standard output
13+
with the optimal mix of tabs and spaces.
14+
Tabs default to every 8 characters, and tabs are used only when they
15+
can replace more than one space, unlike 'col' which uses tabs wherever
16+
possible.
17+
.LP
18+
The options are:
19+
.in+0.5i
20+
.nf
21+
-c Clip trailing tabs and spaces from each line.
22+
-dDelete all tabs from output
23+
-qProtect single and double-quoted strings from tab replacement.
24+
(This option is useful when operating on source code.
25+
Line continuation with back-slashes is also understood.)
26+
-s Minimum spaces needed to replace with a tab (default = 2).
27+
-tNumber of spaces in a tab stop (default = 8).
28+
.fi
29+
.in-0.5i
30+
Detab is equivalent to entab -d.
31+
.SH NOTES
32+
Entab has improved tab handling for certain situations.
33+
It only replaces tabs if there is a user-defined number of spaces
34+
to be saved.
35+
Other tab replacement programs put tabs wherever
36+
possible, so if two words are separated by one space, and that
37+
space is on a tab stop, a tab is inserted.
38+
Then, when words are added to the left, the words are shifted over,
39+
leaving a large gap.
40+
The quote-protection option allows tab replacement without
41+
quoted strings being changed.
42+
Useful when strings in source code will not have the same tab stops
43+
when executed in the program.
44+
.LP
45+
To change a text file created on a system with one size of tab
46+
stop to display properly on a device with different tab setting,
47+
use detab (or entab -d) to remove tabs from the file with the
48+
tab size set to the original tab size, then use entab to re-tab
49+
the file with the new tab size.
50+
.SH AUTHOR
51+
Bruce Momjian, root@candle.pha.pa.us

‎src/tools/entab/halt.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
**
3+
**halt.c
4+
**
5+
**This is used to print out error messages and exit
6+
*/
7+
8+
#include<varargs.h>
9+
#include<signal.h>
10+
#include<stdio.h>
11+
#include<errno.h>
12+
13+
14+
/*-------------------------------------------------------------------------
15+
**
16+
**halt - print error message, and call clean up routine or exit
17+
**
18+
**------------------------------------------------------------------------*/
19+
20+
/*VARARGS*/
21+
voidhalt(va_alist)
22+
va_dcl
23+
{
24+
va_listarg_ptr;
25+
char*format,*pstr;
26+
void (*sig_func)();
27+
28+
va_start(arg_ptr);
29+
format=va_arg(arg_ptr,char*);
30+
if (strncmp(format,"PERROR",6)!=0)
31+
vfprintf(stderr,format,arg_ptr);
32+
else
33+
{
34+
for (pstr=format+6;*pstr==' '||*pstr==':';pstr++)
35+
;
36+
vfprintf(stderr,pstr,arg_ptr);
37+
perror("");
38+
}
39+
va_end(arg_ptr);
40+
fflush(stderr);
41+
42+
/* call one clean up function if defined */
43+
if ( (sig_func=signal(SIGTERM,SIG_DFL))!=SIG_DFL&&
44+
sig_func!=SIG_IGN)
45+
(*sig_func)(0);
46+
elseif ( (sig_func=signal(SIGHUP,SIG_DFL))!=SIG_DFL&&
47+
sig_func!=SIG_IGN)
48+
(*sig_func)(0);
49+
elseif ( (sig_func=signal(SIGINT,SIG_DFL))!=SIG_DFL&&
50+
sig_func!=SIG_IGN)
51+
(*sig_func)(0);
52+
elseif ( (sig_func=signal(SIGQUIT,SIG_DFL))!=SIG_DFL&&
53+
sig_func!=SIG_IGN)
54+
(*sig_func)(0);
55+
exit(1);
56+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp