- char *temp;
- char *string = *orig_string;
-
- /* eat any whitespace */
- while (isspace(*string))
- ++string;
-
- /* split based on '=' */
- temp = strsep(&string, "=");
- *left = temp;
-
- /* take the right side and strip off the '"' */
- while (isspace(*string))
- ++string;
- if (*string == '"')
- ++string;
- temp = strsep(&string, "\"");
- *right = temp;
- *orig_string = string;
-
- return 0;
+ char name[NAME_SIZE];
+ char temp[NAME_SIZE];
+ char *tail;
+ char *pos;
+ char *pos2;
+ char *pos3;
+ int num;
+
+ while (1) {
+ num = 0;
+ pos = strchr(string, '%');
+
+ if (pos) {
+ *pos = '\0';
+ tail = pos+1;
+ if (isdigit(tail[0])) {
+ num = (int) strtoul(&pos[1], &tail, 10);
+ if (tail == NULL) {
+ dbg("format parsing error '%s'", pos+1);
+ break;
+ }
+ }
+ strfieldcpy(name, tail+1);
+
+ switch (tail[0]) {
+ case 'b':
+ if (strlen(udev->bus_id) == 0)
+ break;
+ strcat(pos, udev->bus_id);
+ dbg("substitute bus_id '%s'", udev->bus_id);
+ break;
+ case 'k':
+ if (strlen(udev->kernel_name) == 0)
+ break;
+ strcat(pos, udev->kernel_name);
+ dbg("substitute kernel name '%s'", udev->kernel_name);
+ break;
+ case 'n':
+ if (strlen(udev->kernel_number) == 0)
+ break;
+ strcat(pos, udev->kernel_number);
+ dbg("substitute kernel number '%s'", udev->kernel_number);
+ break;
+ case 'D':
+ if (strlen(udev->kernel_number) == 0) {
+ strcat(pos, "disc");
+ dbg("substitute devfs disc");
+ break;
+ }
+ strcat(pos, "part");
+ strcat(pos, udev->kernel_number);
+ dbg("substitute devfs part '%s'", udev->kernel_number);
+ break;
+ case 'm':
+ sprintf(pos, "%u", udev->minor);
+ dbg("substitute minor number '%u'", udev->minor);
+ break;
+ case 'M':
+ sprintf(pos, "%u", udev->major);
+ dbg("substitute major number '%u'", udev->major);
+ break;
+ case 'c':
+ if (strlen(udev->program_result) == 0)
+ break;
+ if (num) {
+ /* get part of return string */
+ strncpy(temp, udev->program_result, sizeof(temp));
+ pos2 = temp;
+ while (num) {
+ num--;
+ pos3 = strsep(&pos2, " ");
+ if (pos3 == NULL) {
+ dbg("requested part of result string not found");
+ break;
+ }
+ }
+ if (pos3) {
+ strcat(pos, pos3);
+ dbg("substitute part of result string '%s'", pos3);
+ }
+ } else {
+ strcat(pos, udev->program_result);
+ dbg("substitute result string '%s'", udev->program_result);
+ }
+ break;
+ default:
+ dbg("unknown substitution type '%%%c'", pos[1]);
+ break;
+ }
+ strcat(string, name);
+ } else
+ break;
+ }