~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to ex_slab_steps.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                ex_slab_steps.c
 
6
 
 
7
Purpose:
 
8
        Extract slab steps (five doubles) from a string.
 
9
 
 
10
Input:
 
11
        (1) Pointer to ConfigS structure, where values will be stored.
 
12
        (2) Input string pointer.
 
13
 
 
14
Output:
 
15
        Return value.
 
16
 
 
17
Return value:
 
18
        (1) Positive on success.
 
19
        (2) Negative on failure.
 
20
 
 
21
========includes:============================================================*/
 
22
 
 
23
#include <stdio.h>
 
24
#include <ctype.h>
 
25
 
 
26
#include <X11/Xlib.h>
 
27
#include <X11/Xutil.h>
 
28
#include <X11/Xos.h>
 
29
#include <X11/Xatom.h>
 
30
 
 
31
#include "defines.h"
 
32
#include "typedefs.h"
 
33
 
 
34
/*======extract slab steps from a string:====================================*/
 
35
 
 
36
int ExtractSlabSteps_ (ConfigS *configSP, char *sP)
 
37
{
 
38
char            *P0, *P1;
 
39
int             n;
 
40
double          d1, d2, d3, d4, d5;
 
41
 
 
42
/* Colon should be separator: */
 
43
if ((P0 = strstr (sP, ":")) == NULL) P0 = sP;
 
44
 
 
45
/* Replace each non-numeric character (except */
 
46
/* minus sign and  decimal point) with space: */
 
47
P1 = P0;
 
48
while ((n = *P1++) != '\0')
 
49
        {
 
50
        if (!isdigit (n) && (n != '-') && (n != '.')) *(P1 - 1) = ' ';
 
51
        }
 
52
 
 
53
/* Try to read five doubles: */
 
54
if (sscanf (P0, "%lf %lf %lf %lf %lf", &d1, &d2, &d3, &d4, &d5) != 5)
 
55
        {
 
56
        return -1;
 
57
        }
 
58
 
 
59
/* Copy slab steps to ConfigS: */
 
60
configSP->slab_stepA[0] = d1;
 
61
configSP->slab_stepA[1] = d2;
 
62
configSP->slab_stepA[2] = d3;
 
63
configSP->slab_stepA[3] = d4;
 
64
configSP->slab_stepA[4] = d5;
 
65
 
 
66
/* If everything worked fine, return positive number: */
 
67
return 1;
 
68
}
 
69
 
 
70
/*===========================================================================*/
 
71
 
 
72