1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | //
|
---|
3 | // $Id: utils.cc,v 1.1.1.1 1999-11-26 16:37:12 ansari Exp $
|
---|
4 | //
|
---|
5 |
|
---|
6 | #include "machdefs.h"
|
---|
7 | #include "utils.h"
|
---|
8 | #include "pexceptions.h"
|
---|
9 | #include <string.h>
|
---|
10 |
|
---|
11 | // MemCpy marche meme en cas de recouvrement.
|
---|
12 | void* MemCpy(void* dest, const void* source, size_t n)
|
---|
13 | {
|
---|
14 | int i; // THINK C ne veut pas du int i dans chaque for...
|
---|
15 | if (dest < source)
|
---|
16 | for (i=0; i<n; i++)
|
---|
17 | ((char*)dest)[i] = ((char*)source)[i];
|
---|
18 | else
|
---|
19 | for (i=n-1; i>=0; i--)
|
---|
20 | ((char*)dest)[i] = ((char*)source)[i];
|
---|
21 |
|
---|
22 | return dest;
|
---|
23 | }
|
---|
24 |
|
---|
25 | // Dans parmst.cc
|
---|
26 | //int PrtLevel = 0;
|
---|
27 | //int DebugLevel = 0;
|
---|
28 |
|
---|
29 | char const* PeidaWorkPath()
|
---|
30 | {
|
---|
31 | char const* envWP = getenv("PEIDAWORKPATH");
|
---|
32 | if (envWP) return envWP;
|
---|
33 | #ifdef __mac__
|
---|
34 | return "WORK";
|
---|
35 | #endif
|
---|
36 | return ".";
|
---|
37 | }
|
---|
38 |
|
---|
39 | #ifndef __mac__
|
---|
40 | void buildPath(char* dst, const char* dir, const char* file)
|
---|
41 | {
|
---|
42 | strcpy(dst, dir);
|
---|
43 | char *p = dst; while (*p) p++; p--;
|
---|
44 | if (*dir && *p != '/') strcat(dst, "/");
|
---|
45 | strcat(dst, file);
|
---|
46 | }
|
---|
47 |
|
---|
48 | void buildPath(string& dst, const string& dir, const string& file)
|
---|
49 | {
|
---|
50 | dst = dir;
|
---|
51 | if (dir != "" && dir[dir.length()-1] != '/') dst += "/";
|
---|
52 | dst += file;
|
---|
53 | }
|
---|
54 |
|
---|
55 | #else
|
---|
56 | void buildPath(char* dst, const char* dir, const char* file)
|
---|
57 | {
|
---|
58 | if (*dir) {
|
---|
59 | strcpy(dst, ":");
|
---|
60 | strcat(dst, dir);
|
---|
61 | char *p = dst; while (*p) p++; p--;
|
---|
62 | strcat(dst, ":");
|
---|
63 | strcat(dst, file);
|
---|
64 | } else
|
---|
65 | strcpy(dst, file);
|
---|
66 | }
|
---|
67 |
|
---|
68 | void buildPath(string& dst, const string& dir, const string& file)
|
---|
69 | {
|
---|
70 | if (dir != "") {
|
---|
71 | dst = ":" + dir + ":" + file;
|
---|
72 | } else
|
---|
73 | dst = file;
|
---|
74 | }
|
---|
75 |
|
---|
76 | #endif
|
---|
77 |
|
---|
78 |
|
---|
79 | void changeSuffix(char* file, const char* suffix)
|
---|
80 | {
|
---|
81 | char *p = file;
|
---|
82 | while (*p) p++;
|
---|
83 | while (*p != '.' && p > file) p--;
|
---|
84 | if (*p != '.')
|
---|
85 | strcat(file, suffix);
|
---|
86 | else
|
---|
87 | strcpy(p,suffix);
|
---|
88 | }
|
---|
89 |
|
---|
90 | void changeSuffix(string& file, const string& suffix)
|
---|
91 | {
|
---|
92 | size_t pos = file.rfind('.');
|
---|
93 | // if (pos != NPOS) file.remove(pos);
|
---|
94 | if (pos != NPOS) file = file.substr(0,pos);
|
---|
95 | file += suffix;
|
---|
96 | }
|
---|
97 |
|
---|
98 | string itos(int i)
|
---|
99 | {
|
---|
100 | char s[20];
|
---|
101 | sprintf(s, "%d", i);
|
---|
102 | return s;
|
---|
103 | }
|
---|
104 |
|
---|
105 | string ftos(double f)
|
---|
106 | {
|
---|
107 | char s[20];
|
---|
108 | sprintf(s, "%g", f);
|
---|
109 | return s;
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|