~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_format.c

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "mysys_priv.h"
17
 
#include <mystrings/m_string.h>
 
17
#include <m_string.h>
18
18
 
19
19
/*
20
20
  Formats a filename with possible replace of directory of extension
24
24
*/
25
25
 
26
26
char * fn_format(char * to, const char *name, const char *dir,
27
 
                    const char *extension, uint32_t flag)
 
27
                    const char *extension, uint flag)
28
28
{
29
 
  char dev[FN_REFLEN], buff[FN_REFLEN], *pos;
30
 
  const char *startpos = name;
 
29
  char dev[FN_REFLEN], buff[FN_REFLEN], *pos, *startpos;
31
30
  const char *ext;
32
31
  register size_t length;
33
32
  size_t dev_length;
 
33
  DBUG_ENTER("fn_format");
 
34
  DBUG_PRINT("enter",("name: %s  dir: %s  extension: %s  flag: %d",
 
35
                       name,dir,extension,flag));
34
36
 
35
37
  /* Copy and skip directory */
36
 
  name+=(length=dirname_part(dev, startpos, &dev_length));
 
38
  name+=(length=dirname_part(dev, (startpos=(char *) name), &dev_length));
37
39
  if (length == 0 || (flag & MY_REPLACE_DIR))
38
40
  {
39
41
    /* Use given directory */
40
 
    convert_dirname(dev,dir,NULL);              /* Fix to this OS */
 
42
    convert_dirname(dev,dir,NullS);             /* Fix to this OS */
41
43
  }
42
44
  else if ((flag & MY_RELATIVE_PATH) && !test_if_hard_path(dev))
43
45
  {
44
46
    /* Put 'dir' before the given path */
45
 
    strncpy(buff,dev,sizeof(buff)-1);
46
 
    pos=convert_dirname(dev,dir,NULL);
47
 
    strncpy(pos,buff,sizeof(buff)-1- (int) (pos-dev));
 
47
    strmake(buff,dev,sizeof(buff)-1);
 
48
    pos=convert_dirname(dev,dir,NullS);
 
49
    strmake(pos,buff,sizeof(buff)-1- (int) (pos-dev));
48
50
  }
49
51
 
 
52
  if (flag & MY_PACK_FILENAME)
 
53
    pack_dirname(dev,dev);                      /* Put in ./.. and ~/.. */
50
54
  if (flag & MY_UNPACK_FILENAME)
51
55
    (void) unpack_dirname(dev,dev);             /* Replace ~/.. with dir */
52
56
 
53
57
  if (!(flag & MY_APPEND_EXT) &&
54
 
      (pos= (char*) strchr(name,FN_EXTCHAR)) != NULL)
 
58
      (pos= (char*) strchr(name,FN_EXTCHAR)) != NullS)
55
59
  {
56
60
    if ((flag & MY_REPLACE_EXT) == 0)           /* If we should keep old ext */
57
61
    {
75
79
    /* To long path, return original or NULL */
76
80
    size_t tmp_length;
77
81
    if (flag & MY_SAFE_PATH)
78
 
      return NULL;
79
 
    tmp_length= cmin(strlength(startpos), FN_REFLEN-1);
80
 
    strncpy(to,startpos,tmp_length);
81
 
    to[tmp_length]= '\0';
 
82
      return NullS;
 
83
    tmp_length= strlength(startpos);
 
84
    DBUG_PRINT("error",("dev: '%s'  ext: '%s'  length: %u",dev,ext,
 
85
                        (uint) length));
 
86
    (void) strmake(to,startpos,min(tmp_length,FN_REFLEN-1));
82
87
  }
83
88
  else
84
89
  {
85
90
    if (to == startpos)
86
91
    {
87
 
      memmove(buff, name, length); /* Save name for last copy */
 
92
      bmove(buff,(uchar*) name,length);         /* Save name for last copy */
88
93
      name=buff;
89
94
    }
90
 
    char *tmp= strcpy(to, dev) + strlen(dev);
91
 
    pos= strncpy(tmp,name,length) + length;
92
 
    (void) strcpy(pos,ext);                     /* Don't convert extension */
 
95
    pos=strmake(strmov(to,dev),name,length);
 
96
    (void) strmov(pos,ext);                     /* Don't convert extension */
93
97
  }
94
98
  /*
95
99
    If MY_RETURN_REAL_PATH and MY_RESOLVE_SYMLINK is given, only do
100
104
                                   MY_RESOLVE_LINK: 0));
101
105
  else if (flag & MY_RESOLVE_SYMLINKS)
102
106
  {
103
 
    strcpy(buff,to);
 
107
    strmov(buff,to);
104
108
    (void) my_readlink(to, buff, MYF(0));
105
109
  }
106
 
  return(to);
 
110
  DBUG_RETURN(to);
107
111
} /* fn_format */
108
112
 
109
113
 
116
120
{
117
121
  register const char * pos;
118
122
  register const char * found;
 
123
  DBUG_ENTER("strlength");
119
124
 
120
125
  pos= found= str;
121
126
 
133
138
    found=pos;
134
139
    while (*++pos == ' ') {};
135
140
  }
136
 
  return((size_t) (found - str));
 
141
  DBUG_RETURN((size_t) (found - str));
137
142
} /* strlength */