~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to pgadmin/pgscript/utilities/m_apm/mapmistr.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* 
 
3
 *  M_APM  -  mapmistr.c
 
4
 *
 
5
 *  Copyright (C) 1999 - 2007   Michael C. Ring
 
6
 *
 
7
 *  Permission to use, copy, and distribute this software and its
 
8
 *  documentation for any purpose with or without fee is hereby granted,
 
9
 *  provided that the above copyright notice appear in all copies and
 
10
 *  that both that copyright notice and this permission notice appear
 
11
 *  in supporting documentation.
 
12
 *
 
13
 *  Permission to modify the software is granted. Permission to distribute
 
14
 *  the modified code is granted. Modifications are to be distributed by
 
15
 *  using the file 'license.txt' as a template to modify the file header.
 
16
 *  'license.txt' is available in the official MAPM distribution.
 
17
 *
 
18
 *  This software is provided "as is" without express or implied warranty.
 
19
 */
 
20
 
 
21
/*
 
22
 *
 
23
 *      This file contains M_APM -> integer string function
 
24
 *
 
25
 */
 
26
 
 
27
#include "pgAdmin3.h"
 
28
#include "pgscript/utilities/mapm-lib/m_apm_lc.h"
 
29
 
 
30
/****************************************************************************/
 
31
void    m_apm_to_integer_string(char *s, M_APM mtmp)
 
32
{
 
33
void    *vp;
 
34
UCHAR   *ucp, numdiv, numrem;
 
35
char    *cp, *p, sbuf[128];
 
36
int     ct, dl, numb, ii;
 
37
 
 
38
vp = NULL;
 
39
ct = mtmp->m_apm_exponent;
 
40
dl = mtmp->m_apm_datalength;
 
41
 
 
42
/*
 
43
 *  if |input| < 1, result is "0"
 
44
 */
 
45
 
 
46
if (ct <= 0 || mtmp->m_apm_sign == 0)
 
47
  {
 
48
   s[0] = '0';
 
49
   s[1] = '\0';
 
50
   return;
 
51
  }
 
52
 
 
53
if (ct > 112)
 
54
  {
 
55
   if ((vp = (void *)MAPM_MALLOC((ct + 32) * sizeof(char))) == NULL)
 
56
     {
 
57
      /* fatal, this does not return */
 
58
 
 
59
      M_apm_log_error_msg(M_APM_FATAL, 
 
60
                          "\'m_apm_to_integer_string\', Out of memory");
 
61
     }
 
62
 
 
63
   cp = (char *)vp;
 
64
  }
 
65
else
 
66
  {
 
67
   cp = sbuf;
 
68
  }
 
69
 
 
70
p  = cp;
 
71
ii = 0;
 
72
 
 
73
/* handle a negative number */
 
74
 
 
75
if (mtmp->m_apm_sign == -1)
 
76
  {
 
77
   ii = 1;
 
78
   *p++ = '-';
 
79
  }
 
80
 
 
81
/* get num-bytes of data (#digits / 2) to use in the string */
 
82
 
 
83
if (ct > dl)
 
84
  numb = (dl + 1) >> 1;
 
85
else
 
86
  numb = (ct + 1) >> 1;
 
87
 
 
88
ucp = mtmp->m_apm_data;
 
89
 
 
90
while (TRUE)
 
91
  {
 
92
   M_get_div_rem_10((int)(*ucp++), &numdiv, &numrem);
 
93
 
 
94
   *p++ = numdiv + '0';
 
95
   *p++ = numrem + '0';
 
96
 
 
97
   if (--numb == 0)
 
98
     break;
 
99
  }
 
100
 
 
101
/* pad with trailing zeros if the exponent > datalength */
 
102
 
 
103
if (ct > dl)
 
104
  memset(p, '0', (ct + 1 - dl));
 
105
 
 
106
cp[ct + ii] = '\0';
 
107
strcpy(s, cp);
 
108
 
 
109
if (vp != NULL)
 
110
  MAPM_FREE(vp);
 
111
}
 
112
/****************************************************************************/