Read string in Objective-C console application? - objective-c

What is the best way to read string input from a simple Objective-C console application?
I would just like to store the input as an NSString variable.
I've seen multiple people post about scanf, gets and others, but they everyone seems to say that they're "unreliable", or "open to attack".
I can see how this could be true for gets but I'm looking for the best possible way to do this.
Thanks!

scanf should be mostly secure as long as you use your input correctly.
I've heard of scanf_s which is supposed to be more secure but work the same way.

Related

A way to get all declared UTIs in Cocoa (Swift/Obj-C)... and/or, determining UTIs defined by App bundles?

This is actually a two-fold question, I guess. On one part, I'd like to know whether there's a neat way to enumerate all declared UTIs on a given system.
I know lsregister -dump is an option, given some grep and parsing on my side; however, I'm left to wonder if there isn't a better solution.
Further... I'm wondering if there's a way to retrieve a list of imported/exported UTIs given an app's path. I know the reverse should be possible (i.e. finding which bundle has declared a given UTI).
One of the reasons why I'm wondering about this is because a possible solution for the first part of the question would be to iterate through all apps and retrieve their imported/exported UTIs (although I think it would probably not be a very efficient solution)
I've searched everywhere I can think of and am not really any closer to an answer. So far, it would seem it's either parse output of lsregister -dump, or try to read UTI keys directly from apps' Info.plist files...
Finally, in my searching I've come across a private API that might be of use, but I have absolutely no idea how to use it, since there's absolutely no documentation for it online... I'm talking about "__UTCopyDeclaredTypeIdentifiers"... maybe somebody is aware of which (if any) parameters does that function take, and/or what exactly does it return?
import Foundation
#_silgen_name("_UTCopyDeclaredTypeIdentifiers") func UTCopyDeclaredTypeIdentifiers() -> CFArray
let UTIs = UTCopyDeclaredTypeIdentifiers()
print(UTIs)
Should print all the UTIs that the function knows about.

Sizeable screenshot UI code

I am in need of someway to access the UI for the screenshot command in OSX (Cmd+Shft+4) and I would like to be able to activate the UI with a UI button that will screenshot the region selected and save it to a temp location.
Thanks in advance ;)
If there's a direct way to do this from Cocoa, maybe someone will chime in... but I doubt it exists. You can, however, get any behavior you want from the "screencapture" command line utility; it does exactly the same as Cmd-Shift-3 or 4 with a gazillion options. Just type "man screencapture" in Terminal to see all the flags.
But this would require you to run a bash script from your app. If you haven't done that before, well, google it, or check out the many threads here on SO... Opinions vary on how complicated it should be, from a one-liner call to system() to fully thread-safe error reporting NSTask and all kinds of answers in between.
I'd recommend using one of the NSTask answers which keep themselves to half a dozen lines, but YMMV.

Detect USB - Insert/Remove - VB.NET on Windows CE 6.0

I'm becoming mad trying to figure out how to resolve this task. My goal is pretty easy, copy a file on the USB stick every time that it is inserted and then release the USB stick turning off the LED. What is the best way to solve it?
1) I found this article
http://geekswithblogs.net/BruceEitman/archive/2008/06/13/windows-ce-monitoring-for-disk-insertion-to-add-support-for.aspx
or
http://geekswithblogs.net/BruceEitman/archive/2008/06/13/windows-ce-monitoring-for-disk-insertion-to-add-support-for.aspx
but I can't translate it on VB.NET project.
2) Then I read that is enough to use RequestDeviceNotifications for block devices. But How can I do that in VB.NET?
I would like to avoid OpenNetCF if possible.
Thank you
Since you don't want to "use OpenNETCF" I assume that you don't want to use any libraries or capabilities not built in to the CF. We'll skip the argument of that silliness and the "value of your time" discussion and take that as a requirement.
What you need to do is:
Use P/Invoke to call CreateMsgQueue. That's going to give you back a Handle. You'll probably want to do CloseMsgQueue as well for completeness
P/Invoke RequestDeviceNotifications and pass it the handle returned from #1 above along with the DEVCLASS GUID value for the device notifications you want - probably STORE_MOUNT_GUID. Again, adding StopDeviceNotifications for completeness is a good idea.
At that point you'll get a message on the queue whenever a insert or remove happens. You then call ReadMsgQueue to get the DEVDETAIL data in the message.
Parse the DEVDETAIL and look at the fAttached member.
It'd take me a while to write that for you, so you'll need to do this on your own.
Start writing the project, find P/Invoke routines for the calls you need (like FindFirstFile and CreateProcess). On SO, have a look at Storage Card Problem In windows mobile and How to register form for WM_DEVICECHANGE message in windows mobile.
You are only going to be dead in the water if you can not find a particular call that you can't make.
As you work through your project, post (or search for) the actual problems you run into.
Otherwise, it sounds like you are asking someone to write the project and hand it to you.

How to decode GUID in AlbumData.xml (iPhoto)

I tried to parse AlbumData.xml and found strange GUID string value, how to convert it to integer value ?
eg : f7hWRm%xSMiYVfEynRpo7g = 4.29497e+09
Thanks in advance
You simply don't. It's an NSString.
A suggestion is to change the extension to .plist and open in Xcode. You can then see the data types.
Sort of a related thing, iTunes sends a NSDistributedNotificationCenter note whenever its library changes. Does iPhoto do something similar for its AlbumData.xml? I didn't know if I should post this as a new question since it is somewhat relevant to this one.

Hexadecimal numpad

The project I am currently working on requires a lot of hexadecimal numbers to be entered into the code.
I once saw a pic of an old keyboard with a hexadecimal numpad (has A-F letters on it also) replacing the normal numpad. Anyone know where I can get one of these?
IPv6 Buddy -keypad should work well for hexadecimal input.
http://www.ipv6buddy.com/
If you can get your hands on one of the retired space shuttles, they have one!
I have an old Heathkit learning toy with a hex numpad because the only way to program it was to assemble code by hand (it came with a 6800 manual and some notepads) into the online monitor. This was actually fun!
Mine is missing the 'D' button however.
Great idea with the programmable keypad. I think i am going to pick up one of these: DX1 input system. Works for any reconfiguring I might want to do.
Is this the one you're talking about?
funky http://www.cpmuseum.com/Exhibits/Apple%20Lane/7603/7603-0005/images/000%20Front%20View.jpg
While this has a lot of "gee whiz" appeal, I have to say:
You have two hands. Use them. A-F are all reachable with the left hand on a standard keyboard while your right hand is on the num-pad. Instead of putting muscle-memory time into some arcane Hex-pad, you'll be learning to touch-type with your left hand, which has application outside your current project.
Better yet, come up with a smarter way of getting the hex codes into your code. Write a script that extracts them from your data-source and into your code as symbolic variables... or whatever.
EDIT
Ok, I'll give you the benefit of the doubt. Lets assume you're working on a hardware project and need to provide a specialized interface for your user. Maybe a programmable keypad would fit the bill?
Not sure of the specifics right now, but I'm pretty sure you can easily write a keyboard remapper. You could remap the QWASDF keys to ABCDEF in order to type them more quickly. That way you could use 2 hands to type. Or if you are in control of the program they are being typed into, you could just translate the keys in code on the fly. You also might want to try out the Microsoft Keyboard Layout Creator