Changeset 654


Ignore:
Timestamp:
12/28/08 09:23:42 (4 years ago)
Author:
reyalp
Message:
  • add ability to build CHDK lua for host platform. Not built by default.
  • renamed dirent name to d_name to be compatible with conventional libc
Location:
trunk
Files:
8 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/edgeoverlay.c

    r599 r654  
    122122        while( (de = readdir(d)) ) 
    123123        { 
    124                 fr = get_edge_file_num(de->name); 
     124                fr = get_edge_file_num(de->d_name); 
    125125                if( fr > fnum ) 
    126126                { 
  • trunk/core/gui_fselect.c

    r651 r654  
    124124        de = readdir(d); 
    125125        while (de) { 
    126             if (de->name[0] != 0xE5 /* deleted entry */ && (de->name[0]!='.' || de->name[1]!=0)) { 
     126            if (de->d_name[0] != 0xE5 /* deleted entry */ && (de->d_name[0]!='.' || de->d_name[1]!=0)) { 
    127127                *ptr = malloc(sizeof(struct fitem)); 
    128128                if (*ptr) { 
    129129                    (*ptr)->n = count; 
    130                     (*ptr)->name = malloc(strlen(de->name)+1); 
     130                    (*ptr)->name = malloc(strlen(de->d_name)+1); 
    131131                    if ((*ptr)->name) 
    132                         strcpy((*ptr)->name, de->name); 
    133                     sprintf(buf, "%s/%s", dir, de->name); 
     132                        strcpy((*ptr)->name, de->d_name); 
     133                    sprintf(buf, "%s/%s", dir, de->d_name); 
    134134                    if (stat(buf, &st)==0) { 
    135135                        (*ptr)->attr=st.st_attrib; 
     
    137137                        (*ptr)->mtime=st.st_mtime; 
    138138                    } else { 
    139                         (*ptr)->attr=(de->name[0]=='.' && de->name[1]=='.' && de->name[2]==0)?DOS_ATTR_DIRECTORY:0xFF; 
     139                        (*ptr)->attr=(de->d_name[0]=='.' && de->d_name[1]=='.' && de->d_name[2]==0)?DOS_ATTR_DIRECTORY:0xFF; 
    140140                        (*ptr)->size=(*ptr)->mtime=0; 
    141141                    } 
     
    401401           d=opendir(current_dir); 
    402402           while ((de=readdir(d)) != NULL) {//Loop to find all Canon folders 
    403                if (de->name[0] != '.' && de->name[1] != '.') {//If item is not UpDir 
    404                    sprintf(sub_dir, "%s/%s", current_dir, de->name); 
     403               if (de->d_name[0] != '.' && de->d_name[1] != '.') {//If item is not UpDir 
     404                   sprintf(sub_dir, "%s/%s", current_dir, de->d_name); 
    405405                   d2=opendir(sub_dir); 
    406406                   while ((de2=readdir(d2)) != NULL) {//Loop to find all the RAW files inside a Canon folder 
    407                        if (de2->name[0] == 'C' || de2->name[9] == 'C') {//If file is RAW (Either CRW/CR2 prefix or file extension) 
     407                       if (de2->d_name[0] == 'C' || de2->d_name[9] == 'C') {//If file is RAW (Either CRW/CR2 prefix or file extension) 
    408408                           d3=opendir(current_dir); 
    409409                           while ((de3=readdir(d3)) != NULL) {//Loop to find all Canon folders 
    410                                if (de3->name[0] != '.' && de3->name[1] != '.') {//If item is not UpDir 
    411                                    sprintf(sub_dir_search, "%s/%s", current_dir, de3->name); 
     410                               if (de3->d_name[0] != '.' && de3->d_name[1] != '.') {//If item is not UpDir 
     411                                   sprintf(sub_dir_search, "%s/%s", current_dir, de3->d_name); 
    412412                                   d4=opendir(sub_dir_search); 
    413413                                   while ((de4=readdir(d4)) != NULL) {//Loop to find a corresponding JPG file inside a Canon folder 
    414                                        if (de2->name[4] == de4->name[4] && de2->name[5] == de4->name[5] &&//If the four digits of the Canon number are the same 
    415                                            de2->name[6] == de4->name[6] && de2->name[7] == de4->name[7] && 
    416                                            de4->name[9] == 'J' && !(de4->name[0] == 'C' || de4->name[9] == 'C' || de4->name[0] == 0xE5)) {//If file is JPG, is not CRW/CR2 and is not a deleted item 
     414                                       if (de2->d_name[4] == de4->d_name[4] && de2->d_name[5] == de4->d_name[5] &&//If the four digits of the Canon number are the same 
     415                                           de2->d_name[6] == de4->d_name[6] && de2->d_name[7] == de4->d_name[7] && 
     416                                           de4->d_name[9] == 'J' && !(de4->d_name[0] == 'C' || de4->d_name[9] == 'C' || de4->d_name[0] == 0xE5)) {//If file is JPG, is not CRW/CR2 and is not a deleted item 
    417417                                           started(); 
    418418                                           found=1;//A JPG file with the same Canon number was found 
     
    425425                           //If no JPG found, delete RAW file 
    426426                           if (found == 0) { 
    427                                sprintf(selected_item, "%s/%s", sub_dir, de2->name); 
     427                               sprintf(selected_item, "%s/%s", sub_dir, de2->d_name); 
    428428                               remove(selected_item); 
    429429                               finished(); 
     
    448448           d=opendir(current_dir); 
    449449           while ((de=readdir(d)) != NULL) {//Loop to find all the RAW files inside the Canon folder  
    450                if (de->name[0] == 'C' || de->name[9] == 'C') {//If file is RAW (Either CRW/CR2 prefix or file extension) 
     450               if (de->d_name[0] == 'C' || de->d_name[9] == 'C') {//If file is RAW (Either CRW/CR2 prefix or file extension) 
    451451                   d2=opendir(current_dir); 
    452452                   while ((de2=readdir(d2)) != NULL) {//Loop to find a corresponding JPG file inside the Canon folder 
    453                        if (de->name[4] == de2->name[4] && de->name[5] == de2->name[5] &&//If the four digits of the Canon number are the same 
    454                            de->name[6] == de2->name[6] && de->name[7] == de2->name[7] && 
    455                            de2->name[9] == 'J' && !(de2->name[0] == 'C' || de2->name[9] == 'C' || de2->name[0] == 0xE5)) {//If file is JPG and is not CRW/CR2 and is not a deleted item 
     453                       if (de->d_name[4] == de2->d_name[4] && de->d_name[5] == de2->d_name[5] &&//If the four digits of the Canon number are the same 
     454                           de->d_name[6] == de2->d_name[6] && de->d_name[7] == de2->d_name[7] && 
     455                           de2->d_name[9] == 'J' && !(de2->d_name[0] == 'C' || de2->d_name[9] == 'C' || de2->d_name[0] == 0xE5)) {//If file is JPG and is not CRW/CR2 and is not a deleted item 
    456456                           started(); 
    457457                           found=1;//A JPG file with the same Canon number was found 
     
    461461                   //If no JPG found, delete RAW file                 
    462462                   if (found == 0) { 
    463                        sprintf(selected_item, "%s/%s", current_dir, de->name); 
     463                       sprintf(selected_item, "%s/%s", current_dir, de->d_name); 
    464464                       remove(selected_item); 
    465465                       finished(); 
     
    519519            de = readdir(d); 
    520520            while (de) { 
    521                 if (de->name[0] != 0xE5 /* deleted entry */ && (de->name[0]!='.' || (de->name[1]!='.' && de->name[1]!=0) || (de->name[1]=='.' && de->name[2]!=0))) { 
     521                if (de->d_name[0] != 0xE5 /* deleted entry */ && (de->d_name[0]!='.' || (de->d_name[1]!='.' && de->d_name[1]!=0) || (de->d_name[1]=='.' && de->d_name[2]!=0))) { 
    522522                    started(); 
    523                     sprintf(selected_file, "%s/%s", current_dir, de->name); 
     523                    sprintf(selected_file, "%s/%s", current_dir, de->d_name); 
    524524                    remove(selected_file); 
    525525                    finished(); 
  • trunk/include/stdlib.h

    r606 r654  
    213213#if !CAM_DRYOS 
    214214struct dirent { 
    215     char                name[100]; 
     215    char                d_name[100]; 
    216216}; 
    217217#else 
    218218struct dirent { 
    219     char                name[13]; 
     219    char                d_name[13]; 
    220220    unsigned long       unk1; 
    221221    unsigned char       attrib; 
  • trunk/lib/lua/lbaselib.c

    r525 r654  
    1111#include <stdlib.h> 
    1212#include <string.h> 
     13#ifndef HOST_LUA 
    1314#include <script.h>     // script_console_add_line 
     15#endif 
    1416 
    1517#define lbaselib_c 
     
    7173 
    7274  } 
     75#ifdef HOST_LUA 
     76  fprintf(stdout,"%s\n",buf); 
     77#else 
    7378  script_console_add_line(buf); 
     79#endif 
    7480 
    7581  return 0; 
  • trunk/lib/lua/liolib.c

    r517 r654  
    2222#include "lualib.h" 
    2323 
    24  
     24#ifdef HOST_LUA 
     25#include <errno.h> 
     26#include <ctype.h> 
     27#endif 
    2528 
    2629#define IO_INPUT        1 
  • trunk/lib/lua/loadlib.c

    r515 r654  
    331331 
    332332static int readable (const char *filename) { 
     333#ifdef HOST_LUA 
     334  FILE *f = fopen(filename, "r");  /* try to open file */ 
     335  if (f == NULL) return 0;  /* open failed */ 
     336  fclose(f); 
     337#else 
    333338  int f = open(filename,O_RDONLY,0777); 
    334339  if (f == -1) return 0;  /* open failed */ 
    335340  close(f); 
     341#endif 
    336342  return 1; 
    337343} 
  • trunk/lib/lua/loslib.c

    r555 r654  
    1111#include <stdlib.h> 
    1212#include <string.h> 
    13 #if 0 
     13#ifdef HOST_LUA 
     14#include <errno.h> 
    1415#include <time.h> 
     16#include <dirent.h> 
     17#include <sys/stat.h> 
     18#include <utime.h> 
    1519#endif 
    1620 
     
    246250static int os_mkdir (lua_State *L) { 
    247251  const char *dirname = luaL_checkstring(L, 1); 
     252#if defined(HOST_LUA) && !defined(_WIN32) 
     253  return os_pushresult(L, mkdir(dirname,0777) == 0, dirname); 
     254#else 
    248255  return os_pushresult(L, mkdir(dirname) == 0, dirname); 
     256#endif 
    249257} 
    250258 
     
    267275  lua_newtable(L);  
    268276  while((de = readdir(dir))) { 
    269         if(!all && (de->name[0] == 0xE5 || (strcmp(de->name,".")==0) || (strcmp(de->name,"..")==0))) 
     277        if(!all && (/*de->d_name[0] == 0xE5 ||*/ (strcmp(de->d_name,".")==0) || (strcmp(de->d_name,"..")==0))) 
    270278      continue; 
    271279        lua_pushinteger(L, i); 
    272         lua_pushstring(L, de->name); 
     280        lua_pushstring(L, de->d_name); 
    273281        lua_settable(L,-3); 
    274282        ++i; 
     
    302310    setfield(L,"mtime",st.st_mtime);    /* time of last modification */ 
    303311    setfield(L,"ctime",st.st_ctime);    /* time of last change of file status */ 
     312#ifdef HOST_LUA 
     313// fill in some sane values if we aren't running on the camera 
     314// from chdk stdlib 
     315#define DOS_ATTR_DIRECTORY      0x10            /* entry is a sub-directory */ 
     316    setfield(L,"blksize",512);  
     317    setfield(L,"blocks",(st.st_size/512) + (st.st_size%512)?1:0);  
     318    if ( S_ISDIR(st.st_mode) ) { 
     319      setfield(L,"attrib",DOS_ATTR_DIRECTORY); 
     320      setboolfield(L,"is_dir",1); 
     321      setboolfield(L,"is_file",0); 
     322    } 
     323    else { 
     324      setboolfield(L,"is_dir",0); 
     325      setfield(L,"attrib",0); 
     326      if S_ISREG(st.st_mode) { 
     327        setboolfield(L,"is_file",1); 
     328      } 
     329    } 
     330#else 
    304331    setfield(L,"blksize",st.st_blksize); /* This is NOT the dos sector size. Appears to be 512 on all I've tested! */ 
    305332    setfield(L,"blocks",st.st_blocks);   /* number of blocks required to store file. May not be the same as size on disk, per above*/ 
     
    309336        setboolfield(L,"is_dir",st.st_attrib & DOS_ATTR_DIRECTORY); 
    310337        setboolfield(L,"is_file",!(st.st_attrib & (DOS_ATTR_DIRECTORY | DOS_ATTR_VOL_LABEL))); 
     338#endif 
    311339#if 0 
    312340    setfield(L,"reserved1",st.reserved1); 
     
    354382  {"stat",      os_stat}, // reyalp - NOT STANDARD 
    355383  {"utime",     os_utime}, // reyalp - NOT STANDARD 
    356   // TODO add directory listing functions 
    357384  {"remove",    os_remove}, 
    358385  {"rename",    os_rename}, 
  • trunk/makefile.inc

    r638 r654  
    262262HOSTCC=gcc 
    263263HOSTCFLAGS=-g -O2 -Wall 
     264HOSTAR=ar 
    264265 
    265266PAKWIF=$(topdir)tools/pakwif$(EXE) 
Note: See TracChangeset for help on using the changeset viewer.