Exemplo n.º 1
0
Arquivo: eyed.c Projeto: rsms/eye
static FSEventStreamRef my_FSEventStreamCreate(const char **paths, size_t num_paths)
{
  void         *user_data = (void *)(num_paths ? paths[0] : "?");
  FSEventStreamContext  context = {0, user_data, NULL, NULL, NULL};
  FSEventStreamRef    streamRef = NULL;
  CFMutableArrayRef   cfArray;
  
  // Settings
  FSEventStreamEventId sinceWhen = kFSEventStreamEventIdSinceNow;
  int                  flags = 0;
  CFAbsoluteTime       latency = 5.0; // How long it takes from that something 
                                      // happened to an event is dispatched.
  
  // Used as buffer for absolutize_path
  char abspath[PATH_MAX];
  
  // Create paths array
  cfArray = CFArrayCreateMutable(kCFAllocatorDefault, 1, &kCFTypeArrayCallBacks);
  if (NULL == cfArray) {
    log_error("CFArrayCreateMutable() => NULL");
    goto Return;
  }
  
  // Add paths to array
  for(int i=0; i<num_paths; i++) {
    absolutize_path(paths[i], abspath);
    CFStringRef cfStr = CFStringCreateWithCString(kCFAllocatorDefault, abspath, kCFStringEncodingUTF8);
    if (NULL == cfStr) {
      CFRelease(cfArray);
      goto Return;
    }
    CFArraySetValueAtIndex(cfArray, i, cfStr);
    CFRelease(cfStr);
  }
  
  // Create the stream
  streamRef = FSEventStreamCreate(kCFAllocatorDefault,
                  (FSEventStreamCallback)&fsevents_callback,
                  &context,
                  cfArray,
                  /*settings->*/sinceWhen,
                  /*settings->*/latency,
                  /*settings->*/flags);
  
  // Check if FSEventStreamCreate failed
  if (NULL == streamRef) {
    log_error("FSEventStreamCreate() failed");
    goto Return;
  }
  
  // Print the setup
  IFDEBUG(
    FSEventStreamShow(streamRef);
  )
Exemplo n.º 2
0
static void set_default(max_hosts)
{
	int i, j;
	int default_section;
	char *string_default;
	int integer_default;
	bool boolean_default;

	default_section = cfgSectionNameToNumber("default");
	if (default_section == -1) {
		fprintf(stderr, _("Section `default' is required.\n"));
		exit(1);
	}
	for (i = 0; i < max_hosts; i++) {
		for (j = 0; config_table[j].type != CFG_END; j++) {
			switch (config_table[j].type) {
			case CFG_STRING:
				if (*(*(char ***) (config_table[j].value) + i) == NULL) {	/* The section doesn't have the parameter. */
					if (*(*(char ***) (config_table[j].value) + default_section) == NULL) {	/* Section `default' doesn't have the parameter. */
						string_default = get_string_internal_default(config_table[j].parameterName, i);
						if (string_default != NULL) {	/* If weex has internal default value, use it. */
							*(*(char ***) (config_table[j].value) + i) = string_default;
						}
					} else {	/* Section `default' has the parameter. */
						if (strcmp(config_table[j].parameterName, "CacheFile") == 0) { /* Add section name to the value, if parameter is `CacheFile'. */
							*(*(char ***) (config_table[j].value) + i) = str_concat(*(*(char ***) (config_table[j].value) + default_section), ".", cfgSectionNumberToName(i), NULL);
						} else {
							*(*(char ***) (config_table[j].value) + i) = str_dup(*(*(char ***) (config_table[j].value) + default_section));
						}
					}
				}
				break;
			case CFG_INT:
				if (*(*(int **) (config_table[j].value) + i) == -1) {	/* The section doesn't have the parameter. */
					if (*(*(int **) (config_table[j].value) + default_section) == -1) {	/* Section `default' doesn't have the parameter. */
						integer_default = get_integer_internal_default(config_table[j].parameterName);
						if (integer_default != -1) {	/* If weex has internal default value, use it. */
							*(*(int **) (config_table[j].value) + i) = integer_default;
						}
					} else {	/* Section `default' has the parameter. */
						*(*(int **) (config_table[j].value) + i) = *(*(int **) (config_table[j].value) + default_section);
					}
				}
				break;
			case CFG_BOOL:
				if (*(*(bool **) (config_table[j].value) + i) == -1) {	/* The section doesn't have the parameter. */
					if (*(*(bool **) (config_table[j].value) + default_section) == -1) {	/* Section `default' doesn't have the parameter. */
						boolean_default = get_boolean_internal_default(config_table[j].parameterName);
						if (boolean_default != -1) {	/* If weex has internal default value, use it. */
							*(*(bool **) (config_table[j].value) + i) = boolean_default;
						}
					} else {	/* Section `default' has the parameter. */
						*(*(bool **) (config_table[j].value) + i) = *(*(bool **) (config_table[j].value) + default_section);
					}
				}
				break;
			case CFG_STRING_LIST:
				if (*(*(cfgList ***) (config_table[j].value) + i) == NULL) {	/* The section doesn't have the parameter. */
					if (*(*(cfgList ***) (config_table[j].value) + default_section) != NULL) {	/* Section `default' have the parameter. */
						*(*(cfgList ***) (config_table[j].value) + i) = copy_cfg_list(*(*(cfgList ***) (config_table[j].value) + default_section));
					}
				}
				break;
			default:
				internal_error(__FILE__, __LINE__);
			}
			remove_trailing_slash(j, i);
			absolutize_path(j, i);
		}
	}
}