static BOOL LookForEtcFile (void) { char etcfile [MAX_PATH + 1]; char buff [10]; struct passwd *pwd; if ((pwd = getpwuid (geteuid ())) != NULL) { strcpy (etcfile, pwd->pw_dir); if (etcfile [strlen (etcfile) - 1] != '/') strcat (etcfile, "/"); strcat (etcfile, "."); strcat (etcfile, ETCFILENAME); if (GetValueFromEtcFile (etcfile, "system", "gal_engine", buff, 8) == ETC_OK) { strcpy (ETCFILEPATH, etcfile); return TRUE; } } strcpy (etcfile, "/usr/local/etc/" ETCFILENAME); if (GetValueFromEtcFile (etcfile, "system", "gal_engine", buff, 8) == ETC_OK) { strcpy (ETCFILEPATH, etcfile); return TRUE; } strcpy (etcfile, "/etc/" ETCFILENAME); if (GetValueFromEtcFile (etcfile, "system", "gal_engine", buff, 8) == ETC_OK) { strcpy (ETCFILEPATH, etcfile); return TRUE; } return FALSE; }
/* Function: GetIntValueFromEtcFile(const char* pEtcFile, const char* pSection, * const char* pKey); * Parameter: * pEtcFile: etc file path name. * pSection: Section name. * pKey: Key name. * Return: * int meaning * ETC_FILENOTFOUND The etc file not found. * ETC_SECTIONNOTFOUND The section is not found. * ETC_EKYNOTFOUND The Key is not found. * ETC_OK OK. */ int GUIAPI GetIntValueFromEtcFile(const char* pEtcFile, const char* pSection, const char* pKey, int* value) { int ret; char szBuff [51]; ret = GetValueFromEtcFile (pEtcFile, pSection, pKey, szBuff, 50); if (ret < 0) return ret; *value = strtol (szBuff, NULL, 0); if ((*value == LONG_MIN || *value == LONG_MAX) && errno == ERANGE) return ETC_INTCONV; return ETC_OK; }
int GetStringFromResFiles(const char* pResFile, const char* pSection, const char* pKey, char* pString, int iLen,const char* pDefultStr) { char* tmpStr; char* strDelim="#"; char* p; int iChar; int iL; int i, j; int res; if(iLen <=1){ if(B_PRINTF) printf("---------------------------------------%s:%d Get String from file failure!!!!!!!!!", __FILE__, __LINE__); return -1; } res = GetValueFromEtcFile(pResFile, pSection, pKey, pString, iLen-1); if(res<0) { //if(B_PRINTF) printf("---------------------------------------%s:%d Get String from file failure!!!!!!!!!", __FILE__, __LINE__); if(pDefultStr!=NULL) strncpy(pString,pDefultStr,iLen); } return iLen; tmpStr = malloc(iLen); if(tmpStr !=NULL){ res = GetValueFromEtcFile(pResFile, pSection, pKey, tmpStr, iLen); if(res <0){ if(B_PRINTF) printf("%s:%d Get String Failure.\n", __FILE__, __LINE__); free(tmpStr); return -1; } if(B_PRINTF) printf("\n(%s:%d)Get source string is %s. lenth is %d.\n", __FILE__, __LINE__, tmpStr, strlen(tmpStr)); p = (char *)strtok(tmpStr, strDelim); iL= strlen(p); snprintf(pString, iL+1, "%s", p); if(B_PRINTF) printf("p: %s -- %d pvalue: %s -- %d\n", p, iL, pString, strlen(pString)); while((p=(char *)strtok(NULL, strDelim))){ if(isdigit(*p)){ iChar = atoi(p); if(B_PRINTF) printf("D-p: %s ---%d\n", p, iChar); pString[iL]= iChar; iL +=1; } else{ if(B_PRINTF) printf("C-p: %s ---%d, iL is %d.\n", p, strlen(p), iL); for(i=iL, j=0; i<(iL+strlen(p)+1); i++,j++){ pString[i] = p[j]; if(B_PRINTF) printf("i(%d) %c -> %c\n", i, p[j], pString[i]); } if(B_PRINTF) printf("%s --%d\n", pString, strlen(pString)); // iL += strlen(p)+2; iL += strlen(p); } } // if(B_PRINTF) printf("\n\n"); free(tmpStr); } return iLen; }
static BOOL get_dsp_app (void) { int i; DSPITEM* item; char section [10]; int distance_x = START_X; int distance_y = START_Y; SIZE size; if (GetIntValueFromEtcFile (APP_INFO_FILE, "desktop", "app_nr", &icon_info.nr_apps) != ETC_OK) return FALSE; if (icon_info.nr_apps <= 0) return FALSE; if (GetValueFromEtcFile (APP_INFO_FILE, "desktop", "bg_pic", icon_info.bg_path, PATH_MAX) != ETC_OK) return FALSE; if ((icon_info.app_items = (DSPITEM*)calloc (icon_info.nr_apps, sizeof (DSPITEM))) == NULL) { return FALSE; } item = icon_info.app_items; for (i = 0; i < icon_info.nr_apps; i++, item++) { sprintf (section, "dsp-app%d", i); if (GetValueFromEtcFile (APP_INFO_FILE, section, "path", item->path, PATH_MAX) != ETC_OK) goto error; if (GetValueFromEtcFile (APP_INFO_FILE, section, "name", item->name, NAME_MAX) != ETC_OK) goto error; if (GetValueFromEtcFile (APP_INFO_FILE, section, "layer", item->layer, LEN_LAYER_NAME) != ETC_OK) goto error; if (GetValueFromEtcFile (APP_INFO_FILE, section, "pictrue", item->bmp_path, PATH_MAX + NAME_MAX) != ETC_OK) goto error; if (LoadBitmap (HDC_SCREEN, &item->bmp, item->bmp_path) != ERR_BMP_OK) { fprintf (stderr, "desktop load resource:%s error. \n", item->bmp_path); goto error; } item->cdpath = TRUE; item->hot_spot_rc.left = distance_x; item->hot_spot_rc.right = item->hot_spot_rc.left + DEF_WIDTH; item->hot_spot_rc.top = distance_y; item->hot_spot_rc.bottom = item->hot_spot_rc.top + DEF_HEIGHT; GetTextExtent(HDC_SCREEN, item->name, -1, &size); item->text_rc.top = item->hot_spot_rc.bottom; item->text_rc.left = (item->hot_spot_rc.right + item->hot_spot_rc.left - size.cx)/2; item->text_rc.bottom = item->text_rc.top + size.cy; item->text_rc.right = item->text_rc.left + size.cx; distance_y += SPACE + RECTH(item->hot_spot_rc); if(distance_y + DEF_HEIGHT >= g_rcDesktop.bottom) { distance_y = START_Y; distance_x += SPACE + DEF_WIDTH; } } return TRUE; error: free_dsp_app (); return FALSE; }