LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Blogs > rainbowsally
User Name
Password

Notices

  1. Old Comment

    Corrected Broken Links

    ...and likewise thank you for your blog. It's a pleasure to read.
    Posted 09-04-2014 at 04:39 PM by unSpawn unSpawn is online now
  2. Old Comment

    STL Template Experiment (Lists)

    Code:
      // *** We put theStr pointer for new Str objects outside the loop!  Otherwise
      // the objects get automatically deleted by the ingenious C++ mechanism that 
      // removes them as execution leaves the scope.  Try putting this 'Str* pStr' 
      // inside the loop below and see what happens.
    Pretty sure this is wrong. Objects created by new are never deleted automatically. You are leaking those objects.

    Code:
      // Try creating the Str object 
      // the same way the Uint objects are created.  That doesn't work either.
      // [Same reason but more subtle.  In fact they are deleted immediately, even 
      // before the next one is created if you do it the way the Uints are done.
      // Interesting, no?  (Ick!)]
    You didn't make a copy constructor for your Str objects, so both copies try to free() the same string.
    Posted 09-10-2013 at 03:24 PM by ntubski ntubski is offline
  3. Old Comment

    Life In The Computer Mad Science Zone

    Yep, the printf formatting won't work on its own. You need the "10#" prefix on the variable to tell bash, "Look, I know it starts with a zero, but take my word for it, it's decimal!"

    And yes, 4 digits in that example - I lifted it directly from my own incremental backup script and didn't think to change the number of digits.

    Shell syntax is definitely "quirky", I think you chose exactly the right word there.
    Posted 06-24-2013 at 12:18 PM by GazL GazL is offline
  4. Old Comment

    Life In The Computer Mad Science Zone

    Thanks Gazi.

    I tried the "%.3d" format string and it didn't work.

    Bash is so full of quirks that regardless of the advantage of being able to see exactly what the program does, it's sometimes just not worth learning all the work-arounds.

    But there it is! With (it looks like) 4 digits for the build numbers. :-)
    Posted 06-24-2013 at 11:09 AM by rainbowsally rainbowsally is offline
  5. Old Comment

    Life In The Computer Mad Science Zone

    The leading zeros being treated as octal thing in bash can be worked around quite easily. No need to rewrite in c/c++ just because of this.

    Code:
    next="$(printf '%04d' $(( 10#$last + 1 )))"
    Posted 06-21-2013 at 04:25 AM by GazL GazL is offline
    Updated 06-21-2013 at 04:36 AM by GazL
  6. Old Comment

    Computer Mad Science: The Anatomy Of A Makefile Part 1

    Hi again. :-)

    About the "still writing" problem. I think there might be something going on with the way linux caches files or your browser might not have refreshed. But try this -- exactly -- and it should behave as expected.

    Create the file below in a new directory named 'a'.

    file: a/Makefile
    purpose: source file
    Code:
    # keeps writing to temp.txt if run "make" multiple times.
    
    string = "I'm doing something!"
    
    all: temp.txt
    
    temp.txt: target
    	@echo "temp.txt has been created."
    
    target: # dep3
    	echo $(string)                       >> temp.txt
    	@echo "That's all I can tell you right now." >> temp.txt
    open a terminal and type:
    Code:
    echo > terminal
    Then CLOSE the terminal. Open a new terminal and run 'make'.

    No "temp.txt".

    It SAYS it created it, but that's because temp.txt (the target) doesn't make the file in this case. "target" (the target) does, but since the file 'target' was up to date, the target named "target" never ran.

    Clear as mud, eh? ;-)
    Posted 01-17-2013 at 05:01 AM by rainbowsally rainbowsally is offline
  7. Old Comment

    Computer Mad Science: The Anatomy Of A Makefile Part 1

    Still writing!

    Quote:
    Originally Posted by yifangt View Comment
    So, it seems to me target of 'all' is the trick. Once there exists a file with the same name of the target for 'all', make will stop writing/adding to the existing file, Am I right?
    The other targets do the same thing.

    A : B C
    action

    Consider the above.

    Read A "needs B and C" before "action".

    B and C must exist as targets in the makefile but they don't need to produce a file.

    B might be a phony target, like "clean", if you like rebuilding from scratch every time. ;-)

    'clean:' and 'distclean:' are phony targets. They don't create files so they will always run.

    An C might be a filename, or even a library name. If it's a library name, the "action" for C might very well be to cd into another directory and 'make' there.

    And the 'all' in that other makefile is no different from any of the other targets.

    In fact the first target doesn't even really even need to be named "all". It's just named that by convention.

    What would happen if a file named 'all' existed in the same directory with the makefile?

    :-)
    Posted 01-17-2013 at 04:08 AM by rainbowsally rainbowsally is offline
  8. Old Comment

    Computer Mad Science: The Anatomy Of A Makefile Part 1

    Still writing!

    Thanks!
    I tried your makefile-a. First removed temp.txt, and created an empty file named "target" by:
    Code:
    rm temp.txt; touch target
    Then I ran again:
    Code:
    make -f makefile-a
    but it still keeps wrting to temp.txt. Any clue?

    I tried with another makefile:
    Code:
    # does not write to temp.txt if file "target" exists.
    ############################################  
    #   
    string = "I'm doing something!"
    #    
    all: test_target
    
    test_target: 
    	echo $(string)                       >> temp.txt
    	@echo "That's all I can tell you right now." >> temp.txt
    if I run multiple times:
    Code:
    make -f makefile-c
    still new content was added to temp.txt!
    But after I create an empty file "test_target":
    Code:
    touch test_target;
    make -f makefile-c
    make: Nothing to be done for `all'.
    So, it seems to me target of 'all' is the trick. Once there exists a file with the same name of the target for 'all', make will stop writing/adding to the existing file, Am I right?
    Posted 01-14-2013 at 10:21 AM by yifangt yifangt is offline
    Updated 01-14-2013 at 10:41 AM by yifangt
  9. Old Comment

    Computer Mad Science: The Anatomy Of A Makefile Part 1

    Quote:
    Originally Posted by yifangt View Comment
    My confusion is that:
    2nd last Makefile (Makefile-b, I am aware the name must be Makefile to work!)
    First of all, the makefile doesn't need to have any specific name. You can load any file name with the -f switch, like so:
    Code:
    make -f makefile-b
    Now..

    This was a really great observation, yifangt. And I think your examples are probably better than mine because it shows how real targets (as opposed to "phoney" ones) are also file names.

    See the notes in the makefiles below.

    file: a/Makefile
    purpose: source file
    Code:
    # keeps writing to temp.txt if run "make" multiple times.
    #########################################################
    # 'all' has a dependency on 'temp.txt' and the file exists
    # but temp.txt has additional dependenices on 'target'
    # so 'make' checks to see if 'target' (the file) also 
    # exists, which it can't, because 'target' itself is a 
    # phoney target -- never producing a file by that name.
    # It will always run... unless... ;-)
    #########################################################
    
    
    string = "I'm doing something!"
    
    all: temp.txt
    
    temp.txt: target
    	@echo "temp.txt has been created."
    
    target: # dep3
    	echo $(string)                       >> temp.txt
    	@echo "That's all I can tell you right now." >> temp.txt

    file: b/Makefile
    purpose: source file
    Code:
    # does not keeps writing to temp.txt if run "make" multiple times.
    ##################################################################
    # because the file 'temp.txt' exists.  Being the only dependency 
    # for all (either direcly or indirectly), make sees that the file 
    # exists (and all the dependencies are satisfied) so once created, 
    # make is done.
    ##################################################################
    
    string = "I'm doing something!"
    
    all: temp.txt
    	@echo "temp.txt has been created."
    
    temp.txt:
    	@echo "My name is 'echo'" >> temp.txt
    	@printf "What are you doing? "  >> temp.txt
    	@echo "if you don't mind my asking."  >> temp.txt
    	@echo                                 >> temp.txt
    	@echo $(string)                       >> temp.txt
    	@echo "That's all I can tell you right now." >> temp.txt

    Try example 'a' above again and remove temp.txt and create a file named 'target' and see if it even creates the first copy of temp.txt. It can't. Because 'all' doesn't produce a file, it expects 'target' to do that.

    Then remove the file named 'target' and try it again. Now it creates 'temp.txt' and keeps on writing to it for the reason that the file 'target' never exists.

    Bottom line: targets are also file names. In fact 'make' also checks creation times to make sure that depenencies and the files that depend on them are 'current'.

    We could attempt to demonstrate that too, but... well... Maybe later. ;-)

    And thank you for your observations and your question.

    :-)
    Posted 01-13-2013 at 09:12 PM by rainbowsally rainbowsally is offline
    Updated 01-13-2013 at 09:36 PM by rainbowsally (copy/paste TABs into file)
  10. Old Comment

    Computer Mad Science: The Anatomy Of A Makefile Part 1

    My confusion is that:
    2nd last Makefile (Makefile-b, I am aware the name must be Makefile to work!):
    Code:
    string = "I'm doing something!"
    
    all: temp.txt
    
    temp.txt: target
    	@echo "temp.txt has been created."
    
    target: dep3
    	echo $(string)                       >> temp.txt
    	@echo "That's all I can tell you right now." >> temp.txt
    ......
    keeps writing to temp.txt if run "make" multiple times.
    The last Makefile (Makefile-a) does not.
    Code:
    string = "I'm doing something!"
    
    all: temp.txt
    	@echo "temp.txt has been created."
    
    temp.txt:
    	@echo "My name is 'echo'" >> temp.txt
    	@printf "What are you doing? "  >> temp.txt
    	@echo "if you don't mind my asking."  >> temp.txt
    	@echo                                 >> temp.txt
    	@echo $(string)                       >> temp.txt
    	@echo "That's all I can tell you right now." >> temp.txt
    Why?
    1) Because Makefile-b use target as "intermediate output"?
    2) Or any other reason I missed?
    Thanks a lot!
    Posted 01-13-2013 at 07:48 PM by yifangt yifangt is offline
  11. Old Comment

    Computer Mad Science: The Anatomy Of A Makefile Part 1

    Quote:
    Originally Posted by yifangt View Comment
    I am still confused with the second last Makefile and the last one: Why the second last keeps writing to temp.txt but the last one does not?
    Could you please explain it more explicitly? Thanks a lot!
    I wish I could, vifangt. :-)

    If you're interested in how makefiles work, this probably wasn't the best example.

    The interesting stuff 'make' does is in it's reordering of its procedures based on what comes after the colons in the targets. It's freaking packed with features, most of which nobody uses, but in any case, I can't remember what I was up to with this one.

    If this is really a big deal to you, post here again and I'll dig into this and try to figure out what I was up to and what might have been confusing to you.

    Might be that the second one is outputting to stderr instead of stdout? (first guess).

    Unfortunately my modem lives in windows and my linux lives in linux so this requires a bit more than just switching to a terminal and testing the code. Hope to correct this problem soon.

    :-)
    Posted 01-13-2013 at 07:11 PM by rainbowsally rainbowsally is offline
    Updated 01-13-2013 at 07:15 PM by rainbowsally
  12. Old Comment

    Computer Mad Science: The Anatomy Of A Makefile Part 1

    I am still confused with the second last Makefile and the last one: Why the second last keeps writing to temp.txt but the last one does not?
    Could you please explain it more explicitly? Thanks a lot!
    Posted 01-07-2013 at 11:42 PM by yifangt yifangt is offline
    Updated 01-07-2013 at 11:43 PM by yifangt (typo)
  13. Old Comment

    GUI Programming: QT4 Event Preeption Part 2-A (temp)

    Hi ntubski.

    Quote:
    By null string you mean the empty string? That would return 0 actually.
    Not exactly. The only way to get a 0 hash id from this algorithm is by passing a null pointer.

    A null string returns a -1. Or...

    Heh..

    Again, you got me here. I should have used a ~ (not operator) to invert all the bits.

    Thanks for the Quality Control check.

    But the idea is to never have a 0 value in the table though, because that will be an indication that hash entry is the end of the array (as would be a null string in the table).

    This algorithm also generates the hashes for the table which can't be done at compile-time so this ends up being important and you have helped me avoid finding this problem the hard way.

    Thanks again. :-)
    Posted 05-04-2012 at 11:21 AM by rainbowsally rainbowsally is offline
  14. Old Comment

    GUI Programming: QT4 Event Preeption Part 2-A (temp)

    Code:
    int lq_hash32(const char* name)
    {
      const char *p = name;
      if(!p) return 0;  // returns 0 if null pointer
     
      int h = *p;
      if (h) {
        for (p += 1; *p != 0; p++)
          h = ((h << 5) - h) + *p;
      }
      return h < 0 ? h : -h; // returns -1 if null string
    }
    By null string you mean the empty string? That would return 0 actually.
    Posted 05-03-2012 at 04:51 PM by ntubski ntubski is offline
  15. Old Comment

    GUI coding: First Stop QT4

    Actually, I was working on a Forth compiler/interpreter and needed a terminal where I could copy/paste stuff in with the more or less standard keys (Ctrl-C, X, V, Z and stuff).

    The interpreter was integrated into the terminal.

    I got it working with QT4 but I had to set up a separate key buffer (private event queue). The whole process was pretty complicated.

    So... no not exactly. By terminal I just mean io for a keyboard, I guess. Not tied to a shell in any way.

    And xterm is horrible. The scrollbars are a pain, the clipboard in awkward, there is no paste key and junk ansi codes if you press a wrong key...

    And though ncurses is an improvement it's still unacceptable for my (erstwhile) purposes, starting with the oddball treatment of the left and right alt-keys as though they had different functionality, never mind the icky appearance. ;-)

    I did write a forth using termios (non-canonical) and with a separate thread to queue keyboard input while the Forth ran in its own thread though. And it was what I used for my terminal for a while. It was much faster than the QT implementation at least.

    Thanks for the comment.

    :-)
    Posted 04-20-2012 at 08:48 AM by rainbowsally rainbowsally is offline
  16. Old Comment

    GUI coding: First Stop QT4

    By "widget that acts like a terminal" you mean a more tightly integrated form of what might otherwise be done by launching xterm and having it launch the application that wants to work on a terminal ... something that can run in an event loop, but still has terminal semantics to its output?
    Posted 04-19-2012 at 04:04 PM by Skaperen Skaperen is offline
  17. Old Comment

    C/C++ dosex (irregular expressions :) for copying, renaming with wildcards

    Hi ntubski.

    It's hard to expect what ms products produce. :-)

    Tested against XP cmd.exe and the same unexpected results occur. I thought it best to remain DOS compatible in case anyone wanted to duplicate any old dos 'move' or 'copy/xcopy' 'ren' types of functions so I didn't try to change any of the counterintuitive stuff.

    And re changing the name of '.' input file name. Dot is considered the end of a substring in DOS. If you look at the algorithm you can see why that failed to match.

    :-)
    Posted 04-09-2012 at 05:56 AM by rainbowsally rainbowsally is offline
  18. Old Comment

    C/C++ dosex (irregular expressions :) for copying, renaming with wildcards

    So it looks like replacestr is matched against inputstr, with literals in replacestr acting as "?" for matching but get output as themselves, and wildcards are output as whatever they match against in inputstr. findstr is irrelevant to the output as long as it matches inputstr.

    I may have found a bug, one of the example arguments doesn't give the expected results:
    Code:
    % ./dosex abc.defg '*.*' 'test4*'
    Using args
       inputstr:   abc.defg
       findstr:    *.*
       replacestr: test4*
    Output -> 'test4'
    Getting "test4" instead of "test.defg" (hmm, I just realized that if "test.defg" really is the expected result, my description above is wrong). It seems like findstr is matching wildcards to "." (like in unix), but replacestr doesn't (like in DOS):
    Code:
    % ./dosex . '*' x
    Using args
       inputstr:   .
       findstr:    *
       replacestr: x
    Output -> 'x'
    % ./dosex . '*' '*'
    Using args
       inputstr:   .
       findstr:    *
       replacestr: *
    Can't copy/replace input strings
    How do you access this functionality in DOS?
    Posted 04-07-2012 at 09:06 AM by ntubski ntubski is offline
  19. Old Comment

    More Mad Computer Science? (Simple multi-threading in a shell script)

    Quote:
    Originally Posted by rainbowsally
    Try it and see. (Remember the app is clickable.)
    Eh, I don't really want to install all of KDE to test this out

    Quote:
    But running nohup from the script when clicked on doesn't work.
    That's weird, I guess KDE has some strange requirements on clicked shell scripts? It works from the command line right? I also see you have
    Code:
    // Can't just close stdout or kde will spin out.
    which appears to be another strange requirement. I feel like these ought to be documented somewhere, but I can't find them

    Quote:
    the unparse_args() call which may be a duplicate at this blog, but can be very useful when using system() calls (which expect args in a singl string) from an argument list (of broken up strings) input to a C/C++ main() function.
    That function will give you surprising results if there are special characters in the arguments. Also I think by using snprintf() you can avoid the malloc().
    Posted 04-05-2012 at 07:40 PM by ntubski ntubski is offline
  20. Old Comment

    C/C++ dosex (irregular expressions :) for copying, renaming with wildcards

    Compile the demo. It has one preset pair of strings. You can chance the default oldname/newname wildcards in the program or input them from the commandline.

    Remember to quote the args so the shell doesn't expand them behind your back.

    :-)
    Posted 04-05-2012 at 07:12 PM by rainbowsally rainbowsally is offline

  



All times are GMT -5. The time now is 03:05 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration