~ubuntu-branches/ubuntu/wily/apvlv/wily

« back to all changes in this revision

Viewing changes to src/ApvlvParams.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2011-06-01 22:18:49 UTC
  • mfrom: (10.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110601221849-niibd5p5i7avemy4
Tags: 0.1.1-1.1
* Non-maintainer upload.
* Add support for poppler >= 0.15. Patch by Pino Toscano. (Closes: #627609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "ApvlvCmds.hpp"
31
31
#include "ApvlvParams.hpp"
32
32
 
33
 
#include <stdlib.h>
34
 
#include <string.h>
35
 
 
36
33
#include <iostream>
37
34
#include <fstream>
38
35
#include <sstream>
39
36
 
40
37
namespace apvlv
41
 
{
 
38
  {
42
39
  ApvlvParams *gParams = NULL;
43
40
 
44
 
    ApvlvParams::ApvlvParams ()
 
41
  ApvlvParams::ApvlvParams ()
45
42
  {
 
43
    push ("inverted", "no");
46
44
    push ("fullscreen", "no");
47
45
    push ("zoom", "fitwidth");
48
46
    push ("continuous", "yes");
77
75
  bool ApvlvParams::loadfile (const char *filename)
78
76
  {
79
77
    if (filename == NULL
80
 
        || g_file_test (filename, G_FILE_TEST_IS_REGULAR) == FALSE)
 
78
        || g_file_test (filename, G_FILE_TEST_IS_REGULAR) == FALSE)
81
79
      {
82
 
        return false;
 
80
        return false;
83
81
      }
84
82
 
85
83
//    debug ("load debug: %s", filename);
88
86
 
89
87
    if (!os.is_open ())
90
88
      {
91
 
        errp ("Open configure file %s error", filename);
92
 
        return false;
 
89
        errp ("Open configure file %s error", filename);
 
90
        return false;
93
91
      }
94
92
 
95
93
    while ((getline (os, str)) != NULL)
96
94
      {
97
 
        string argu, data, crap;
98
 
        stringstream is (str);
99
 
        // avoid commet line, continue next
100
 
        is >> crap;
101
 
        if (crap[0] == '\"' || crap == "")
102
 
          {
103
 
            continue;
104
 
          }
105
 
        // parse the line like "set fullscreen=yes" or set "set zoom=1.5"
106
 
        else if (crap == "set")
107
 
          {
108
 
            is >> argu;
109
 
            size_t off = argu.find ('=');
110
 
            if (off == string::npos)
111
 
              {
112
 
                is >> crap >> data;
113
 
                if (crap == "=")
114
 
                  {
115
 
                    push (argu.c_str (), data.c_str ());
116
 
                    continue;
117
 
                  }
118
 
              }
119
 
            else if (off < 32)
120
 
              {
121
 
                char k[32], v[32], *p;
122
 
                memcpy (k, argu.c_str (), off);
123
 
                k[off] = '\0';
124
 
 
125
 
                p = (char *) argu.c_str () + off + 1;
126
 
                while (isspace (*p))
127
 
                  {
128
 
                    p++;
129
 
                  }
130
 
 
131
 
                g_snprintf (v, sizeof v, "%s", *p ? p : "");
132
 
 
133
 
                p = (char *) v + strlen (v) - 1;
134
 
                while (isspace (*p) && p >= v)
135
 
                  {
136
 
                    p--;
137
 
                  }
138
 
                *(p + 1) = '\0';
139
 
 
140
 
                push (k, v);
141
 
                continue;
142
 
              }
143
 
 
144
 
            errp ("Syntax error: set: %s", str.c_str ());
145
 
          }
146
 
        // like "map n next-page"
147
 
        else if (crap == "map")
148
 
          {
149
 
            is >> argu;
150
 
 
151
 
            if (argu.length () == 0)
152
 
              {
153
 
                errp ("map command not complete");
154
 
                continue;
155
 
              }
156
 
 
157
 
            getline (is, data);
158
 
 
159
 
            while (data.length () > 0 && isspace (data[0]))
160
 
              data.erase (0, 1);
161
 
 
162
 
            if (argu.length () > 0 && data.length () > 0)
163
 
              {
164
 
                gCmds->buildmap (argu.c_str (), data.c_str ());
165
 
              }
166
 
            else
167
 
              {
168
 
                errp ("Syntax error: map: %s", str.c_str ());
169
 
              }
170
 
          }
171
 
        else
172
 
          {
173
 
            errp ("Unknown rc command: %s: %s", crap.c_str (), str.c_str ());
174
 
          }
 
95
        string argu, data, crap;
 
96
        stringstream is (str);
 
97
        // avoid commet line, continue next
 
98
        is >> crap;
 
99
        if (crap[0] == '\"' || crap == "")
 
100
          {
 
101
            continue;
 
102
          }
 
103
        // parse the line like "set fullscreen=yes" or set "set zoom=1.5"
 
104
        else if (crap == "set")
 
105
          {
 
106
            is >> argu;
 
107
            size_t off = argu.find ('=');
 
108
            if (off == string::npos)
 
109
              {
 
110
                is >> crap >> data;
 
111
                if (crap == "=")
 
112
                  {
 
113
                    push (argu.c_str (), data.c_str ());
 
114
                    continue;
 
115
                  }
 
116
              }
 
117
            else if (off < 32)
 
118
              {
 
119
                char k[32], v[32], *p;
 
120
                memcpy (k, argu.c_str (), off);
 
121
                k[off] = '\0';
 
122
 
 
123
                p = (char *) argu.c_str () + off + 1;
 
124
                while (isspace (*p))
 
125
                  {
 
126
                    p++;
 
127
                  }
 
128
 
 
129
                g_snprintf (v, sizeof v, "%s", *p ? p : "");
 
130
 
 
131
                p = (char *) v + strlen (v) - 1;
 
132
                while (isspace (*p) && p >= v)
 
133
                  {
 
134
                    p--;
 
135
                  }
 
136
                *(p + 1) = '\0';
 
137
 
 
138
                push (k, v);
 
139
                continue;
 
140
              }
 
141
 
 
142
            errp ("Syntax error: set: %s", str.c_str ());
 
143
          }
 
144
        // like "map n next-page"
 
145
        else if (crap == "map")
 
146
          {
 
147
            is >> argu;
 
148
 
 
149
            if (argu.length () == 0)
 
150
              {
 
151
                errp ("map command not complete");
 
152
                continue;
 
153
              }
 
154
 
 
155
            getline (is, data);
 
156
 
 
157
            while (data.length () > 0 && isspace (data[0]))
 
158
              data.erase (0, 1);
 
159
 
 
160
            if (argu.length () > 0 && data.length () > 0)
 
161
              {
 
162
                gCmds->buildmap (argu.c_str (), data.c_str ());
 
163
              }
 
164
            else
 
165
              {
 
166
                errp ("Syntax error: map: %s", str.c_str ());
 
167
              }
 
168
          }
 
169
        else
 
170
          {
 
171
            errp ("Unknown rc command: %s: %s", crap.c_str (), str.c_str ());
 
172
          }
175
173
      }
176
174
 
177
175
    return true;
197
195
    it = mSettings.find (ss);
198
196
    if (it != mSettings.end ())
199
197
      {
200
 
        return it->second.c_str ();
 
198
        return it->second.c_str ();
201
199
      }
202
200
    return NULL;
203
201
  }
209
207
    it = mSettings.find (ss);
210
208
    if (it != mSettings.end ())
211
209
      {
212
 
        return atoi (it->second.c_str ());
 
210
        return atoi (it->second.c_str ());
213
211
      }
214
212
    return -1;
215
213
  }
221
219
    it = mSettings.find (ss);
222
220
    if (it != mSettings.end ())
223
221
      {
224
 
        return atof (it->second.c_str ());
 
222
        return atof (it->second.c_str ());
225
223
      }
226
224
    return -1.0;
227
225
  }
233
231
    it = mSettings.find (ss);
234
232
    if (it != mSettings.end () && it->second.compare ("yes") == 0)
235
233
      {
236
 
        return true;
 
234
        return true;
237
235
      }
238
236
    return false;
239
237
  }