Revision: 4231
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4231&view=rev
Author:   hofman
Date:     2008-07-16 23:59:49 +0000 (Wed, 16 Jul 2008)

Log Message:
-----------
define macros for some strings

Modified Paths:
--------------
    trunk/SkimNotes/SKNExtendedAttributeManager.m
    trunk/SkimNotes/skimnotes.m

Modified: trunk/SkimNotes/SKNExtendedAttributeManager.m
===================================================================
--- trunk/SkimNotes/SKNExtendedAttributeManager.m       2008-07-16 23:58:56 UTC 
(rev 4230)
+++ trunk/SkimNotes/SKNExtendedAttributeManager.m       2008-07-16 23:59:49 UTC 
(rev 4231)
@@ -36,6 +36,11 @@
 #define UNIQUE_VALUE            [[NSProcessInfo processInfo] 
globallyUniqueString]
 #define PREFIX                  @"net_sourceforge_skim-app"
 
+#define NAME_SEPARATOR          @"_"
+#define UNIQUE_KEY_SUFFIX       @"_unique_key"
+#define WRAPPER_KEY_SUFFIX      @"_has_wrapper"
+#define FRAGMENTS_KEY_SUFFIX    @"_number_of_fragments"
+
 static NSString *SKNErrorDomain = @"SKNErrorDomain";
 
 @interface SKNExtendedAttributeManager (SKNPrivate)
@@ -84,10 +89,10 @@
 {
     if (self = [super init]) {
         if (prefix) {
-            namePrefix = [[prefix stringByAppendingString:@"_"] retain];
-            uniqueKey = [[prefix stringByAppendingString:@"_unique_key"] 
retain];
-            wrapperKey = [[prefix stringByAppendingString:@"_has_wrapper"] 
retain];
-            fragmentsKey = [[prefix 
stringByAppendingString:@"_number_of_fragments"] retain];
+            namePrefix = [[prefix stringByAppendingString:NAME_SEPARATOR] 
retain];
+            uniqueKey = [[prefix stringByAppendingString:UNIQUE_KEY_SUFFIX] 
retain];
+            wrapperKey = [[prefix stringByAppendingString:WRAPPER_KEY_SUFFIX] 
retain];
+            fragmentsKey = [[prefix 
stringByAppendingString:FRAGMENTS_KEY_SUFFIX] retain];
         } else if (sharedNoSplitManager) {
             [self release];
             self = [sharedNoSplitManager retain];
@@ -247,15 +252,15 @@
         BOOL success = (nil != uniqueValue && numberOfFragments > 0);
         
         if (success == NO)
-            NSLog(@"failed to read unique key %@ for %u fragments from 
property list.", uniqueKey, numberOfFragments);
+            NSLog(@"failed to read unique key %@ for %lu fragments from 
property list.", uniqueKey, (long)numberOfFragments);
         
         // reassemble the original data object
         for (i = 0; success && i < numberOfFragments; i++) {
             NSError *tmpError = nil;
-            name = [NSString stringWithFormat:@"[EMAIL PROTECTED]", 
uniqueValue, i];
+            name = [NSString stringWithFormat:@"[EMAIL PROTECTED]@%lu", 
uniqueValue, NAME_SEPARATOR, (long)i];
             subdata = [self extendedAttributeNamed:name atPath:path 
traverseLink:follow error:&tmpError];
             if (nil == subdata) {
-                NSLog(@"failed to find subattribute %@ of %u for attribute 
named [EMAIL PROTECTED] %@", name, numberOfFragments, attr, [tmpError 
localizedDescription]);
+                NSLog(@"failed to find subattribute %@ of %lu for attribute 
named [EMAIL PROTECTED] %@", name, (long)numberOfFragments, attr, [tmpError 
localizedDescription]);
                 success = NO;
             } else {
                 [buffer appendData:subdata];
@@ -338,14 +343,14 @@
         const char *valuePtr = [value bytes];
         
         for (j = 0; success && j < numberOfFragments; j++) {
-            name = [[NSString alloc] initWithFormat:@"[EMAIL PROTECTED]", 
uniqueValue, j];
+            name = [[NSString alloc] initWithFormat:@"[EMAIL PROTECTED]@%lu", 
uniqueValue, NAME_SEPARATOR, (long)j];
             
             char *subdataPtr = (char *)&valuePtr[j * MAX_XATTR_LENGTH];
             size_t subdataLen = j == numberOfFragments - 1 ? ([value length] - 
j * MAX_XATTR_LENGTH) : MAX_XATTR_LENGTH;
             
             // could recurse here, but it's more efficient to use the 
variables we already have
             if (setxattr(fsPath, [name UTF8String], subdataPtr, subdataLen, 0, 
xopts)) {
-                NSLog(@"full data length of note named %@ was %d, subdata 
length was %d (failed on pass %d)", name, [value length], subdataLen, j);
+                NSLog(@"full data length of note named %@ was %lu, subdata 
length was %lu (failed on pass %lu)", name, (long)[value length], 
(long)subdataLen, (long)j);
             }
             [name release];
         }
@@ -427,7 +432,7 @@
                 
                 // remove the sub attributes
                 for (i = 0; i < numberOfFragments; i++) {
-                    name = [NSString stringWithFormat:@"[EMAIL PROTECTED]", 
uniqueValue, i];
+                    name = [NSString stringWithFormat:@"[EMAIL 
PROTECTED]@%lu", uniqueValue, NAME_SEPARATOR, (long)i];
                     const char *subAttrName = [name UTF8String];
                     status = removexattr(fsPath, subAttrName, xopts);
                     if (status == -1) {

Modified: trunk/SkimNotes/skimnotes.m
===================================================================
--- trunk/SkimNotes/skimnotes.m 2008-07-16 23:58:56 UTC (rev 4230)
+++ trunk/SkimNotes/skimnotes.m 2008-07-16 23:59:49 UTC (rev 4231)
@@ -2,8 +2,8 @@
 #import "SKNExtendedAttributeManager.h"
 #import "SKNAgentListener.h"
 
-#define SKIM_NOTES_KEY @"net_sourceforge_skim-app_notes"
-#define SKIM_RTF_NOTES_KEY @"net_sourceforge_skim-app_rtf_notes"
+#define SKIM_NOTES_KEY      @"net_sourceforge_skim-app_notes"
+#define SKIM_RTF_NOTES_KEY  @"net_sourceforge_skim-app_rtf_notes"
 #define SKIM_TEXT_NOTES_KEY @"net_sourceforge_skim-app_text_notes"
 
 static char *usageStr = "Usage:\n skimnotes set PDF_FILE [SKIM_FILE|-]\n 
skimnotes get [-format skim|text|rtf] PDF_FILE 
[SKIM_FILE|RTF_FILE|TEXT_FILE|-]\n skimnotes remove PDF_FILE\n skimnotes agent 
[SERVER_NAME]\n skimnotes protocol\n skimnotes help [VERB]\n skimnotes version";
@@ -19,6 +19,33 @@
 
 static char *protocolStr = "@protocol SKNAgentListenerProtocol\n- (bycopy 
NSData *)SkimNotesAtPath:(in bycopy NSString *)aFile;\n- (bycopy NSData 
*)RTFNotesAtPath:(in bycopy NSString *)aFile;\n- (bycopy NSData 
*)textNotesAtPath:(in bycopy NSString *)aFile 
encoding:(NSStringEncoding)encoding;[EMAIL PROTECTED]";
 
+#define ACTION_GET_STRING       @"get"
+#define ACTION_SET_STRING       @"set"
+#define ACTION_REMOVE_STRING    @"remove"
+#define ACTION_AGENT_STRING     @"agent"
+#define ACTION_PROTOCOL_STRING  @"protocol"
+#define ACTION_VERSION_STRING   @"version"
+#define ACTION_HELP_STRING      @"help"
+
+#define FORMAT_OPTION_STRING    @"-format"
+
+#define FORMAT_SKIM_STRING  @"skim"
+#define FORMAT_TEXT_STRING  @"text"
+#define FORMAT_TXT_STRING   @"txt"
+#define FORMAT_RTF_STRING   @"rtf"
+
+#define PDF_EXTENSION   @"pdf"
+#define SKIM_EXTENSION  @"skim"
+#define TXT_EXTENSION   @"txt"
+#define TEXT_EXTENSION  @"text"
+#define RTF_EXTENSION   @"rtf"
+
+#define STD_IN_OUT_FILE @"-"
+
+#define WRITE_OUT(msg)         fprintf(stdout, "%s\n", msg)
+#define WRITE_OUT_VERSION(msg) fprintf(stdout, "%s\n%s\n", msg, versionStr)
+#define WRITE_ERROR            fprintf(stderr, "%s\n%s\n", usageStr, 
versionStr)
+
 enum {
     SKNActionUnknown,
     SKNActionGet,
@@ -38,26 +65,26 @@
 };
 
 static NSInteger SKNActionForName(NSString *actionString) {
-    if ([actionString caseInsensitiveCompare:@"get"] == NSOrderedSame)
+    if ([actionString caseInsensitiveCompare:ACTION_GET_STRING] == 
NSOrderedSame)
         return SKNActionGet;
-    else if ([actionString caseInsensitiveCompare:@"set"] == NSOrderedSame)
+    else if ([actionString caseInsensitiveCompare:ACTION_SET_STRING] == 
NSOrderedSame)
         return SKNActionSet;
-    else if ([actionString caseInsensitiveCompare:@"remove"] == NSOrderedSame)
+    else if ([actionString caseInsensitiveCompare:ACTION_REMOVE_STRING] == 
NSOrderedSame)
         return SKNActionRemove;
-    else if ([actionString caseInsensitiveCompare:@"agent"] == NSOrderedSame)
+    else if ([actionString caseInsensitiveCompare:ACTION_AGENT_STRING] == 
NSOrderedSame)
         return SKNActionAgent;
-    else if ([actionString caseInsensitiveCompare:@"protocol"] == 
NSOrderedSame)
+    else if ([actionString caseInsensitiveCompare:ACTION_PROTOCOL_STRING] == 
NSOrderedSame)
         return SKNActionProtocol;
-    else if ([actionString caseInsensitiveCompare:@"version"] == NSOrderedSame)
+    else if ([actionString caseInsensitiveCompare:ACTION_VERSION_STRING] == 
NSOrderedSame)
         return SKNActionVersion;
-    else if ([actionString caseInsensitiveCompare:@"help"] == NSOrderedSame)
+    else if ([actionString caseInsensitiveCompare:ACTION_HELP_STRING] == 
NSOrderedSame)
         return SKNActionHelp;
     else
         return SKNActionUnknown;
 }
 
 static inline NSString *SKNNormalizedPath(NSString *path) {
-    if ([path isEqualToString:@"-"] == NO) {
+    if ([path isEqualToString:STD_IN_OUT_FILE] == NO) {
         if ([path isAbsolutePath] == NO) {
             NSString *basePath = [[NSFileManager defaultManager] 
currentDirectoryPath];
             if (basePath)
@@ -74,7 +101,7 @@
     NSArray *args = [[NSProcessInfo processInfo] arguments];
     
     if (argc < 2) {
-        fprintf (stderr, "%s\n%s\n", usageStr, versionStr);
+        WRITE_ERROR;
         [pool release];
         exit (1);
     }
@@ -103,7 +130,7 @@
         
     } else if (action == SKNActionProtocol) {
         
-        fprintf (stdout, "%s\n", protocolStr);
+        WRITE_OUT(protocolStr);
         
     } else if (action == SKNActionHelp) {
         
@@ -111,40 +138,40 @@
         
         switch (helpAction) {
             case SKNActionUnknown:
-                fprintf (stdout, "%s\n%s\n", usageStr, versionStr);
+                WRITE_OUT_VERSION(usageStr);
                 break;
             case SKNActionGet:
-                fprintf (stdout, "%s\n", getHelpStr);
+                WRITE_OUT(getHelpStr);
                 break;
             case SKNActionSet:
-                fprintf (stdout, "%s\n", setHelpStr);
+                WRITE_OUT(setHelpStr);
                 break;
             case SKNActionRemove:
-                fprintf (stdout, "%s\n", removeHelpStr);
+                WRITE_OUT(removeHelpStr);
                 break;
             case SKNActionAgent:
-                fprintf (stdout, "%s\n", agentHelpStr);
+                WRITE_OUT(agentHelpStr);
                 break;
             case SKNActionProtocol:
-                fprintf (stdout, "%s\n", protocolHelpStr);
+                WRITE_OUT(protocolHelpStr);
                 break;
             case SKNActionVersion:
-                fprintf (stdout, "%s\n", versionHelpStr);
+                WRITE_OUT(versionHelpStr);
                 break;
             case SKNActionHelp:
-                fprintf (stdout, "%s\n", helpHelpStr);
+                WRITE_OUT(helpHelpStr);
                 break;
         }
         success = YES;
         
     } else if (action == SKNActionVersion) {
         
-        fprintf (stdout, "%s\n", versionStr);
+        WRITE_OUT(versionStr);
         
     } else {
         
         if (argc < 3) {
-            fprintf (stderr, "%s\n%s\n", usageStr, versionStr);
+            WRITE_ERROR;
             [pool release];
             exit (1);
         }
@@ -153,19 +180,19 @@
         NSInteger format = SKNFormatAuto;
         int offset = 2;
         
-        if ([[args objectAtIndex:2] isEqualToString:@"-format"]) {
+        if ([[args objectAtIndex:2] isEqualToString:FORMAT_OPTION_STRING]) {
             if (argc < 5) {
-                fprintf (stderr, "%s\n%s\n", usageStr, versionStr);
+                WRITE_ERROR;
                 [pool release];
                 exit (1);
             }
             offset = 4;
             formatString = [args objectAtIndex:3];
-            if ([formatString caseInsensitiveCompare:@"skim"] == NSOrderedSame)
+            if ([formatString caseInsensitiveCompare:FORMAT_SKIM_STRING] == 
NSOrderedSame)
                 format = SKNFormatSkim;
-            if ([formatString caseInsensitiveCompare:@"text"] == NSOrderedSame 
|| [formatString caseInsensitiveCompare:@"txt"] == NSOrderedSame)
+            if ([formatString caseInsensitiveCompare:FORMAT_TEXT_STRING] == 
NSOrderedSame || [formatString caseInsensitiveCompare:FORMAT_TXT_STRING] == 
NSOrderedSame)
                 format = SKNFormatText;
-            if ([formatString caseInsensitiveCompare:@"rtf"] == NSOrderedSame)
+            if ([formatString caseInsensitiveCompare:FORMAT_RTF_STRING] == 
NSOrderedSame)
                 format = SKNFormatRTF;
         }
         
@@ -176,12 +203,12 @@
         NSError *error = nil;
         
         if (action != SKNActionRemove && notesPath == nil) {
-            notesPath = [[pdfPath stringByDeletingPathExtension] 
stringByAppendingPathExtension:format == SKNFormatText ? @"txt" : format == 
SKNFormatRTF ? @"rtf" : @"skim"];
+            notesPath = [[pdfPath stringByDeletingPathExtension] 
stringByAppendingPathExtension:format == SKNFormatText ? TXT_EXTENSION : format 
== SKNFormatRTF ? RTF_EXTENSION : SKIM_EXTENSION];
         }
         
-        if ([[pdfPath pathExtension] caseInsensitiveCompare:@"pdf"] == 
NSOrderedSame && 
+        if ([[pdfPath pathExtension] caseInsensitiveCompare:PDF_EXTENSION] == 
NSOrderedSame && 
             ([fm fileExistsAtPath:pdfPath isDirectory:&isDir] == NO || isDir))
-            pdfPath = [pdfPath stringByAppendingPathExtension:@"pdf"];
+            pdfPath = [pdfPath stringByAppendingPathExtension:PDF_EXTENSION];
         
         if ([fm fileExistsAtPath:pdfPath isDirectory:&isDir] == NO || isDir) {
             error = [NSError errorWithDomain:NSPOSIXErrorDomain code:ENOENT 
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"PDF file does not exist", 
NSLocalizedDescriptionKey, nil]];
@@ -189,9 +216,9 @@
             NSData *data = nil;
             if (format == SKNFormatAuto) {
                 NSString *extension = [notesPath pathExtension];
-                if ([extension caseInsensitiveCompare:@"rtf"] == NSOrderedSame)
+                if ([extension caseInsensitiveCompare:RTF_EXTENSION] == 
NSOrderedSame)
                     format = SKNFormatRTF;
-                else if ([[notesPath pathExtension] 
caseInsensitiveCompare:@"txt"] == NSOrderedSame || [[notesPath pathExtension] 
caseInsensitiveCompare:@"text"] == NSOrderedSame)
+                else if ([[notesPath pathExtension] 
caseInsensitiveCompare:TXT_EXTENSION] == NSOrderedSame || [[notesPath 
pathExtension] caseInsensitiveCompare:TEXT_EXTENSION] == NSOrderedSame)
                     format = SKNFormatText;
                 else
                     format = SKNFormatSkim;
@@ -212,7 +239,7 @@
                     data = [NSData data];
             }
             if (data) {
-                if ([notesPath isEqualToString:@"-"]) {
+                if ([notesPath isEqualToString:STD_IN_OUT_FILE]) {
                     if ([data length])
                         [(NSFileHandle *)[NSFileHandle 
fileHandleWithStandardOutput] writeData:data];
                     success = YES;
@@ -228,9 +255,9 @@
                     }
                 }
             }
-        } else if (action == SKNActionSet && notesPath && ([notesPath 
isEqualToString:@"-"] || ([fm fileExistsAtPath:notesPath isDirectory:&isDir] && 
isDir == NO))) {
+        } else if (action == SKNActionSet && notesPath && ([notesPath 
isEqualToString:STD_IN_OUT_FILE] || ([fm fileExistsAtPath:notesPath 
isDirectory:&isDir] && isDir == NO))) {
             NSData *data = nil;
-            if ([notesPath isEqualToString:@"-"])
+            if ([notesPath isEqualToString:STD_IN_OUT_FILE])
                 data = [[NSFileHandle fileHandleWithStandardInput] 
readDataToEndOfFile];
             else
                 data = [NSData dataWithContentsOfFile:notesPath];


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to