~ubuntu-branches/ubuntu/quantal/texmacs/quantal

« back to all changes in this revision

Viewing changes to src/Data/Tmfs/tmfs_file.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA, Kamaraju Kusumanchi, kohda
  • Date: 2008-04-06 15:11:41 UTC
  • mfrom: (1.1.7 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080406151141-w0sg20jnv86mlt6f
Tags: 1:1.0.6.14-1
[Kamaraju Kusumanchi <kamaraju@gmail.com>]
* New upstream release
* 01_american.dpatch is updated
* Since thread support in guile-1.8 is now disabled, the segmentation faults
  should not arise anymore. More info at #439923. (Closes: #450499, #458685)
[kohda]
* This version fixed menu problem.  (Closes: #447083)
* Reverted orig.tar.gz to the upstream tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************************************
 
3
* MODULE     : tmfs_file.cpp
 
4
* DESCRIPTION: files and projects
 
5
* COPYRIGHT  : (C) 2007  Joris van der Hoeven
 
6
*******************************************************************************
 
7
* This software falls under the GNU general public license and comes WITHOUT
 
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
 
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
 
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
11
******************************************************************************/
 
12
 
 
13
#include "tmfs.hpp"
 
14
 
 
15
/******************************************************************************
 
16
* Versioning routines
 
17
******************************************************************************/
 
18
 
 
19
string
 
20
tmfs_create_file (string name, string contents, string user, properties xps) {
 
21
  string master= tmfs_create_identifier ();
 
22
  string file  = tmfs_create_ressource ();
 
23
  properties ps;
 
24
  ps << seq ("file", file)
 
25
     << seq ("name", file, name)
 
26
     << seq ("master", file, master)
 
27
     << seq ("owner", file, user)
 
28
     << seq ("in", file, user)
 
29
     << seq ("read", file, user)
 
30
     << seq ("write", file, user)
 
31
     << substitute (xps, "self", file);
 
32
  tmfs_save_ressource (file, contents, ps);
 
33
  return file;
 
34
}
 
35
 
 
36
collection
 
37
tmfs_search_file (string name) {
 
38
  properties ps; ps << seq ("name", "?file", name) << seq ("file", "?file");
 
39
  return tmfs_query (ps, "?file");
 
40
}
 
41
 
 
42
void
 
43
tmfs_save (string file, string contents, properties ps) {
 
44
  if (tmfs_allows (file, "write") && tmfs_allows (file, "owner"))
 
45
    tmfs_save_ressource (file, contents, ps);
 
46
}
 
47
 
 
48
void
 
49
tmfs_save_file (string file, string cont) {
 
50
  if (tmfs_allows (file, "write"))
 
51
    tmfs_save_ressource (file, cont, tmfs_load_ressource_properties (file));
 
52
}
 
53
 
 
54
string
 
55
tmfs_load_file (string file) {
 
56
  if (tmfs_allows (file, "read"))
 
57
    return tmfs_load_ressource_file (file);
 
58
  return "";
 
59
}
 
60
 
 
61
/******************************************************************************
 
62
* Projects
 
63
******************************************************************************/
 
64
 
 
65
string
 
66
tmfs_create_project (string name, string user) {
 
67
  string project= tmfs_create_ressource ();
 
68
  string home= tmfs_create_file (name * " - home", "", project);
 
69
  properties ps;
 
70
  ps << seq ("project", project)
 
71
     << seq ("name", project, name)
 
72
     << seq ("owner", project, user)
 
73
     << seq ("in", project, user)
 
74
     << seq ("read", project, user)
 
75
     << seq ("write", project, user)
 
76
     << seq ("home", project, home);
 
77
  tmfs_save_ressource (project, "", ps);
 
78
  return project;
 
79
}
 
80
 
 
81
collection
 
82
tmfs_search_project (string name) {
 
83
  properties ps; ps << seq ("name", "?p", name) << seq ("project", "?p");
 
84
  return tmfs_query (ps, "?p");
 
85
}
 
86
 
 
87
collection
 
88
tmfs_get_file_projects (string file) {
 
89
  return tmfs_query (seq ("in", file, "?project"), "?project");
 
90
}
 
91
 
 
92
collection
 
93
tmfs_get_project_files (string project) {
 
94
  properties ps; ps << seq ("in", "?file", project) << seq ("file", "?file");
 
95
  collection files= tmfs_query (ps, "?file");
 
96
  collection homes= tmfs_query (seq ("home", project, "?home"), "?home");
 
97
  return files * invert (homes);
 
98
}
 
99
 
 
100
/******************************************************************************
 
101
* Branches
 
102
******************************************************************************/
 
103
 
 
104
void
 
105
tmfs_branch_file (string old_file, string branch) {
 
106
  string contents= tmfs_load_file (old_file);
 
107
  properties ps  = tmfs_get_attributes (old_file);
 
108
  string new_file= tmfs_create_ressource ();
 
109
  ps= substitute (ps, old_file, new_file);
 
110
  properties mp;
 
111
  mp << seq ("owner", old_file, "?user")
 
112
     << seq ("in", old_file, "?user")
 
113
     << seq ("read", old_file, "?user")
 
114
     << seq ("write", old_file, "?user");
 
115
  ps= reset (ps, mp);
 
116
  ps << seq ("owner", new_file, branch)
 
117
     << seq ("in", new_file, branch)
 
118
     << seq ("read", new_file, branch)
 
119
     << seq ("write", new_file, branch);
 
120
  tmfs_save_ressource (new_file, contents, ps);
 
121
}
 
122
 
 
123
string
 
124
tmfs_create_branch (string project, string name, string user) {
 
125
  collection c= tmfs_query (seq ("name", project, "?name"), "?name");
 
126
  if (N(c) == 0) return "";
 
127
  string full_name= first (c) * " - " * name;
 
128
  string branch= tmfs_create_project (full_name, user);
 
129
  strings files= as_strings (tmfs_get_project_files (project));
 
130
  for (int i=0; i<N(files); i++)
 
131
    tmfs_branch_file (files[i], branch);
 
132
  return branch;
 
133
}