source: trunk/lib/utility.cc @ 163

Last change on this file since 163 was 163, checked in by Jari Häkkinen, 16 years ago

Removed unused variable in lib/utility.cc.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1// $Id: utility.cc 163 2006-08-22 22:22:52Z jari $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "utility.h"
25
26#include <fstream>
27#include <iostream> // remove this when 'blame' is removed
28#include <sstream>
29#include <stdexcept>
30#include <string>
31#include <sys/param.h>
32#include <unistd.h>
33
34namespace theplu{
35namespace svndigest{
36
37  int access_rights(const std::string& path, const std::string& bits)
38  {
39    if (access(path.c_str(),F_OK)) {
40      throw std::runtime_error(std::string("access_rights: ") + path +
41                               "' does not exist.");
42    }
43    int mode=0;
44    for (u_int i=0; i<bits.length(); i++)
45      switch (bits[i]) {
46          case 'r':
47            mode|=R_OK;
48            break;
49          case 'w':
50            mode|=W_OK;
51            break;
52          case 'x':
53            mode|=X_OK;
54            break;
55      }
56    return access(path.c_str(),mode);
57  }
58
59
60  std::string file_name(const std::string& full_path)
61  {
62    std::stringstream ss(full_path);
63    std::string name;
64    while (getline(ss,name,'/')) {}
65    return name;
66  }
67
68
69  void print_css(std::ostream& s)
70  {
71    s << "body {\n";
72    s << " background: #fff; \n";
73    s << " color: #000; \n";
74    s << " margin: 0px; \n";
75    s << " padding: 0; \n";
76    s << "} \n";
77    s << "\n";
78    s << "#menu {\n";
79    s << " background: #eee;\n";
80    s << " width: 100%;\n";
81    s << " margin: 0px;\n";
82    s << " padding: 0px;\n";
83    s << "}\n\n";
84    s << "#menu ul\n";
85    s << "{ \n";
86    s << "padding: 0px;\n";
87    s << "margin: 0px;list-style-type: none; text-align: center;"
88      << "border-bottom: 1px solid black;}\n";
89    s << "#menu ul li { display: inline; border-right: 1px solid black;}\n";
90    s << "#menu ul li a {text-decoration: none; padding-right: 1em;" 
91      << "padding-left: 1em; margin: 0px;}\n";
92    s << "#menu ul li a:hover{ color: #000; background: #ddd;}\n";
93    s << "\n";
94    s << "#main {\n";
95    s << " margin: 10px; \n";
96    s << "}\n";
97    s << "\n";
98    s << "body, th, td {\n";
99    s << " font: normal 13px verdana,arial,'Bitstream Vera Sans',"
100      << "helvetica,sans-serif;\n";
101    s << "}\n";
102    s << ":link, :visited {\n";
103    s << " text-decoration: none;\n";
104    s << " color: #b00;\n";
105    s << "}\n";
106    s << "\n";
107    s << "table.listings {\n";
108    s << " clear: both;\n";
109    s << " border-bottom: 1px solid #d7d7d7;\n";
110    s << " border-collapse: collapse;\n";
111    s << " border-spacing: 0;\n";
112    s << " margin-top: 1em;\n";
113    s << " width: 100%;\n";
114    s << "}\n";
115    s << "\n";
116    s << "table.listings th {\n";
117    s << " text-align: left;\n";
118    s << " padding: 0 1em .1em 0;\n";
119    s << " font-size: 12px\n";
120    s << "}\n";
121    s << "table.listings thead { background: #f7f7f0 }\n";
122    s << "table.listings thead th {\n";
123    s << " border: 1px solid #d7d7d7;\n";
124    s << " border-bottom-color: #999;\n";
125    s << " font-size: 11px;\n";
126    s << " font-wheight: bold;\n";
127    s << " padding: 2px .5em;\n";
128    s << " vertical-align: bottom;\n";
129    s << "}\n";
130    s << "\n";
131    s << "table.listings tbody td a:hover, table.listing tbody th a:hover {\n";
132    s << " background-color: transparent;\n";
133    s << "}\n";
134    s << "\n";
135    s << "table.listings tbody td, table.listing tbody th {\n";
136    s << " border: 1px dotted #ddd;\n";
137    s << " padding: .33em .5em;\n";
138    s << " vertical-align: top;\n";
139    s << "}\n";
140    s << "\n";
141    s << "table.listings tbody td a:hover, table.listing tbody th a:hover {\n";
142    s << " background-color: transparent;\n";
143    s << "}\n";
144    s << "table.listings tbody tr { border-top: 1px solid #ddd }\n";
145    s << "table.listings tbody tr.light { background-color: #fcfcfc }\n";
146    s << "table.listings tbody tr.dark { background-color: #f7f7f7 }\n";
147    s << "table.listings tbody tr:hover { background: #eed }\n";
148    s << "\n";
149    s << "\n";
150    s << "\n";
151  }
152
153
154  std::string pwd(void)
155  {
156    char buffer[MAXPATHLEN];
157    if (!getcwd(buffer, MAXPATHLEN))
158      throw std::runtime_error("Failed to get current working directory");
159    return std::string(buffer);
160  }
161
162}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.