Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add "line" and "linetext" stdin modes, and some more logging.

  • Loading branch information...
commit a518b98314c11d5415ed39fe9d05f7484cfef7c2 1 parent 715bdd2
Tom Seddon tom-seddon authored
10 XCFixin_UserScripts/UserScripts.org
View
@@ -95,12 +95,14 @@ The current option names are:
- =none= :: no data sent
- =selection= (default) :: selection is used; no data
sent if no selection
+ - =line= :: current line (including line ending
+ char(s)) sent
+ - =linetext= :: current line (excluding line ending
+ char(s)) sent
- =linetextOrSelection= :: selection is used, if any;
- current line (excluding line ending chars) sent
- if no selection
+ otherwise, as per =linetext=
- =lineOrSelection= :: selection is used, if any;
- current line (including line ending chars) sent
- if no selection
+ otherwise, as per =line=
- =reselectMode= :: value is string indicating how the selection
should be reinstated after the script has run,
57 XCFixin_UserScripts/XCFixin_UserScripts.m
View
@@ -47,12 +47,56 @@ static void Log(NSString *fmt,...)
va_end(v);
}
+static void DumpData(NSData *data,NSString *prefix)
+{
+ const uint8_t *p=(const uint8_t *)[data bytes];
+ NSUInteger n=[data length];
+ NSUInteger stride=16;
+
+ for(NSUInteger i=0;i<MAX(n,1);i+=stride)
+ {
+ NSMutableString *line=[NSMutableString stringWithCapacity:100];
+
+ if(i==0)
+ [line appendString:prefix];
+ else
+ [line appendFormat:@"%-*s",(int)[prefix length],""];
+
+ [line appendFormat:@"%08X:",(unsigned)i];
+
+ for(NSUInteger j=0;j<stride;++j)
+ {
+ if(i+j<n)
+ [line appendFormat:@" %02X",p[i+j]];
+ else
+ [line appendString:@" "];
+ }
+
+ [line appendString:@" "];
+
+ for(NSUInteger j=0;j<stride;++j)
+ {
+ if(i+j<n)
+ [line appendFormat:@"%c",isprint((char)p[i+j])?(char)p[i+j]:'.'];
+ else
+ [line appendString:@" "];
+ }
+
+ Log(@"%@\n",line);
+ }
+}
+
#else//VERBOSE_LOGGING
#define Log(...) ((void)0)
+#define DumpData(DATA,PREFIX) ((void)0)
+
#endif//VERBOSE_LOGGING
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -112,12 +156,15 @@ static void Log(NSString *fmt,...)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
+// TODO: this mechanism needs tidying up.
enum ScriptStdinMode
{
SSM_NONE,
SSM_SELECTION,
SSM_LINETEXT_OR_SELECTION,
SSM_LINE_OR_SELECTION,
+ SSM_LINETEXT,
+ SSM_LINE,
};
typedef enum ScriptStdinMode ScriptStdinMode;
@@ -218,6 +265,8 @@ -(void)run
case SSM_LINE_OR_SELECTION:
if(inputRange.length==0)
{
+ case SSM_LINETEXT:
+ case SSM_LINE:;
NSUInteger startIndex,contentsEndIndex,endIndex;
[textStorageString getLineStart:&startIndex
end:&endIndex
@@ -226,7 +275,7 @@ -(void)run
inputRange.location=startIndex;
- if(stdinMode_==SSM_LINE_OR_SELECTION)
+ if(stdinMode_==SSM_LINE_OR_SELECTION||stdinMode_==SSM_LINE)
inputRange.length=endIndex-startIndex;
else
inputRange.length=contentsEndIndex-startIndex;
@@ -271,6 +320,7 @@ -(void)run
Log(@"%s: writing %zu bytes to task's stdin...\n",__FUNCTION__,(size_t)[inputData length]);
[[stdinPipe fileHandleForWriting] writeData:inputData];
Log(@"%s: wrote to task's stdin.\n",__FUNCTION__);
+ DumpData(inputData,@"stdin data: ");
}
@catch(NSException *e)
{
@@ -286,6 +336,7 @@ -(void)run
Log(@"%s: reading from task's stdout...\n",__FUNCTION__);
stdoutData=[[stdoutPipe fileHandleForReading] readDataToEndOfFile];
Log(@"%s: read %zu bytes from task's stdout.\n",__FUNCTION__,(size_t)[stdoutData length]);
+ DumpData(stdoutData,@"stdout data: ");
}
@catch(NSException *e)
{
@@ -654,6 +705,10 @@ -(void)refreshScriptsMenu
[script setStdinMode:SSM_LINE_OR_SELECTION];
else if([stdinMode caseInsensitiveCompare:@"linetextorselection"]==NSOrderedSame)
[script setStdinMode:SSM_LINETEXT_OR_SELECTION];
+ else if([stdinMode caseInsensitiveCompare:@"line"]==NSOrderedSame)
+ [script setStdinMode:SSM_LINE];
+ else if([stdinMode caseInsensitiveCompare:@"linetext"]==NSOrderedSame)
+ [script setStdinMode:SSM_LINETEXT];
}
NSString *reselectMode=[scriptProperties objectForKey:@"reselectMode"];
Please sign in to comment.
Something went wrong with that request. Please try again.