source: branches/port5/ptpan/PTP_etc.cxx

Last change on this file was 5908, checked in by westram, 16 years ago
  • source files with identical names are really a pain when using valgrind
File size: 2.4 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4// #include <malloc.h>
5#include <memory.h>
6#include <PT_server.h>
7#include <PT_server_prototypes.h>
8#include "ptpan.h"
9#include "pt_prototypes.h"
10#include <struct_man.h>
11
12/* *** FIXME *** do we need this function? */
13/* called by:
14   PROBE/PT_match.cxx:      pt_export_error(locs,"error: probe too short!!\n");
15   PROBE/PT_new_design.cxx: pt_export_error(locs,"No Species selected");
16*/
17
18/* /// "SetARBErrorMsg()" */
19void SetARBErrorMsg(PT_local *locs, const STRPTR error)
20{
21  if(locs->ls_error)
22  {
23    free(locs->ls_error);
24  }
25  locs->ls_error = strdup(error);
26}
27/* \\\ */
28
29/* get the name with a virtual function */
30/* /// "virt_name()" */
31extern "C" STRPTR virt_name(PT_probematch *ml)
32{
33  struct PTPanGlobal *pg = PTPanGlobalPtr;
34  return(pg->pg_SpeciesMap[ml->name]->ps_Name);
35}
36/* \\\ */
37
38/* /// "virt_fullname()" */
39extern "C" STRPTR virt_fullname(PT_probematch *ml)
40{
41  struct PTPanGlobal *pg = PTPanGlobalPtr;
42  return(pg->pg_SpeciesMap[ml->name]->ps_FullName);
43}
44/* \\\ */
45
46/* called by:
47   AISC
48*/
49extern "C" bytestring *PT_unknown_names(struct_PT_pdc *pdc)
50{
51  struct PTPanGlobal *pg = PTPanGlobalPtr;
52  STRPTR specnames;
53  STRPTR namestart;
54  UBYTE namechr;
55  ULONG allocsize = 2;
56  ULONG pos = 0;
57  STRPTR tarptr;
58
59  printf("EXTERN: PT_unknown_names\n");
60  /* free old string and allocate minimum buffer */
61  freeset(pg->pg_UnknownSpecies.data, (STRPTR) malloc(allocsize));
62  *pg->pg_UnknownSpecies.data = 0;
63  namestart = specnames = pdc->names.data;
64  do
65  {
66    namechr = *specnames;
67    /* if we encounter a hash or a nullbyte, we're at the end of a species string */
68    if((namechr == '#') || (!namechr))
69    {
70      if(namestart < specnames) /* don't try to find an empty string */
71      {
72    /* temporarily terminate the string */
73    *specnames = 0;
74    if(!GBS_read_hash(pg->pg_SpeciesNameHash, namestart))
75    {
76    allocsize += (specnames - namestart) + 1;
77    pg->pg_UnknownSpecies.data = (STRPTR) realloc(pg->pg_UnknownSpecies.data, allocsize);
78    tarptr = &pg->pg_UnknownSpecies.data[pos];
79    if(pos)
80    {
81        *tarptr++ = '#';
82    }
83    /* copy name */
84    while((*tarptr++ = *namestart++))
85    {
86        pos++;
87    }
88    }
89    /* restore character */
90    *specnames++ = namechr;
91    namestart = specnames;
92      } else {
93    namestart = ++specnames;
94      }
95    } else {
96      specnames++;
97    }
98  } while(namechr);
99  pg->pg_UnknownSpecies.size = pos + 1;
100  return(&pg->pg_UnknownSpecies);
101}
Note: See TracBrowser for help on using the repository browser.