handleInterrupt21(int ax, int bx, int cx, int dx) { //printString("Hello World!\0"); //char *dgb = "AX = x\n"; //dgb[5] = '0' + ax; //printString(dgb); switch(ax) { case 0: printString(bx); break; case 1: readString(bx); break; case 2: readSector(bx, cx); break; case 3: readFile(bx, cx); break; case 4: executeProgram(bx, cx); break; case 5: terminate(); break; case 6: writeSector(bx, cx); break; case 7: deleteFile(bx); break; case 8: writeFile(bx, cx, dx); break; default: printString("Error!"); } }
// ~~~~~~~~~~~~~~~~~~ function to handle interrupt ~~~~~~~~~~~~~~~~~~~~~ void handleInterrupt21(int ax, int bx, int cx, int dx) { if (ax == 0) { printString(bx); } else if (ax == 1) { readString(bx); } else if (ax == 2) { readSector(bx, cx); } else if (ax == 3) { readFile(bx, cx); } else if (ax = 4) { executeProgram(bx, cx); } else if (ax = 5) { terminate(); } else { printString("Interrupt21 error \r\n\0"); } }
int main(int argc, char** argv) { m::system::Log::registerDefaultLogImpl(); m::system::Log log("", m::LOG_INFO); log() << " Haize v" << HAIZE_VERSION << ", a C++ Script Language " << m::endl; log() << " Copyright (C) 2015-2016 Louis Schnellbach" << m::endl << m::endl; if (parseArguments(argc, argv)) { executeProgram(); } else { displayUsage(); } leave(0); }
main(){ while (1) { // interrupt(0x21,0x00,"\n",0,0); // interrupt(0x21,0x00,"Shell> ",0,0); // interrupt(0x21,0x01,ch,0,0 ); //printString("\n"); printString("Shell> "); readString(ch); if(ch[0]== 't' && ch[1] == 'y'&& ch[2] == 'p' && ch[3] == 'e'){ int i = 0; filename[0]= ch[5]; filename[1]= ch[6]; filename[2]= ch[7]; filename[3]= ch[8]; filename[4]= ch[9]; filename[5]= ch[10]; interrupt(0x21,0x00,filename,0,0); // interrupt(0x21,0x03,filename,buf,0); // interrupt(0x21,0x00,buf,0,0 ); readfile(filename,buf); printString(buf); } else if(ch[0]== 'e' && ch[1] == 'x'&& ch[2] == 'e' && ch[3] == 'c' && ch[4] == 'u'&& ch[5] == 't' && ch[6] == 'e'){ filename[0]= ch[8]; filename[1]= ch[9]; filename[2]= ch[10]; filename[3]= ch[11]; filename[4]= ch[12]; filename[5]= ch[13]; //interrupt(0x21,0x00,filename,0,0); //interrupt(0x21,0x04,filename,0x2000,0); //interrupt(0x21, 0x04, "uprog1\0", 0x2000, 0); executeProgram(filename,0x2000); } else{ interrupt(0x21,0,"Unrecognized command \n ",0,0); } } }
handleInterrupt21(int ax, int bx, int cx, int dx){ if(ax==0) printString(bx); if(ax==1) readString(bx); if(ax==2) readSector(bx,cx); if(ax==3) readfile(bx,cx); if(ax==4) executeProgram(bx,cx); if(ax==5) terminate(); if(ax==6) writeSector(bx,cx); if(ax==7) deleteFile(bx); if(ax==8) writeFile(bx,cx,dx); if(ax>=9) printString("Error"); }
void handleInterrupt21(int ax, int bx, int cx, int dx) { if(ax == 0) printString(bx); else if(ax == 1) readString(bx); else if(ax == 2) readSector(bx, cx); else if(ax == 3) readFile(bx,cx); else if(ax == 4) executeProgram(bx, cx); else if(ax == 5) terminateProgram(); else if (ax == 6) writeSector(bx,cx); else if (ax == 7) deleteFile(bx); else if(ax == 8) writeFile(bx,cx,dx); else printString("error\0"); }
int main() { //Obtaining the path of main.c *getcwd(directoryPath,300); strcpy(rootPath,directoryPath); //Setting the initial directories rootDirectory = opendir(directoryPath); currentDirectory = rootDirectory; int c = 1; char d ='\0'; char l[250]; Word Words[30]; printf("[TuriShell]"); while(c!=0) { int i=0; int j=0; while((l[0]=getchar())!='\n') { if(l[0]!=' ') { Words[j].c[i]=l[0]; i++; } else { j++; i=0; } } /*if(l[0]=='\377') { printf("LOOOL"); }*/ if(compareArray(&Words[0].c,&"cd",2)==1) { if(Words[1].c[0]=='\000') { currentDirectory = rootDirectory; strcpy(directoryPath,rootPath); puts(directoryPath); } else { cdFunction(&Words[1].c); } } if(compareArray(&Words[0].c,&"ls",2)==1) { lsFunction(); } if(compareArray(&Words[0].c,&"clear",5)==1) { system("clear"); } if(compareArray(&Words[0].c,&"exit",4)==1) { return 0; } if(Words[0].c[0]=='.'&&Words[0].c[1]=='/') { executeProgram(&Words[0].c[1]); } if(l[0]=='\n') { printf("[TuriShell]"); } else { printf("Comando no reconocido"); printf("[TuriShell]"); } //reset the commands array int b =0; for(;b<30;b++) { int p=0; for(;p<250;p++) { Words[b].c[p]='\000'; } } } return 0; }
int process(char *argu){ char *trail; trail = argu; int trailingOp = -1; //0 for bg, 1 for routing, -1 for neither while (trail != NULL){ if (strcmp(trail, "&") == 0){ //anything after the & is summarily ignored //run in background trailingOp = 0; break; } if (strcmp(trail, ">") == 0){ trailingOp = 1; //routing break; } args[argSize] = trail; //printf("Trail = %s. Arg = %s.\n", trail, args[argSize]); argSize++; trail = strtok(NULL, " \n\t\r"); } args[argSize] = '\0'; //sets end of argument array to \0 because execvp likes that argSize++; if (trailingOp == 0){ //implementation to run jobs in the backgrounds if (executeProgram(argu, 0) == 0){ return 0; } } else if (trailingOp == 1){ //implementation to redirect job output trail = strtok(NULL, " \n\t\r"); char outPath[512]; memset(outPath, '\0', 512); strcpy(outPath, trail); //outpath now holds the name/path of the output file that the user has specified int i; for (i = 0; i < 512; i++){ if ((outPath[i] == ' ') || (outPath[i] == '>')){ fprintf(stderr, "Error: Invalid file name.\n"); return -1; } } if (redir(outPath, argu) == 0){ return 0; } else return -1; } //checks the first word in the user input //exit if (strcmp(argu, "exit") == 0){ exit(0); } //returns current pid, good for testing if (strcmp(argu, "pid") == 0){ int pid = getpid(); printf("PID: %d\n", pid); return 0; } //wait if (strcmp(argu, "wait") == 0){ //wont return until all background jobs are completed wait(); return(0); } if (strcmp(argu, "pwd") == 0){ char buffer[255]; //all ex file systems have a maximum file name size of 255 bytes getcwd(buffer, 256); printf("%s\n", buffer); return(0); } if (strcmp(argu, "cd") == 0){ char *argu; char path[512]; if (args[1] == NULL){ strcpy(path, getenv("HOME")); } else { strcpy(path, args[1]); } chdir(path); return 0; } if (python(argu) == 0){ char *pyArg[512]; char path[128]; strcpy(path, "python"); pyArg[0] = argu; int i; for(i = 1; i < argSize + 1; i++){ pyArg[i] = args[i - 1]; } int childID = fork(); if (childID == 0){ execvp(path, pyArg); } return 0; } if (executeProgram(argu, 1) == 0) return 0; else return -1; }
int main(int argc, char *argv[]) { struct USBConnection *connection; int opt; int repeatCount = 0; char *script = NULL; int delay = 10; int daemon = 0; while ((opt = getopt(argc, argv, "s:d:c:Dv")) != -1) { switch (opt) { case 's': script = optarg; break; case 'd': delay = atoi(optarg); break; case 'c': repeatCount = atoi(optarg); break; case 'D': daemon = 1; break; case 'v': enable_debug(); break; default: printUsage(argv[0]); return -1; } } if (optind >= argc) { fprintf(stderr, "Missing USB device parameter.\n"); printUsage(argv[0]); return -1; } if (daemon && script == NULL) { fprintf(stderr, "Missing script parameter. Running the program as a daemon implies -s.\n"); return -1; } if (daemon) { initlog(1); daemonize(); } else { initlog(0); } log_output(LOG_DEBUG, "Opening USB device\n"); connection = initUSBConnection(argv[optind]); if (connection != NULL) { int i; int increment = 1; log_output(LOG_INFO, "Connection initialization successful. UVR mode 0x%X\n", (unsigned int)connection->uvr_mode); if (repeatCount == 0) { increment = 0; repeatCount = 1; // prepare the values in a way that the loop below runs infinitely } for (i = 0; i < repeatCount; i+=increment) { struct SystemState *result; result = readCurrentData(connection); if (result != NULL) { if (script != NULL) { executeProgram(script, result); } else { printf("Inputs\n"); printValueList("S", result->inputs); printf("Outputs\n"); printValueList("O", result->outputs); printf("Heat registers\n"); printValueList("", result->heatRegisters); } freeSystemState(result); result = NULL; } sleep(delay); } } else { fprintf(stderr, "Could not initialize connection to UVR. %s\n", strerror(errno)); cleanupUSBConnection(connection); return -1; } cleanupUSBConnection(connection); return 0; }