From jcollet.ext at orange-ftgroup.com Mon Apr 2 04:44:30 2007 From: jcollet.ext at orange-ftgroup.com (zze-Icom COLLET J ext RD-MAPS-REN) Date: Mon Apr 2 04:44:37 2007 Subject: (no subject) Message-ID: <3418F3471F1CA4409901547349FFAE2E051E8384@FTRDMEL2.rd.francetelecom.fr> Hi Everybody We are writing a multi OS application using gcc but on MAC, we have troubles using it, concerning link. We have troubles to link correctly, using relatives paths to retrieve our libraries. The line to link is the following one: LIBS += -L../../../../Build/lib/MacOSX/Release -lMosaic Mosaic is a framework developed by us. The trouble is that when we start our application from another Mac, if the path from where we launch the application is different from "Build/lib/MacOSX/Release", a message is displayed from the terminal. For example, all files of application are put in path /Users/fique100/softphone. The application is launched from a terminal using softphone app. dyld: Library not loaded: ../../../../Build/lib/MacOSX/Release/libMosaic.dylib Referenced from: /Users/fique100/softphone/softphone Reason: image not found Trace/BPT trap On the contrary if path is /Users/fique100/softphone/lib/MacOSX/Release/ , everything works. I don't understand. On Linux, the same line to link with mosaic works perfectly and the library is found, evn the path is different. I hope someone could help me. Thanks Jeremie PS : sorry for my English, I'm French ;-) From jalkut at red-sweater.com Mon Apr 2 06:46:49 2007 From: jalkut at red-sweater.com (Daniel Jalkut) Date: Mon Apr 2 06:58:14 2007 Subject: (no subject) In-Reply-To: <3418F3471F1CA4409901547349FFAE2E051E8384@FTRDMEL2.rd.francetelecom.fr> References: <3418F3471F1CA4409901547349FFAE2E051E8384@FTRDMEL2.rd.francetelecom.fr> Message-ID: On Apr 2, 2007, at 7:44 AM, zze-Icom COLLET J ext RD-MAPS-REN wrote: > I don't understand. On Linux, the same line to link with mosaic works > perfectly and the library is found, evn the path is different. On Mac OS X, you need to make sure the library will be in a default library search path at launch time, or else give the library specific instructions for where to find it. > dyld: Library not loaded: > ../../../../Build/lib/MacOSX/Release/libMosaic.dylib > > Referenced from: /Users/fique100/softphone/softphone Given this example, you probably want the library to be "relative to the executable" of the main program. You do this by setting the "Install Directory" of the subsidiary library, when you build it. See: http://developer.apple.com/documentation/MacOSX/Conceptual/ BPFrameworks/Tasks/CreatingFrameworks.html Even if you're not creating a "framework", the same principles apply. Daniel From jcollet.ext at orange-ftgroup.com Mon Apr 2 07:23:31 2007 From: jcollet.ext at orange-ftgroup.com (zze-Icom COLLET J ext RD-MAPS-REN) Date: Mon Apr 2 07:23:44 2007 Subject: (no subject) In-Reply-To: References: <3418F3471F1CA4409901547349FFAE2E051E8384@FTRDMEL2.rd.francetelecom.fr> Message-ID: <3418F3471F1CA4409901547349FFAE2E051E8385@FTRDMEL2.rd.francetelecom.fr> Thanks for your help I will try as soon as possible Jeremie -----Message d'origine----- De?: Daniel Jalkut [mailto:jalkut@red-sweater.com] Envoy??: lundi 2 avril 2007 15:47 ??: zze-Icom COLLET J ext RD-MAPS-REN Cc?: macosx-dev@omnigroup.com Objet?: Re: (no subject) On Apr 2, 2007, at 7:44 AM, zze-Icom COLLET J ext RD-MAPS-REN wrote: > I don't understand. On Linux, the same line to link with mosaic works > perfectly and the library is found, evn the path is different. On Mac OS X, you need to make sure the library will be in a default library search path at launch time, or else give the library specific instructions for where to find it. > dyld: Library not loaded: > ../../../../Build/lib/MacOSX/Release/libMosaic.dylib > > Referenced from: /Users/fique100/softphone/softphone Given this example, you probably want the library to be "relative to the executable" of the main program. You do this by setting the "Install Directory" of the subsidiary library, when you build it. See: http://developer.apple.com/documentation/MacOSX/Conceptual/ BPFrameworks/Tasks/CreatingFrameworks.html Even if you're not creating a "framework", the same principles apply. Daniel From janos.lobb at yale.edu Thu Apr 5 10:10:56 2007 From: janos.lobb at yale.edu (=?ISO-8859-1?Q?J=E1nos?=) Date: Thu Apr 5 10:10:55 2007 Subject: C strtok question Message-ID: Hi, I am trying to parse a string with the C library string function strtok. The string can have the value from: " -t any -j 1 -q 17" to " -t any -j 1 -q 17 -n 3 -d 10 -k 3 -m " If the -m flag is present it always at the end of the string. The delimiter is a single space. Here are the declarations for variables I use. uint16 i, j ; uint16 n, om, qs, nr, sk, mr; uint32 lj, index, cst ; const char *cflags ; char *flg; char *token; char *tokenval; char *code; const char *delim; delim = " "; I use this while loop to parse the string that is in flg flg = (char *)cflags; token = (char *)delim; tokenval = (char *)delim; j = 1; while (token !=NULL || tokenval !=NULL) { if (j==1) token = strtok(flg,delim); else token = strtok(NULL,delim); if ( strstr( token,"-t") != NULL) { tokenval = strtok(NULL,delim); code = tokenval; } if ( strstr( token,"-j") != NULL) { tokenval = strtok(NULL,delim); lj = (uint32)tokenval; } if ( strstr( token,"-q") != NULL) { tokenval = strtok(NULL,delim); cst = (uint32)tokenval; qs = (uint16)cst; } if ( strstr( token,"-n") != NULL) { tokenval = strtok(NULL,delim); cst = (uint32)tokenval; nr = (uint16)cst; } if ( strstr( token,"-d") != NULL) { tokenval = strtok(NULL,delim); cst = (uint32)tokenval; om = (uint16)cst; } if ( strstr( token,"-k") != NULL) { tokenval = strtok(NULL,delim); cst = (uint32)tokenval; sk = (uint16)cst; } if ( strstr( token,"-m") != NULL) { mr = 1; break ; } fprintf(stderr, "token=%s tokenval=%s\n", token,tokenval); j++; } fprintf(stderr, "-t=%s -j=%d -q=%d -n=%d -d=%d -k=%d -m=%d \n", code,lj,qs,nr,om,sk,mr); I never get to the second fprint, after the while. Here is a typical output by the first fprint if I parse the " -t any -j 1 -q 17" string token=-t tokenval=any token=-j tokenval=1 token=-q tokenval=17 Bus error I am following this example: http://math1.unice.fr/laboratoire/help/info/glibc/libc_65.html What am I doing wrong ? Thanks ahead, J?nos P.S. If I comment out the second fprint I got the same output, so the program dies in the while when the value of token becomes NULL. Before the second fprint. I do the (uint32) and (uint16) castings to avoid a warning of "cast from pointer to integer of different size". From norman at astro.gla.ac.uk Thu Apr 5 10:23:02 2007 From: norman at astro.gla.ac.uk (Norman Gray) Date: Thu Apr 5 10:38:37 2007 Subject: C strtok question In-Reply-To: References: Message-ID: J?nos, hello. On 2007 Apr 5 , at 18.10, J?nos wrote: > I am trying to parse a string with the C library string function > strtok. The string can have the value from: > > " -t any -j 1 -q 17" It looks as if you're actually trying to parse a command line with options. If that's so, then you'd probably be best off looking at getopt(3), which will do all the fiddly bits for you. Norman -- ------------------------------------------------------------------ Norman Gray : http://nxg.me.uk eurovotech.org : University of Leicester, UK From peter.ilberg at gmail.com Thu Apr 5 11:03:43 2007 From: peter.ilberg at gmail.com (Peter Ilberg) Date: Thu Apr 5 11:03:51 2007 Subject: C strtok question In-Reply-To: References: Message-ID: In your test case, strtok is returning NULL on its last iteration through the loop. strstr doesn't like NULL as an input argument. You avoid the problem in your longer test case by explicity jumping out of the loop after processing "-m". Try rewriting the loop this way: flg = (char *)cflags; tokenval = (char *)delim; for (token = strtok(flg,delim); token; token = strtok(NULL,delim)) { if ( strstr( token,"-t") != NULL) { tokenval = strtok(NULL,delim); code = tokenval; } [...other options...] if ( strstr( token,"-m") != NULL) { mr = 1; } fprintf(stderr, "token=%s tokenval=%s\n", token,tokenval); } If all of your options are single letters, you can rewrite the loop body: if (token[0] == '-') switch (token[1]) { case 't': tokenval = strtok(NULL,delim); code = tokenval; break; [...other options...] case 'm': mr = 1; break; } --- Peter From janos.lobb at yale.edu Thu Apr 5 11:49:38 2007 From: janos.lobb at yale.edu (=?ISO-8859-1?Q?J=E1nos?=) Date: Thu Apr 5 11:49:37 2007 Subject: C strtok question In-Reply-To: References: Message-ID: On Apr 5, 2007, at 2:03 PM, Peter Ilberg wrote: > In your test case, strtok is returning NULL on its last iteration > through > the loop. strstr doesn't like NULL as an input argument. You avoid the > problem in your longer test case by explicity jumping out of the loop > after processing "-m". Try rewriting the loop this way: > > flg = (char *)cflags; > tokenval = (char *)delim; > for (token = strtok(flg,delim); token; token = strtok > (NULL,delim)) { > if ( strstr( token,"-t") != NULL) { > tokenval = strtok(NULL,delim); > code = tokenval; > } > [...other options...] > if ( strstr( token,"-m") != NULL) { > mr = 1; > } > fprintf(stderr, "token=%s tokenval=%s\n", token,tokenval); > } > > If all of your options are single letters, you can rewrite the loop > body: > > if (token[0] == '-') > switch (token[1]) { > case 't': > tokenval = strtok(NULL,delim); > code = tokenval; > break; > [...other options...] > case 'm': > mr = 1; > break; > } > > --- Peter > _______________________________________________ Peter, That is it. /I found out in the meantime as I tried to debug/ Thanks a lot, J?nos P.S. Almost all C books I read say that I should use switch just with int values, so I was afraid to do so although originally that was my first choice. From andy at hexten.net Thu Apr 5 11:57:18 2007 From: andy at hexten.net (Andy Armstrong) Date: Thu Apr 5 12:29:46 2007 Subject: C strtok question In-Reply-To: References: Message-ID: On 5 Apr 2007, at 19:49, J?nos wrote: > That is it. > > /I found out in the meantime as I tried to debug/ > > Thanks a lot, > > J?nos > P.S. Almost all C books I read say that I should use switch just > with int values, so I was afraid to do so although originally that > was my first choice. chars /are/ ints :) -- Andy Armstrong, hexten.net From steinitz at datatactics.com.au Sun Apr 8 17:53:03 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Sun Apr 8 19:22:30 2007 Subject: Printing a database report Message-ID: Hello, I'm using a crude method to print a twenty-page Core Data report which has a number of formatting, grouping and summarizing aspects. Every time the printing system calls my printing view's drawRect I calculate the entire report but only actually draw the stuff that intersects with the page rect passed by the printing system. Inelegant, I know. That method works but because for each page I have to do hundreds of fetches - all the fetches for the whole report - each page takes too many seconds to image. Its too slow for the busy retailer using the system. I've made some futile attempts to optimize the fetching and calculating but now I have a nebulous idea that I could image the whole report into a second view or perhaps to pdf or even to a low-level graphics-system object... and then, when the printing system calls my drawRect, I return rects of that intermediate object, page by page. I would have thought that that idea had been discussed elsewhere, but I can't seem to find it. Thanks for any pointers, Steve From sstevenson at mac.com Sun Apr 8 22:00:28 2007 From: sstevenson at mac.com (Scott Stevenson) Date: Sun Apr 8 22:00:35 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: On Apr 8, 2007, at 5:53 PM, Steve Steinitz wrote: > calculating but now I have a nebulous idea that I could image the > whole report into a second view or perhaps to pdf or even to a > low-level graphics-system object... and then, when the printing system > calls my drawRect, I return rects of that intermediate object Can you just generate HTML and print it via a WebView? - Scott From steinitz at datatactics.com.au Sun Apr 8 22:46:47 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Sun Apr 8 22:46:55 2007 Subject: Printing a database report In-Reply-To: Message-ID: Hi Scott, Thanks for your reply. You wrote: > On Apr 8, 2007, at 5:53 PM, Steve Steinitz wrote: > > > image the whole report into a second view or perhaps to pdf or > > even to a low-level graphics-system object... and then, when the > > printing system calls my drawRect, I return rects of that > > intermediate object > > Can you just generate HTML and print it via a WebView? I currently have fine, down-to-the-pixel control over the report and I'm not sure how I'd accomplish that in html. But its certainly along the lines of what I was thinking. I'm open to other ideas. Thanks, Steve From kusterer at gmail.com Mon Apr 9 03:10:17 2007 From: kusterer at gmail.com (M. Uli Kusterer) Date: Mon Apr 9 03:10:22 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: <758cc1960704090310g1a328ce3nf20760f9f42c558d@mail.gmail.com> On 09/04/07, Steve Steinitz wrote: > I currently have fine, down-to-the-pixel control over the report and > I'm not sure how I'd accomplish that in html. But its certainly along > the lines of what I was thinking. > > I'm open to other ideas. You could just load what you need into a cache, and then use that cache to not have to re-fetch the information you want to output each time. Similarly, you could cache dimensions of parts you've already printed, and remove their data from your cache, so you save RAM and you only have to draw things twice that cross several pages. That would take less RAM, and thus prevent unnecessary swap-outs to hard disk that could cost unneeded electricity on laptops. Cheers, M. Uli Kusterer ------------------------------------------------------------ "The Witnesses of TeachText are everywhere..." http://www.zathras.de From steinitz at datatactics.com.au Mon Apr 9 05:11:05 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Mon Apr 9 05:11:15 2007 Subject: Printing a database report In-Reply-To: <758cc1960704090310g1a328ce3nf20760f9f42c558d@mail.gmail.com> Message-ID: Hello Uli, Thank you for your reply. On Monday, 9 April 2007 at 12:10 pm, M. Uli Kusterer wrote: > > I currently have fine, down-to-the-pixel control over the report and > > I'm not sure how I'd accomplish that in html. But its certainly along > > the lines of what I was thinking. > > > > I'm open to other ideas. > > You could just load what you need into a cache, and then use that > cache to not have to re-fetch the information you want to output each > time. Similarly, you could cache dimensions of parts you've already > printed, and remove their data from your cache, so you save RAM and > you only have to draw things twice that cross several pages. > > That would take less RAM, and thus prevent unnecessary swap-outs to > hard disk that could cost unneeded electricity on laptops. When it comes time to optimize for ram and electricity I will take your good advice. However at present I am trying to significantly speed up the printing, say, by a factor of 10 - 100 and with a minimum of effort. Has anyone tried something like imaging to a large view (or something) and then giving the printing system pieces of it when it calls drawRect? Thanks again, Steve From andreas at harmless.de Mon Apr 9 05:42:00 2007 From: andreas at harmless.de (Andreas Mayer) Date: Mon Apr 9 05:42:02 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: <1CDC52F6-8793-4D2F-9F46-CC3F7C6F67B1@harmless.de> Am 09.04.2007 um 14:11 Uhr schrieb Steve Steinitz: > Has anyone tried something like imaging to a large view (or something) > and then giving the printing system pieces of it when it calls > drawRect? Yes. Though I'm not sure how that answer does help. :} Andreas From danhd123 at mac.com Mon Apr 9 10:48:16 2007 From: danhd123 at mac.com (Daniel DeCovnick) Date: Mon Apr 9 10:48:41 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: Is there an easy way to do that? I've got a similar situation, and "printing" HTML to a WebView instead of formatting parts of an NSMutableAttributedString sounds like it could save me some time and energy, while making it easier to modify, IF there's a relatively easy way to generate HTML (other than WebObjects 4.5.1 ;-) ) On Apr 8, 2007, at 10:00 PM, Scott Stevenson wrote: > > On Apr 8, 2007, at 5:53 PM, Steve Steinitz wrote: > >> calculating but now I have a nebulous idea that I could image the >> whole report into a second view or perhaps to pdf or even to a >> low-level graphics-system object... and then, when the printing >> system >> calls my drawRect, I return rects of that intermediate object > > Can you just generate HTML and print it via a WebView? > > - Scott > > _______________________________________________ > MacOSX-dev mailing list > MacOSX-dev@omnigroup.com > http://www.omnigroup.com/mailman/listinfo/macosx-dev From mah at jump-ing.de Mon Apr 9 11:49:43 2007 From: mah at jump-ing.de (Markus Hitter) Date: Mon Apr 9 11:50:14 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: <2D3014CE-BFB8-4ACB-BAE3-AABFBD9C0089@jump-ing.de> Am 09.04.2007 um 14:11 schrieb Steve Steinitz: > Has anyone tried something like imaging to a large view (or something) > and then giving the printing system pieces of it when it calls > drawRect? If your view changes rarely, you could draw into a PDF, then show the PDF on the screen as well as using it for printing. Markus - - - - - - - - - - - - - - - - - - - Dipl. Ing. Markus Hitter http://www.jump-ing.de/ From steinitz at datatactics.com.au Mon Apr 9 17:49:32 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Mon Apr 9 17:49:41 2007 Subject: Printing a database report Message-ID: Hi Andreas, On Monday, 9 April 2007 at 2:42 pm, Andreas Mayer wrote: > Yes. Would you care to elaborate? :) Thank you for any pointers, Steve From steinitz at datatactics.com.au Mon Apr 9 17:56:31 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Mon Apr 9 17:56:39 2007 Subject: Printing a database report In-Reply-To: <2D3014CE-BFB8-4ACB-BAE3-AABFBD9C0089@jump-ing.de> Message-ID: Hi Markus, Thanks for you reply On Monday, 9 April 2007 at 8:49 pm, Markus Hitter wrote: > > Has anyone tried something like imaging to a large view (or something) > > and then giving the printing system pieces of it when it calls > > drawRect? > > If your view changes rarely, you could draw into a PDF, then show the > PDF on the screen as well as using it for printing. Unfortunately, it changes by the minute. And I have a second screen report. What I have gathered from replies to this thread is that there is not a standard, well-known way to create an image for printing and then feed it piece by piece to the printing system when it calls drawRect. Indeed Andreas, who is usually right on the money, hinted that its not even a good idea. That said, I make another plea to any printing experts to share ideas they may have in this area. Thanks again, Steve From jcollet.ext at orange-ftgroup.com Tue Apr 10 00:31:11 2007 From: jcollet.ext at orange-ftgroup.com (zze-Icom COLLET J ext RD-MAPS-REN) Date: Tue Apr 10 00:31:46 2007 Subject: (no subject) In-Reply-To: References: <3418F3471F1CA4409901547349FFAE2E051E8384@FTRDMEL2.rd.francetelecom.fr> Message-ID: <3418F3471F1CA4409901547349FFAE2E051E839E@FTRDMEL2.rd.francetelecom.fr> Hi, Sorry if i answer late, but, I wasn't at work. I looked at the link and tried to use install-directory path. We have common makefiles for our libraries. I have added the line LIBS += -L$(TOROOT)/../MOSAIC/lib/$(TARGET_OS)/$(BUILD) -lMosaic -Wl,-install_name ./ But now the trouble is that with libraries that are linked together (for example : UI_QT_WIDGET with UI_QT_TOOLS), the link cannot be performed (ld: ../../../../Build/MacOsX/10.4/Debug/libUI_QT_TOOLS.a can't be linked because it has the same install_name (./) as the output /usr/bin/libtool: internal link edit command failed make[1]: *** [../../../../Build/MacOsX/10.4/Debug/libUI_QT_WIDGET.dylib] Error 1 make: *** [debug] Error 2). I don't understand very well why ... I'm a newbie on Mac... ************************************ COMPILING UI_QT_TOOLS ************************************ Linking ++ DEBUG COMPILATION SUCCEDED ++ ************************************ COMPILING UI_QT_WIDGET ************************************ Linking ld: ../../../../Build/MacOsX/10.4/Debug/libUI_QT_TOOLS.a can't be linked because it has the same install_name (./) as the output /usr/bin/libtool: internal link edit command failed make[1]: *** [../../../../Build/MacOsX/10.4/Debug/libUI_QT_WIDGET.dylib] Error 1 make: *** [debug] Error 2 ERROR COMPILING UI_QT_WIDGET ! If you have ideas; Jeremie -----Message d'origine----- De?: Daniel Jalkut [mailto:jalkut@red-sweater.com] Envoy??: lundi 2 avril 2007 15:47 ??: zze-Icom COLLET J ext RD-MAPS-REN Cc?: macosx-dev@omnigroup.com Objet?: Re: (no subject) On Apr 2, 2007, at 7:44 AM, zze-Icom COLLET J ext RD-MAPS-REN wrote: > I don't understand. On Linux, the same line to link with mosaic works > perfectly and the library is found, evn the path is different. On Mac OS X, you need to make sure the library will be in a default library search path at launch time, or else give the library specific instructions for where to find it. > dyld: Library not loaded: > ../../../../Build/lib/MacOSX/Release/libMosaic.dylib > > Referenced from: /Users/fique100/softphone/softphone Given this example, you probably want the library to be "relative to the executable" of the main program. You do this by setting the "Install Directory" of the subsidiary library, when you build it. See: http://developer.apple.com/documentation/MacOSX/Conceptual/ BPFrameworks/Tasks/CreatingFrameworks.html Even if you're not creating a "framework", the same principles apply. Daniel From sstevenson at mac.com Tue Apr 10 00:48:31 2007 From: sstevenson at mac.com (Scott Stevenson) Date: Tue Apr 10 00:48:40 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: <2C3AB944-2FAE-48E6-BD8C-71C891EEBE7F@mac.com> On Apr 9, 2007, at 10:48 AM, Daniel DeCovnick wrote: > Is there an easy way to do that? I've got a similar situation, and > "printing" HTML to a WebView instead of formatting parts of an > NSMutableAttributedString sounds like it could save me some time > and energy, while making it easier to modify, IF there's a > relatively easy way to generate HTML (other than WebObjects > 4.5.1 ;-) ) I'm not aware of a stock class that does it, and I'm actually not sure how such a thing would be able to infer formatting from your data. You might be able to take advantage of the Objective-C/ JavaScript bridge, though. Another option is to take advantage of the "canvas" tag supported by Safari (and I believe Firefox now?), which basically gives you a 2D graphics context to draw into using CG-like functions. I still think regular HTML+CSS would be easier in most cases, though, as it's declarative. Steve Steinitz expressed concerns about not being able to achieve pixel-level control over placement, but CSS absolutely can do that: #item { position: absolute; top: 100px; left: 10px } .....
Help, I'm stuck in a div tag.
It should be even easier under such a controlled environment. - Scott From andreas at harmless.de Tue Apr 10 02:09:57 2007 From: andreas at harmless.de (Andreas Mayer) Date: Tue Apr 10 02:10:28 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: <26437B05-EA30-4D9B-B340-5A896E7BACD2@harmless.de> Am 10.04.2007 um 02:49 Uhr schrieb Steve Steinitz: > On Monday, 9 April 2007 at 2:42 pm, Andreas Mayer wrote: > >> Yes. > > Would you care to elaborate? :) I'm not quite sure on what? It seems rather straightforward. You build your pages, line them up and give them out to the printing system as requested. Did you *try* it? Maybe you can ask some specific question on parts that don't work for you? Also, it doesn't really matter *how* you render your pages. Just get the content in a view *somehow* and you can print it. You can even mix different techniques by adding several "page views" to one big "print view". Andreas From steinitz at datatactics.com.au Tue Apr 10 04:11:50 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Tue Apr 10 04:12:36 2007 Subject: Printing a database report In-Reply-To: <26437B05-EA30-4D9B-B340-5A896E7BACD2@harmless.de> Message-ID: Hi Andreas, Thanks for your reply. On Tuesday, 10 April 2007 at 11:09 am, Andreas Mayer wrote: > It seems rather straightforward. You build your pages, Excuse my ignorance but I don't know what you mean by 'build your pages'. I'd appreciate any clarification you would care to provide. Thanks again, Steve From andreas at harmless.de Tue Apr 10 05:59:54 2007 From: andreas at harmless.de (Andreas Mayer) Date: Tue Apr 10 06:00:25 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: Am 10.04.2007 um 13:11 Uhr schrieb Steve Steinitz: >> It seems rather straightforward. You build your pages, > > Excuse my ignorance but I don't know what you mean by 'build your > pages'. I mean "draw your content in a view the size of a page". I don't quite understand what you want me to tell you. Actually, you already made me say something I didn't mean. You do *not* have to make a single view per page. You *can*. But it's really up to you. Andreas From bob at apple.com Tue Apr 10 06:54:02 2007 From: bob at apple.com (Bob Frank) Date: Tue Apr 10 07:20:29 2007 Subject: MEETING: Chicago CocoaHeads / CAWUG Tuesday 4/10 - BaseTen Message-ID: <91E3F836-B7E0-40EA-B1C6-823BA47EAE97@apple.com> Hi all, Just a quick reminder. Tonight Jon will be talking about BaseTen. Hope to see you there. The Chicago CocoaHeads / Chicago Cocoa and WebObjects User Group (CAWUG) is holding our next meeting this coming Tuesday, April 10th, at 6:00 PM at the Apple Store on Michigan Ave. Agenda: - Introductions & Announcements - Jon 'Wolf' Rentzsch on BaseTen - Q & A - adjournment to O'Toole's When: Tuesday, March 13th, 6:00 PM Where: Apple Store Michigan Avenue 679 North Michigan Ave. (at the corner of Huron & Michigan Ave.) Chicago, IL 60611 http://maps.yahoo.com/maps_result? ed=gYbE5Op_0Tokf_p7h61dwjbWtjC2r1YehzWw&csz=60611 - Jon on BaseTen BaseTen is Marko Karppinen's new dual-licensed (GPL2/commercial-per- developer) open-source Cocoa database persistence framework. It has similarities to EOF and Core Data, but is definitely not a clone of either. Jonathan 'Wolf' Rentzsch will detail BaseTen's architecture, including its unique leverage of PostgreSQL's finer features (SAVEPOINT, NOTIFY). - O'Tooles We will continue the discussion at our local watering hold Timothy O'Toole's at 622 Fairbanks (2 blocks east of the store). We also wish to thank the folks who run the theater space at the Apple store for letting us have our meetings there, and Jonathan 'Wolf' Rentzsch for hosting the new and revived CAWUG web site and taking over hosting our listserve. Thanks all. Also, if you are working on a project and would like to talk about it briefly / promote it, I think it would be fun for people to hear about other people's projects. Please email me off line and you can talk at a future meeting or would like a book to review. Future meetings dates: 5/8/07 & no June Meeting WWDC CAWUG Resources Web Site: http://www.cawug.org/ RSS feed: http://www.cawug.org/rss.xml Mail list: http://redshed.net/mailman/listinfo/cawug-announce iCal: http://ical.mac.com/chicagobob/ Chicago-CocoaHeads-CAWUG (view on the web) iCal: webcal://ical.mac.com/chicagobob/Chicago-CocoaHeads-CAWUG.ics (subscribe to in iCal) Cocoa Heads web site: http://cocoaheads.org/us/ChicagoIllinois/index.html Hope to see you at the meeting. -Bob --- Bob Frank (312) 961 - 0509 [cell] bob@apple.com From bentley at crenelle.com Tue Apr 10 12:42:22 2007 From: bentley at crenelle.com (Michael Brian Bentley) Date: Tue Apr 10 12:43:54 2007 Subject: byteswap.h Message-ID: There's a couple files that occasionally seem to plague GNU/Linux software source that I'd like to find a relatively benign solution for under OS X. The files are byteswap.h and, perhaps, endian.h. I won't be adding any conditional compiles to the original source I'm trying to build, or modifying the original source to change the include file names, but I have no problem inventing these two files to fulfill the build requirements. If you know offhand, please let me know, otherwise I'll just be inventive. Thanks! -Mike From ssen at apple.com Tue Apr 10 14:34:37 2007 From: ssen at apple.com (Shantonu Sen) Date: Tue Apr 10 14:34:52 2007 Subject: byteswap.h In-Reply-To: References: Message-ID: <246BFC2B-73A4-4574-B3D0-8CC5BB53E025@apple.com> You can create a byteswap.h that includes , and implement whatever functions you need either as macros or inline functions to call the libkern versions Shantonu On Apr 10, 2007, at 3:42 PM, Michael Brian Bentley wrote: > There's a couple files that occasionally seem to plague GNU/Linux > software source that I'd like to find a relatively benign solution > for under OS X. The files are byteswap.h and, perhaps, endian.h. > > I won't be adding any conditional compiles to the original source > I'm trying to build, or modifying the original source to change the > include file names, but I have no problem inventing these two files > to fulfill the build requirements. > > If you know offhand, please let me know, otherwise I'll just be > inventive. > > Thanks! > > -Mike > _______________________________________________ > MacOSX-dev mailing list > MacOSX-dev@omnigroup.com > http://www.omnigroup.com/mailman/listinfo/macosx-dev From kusterer at gmail.com Fri Apr 6 03:26:03 2007 From: kusterer at gmail.com (Uli Kusterer) Date: Tue Apr 10 15:19:54 2007 Subject: C strtok question In-Reply-To: References: Message-ID: Am 05.04.2007 um 19:10 schrieb J?nos: > I am trying to parse a string with the C library string function > strtok. Just one note: You really shouldn't be using strtok() if you can help it. It has some issues. If you check out the manpage for strtok you'll find that they actually recommend using strsep() instead. Cheers, -- M. Uli Kusterer http://www.zathras.de From kusterer at gmail.com Tue Apr 10 15:57:49 2007 From: kusterer at gmail.com (Uli Kusterer) Date: Tue Apr 10 15:58:18 2007 Subject: byteswap.h In-Reply-To: <246BFC2B-73A4-4574-B3D0-8CC5BB53E025@apple.com> References: <246BFC2B-73A4-4574-B3D0-8CC5BB53E025@apple.com> Message-ID: <831ACF71-9B6C-4B94-AAA1-52E5E325040F@gmail.com> Am 10.04.2007 um 23:34 schrieb Shantonu Sen: > You can create a byteswap.h that includes , > and implement whatever functions you need either as macros or > inline functions to call the libkern versions There's also an Endian.h header in Apple's frameworks (CoreServices, I think), which does Little/Big-to-native, always-swap and always-big-to-little (or the reverse), but the macros in there are probably named differently. Whatever way you choose, you can probably just create your own headers containing an #include and half a dozen #defines. Cheers, -- M. Uli Kusterer http://www.zathras.de From steinitz at datatactics.com.au Tue Apr 10 16:33:18 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Tue Apr 10 16:33:24 2007 Subject: Printing a database report In-Reply-To: Message-ID: Hello Andreas and List Members, On Tuesday, 10 April 2007 at 2:59 pm, Andreas Mayer wrote: > I mean "draw your content in a view the size of a page". I'm sure its all very simple but that is the part I don't understand. If I google for 'draw into a view' I get confusing answers. > I don't quite understand what you want me to tell you. Well, my printing code is in a view so I don't currently have to think about drawing into a view, I just call the view's drawing routines. I'm not sure how to draw into another view and then use that view to print in my 'printing' view. Again, I'm sure its all very simple but I'd appreciate any help in seeing the light. > Actually, you already made me say something I didn't mean. For that I am sorry :) > You do *not* have to make a single view per page. You *can*. But > it's really up to you. I am not clear on how to make a second view from inside my printing view and then draw to it. Nor even if that is the right way to think about it. I know its simple in principle but the printing system confuses me a bit. And yes, I realize that once I know how to work with the second view I will be able to decide whether I want one of them or many. Let me take a stab at answering my own question. Perhaps I've been thinking about it inside out. Rather than making a second view inside my printing view maybe I instead need to make a new, simpler printing view that has an instance of my existing printing view. When the printing system first calls my new view's drawrect, I call my existing view's drawRect with a very big rect then call setFrame with the rect from the printing system and return the visibleRect. On subsequent calls to drawRect I only have to call my existing view's setFrame and return the visibleRect Would that be the idea? If so, I don't need to try understand what you meant by 'draw your content into a view'. I can remain blissfully ignorant. Thanks to anyone on the list for any help, Steve From idiotsavant2005 at gmail.com Tue Apr 10 16:55:41 2007 From: idiotsavant2005 at gmail.com (I. Savant) Date: Tue Apr 10 16:55:39 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: <3409917E-E1BA-41F7-887D-BE05B6BEBF57@gmail.com> On Apr 10, 2007, at 7:33 PM, Steve Steinitz wrote: >> I mean "draw your content in a view the size of a page". > > I'm sure its all very simple but that is the part I don't understand. > If I google for 'draw into a view' I get confusing answers. That is why you need to read the documentation - it's also probably why Andreas is confused by your line of questioning, since it's clearly answered in the docs. To get you started: http://developer.apple.com/documentation/Cocoa/Conceptual/ CocoaDrawingGuide/index.html -- I.S. From aglee at earthlink.net Tue Apr 10 17:11:00 2007 From: aglee at earthlink.net (Andy Lee) Date: Tue Apr 10 17:11:31 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: <1AE9BE6B-209B-42CA-867D-58770D777A72@earthlink.net> I'm hardly a printing expert, but I do have questions about what's going on here... On Apr 8, 2007, at 8:53 PM, Steve Steinitz wrote: > That method works but because for each page I have to do hundreds of > fetches - all the fetches for the whole report - each page takes too > many seconds to image. Have you measured to be sure it's the fetches that are taking too long and not some accidentally slow drawing code? You're probably right -- I'm just asking as a sanity check. More importantly, *why* do you have to refetch on every page? Is it because you don't know in advance where the page breaks will be? I'm wondering why you can't fetch once at the beginning and then precompute everything that will be needed for all twenty pages. Aside from the question of when you execute drawing commands to render those twenty pages -- is there some data structure you could use to store their content, so you don't have to refetch on every page? For example, if you dataset is a million numbers, and each page contains a different weighted average of those numbers, you could compute the 20 weighted averages up front and keep them in an array, instead of refetching the million numbers each time you print a page. It might help if we understood something about the computations you are doing. > I have a nebulous idea that I could image the > whole report into a second view or perhaps to pdf or even to a > low-level graphics-system object... and then, when the printing system > calls my drawRect, I return rects of that intermediate object, page by > page. From this it sounds like you might indeed have enough data to render the whole report with just one fetch? If so, sure, you could create a big view up front that is the size of 20 pages, and pre-image the whole report. But that view will be expensive memory-wise. I don't think it buys you anything in terms of performance. --Andy From aglee at earthlink.net Tue Apr 10 17:13:38 2007 From: aglee at earthlink.net (Andy Lee) Date: Tue Apr 10 17:14:08 2007 Subject: Printing a database report In-Reply-To: <3409917E-E1BA-41F7-887D-BE05B6BEBF57@gmail.com> References: <3409917E-E1BA-41F7-887D-BE05B6BEBF57@gmail.com> Message-ID: On Apr 10, 2007, at 7:55 PM, I. Savant wrote: > On Apr 10, 2007, at 7:33 PM, Steve Steinitz wrote: >>> I mean "draw your content in a view the size of a page". >> >> I'm sure its all very simple but that is the part I don't understand. >> If I google for 'draw into a view' I get confusing answers. > > > That is why you need to read the documentation - it's also > probably why Andreas is confused by your line of questioning, I was confused by your confusion too. You said you already have pixel-level control of your report's output. How are you doing that -- how are you rendering your report at all -- if you aren't "drawing into a view"? --Andy From chad+macosx at objectwerks.com Tue Apr 10 19:20:38 2007 From: chad+macosx at objectwerks.com (Chad Leigh -- ObjectWerks Inc) Date: Tue Apr 10 19:20:44 2007 Subject: Printing a database report In-Reply-To: References: <3409917E-E1BA-41F7-887D-BE05B6BEBF57@gmail.com> Message-ID: On Apr 10, 2007, at 6:13 PM, Andy Lee wrote: > On Apr 10, 2007, at 7:55 PM, I. Savant wrote: >> On Apr 10, 2007, at 7:33 PM, Steve Steinitz wrote: >>>> I mean "draw your content in a view the size of a page". >>> >>> I'm sure its all very simple but that is the part I don't >>> understand. >>> If I google for 'draw into a view' I get confusing answers. >> >> >> That is why you need to read the documentation - it's also >> probably why Andreas is confused by your line of questioning, > > I was confused by your confusion too. You said you already have > pixel-level control of your report's output. How are you doing > that -- how are you rendering your report at all -- if you aren't > "drawing into a view"? > I think the issue is a terminology issue and not a technical issue. When I first started doing printing on OS X I was confused about "printing into a view" myself. I eventually sorted it out and got it working. Unfortunately I have not worked on that part of my app in some time and am in Japan on a laptop without my source so I cannot be more specific on what my confusions were. Chad From koryn.grant at gmail.com Tue Apr 10 23:35:00 2007 From: koryn.grant at gmail.com (Koryn Grant) Date: Tue Apr 10 23:35:46 2007 Subject: C strtok question In-Reply-To: References: Message-ID: <5E1E04C1-406C-43D8-A2A4-A71E79BABD13@gmail.com> On 6/04/2007, at 10:26 PM, Uli Kusterer wrote: > Am 05.04.2007 um 19:10 schrieb J?nos: >> I am trying to parse a string with the C library string function >> strtok. > > Just one note: You really shouldn't be using strtok() if you can > help it. It has some issues. If you check out the manpage for > strtok you'll find that they actually recommend using strsep() > instead. Not on the man page I have installed (stock standard Apple Developer Tools for OS X 10.4). However, I would recommend using strtok_r() instead of strtok(). Bugs involving nested calls to strtok() are not pleasant to track down. Cheers, Koryn From steinitz at datatactics.com.au Wed Apr 11 02:10:31 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Wed Apr 11 02:10:40 2007 Subject: Printing a database report Message-ID: Hello Andy, Thanks for your input. I'm going to briefly answer your questions and also show a solution that a friend of mine offered, having seen my struggles with expressing my question. On Tuesday, 10 April 2007 at 8:11 pm, Andy Lee wrote: > Have you measured to be sure it's the fetches that are taking too > long and not some accidentally slow drawing code? You're probably > right -- I'm just asking as a sanity check. Yes. But its a good point. Its not so much that each fetch takes very long but I end up doing hundreds of them. > More importantly, *why* do you have to refetch on every page? Is it > because you don't know in advance where the page breaks will be? Yes. I load objects grouped by a couple of attributes and print them with pretty labels at the top of each page based on the attributs. Its hard to know how big it will be and also hard to 'keep my place' for the next page. > I'm > wondering why you can't fetch once at the beginning and then > precompute everything that will be needed for all twenty pages. That's more or less what I want to do. But rather than 'compute everything that will be needed', which sounds hard, I want to just image it all somewhere and print bits of it as requested by the printing system. > Aside from the question of when you execute drawing commands to > render those twenty pages -- is there some data structure you could > use to store their content, so you don't have to refetch on every > page? Yes, I'm sure there is but that's a little project that neither I nor the client want to pay for at this point. I confess laziness. > For example, if you dataset is a million numbers, and each > page contains a different weighted average of those numbers, you > could compute the 20 weighted averages up front and keep them in an > array, instead of refetching the million numbers each time you print > a page. I may have misled you with earlier statements about computation. Its more formatting and pagination (my own) -- What titles to draw for subgroups, whether or not to start a new page after a group page number, date, headers... > It might help if we understood something about the computations you > are doing. That might be so if I was asking for a way to redo my report, but I'm not. Practical matters dictate that I am finished with the report, I just want to print it faster. > > I have a nebulous idea that I could image the > > whole report into a second view or perhaps to pdf or even to a > > low-level graphics-system object... and then, when the printing system > > calls my drawRect, I return rects of that intermediate object, page by > > page. > > From this it sounds like you might indeed have enough data to render > the whole report with just one fetch? Yes that's true and that's my desire -- if I understand you. But I'm wondering if I'm missing something in what you're saying because I don't understand the 'enough data to' part of it. > If so, sure, you could create a big view up front that is the size > of 20 pages, and pre-image the whole report. Yes, now you are singing my song :) > But that view will be expensive memory-wise. I don't think it buys > you anything in terms of performance. That's possible. Each page now takes about 5 seconds to print on a 1Ghz G4. I'd like to get it down to three seconds to image and 1 second per page. Even if virtual memory were getting bashed that would seem achievable. Now, having addressed your comments to some degree I will present a solution presented by my friend, Ross, for your perusal. Note especially the part about creating a PDF. That is along the lines of what I am seeking and indeed may be 'the go' (as they say here in Oz). Thanks, Steve --------------------------------------------------------------------- Hi Steve, I had a look at the thread for your printing problem. My thoughts: Uli Kusterer's first reply to your message seems like the correct answer to me: When your print view is instantiated cache all the data your going to need for the report printing. So can you cache the fetches? Or is this just too much data. You could (as you suggest) paginate the entire report into a PDF document, then, on demand, composite individual parts from the PDF into your print view but that doesn't seem like the right way to go (to me anyway). If you do want to create a PDF from a NSView have a look at NSView's dataWithPDFInsideRect. This will give you a big chunk of PDF data for your view. Create a NSImage using this data. In your print loop you'll need to calc the current page offset and draw just the required portion of the NSImage. Try [NSImage drawInRect:fromRect:operation:fraction] with the fromRect set to the correct offset. Hope this helps. Ross From steinitz at datatactics.com.au Wed Apr 11 02:11:12 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Wed Apr 11 02:11:21 2007 Subject: Printing a database report Message-ID: Hello, On Tuesday, 10 April 2007 at 7:55 pm, I. Savant wrote: > That is why you need to read the documentation - it's also > probably why Andreas is confused by your line of questioning, since > it's clearly answered in the docs. I looked at the docs listed below and would not agree that the exact thing I want to do is clearly answered in the docs. > To get you started: > > http://developer.apple.com/documentation/Cocoa/Conceptual/ > CocoaDrawingGuide/index.html That is indeed an interesting document. Particularly the section called Graphics Context Basics. However, having read it, I still feel I could benefit from the wisdom and experience of members of this list, should any of you feel so inclined.. Steve From steinitz at datatactics.com.au Wed Apr 11 02:21:35 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Wed Apr 11 02:21:41 2007 Subject: Printing a database report In-Reply-To: Message-ID: Hi Chad, On Tuesday, 10 April 2007 at 8:20 pm, Chad Leigh -- ObjectWerks Inc wrote: > I think the issue is a terminology issue and not a technical issue. Yes. I hesitated for six months to post this question because I couldn't decide on terminology and didn't want to start a snytactic storm. > When I first started doing printing on OS X I was confused about > "printing into a view" myself. I eventually sorted it out and got it > working. Unfortunately I have not worked on that part of my app in > some time and am in Japan on a laptop without my source so I cannot > be more specific on what my confusions were. Thank you for that commiseration. I have just finished a phone call with Ross, whose intelligence and Cocoa skill I greatly admire. I was pleased to note that even he had some hesitation with the specifics of the printing and imaging subsystems. I have clarified now it to some degree in my mind and will probably go ahead with his plan, presented in a earlier email. One key idea which I.Savant indirectly pointed out is that the results of a view's drawRect, whether during printing or not, ends up an a Graphics Context. If one were curious, one could while away many idle and pleasant days pondering and studying the exact meanings and implications of that. Steve From kusterer at gmail.com Wed Apr 11 02:27:51 2007 From: kusterer at gmail.com (Uli Kusterer) Date: Wed Apr 11 02:28:03 2007 Subject: C strtok question In-Reply-To: <5E1E04C1-406C-43D8-A2A4-A71E79BABD13@gmail.com> References: <5E1E04C1-406C-43D8-A2A4-A71E79BABD13@gmail.com> Message-ID: Am 11.04.2007 um 08:35 schrieb Koryn Grant: > Not on the man page I have installed (stock standard Apple > Developer Tools for OS X 10.4). > > However, I would recommend using strtok_r() instead of strtok(). > Bugs involving nested calls to strtok() are not pleasant to track > down. Well, I have the latest version installed (no modifications otherwise), and the first thing it says, in bold, under "DESCRIPTION" is "This interface is obsoleted by strsep(3)." Which is obvious when you read this part of strsep's manpage: The strsep() function is intended as a replacement for the strtok() func- tion. While the strtok() function should be preferred for portability reasons (it conforms to ISO/IEC 9899:1990 (``ISO C90'')) it is unable to handle empty fields, i.e., detect fields delimited by two adjacent delim- iter characters, or to be used for more than a single string at a time. The strsep() function first appeared in 4.4BSD. But you could do worse than using strtok_r(), obviously. By the way: If you're using Cocoa, you may want to look into NSScanner and NSString's componentsSeparatedByString:. Cheers, -- M. Uli Kusterer http://www.zathras.de From geowar at apple.com Wed Apr 11 09:10:52 2007 From: geowar at apple.com (George Warner) Date: Wed Apr 11 09:10:56 2007 Subject: C strtok question Message-ID: On Wed, 11 Apr 2007 18:35:00 +1200, Koryn Grant wrote: > On 6/04/2007, at 10:26 PM, Uli Kusterer wrote: >> Am 05.04.2007 um 19:10 schrieb J?nos: >>> I am trying to parse a string with the C library string function >>> strtok. >> >> Just one note: You really shouldn't be using strtok() if you can >> help it. It has some issues. If you check out the manpage for >> strtok you'll find that they actually recommend using strsep() >> instead. > > Not on the man page I have installed (stock standard Apple Developer > Tools for OS X 10.4). In the man page for strtok on 10.4.9: DESCRIPTION This interface is obsoleted by strsep(3). and in the man page for strsep: HISTORY The strsep() function is intended as a replacement for the strtok() function. While the strtok() function should be preferred for portability reasons (it conforms to ISO/IEC 9899:1990 (``ISO C90'')) it is unable to handle empty fields, i.e., detect fields delimited by two adjacent delimiter characters, or to be used for more than a single string at a time. The strsep() function first appeared in 4.4BSD. > However, I would recommend using strtok_r() instead of strtok(). > Bugs involving nested calls to strtok() are not pleasant to track down. strsep is reentrant (no _r variant is necessary). -- Enjoy, George Warner, Schizophrenic Optimization Scientist Apple Developer Technical Support (DTS) From johankool at gmail.com Wed Apr 11 09:34:36 2007 From: johankool at gmail.com (Johan Kool) Date: Wed Apr 11 09:34:39 2007 Subject: Printing a database report In-Reply-To: References: Message-ID: Hello Steve, You say that you draw everything for every page on every call of drawRect: (which happens for each page when printing). This causes your printing time to be very long. I didn't see it explicitly mentioned in the other responses, but the thing you should do is to only draw that part of the view that is needed for the rect (for each subsequent page) that the method drawRect: gives you. So in your drawRect: implementation of your custom view, check what data you need to fetch to draw that particular rect and only worry about fetching that data. If for some reason you need to draw everything at once, you could try to fetch the pdf representation before the print operation starts and only draw the needed part of the pdf when requested for it in your drawRect method. The dataWithPDFInsideRect: method is very useful for this, but it uses a print operation, and since there can be only one print operation on a single thread you have to either fetch the whole pdf before you start the print operation, or do the fetching in a separate thread. The former has as disadvantage that you do a lot of work, even if the users is not going to print after all (clicks Cancel) or only wants a few pages. The latter is using threading, which has many pitfalls too. Code snippet for using dataWithPDFInsideRect: NSData *data = [yourView dataWithPDFInsideRect:[yourView frame]]; NSPDFImageRep* pdfRep = [NSPDFImageRep imageRepWithData:data]; // Create a new image to hold the PDF representation. NSRect yourBounds = [yourView bounds]; [yourImage setSize: yourBounds.size]; [yourImage addRepresentation:pdfRep]; Reading back, I see part of what I wrote here you already know. But I figured you might want to know about the single print operation per thread anyway. Hope this helps. Johan Kool --- http://www.johankool.nl/ From leeg at thaesofereode.info Wed Apr 11 09:40:29 2007 From: leeg at thaesofereode.info (Graham J Lee) Date: Wed Apr 11 09:40:38 2007 Subject: C strtok question In-Reply-To: References: <5E1E04C1-406C-43D8-A2A4-A71E79BABD13@gmail.com> Message-ID: <62E94334-D7A8-4408-91A6-FE5D8C629F79@thaesofereode.info> On 11 Apr 2007, at 10:27, Uli Kusterer wrote: > > But you could do worse than using strtok_r(), obviously. On Darwin as with other systems, won't that be automatic if you - DREENTRANT ? Graham. From janos.lobb at yale.edu Wed Apr 11 09:57:22 2007 From: janos.lobb at yale.edu (=?ISO-8859-1?Q?J=E1nos?=) Date: Wed Apr 11 09:57:22 2007 Subject: C strtok question In-Reply-To: References: Message-ID: <8B5F4A34-7FF9-411E-8E42-49CEDB2C2C49@yale.edu> Thank you all who responded. I am in the process to rewrite it with strsep. I have an additional newbie question. As I am doing the parsing and getting the values, I have to convert some of them to uint16 and some of them to uint36. Being a newbie and reading just the K&R book, I am using atoi or atol and do a type cast before them. Like: lj = (uint32)atol(tokenval); or qs = (uint16)atoi(tokenval); where lj is declared uint32 and qs is declared uint16. However someting is not quite right because the compiled library function to whom I pass these values are not performing the same way as if I just do a direct assignment like lj = 3; and use that lj to pass it to the compiled library function. Of course the man page says the following about the atoi function: The atoi() function has been deprecated by strtol() and should not be used in new code. So if I replace atoi with strtol how do I get an uint16 or uint32 from that int that strtol gives. Thanks ahead, J?nos P.S It is just pure C code, a wrapper to a compiled C dylib used from Java via JNI :)..., so I do not think that I can use Cocoa here. On Apr 11, 2007, at 12:10 PM, George Warner wrote: > On Wed, 11 Apr 2007 18:35:00 +1200, Koryn Grant > > wrote: >> On 6/04/2007, at 10:26 PM, Uli Kusterer wrote: >>> Am 05.04.2007 um 19:10 schrieb J?nos: >>>> I am trying to parse a string with the C library string function >>>> strtok. >>> >>> Just one note: You really shouldn't be using strtok() if you can >>> help it. It has some issues. If you check out the manpage for >>> strtok you'll find that they actually recommend using strsep() >>> instead. >> >> Not on the man page I have installed (stock standard Apple Developer >> Tools for OS X 10.4). > > In the man page for strtok on 10.4.9: > > DESCRIPTION > This interface is obsoleted by strsep(3). > > and in the man page for strsep: > > HISTORY > The strsep() function is intended as a replacement for the > strtok() > function. While the strtok() function should be preferred for > portability reasons (it conforms to ISO/IEC 9899:1990 (``ISO > C90'')) it > is unable to handle empty fields, i.e., detect fields > delimited by two > adjacent delimiter characters, or to be used for more than a > single > string at a time. The strsep() function first appeared in 4.4BSD. > >> However, I would recommend using strtok_r() instead of strtok(). >> Bugs involving nested calls to strtok() are not pleasant to track >> down. > > strsep is reentrant (no _r variant is necessary). > > -- > Enjoy, > George Warner, > Schizophrenic Optimization Scientist > Apple Developer Technical Support (DTS) > > > > _______________________________________________ > MacOSX-dev mailing list > MacOSX-dev@omnigroup.com > http://www.omnigroup.com/mailman/listinfo/macosx-dev From matt at tidbits.com Wed Apr 11 10:20:48 2007 From: matt at tidbits.com (Matt Neuburg) Date: Wed Apr 11 10:21:29 2007 Subject: Printing a database report Message-ID: On Wed, 11 Apr 2007 19:10:31 +1000, Steve Steinitz said: >> For example, if you dataset is a million numbers, and each >> page contains a different weighted average of those numbers, you >> could compute the 20 weighted averages up front and keep them in an >> array, instead of refetching the million numbers each time you print >> a page. > >I may have misled you with earlier statements about computation. >Its more formatting and pagination (my own) -- What titles to draw >for subgroups, whether or not to start a new page after a group >page number, date, headers... I've been hanging back, waiting for you to clarify your question. Even after this clarification, I'm *still* not sure that what I'm about to say is going to be speaking to your actual problem / situation. So if not, just ignore it. What I'd like to point out is that printing can be an object-oriented activity. I think many beginners make the mistake of thinking that the way you print is to put all the code into one massive drawRect. But you don't have to do it that way at all. I never do it that way. :) What you do have to do is supply an NSView. But an NSView is just a canvas, and you can fill it with other stuff than explicit drawing instructions. In particular, you can can fill it with other NSViews (subviews). And those NSViews can themselves be composed of NSViews (subviews). You construct this setup exactly the same way you'd construct a window's content in code, i.e. by making each view and calling addSubview. The idea is that at the lowest level each subview knows how to draw itself. In fact, in many cases you can use an existing view type, or a nib, so that a subview knows how to draw itself without your even writing any code. Plus, each subview knows what to do if the printing mechanism wants to insert a page break inside it (adjustPageHeightNew:). Higher level drawRect calls are empty. Now, all of these subviews get created by the top-level view's init. At that time, each subview works out its own size and what gets drawn inside itself. All of that happens just once, so there is a meaningful sense in which the repetition and recalculation you're talking about goes away. m. -- matt neuburg, phd = matt@tidbits.com, A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! From koryn.grant at gmail.com Wed Apr 11 12:36:20 2007 From: koryn.grant at gmail.com (Koryn Grant) Date: Wed Apr 11 17:11:40 2007 Subject: C strtok question In-Reply-To: References: <5E1E04C1-406C-43D8-A2A4-A71E79BABD13@gmail.com> Message-ID: On 11/04/2007, at 9:27 PM, Uli Kusterer wrote: > But you could do worse than using strtok_r(), obviously. By the > way: If you're using Cocoa, you may want to look into NSScanner and > NSString's componentsSeparatedByString:. For the majority of my (non-Java) development portability is a priority, so I stick to ISO C and SUSv3 as closely as possible. Hence my preference for strtok_r() over strtok() or strsep(). Cheers, Koryn From steinitz at datatactics.com.au Thu Apr 12 05:37:15 2007 From: steinitz at datatactics.com.au (Steve Steinitz) Date: Thu Apr 12 05:37:37 2007 Subject: Printing a database report In-Reply-To: Message-ID: Hi Matt, Thanks for your reply. Please forgive a rare instance of top posting on my part. (I'm the sworn enemy of top-posting.) But your email is so perfectly written and genteel that I didn't want to crudely insert any comments into it. I confess I had not thought of your idea. Thinking about it I realize that I do actually print in sections. I make queries to the database for chunks of my objects based on each object's 'type' and whether it is relevant to men, women, boys or girls. I could prebuild little views that contained each of those little sections and subsections. I suppose I would then put references to all the little views into a dictionary or similar for access when the printing system took over the show. The little views would all be of the same class and would have the printing logic currently contained in my main printing view except for the fetching logic which I would move to a new 'main' printing view. Maybe the main view would also handle page headings and similar. I like it. The only thing I'm still unclear on is, and this is hard to express, how exactly one would go about simulating, for the little views, the graphics context etc that the printing system provides provides for the main printing view -- or if indeed that is an issue at all. Thanks and best regards, Steve On Wednesday, 11 April 2007 at 10:20 am, Matt Neuburg wrote: > On Wed, 11 Apr 2007 19:10:31 +1000, Steve Steinitz > said: > >> For example, if you dataset is a million numbers, and each > >> page contains a different weighted average of those numbers, you > >> could compute the 20 weighted averages up front and keep them in an > >> array, instead of refetching the million numbers each time you print > >> a page. > > > >I may have misled you with earlier statements about computation. > >Its more formatting and pagination (my own) -- What titles to draw > >for subgroups, whether or not to start a new page after a group > >page number, date, headers... > > I've been hanging back, waiting for you to clarify your question. Even after > this clarification, I'm *still* not sure that what I'm about to say is going > to be speaking to your actual problem / situation. So if not, just ignore > it. > > What I'd like to point out is that printing can be an object-oriented > activity. I think many beginners make the mistake of thinking that the way > you print is to put all the code into one massive drawRect. But you don't > have to do it that way at all. I never do it that way. :) > > What you do have to do is supply an NSView. But an NSView is just a canvas, > and you can fill it with other stuff than explicit drawing instructions. In > particular, you can can fill it with other NSViews (subviews). And those > NSViews can themselves be composed of NSViews (subviews). You construct this > setup exactly the same way you'd construct a window's content in code, i.e. > by making each view and calling addSubview. > > The idea is that at the lowest level each subview knows how to draw itself. > In fact, in many cases you can use an existing view type, or a nib, so that > a subview knows how to draw itself without your even writing any code. Plus, > each subview knows what to do if the printing mechanism wants to insert a > page break inside it (adjustPageHeightNew:). Higher level drawRect calls are > empty. > > Now, all of these subviews get created by the top-level view's init. At that > time, each subview works out its own size and what gets drawn inside itself. > All of that happens just once, so there is a meaningful sense in which the > repetition and recalculation you're talking about goes away. > > m. > From llothar at web.de Sat Apr 14 22:05:53 2007 From: llothar at web.de (Lothar Scholz) Date: Sat Apr 14 08:07:32 2007 Subject: Is there something like "kdesu" on MacOSX Message-ID: <165503865.20070414220553@web.de> Hello MacOSX-Dev, I need to run a script with root rights. On Linux it is easy to use either "gtksu" or "kdesu" which both show the common dialog, ask for the password and then executes the command with correctly set user id. What is the equivalent on MacOSX ? -- Best regards, Lothar mailto:llothar@web.de From shawnce at gmail.com Sat Apr 14 08:22:59 2007 From: shawnce at gmail.com (Shawn Erickson) Date: Sat Apr 14 08:23:05 2007 Subject: Is there something like "kdesu" on MacOSX In-Reply-To: <165503865.20070414220553@web.de> References: <165503865.20070414220553@web.de> Message-ID: On Apr 14, 2007, at 10:05 PM, Lothar Scholz wrote: > Hello MacOSX-Dev, > > I need to run a script with root rights. On Linux it is easy to use > either "gtksu" or "kdesu" which both show the common dialog, ask > for the password and then executes the command with correctly set > user id. > > What is the equivalent on MacOSX ? I don't think a command-line graphical tool directly exists, at least not one that Apple provides as a support method on Mac OS X. Review the following for a supported method... -Shawn From incanus at codesorcery.net Mon Apr 16 06:45:05 2007 From: incanus at codesorcery.net (Justin R. Miller) Date: Mon Apr 16 06:45:18 2007 Subject: Is there something like "kdesu" on MacOSX In-Reply-To: <165503865.20070414220553@web.de> References: <165503865.20070414220553@web.de> Message-ID: <5FB840A4-745C-40D2-9F8A-8053A5E84D70@codesorcery.net> On Apr 15, 2007, at 1:05 AM, Lothar Scholz wrote: > Hello MacOSX-Dev, > > I need to run a script with root rights. On Linux it is easy to use > either "gtksu" or "kdesu" which both show the common dialog, ask > for the password and then executes the command with correctly set > user id. > > What is the equivalent on MacOSX ? I came across this a few years ago: http://personalpages.tds.net/~brian_hill/pseudo.html However, I don't think it's been updating very recently. -- Justin R. Miller Code Sorcery Workshop http://codesorcery.net From llothar at web.de Mon Apr 16 23:43:33 2007 From: llothar at web.de (Lothar Scholz) Date: Mon Apr 16 09:47:08 2007 Subject: Passing command line arguments to a carbon app Message-ID: <1478539097.20070416234333@web.de> Hello MacOSX-Dev, I'm starting porting the GUI of an app now and wonder if there is a way to pass arguments to main. I tried it with "open my.app test1" but the system tells me that "test1" is not a file (it is the name of a test case) and if i pass a file i get something that is -psn_0_14548993. Any workaround available ? -- Best regards, Lothar mailto:llothar@web.de From llothar at web.de Mon Apr 16 23:46:18 2007 From: llothar at web.de (Lothar Scholz) Date: Mon Apr 16 09:47:38 2007 Subject: Is there something like "kdesu" on MacOSX In-Reply-To: <5FB840A4-745C-40D2-9F8A-8053A5E84D70@codesorcery.net> References: <165503865.20070414220553@web.de> <5FB840A4-745C-40D2-9F8A-8053A5E84D70@codesorcery.net> Message-ID: <863930582.20070416234618@web.de> Hello Justin, Monday, April 16, 2007, 6:45:05 AM, you wrote: JRM> On Apr 15, 2007, at 1:05 AM, Lothar Scholz wrote: >> Hello MacOSX-Dev, >> >> I need to run a script with root rights. On Linux it is easy to use >> either "gtksu" or "kdesu" which both show the common dialog, ask >> for the password and then executes the command with correctly set >> user id. >> >> What is the equivalent on MacOSX ? JRM> I came across this a few years ago: JRM> http://personalpages.tds.net/~brian_hill/pseudo.html JRM> However, I don't think it's been updating very recently. Thanks, in the meantime i found the code for sudo as an example in -- Best regards, Lothar mailto:llothar@web.de From shawnce at gmail.com Mon Apr 16 09:55:24 2007 From: shawnce at gmail.com (Shawn Erickson) Date: Mon Apr 16 09:55:27 2007 Subject: Passing command line arguments to a carbon app In-Reply-To: <1478539097.20070416234333@web.de> References: <1478539097.20070416234333@web.de> Message-ID: On 4/16/07, Lothar Scholz wrote: > Hello MacOSX-Dev, > > I'm starting porting the GUI of an app now and wonder if there is a > way to pass arguments to main. I tried it with "open my.app test1" > but the system tells me that "test1" is not a file (it is the name of > a test case) and if i pass a file i get something that is > -psn_0_14548993. > > Any workaround available ? To make sure you are going down the right path. What are you trying to achieve by passing command line options to your application? On Mac OS X you generally never pass information via command-line args to a graphical application... so knowing what you want are attempting to do will help use answer the correct way to do this type of thing on Mac OS X. The "open" command behaves as if the user double-clicked on your application or on a file that your application is a viewer or editor of. This is different then attempting to run your application as a traditional command-line tool (which you can do by actually running the executable itself directly from the command-line however as I said before that is non-standard). -Shawn From shawnce at gmail.com Mon Apr 16 10:02:22 2007 From: shawnce at gmail.com (Shawn Erickson) Date: Mon Apr 16 10:02:27 2007 Subject: Passing command line arguments to a carbon app In-Reply-To: References: <1478539097.20070416234333@web.de> Message-ID: On 4/16/07, Shawn Erickson wrote: > On 4/16/07, Lothar Scholz wrote: > > Hello MacOSX-Dev, > > > > I'm starting porting the GUI of an app now and wonder if there is a > > way to pass arguments to main. I tried it with "open my.app test1" > > but the system tells me that "test1" is not a file (it is the name of > > a test case) and if i pass a file i get something that is > > -psn_0_14548993. > > > > Any workaround available ? > > To make sure you are going down the right path. What are you trying to > achieve by passing command line options to your application? On Mac OS > X you generally never pass information via command-line args to a > graphical application... so knowing what you want are attempting to do > will help use answer the correct way to do this type of thing on Mac > OS X. > > The "open" command behaves as if the user double-clicked on your > application or on a file that your application is a viewer or editor > of. This is different then attempting to run your application as a > traditional command-line tool (which you can do by actually running > the executable itself directly from the command-line however as I said > before that is non-standard). If you want to send in command-line options as part of development work or testing then you can do it as follows in a shell (Terminal.app)... > ./MyApplication.app/Contents/MacOS/MyApplication It is important to understand that doing things this way results in your application running in a way different then the user double-clicking on it. For example working directory, environment vars, stdout/in, etc. will be different. -Shawn From llothar at web.de Tue Apr 17 00:23:15 2007 From: llothar at web.de (Lothar Scholz) Date: Mon Apr 16 10:24:36 2007 Subject: Passing command line arguments to a carbon app In-Reply-To: References: <1478539097.20070416234333@web.de> Message-ID: <55495820.20070417002315@web.de> Hello Shawn, SE> If you want to send in command-line options as part of development SE> work or testing then you can do it as follows in a shell SE> (Terminal.app)... Yes that's the purpose. >> ./MyApplication.app/Contents/MacOS/MyApplication SE> It is important to understand that doing things this way results in SE> your application running in a way different then the user SE> double-clicking on it. For example working directory, environment SE> vars, stdout/in, etc. will be different. AFAIK then the GUI does not work anymore (i tried some time ago on 10.3). So it seems that i write a little startscript that wraps the test arguments into environment variables. Is it possible or are the environment variables also not taken from the starting terminal process (i would now guess so). -- Best regards, Lothar mailto:llothar@web.de From dunham at mac.com Mon Apr 16 10:35:47 2007 From: dunham at mac.com (David Dunham) Date: Mon Apr 16 10:36:00 2007 Subject: Passing command line arguments to a carbon app In-Reply-To: <1478539097.20070416234333@web.de> References: <1478539097.20070416234333@web.de> Message-ID: On 16 Apr 2007, at 23:43, Lothar Scholz wrote: > I'm starting porting the GUI of an app now and wonder if there is a > way to pass arguments to main. I tried it with "open my.app test1" > but the system tells me that "test1" is not a file (it is the name of > a test case) and if i pass a file i get something that is > -psn_0_14548993. I'm pretty sure the answer is "no," depending on exactly what you want to do. > Any workaround available ? Send an 'open' Apple Event if you're trying to open a file. (Most GUI apps need to be able to open documents at times other than launch...) ------------ David Dunham dunham@mac.com http://www.pensee.com/dunham/ "No matter how far you have gone on a wrong road, turn back." - Turkish proverb From shawnce at gmail.com Mon Apr 16 11:10:58 2007 From: shawnce at gmail.com (Shawn Erickson) Date: Mon Apr 16 11:11:02 2007 Subject: Passing command line arguments to a carbon app In-Reply-To: <55495820.20070417002315@web.de> References: <1478539097.20070416234333@web.de> <55495820.20070417002315@web.de> Message-ID: On 4/17/07, Lothar Scholz wrote: > Hello Shawn, > > SE> If you want to send in command-line options as part of development > SE> work or testing then you can do it as follows in a shell > SE> (Terminal.app)... > > Yes that's the purpose. > > >> ./MyApplication.app/Contents/MacOS/MyApplication > > SE> It is important to understand that doing things this way results in > SE> your application running in a way different then the user > SE> double-clicking on it. For example working directory, environment > SE> vars, stdout/in, etc. will be different. > > AFAIK then the GUI does not work anymore (i tried some time ago on > 10.3). Humm... it works fine for Cocoa application maybe a Carbon specific issue? > So it seems that i write a little startscript that wraps the test > arguments into environment variables. Is it possible or are the > environment variables also not taken from the starting terminal > process (i would now guess so). If you are using Xcode to run your application you can modify the way it executes your application. Look for the "Executables" group and then double click on your application (or command-I). -Shawn From llothar at web.de Tue Apr 17 01:24:54 2007 From: llothar at web.de (Lothar Scholz) Date: Mon Apr 16 11:26:23 2007 Subject: Passing command line arguments to a carbon app In-Reply-To: References: <1478539097.20070416234333@web.de> <55495820.20070417002315@web.de> Message-ID: <501957134.20070417012454@web.de> Hello Shawn, Monday, April 16, 2007, 11:10:58 AM, you wrote: SE> If you are using Xcode to run your application you can modify the way SE> it executes your application. Look for the "Executables" group and SE> then double click on your application (or command-I). No Xcode here. I'm using my own Eiffel compiler from command line. Only IB to create NIB's. I need a test control program (a ruby ones) on the command line that runs executables with different input values. My next try was to store them in a file relative to the current directory, but the current directory of a carbon app is always '/'. But luckily the environment variables are taken from the shell, so i only need to write a small bash script that converts arguments into envs and restore them in the carbon apps main. -- Best regards, Lothar mailto:llothar@web.de From leeg at thaesofereode.info Mon Apr 16 12:16:08 2007 From: leeg at thaesofereode.info (Graham J Lee) Date: Mon Apr 16 12:16:24 2007 Subject: Passing command line arguments to a carbon app In-Reply-To: <1478539097.20070416234333@web.de> References: <1478539097.20070416234333@web.de> Message-ID: <0DB36088-0235-4279-8976-CB3003E5564D@thaesofereode.info> On 17 Apr 2007, at 07:43, Lothar Scholz wrote: > Hello MacOSX-Dev, > > I'm starting porting the GUI of an app now and wonder if there is a > way to pass arguments to main. I tried it with "open my.app test1" > but the system tells me that "test1" is not a file (it is the name of > a test case) and if i pass a file i get something that is > -psn_0_14548993. > > Any workaround available ? Note that Cocoa tries to consume app arguments as one of the app's defaults domains, so that you can do things like: /Applications/Foo.app/Contents/MacOS/Foo -Wibble 1 then use the NSUserDefaults' -integerForKey:@"Wibble" or whatever. Cheers, Graham. From kusterer at gmail.com Tue Apr 17 17:15:28 2007 From: kusterer at gmail.com (Uli Kusterer) Date: Tue Apr 17 17:15:48 2007 Subject: Passing command line arguments to a carbon app In-Reply-To: <501957134.20070417012454@web.de> References: <1478539097.20070416234333@web.de> <55495820.20070417002315@web.de> <501957134.20070417012454@web.de> Message-ID: <06293CF2-EDA6-4E62-B105-B90A24697F1B@gmail.com> Am 17.04.2007 um 10:24 schrieb Lothar Scholz: > No Xcode here. I'm using my own Eiffel compiler from command line. > Only IB to create NIB's. Is your app bundled, or not? AFAIK the GUI issues were corrected for 10.3 or 10.4, but if your app isn't in a bundle or does some other things in a nonstandard way, you might still get problems that look similar. > I need a test control program (a ruby ones) on the command line that > runs executables with different input values. My next try was to > store them in a file relative to the current directory, but the > current directory of a carbon app is always '/'. Not always. Just when launched by the Finder. Some applications change their current directory themselves, Xcode sets it to the Release or Debug folders... in short, you can't rely on the current directory. Instead, put support files in your bundle's "Resources" folder and get its URL based on your application's path, or better via CFBundle or NSBundle. Cheers, -- M. Uli Kusterer http://www.zathras.de From llothar at web.de Wed Apr 18 22:20:12 2007 From: llothar at web.de (Lothar Scholz) Date: Wed Apr 18 08:21:34 2007 Subject: GUI design question Message-ID: <597095246.20070418222012@web.de> Hello MacOSX-Dev, How do you handle complex (preferences) dialog windows? The HI Design Guide tells me the settings should apply immediately. On windows i have an apply button at the bottom the items (all my settings dialogs are already non-modal). But the settings might have dependencies and are invalid if a value in one control does not fit together with the value in another control. So when the user hits "Apply" or "Okay" an alert box might come up telling the user about the error and nothing is changed. BTW: i have little error indicator icons near the controls for immediate visual cues if the input is correct. So how to do this on Apple Systems? First i thought i catch an window decativated event and apply the settings at that time. But with the alert that may come up i guess it is confusing to people. But this would at least be good for applying values from TextControls (where it is unclear when the user has finished its typing). What do you recommend? -- Best regards, Lothar mailto:llothar@web.de From fabianschuiki at bluewin.ch Wed Apr 18 08:43:15 2007 From: fabianschuiki at bluewin.ch (Fabian Schuiki) Date: Wed Apr 18 08:43:22 2007 Subject: GUI design question In-Reply-To: <597095246.20070418222012@web.de> References: <597095246.20070418222012@web.de> Message-ID: <2F27C8FD-5FA7-4028-BBB8-5BD704B758D3@bluewin.ch> Hi, Use Cocoa Bindings to bind the element's enable property to other elements. Do this in a way that if the user clicks or checkes something, the settings that would collide with that checkbox are being deactivated (disabled). Remember that changes to the user defaults should not apply immediately. So if you store anything in your user defaults using NSUserDefaults, the values are being hold temporarly until the app is being quit properly, at which time the settings are stored. If you show your alert box, make to have the previous defaults stored somewhere, so that you can restore the settings that worked before the alert appeared. Alert boxes are, anyway, not the best way to do this. I think the best approach would be to enable and disable certain elements depending on the value of others. Best, Fabian Fabian Schuiki fabianschuiki@bluewin.ch Am 19.04.2007 um 07:20 schrieb Lothar Scholz: > Hello MacOSX-Dev, > > How do you handle complex (preferences) dialog windows? > > The HI Design Guide tells me the settings should apply immediately. > On windows i have an apply button at the bottom the items (all my > settings > dialogs are already non-modal). But the settings might have > dependencies and > are invalid if a value in one control does not fit together with the > value in another control. So when the user hits "Apply" or "Okay" > an alert box > might come up telling the user about the error and nothing is changed. > BTW: i have little error indicator icons near the controls for > immediate > visual cues if the input is correct. > > So how to do this on Apple Systems? > > First i thought i catch an window decativated event and apply the > settings at that time. But with the alert that may come up i guess > it is confusing to people. But this would at least be good for > applying values from TextControls (where it is unclear when the > user has finished its typing). > > What do you recommend? > > -- > Best regards, > Lothar mailto:llothar@web.de > > _______________________________________________ > MacOSX-dev mailing list > MacOSX-dev@omnigroup.com > http://www.omnigroup.com/mailman/listinfo/macosx-dev From idiotsavant2005 at gmail.com Wed Apr 18 08:54:03 2007 From: idiotsavant2005 at gmail.com (I. Savant) Date: Wed Apr 18 08:54:07 2007 Subject: GUI design question In-Reply-To: <597095246.20070418222012@web.de> References: <597095246.20070418222012@web.de> Message-ID: Lothar: On 4/19/07, Lothar Scholz wrote: > So how to do this on Apple Systems? > Definitely get rid of the apply button. :-) I recommend using KVO/KVC and Bindings (read the documentation for details). This allows you to use NSUserDefaultsController to apply preference changes immediately. It also allows you to use the validation method -validateValue:forKeyPath:error: to take immediate corrective action. See this doc for a good overview of the process: http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/MessageFlow.html Without specific details about some of the settings and the nature of their dependencies, that's about as detailed as anybody can get. -- I.S. From llothar at web.de Thu Apr 19 00:33:14 2007 From: llothar at web.de (Lothar Scholz) Date: Wed Apr 18 10:34:52 2007 Subject: GUI design question In-Reply-To: References: <597095246.20070418222012@web.de> Message-ID: <1286654311.20070419003314@web.de> Hello I., Wednesday, April 18, 2007, 8:54:03 AM, you wrote: IS> Lothar: IS> On 4/19/07, Lothar Scholz wrote: >> So how to do this on Apple Systems? >> IS> Definitely get rid of the apply button. :-) Advise acknowledged. IS> I recommend using KVO/KVC and Bindings (read the documentation for IS> details). This allows you to use NSUserDefaultsController to apply IS> preference changes immediately. It also allows you to use the IS> validation method -validateValue:forKeyPath:error: to take immediate IS> corrective action. See this doc for a good overview of the process: IS> http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/MessageFlow.html IS> Without specific details about some of the settings and the nature IS> of their dependencies, that's about as detailed as anybody can get. Okay one example (by the way it is the port of http://www.ruby-ide.com). In this IDE the user can start a tool program and the output is parsed by an regexpr to catch error messages for example from gcc. So one of the configuration dialogs is the parameters for the start of external programs and one option is a checkbox to mark that a regexpr is used. I enable the text field only when the checkbox is checked. If the textfield with the regexpr contains a syntax error a small indicator error icon will appear to the right of the text field, giving a visual clue. In this case, if there is an error and the user want to run this program. What is the most expected behaviour of a MacOSX application: 1) Interrupt the workflow of the user and tell him his input is incorrect (at least issue a warning). 2) Don't run the program and show an alert box that the output will not be parsed correctly because the regexpr is invalid. Means: check preferences before the first use. 3) Run the program and the user will see it on his own because the error lines in the output are not highlighted. Let him guess that this have to do with his wrong input. Thats only one example (it's the current part i'm working on it) but i think this catches a lot of common preference settings problem i have at the moment. By the way: should a preference window have a "reset" button to revert all the options to the time when the dialog was shown the first time? -- Best regards, Lothar mailto:llothar@web.de From llothar at web.de Thu Apr 19 00:33:12 2007 From: llothar at web.de (Lothar Scholz) Date: Wed Apr 18 10:37:40 2007 Subject: GUI design question In-Reply-To: <2F27C8FD-5FA7-4028-BBB8-5BD704B758D3@bluewin.ch> References: <597095246.20070418222012@web.de> <2F27C8FD-5FA7-4028-BBB8-5BD704B758D3@bluewin.ch> Message-ID: <1885586365.20070419003312@web.de> Hello Fabian, Wednesday, April 18, 2007, 8:43:15 AM, you wrote: FS> Hi, FS> Use Cocoa Bindings to bind the element's enable property to other FS> elements. Do this in a way that if the user clicks or checkes FS> something, the settings that would collide with that checkbox are FS> being deactivated (disabled). Sorry application logic is written in platform independent Eiffel code, Cocoa and Carbon is only under the surface. But i'm doing this already. Unfortunately enable/disable does not solve all cases. See my example in the next message (reply to I. Savant) FS> Remember that changes to the user defaults should not apply FS> immediately. So if you store anything in your user defaults using FS> NSUserDefaults, the values are being hold temporarly until the app is FS> being quit properly, Okay this is also different from windows. FS> at which time the settings are stored. If you FS> show your alert box, make to have the previous defaults stored FS> somewhere, so that you can restore the settings that worked before FS> the alert appeared. So you would say that the dialog window should be closed even with wrong settings? On windows i never close (only if user cancels) the window until it contains usefull data. -- Best regards, Lothar mailto:llothar@web.de From fabianschuiki at bluewin.ch Wed Apr 18 10:47:31 2007 From: fabianschuiki at bluewin.ch (Fabian Schuiki) Date: Wed Apr 18 10:47:54 2007 Subject: GUI design question In-Reply-To: <1885586365.20070419003312@web.de> References: <597095246.20070418222012@web.de> <2F27C8FD-5FA7-4028-BBB8-5BD704B758D3@bluewin.ch> <1885586365.20070419003312@web.de> Message-ID: <9D72B3FD-C243-454A-AD5A-894CEFB0FD3A@bluewin.ch> Hi, Try to solve as many cases as possible with enable/disable, for the other cases try to create some smooth visualization of the problem for the user, but avoid alert boxes as often as possible in Mac OS X. The idea of Aqua is to give the user immediate response whether his configuration of buttons and checkboxes works with other elements using things like enable/disable. To show/hide different elements to show the user what configurations are possible with which boxes checked or so. The idea behind the Mac OS X defaults system is to eliminate the risk of setting wrong defaults for your app which makes your app crash. Because the defaults are stored only if the application quits properly, settings that crash the app are not being stored and the app still opens after the crash. I think the OS also asks you after a crash whether you want to keep your new defaults, or restore the old ones. Is this all about a preferences panel or similar? If yes, have a look how complex apps like Photoshop solves this. Creating a System Prefs- like Preferences panel is quite useful in most cases ? given that your app has many settings to adjust. Best, Fabian Fabian Schuiki fabianschuiki@bluewin.ch Am 19.04.2007 um 09:33 schrieb Lothar Scholz: > Hello Fabian, > > Wednesday, April 18, 2007, 8:43:15 AM, you wrote: > > FS> Hi, > > FS> Use Cocoa Bindings to bind the element's enable property to other > FS> elements. Do this in a way that if the user clicks or checkes > FS> something, the settings that would collide with that checkbox are > FS> being deactivated (disabled). > > Sorry application logic is written in platform independent Eiffel > code, Cocoa and Carbon is only under the surface. > > But i'm doing this already. Unfortunately enable/disable does not > solve all cases. See my example in the next message (reply to > I. Savant) > > FS> Remember that changes to the user defaults should not apply > FS> immediately. So if you store anything in your user defaults using > FS> NSUserDefaults, the values are being hold temporarly until the > app is > FS> being quit properly, > > Okay this is also different from windows. > > FS> at which time the settings are stored. If you > FS> show your alert box, make to have the previous defaults stored > FS> somewhere, so that you can restore the settings that worked before > FS> the alert appeared. > > So you would say that the dialog window should be closed even with > wrong settings? On windows i never close (only if user cancels) > the window until it contains usefull data. > > -- > Best regards, > Lothar mailto:llothar@web.de > From cmhofman at gmail.com Wed Apr 18 11:11:34 2007 From: cmhofman at gmail.com (Christiaan Hofman) Date: Wed Apr 18 11:11:44 2007 Subject: GUI design question In-Reply-To: <1885586365.20070419003312@web.de> References: <597095246.20070418222012@web.de> <2F27C8FD-5FA7-4028-BBB8-5BD704B758D3@bluewin.ch> <1885586365.20070419003312@web.de> Message-ID: <0244239B-61D0-42C4-B303-5AB04CC55AC1@gmail.com> On 19 Apr 2007, at 9:33 AM, Lothar Scholz wrote: > Hello Fabian, > > Wednesday, April 18, 2007, 8:43:15 AM, you wrote: > > FS> Hi, > > FS> Use Cocoa Bindings to bind the element's enable property to other > FS> elements. Do this in a way that if the user clicks or checkes > FS> something, the settings that would collide with that checkbox are > FS> being deactivated (disabled). > > Sorry application logic is written in platform independent Eiffel > code, Cocoa and Carbon is only under the surface. > > But i'm doing this already. Unfortunately enable/disable does not > solve all cases. See my example in the next message (reply to > I. Savant) > > FS> Remember that changes to the user defaults should not apply > FS> immediately. So if you store anything in your user defaults using > FS> NSUserDefaults, the values are being hold temporarly until the > app is > FS> being quit properly, > > Okay this is also different from windows. > > FS> at which time the settings are stored. If you > FS> show your alert box, make to have the previous defaults stored > FS> somewhere, so that you can restore the settings that worked before > FS> the alert appeared. > > So you would say that the dialog window should be closed even with > wrong settings? On windows i never close (only if user cancels) > the window until it contains usefull data. > These remarks are not really correct. User defaults can be saved during application run, not only when the app is quit (you, and any framework, can force it using -synchronize). The main point is: you don't know, so defaults on disk are not necessarily synchronized with defaults in the app. But I don't think this is relevant for any of this discussion, it is only relevant if you want to change the prefs outside the app (e.g. using 'defaults write'). So this does /not/ mean you should close a pref window with invalid settings. Committing the pref settings may not be an immediate synchronization, it /could/ be, and it will become persistent when you quit the app. You should always make sure committed prefs (saved to disk or not) are consistent. If a value is not consistent, you can show an alert where you can ask the user to either revert the setting to the last value or continue to edit (if that's possible). This is what the usual validation mechanism using bindings does. Christiaan > -- > Best regards, > Lothar mailto:llothar@web.de > > _______________________________________________ > MacOSX-dev mailing list > MacOSX-dev@omnigroup.com > http://www.omnigroup.com/mailman/listinfo/macosx-dev From llothar at web.de Thu Apr 19 02:22:59 2007 From: llothar at web.de (Lothar Scholz) Date: Wed Apr 18 12:24:23 2007 Subject: Carbon event loop porting question Message-ID: <1809168885.20070419022259@web.de> Hello macosx-dev, I don't want details, i just ask to see what overall design changes are required. On X11-Unix all toolkits have the feature that i can add a file descriptor (in my case a pipe that signals data is available from background worker threads) to the event loop. Is the same true for Carbon or do i have to rewrite this with special posted user event? -- Best regards, Lothar mailto:llothar@web.de From shawnce at gmail.com Wed Apr 18 13:17:15 2007 From: shawnce at gmail.com (Shawn Erickson) Date: Wed Apr 18 13:17:20 2007 Subject: Carbon event loop porting question In-Reply-To: <1809168885.20070419022259@web.de> References: <1809168885.20070419022259@web.de> Message-ID: On 4/19/07, Lothar Scholz wrote: > Hello macosx-dev, > > I don't want details, i just ask to see what overall design changes > are required. On X11-Unix all toolkits have the feature that i can add a > file descriptor (in my case a pipe that signals data is available > from background worker threads) to the event loop. > > Is the same true for Carbon or do i have to rewrite this with special > posted user event? Since you don't want details... yes and no... maybe. ;) For the details... -Shawn From leeg at thaesofereode.info Wed Apr 18 16:11:31 2007 From: leeg at thaesofereode.info (Graham J Lee) Date: Wed Apr 18 16:11:45 2007 Subject: Carbon event loop porting question In-Reply-To: <1809168885.20070419022259@web.de> References: <1809168885.20070419022259@web.de> Message-ID: <1F42C0A0-28B1-4C1C-95A9-2B0473374080@thaesofereode.info> On 19 Apr 2007, at 10:22, Lothar Scholz wrote: > Hello macosx-dev, > > I don't want details, i just ask to see what overall design changes > are required. On X11-Unix all toolkits have the feature that i can > add a > file descriptor (in my case a pipe that signals data is available > from background worker threads) to the event loop. > > Is the same true for Carbon or do i have to rewrite this with special > posted user event? I think you can do this with kqueue...at least, I'm currently reading chapter 15 of Mark Dalrymple's book and it looks like you can do this with kqueue ;-). Come back when I've finished the chapter or read the chapter yourself and find out... it's a very good read BTW... "Advanced Mac OS X Programming" by Dalrymple and Hillegass. Graham. From kusterer at gmail.com Thu Apr 19 00:17:23 2007 From: kusterer at gmail.com (Uli Kusterer) Date: Thu Apr 19 00:17:40 2007 Subject: GUI design question In-Reply-To: <1286654311.20070419003314@web.de> References: <597095246.20070418222012@web.de> <1286654311.20070419003314@web.de> Message-ID: Am 19.04.2007 um 09:33 schrieb Lothar Scholz: > 1) Interrupt the workflow of the user and tell him his input is > incorrect (at least issue a warning). Well, not while the user is typing, but a common technique is to do that either when the user removes the cursor from the field, or to prevent the user from closing the Prefs window unless something valid has been entered (offering to either return to the most recent valid value, or to not close and fix it). Personally I prefer the latter, because that means they'll be able to switch to another app while there's something invalid in the field (e.g. so they can look up the syntax of regular expressions on the web, or whatever). > 2) Don't run the program and show an alert box that the output will > not > be parsed correctly because the regexpr is invalid. Means: check > preferences before the first use. If you allow switching between windows while an invalid value is in the field, that might be a good idea. > 3) Run the program and the user will see it on his own because the > error lines in the output are not highlighted. Let him guess that this > have to do with his wrong input. Wouldn't do that. > By the way: should a preference window have a "reset" button to > revert all the options to the time when the dialog was shown the > first time? Usually, such a button is called "Revert", but yeah, it's not a bad idea. Some apps also have "Revert to Factory Settings", which is a related but different function. Cheers, -- M. Uli Kusterer http://www.zathras.de From kusterer at gmail.com Thu Apr 19 00:21:25 2007 From: kusterer at gmail.com (Uli Kusterer) Date: Thu Apr 19 00:21:43 2007 Subject: Carbon event loop porting question In-Reply-To: <1809168885.20070419022259@web.de> References: <1809168885.20070419022259@web.de> Message-ID: <6EBE6110-9005-422F-B663-C9991A1CC8C1@gmail.com> Am 19.04.2007 um 11:22 schrieb Lothar Scholz: > I don't want details, i just ask to see what overall design changes > are required. On X11-Unix all toolkits have the feature that i can > add a > file descriptor (in my case a pipe that signals data is available > from background worker threads) to the event loop. I think you can also do this with a CFRunLoop (and CFStream or whatever). Every CarbonEventLoop is eventually backed by a run loop, so you should be able to get at that somehow. Cheers, -- M. Uli Kusterer http://www.zathras.de From sstevenson at mac.com Thu Apr 19 00:32:51 2007 From: sstevenson at mac.com (Scott Stevenson) Date: Thu Apr 19 00:33:05 2007 Subject: Carbon event loop porting question In-Reply-To: <1F42C0A0-28B1-4C1C-95A9-2B0473374080@thaesofereode.info> References: <1809168885.20070419022259@web.de> <1F42C0A0-28B1-4C1C-95A9-2B0473374080@thaesofereode.info> Message-ID: <717EBDEC-947F-4514-A943-AE3CDA5B751F@mac.com> On Apr 18, 2007, at 4:11 PM, Graham J Lee wrote: > I think you can do this with kqueue...at least, I'm currently > reading chapter 15 of Mark Dalrymple's book and it looks like you > can do this with kqueue ;-). Come back when I've finished the > chapter or read the chapter yourself and find out... > > it's a very good read BTW... "Advanced Mac OS X Programming" by > Dalrymple and Hillegass. It's a fantastic book. Anybody past the beginner stages should get a copy. Not simply good information, but very well written. - Scott From cmhofman at gmail.com Thu Apr 19 05:06:51 2007 From: cmhofman at gmail.com (Christiaan Hofman) Date: Thu Apr 19 05:07:00 2007 Subject: Custom tool-tips Message-ID: <349B9D3C-4AE1-47F6-81EA-19714861748E@gmail.com> Hi list, I was wondering if anyone could give me some hint about implementing custom tool-tips for a view myself. I don't just mean supplying a string for a tooltip, that's easy, but custom managing and showing of tool-tips. Reason: my tool-tips are not simply strings, but are more involved (like images). Also due to an Apple bug we had to disable the standard tool-tips. We basically have the code for showing the tool-tip (a custom window subclass with a timer and animation), that works all nicely now. My question is about the event handling: how to catch the relevant events and when to show/hide the tool-tip window. Currently we use -mouseMoved: for that. That basically works, but it has one problem: it is only called when the view is first responder. Normal tool-tips are also shown when a view is not first responder, and I'd like to have that too. I also tried adding tracking rects and implementing -mouseEntered:/ Exited:. That has several problems of its own. The most important is that those are often delayed, giving an annoying lagging behavior, and also do not come in a logical order (I often get a sequence like entered-entered-exited-exited, even for non-overlapping rects). I wonder what the normal behavior for tooltips added using - addToolTipRect:owner:userData: does. Is it true that those are handled by the window, rather than the view? And most importantly: what events does the window(?) catch to support tool-tips, and when and how? Is this already in private methods before the event is further dispatched to the view hierarchy? Would it mean that I should subclass the window to simulate the normal tool-tip behavior (and the natural next question: how)? I would appreciate some hints to help me further. Christiaan From gerti at bitart.com Thu Apr 19 08:07:02 2007 From: gerti at bitart.com (Gerd Knops) Date: Thu Apr 19 08:13:42 2007 Subject: Custom tool-tips In-Reply-To: <349B9D3C-4AE1-47F6-81EA-19714861748E@gmail.com> References: <349B9D3C-4AE1-47F6-81EA-19714861748E@gmail.com> Message-ID: I would use a top-down approach: Subclass NSApplication, specifically - (void)sendEvent:(NSEvent *)anEvent This is where all events pass through. Here you can observe mouseMoved events. When the proper timing/pause is detected, find the window and view the mouse is over, and query the view for your custom ToolTip data. Gerd On Apr 19, 2007, at 7:06 AM, Christiaan Hofman wrote: > Hi list, > > I was wondering if anyone could give me some hint about > implementing custom tool-tips for a view myself. I don't just mean > supplying a string for a tooltip, that's easy, but custom managing > and showing of tool-tips. Reason: my tool-tips are not simply > strings, but are more involved (like images). Also due to an Apple > bug we had to disable the standard tool-tips. > > We basically have the code for showing the tool-tip (a custom > window subclass with a timer and animation), that works all nicely > now. > > My question is about the event handling: how to catch the relevant > events and when to show/hide the tool-tip window. > > Currently we use -mouseMoved: for that. That basically works, but > it has one problem: it is only called when the view is first > responder. Normal tool-tips are also shown when a view is not first > responder, and I'd like to have that too. > > I also tried adding tracking rects and implementing -mouseEntered:/ > Exited:. That has several problems of its own. The most important > is that those are often delayed, giving an annoying lagging > behavior, and also do not come in a logical order (I often get a > sequence like entered-entered-exited-exited, even for non- > overlapping rects). > > I wonder what the normal behavior for tooltips added using - > addToolTipRect:owner:userData: does. Is it true that those are > handled by the window, rather than the view? And most importantly: > what events does the window(?) catch to support tool-tips, and when > and how? Is this already in private methods before the event is > further dispatched to the view hierarchy? Would it mean that I > should subclass the window to simulate the normal tool-tip behavior > (and the natural next question: how)? > > I would appreciate some hints to help me further. > > Christiaan > > _______________________________________________ > MacOSX-dev mailing list > MacOSX-dev@omnigroup.com > http://www.omnigroup.com/mailman/listinfo/macosx-dev From cmhofman at gmail.com Fri Apr 20 09:13:29 2007 From: cmhofman at gmail.com (Christiaan Hofman) Date: Fri Apr 20 09:13:33 2007 Subject: Custom tool-tips In-Reply-To: References: <349B9D3C-4AE1-47F6-81EA-19714861748E@gmail.com> Message-ID: <20166d560704200913p2589ecf5s9e22471df4ade400@mail.gmail.com> (Solved) Thanks Gerd, but that sounds far too involved. It would require finding the relevant window and view under the mouse; I wouldn't even know how to do this (I can't find a hitTest method to find the top window ion the public API, and the -[NSView hitTest:] method should be send to the private root view of a window, as it seems to me). Also this would come for every mouseMoved, even ones completely unrelated to my windows. That's a lot of overhead. I have found a better solution using tracking rects. The buggy ordering of the entered/exited events can be worked around by ignoring mouseExited events that do not match the last mouseEntered event (yes, I consider this a bug). I found that the delay of these events was related to a queuing of mouseEntered/mouseExited (mouseMoved does not seem to be queued), and the delay was basically due to the drawing of a lot of tool-tips (the problem arises when moving the mouse fast over a lot of tracking rects). It is better to drop tool-tips when they come fast behind each other, as the system does. My idea to do this is to use a timer with a small time interval. This did not work at first because of a bug in NSTimer (class methods apparently ignore a sub-second time interval, but the init... method does not seem to be affected). But I've got that fixed now. Christiaan On 4/19/07, Gerd Knops wrote: > > I would use a top-down approach: > > Subclass NSApplication, specifically > > - (void)sendEvent:(NSEvent *)anEvent > > > This is where all events pass through. Here you can observe > mouseMoved events. When the proper timing/pause is detected, find the > window and view the mouse is over, and query the view for your custom > ToolTip data. > > Gerd > > On Apr 19, 2007, at 7:06 AM, Christiaan Hofman wrote: > > > Hi list, > > > > I was wondering if anyone could give me some hint about > > implementing custom tool-tips for a view myself. I don't just mean > > supplying a string for a tooltip, that's easy, but custom managing > > and showing of tool-tips. Reason: my tool-tips are not simply > > strings, but are more involved (like images). Also due to an Apple > > bug we had to disable the standard tool-tips. > > > > We basically have the code for showing the tool-tip (a custom > > window subclass with a timer and animation), that works all nicely > > now. > > > > My question is about the event handling: how to catch the relevant > > events and when to show/hide the tool-tip window. > > > > Currently we use -mouseMoved: for that. That basically works, but > > it has one problem: it is only called when the view is first > > responder. Normal tool-tips are also shown when a view is not first > > responder, and I'd like to have that too. > > > > I also tried adding tracking rects and implementing -mouseEntered:/ > > Exited:. That has several problems of its own. The most important > > is that those are often delayed, giving an annoying lagging > > behavior, and also do not come in a logical order (I often get a > > sequence like entered-entered-exited-exited, even for non- > > overlapping rects). > > > > I wonder what the normal behavior for tooltips added using - > > addToolTipRect:owner:userData: does. Is it true that those are > > handled by the window, rather than the view? And most importantly: > > what events does the window(?) catch to support tool-tips, and when > > and how? Is this already in private methods before the event is > > further dispatched to the view hierarchy? Would it mean that I > > should subclass the window to simulate the normal tool-tip behavior > > (and the natural next question: how)? > > > > I would appreciate some hints to help me further. > > > > Christiaan > > > > _______________________________________________ > > MacOSX-dev mailing list > > MacOSX-dev@omnigroup.com > > http://www.omnigroup.com/mailman/listinfo/macosx-dev > > From milke at mac.com Sun Apr 22 05:17:11 2007 From: milke at mac.com (=?UTF-8?Q?Dragan_Mili=C4=87?=) Date: Sun Apr 22 05:17:26 2007 Subject: Yet another problem with NSTask and NSPipe Message-ID: <8C1D944D-FA3F-4437-AB60-EDAD9F9E8425@mac.com> Hello all, I know this topic has been beaten do death during past seven years, yet after reading from archives all that I could find about it and after struggling for couple of days, I'm not able to solve it, hence need some help. The situation is quite standard. I run hdiutil inside NSTask. The goal is to get information on an image and use it afterwards. For that reason I use -plist option of the hdiutil, so the NSTask should do: hdiutil imageinfo -plist image_name Not to spend too many words, here is the part of code that I use: NSPipe *stdInPipe = [NSPipe pipe]; NSPipe *stdOutPipe = [NSPipe pipe]; NSFileHandle *stdOutHandle = [stdOutPipe fileHandleForReading]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(outPipeDataAvailable:) name:NSFileHandleReadCompletionNotification object:stdOutHandle]; NSTask *task = [[[NSTask alloc] init] autorelease]; [task setStandardInput:stdInPipe]; [task setStandardOutput:stdOutPipe]; [task setArguments:[NSArray arrayWithObjects:@"hdiutil", @"imageinfo", @"-plist", imageName, nil]]; [task setLaunchPath:@"/usr/bin/env"]; [stdOutHandle readInBackgroundAndNotify]; [self setStdOutData:[NSMutableData data]]; [task launch]; [task waitUntilExit]; int terminationStatus = [task terminationStatus]; [task release]; if (terminationStatus != 0) { // error handling } [[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleReadCompletionNotification object:nil]; NSDictionary *properties = [[[[NSString alloc] initWithData:stdOutData encoding:NSASCIIStringEncoding] autorelease] propertyList]; ... ... The notification method: - (void)outPipeDataAvailable:(NSNotification *)notification { NSData *data = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem]; if ([data length] > 0) { [stdOutData appendData:data]; [[notification object] readInBackgroundAndNotify]; } } When I run this code on 900Mhz G3 iBook, it runs just fine. I can notice that the whole plist dictionary is read and stuffed into stdOutData in a few readings, meaning that the notification method gets called several times. But, if I run this code on much faster computer, e.g. 2.0GHz Intel Core 2 Duo MacBook, I notice that the notification method gets called only once, and then the task finishes its execution, leaving me with incomplete output that cannot be parsed into -[NSString propertyList] method. Like the task has been executed so quickly that the output pipe hasn't had a chance to be read to the end. I've tried various approaches and everything that I could find on mailing lists on NSTask and NSPipe topics and that I could think of, including pooling file descriptor of stdOutHandle with select() and setting it to O_NONBLOCK, reading in separate thread, putting delays in the main method, postponing removing of object from notification center until later, postponing releasing of NSTask object until later,... None of it helped. Can anyone point to me the correct way of doing this, which will discard all possible timing issues? Any help is much appreciated. Cheers, Milke From shawnce at gmail.com Tue Apr 24 23:08:59 2007 From: shawnce at gmail.com (Shawn Erickson) Date: Tue Apr 24 23:09:03 2007 Subject: Yet another problem with NSTask and NSPipe In-Reply-To: <8C1D944D-FA3F-4437-AB60-EDAD9F9E8425@mac.com> References: <8C1D944D-FA3F-4437-AB60-EDAD9F9E8425@mac.com> Message-ID: <94E594CC-73A4-4F01-A767-B646806DC3B2@gmail.com> On Apr 22, 2007, at 5:17 AM, Dragan Mili? wrote: > Hello all, > > I know this topic has been beaten do death during past seven years, > yet after reading from archives all that I could find about it and > after struggling for couple of days, I'm not able to solve it, > hence need some help. > > The situation is quite standard. I run hdiutil inside NSTask. The > goal is to get information on an image and use it afterwards. For > that reason I use -plist option of the hdiutil, so the NSTask > should do: > > hdiutil imageinfo -plist image_name > > Not to spend too many words, here is the part of code that I use: > > NSPipe *stdInPipe = [NSPipe pipe]; > NSPipe *stdOutPipe = [NSPipe pipe]; > NSFileHandle *stdOutHandle = [stdOutPipe fileHandleForReading]; > [[NSNotificationCenter defaultCenter] > addObserver:self > selector:@selector(outPipeDataAvailable:) > name:NSFileHandleReadCompletionNotification > object:stdOutHandle]; > NSTask *task = [[[NSTask alloc] init] autorelease]; > [task setStandardInput:stdInPipe]; > [task setStandardOutput:stdOutPipe]; > [task setArguments:[NSArray arrayWithObjects:@"hdiutil", > @"imageinfo", @"-plist", imageName, nil]]; > [task setLaunchPath:@"/usr/bin/env"]; > [stdOutHandle readInBackgroundAndNotify]; > [self setStdOutData:[NSMutableData data]]; > [task launch]; > [task waitUntilExit]; > int terminationStatus = [task terminationStatus]; > [task release]; > if (terminationStatus != 0) { > // error handling > } > [[NSNotificationCenter defaultCenter] > removeObserver:self > name:NSFileHandleReadCompletionNotification > object:nil]; Don't use the exit of the task as the trigger to stop reading data. Use the ending of the pipe as way to know that you have read all of the data. -Shawn From lierfeld at ient.rwth-aachen.de Thu Apr 26 07:34:44 2007 From: lierfeld at ient.rwth-aachen.de (Marco Lierfeld) Date: Thu Apr 26 07:50:49 2007 Subject: Canon EDSDK using C++ Message-ID: <1177598084.21898.27.camel@im35.ient.rwth-aachen.de> Hello, I would like to write a shell tool using the Canon SDK for EOS-Cameras in C++ using XCode. But unfortunately there is a problem: After I have initialized the SDK successfully, got a list of all connected cameras (currently one) and a reference to this camera, I would like to open a session to this camera (to be able to send commands to it). At this point the problem occurs: The function EdsOpenSession() does not return after it has been called and waits forever. I already presumed my code to be faulty and tried the sample-code from Canon's documentation for the SDK (after correcting some minor bugs like mixed up == and =) - unfortunately with the same result :( Has anybody else seen this problem? Or even better: Has somebody already solved it? I would be glad about any answers! Regards, Marco From janos.lobb at yale.edu Thu Apr 26 11:04:39 2007 From: janos.lobb at yale.edu (=?ISO-8859-1?Q?J=E1nos?=) Date: Thu Apr 26 11:04:32 2007 Subject: dev setup question for moving from CLI to IDEs Message-ID: Hi, Until now I used command line tools compile Java and C code. Here is the directory content of this mini jni project: -rw-r--r-- 1 janos janos 505 Apr 23 13:08 BarJNI$1.class -rw-r--r-- 1 janos janos 6825 Apr 23 13:08 BarJNI.class -rw-r--r-- 1 janos janos 430 Mar 14 17:16 BarJNI.h -rw-r--r-- 1 janos janos 11158 Apr 23 13:08 BarJNI.java -rw-r--r-- 1 janos janos 11158 Apr 23 12:59 BarJNIC.c -rwxr--r-- 1 janos janos 2377 Nov 10 05:43 barcode.h -rwxr-xr-x 1 janos janos 425268 Mar 19 05:46 libbardecode.dylib barcode.h and libbardecode.dylib was provided by the vendor. I use a simple text editor to edit both the Java and the C code. If I want ot compile Java I just do: bml0042:~/XCodeProjects/barjni janos$ javac BarJNI.java If I want to compile C I just do: bml0042:~/XCodeProjects/barjni janos$ gcc -dynamiclib -o /Volumes/ Home/janos/XCodeProjects/Nativelibs/libBarJNIC.jnilib libbardecode.dylib BarJNIC.c and it works marvelously. My dilemma is that the Java code will be part of a much bigger project and that project is managed and developed using IntelliJ IDEA. Sooner or later someone wants also to compile the C portion from XCode and create the BSD library. So the question is what kind of directory structure should I have that when I compile in XCode the resulting library will be seen by the Java class ? To start with I created an ~/IdeaProjects/bar folder and its content looks: drwxr-xr-x 4 janos janos 136 Apr 25 13:51 CPart -rw-r--r-- 1 janos janos 516 Apr 24 16:25 bar.iml -rw-r--r-- 1 janos janos 15662 Apr 24 16:25 bar.ipr -rw-r--r-- 1 janos janos 28054 Apr 24 17:07 bar.iws drwxr-xr-x 4 janos janos 136 Apr 24 16:59 classes drwxr-xr-x 6 janos janos 204 Apr 24 16:51 src In the src directory are the renamed Java sources - /and the C source and header files momentary/: bml0042:~/IdeaProjects/bar janos$ ls -l src total 64 -rw-r--r-- 1 janos janos 470 Apr 24 16:53 IFEBarcodeReader.h -rw-r--r-- 1 janos janos 10541 Apr 24 16:48 IFEBarcodeReader.java -rw-r--r-- 1 janos janos 11178 Apr 24 16:54 IFEBarcodeReaderC.c -rwxr--r-- 1 janos janos 2377 Nov 10 05:43 barcode.h and I plan to move the C parts into CPart. The question is where the vendor supplied barcode.h header and libbardecode.dylib dylib files should go, so that I can see it when I compile the C in Xcode and the compiled wrapper dlyb will be visible to the Java Class ? Right now if I compile and run the Java in IntelliJ IDEA I am getting the class not found message: Exception in thread "main" java.lang.UnsatisfiedLinkError: no IFEBarcodeReaderC in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682) at java.lang.Runtime.loadLibrary0(Runtime.java:822) at java.lang.System.loadLibrary(System.java:992) at IFEBarcodeReader.(IFEBarcodeReader.java:350) Process finished with exit code 1 So looks like that whereever XCode will create the FEBarcodeReaderC.dylib, that directory has to be added to the java.library.path so IDEA will see it. Are there any settings for it in Xcode and IDEA I can setup ? Thanks ahead, J?nos From matt at tidbits.com Thu Apr 26 11:05:02 2007 From: matt at tidbits.com (Matt Neuburg) Date: Thu Apr 26 11:05:23 2007 Subject: Yet another problem with NSTask and NSPipe Message-ID: On Tue, 24 Apr 2007 23:08:59 -0700, Shawn Erickson said: > >On Apr 22, 2007, at 5:17 AM, Dragan Mili?? wrote: > >> Hello all, >> >> I know this topic has been beaten do death during past seven years, >> yet after reading from archives all that I could find about it and >> after struggling for couple of days, I'm not able to solve it, >> hence need some help. >> >> The situation is quite standard. I run hdiutil inside NSTask. The >> goal is to get information on an image and use it afterwards. For >> that reason I use -plist option of the hdiutil, so the NSTask >> should do: >> >> hdiutil imageinfo -plist image_name >> >> Not to spend too many words, here is the part of code that I use: >> >> NSPipe *stdInPipe = [NSPipe pipe]; >> NSPipe *stdOutPipe = [NSPipe pipe]; >> NSFileHandle *stdOutHandle = [stdOutPipe fileHandleForReading]; >> [[NSNotificationCenter defaultCenter] >> addObserver:self >> selector:@selector(outPipeDataAvailable:) >> name:NSFileHandleReadCompletionNotification >> object:stdOutHandle]; >> NSTask *task = [[[NSTask alloc] init] autorelease]; >> [task setStandardInput:stdInPipe]; >> [task setStandardOutput:stdOutPipe]; >> [task setArguments:[NSArray arrayWithObjects:@"hdiutil", >> @"imageinfo", @"-plist", imageName, nil]]; >> [task setLaunchPath:@"/usr/bin/env"]; >> [stdOutHandle readInBackgroundAndNotify]; >> [self setStdOutData:[NSMutableData data]]; >> [task launch]; >> [task waitUntilExit]; >> int terminationStatus = [task terminationStatus]; >> [task release]; >> if (terminationStatus != 0) { >> // error handling >> } >> [[NSNotificationCenter defaultCenter] >> removeObserver:self >> name:NSFileHandleReadCompletionNotification >> object:nil]; > >Don't use the exit of the task as the trigger to stop reading data. >Use the ending of the pipe as way to know that you have read all of >the data. Well, it's a little more complicated than that. The OP is calling readInBackgroundAndNotify, but he is also calling waitUntilExit. That doesn't make any sense to me. And there are some other very weird things about the code as well. m. -- matt neuburg, phd = matt@tidbits.com, A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! From philippe.robert at gmx.net Thu Apr 26 15:07:38 2007 From: philippe.robert at gmx.net (Philippe C.D. Robert) Date: Thu Apr 26 15:08:07 20