-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBe
More file actions
executable file
·313 lines (233 loc) · 7.18 KB
/
Be
File metadata and controls
executable file
·313 lines (233 loc) · 7.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/bin/csh -f
#
# Makes a webpage that reflects the contents of the current directory.
# (Very simple webpages)
# Does it recursively, so directories within directories have the same thing done.
# Output will be an html file with the same name as the current working directory (+.html)
# Format of that html file is:
#
# It's intent is to keep the file structure of my research log consistent. We'll see how well it works.
# dcc 02/23/06 3:30 pm.
# San Diego, CA. Chilly with clear skies.
# Just ate some grapes.
# <link to parent dir. Same as this file>
# <list of links to sub directories. Same as this file>
# <list of links to files. Open in window to the right.>
# Directories that contain a file called 'index.html' are treated like html files.
# Directories in said file will not be recuresed into.
# 04/10/06: added exclusion
# the file Exclude.Be will contain a list of files to be ignored.
# 09/10/07: re-ordered pages, StuffYouWant, and dirs.
# Flow for this code:
# 1.) Create destination file, set up working variables.
# 2.) Create link for Parent Dir
# 3.) Get list of directories
# 4.) Check for index.html. Set up "Stuff You Want" links.
# 5.) Create links for Sub directories.
# 6.) Create links for html.
# 7.) Recurse into subdirectories, call this routine again.
# (repeat for new directory)
#
# Lets go.
#
# clean up temp files.
touch turd~
rm *~
pwd
#Set up the driving routines.
#Link returns a html link tag. Takes 3 arguments: source, text, target. Target is optional.
#MeetYourMaker should reflect this routine, wherever it is.
set WhereItsAt = "/Users/davidcollins/Scripts"
set Link = $WhereItsAt/Link
set MeetYourMaker = $WhereItsAt/Be
#
# Generate destination file.
#
#Clean, create the destination file.
set ThisDir = `pwd`
set ThisFileName = `basename $ThisDir`.html
#echo $ThisFileName
#
# Paused "AddTo" program. Un comment the AddTo line, remove the rm $ThisFileName,
# you were about to do the directories.
set AddTo = 'no'
if ( -e $ThisFileName ) then
# set AddTo = 'yes'
rm $ThisFileName
else
touch $ThisFileName
chmod a+r $ThisFileName
endif
#
# Generate Parent Dir tag.
#
cd ..
set ParentDir = `pwd`
set ParentFile = `basename $ParentDir`
set ParentHTML = "../"$ParentFile".html"
set ParentText = "Up One Dir"
#echo $ParentHTML
#go back to 'current'
cd $ThisDir
#Make link to parent direcory
set LinkToAdd = `$Link $ParentHTML "$ParentText"`
if( $AddTo == 'yes' ) then
#watch these quotes: single to escape command line, double to escape sed.
sed -i -e '1s:.*:'"$LinkToAdd": $ThisFileName
else
echo $LinkToAdd >> $ThisFileName
endif
#Write name of Current Directory.
set LinkToAdd = " <br><br><font size = 4> `basename $ThisDir` </font><br> "
if( $AddTo == 'yes') then
sed -i -e '2s:.*:'"$LinkToAdd": $ThisFileName
else
echo "<br><br><font size = 4>" `basename $ThisDir` "</font><br>" >> $ThisFileName
endif
#
# foreach directory in file, make a link. Probably wants something fancier in the future.
# Also set up 'exclusion' list.
#
#get list of directories.
set dirlistFull = `ls -l | grep "^d" | awk '{print $9}'`
#
# From dirlistFull, remove all directories in Exclude.Be (if such a
# file exists).
#
set dirlist = ""
# remove from dirlist based on existance in Exclude.Be or $ThisFile
if( -e Exclude.Be ) then
foreach dir ( $dirlistFull )
set Excluded = `grep -w $dir Exclude.Be | wc -l`
if( $AddTo == 'yes' ) then
@ Excluded = $Excluded + `grep $dir".html" $ThisFileName | wc -l`
endif
if ( $Excluded == '0' ) set dirlist = "$dirlist $dir"
end
else
set dirlist = "$dirlistFull"
endif
#For directories containing a file called 'index.html', make them look
#like files (open index.html in RHS.)
#To do so, Set up 'keep list', the list
set RecurseList = ""
set HasIndex = ""
#
# set up list of index files first. These are the most important
# things. Make a list (HasIndex) of directories that have index.html files.
#
foreach d ($dirlist)
if( -e $d/index.html ) then
set HasIndex = "$HasIndex $d"
endif
end
# set title for the index section (or, check that it's there.)
# (This removal is more complicated because it might not be there.)
#if ("$HasIndex" != "") then
# if( $AddTo == 'yes' ) then
# gsed -i -e '/Stuff You Want/d' $ThisFileName
# gsed -i -e '3i\<br><br> Stuff You Want <br><br>' $ThisFileName
# else
# echo "<br><br> Stuff You Want <br><br> " >> $ThisFileName
# endif
#endif
# moved the rest of HasIndex stuff below
#
# Stopped the "existing file" program here. need to get some research done.
#
#if there are directories, print a header for 'directories,' then
#print the directories.
if ( "$dirlist" != "" ) then
echo "<br><br> Dirs <br><br> " >> $ThisFileName
endif
foreach d ($dirlist)
set skip = 0
foreach h ($HasIndex )
if( $d == $h ) set skip = 1
end
if( $skip == 0 ) then
set dirhtml = "./$d/$d.html"
$Link $dirhtml $d >> $ThisFileName
echo "<br>" >> $ThisFileName
set RecurseList = "$RecurseList $d"
#echo "Recurse List " $RecurseList
endif
end
# I used to exclude recursion if there was an 'index' file.
# Stopped doing it, but this is the code I used to use. Saved for posterity.
#foreach d ($dirlist)
# if( -e $d/index.html ) then
# set HasIndex = "$HasIndex $d"
# #echo "Has Index " $HasIndex
# else
# set dirhtml = "./$d/$d.html"
# $Link $dirhtml $d >> $ThisFileName
# echo "<br>" >> $ThisFileName
# set RecurseList = "$RecurseList $d"
# #echo "Recurse List " $RecurseList
# endif
#end
#
#for each html file, add a link. Skip the page I'm making now, and
#anything in Exlcude.Be
#
set filelistFull = `ls *.html *.php`
#
# Create working filelist from filelistFull w/ files in Exclude.Be excluded.
#
set filelist = ""
if( -e Exclude.Be ) then
foreach file ( $filelistFull )
set Exclude = `grep $file Exclude.Be | wc -l`
if( $Exclude == '0' ) set filelist = "$filelist $file"
end
else
set filelist = "$filelistFull"
endif
#
# 08/07/06: now I want to exclude X.html that have associated X.jpg.
#
set filelistFull = "$filelist"
set filelist = ""
foreach f ($filelistFull)
set base = `basename $f .html`
if( !( -e "$base"."jpg" ) ) then
set filelist = "$filelist $f"
endif
end
if ( ("$filelist" != $ThisFileName) ) echo "<br><br> Pages <br><br> " >> $ThisFileName
foreach f ($HasIndex)
if ( $f != $ThisFileName ) then
set phtml = "."/$f/index.html
set word = $f
#echo $phtml
set LinkToAdd = `$Link $phtml $word BIG`
set LinkToAdd = "$LinkToAdd <font size = "-1"> `$Link "./$f/$f.html" '(d)'` </font>"
#check for existance in existing file.
if( $AddTo == 'yes') then
if( `grep "$LinkToAdd" $ThisFileName |wc -l` == '0' ) \
gsed -i -e "/<br><br> Dirs <br><br>/i\$LinkToAdd <br>" $ThisFileName
else
echo $LinkToAdd >> $ThisFileName
echo "<br>" >> $ThisFileName
endif
endif
end
foreach f ($filelist)
if ( $f != $ThisFileName ) then
set phtml = "."/$f
set word = `basename $f .html`
#echo $phtml
$Link $phtml $word BIG >> $ThisFileName
echo "<br>" >> $ThisFileName
endif
end
#
# Recursively call. (this should be interesting, god I hope this works.)
#
foreach d ($RecurseList)
cd $d
$MeetYourMaker
cd ..
end
#Make it recursive.