1
0
Fork 0

Improve compliance when printing drive labels

This commit is contained in:
krcroft 2020-01-19 21:53:42 -08:00 committed by Patryk Obara
parent 508d338c27
commit c7484ceaaa
5 changed files with 31 additions and 8 deletions

View file

@ -30,6 +30,7 @@
bool WildFileCmp(const char * file, const char * wild);
void Set_Label(char const * const input, char * const output, bool cdrom);
std::string To_Label(const char* name);
class DriveManager {
public:

View file

@ -93,5 +93,7 @@ Bits ConvHexWord(char * word);
void trim(std::string& str);
void upcase(std::string &str);
void lowcase(std::string &str);
void strip_punctuation(std::string &str);
#endif

View file

@ -144,16 +144,13 @@ public:
if (ret) {
dta.GetResult(name,size,date,time,attr);
DOS_FindNext(); //Mark entry as invalid
} else name[0] = 0;
/* Change 8.3 to 11.0 */
char* dot = strchr(name,'.');
if(dot && (dot - name == 8) ) {
name[8] = name[9];name[9] = name[10];name[10] = name[11];name[11] = 0;
} else {
name[0] = 0;
}
std::string label = To_Label(name);
root[1] = 0; //This way, the format string can be reused.
WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_FORMAT"),root, Drives[d]->GetInfo(),name);
WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_FORMAT"),
root, Drives[d]->GetInfo(), label.c_str());
}
dos.dta(save_dta);
}

View file

@ -73,6 +73,19 @@ checkext:
return true;
}
std::string To_Label(const char* name) {
// Reformat the name per the DOS label specification:
// - Upper-case, up to 11 ASCII characters
// - Internal spaces allowed but no: tabs ? / \ | . , ; : + = [ ] < > " '
std::string label(name);
trim(label); // strip front-and-back white-space
strip_punctuation(label); // strip all punctuation
label.resize(11); // collapse remainder to (at-most) 11 chars
upcase(label);
return label;
}
void Set_Label(char const * const input, char * const output, bool cdrom) {
Bitu togo = 8;
Bitu vnamePos = 0;

View file

@ -21,6 +21,7 @@
#include <assert.h>
#include <cctype>
#include <ctype.h>
#include <functional>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@ -51,6 +52,15 @@ void trim(std::string &str) {
if (loc != std::string::npos) str.erase(loc+1);
}
void strip_punctuation(std::string &str) {
str.erase(
std::remove_if(
str.begin(),
str.end(),
[](unsigned char c){ return std::ispunct(c); }),
str.end());
}
/*
Ripped some source from freedos for this one.