static void readdumptimes(FILE *df) { int i; struct dumptime *dtwalk; for (;;) { dtwalk = (struct dumptime *)calloc(1, sizeof(struct dumptime)); if (getrecord(df, &(dtwalk->dt_value)) < 0) { free(dtwalk); break; } nddates++; dtwalk->dt_next = dthead; dthead = dtwalk; } ddates_in = 1; /* * arrayify the list, leaving enough room for the additional * record that we may have to add to the ddate structure */ ddatev = (struct dumpdates **) calloc((unsigned) (nddates + 1), sizeof(struct dumpdates *)); dtwalk = dthead; for (i = nddates - 1; i >= 0; i--, dtwalk = dtwalk->dt_next) ddatev[i] = &dtwalk->dt_value; }
static void readdumptimes(FILE *df) { int i; struct dumptime *dtwalk; for (;;) { dtwalk = (struct dumptime *)calloc(1, sizeof (struct dumptime)); if (getrecord(df, &(dtwalk->dt_value)) < 0) { free(dtwalk); break; } nddates++; SLIST_INSERT_HEAD(&dthead, dtwalk, dt_list); } /* * arrayify the list, leaving enough room for the additional * record that we may have to add to the ddate structure */ ddatev = (struct dumpdates **) calloc((unsigned) (nddates + 1), sizeof (struct dumpdates *)); dtwalk = SLIST_FIRST(&dthead); for (i = nddates - 1; i >= 0; i--, dtwalk = SLIST_NEXT(dtwalk, dt_list)) ddatev[i] = &dtwalk->dt_value; }
std::vector<Recordtable> DataBase::getrecordtable() { QSqlQuery query(db); query.exec("SELECT * FROM record ORDER BY record DESC"); std::vector<Recordtable> rcv; while(query.next()) rcv.push_back(getrecord(query.value(1).toInt())); return rcv; }
/* || Extract files from the tape "archive" (ie think "unzip") Only works on SL tapes. */ int extractfiles( ) { SLFMT fmt; SLLABEL lab; unsigned char *ptr; int rc; FILE *outf; /* || First block should be a VOL1 record */ rc = get_sl( &lab ); if( rc < 0 || !sl_isvol( &lab, 1 ) ) { logmsg( "Expected VOL1 label\n" ); return( -1 ); } /* process all files on tape */ while (rc >= 0) { /* || Get the HDR1 label. */ rc = get_sl( &lab ); if( rc < 0 || !sl_ishdr( &lab, 1 ) ) { /* quietly return when no more files */ return( 0 ); } /* || Make the label more managable */ sl_fmtlab( &fmt, &lab ); logmsg("%-17.17s", fmt.slds1.dsid ); /* || Get the HDR2 label. */ rc = get_sl( &lab ); if( rc < 0 || !sl_ishdr( &lab, 2 ) ) { logmsg( "Expected HDR2 label\n" ); return( -1 ); } /* || Merge the DCB information */ merge( &lab, 1 ); /* || Hop over the tapemark */ if ( opts.faketape ) rc = fet_fsf( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { logmsg( "%s while spacing to start of data\n", het_error( rc ) ); return( rc ); } /* || process the current file */ { /* || Open the output file */ char pathname[MAX_PATH]; opts.ofile = fmt.slds1.dsid; hostpath(pathname, opts.ofile, sizeof(pathname)); outf = fopen( pathname, (opts.flags & O_ASCII) ? "w" : "wb" ); if( outf == NULL ) { logmsg("unable to open %s\n", opts.ofile); return( -1 ); } } /* this should be in a common block, or at least indented */ /* || Different processing when converting to ASCII */ if( opts.flags & ( O_ASCII | O_UNBLOCK | O_RDW ) ) { /* || Get a record */ while( ( rc = getrecord( ) ) >= 0 ) { #ifdef EXTERNALGUI if( extgui ) { off_t curpos; /* Report progress every nnnK */ if ( opts.faketape ) curpos = ftell( opts.fetb->fd ); else curpos = ftell( opts.hetb->fd ); if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) ) { prevpos = curpos; fprintf( stderr, "IPOS=%" I64_FMT "d\n", (U64)curpos ); } } #endif /*EXTERNALGUI*/ /* || Get working copy of record ptr */ ptr = recptr; /* || Only want data portion for RECFM=V records */ if( opts.recfm & O_VARIABLE ) { ptr += 4; rc -= 4; } /* || Convert record to ASCII */ if( opts.flags & O_ASCII ) { sl_etoa( NULL, ptr, rc ); } /* || Strip trailing blanks */ if( opts.flags & O_STRIP || ((opts.flags & O_HRCTXT) && (opts.recfm & O_FIXED) ) ) { while( rc > 0 && ptr[ rc - 1 ] == ' ' ) { rc--; } /* if a text file has been copied, in binary mode, into a fixed dataset, it will have NUL-padding. Since we don't want NULs in a text file, we clean them up too */ if (opts.recfm & O_FIXED) { while( rc > 0 && ptr[ rc - 1 ] == '\0' ) { rc--; } } } /* || Write the record out */ if ( (opts.flags & O_ASCII) && rc == 1 && ptr[0] == ' ' && !(opts.flags & O_RDW) && ( ((opts.recfm & O_UNDEFINED) && !(opts.flags & O_NO_NEW) ) || (opts.recfm & O_VARIABLE) ) ) { /* if the dataset is undefined or variable and has a single space, then don't write out that space, because the space most likely exists because it was artificially inserted to prevent empty records or blocks rather than because the user really wants a space. Also, if they are taking care of newlines themselves for RECFM=U, then any single space in the last block would be genuine albeit extremely unlikely. */ rc = 0; } /* write out an artificial RDW */ if ((opts.flags & O_RDW) || ((opts.flags & O_HRCBIN) && (opts.recfm & O_VARIABLE) ) ) { int havenl = 0; /* take into account newline */ if( opts.flags & O_ASCII && (!(opts.flags & O_NO_NEW) || !(opts.recfm & O_UNDEFINED) ) ) { havenl = 1; rc++; } rc += 4; fputc( (((unsigned int)rc >> 8) & 0xff), outf ); fputc( ((unsigned int)rc & 0xff), outf ); fputc( 0x00, outf ); fputc( 0x00, outf ); rc -= 4; if (havenl) { rc--; } } fwrite( ptr, rc, 1, outf ); /* || Put out a linefeed when converting */ if( opts.flags & O_ASCII && (!(opts.flags & O_NO_NEW) || !(opts.recfm & O_UNDEFINED) ) ) { fwrite( "\n", 1, 1, outf ); } } } else { /* || Get a record */ while( ( rc = getblock( ) ) >= 0 )
/* || Extract the file from the tape */ int getfile( FILE *outf ) { SLFMT fmt; SLLABEL lab; unsigned char *ptr; int fileno; int rc; /* || Skip to the desired file */ if( opts.flags & O_NL ) { /* || For NL tapes, just use the specified file number */ fileno = opts.fileno; /* || Start skipping */ while( --fileno ) { /* || Forward space to beginning of next file */ if ( opts.faketape ) rc = fet_fsf ( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { char msgbuf[128]; MSGBUF( msgbuf, "%set_fsf() while positioning to file '%d'", opts.faketape ? "f" : "h", opts.fileno ); WRMSG( HHC00075, "E", msgbuf, het_error( rc ) ); return( rc ); } } } else { /* || First block should be a VOL1 record */ rc = get_sl( &lab ); if( rc < 0 || !sl_isvol( &lab, 1 ) ) { WRMSG( HHC02753, "E", "VOL1" ); return( -1 ); } /* || For SL, adjust the file # so we end up on the label before the data */ fileno = ( opts.fileno * 3 ) - 2; /* || Start skipping */ while( --fileno ) { /* || Forward space to beginning of next file */ if ( opts.faketape ) rc = fet_fsf ( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { char msgbuf[128]; MSGBUF( msgbuf, "%set_fsf() while positioning to file '%d'", opts.faketape ? "f" : "h", opts.fileno ); WRMSG( HHC00075, "E", msgbuf, het_error( rc ) ); return( rc ); } } /* || Get the HDR1 label. */ rc = get_sl( &lab ); if( rc < 0 || !sl_ishdr( &lab, 1 ) ) { WRMSG( HHC02753, "E", "HDR1" ); return( -1 ); } /* || Make the label more managable */ sl_fmtlab( &fmt, &lab ); WRMSG( HHC02754, "E", fmt.slds1.dsid ); /* || Get the HDR2 label. */ rc = get_sl( &lab ); if( rc < 0 || !sl_ishdr( &lab, 2 ) ) { WRMSG( HHC02753, "E", "HDR2" ); return( -1 ); } /* || Merge the DCB information */ merge( &lab ); /* || Hop over the tapemark */ if ( opts.faketape ) rc = fet_fsf( opts.fetb ); else rc = het_fsf( opts.hetb ); if( rc < 0 ) { if ( opts.faketape ) WRMSG( HHC00075, "E", "fet_fsf()", fet_error( rc ) ); else WRMSG( HHC00075, "E", "het_fsf()", het_error( rc ) ); return( rc ); } } /* || Different processing when converting to ASCII */ if( opts.flags & ( O_ASCII | O_UNBLOCK ) ) { /* || Get a record */ while( ( rc = getrecord( ) ) >= 0 ) { #ifdef EXTERNALGUI if( extgui ) { off_t curpos; /* Report progress every nnnK */ if ( opts.faketape ) curpos = ftell( opts.fetb->fd ); else curpos = ftell( opts.hetb->fd ); if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) ) { prevpos = curpos; fprintf( stderr, "IPOS=%" I64_FMT "d\n", (U64)curpos ); } } #endif /*EXTERNALGUI*/ /* || Get working copy of record ptr */ ptr = recptr; /* || Only want data portion for RECFM=V records */ if( opts.recfm & O_VARIABLE ) { ptr += 4; rc -= 4; } /* || Convert record to ASCII */ if( opts.flags & O_ASCII ) { sl_etoa( NULL, ptr, rc ); } /* || Strip trailing blanks */ if( opts.flags & O_STRIP ) { while( rc > 0 && ptr[ rc - 1 ] == ' ' ) { rc--; } } /* || Write the record out */ fwrite( ptr, rc, 1, outf ); /* || Put out a linefeed when converting */ if( opts.flags & O_ASCII ) { fwrite( "\n", 1, 1, outf ); } } } else { /* || Get a record */ while( ( rc = getblock( ) ) >= 0 ) { #ifdef EXTERNALGUI if( extgui ) { off_t curpos; /* Report progress every nnnK */ if ( opts.faketape ) curpos = ftell( opts.fetb->fd ); else curpos = ftell( opts.hetb->fd ); if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) ) { prevpos = curpos; fprintf( stderr, "IPOS=%" I64_FMT "d\n", (U64)curpos ); } } #endif /*EXTERNALGUI*/ /* || Write the record out */ fwrite( blkptr, blklen, 1, outf ); } } return( rc ); }
static int execute( /* compute result */ char *fname ) { double inpval[MAXCOL]; double tally[MAXCOL]; short rsign[MAXCOL]; double result[MAXCOL]; int n; int nread, ncol; long nlin, ltotal; FILE *fp; /* open file */ if (fname == NULL) fp = stdin; else if ((fp = fopen(fname, "r")) == NULL) { fprintf(stderr, "%s: cannot open\n", fname); return(-1); } if (nbicols) SET_FILE_BINARY(fp); #ifdef getc_unlocked /* avoid lock/unlock overhead */ flockfile(fp); #endif ltotal = 0; while (!feof(fp)) { if (ltotal == 0) { /* initialize */ if (func == MULT) /* special case */ for (n = 0; n < MAXCOL; n++) { tally[n] = 0.0; rsign[n] = 1; } else for (n = 0; n < MAXCOL; n++) tally[n] = init_val[func]; } ncol = 0; for (nlin = 0; (count <= 0 || nlin < count) && (nread = getrecord(inpval, fp)) > 0; nlin++) { /* compute */ for (n = 0; n < nread; n++) switch (func) { case ADD: if (inpval[n] == 0.0) break; if (power != 0.0) tally[n] += pow(fabs(inpval[n]),power); else tally[n] += inpval[n]; break; case MULT: if (inpval[n] == 0.0) rsign[n] = 0; else if (inpval[n] < 0.0) { rsign[n] = -rsign[n]; inpval[n] = -inpval[n]; } if (rsign[n]) tally[n] += log(inpval[n]); break; case MAX: if (inpval[n] > tally[n]) tally[n] = inpval[n]; break; case MIN: if (inpval[n] < tally[n]) tally[n] = inpval[n]; break; } if (nread > ncol) ncol = nread; } if (nlin == 0) break; /* compute and print */ ltotal += nlin; for (n = 0; n < ncol; n++) { result[n] = tally[n]; if (mean) { result[n] /= (double)ltotal; if (func == ADD && power != 0.0 && result[n] != 0.0) result[n] = pow(result[n], 1.0/power); } if (func == MULT) result[n] = rsign[n] * exp(result[n]); } putrecord(result, ncol, stdout); if (!subtotal) ltotal = 0; } /* close input */ return(fclose(fp)); }
void main() { int ch=0,ans=0; int val=0; char str[15]; struct node *new1,*new2; clrscr(); /* initialization of list with the existing records */ fp=fopen("phone.txt","r"); if(fp==NULL) { printf("File cant be opened !"); getch(); exit(1); } while(!feof(fp)) { new1=getrecord(); if(insert(new1)==-1) printf("Cant insert record ! Error..."); else printf("Record entered..."); } getch(); fclose(fp); do { clrscr(); printf("Menu"); printf("1. Add a New phone record."); printf("2. Delete an existing Record."); printf("3. show all Records."); printf("4. Modify a particular Record."); printf("5. Exit."); printf("Enter your choice--->"); scanf("%d",&ch); switch(ch) { case 1: new1 = getnode(); val = insert(new1); if(val==-1) printf("Employee id already exists ! try again..."); else printf("Employee details successfully stored"); break; case 2: printf("Enter the phone no.you wish to delete--->"); scanf("%d",&val); ans=delnode(val); if(ans==-1) printf("Record doesnt exist ! Try again..."); if(ans==0) printf("Record deleted !"); break; case 3: display(); break; case 4: printf("Search by phone no. or Name ? (1/2)--->"); scanf("%d",&ch); if(ch==1) { printf("Enter the phone no. you wish to search for--->"); scanf("%d",&val); new2=query(val,&str,1); } else { printf("Enter the name of the person you wish to search for--->"); scanf("%s",&str); new2=query(val,&str,0); } if(new2) { printf("Enter the New name of the person--->"); scanf("%s",&new2->name); printf("Enter new phone no. of the person--->"); scanf("%d",&new2->num); printf("Record modified successfully !"); } break; case 5: printf("Leaving Database,writing back to file..."); CopyToFile(); getch(); free(list); exit(1); break; } getch(); } while(1); }