Ticket #12562: addattr_main.cpp.patch
File addattr_main.cpp.patch, 3.6 KB (added by , 9 years ago) |
---|
-
main.
old new 90 90 } 91 91 } 92 92 93 // type didn't show up - in this case, we parse the string94 // as number and use it directly as type code93 // type didn't show up - in this case, we try to parse 94 // the string as number and use it directly as type code 95 95 96 if (sscanf(string, "%" B_SCN u32, _result) == 1)96 if (sscanf(string, "%" B_SCNi32, _result) == 1) 97 97 return B_OK; 98 98 99 // if that didn't work, try the string as a char-type-code 100 // enclosed in single quotes 99 101 uchar type[4]; 100 102 if (sscanf(string, "'%c%c%c%c'", &type[0], &type[1], &type[2], &type[3]) == 4) { 101 103 *_result = (type[0] << 24) | (type[1] << 16) | (type[2] << 8) | type[3]; … … 109 111 void 110 112 usage(int returnValue) 111 113 { 112 fprintf(stderr, "usage: %s [-t type ] [ -P ] attr value file1 [file2...]\n"113 " or: %s [-f value-from-file] [-t type ] [ -P ] attr file1 [file2...]\n\n"114 fprintf(stderr, "usage: %s [-t type|-c code] [ -P ] attr value file1 [file2...]\n" 115 " or: %s [-f value-from-file] [-t type|-c code] [ -P ] attr file1 [file2...]\n\n" 114 116 "\t-P : Don't resolve links\n" 115 "\tType is one of:\n" 116 "\t\tstring, mime, int, llong, float, double, bool, time, icon, raw\n" 117 "\t\tor a numeric value (ie. 0x1234, 42, 'ABCD', ...)\n" 118 "\tThe default is \"string\"\n", kProgramName, kProgramName); 117 "\tThe '-t' and '-c' options are alternatives; use one or the other.\n" 118 "\ttype is one of:\n" 119 "\t\tstring, mime, int, int32, uint32, llong, int64, uint64,\n" 120 "\t\tfloat, double, bool, icon, time, raw\n" 121 "\t\tor a numeric value (ie. 0x1234, 42, ...),\n" 122 "\t\tor an escape-quoted type code, eg. \\'MICN\\'\n" 123 "\tThe default is \"string\"\n" 124 "\tcode is a four-char type ID (eg. MICN)\n", kProgramName, kProgramName); 119 125 120 126 exit(returnValue); 121 127 } … … 126 132 { 127 133 fprintf(stderr, "%s: attribute type \"%s\" is not valid\n", kProgramName, 128 134 attrTypeName); 129 fprintf(stderr, "\tTry one of: string, mime, int, llong, float, double,\n"); 130 fprintf(stderr, "\t\tbool, time, icon, raw, or a numeric value (ie. 0x1234, 42, 'ABCD'" 131 ", ...)\n"); 135 fprintf(stderr, "\tTry one of: string, mime, int, llong, float, double,\n" 136 "\t\tbool, icon, time, raw, or a numeric value (ie. 0x1234, 42, ...),\n" 137 "\t\tor a quoted type code, eg.: \\'MICN\\'\n" 138 "\t\tOr enter the actual type code with the '-c' option\n"); 139 140 exit(1); 141 } 142 143 144 void 145 invalidTypeCode(const char* attrTypeName) 146 { 147 fprintf(stderr, "%s: attribute type code \"%s\" is not valid\n", kProgramName, 148 attrTypeName); 149 fprintf(stderr, "\tIt must be exactly four characters\n"); 132 150 133 151 exit(1); 134 152 } … … 139 157 { 140 158 fprintf(stderr, "%s: attribute value \"%s\" is not valid\n", kProgramName, 141 159 value); 142 fprintf(stderr, "\tBool accepts: 0, f, false, disabled, off,\n" );143 fprintf(stderr,"\t\t1, t, true, enabled, on\n");160 fprintf(stderr, "\tBool accepts: 0, f, false, disabled, off,\n" 161 "\t\t1, t, true, enabled, on\n"); 144 162 145 163 exit(1); 146 164 } … … 155 173 bool resolveLinks = true; 156 174 157 175 int c; 158 while ((c = getopt_long(argc, argv, "hf:t: P", kLongOptions, NULL)) != -1) {176 while ((c = getopt_long(argc, argv, "hf:t:c:P", kLongOptions, NULL)) != -1) { 159 177 switch (c) { 160 178 case 0: 161 179 break; … … 202 220 if (typeForString(optarg, &attrType) != B_OK) 203 221 invalidAttrType(optarg); 204 222 break; 223 case 'c': 224 if (strlen(optarg) == 4) { 225 // Get the type code directly 226 char code[] = "' '"; 227 strncpy(code+1, optarg, 4); 228 if (typeForString(code, &attrType) == B_OK) 229 break; 230 } 231 invalidTypeCode(optarg); // exits... 205 232 case 'P': 206 233 resolveLinks = false; 207 234 break;