question about name checking code in fselect - General Discussion and Assistance - CHDK Forum

question about name checking code in fselect

  • 3 Replies
  • 3576 Views
*

Offline reyalp

  • ******
  • 14125
question about name checking code in fselect
« on: 05 / August / 2008, 20:54:04 »
Advertisements
Is there a reason things like
Code: [Select]
           if (selected->name[0] == 'D' && selected->name[1] == 'C' && selected->name[2] == 'I' && selected->name[3] == 'M') {//If selected item is DCIM folder
are used instead of str[n]cmp ?

Also, the extension checks such as
Code: [Select]
           else if (selected->name[9] == 'C' || selected->name[9] == 'T' || selected->name[9] == 'W' || selected->name[9] == 'J') {//If seleted item is a file produced by the camera
just use the 10th letter. Not only will XXXXXXXX.[CTWJ]?? match, name[9] might also be after the end of the name (and off the end off the buffer if I'm not mistaken.)
Don't forget what the H stands for.

*

Offline DataGhost

  • ****
  • 314
  • EOS 40D, S5IS
    • DataGhost.com
Re: question about name checking code in fselect
« Reply #1 on: 06 / August / 2008, 05:49:32 »
The DCIM folder layout and naming follows some standard (forgot which one), which states that the files are of the form
AAAAXXXX.EXT
AAAA being four characters, doesn't really matter what
XXXX being four numbers, must be unique unless the files belong to each other (AVI + THM, for example)
EXT being the extension, of course.
So there is really no way that the camera produces a file, in the DCIM folder, which doesn't pass validation in this way. Granted, it's probably not the best way but it works.

*

Offline ewavr

  • ****
  • 1057
  • A710IS
Re: question about name checking code in fselect
« Reply #2 on: 06 / August / 2008, 06:06:55 »
Is there a reason things like
Code: [Select]
   if (selected->name[0] == 'D' && selected->name[1] == 'C' && selected->name[2] == 'I' && selected->name[3] == 'M') {//If selected item is DCIM folder
are used instead of str[n]cmp ?

Offtopic on

Maybe, it works faster?
Code: [Select]
 if ((*(long*)selected->name)==0x4D494344)
Works superfast.  :D

*

Offline reyalp

  • ******
  • 14125
Re: question about name checking code in fselect
« Reply #3 on: 06 / August / 2008, 17:32:11 »
@dataghost:
Thanks. It looks like this Design rule for Camera File system - Wikipedia, the free encyclopedia is the standard in question.
Version 1 can be found as a PDF, the latest is about $50 from JEITA
Maybe, it works faster?
Code: [Select]
 if ((*(long*)selected->name)==0x4D494344)
Works superfast.  :D
:D
When the next operation involves reading/writing flash or updating the most of the display framebuffer anyway, I'd take clarity over a few ns more performance  :D
Don't forget what the H stands for.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal