static int dirWalk(const char * dn) { rpmop op = memset(alloca(sizeof(*op)), 0, sizeof(*op)); int xx = rpmswEnter(op, 0); DIR * dir; struct dirent * dp; off_t d_off = -1; int nentries = 0; int rc = 1; if ((dir = Opendir(dn)) == NULL) goto exit; while ((dp = Readdir(dir)) != NULL) { if (nentries == 0) d_off = Telldir(dir); printDir(dp, Telldir(dir), nentries++); } #ifdef NOISY nentries = 0; Rewinddir(dir); while ((dp = Readdir(dir)) != NULL) printDir(dp, Telldir(dir), nentries++); Seekdir(dir, d_off); while ((dp = Readdir(dir)) != NULL) { printDir(dp, Telldir(dir), 0); break; } #endif rc = Closedir(dir); #ifdef REFERENCE { struct dirent ** dirents = NULL; int i; nentries = Scandir(dn, &dirents, NULL, Alphasort); for (i = 0; i < nentries; i++) { dp = dirents[i]; printDir(dp, dp->d_off, i); dirents[i] = _free(dirents[i]); } dirents = _free(dirents); } #endif exit: xx = rpmswExit(op, nentries); fprintf(stderr, "===== %s: %d entries\n", dn, nentries); if (_rpmsw_stats) rpmswPrint("opendir:", op, NULL); return rc; }
int main(int argc, char *argv[]) { int i = 0; int numDir = 5; FILE *file = NULL; char *buffer[20]; signal(SIGALRM, SIG_DFL); alarm(2); signal(SIGALRM, handler_alarm); createDir(); for (i = 0; i < numDir; i++) { printf("Creando archivos\n"); int signal; flag = 1; file = fopen(buffer, "w+"); sprintf(buffer, "./Data/a%d", i); alarm(3); while (flag) fputc('x', file); fclose(file); } printf("INFO\n\n"); printDir(); return 0; }
// /?/web_server.c=111&/1.html=&/2.html=&/server_options.c=&/web=&/dir.c~=&/server_options.h=&/no= int getRenameInfo (int fd, char web_root[], char url_link[]) { char file_tmp[DIR_LENGTH]; memset(file_tmp, 0, DIR_LENGTH*sizeof(char)); char name_tmp[32]; memset(name_tmp, 0, 32*sizeof(char)); char path_tmp[DIR_LENGTH]; memset(path_tmp, 0, DIR_LENGTH*sizeof(char)); char current_path[DIR_LENGTH]; memset(current_path, 0, DIR_LENGTH*sizeof(char)); int i, j; int pos_equal = 0; int pos_and = 0; sscanf(url_link, "%*[^.].%[^?]", current_path); printf("current path1 %s\n", current_path); char* seps = "."; char* token = strtok( current_path, seps ); while( token != NULL ) { strcpy(current_path,token); token = strtok( NULL, seps ); } // memset(current_path, 0, DIR_LENGTH*sizeof(char)); printf("current path2 %s\n", current_path); char strTmp[DIR_LENGTH]; strcpy(strTmp,url_link); seps = "/&"; token = strtok( strTmp, seps ); while( token != NULL ) { /* While there are tokens in "string" */ printf( " %s\n", token ); /* process:get new name */ sscanf(token, "%[^=]=%s", file_tmp, name_tmp); //get file and new name if (strlen(name_tmp) != 0) { printf("file %s\nname %s len= %d\n", file_tmp, name_tmp,strlen(name_tmp)); sprintf(path_tmp,"%s%s/%s",web_root,current_path,file_tmp); printf("file %s\n", path_tmp); if ( reName(path_tmp,name_tmp) == 0 ) { printf("reName%s to %s\n",path_tmp,name_tmp ); } memset(name_tmp, 0, 32*sizeof(char)); memset(path_tmp, 0, DIR_LENGTH*sizeof(char)); memset(file_tmp, 0, DIR_LENGTH*sizeof(char)); } /* Get next token: */ token = strtok( NULL, seps ); } printDir(fd, web_root, current_path); return 0; }
int deteleFiles (int fd, char web_root[], char offset_dir[]) { int len = strlen(offset_dir); if ( ( *(offset_dir+len-1) != '.') ) { printf("_dir%s\n", offset_dir); printf("The last character is not '.',not delete command\n"); return -1; } *(offset_dir+len-1) = '\0'; char path[DIR_LENGTH]; memset(path,0,DIR_LENGTH*sizeof(char)); strcpy(path,web_root); strcat(path,offset_dir); printf("delete file %s\n",path); char parent_dir[DIR_LENGTH] ; memset(parent_dir,0,DIR_LENGTH*sizeof(char)); getParentDir(parent_dir,offset_dir); printf("uri %s parent dir %s\n",offset_dir,parent_dir); if( remove(path) != 0 ) { perror("delete file error!"); return -1; } printDir(fd, web_root, parent_dir); return 0; }
void inst(const std::string &where, bool doUpgrade) { cout << "\nINSTALLING to " << where << endl; JobInfoPtr inf = spr->installPack("test", "test", where, NULL, false, doUpgrade); if(inf) if(inf->isSuccess()) cout << "SUCCESS!\n"; else inf->failError(); else cout << "NO JOB EXECUTED\n"; printDir(where); }
void Finger::printDetails(void) { MYSERIAL.print("Finger "); MYSERIAL.print(fingerIndex); MYSERIAL.print(" "); printSpeed(); printPos(); printDir(); printReached(true); // print new line after }
//moves in direction d void moveDirection(int x, int y, int d, char ** maze, int w, int h){ int type = HALLWAY;//holds the type of the current point (HALLWAY to start the loop) int i = 0; int a = x; int b = y; while(type == HALLWAY){ appendLocation(&a, &b, d); type = spaceType(a, b, d, maze, w, h); i++; } //print direction int opposite; opposite = printDir(d, i); //if the type is an intersection if (type == INTERSECTION) { atIntersection(a, b, d, maze, w, h); } //print opposite direction to return to previous intersection d = printDir(opposite, i); }
int main() { char cmdLine[MAXLINE]; char cmdPart[2]; while(1) { /* read */ printDir(); fgets(cmdLine, MAXLINE, stdin); if(feof(stdin)) { exit(0); } /* evaluate */ eval(cmdLine); } }
void print_directions(char** maze, int w, int h){ //find the start of the maze int i = 0; int j = 0; while(maze[0][i] != ' ') { i++; } printf("the entrance is location (0, %d\n", i); //move south until an intersection int a = 0; int b = i; int type = HALLWAY; while(type == HALLWAY){ appendLocation(&a, &b, SOUTH); type = spaceType(a, b, SOUTH, maze, w, h); j++; } printDir(SOUTH, j); atIntersection(a, b, SOUTH, maze, w, h); }
void TestCFSM::printDir(const QString dirname, const int depth) { QTextStream console(stdout); QModelIndex index; QModelIndex dir; dir = _model.index(dirname); for(int i = 0; i < _model.rowCount(dir); i++) { index = dir.child(i, dir.column()); console << _model.data(index, Qt::CheckStateRole).toInt() << "\t"; // Add indents to show the directory structure. for(int j = 0; j < depth; j++) console << "\t"; console << _model.fileName(index) << endl; // Recursively print the subdirectory. if(_model.isDir(index)) { printDir(_model.filePath(index), depth + 1); } } }
void execCommand(char* command) { // Interpret the user command if(isCommand("boot\0", command)) { interrupt(33, 11, 0, 0, 0); } else if(isCommand("cls\0", command)) { interrupt(33, 12, 4, 11, 0); } else if(isCommand("dir\0", command)) { printDir(); } else if(isCommand("copy\0", command)) { copy(command + 5); } else if(isCommand("del\0", command)) { delete(command + 4); } else if(isCommand("echo\0", command)) { echo(command + 5); } else if(isCommand("type\0", command)) { type(command + 5); } else if(isCommand("run\0", command)) { run(command + 4); } else if(isCommand("tweet\0", command)) { tweet(command + 6); } else if(isCommand("help\0", command)) { help(); } else { commandNotRecognized(); } }
int main() { /* DIRECTORY AND MEMORY OBJECTS */ /* I know the array is unnecessary, but at 2am my brain isnt entirely working very well to optimise shit so i just did whatever worked */ struct Entry directory[MAX_SPACE]; // array of directory entries Entry* head = NULL; // head of linked list int entries = 0; // keeps track of number of entries int blkCount; // number of blocks needed int tokCount; // keeps track of file data int arrCount; // keeps track of index /* INPUT OBJECTS */ char file[30]; // for input string int i = 0, itemCount = 0; // number of items currently in list out of MAX_SIZE char *input[MAX_LINES]; // maximum number of instructions to be processed char *copy[MAX_LINES]; // to copy the input line (otherwise menu gets messed up) char line[1024]; // fgets buffer char *tok[MAX_NUM_TOKENS]; // maximum number of tokens for each line of instructions int len; // length for each tokenised line int exe; // its definitely used somewhere in this code trust me // input file do { printf("\nEnter input file name (with .csv): "); scanf("%s", &file); } while (access(file, F_OK) != 0); FILE* stream = fopen(file, "r"); // add items from buffer into input and increment itemCount for each item while (fgets(line, 1024, stream)) { input[i] = strdup(line); copy[i] = strdup(line); i++; itemCount++; char* tmp = strdup(line); free(tmp); } printf("File loaded!"); do { printf("\n\nType index of line to execute: \n"); for (int j = 1; j < itemCount; j++) printf("%d: %s", j, input[j]); printf("%d: view directory\n%d: view system\n%d: exit\n>> ", itemCount, itemCount + 1, itemCount + 2); scanf("%d", &exe); if (exe == itemCount) printDir(head); else if (exe == itemCount + 1) printSys(); else if (exe < itemCount) { if (strcmp(input[exe], "NULL\n") == 0) continue; strcpy(copy[exe], input[exe]); // duplicate string len = tokenise(copy[exe], tok); // tokenise string // ADDING if (strcmp(tok[0], "add") == 0) { blkCount = ((len - 1) / 3) + ((len - 1) % 3); // determine number of blocks needed int blkArray[blkCount]; // array of available blocks // check if there is enough space if (checkSpace(blkCount, blkArray) == 0) { tokCount = 1; // start from the second elent in tok[] for (int i = 0; i < blkCount; i++) { arrCount = 0; // counter for index inside block array // while not all the tokens are loaded while (tokCount != len && arrCount < 3) { // loading into file system!!! yay // printf("Putting %d in %d\n", atoi(tok[tokCount]), (blkArray[i] * 4) + arrCount); fileSystem[(blkArray[i] * 4) + arrCount] = atoi(tok[tokCount]); tokCount++; arrCount++; } // if all data is loaded if (tokCount == len) printf(""); else { // linking!!!! woooo // printf("Linking %d to %d\n", blkArray[i] + 3, blkArray[i + 1]); fileSystem[(blkArray[i] * 4) + 3] = blkArray[i + 1]; // links to the next block } } // updating directory Entry entry = { atoi(tok[1]), blkArray[0], blkArray[blkCount - 1], NULL }; directory[entries] = entry; // if the entry is the first entry, head = that entry if (entries == 0) head = &directory[entries]; // link prev entry to current entry if ((entries - 1) >= 0) directory[entries - 1].next = &directory[entries]; entries++; printf("\nEntry %d loaded!\n", exe); strcpy(input[exe], "NULL\n"); } else printf("There isn't enough space in memory.\n"); } // READING else if (strcmp(tok[0], "read") == 0) { // run time is like more than O(n) sorry Entry* curr = head; while (curr != NULL) { if (atoi(tok[1]) - curr->file < 0) curr = curr->next; else { int block = curr->start; while (1) // while true la ok everything also while true { for (arrCount = 0; arrCount < 3; arrCount++) { if (fileSystem[(block * 4) + arrCount] == atoi(tok[1])) { printf("\nFile: %d is located at block %d, index %d.\n", atoi(tok[1]), block, (block * 4) + arrCount); break; } } if (block == curr->end) break; block = fileSystem[(block * 4) + 3]; // move on to the next block } } break; } } // DELETING else if (strcmp(tok[0], "delete") == 0) { // run time is also O(n) sorry Entry* curr = head; Entry* prev = NULL; while (curr != NULL) { if (curr->file != atoi(tok[1])) { prev = curr; curr = curr->next; } else { int block = curr->start; while (1) { // deleting for (arrCount = 0; arrCount < 3; arrCount++) fileSystem[(block * 4) + arrCount] = 0; // if all data is deleted if (block == curr->end) break; else block = fileSystem[(block * 4) + 3]; // move on to the next block } // updating directory if (entries == 1) // if entry is the only entry in directory head = NULL; else if (entries > 1) prev->next = curr->next; // link the entry behind to the entry ahead entries--; printf("\nEntry %d deleted!\n", curr->file); break; } } } } } while (exe != itemCount + 2); printf("\nBye!\n"); }
int main(int argc, char * argv[], char * env[]) { char line[128], command[128], pathname[128]; int ID; // DEVICE SELECT get_device(); // INITIALIZE init(); // MOUNT ROOT mount_root(); // PROCESS LOOP while(1) { strcpy(line, ""); strcpy(command, ""); strcpy(pathname, ""); strcpy(completePath, ""); printf("\n\ninput a command (type help for more info): "); //read a line containting command [pathname]; // [ ] means optional fgets(line, 256, stdin); line[strlen(line)-1] = '\0'; //Find the command string and call the corresponding function; parseString(line, arg1, command, pathname); compPath(pathname); printf("PATHNAME: %s\n", pathname); ID = findCommand(command); switch(ID) { case -1 : printDir(running->cwd->ino); break; case 0 : _menu (arg1, pathname); break; case 1 : _ls (arg1, pathname); break; case 2 : _cd (arg1, pathname); break; case 3 : _mkdir (arg1, pathname); break; case 4 : _rmdir (arg1, pathname); break; case 5 : _pwd (arg1, pathname); break; case 6 : _creat0(arg1, pathname); break; case 7 : _rm (arg1, pathname); break; case 8 : _stat (arg1, pathname); break; case 9 : compPath(arg1); _link(arg1, pathname); break; case 10: _unlink(arg1, pathname); break; case 11: compPath(arg1); _symlink(arg1, pathname); break; case 12: _touch (arg1, pathname); break; case 13: _chmod (arg1, pathname); break; case 14: _chown (arg1, pathname); break; case 15: _chgrp (arg1, pathname); break; case 16: _open (arg1, pathname); break; case 17: _close (arg1, pathname); break; case 18: _read (arg1, pathname); break; case 19: _write (arg1, pathname); break; case 20: _pfd (arg1, pathname); break; case 21: _lseek (arg1, pathname); break; case 22: _cat (arg1, pathname); break; case 23: _cp (arg1, pathname); break; case 24: _mv (arg1, pathname); break; case 25: __exit (arg1, pathname); break; } } quit(); return 0; }
void ComputeIntersection(Vec *P, Vec *Q) { Vec Pdir, Qdir; /* "Current" directed edges on P and Q */ Vec other; /* Temporary "edge-like" variable */ int ip, iq; /* Indices of ends of Pdir, Qdir */ int ip_begin, iq_begin; /* Indices of beginning of Pdir, Qdir */ int PToQDir; /* Qdir direction relative to Pdir */ /* (e.g. CLOCKWISE) */ int qEndpointFromPdir; /* End P vertex as viewed from beginning */ /* of Qdir relative to Qdir */ int pEndpointFromQdir; /* End Q vertex as viewed from beginning */ /* of Pdir relative to Pdir */ Vec firstIntersection; /* Point of intersection of Pdir, Qdir */ Vec secondIntersection; /* Second point of intersection */ /* (if there is one) */ int interiorFlag; /* Which polygon is inside the other */ int contained; /* Used for "completely contained" check */ int p_advances, q_advances; /* Number of times we've advanced */ /* P and Q indices */ int isFirstPoint; /* Is this the first point? */ int intersectionCode; /* SegSegIntersect() return code. */ /* Check for Q contained in P */ contained = TRUE; for(ip=0; ip<np; ++ip) { ip_begin = (ip + np - 1) % np; Cross(&P[ip_begin], &P[ip], &Pdir); Normalize(&Pdir); for(iq=0; iq<nq; ++iq) { if(debug >= 4) { printf("Q in P: Dot%d%d = %12.5e\n", ip, iq, Dot(&Pdir, &Q[iq])); fflush(stdout); } if(Dot(&Pdir, &Q[iq]) < -tolerance) { contained = FALSE; break; } } if(!contained) break; } if(contained) { if(debug >= 4) { printf("Q is entirely contained in P (output pixel is in input pixel)\n"); fflush(stdout); } for(iq=0; iq<nq; ++iq) SaveVertex(&Q[iq]); return; } /* Check for P contained in Q */ contained = TRUE; for(iq=0; iq<nq; ++iq) { iq_begin = (iq + nq - 1) % nq; Cross(&Q[iq_begin], &Q[iq], &Qdir); Normalize(&Qdir); for(ip=0; ip<np; ++ip) { if(debug >= 4) { printf("P in Q: Dot%d%d = %12.5e\n", iq, ip, Dot(&Qdir, &P[ip])); fflush(stdout); } if(Dot(&Qdir, &P[ip]) < -tolerance) { contained = FALSE; break; } } if(!contained) break; } if(contained) { if(debug >= 4) { printf("P is entirely contained in Q (input pixel is in output pixel)\n"); fflush(stdout); } nv = 0; for(ip=0; ip<np; ++ip) SaveVertex(&P[ip]); return; } /* Then check for polygon overlap */ ip = 0; iq = 0; p_advances = 0; q_advances = 0; interiorFlag = UNKNOWN; isFirstPoint = TRUE; while(FOREVER) { if(p_advances >= 2*np) break; if(q_advances >= 2*nq) break; if(p_advances >= np && q_advances >= nq) break; if(debug >= 4) { printf("-----\n"); if(interiorFlag == UNKNOWN) { printf("Before advances (UNKNOWN interiorFlag): ip=%d, iq=%d ", ip, iq); printf("(p_advances=%d, q_advances=%d)\n", p_advances, q_advances); } else if(interiorFlag == P_IN_Q) { printf("Before advances (P_IN_Q): ip=%d, iq=%d ", ip, iq); printf("(p_advances=%d, q_advances=%d)\n", p_advances, q_advances); } else if(interiorFlag == Q_IN_P) { printf("Before advances (Q_IN_P): ip=%d, iq=%d ", ip, iq); printf("(p_advances=%d, q_advances=%d)\n", p_advances, q_advances); } else printf("\nBAD INTERIOR FLAG. Shouldn't get here\n"); fflush(stdout); } /* Previous point in the polygon */ ip_begin = (ip + np - 1) % np; iq_begin = (iq + nq - 1) % nq; /* The current polygon edges are given by */ /* the cross product of the vertex vectors */ Cross(&P[ip_begin], &P[ip], &Pdir); Cross(&Q[iq_begin], &Q[iq], &Qdir); PToQDir = DirectionCalculator(&P[ip], &Pdir, &Qdir); Cross(&Q[iq_begin], &P[ip], &other); pEndpointFromQdir = DirectionCalculator(&Q[iq_begin], &Qdir, &other); Cross(&P[ip_begin], &Q[iq], &other); qEndpointFromPdir = DirectionCalculator(&P[ip_begin], &Pdir, &other); if(debug >= 4) { printf(" "); printDir("P", "Q", PToQDir); printDir("pEndpoint", "Q", pEndpointFromQdir); printDir("qEndpoint", "P", qEndpointFromPdir); printf("\n"); fflush(stdout); } /* Find point(s) of intersection between edges */ intersectionCode = SegSegIntersect(&Pdir, &Qdir, &P[ip_begin], &P[ip], &Q[iq_begin], &Q[iq], &firstIntersection, &secondIntersection); if(intersectionCode == NORMAL_INTERSECT || intersectionCode == ENDPOINT_ONLY) { if(interiorFlag == UNKNOWN && isFirstPoint) { p_advances = 0; q_advances = 0; isFirstPoint = FALSE; } interiorFlag = UpdateInteriorFlag(&firstIntersection, interiorFlag, pEndpointFromQdir, qEndpointFromPdir); if(debug >= 4) { if(interiorFlag == UNKNOWN) printf(" interiorFlag -> UNKNOWN\n"); else if(interiorFlag == P_IN_Q) printf(" interiorFlag -> P_IN_Q\n"); else if(interiorFlag == Q_IN_P) printf(" interiorFlag -> Q_IN_P\n"); else printf(" BAD interiorFlag. Shouldn't get here\n"); fflush(stdout); } } /*-----Advance rules-----*/ /* Special case: Pdir & Qdir overlap and oppositely oriented. */ if((intersectionCode == COLINEAR_SEGMENTS) && (Dot(&Pdir, &Qdir) < 0)) { if(debug >= 4) { printf(" ADVANCE: Pdir and Qdir are colinear.\n"); fflush(stdout); } SaveSharedSeg(&firstIntersection, &secondIntersection); RemoveDups(); return; } /* Special case: Pdir & Qdir parallel and separated. */ if((PToQDir == PARALLEL) && (pEndpointFromQdir == CLOCKWISE) && (qEndpointFromPdir == CLOCKWISE)) { if(debug >= 4) { printf(" ADVANCE: Pdir and Qdir are disjoint.\n"); fflush(stdout); } RemoveDups(); return; } /* Special case: Pdir & Qdir colinear. */ else if((PToQDir == PARALLEL) && (pEndpointFromQdir == PARALLEL) && (qEndpointFromPdir == PARALLEL)) { if(debug >= 4) { printf(" ADVANCE: Pdir and Qdir are colinear.\n"); fflush(stdout); } /* Advance but do not output point. */ if(interiorFlag == P_IN_Q) iq = Advance(iq, &q_advances, nq, interiorFlag == Q_IN_P, &Q[iq]); else ip = Advance(ip, &p_advances, np, interiorFlag == P_IN_Q, &P[ip]); } /* Generic cases. */ else if(PToQDir == COUNTERCLOCKWISE || PToQDir == PARALLEL) { if(qEndpointFromPdir == COUNTERCLOCKWISE) { if(debug >= 4) { printf(" ADVANCE: Generic: PToQDir is COUNTERCLOCKWISE "); printf("|| PToQDir is PARALLEL, "); printf("qEndpointFromPdir is COUNTERCLOCKWISE\n"); fflush(stdout); } ip = Advance(ip, &p_advances, np, interiorFlag == P_IN_Q, &P[ip]); } else { if(debug >= 4) { printf(" ADVANCE: Generic: PToQDir is COUNTERCLOCKWISE "); printf("|| PToQDir is PARALLEL, qEndpointFromPdir is CLOCKWISE\n"); fflush(stdout); } iq = Advance(iq, &q_advances, nq, interiorFlag == Q_IN_P, &Q[iq]); } } else { if(pEndpointFromQdir == COUNTERCLOCKWISE) { if(debug >= 4) { printf(" ADVANCE: Generic: PToQDir is CLOCKWISE, "); printf("pEndpointFromQdir is COUNTERCLOCKWISE\n"); fflush(stdout); } iq = Advance(iq, &q_advances, nq, interiorFlag == Q_IN_P, &Q[iq]); } else { if(debug >= 4) { printf(" ADVANCE: Generic: PToQDir is CLOCKWISE, "); printf("pEndpointFromQdir is CLOCKWISE\n"); fflush(stdout); } ip = Advance(ip, &p_advances, np, interiorFlag == P_IN_Q, &P[ip]); } } if(debug >= 4) { if(interiorFlag == UNKNOWN) { printf("After advances: ip=%d, iq=%d ", ip, iq); printf("(p_advances=%d, q_advances=%d) interiorFlag=UNKNOWN\n", p_advances, q_advances); } else if(interiorFlag == P_IN_Q) { printf("After advances: ip=%d, iq=%d ", ip, iq); printf("(p_advances=%d, q_advances=%d) interiorFlag=P_IN_Q\n", p_advances, q_advances); } else if(interiorFlag == Q_IN_P) { printf("After advances: ip=%d, iq=%d ", ip, iq); printf("(p_advances=%d, q_advances=%d) interiorFlag=Q_IN_P\n", p_advances, q_advances); } else printf("BAD INTERIOR FLAG. Shouldn't get here\n"); printf("-----\n\n"); fflush(stdout); } } RemoveDups(); return; }
int main() { signal(SIGINT, &prohandler); signal(SIGTERM, &prohandler); /** Allocation of the arguments' array */ char** argumentArray = (char**) malloc(sizeof(char*) * NUM_OF_ARGS); int i=0; for(i=0;i<NUM_OF_ARGS;i++) { argumentArray[i] = (char*) malloc(sizeof(char) * MAX_ARG_SIZE); } /** Allocation of the input command array */ char* command = malloc(MAX_COMMAND_SIZE); if (command == NULL) { printf("No memory \n"); return 1; } /** Allocation of the home path array */ char* home = malloc(1024); if (home == NULL) { printf("No memory \n"); return 1; } /** End of allocations */ /****************************************** MAIN LOOP ********************************************************************/ /**************************************************************************************************************************/ //Like a normal shell - user@hostname struct passwd *p = getpwuid(getuid()); // Check for NULL! char hostname[HOST_NAME_MAX+1]; while(1) { /** * Shell waiting for input. If you just press enter, or enter something starting with a whitespace, the shell will ask for * new entry. If Ctrl-C is pressed while in the loop, the loop breaks. */ do { //printf("User name: %s\n", p->pw_name); gethostname(hostname, sizeof(hostname)); // Check the return value! //printf("Host name: %s\n", hostname); //fprintf(stdout, KRED "SuperHackingShell:" RESET); fprintf(stdout, KCYN "%s" RESET "@" KGRN "%s:" RESET,p->pw_name,hostname); printDir(); fprintf(stdout, KNRM "$ " RESET); fgets(command, MAX_COMMAND_SIZE, stdin); }while(strFilter(command)==0 ); /** Check for exit command */ if (stringCompare(command,"exit")) break; /** Parsing */ int args = cmdParser(command, argumentArray, NUM_OF_ARGS); //args contains the number of arguments the command contained. /** Executing programs and commands - if no cd command given */ if(cd(argumentArray) != 0) { /** Check for background execution */ if( *argumentArray[args-1] == 38) //if last argument of command is "&"(38), execute in background { *argumentArray[args-1] = 0; //doesn't appear to create problems NOPE: me ls -l & peos //prepei na kopsw to teleutaio argument //printf("%s %s",argumentArray[0],argumentArray[1]);//tsekarei an to ekopse cmdExecBack(argumentArray); } /** Normal execution */ else cmdExecute(argumentArray); } } fprintf(stdout, KRED"<1337>...SuperHackingShell...exiting... <1337> \n" RESET); free(command); free(argumentArray); exit(0); }
void _pf_prin(FILE *f, _pf_Stack *stack, boolean formal) /* Print out single variable where type is determined at run time. */ { struct _pf_type *type = _pf_type_table[stack->Var.typeId]; struct _pf_base *base = type->base; union _pf_varless val = stack->Var.val; struct hash *idHash = NULL; switch (base->singleType) { case pf_stBit: fprintf(f, "%d", val.Bit); break; case pf_stByte: fprintf(f, "%d", val.Byte); break; case pf_stChar: fprintf(f, "%c", val.Char); break; case pf_stShort: fprintf(f, "%d", val.Short); break; case pf_stInt: fprintf(f, "%d", val.Int); break; case pf_stLong: fprintf(f, "%lld", val.Long); break; case pf_stFloat: if (formal) fprintf(f, "%f", val.Float); else fprintf(f, "%0.2f", val.Float); break; case pf_stDouble: if (formal) fprintf(f, "%f", val.Double); else fprintf(f, "%0.2f", val.Double); break; case pf_stString: if (formal || val.String == NULL) printString(f, val.String); else fprintf(f, "%s", val.String->s); break; case pf_stClass: idHash = newHash(18); printClass(f, val.Obj, base, idHash); break; case pf_stArray: idHash = newHash(18); printArray(f, val.Array, base, idHash); break; case pf_stDir: idHash = newHash(18); printDir(f, val.Dir, base, idHash); break; case pf_stToPt: fprintf(f, "<toPt %p>\n", val.FunctionPt); break; case pf_stFlowPt: fprintf(f, "<flowPt %p>\n", val.FunctionPt); break; default: fprintf(f, "<type %d>\n", base->singleType); internalErr(); break; } if (base->needsCleanup) { if (val.Obj != NULL && val.Obj->_pf_cleanup != NULL && --val.Obj->_pf_refCount <= 0) val.Obj->_pf_cleanup(val.Obj, stack->Var.typeId); } freeHash(&idHash); }
void _pf_printField(FILE *f, void *data, struct _pf_base *base, struct hash *idHash) /* Print out a data from a single field of given type. */ { switch (base->singleType) { case pf_stBit: { _pf_Bit *p = data; fprintf(f, "%d", *p); break; } case pf_stChar: { _pf_Char *p = data; _pf_Char b = *p; fprintf(f, "%c", b); break; } case pf_stByte: { _pf_Byte *p = data; _pf_Byte b = *p; fprintf(f, "%d", b); break; } case pf_stShort: { _pf_Short *p = data; fprintf(f, "%d", *p); break; } case pf_stInt: { _pf_Int *p = data; fprintf(f, "%d", *p); break; } case pf_stLong: { _pf_Long *p = data; fprintf(f, "%lld", *p); break; } case pf_stFloat: { _pf_Float *p = data; fprintf(f, "%f", *p); break; } case pf_stDouble: { _pf_Double *p = data; fprintf(f, "%f", *p); break; } case pf_stString: { _pf_String *p = data; printString(f, *p); break; } case pf_stClass: { struct _pf_object **p = data; printClass(f, *p, base, idHash); break; } case pf_stArray: { struct _pf_array **p = data; printArray(f, *p, base, idHash); break; } case pf_stDir: { struct _pf_dir **p = data; printDir(f, *p, base, idHash); break; } case pf_stToPt: { _pf_FunctionPt **p = data; fprintf(f, "<toPt %p>", *p); break; } case pf_stFlowPt: { _pf_FunctionPt **p = data; fprintf(f, "<flowPt %p>", *p); break; } case pf_stVar: { struct _pf_var *var = data; struct _pf_type *type = _pf_type_table[var->typeId]; _pf_printField(f, &var->val, type->base, idHash); break; } default: internalErr(); break; } }
void Finger::printDir(void) { printDir(0); }
const Status Index::insertEntry(const void *value, RID rid) { Bucket* bucket; Status status; Bucket *newBucket; int newPageNo; char data[PAGESIZE*2]; int counter; int index; // If the 'unique' flag is set, scan the index to see if the // <attribute, rid> pair already exists if (headerPage->unique == UNIQUE) { RID outRid; if((status = startScan(value)) != OK) return status; while ((status = scanNext(outRid)) != NOMORERECS) { if (status != OK) return status; if (!memcmp(&outRid, &rid, sizeof(RID))) return NONUNIQUEENTRY; } if((status = endScan()) != OK) return status; } // Get the bucket containing the entry into buffer pool status = hashIndex(value, index); int pageNo = headerPage->dir[index]; #ifdef DEBUGIND cout << "Inserting entry " << *(int*)value << " to bucket " << pageNo << endl; #endif status = bufMgr->readPage(file, pageNo, (Page*&)bucket); if (status != OK) return status; // the bucket needs to be splitted if the number of entries // on the bucket equals the maximum if (bucket->slotCnt == numSlots) { // splitting bucket // allocate a new bucket status = bufMgr->allocPage(file, newPageNo, (Page*&)newBucket); if (status != OK) return status; // Initialize this newly allocated bucket newBucket->depth = ++(bucket->depth); newBucket->slotCnt = 0; // Copy all (value, rid) pairs in the old bucket and the new // entry to a temporary area memcpy(data, bucket->data, numSlots*recSize); memcpy(&(data[numSlots*recSize]), value, headerPage->length); memcpy(&(data[numSlots*recSize + headerPage->length]), &rid, sizeof(RID)); counter = bucket->slotCnt + 1; bucket->slotCnt = 0; // the directory needs to be doubled if the depth of the bucket // being splitted equals the depth of the directory if (bucket->depth > headerPage->depth) { // doubling directory // The directory is doubled and the lower half of the directory // is copied to the upper half int newDirSize = 2 * dirSize; if (newDirSize > DIRSIZE) return DIROVERFLOW; for (int i = 0; i < dirSize; i++) headerPage->dir[i + dirSize] = headerPage->dir[i]; dirSize = newDirSize; (headerPage->depth)++; headerPage->dir[index + (1 << (bucket->depth - 1))] = newPageNo; } else { // reset the appropriate directories to the new bucket int oldindex = index % (1 << (bucket->depth - 1)); int newindex = oldindex + (1 << (bucket->depth - 1)); for (int j = 0; j < dirSize; j++) if ((j % (1 << (bucket->depth))) == newindex) headerPage->dir[j] = newPageNo; } #ifdef DEBUGIND printDir(); #endif // call insertEntry recursively to insert all (value, rid) // pairs in the temporary area to the index for (int k = 0; k < counter; k++) { value = &(data[k * recSize]); rid = * ((RID *)((char *)value + headerPage->length)); status = insertEntry(value, rid); if (status != OK) return status; } status = bufMgr->unPinPage(file, newPageNo, true); if (status != OK) return status; } else { // There is sufficient free space in the bucket. Insert (value, rid) here int offset = (bucket->slotCnt) * recSize; memcpy(&(bucket->data[offset]), value, headerPage->length); memcpy(&(bucket->data[offset+headerPage->length]), &rid, sizeof(RID)); (bucket->slotCnt)++; } status = bufMgr->unPinPage(file, pageNo, true); return status; }
void TestCFSM::printModel() { printDir(_model.rootPath(), 0); }