/* * This function tries to access the printer, and upon (eventually) * doing so, it starts printing - that process takes somewhere between * 0 and 9 seconds. * It then releases the printer for the next thread (client) to use. */ SGint SG_EXPORT client(void* data) { unsigned int* i = data; srand(*i); mprintf("%*u [%p]: Waiting for printer...\n", numdigits(NUMTHREADS, 10), *i, sgThreadGetCurrent()); sgSemaphoreWait(sem); mprintf("%*u [%p]: Printing...\n", numdigits(NUMTHREADS, 10), *i, sgThreadGetCurrent()); sgMSleep(1000 * (rand() % 10)); mprintf("%*u [%p]: Done printing\n", numdigits(NUMTHREADS, 10), *i, sgThreadGetCurrent()); sgSemaphorePost(sem); return 0; }
getelements() /* Calculates and prints each element as a word in the generators (the 'list' command ) */ { register int i; char *s=(char *) malloc(MAXELTLEN); if (!valid_table) {printf("\nNo enumeration has been done!\n");return;} sprintf(s,"[%%%dd] %%s\n",numdigits(last)); for (i=1;i<=last;i++) { if (i%lpp==0) WAITKEYB; printf(s,i,trans_word(i)); } }
void num_print (double r, int w, char *unit) { char *pfx = 0, i; if (w == 0) { w = 4; if (r > 1.099511627776e12 ) { r *= 1e-12; pfx = "T"; } else if (r > 1.073741824e9) { r *= 1e-9; pfx = "G"; } else if (r > 1.048576e6) { r *= 1e-6; pfx = "M"; } else if (r > 1.024e3) { r *= 1e-3; pfx = "k"; } else pfx = spc; } for (i=w-numdigits(r); i >0; i--) fputs(spc, stdout); printf("%.0f", r); if (pfx || unit) fputs(" </fc>", stdout); if (pfx) fputs(pfx, stdout); if (unit) fputs(unit,stdout); if (pfx || unit) fputs("<fc=gray>", stdout); }
char *replace_host_port(const char *request_url, const char *agent_host, int agent_port, void* agent_config) { char *modified_url = NULL; am_web_log_debug("replace_host_port(): Orginal request url => %s", request_url); if ( request_url != NULL && agent_host != NULL ) { char *temp_url = strdup(request_url); if ( temp_url != NULL) { char *holder = NULL; char *proto = strtok_r(temp_url, "/", &holder); char *host_url = strtok_r(NULL, "/", &holder); if ( proto != NULL && host_url != NULL) { char *loc1 = strchr(request_url, '/'); if ( loc1 != NULL) { char *loc2 = strchr(loc1+1, '/'); if ( loc2 != NULL) { char *loc3 = strchr(loc2+1, '/'); if (loc3 != NULL) { int new_len = strlen(proto) + 2 + strlen(agent_host) + 1 + numdigits(agent_port) + strlen(loc3) + 1; modified_url = (char *)malloc(new_len); if ( modified_url != NULL) { sprintf(modified_url, "%s//%s:%d%s", proto, agent_host, agent_port, loc3); am_web_log_debug("replace_host_port() Modified url => %s", modified_url); } } } } } free(temp_url); } } return modified_url; }
char * intToString(int n , HeapHandler hh){ char * s = allocateMemory(hh , numdigits(n)+1); itoa(n , s , 10); return s; }
/*Function for modifying a customer record*/ void account::modify() { char ch; long input_no; int flag=0; fstream fptr1,fptr2; fptr1.open("db.dat",ios::in); if(fptr1.fail()) { cout<<"Cannot open the db.dat file!"; getch(); return; } fptr2.open("dbtemp.dat",ios::out); if(fptr2.fail()) { cout<<"Cannot open the dbtemp.dat file!"; getch(); return; } clrscr(); gotoxy(20,3); cout<<"Enter the phone no whose record is to be modified:"; cin>>input_no; while(fptr1.read((char*)this,sizeof(obj))) { if(input_no==phone_no) { flag=1; gotoxy(20,5); cout<<"Name:"<<name; gotoxy(20,6); cout<<"Address:"<<address; gotoxy(20,7); cout<<"Account no:"<<acc_no; gotoxy(20,10); cout<<"Modify this customer's record(Y/N)"; ch=getch(); ch=toupper(ch); if(ch=='Y') { gotoxy(20,14); cout<<"Enter the customer's modified details.."; while(1) { gotoxy(20,16); cout<<"Name:"; gets(name); if(strlen(name)==0) { gotoxy(30,24); clreol(); cout<<"Name cannot be left blank!"; } else { gotoxy(30,24); clreol(); break; } } while(1) { gotoxy(20,18); cout<<"Address:"; gets(address); if(strlen(address)==0) { gotoxy(30,24); clreol(); cout<<"Address cannot be left blank!"; } else { gotoxy(30,24); clreol(); break; } } while(1) { gotoxy(20,20); cout<<"Phone no.:"; cin>>phone_no; if((numdigits(phone_no))!=7) { gotoxy(44,20); clreol(); gotoxy(30,24); clreol(); cout<<"Phone no. should be of seven digits!"; } else { gotoxy(30,24); clreol(); break; } } while(1) { gotoxy(20,22); cout<<"Account no.:"; cin>>acc_no; if((numdigits(acc_no))!=5) { gotoxy(44,22); clreol(); gotoxy(30,24); clreol(); cout<<"Account no. should be of five digits!"; } else { gotoxy(30,24); clreol(); break; } } } }
/*Function adding a customer*/ void account::add() { char ch1; fstream fptr; fptr.open("db.dat",ios::app); if(fptr.fail()) { cout<<"Cannot open file db.bat file!"; getch(); return; } clrscr(); gotoxy(30,5); cout<<"Enter new customer's details.."; while(1) { gotoxy(30,8); cout<<"Name:"; gets(name); if(strlen(name)==0) { gotoxy(30,24); clreol(); cout<<"Name cannot be left blank!"; } else { gotoxy(30,30); clreol(); break; } } while(1) { gotoxy(30,10); cout<<"Address:"; gets(address); if(strlen(address)==0) { gotoxy(30,24); clreol(); cout<<"Address cannot be left blank!"; } else { gotoxy(30,24); clreol(); break; } } while(1) { gotoxy(30,12); cout<<"Phone no.:"; cin>>phone_no; if((numdigits(phone_no))!=7) { gotoxy(54,12); clreol(); gotoxy(30,24); clreol(); cout<<"Phone no. should be of seven digits!"; } else { gotoxy(30,24); clreol(); break; } } while(1) { gotoxy(30,14); cout<<"Account no.:"; cin>>acc_no; if((numdigits(acc_no))!=5) { gotoxy(54,14); clreol(); gotoxy(30,24); clreol(); cout<<"Account no. should be of five digits!"; } else { gotoxy(30,24); clreol(); break; } } gotoxy(30,24); cout<<"`S'ave and exit"; gotoxy(30,25); cout<<"`E'xit without saving"; ch1=getch(); ch1=toupper(ch1); switch(ch1) { case('S'): fptr.write((char*)this,sizeof(obj)); fptr.close(); return; case('E'): fptr.close(); return; } getch(); }//End of add()