int main(int ac, char *av[] ) { int num; char *unit; int rtn = 0; cmdName=av[0]; if (ac < 2 ) { usage(); goto err; } cell = av[1]; ac--; av++; if ( ac > 1 && strcmp(av[1],"--full") == 0 ) { isHole = 0; ac--; av++; } if ( ac < 3 ) { usage(); goto err; } name = av[1]; num = strtoul(av[2],&unit,0); if ( num <= 0 || num > 1024) { fprintf(stderr,"factor(%d) is invalid.\n",num); goto err; } if ( ( *unit != 'K' && *unit != 'M' && *unit != 'G' && *unit != 'T' ) || *(unit + 1 ) != '\0' ) { fprintf(stderr,"unit(%s) is invalid.\n",unit); goto err; } size = num; switch (*unit) { default: /////// not reached abort(); break; case 'T': size *= 1024; case 'G': size *= 1024; case 'M': size *= 1024; case 'K': size *= 1024; break; } rtn = clearFile(); out: return rtn; err: rtn = -1; goto out; }
void DataFileExporter::enableExporterDuringLog() { _dataExportBuffer.clear(); lastLogTime = QDateTime::currentMSecsSinceEpoch(); // Clean file clearFile(_pSettingsModel->writeDuringLogFile()); exportDataHeader(); }
void printToFile(FILE * pfile,char* string) { if(firstTime) { clearFile(pfile); firstTime=0; } pfile = fopen(filename,"a+"); fprintf(pfile,"%s",string); fclose(pfile); }
// 初始化所有表格和文件 void AppDockWidget::clearAll() { clearFile(QString("sigtogui.txt")); clearFile(QString("info_registers.txt")); clearFile(QString("info_backtrace.txt")); clearFile(QString("info_threads.txt")); clearFile(QString("info_threadcurrentline.txt")); clearFile(QString("info_threadcore.txt")); clearFile(QString("info_core.txt")); clearFile(QString("info_time.txt")); clearFile(QString("info_coreutilization.txt")); ui.breakpointTableWidget->clearContents(); ui.variableTableWidget->clearContents(); ui.registerTableWidget->clearContents(); ui.backTraceTableWidget->clearContents(); ui.threadcoreTableWidget->clearContents(); ui.coreTableWidget->clearContents(); ui.coreUtilizationTableWidget->clearContents(); ui.timeTableWidget->clearContents(); ui.infothreadtableWidget->clearContents(); }
void startCountingFileTokens(const char* filename) { static bool firstCall = true; if (firstCall) { firstCall = false; initTokenCount(); } tokenCountingOn = true; if (countTokens) { clearFile(); clearLine(); if (printTokens) { fprintf(stderr, "%s\n", filename); printSeparator(); } } }
void DataFileExporter::exportDataFile(QString dataFile) { if (_pGraphDataModel->activeCount() != 0) { const QList<double> keyList = _pGraphView->graphTimeData(); QList<QCPDataMap *> dataList; QStringList logData; // Create header logData.append(constructDataHeader(false)); // Create label row logData.append(createLabelRow()); QList<quint16> activeGraphIndexes; _pGraphDataModel->activeGraphIndexList(&activeGraphIndexes); for(qint32 idx = 0; idx < activeGraphIndexes.size(); idx++) { // Save data lists dataList.append(_pGraphDataModel->dataMap(activeGraphIndexes[idx])); } // Add data lines for(qint32 i = 0; i < keyList.size(); i++) { QList<double> dataRowValues; for(qint32 d = 0; d < dataList.size(); d++) { dataRowValues.append(dataList[d]->value(keyList[i]).value); } logData.append(formatData(keyList[i], dataRowValues)); } // Clean file clearFile(dataFile); // Export data writeToFile(dataFile, logData); } }
int writeToFile(Job* jobInfo){ /** @type function Writes to output file information about job's metricas (time of pushing into queue, scheduling, starting of execution, anomalies, etc.) Parameters: --------------------------- @jobInfo job object which fields contains time metrics. */ MSG_sem_acquire(sem_link); static size_t n = 0; if (n == 0) clearFile(); const char* typesStr[] = {"USER", "DATASTRIPPING", "MERGE", "MCStripping", "DATARECONSTRUCTION", "TURBO", "MCRECONSTRUCTION", "WGPRODUCTION", "MCMERGE", "UNKNOWN", "MCSIMULATION", "TEST", NULL}; fprintf(FP, "%lu,%d,", jobInfo->JobId, jobInfo->successExecuted); //typesStr[jobInfo->type] fprintf(FP, "%.0f,%f,%f,%f,", jobInfo->SubmissionTime, jobInfo->startSchedulClock, jobInfo->StartExecTime, jobInfo->EndExecTime); fprintf(FP, "%s,%s\n", jobInfo->Federation.c_str(), jobInfo->JobType.c_str()); n++; MSG_sem_release(sem_link); return(0); }
int extractFileFromArchive(char * fileName, int arkiv, off_t nbytes){ #ifdef DEBUG printf("extractFileFromArchive(%s)\n", fileName); #endif // Set up required paths for fileName if(setupPath(fileName) != 0){ return -1; } if(isDir(fileName) == 1){ // setupPath already took care of it for us #ifdef DEBUG printf(" %s is already a directory\n", fileName); #endif return 0; } // Check if file is read-only if(clearFile(fileName) == 0){ snprintf(errDesc, ERR_STATUS_LENGTH, "removing read-only %s", fileName); return -1; } // File descriptor for file to extract int outputFile; if ((outputFile= open(fileName, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1){ snprintf(errDesc, ERR_STATUS_LENGTH, "opening initial %s", fileName); return -1; } // Write to file if(copyBytes(fileName, arkiv, outputFile, nbytes) == -1){ return -1; } return 0; }
int main(int argc, char const* argv[]) { struct timeval timeout; /*struct*/ fd_set master_set, working_set; // no struct cause of deb? int rc, on = 1; int max_sd; int file_not_received = 1; int charsWritten = 0; //const char *message = "Hello World"; struct filePkg recvChunk = {}; // initialize to zero /*char recvMessage[256];*/ //struct netCommand recvCommand; // clear file to remove old garbage clearFile("out.txt"); // Init struckt for Metadata struct fileStatus fileStatus; fileStatus.protocolVersion = -1; fileStatus.size = -1; // Declare Communication Information int sfd; struct sockaddr_in6 address; // IPv6 address.sin6_family = AF_INET6; address.sin6_addr = in6addr_any; address.sin6_port = htons(PORT); //int addrlen = sizeof(address); struct netCommand command; command.protocolVersion = 1; command.command = READ; command.offset = 2; command.length = 12; strncpy(command.fname, "foo.txt", MAXFNLEN); do { sfd = socket(PF_INET6, SOCK_STREAM, 0); if (sfd == -1) { perror("Unable to open socket"); exit(1); } // Make socket reuseable rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)); if (rc < 0) { perror("setsockopt() failed"); close(sfd); exit(1); } // Make socket non-blocking //rc = ioctl(sfd, FIONBIO, (char *) &on); //if (rc < 0) { // perror("ioctl() failed"); // close(sfd); // exit(1); //} rc = connect(sfd, (struct sockaddr *) &address, sizeof(address)); if (rc < 0) { perror("connect() failed"); close(sfd); exit(1); } // Add socket to listen filedescriptor set FD_ZERO(&master_set); max_sd = sfd; FD_SET(sfd, &master_set); /* Sending Back what's going on */ //sendto(sfd, message, strlen(message) + 1, 0, //(struct sockaddr *) &address, (socklen_t) addrlen); // init timeval struct, cause linux updates it timeout.tv_sec = 10; // 3 Mins timeout.tv_usec = 0; // is this val even necessary? // save master fd_set to working fd_set memcpy(&working_set, &master_set, sizeof(master_set)); if (fileStatus.size == -1) { command.protocolVersion = 1; command.command = STATUS; command.offset = 0; command.length = 0; strncpy(command.fname, "foo.txt", MAXFNLEN); } else { command.protocolVersion = 1; command.command = READ; command.offset = charsWritten; command.length = 99; strncpy(command.fname, "foo.txt", MAXFNLEN); } // sending the request //sendto(sfd, // &command, // sizeof(command), // 0, // (struct sockaddr *) &address, // (socklen_t) addrlen // ); write(sfd, &command, sizeof(command)); // use select to wait for response //printf("%s\n", "Waiting for select()"); rc = select( max_sd + 1, // highest numbered FD + 1 &working_set, // Set of read FDs NULL, // Set of write FDs NULL, // Set of exception FDs &timeout // Minimum wait interval ); //recvfrom(sfd, &recvCommand, sizeof(recvCommand), 0, //(struct sockaddr *) &address, (socklen_t *) &addrlen); if (rc < 0) { perror("select() has failed!"); break; } if (rc == 0) { perror("select() has reached the timeout"); continue; } // select must have a FD ready, since we're only watching sfd // we consider it the ready FD if (FD_ISSET(sfd, &working_set)) { if (command.command == STATUS) { //recvfrom(sfd, // &fileStatus, // sizeof(fileStatus), // 0, // (struct sockaddr *) &address, // (socklen_t *) &addrlen // ); read(sfd, &fileStatus, sizeof(fileStatus)); printf("size is %d\n", fileStatus.size); } else if(command.command == READ) { //recvfrom(sfd, // &recvChunk, // sizeof(recvChunk), // 0, // (struct sockaddr *) &address, // (socklen_t *) &addrlen // ); read(sfd, &recvChunk, sizeof(recvChunk)); printf("Got Msg: %s\n", recvChunk.text); printf("Of size: %d\n", recvChunk.strLength); printf("filepos: %d\n", recvChunk.filePos); printf("goteof : %d\n", recvChunk.gotEOF); charsWritten = recvChunk.filePos + recvChunk.strLength; appendToFile("out.txt", recvChunk.filePos, recvChunk.text, recvChunk.strLength ); } } close(sfd); file_not_received++; sleep(1); } while (!recvChunk.gotEOF || charsWritten < fileStatus.size); //printf("%s\n", receivemsg); return 0; }
/** * Program pooling a directory, and doing a scheduling. **/ int main (int argc, char** argv) { initPins(); adc_init(); lcd_init(); /** The status does not exist at the launch of the schduler prgram*/ clearFile(); int pid=readPid(); stopIfPidExists(pid); writePid(); SetChrMode(); int nbSecond; int remainingSeconds; uchar intensity; uchar tmpintensity; int i; int valueInFile; time_t whenItsComplete ; char timestr[7]; pinMode (RELAY_IN, OUTPUT); // Permanent loop checking file. int cycle=0; while(1){ valueInFile=getCoundownValue(); #ifndef PROD printf("pause:%d,valueInFile:%d\n",pauseSt,valueInFile); #endif if(valueInFile>=0){ nbSecond=valueInFile; // The countdown whenItsComplete = time(NULL)+nbSecond; remainingSeconds=whenItsComplete-time(NULL); } else{remainingSeconds=-1;} #ifndef PROD printf("nbsecond:%d\n",nbSecond); #endif do { /** * Do a regular reset of the LCD **/ if(cycle%500==0){ lcd_init(); } else if(cycle%60==0){ resetLcd(); } /** * Write the remaining seconds **/ if(cycle%60==0){ writeRemaining(remainingSeconds); } /** * Increment only if not in pause (Cycle increments will be at the end of the cycle loop. **/ updateStandbyStatus(); cycle++; if(remainingSeconds>-1){ if(pauseSt==IS_RUNNING){ remainingSeconds=whenItsComplete-time(NULL); }else{ whenItsComplete=remainingSeconds+time(NULL); } openRelay(); if(lastImmobileState==0||(time(NULL)-lastImmobileState)<NBSECONDBEFORECREENSHUTDOWN){ digitalWrite (TRANSISTOR, LOW); } else{ digitalWrite (TRANSISTOR, HIGH); } int seconds=remainingSeconds%60; int hours=remainingSeconds/3600; int minutes=remainingSeconds/60%60; sprintf(timestr,"%02d:%02d:%02d",hours,minutes,seconds); goHome(); lcd_text(timestr); #ifndef PROD printf("%s\n",timestr); #endif sleep(1); } /** * Block measuring intensity */ if(cycle%20==0){ intensity=get_ADC_Result(); #ifndef PROD printf("Intensite: %d\n",intensity); #endif } #ifndef PROD printf("Remaining seconds %d,cycle=%d\n",remainingSeconds,cycle); #endif } while ( remainingSeconds>0&& !isFilePresent()); #ifndef PROD // printf("Sortie boucle décompte\n"); #endif /** * Every 10 ccyle there is a full reset of the screen. Otherwise it is light reset. **/ if(cycle%100==0){ lcd_init(); } nbSecond=0; /** * **/ if(valueInFile==NO_FILE){ goHome(); closeRelay(); digitalWrite (TRANSISTOR, HIGH); lcd_text("Expire " ); #ifndef PROD printf("Expire\n"); #endif } else if(valueInFile==TV_ON){ goHome(); openRelay(); digitalWrite (TRANSISTOR, LOW); lcd_text("Tele on " ); } else if(valueInFile==TV_OFF){ goHome(); digitalWrite (TRANSISTOR, HIGH); closeRelay(); lcd_text("Tele off " ); } sleep(3); } }
int main() { char command[1024]; printf("------------------\n<<< Commands >>>\nclf\ncontf\ncof\ncrf\ndef\nmof\nrname\ntappend\ntinsert\nexit()\n"); printf("\n* Be careful, the program is case sensitive.\n** To get information about how command works, add \\h next to the command (command\\h). \nFor example: clf\\h\n------------------\n\nEnter a command:\n"); scanf("%s", command); while(strcmp("exit()",command)!=0) { if (strcmp("clf",command)==0) { clearFile(); } else if (strcmp("contf",command)==0) { contentFile(); } else if (strcmp("cof",command)==0) { copyFile(); } else if (strcmp("crf",command)==0) { createFile(); } else if (strcmp("def",command)==0) { deleteFile(); } else if (strcmp("mof",command)==0) { moveFile(); } else if (strcmp("rname",command)==0) { rnameFile(); } else if (strcmp("tappend",command)==0) { tappendFile(); } else if (strcmp("tinsert",command)==0) { tinsertFile(); } else if(strcmp(command,"clf\\h")==0){ printf("\n> This function removes all text in a file.\nWhen function asks, You should just enter the file path. \n\n"); } else if(strcmp(command,"contf\\h")==0){ printf("\n> This function shows the content of a text file, with the ability to pause per page. The number of lines per page can be specified by the user.\nWhen function asks, You should enter the file path and enter a number to specify number of lines per page.\n\n"); } else if(strcmp(command,"cof\\h")==0){ printf("\n> This function copies the given file to specific path.\nWhen function asks, You should enter the file path and a path you want to copy file in.\n\n"); } else if(strcmp(command,"crf\\h")==0){ printf("\n> This function creates a file in given path.\nWhen function asks, You should just enter the file path and it will create the file if there is no\nfile with same filename.\n\n"); } else if(strcmp(command,"def\\h")==0){ printf("\n> This function deletes the given file.\nWhen function asks, You should just enter the file path and it will delete the file if file exists.\n\n"); } else if(strcmp(command,"mof\\h")==0){ printf("\n> This function moves the given file to specific pat.\nWhen function asks, You should enter the file path and a path you want to move file in.\n\n"); } else if(strcmp(command,"rname\\h")==0){ printf("\n> This function change name of the given file.\nWhen function asks, You should just enter the file path and it will change the file name if there is no file with same filename.\n\n"); } else if(strcmp(command,"tappend\\h")==0){ printf("\n> This function appends given text to the end of the given file.\nWhen function asks, You should enter a text and file path.\n\n"); } else if(strcmp(command,"tinsert\\h")==0){ printf("\n> This function inserts given text in a specific position (counted in characters) of the file.\nWhen function asks, You should enter file path, text and the position you want to insert text in.\n\n"); } else{ printf("\n!!! Command is not valid. Please enter a from the menu. !!!\n\n"); } scanf("%s", command); } }