1 /***********************************************************************/
2 /* Open Visualization Data Explorer */
3 /* (C) Copyright IBM Corp. 1989,1999 */
4 /* ALL RIGHTS RESERVED */
5 /* This code licensed under the */
6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
7 /***********************************************************************/
8
9 #include <dxconfig.h>
10
11
12 #include <dx/dx.h>
13 #include "path.h"
14 #include "utils.h"
15
16
17 #define EX_MAXPATH 4096
18 #define EX_I_SEP ':' /* instance # separator */
19 #define EX_M_SEP '/' /* macro/module separator */
20 #define EX_END '\000' /* NULL */
21 #define EX_NUM_LEN 11 /* max printable length of int */
22 #define EX_PATHLEN(l) ((l)+EX_NUM_LEN+3) /* chars to add path */
23
24
25 char
_dxf_ExPathStrPrepend(char * name,int instance,char * path)26 *_dxf_ExPathStrPrepend (char *name, int instance, char *path)
27 {
28 static char localPath[EX_MAXPATH];
29 char *tail = localPath;
30 int l = strlen (name);
31 int np;
32
33 *(tail++) = EX_M_SEP;
34 strcpy (tail, name);
35 tail += l;
36 *(tail++) = EX_I_SEP;
37 if (instance < 0 || instance > 999)
38 {
39 /* sprintf automatically appends \0 to the end of a
40 string so why include it twice? */
41 /* was -- sprintf(tail, "%d\0", instance); */
42 sprintf(tail, "%d", instance);
43 l = strlen(tail);
44 tail += l;
45 }
46 else if (instance > 99)
47 {
48 np = instance / 100;
49 *(tail++) = np + '0';
50 instance -= np * 100;
51 np = instance / 10;
52 *(tail++) = np + '0';
53 instance -= np * 10;
54 *(tail++) = instance + '0';
55 }
56 else if (instance > 9)
57 {
58 np = instance / 10;
59 *(tail++) = np + '0';
60 instance -= np * 10;
61 *(tail++) = instance + '0';
62 }
63 else
64 *(tail++) = instance + '0';
65 *(tail) = '\0';
66
67 if (path != NULL)
68 strcat(tail, path);
69
70 return localPath;
71 }
72