+static void set_str(char *to, const char *from, size_t count)
+{
+ size_t i, j, len;
+
+ /* strip trailing whitespace */
+ len = strnlen(from, count);
+ while (isspace(from[len-1]))
+ len--;
+
+ /* strip leading whitespace */
+ i = 0;
+ while (isspace(from[i]) && (i < len))
+ i++;
+
+ j = 0;
+ while (i < len) {
+ /* substitute multiple whitespace */
+ if (isspace(from[i])) {
+ while (isspace(from[i]))
+ i++;
+ to[j++] = '_';
+ }
+ /* skip chars */
+ if (from[i] == '/') {
+ i++;
+ continue;
+ }
+ to[j++] = from[i++];
+ }
+ to[j] = '\0';
+}
+
+static void set_type(char *to, const char *from, size_t len)
+{
+ int type_num;
+ char *eptr;
+ char *type = "generic";
+
+ type_num = strtoul(from, &eptr, 0);
+ if (eptr != from) {
+ switch (type_num) {
+ case 0:
+ type = "disk";
+ break;
+ case 1:
+ type = "tape";
+ break;
+ case 4:
+ type = "optical";
+ break;
+ case 5:
+ type = "cd";
+ break;
+ case 7:
+ type = "optical";
+ break;
+ case 0xe:
+ type = "disk";
+ break;
+ case 0xf:
+ type = "optical";
+ break;
+ default:
+ break;
+ }
+ }
+ strncpy(to, type, len);
+ to[len-1] = '\0';
+}
+