Objective-C: Determine which file has performed an NSLog [duplicate] - objective-c

This question already has answers here:
How to print out the method name and line number and conditionally disable NSLog?
(13 answers)
Closed 9 years ago.
Say I have 10 different implementation files that are run in an chaotic order, and in each of them I have an NSLog(#"Log");, and when I run the program I will get 10 Log's to my console output, but how can I know which one was logged by which file? I'm searching for something like
`In someFile1.m: Log`
`In someFile3.m: Log`
`In someFile2.m: Log`
`...`
And so on and so forth. Is that possible?

You can use preprocessor macros for that, take a look at this example:
NSLog(#"In %s - %s:%d someObject=%#", __FILE__, __func__, __LINE__, someObject);
Here's what's available:
https://developer.apple.com/library/ios/qa/qa1669/_index.html

You can use __FILE__ macro:
NSLog(#"%s",__FILE__ );
Which outputs filename:
2013-10-16 20:49:17.536 ABC[3637:a0b] /Users/who/where//DeviceViewController.m

Related

What am I doing wrong with my CGI Script? [duplicate]

This question already has answers here:
How can I troubleshoot my Perl CGI script?
(8 answers)
Closed 3 months ago.
I am still fairly new to this and I am trying to run this CGI Script on my apache server. When I go to the webpage all I get is a blank page. What am I doing wrong?
#!/usr/bin/perl
use CGI qw(:standard);
print"Content-type: text/html \n\n";
$cost=param('cost');
$num=param('number');
$rev=param('revenue');
$avg = $cost/$num;
$avg=sprintf("%.2f",$avg);
$gp = $rev - $cost;
print "Project Cost Last Year was \$ $cost .<p>";
print "We completed $num projects during the year.";
print " That works out to an average of \$ $avg cost per project.";
print "<p>Our annual project revenue was \$ $rev <br>";
print "We made a gross profit of \$ $gp \n";
That is my current code for the script. I have made sure that my the file is executable as well.
the url i used was 192.168.1.49/cgi-bin/cgi.cgi
I believe you mean http://192.168.1.49/cgi-bin/cgi.cgi.
Given that request URL, what exactly do you expect to happen for the following?
$cost=param('cost');
$num=param('number');
$rev=param('revenue');
$avg = $cost/$num;
Since you didn't provide a value for the number parameter, $num is undef and treated as zero in $avg = $cost/$num;.
Division by zero makes the CPU sad.
You should have figured this out yourself.
An exception like this would have caused the server to return an HTTP status of 500. This indicates you should read your error logs, where you would have found the following message:
Illegal division by zero at [filename] line 7.
If you had used use warnings; as normal, you would also have received these errors:
Use of uninitialized value $num in division (/) at [filename] line 7.
Use of uninitialized value $cost in division (/) at [filename] line 7.
Always use use strict; use warnings;.
Your code suffers from MAJOR security bugs.
Specifically, your code suffers from code injection bugs which can easily be exploited for cross-site scripting attacks and url redirection attacks.
Text included in HTML needs to be converted to HTML.

Why there is no output on asking input from user in lua using sublime text [duplicate]

This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Running Code in Sublime text 2 ( Mac OS X )
(1 answer)
Closed 2 years ago.
On initiating this program i got no output, not even the compiler asked me for input
You're supposed to submit text, not images.
That being said: Your script is fine, but Sublime pipes output to the editor, but isn't a full terminal, so doesn't allow input.
#! /usr/bin/env lua
io.write( 'Enter a number : ' )
local a = io.stdin:read('*n')
while a < 200 do
print( 'value of a :', a )
a = a +1
end
You'll have to open an actual terminal, cd into the relevant directory, then run your script.
chmod +x NAME_OF_SCRIPT.lua && ./NAME_OF_SCRIPT.lua
or
lua NAME_OF_SCRIPT.lua

Windows command line script has embedded blank character [duplicate]

This question already has answers here:
What does %date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2% mean?
(2 answers)
Closed 4 years ago.
I want to copy a file to another file that contains the time and date
in its name.
I use the statement below but the problem is for time values earlier than 10 AM (for which the hour value is only a single digit) there is a blank character instead of a leading zero, which I want.
copy "M:\Production Schedule.xlsm" m:\gsdBackups\ProductionSchedule%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%%time:~6,0%.xlsm
In the example above when I run it at 9:50 I get the resulting name:
GSDProductionSchedule20180509_ 950.xlsm
I do not understand all of the formatting that is going on in the above copy command. Rather than the " 950" below I'd like to have "0950"
As a recurring task this should be a batch file hiding the details.
use wmic or PowerShell to get date/time in a user settings /locale independent format
name the batch file to any name with the extension .bat or .cmd and place it in a folder which is in the path
:: Q:\Test\2018\05\09\SO_50256566.cmd
#echo off
Set "Src=M:\Production Schedule.xlsm"
Set "Dst=M:\gsdBackups"
:: Get date and time in a user settinhs/locale independent format
For /f %%Y in ('
powershell -NoP -C "(get-date).AddDays(0).ToString('yyyyMMdd_HHmm')"
') Do Set _DT=%%Y
:: get source and use for variable modifiers to get name extension separated
For %%F in ("%Src%") Do echo copy "%%~F" "%Dst%\%%~nF_%_DT%%%~xF"
Sample output:
> SO_50256566.cmd
copy "M:\Production Schedule.xlsm" "M:\gsdBackups\Production Schedule_20180509_1743.xlsm"
If it looks OK to you remove the echo in front of copy.

Why does terminfo disagree with read? [duplicate]

This question already has an answer here:
Why is terminfo[kcuu1] = '\EOA'?
(1 answer)
Closed 5 years ago.
I'm using xterm. If I type infocmp $TERM | grep end, I see that kend=\EOF. However, if I type read, and then the End key, I see that the sequence \E[F is generated. This seems to be a problem with other keys, too.
Surely the values should be identical??
The terminal can be set on a special mode to send keystrokes from the keypad. You can set that mode by running tput smkx and unset it by tput rmkx.

&& Equivalent in Powershell [duplicate]

This question already has answers here:
What are the PowerShell equivalents of Bash's && and || operators?
(4 answers)
Can I get "&&" or "-and" to work in PowerShell?
(13 answers)
Closed 3 years ago.
In bash I use ./task1.sh && ./task2.sh to run task1, and then run task2 as long as task1 did not return an error code. When I try .\task1.bat && .\task2.bat in Powershell I get the error "The Token && Is not a valid separator in this version."
Is there an equivalent for && in Windows Powershell?
This is the closest I can get:
.\task1.ps1 ; if($?){.\task2.ps1}
I think the closest equivalent would be:
.\task1.bat;if($lastexitcode -eq 0){.\task2.bat}
Also, Powershell has -and which you might want to try, but it is not really the same.