void Boot::Wait::wait() { ulen cnt=0; bool aloud=true; for(;;) switch( msem.take(3_sec) ) { case SignalTimeout : { if( aloud ) { if( !cnt ) cnt=10; Printf(Con,"waiting#;\n",RepeatChar(cnt--,'.')); } } break; case SignalDone : { Printf(Con,"\ndone\n"); return; } break; case SignalKey : { if( aloud ) { Printf(Con,"silent\n"); aloud=false; } else { Printf(Con,"aloud\n"); aloud=true; } } break; } }
/********************************************************* Display Output function *********************************************************/ void DisplayOutput(My402List *pList) { My402ListElem *elem = NULL; time_t timestamp; int balance = 0; char *description; int i,j,k; /* Print the header information */ fputs("+",stdout); RepeatChar("-",17); fputs("+",stdout); RepeatChar("-",26); fputs("+",stdout); RepeatChar("-",16); fputs("+",stdout); RepeatChar("-",16); fputs("+",stdout); fputs("\n",stdout); fputs("|",stdout); RepeatChar(" ",7); fputs("Date",stdout); RepeatChar(" ",6); fputs("|",stdout); fputs(" Description",stdout); RepeatChar(" ",14); fputs("|",stdout); RepeatChar(" ",9); fputs("Amount ",stdout); fputs("|",stdout); RepeatChar(" ",8); fputs("Balance ",stdout); fputs("|",stdout); fputs("\n",stdout); fputs("+",stdout); RepeatChar("-",17); fputs("+",stdout); RepeatChar("-",26); fputs("+",stdout); RepeatChar("-",16); fputs("+",stdout); RepeatChar("-",16); fputs("+",stdout); fputs("\n",stdout); /* Header Information Printed */ /* Print each element in the list */ for (elem=My402ListFirst(pList); elem != NULL; elem=My402ListNext(pList, elem)) { /* Print time */ timestamp = (time_t)(((trnx*)(elem->obj))->timeval); fputs("| ",stdout); char *ctimestamp = ctime(×tamp); //char *temptime; for(i=0;i<11;i++) { fprintf(stdout,"%c",ctimestamp[i]); } for(i=20;i<24;i++) { fprintf(stdout,"%c",ctimestamp[i]); } //fprintf(stdout,"%s here",ctimestamp); fputs(" | ",stdout); /* Print Description */ description = (((trnx*)(elem->obj))->description); if (strlen(description) > 24) { for (i=0;i<24;i++) { fprintf(stdout,"%c",description[i]); } fputs(" ",stdout); } else { for (i=0;i<(strlen(description)-1);i++) { fprintf(stdout,"%c",description[i]); } for(i=0;i<=(25-strlen(description));i++) { fputs(" ",stdout); } } fputs("| ",stdout); /* Print Amount */ char *amount= malloc(15); char *temp = malloc(16); sprintf(amount,"%d",((trnx*)(elem->obj))->amt); if(strcmp(((trnx*)(elem->obj))->op,"-") == 0) { fputs("(",stdout); } else { fputs(" ",stdout); } if(strlen(amount) == 2 ) { temp[0] = '0'; temp[1] ='.'; temp[2] = amount[0]; temp[3] = amount[1]; k = 4; } else if (strlen(amount) == 1 ) { temp[0] = '0'; temp[1] ='.'; temp[2] = '0'; temp[3] = amount[0]; k = 4; } else { for(i=strlen(amount)-1,j = 0,k=0;i>=0;i--,j++) { if(i == 8 || i == 5) { temp[k]=amount[j]; k++; temp[k]= ','; k++; } else if( i == 2) { temp[k]=amount[j]; k++; temp[k]= '.'; k++; } else { temp[k]=amount[j]; k++; } } } temp[k]= '\0'; for(i=0;i<12-strlen(temp);i++) { fputs(" ",stdout); } fprintf(stdout,"%s",temp); if(strcmp(((trnx*)(elem->obj))->op,"-") == 0) { fputs(")",stdout); } else { fputs(" ",stdout); } fputs(" | ",stdout); free(temp); /* Print Balance */ if(strcmp(((trnx*)(elem->obj))->op,"-") == 0) { balance = balance - ((trnx*)(elem->obj))->amt; } else { balance = balance + ((trnx*)(elem->obj))->amt; } char *bal_amount = malloc(15); temp = malloc(16); sprintf(bal_amount,"%d",abs(balance)); if(balance < 0) { fputs("(",stdout); } else { fputs(" ",stdout); } if(strlen(bal_amount)> 9) { free(bal_amount); bal_amount = malloc(15); strncpy(bal_amount,"?,???,???.??",15); fprintf(stdout,"%s",bal_amount); } else { for(i=strlen(bal_amount)-1,j = 0,k=0;i>=0;i--,j++) { if(i == 8 || i == 5) { temp[k]=bal_amount[j]; k++; temp[k]= ','; k++; } else if( i == 2) { temp[k]=bal_amount[j]; k++; temp[k]= '.'; k++; } else { temp[k]=bal_amount[j]; k++; } } temp[k]= '\0'; for(i=0;i<12-strlen(temp);i++) { fputs(" ",stdout); } } fprintf(stdout,"%s",temp); if(balance < 0) { fputs(")",stdout); } else { fputs(" ",stdout); } fputs(" |",stdout); //fputs("\n",stdout); free(temp); free(bal_amount); free(amount); fputs("\n",stdout); } fputs("+",stdout); RepeatChar("-",17); fputs("+",stdout); RepeatChar("-",26); fputs("+",stdout); RepeatChar("-",16); fputs("+",stdout); RepeatChar("-",16); fputs("+",stdout); fputs("\n",stdout); }