JSValueRef function_cache(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef args[], JSValueRef *exception) { if (argc == 4 && JSValueGetType(ctx, args[0]) == kJSTypeString && JSValueGetType(ctx, args[1]) == kJSTypeString && (JSValueGetType(ctx, args[2]) == kJSTypeString || JSValueGetType(ctx, args[2]) == kJSTypeNull) && (JSValueGetType(ctx, args[3]) == kJSTypeString || JSValueGetType(ctx, args[3]) == kJSTypeNull)) { // debug_print_value("cache", ctx, args[0]); char *cache_prefix = value_to_c_string(ctx, args[0]); char *source = value_to_c_string(ctx, args[1]); char *cache = value_to_c_string(ctx, args[2]); char *sourcemap = value_to_c_string(ctx, args[3]); char *suffix = NULL; int max_suffix_len = 20; size_t prefix_len = strlen(cache_prefix); char *path = malloc((prefix_len + max_suffix_len) * sizeof(char)); memset(path, 0, prefix_len + max_suffix_len); suffix = ".js"; strcpy(path, cache_prefix); strcat(path, suffix); write_contents(path, source); suffix = ".cache.json"; strcpy(path, cache_prefix); strcat(path, suffix); write_contents(path, cache); suffix = ".js.map.json"; strcpy(path, cache_prefix); strcat(path, suffix); if (sourcemap) { write_contents(path, sourcemap); } free(cache_prefix); free(source); free(cache); free(sourcemap); free(path); } return JSValueMakeNull(ctx); }
int main(int argc, char *argv[]) { int port; char *name = NULL; union { short word; char bytes[2]; } endianTest; endianTest.bytes[0] = 1; endianTest.bytes[1] = 0; if (endianTest.word == 1) { strcpy(endianness, "little"); } else { strcpy(endianness, "big"); } /* verify that all datatypes have the expected syze in bytes */ check_datatypes(); #ifdef WIN32 timeBeginPeriod(1); #endif if (argc<2) { fprintf(stderr, "Usage: recording <directory> [port/unix socket]\n"); return 1; } strncpy(baseDirectory, argv[1], sizeof(baseDirectory)); if (argc>2) { port = atoi(argv[2]); if (port == 0) { name = argv[2]; } } else { port = 1972; } memset(queue, sizeof(queue), 0); if (!write_contents()) goto cleanup; S = ft_start_buffer_server(port, name, my_request_handler, NULL); if (S==NULL) return 1; signal(SIGINT, abortHandler); while (keepRunning) { if (queue[qReadPos].command == 0) { usleep(1000); } else { switch(queue[qReadPos].command) { case PUT_HDR: if (setCounter>0) ft_storage_close(OS); write_header_to_disk(); if (OS==NULL) { fprintf(stderr, "!!!!!!!!!!!!! WARNING !!!!!!!!!!\n"); fprintf(stderr, "!! will NOT save this dataset !!\n"); fprintf(stderr, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); } break; case PUT_DAT: if (OS) write_samples_to_disk(queue[qReadPos].quantity, queue[qReadPos].t); break; case PUT_EVT: if (OS) write_events_to_disk(queue[qReadPos].quantity, queue[qReadPos].t); break; } queue[qReadPos].command = 0; if (++qReadPos == QUEUE_SIZE) qReadPos = 0; } } printf("Ctrl-C pressed -- stopping buffer server...\n"); if (setCounter>0 && OS!=NULL) ft_storage_close(OS); ft_stop_buffer_server(S); printf("Done.\n"); cleanup: #ifdef WIN32 timeEndPeriod(1); #endif return 0; }
int main(int argc, char ** argv) { struct Node * head = NULL; char index_file_name[1024]; FILE * index_fd = NULL; char file_or_dir[1024]; char cwd[1024]; DIR *dp; struct dirent *ep; struct hash_table * table = new_hash_table(256); struct stat sb; if (argc != 3) { puts("usage:\n\tindexer <index file> <dir or file>"); return 0; } getcwd(file_or_dir, sizeof(file_or_dir)); strcat(file_or_dir, "/"); strcat(file_or_dir, argv[2]); index_fd = fopen(argv[1], "w+"); /* check if the index file exists to make a hash table from it */ if (index_fd == NULL) { fprintf(stderr, "could not open or create an index file %s\n", argv[1]); return 1; } /* if a folder is in the local dir, use it. otherwise assume it's an absolute dir */ printf("checking for %s\n", file_or_dir); stat(file_or_dir, &sb); if ( S_ISREG(sb.st_mode) ) { index_file(file_or_dir, table); } else if ( S_ISDIR(sb.st_mode) ) { dp = opendir (argv[2]); if ((ep = readdir (dp)) != NULL && ep->d_type == DT_DIR) { strcpy(cwd, argv[2]); } else { strcat(cwd, "/"); strcat(cwd, argv[2]); } head = get_files_in_folder(head, cwd); while (head) { index_file(head->data, table); head = head->next; } } else { fprintf(stderr, "no such directory of file found: %s\n", file_or_dir); return 1; } write_contents(table, index_fd); free_hash_table(table); fclose(index_fd); return 0; }