Author: axeld Date: 2009-12-02 11:18:42 +0100 (Wed, 02 Dec 2009) New Revision: 34438 Changeset: http://dev.haiku-os.org/changeset/34438/haiku Modified: haiku/trunk/src/bin/Jamfile haiku/trunk/src/bin/catattr.cpp haiku/trunk/src/bin/listattr.cpp Log: * Added some more types that are printed as string in catattr, and listattr. * catattr no longer pretends B_MIME_STRING to be of type string. * Added message output for both listattr, and catattr. Modified: haiku/trunk/src/bin/Jamfile =================================================================== --- haiku/trunk/src/bin/Jamfile 2009-12-02 09:21:28 UTC (rev 34437) +++ haiku/trunk/src/bin/Jamfile 2009-12-02 10:18:42 UTC (rev 34438) @@ -23,7 +23,6 @@ StdBinCommands badblocks.c cal.c - catattr.cpp chop.c clear.c clockconfig.c @@ -77,6 +76,7 @@ # standard commands that need libbe.so StdBinCommands beep.cpp + catattr.cpp checkfs.cpp clipboard.cpp df.cpp Modified: haiku/trunk/src/bin/catattr.cpp =================================================================== --- haiku/trunk/src/bin/catattr.cpp 2009-12-02 09:21:28 UTC (rev 34437) +++ haiku/trunk/src/bin/catattr.cpp 2009-12-02 10:18:42 UTC (rev 34438) @@ -1,6 +1,6 @@ /* * Copyright 2005, Stephan Aßmus, superstippi@xxxxxxxxxxxxxxxx - * Copyright 2004, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx + * Copyright 2004-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx * Copyright 2002, Sebastian Nozzi. * * Distributed under the terms of the MIT license. @@ -20,8 +20,7 @@ #include <unistd.h> -/** Used to present the characters in the raw data view */ - +/*! Used to present the characters in the raw data view */ static void putCharOrDot(uchar c) { @@ -29,12 +28,11 @@ } -/** Dumps the contents of the attribute in the form of - * raw data. This view is used for the type B_RAW_DATA_TYPE, - * for custom types and for any type that is not directly - * supported by the utility "addattr" - */ - +/*! Dumps the contents of the attribute in the form of + raw data. This view is used for the type B_RAW_DATA_TYPE, + for custom types and for any type that is not directly + supported by the utility "addattr" +*/ static void dumpRawData(const char *buffer, size_t size) { @@ -82,8 +80,11 @@ // limit size of the attribute, only the first 64k will make it on screen off_t size = info.size; - if (size > 64 * 1024) + bool cut = false; + if (size > 64 * 1024) { size = 64 * 1024; + cut = true; + } char* buffer = (char*)malloc(size); if (!buffer) { @@ -98,7 +99,8 @@ } if (bytesRead != size) { - fprintf(stderr, "Could only read %ld bytes from attribute!\n", bytesRead); + fprintf(stderr, "Could only read %ld bytes from attribute!\n", + bytesRead); free(buffer); return B_ERROR; } @@ -112,21 +114,28 @@ // check for write error if (written < bytesRead) { if (written >= 0) { - fprintf(stderr, "Could only write %ld bytes to stream!\n", written); + fprintf(stderr, "Could only write %ld bytes to stream!\n", + written); written = B_ERROR; - } else - fprintf(stderr, "Failed to write to stream: %s\n", strerror(written)); + } else { + fprintf(stderr, "Failed to write to stream: %s\n", + strerror(written)); + } break; } // read next chunk of data at pos pos += bytesRead; - bytesRead = fs_read_attr(fd, attribute, info.type, pos, buffer, size); + bytesRead = fs_read_attr(fd, attribute, info.type, pos, buffer, + size); // check for read error if (bytesRead < size && pos + bytesRead < info.size) { - if (bytesRead >= 0) - fprintf(stderr, "Could only read %ld bytes from attribute!\n", bytesRead); - else - fprintf(stderr, "Failed to read from attribute: %s\n", strerror(bytesRead)); + if (bytesRead >= 0) { + fprintf(stderr, "Could only read %ld bytes from " + "attribute!\n", bytesRead); + } else { + fprintf(stderr, "Failed to read from attribute: %s\n", + strerror(bytesRead)); + } written = B_ERROR; break; } @@ -172,10 +181,31 @@ printf("%s : bool : %d\n", fileName, *((unsigned char *)buffer)); break; case B_STRING_TYPE: - case B_MIME_STRING_TYPE: printf("%s : string : %s\n", fileName, buffer); break; + case B_MIME_STRING_TYPE: + case 'MSIG': + case 'MSDC': + case 'MPTH': + printf("%s : '%c%c%c%c' : %s\n", fileName, + (int)((info.type >> 24) & 0xff), + (int)((info.type >> 16) & 0xff), + (int)((info.type >> 8) & 0xff), (int)(info.type & 0xff), + buffer); + break; + + case B_MESSAGE_TYPE: + { + BMessage message; + if (!cut && message.Unflatten(buffer) == B_OK) { + printf("%s : message :\n", fileName); + message.PrintToStream(); + break; + } + // supposed to fall through + } + default: // The rest of the attributes types are displayed as raw data printf("%s : raw_data : \n", fileName); Modified: haiku/trunk/src/bin/listattr.cpp =================================================================== --- haiku/trunk/src/bin/listattr.cpp 2009-12-02 09:21:28 UTC (rev 34437) +++ haiku/trunk/src/bin/listattr.cpp 2009-12-02 10:18:42 UTC (rev 34438) @@ -62,9 +62,12 @@ // limit size of the attribute, only the first kLimit byte will make it on // screen int kLimit = 256; + bool cut = false; off_t size = info.size; - if (size > kLimit) + if (size > kLimit) { size = kLimit; + cut = true; + } char buffer[kLimit]; ssize_t bytesRead = node.ReadAttr(attribute, info.type, 0, buffer, size); @@ -110,9 +113,24 @@ break; case B_STRING_TYPE: case B_MIME_STRING_TYPE: + case 'MSIG': + case 'MSDC': + case 'MPTH': printf("%s\n", buffer); break; + case B_MESSAGE_TYPE: + { + BMessage message; + if (!cut && message.Unflatten(buffer) == B_OK) { + putchar('\n'); + message.PrintToStream(); + putchar('\n'); + break; + } + // supposed to fall through + } + default: // The rest of the attributes types are displayed as raw data putchar('\n');