Rev 4419 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4419 | Rev 4420 | ||
---|---|---|---|
Line 112... | Line 112... | ||
112 | return true; |
112 | return true; |
113 | } |
113 | } |
114 | 114 | ||
115 | void fat_dentry_name_get(const fat_dentry_t *d, char *buf) |
115 | void fat_dentry_name_get(const fat_dentry_t *d, char *buf) |
116 | { |
116 | { |
117 | int i; |
117 | unsigned int i; |
118 | 118 | ||
119 | for (i = 0; i < FAT_NAME_LEN; i++) { |
119 | for (i = 0; i < FAT_NAME_LEN; i++) { |
120 | if (d->name[i] == FAT_PAD) |
120 | if (d->name[i] == FAT_PAD) |
121 | break; |
121 | break; |
- | 122 | ||
122 | if (d->name[i] == FAT_DENTRY_E5_ESC) |
123 | if (d->name[i] == FAT_DENTRY_E5_ESC) |
123 | *buf++ = 0xe5; |
124 | *buf++ = 0xe5; |
- | 125 | else { |
|
- | 126 | if (d->lcase & FAT_LCASE_LOWER_NAME) |
|
- | 127 | *buf++ = tolower(d->name[i]); |
|
124 | else |
128 | else |
125 | *buf++ = d->name[i]; |
129 | *buf++ = d->name[i]; |
- | 130 | } |
|
126 | } |
131 | } |
- | 132 | ||
127 | if (d->ext[0] != FAT_PAD) |
133 | if (d->ext[0] != FAT_PAD) |
128 | *buf++ = '.'; |
134 | *buf++ = '.'; |
- | 135 | ||
129 | for (i = 0; i < FAT_EXT_LEN; i++) { |
136 | for (i = 0; i < FAT_EXT_LEN; i++) { |
130 | if (d->ext[i] == FAT_PAD) { |
137 | if (d->ext[i] == FAT_PAD) { |
131 | *buf = '\0'; |
138 | *buf = '\0'; |
132 | return; |
139 | return; |
133 | } |
140 | } |
- | 141 | ||
134 | if (d->ext[i] == FAT_DENTRY_E5_ESC) |
142 | if (d->ext[i] == FAT_DENTRY_E5_ESC) |
135 | *buf++ = 0xe5; |
143 | *buf++ = 0xe5; |
- | 144 | else { |
|
- | 145 | if (d->lcase & FAT_LCASE_LOWER_EXT) |
|
- | 146 | *buf++ = tolower(d->ext[i]); |
|
136 | else |
147 | else |
137 | *buf++ = d->ext[i]; |
148 | *buf++ = d->ext[i]; |
- | 149 | } |
|
138 | } |
150 | } |
- | 151 | ||
139 | *buf = '\0'; |
152 | *buf = '\0'; |
140 | } |
153 | } |
141 | 154 | ||
142 | void fat_dentry_name_set(fat_dentry_t *d, const char *name) |
155 | void fat_dentry_name_set(fat_dentry_t *d, const char *name) |
143 | { |
156 | { |
144 | int i; |
157 | unsigned int i; |
145 | const char fake_ext[] = " "; |
158 | const char fake_ext[] = " "; |
146 | - | ||
- | 159 | bool lower_name = true; |
|
- | 160 | bool lower_ext = true; |
|
147 | 161 | ||
148 | for (i = 0; i < FAT_NAME_LEN; i++) { |
162 | for (i = 0; i < FAT_NAME_LEN; i++) { |
149 | switch ((uint8_t) *name) { |
163 | switch ((uint8_t) *name) { |
150 | case 0xe5: |
164 | case 0xe5: |
151 | d->name[i] = FAT_DENTRY_E5_ESC; |
165 | d->name[i] = FAT_DENTRY_E5_ESC; |
152 | name++; |
166 | name++; |
Line 154... | Line 168... | ||
154 | case '\0': |
168 | case '\0': |
155 | case '.': |
169 | case '.': |
156 | d->name[i] = FAT_PAD; |
170 | d->name[i] = FAT_PAD; |
157 | break; |
171 | break; |
158 | default: |
172 | default: |
- | 173 | if (isalpha(*name)) { |
|
- | 174 | if (!islower(*name)) |
|
- | 175 | lower_name = false; |
|
- | 176 | } |
|
- | 177 | ||
159 | d->name[i] = toupper(*name++); |
178 | d->name[i] = toupper(*name++); |
160 | break; |
179 | break; |
161 | } |
180 | } |
162 | } |
181 | } |
- | 182 | ||
163 | if (*name++ != '.') |
183 | if (*name++ != '.') |
164 | name = fake_ext; |
184 | name = fake_ext; |
- | 185 | ||
165 | for (i = 0; i < FAT_EXT_LEN; i++) { |
186 | for (i = 0; i < FAT_EXT_LEN; i++) { |
166 | switch ((uint8_t) *name) { |
187 | switch ((uint8_t) *name) { |
167 | case 0xe5: |
188 | case 0xe5: |
168 | d->ext[i] = FAT_DENTRY_E5_ESC; |
189 | d->ext[i] = FAT_DENTRY_E5_ESC; |
169 | name++; |
190 | name++; |
170 | break; |
191 | break; |
171 | case '\0': |
192 | case '\0': |
172 | d->ext[i] = FAT_PAD; |
193 | d->ext[i] = FAT_PAD; |
173 | break; |
194 | break; |
174 | default: |
195 | default: |
- | 196 | if (isalpha(*name)) { |
|
- | 197 | if (!islower(*name)) |
|
- | 198 | lower_ext = false; |
|
- | 199 | } |
|
- | 200 | ||
175 | d->ext[i] = toupper(*name++); |
201 | d->ext[i] = toupper(*name++); |
176 | break; |
202 | break; |
177 | } |
203 | } |
178 | } |
204 | } |
- | 205 | ||
- | 206 | if (lower_name) |
|
- | 207 | d->lcase |= FAT_LCASE_LOWER_NAME; |
|
- | 208 | else |
|
- | 209 | d->lcase &= ~FAT_LCASE_LOWER_NAME; |
|
- | 210 | ||
- | 211 | if (lower_ext) |
|
- | 212 | d->lcase |= FAT_LCASE_LOWER_EXT; |
|
- | 213 | else |
|
- | 214 | d->lcase &= ~FAT_LCASE_LOWER_EXT; |
|
179 | } |
215 | } |
180 | 216 | ||
181 | fat_dentry_clsf_t fat_classify_dentry(const fat_dentry_t *d) |
217 | fat_dentry_clsf_t fat_classify_dentry(const fat_dentry_t *d) |
182 | { |
218 | { |
183 | if (d->attr & FAT_ATTR_VOLLABEL) { |
219 | if (d->attr & FAT_ATTR_VOLLABEL) { |