int main(int argc, char *argv[]) { /* Performance */ clock_t begin, end; double time_spent; begin = clock(); /* Some variables to initialise the input files read */ FILE *inputMovieData = fopen(argv[1], "r"); FILE *outputFile = fopen(argv[2], "w"); /* Initialise a global tree of type node */ node *tree = makedict(); /* Read in the binary tree with data from argv 1 */ createBinaryTree(tree, inputMovieData); /* Search the tree and write the data to a file specified in argv 2 */ searchTree(tree, outputFile); /* Close the files at the end */ fclose(inputMovieData); fclose(outputFile); /* Performance Log */ end = clock(); time_spent = (double) (end - begin) / CLOCKS_PER_SEC; printf("\nEXECUTION TIME: %.5f seconds\n", time_spent); return 0; }
int makenapply(const char *key, const char *val) { int ret = 1; CFMutableDictionaryRef dict = makedict(key, val); if(!dict) { ERROR("failed to make cf dict\n"); return ret; } ret = applydict(dict); if (ret) { ERROR("applydict failed\n"); } CFRelease(dict); return ret; }
int main(void) { LBIG memsetup[5] = { 1000, 100, 20, 10, 200 }; B* startup_dvt; B fromconsoleframe[FRAMEBYTES], *sf; P nb, retc,tnb; B *sysdict, *userdict, *p; int sufd; sysop = _sysop; syserrc = _syserrc; syserrm = _syserrm; createfds(); serialized = TRUE; // no serialize operator /*----------------- SIGNALS that we wish to handle -------------------*/ /* FPU indigestion is recorded in the numovf flag; we do not wish to be killed by it */ numovf = FALSE; signal(SIGFPE, SIGFPEhandler); /* The broken pipe signal is ignored, so it cannot kill us; it will pop up in attempts to send on a broken connection */ signal(SIGPIPE, SIG_IGN); /* We use alarms to time-limit read/write operations on sockets */ timeout = FALSE; signal(SIGALRM, SIGALRMhandler); /* The interrupt signal is produced by the control-c key of the console keyboard, it triggers the execution of 'abort' */ abortflag = FALSE; signal(SIGINT, SIGINThandler); /*--------------------- set up the tiny D machine ------------------- Not so tiny for the dvt, this should be good for most work */ if (makeDmemory(memsetup)) dm_error(0, "D memory"); /*----------------- construct frames for use in execution of D code */ makename((B*) "error", errorframe); ATTR(errorframe) = ACTIVE; makename((B*) "fromconsole", fromconsoleframe); ATTR(fromconsoleframe) = ACTIVE; TAG(FREEvm) = STRING; ARRAY_SIZE(FREEvm) = 1024; VALUE_PTR(FREEvm) = FREEvm + FRAMEBYTES; ATTR(FREEvm) = ACTIVE; moveframe(FREEvm, inputframe); FREEvm += FRAMEBYTES + 1024; /* The system dictionary is created in the workspace of the tiny D machine. If the operator 'makeVM' is used to create a large D machine, this larger machine inherits the system dictionary of the tiny machine. We memorize the pointers of the tiny D memory so we can revert to the tiny setup. */ if ((sysdict = makeopdict((B *)sysop, syserrc, syserrm)) == (B *)(-1L)) dm_error(0,"Cannot make system dictionary"); if ((userdict = makedict(memsetup[4])) == (B *)(-1L)) dm_error(0,"Cannot make user dictionary"); /* The first two dictionaries on the dicts are systemdict and userdict; they are not removable */ moveframe (sysdict-FRAMEBYTES,FREEdicts); FREEdicts += FRAMEBYTES; moveframe (userdict-FRAMEBYTES,FREEdicts); FREEdicts += FRAMEBYTES; setupdirs(); fprintf(stderr, "Startup dir: %s\n", startup_dir); /*----------- read startup_dvt.d and push on execs ----------*/ startup_dvt = (B*)strcat(strcpy(malloc(strlen((char*)startup_dir) + strlen("/startup_dgen.d") + 1), startup_dir), "/startup_dgen.d"); if ((sufd = open((char*)startup_dvt, O_RDONLY)) == -1) dm_error(errno,"Opening %s", startup_dvt); tnb = 0; sf = FREEvm; p = sf + FRAMEBYTES; TAG(sf) = ARRAY | BYTETYPE; ATTR(sf) = READONLY | ACTIVE | PARENT; VALUE_BASE(sf) = (P)p; while (((nb = read(sufd,p,CEILvm-p)) > 0) && (p <= CEILvm)) { tnb += nb; p += nb; } if (nb == -1) dm_error(errno,"Reading %s", startup_dvt); if (p == CEILvm) dm_error(ENOMEM,"%s > VM", startup_dvt); ARRAY_SIZE(sf) = tnb; FREEvm += DALIGN(FRAMEBYTES + tnb); moveframe(sf,x1); FREEexecs = x2; /*-------------------------- run the D mill --------------------- */ while (1) { switch(retc = exec(1000)) { case MORE: continue; case DONE: moveframe(fromconsoleframe, x1); FREEexecs=x2; continue; case ABORT: printf("Failure...\n"); exitval = ((UL32) EXIT_FAILURE) & 0xFF; die(); case QUIT: case TERM: printf("Success..\n"); die(); default: break; } /*----------------------- error handler ---------------------------*/ makeerror(retc, errsource); }; } /* of main */