~ojwb/survex/master

« back to all changes in this revision

Viewing changes to src/avenprcore.cc

  • Committer: Olly Betts
  • Date: 2010-06-18 07:16:42 UTC
  • mfrom: (2003.1.853)
  • Revision ID: git-v1:75fe355c16c77b1090c4426a3dc0b8dabca31904
Rename branches/survex-1_1 to trunk.

git-svn-id: file:///home/survex-svn/survex/trunk@3454 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* avenprcore.c
 
1
/* avenprcore.cc
2
2
 * Printer independent parts of Survex printer drivers
3
 
 * Copyright (C) 1993-2002,2004,2005 Olly Betts
 
3
 * Copyright (C) 1993-2002,2004,2005,2006 Olly Betts
4
4
 * Copyright (C) 2004 Philip Underwood
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
17
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
21
/* FIXME provide more explanation when reporting errors in print.ini */
52
52
layout::layout(wxPageSetupDialogData* data)
53
53
        : Labels(false), Crosses(false), Shots(true), Surface(false),
54
54
          SkipBlank(false), Border(true), Cutlines(true), Raw(false),
55
 
          title(NULL), datestamp(NULL), Scale(0), rot(0), tilt(0),
 
55
          title(), datestamp(), Scale(0), rot(0), tilt(0),
56
56
          view(PLAN), scX(1), scY(1), xMin(0), xMax(-1), yMin(0), yMax(-1),
57
 
          pagesX(1), pagesY(1), pages(1), xOrg(0), yOrg(0), footer(NULL)
 
57
          pagesX(1), pagesY(1), pages(1), xOrg(0), yOrg(0), footer()
58
58
{
59
59
    // Create a temporary wxPrinterDC/wxPostScriptDC so we can get access to
60
60
    // the size of the printable area in mm to allow us to calculate how many
120
120
              v, p);
121
121
}
122
122
 
123
 
char *
124
 
as_string(const char *v, char *p)
125
 
{
126
 
   if (!p) setting_missing(v);
127
 
   return p;
128
 
}
129
 
 
130
123
int
131
124
as_int(const char *v, char *p, int min_val, int max_val)
132
125
{
214
207
   return val;
215
208
}
216
209
 
217
 
int
218
 
as_bool(const char *v, char *p)
219
 
{
220
 
   return as_int(v, p, 0, 1);
221
 
}
222
 
 
223
 
double
224
 
as_double(const char *v, char *p, double min_val, double max_val)
225
 
{
226
 
   double val;
227
 
   char *pEnd;
228
 
   if (!p) setting_missing(v);
229
 
   val = strtod(p, &pEnd);
230
 
   if (pEnd == p || val < min_val || val > max_val)
231
 
      setting_bad_value(v, p);
232
 
   osfree(p);
233
 
   return val;
234
 
}
235
 
 
236
 
/*
237
 
Codes:
238
 
\\ -> '\'
239
 
\xXX -> char with hex value XX
240
 
\0, \n, \r, \t -> nul (0), newline (10), return (13), tab (9)
241
 
\[ -> Esc (27)
242
 
\? -> delete (127)
243
 
\A - \Z -> (1) to (26)
244
 
*/
245
 
 
246
 
/* Takes a string, converts escape sequences in situ, and returns length
247
 
 * of result (needed since converted string may contain '\0' */
248
 
int
249
 
as_escstring(const char *v, char *s)
250
 
{
251
 
   char *p, *q;
252
 
   char c;
253
 
   int pass;
254
 
   static const char *escFr = "[nrt?0"; /* 0 is last so maps to the implicit \0 */
255
 
   static const char *escTo = "\x1b\n\r\t\?";
256
 
   bool fSyntax = fFalse;
257
 
   if (!s) setting_missing(v);
258
 
   for (pass = 0; pass <= 1; pass++) {
259
 
      p = q = s;
260
 
      while (*p) {
261
 
         c = *p++;
262
 
         if (c == '\\') {
263
 
            c = *p++;
264
 
            switch (c) {
265
 
             case '\\': /* literal "\" */
266
 
               break;
267
 
             case 'x': /* hex digits */
268
 
               if (isxdigit((unsigned char)*p) &&
269
 
                   isxdigit((unsigned char)p[1])) {
270
 
                  if (pass) c = (CHAR2HEX(*p) << 4) | CHAR2HEX(p[1]);
271
 
                  p += 2;
272
 
                  break;
273
 
               }
274
 
               /* \x not followed by 2 hex digits */
275
 
               /* !!! FALLS THROUGH !!! */
276
 
             case '\0': /* trailing \ is meaningless */
277
 
               fSyntax = 1;
278
 
               break;
279
 
             default:
280
 
               if (pass) {
281
 
                  const char *t = strchr(escFr, c);
282
 
                  if (t) {
283
 
                     c = escTo[t - escFr];
284
 
                     break;
285
 
                  }
286
 
                  /* \<capital letter> -> Ctrl-<letter> */
287
 
                  if (isupper((unsigned char)c)) {
288
 
                     c -= '@';
289
 
                     break;
290
 
                  }
291
 
                  /* otherwise don't do anything to c (?) */
292
 
                  break;
293
 
               }
294
 
            }
295
 
         }
296
 
         if (pass) *q++ = c;
297
 
      }
298
 
      if (fSyntax) {
299
 
         SVX_ASSERT(pass == 0);
300
 
         setting_bad_value(v, s);
301
 
      }
302
 
   }
303
 
   return (q - s);
304
 
}
305
 
 
306
210
#define DEF_RATIO (1.0/(double)DEFAULT_SCALE)
307
211
 
308
212
/* pick a scale which will make it fit in the desired size */