/** * Format and send a error message containing the current command * * @param kmsg2 * Second line of error message with a "$" appended to it * A point to the bad token will be added to this line. * The first line will contain a standard error message * with the current command appended to it. * @param kmsg2_s * Length of \p kmsg2 * * @date 820615: Added call to CERR to set error condition. * @date 820420: Original version. * */ void cfmt(char *kmsg2, int kmsg2_s) { static char kmsg1[28] = "ERROR interpreting command:"; /* - Raise command syntax error condition. */ cerr( 1001 ); char *s = strcut(kmsg2, 1, indexb(kmsg2, kmsg2_s)); bell(); fprintf(stdout, " %s %s \n", kmsg1, lexer_input()); if(arg()) { fprintf(stdout, " %*s %*s\n", -(int)strlen(kmsg1), s, arg()->col, "^"); } else { fprintf(stdout, " %*s %*s\n", -(int)strlen(kmsg1), s, (int)strlen(lexer_input()), "^"); } FREE(s); return; return; } /* end of function */
/** * Determine the number of output entries that would * result frm reading a card using a given format statement. * * @param kfmt * Format statement * @param kfmt_s * Length of \p kfmt * @param nentry * Number of floating point field to be read * * @date 970129: Add parameter (0) to cnvati. 0 means that if a string * of digits is too long, let it slide by. maf * @date 860910: Original version. */ void detnum(char *kfmt, int kfmt_s, int *nentry) { int imult, int_, iten, jc, ji, nc, nerr; /* - Initialize output argument. */ *nentry = 0; /* - Determine number of characters in format statement. */ nc = indexb( kfmt,kfmt_s ); /* - Loop on each character in format statement. * Ignore the first and last characters which * should be parentheses. */ jc = 2; nc = nc - 1; L_1000: if( jc <= nc ){ /* -- Search for "F", "E", or "G". */ if( (kfmt[jc - 1] == 'F' || kfmt[jc - 1] == 'E') || kfmt[jc - 1] == 'G') { /* --- If found, search backward to see if * there is a preceeding multiplier. */ imult = 0; iten = 1; ji = jc - 1; L_2000: cnvati( &kfmt[ji - 1],1, &int_, 0, &nerr ); if( nerr == 0 ){ imult = imult + iten*int_; iten = 10*iten; ji = ji - 1; goto L_2000; } /* --- Accumulate the number of entries here. */ if( imult > 0 ){ *nentry = *nentry + imult; } else{ *nentry = *nentry + 1; } } /* -- Loop back until format statement is exhausted. */ jc = jc + 1; goto L_1000; } return; }
void ColorHistogramRGB<Mesh>::extract(const Mesh&m,arma::vec&hist) { hist = arma::vec( Nr_*Ng_*Nb_ ,arma::fill::ones); arma::Mat<uint8_t> rgb_mat((uint8_t*)m.vertex_colors(),3,m.n_vertices(),false,true); arma::fmat frgb_mat = arma::conv_to<arma::fmat>::from(rgb_mat); for( size_t index = 0 ; index < frgb_mat.n_cols ; ++index ) { arma::fvec rgb = frgb_mat.col(index); hist[( indexr(rgb(0))*Ng_ + indexg(rgb(1)) )*Nb_ + indexb(rgb(2))] += 1.0 ; } hist /= arma::accu(hist); hist *= hist.size(); }
/** * Execute the PAUSE command to pause. * The command sends a message to the terminal and then pauses * and waits for a return message * * @param nerr * Error Return Flag * - 0 on Success * * @date 860925: Added PERIOD option. * @date 840206: Original version. * */ void xpause(int *nerr) { char kret[9]; int nc; double fperio; *nerr = 0; fperio = cmexm.nperio / 1000.0; while ( lcmore( nerr ) ){ /* -- "PERIOD ON|OFF|v": set period of time to pause. */ if( lklogr( "PERIOD$",8, &cmexm.lperio, &fperio ) ){ cmexm.nperio = (int)( 1000.0*fperio ); if( cmexm.nperio <= 0 ) cmexm.lperio = FALSE; } /* -- Determine text of pause message. */ else if( lkchar( "MESSAG$",8, MCMSG - 2, kmexm.kpause,MCMSG+1, &nc ) ){ subscpy( kmexm.kpause, nc, -1, MCMSG, " $" ); } /* -- Bad syntax. */ else{ cfmt( "ILLEGAL OPTION:",17 ); cresp(); } } if( cmexm.lperio ){ nc = indexb( kmexm.kpause,MCMSG+1 ); if( nc > 2 ) { int n = 1; char *p = &kmexm.kpause[0]; while(*p && *p != '$' && n < nc-1) { fprintf(stdout, "%c", *p); p++; n++; } fflush(stdout); } zsleep( cmexm.nperio ); } else{ zgtmsg( kmexm.kpause,MCMSG+1, kret,9 ); } return; }
/** * Append alphanumberic string \p kalpha to current message * * \param kalpha * Alphanumberic string to append to current message * \param kalpha_s * Length of string \p kalpha * * \return Nothing * * \see indexb outmsg clrmsg * \see t_cmmsg.nlimsg * \see t_cmmsg.nchmsg * \see t_cmmsg.autoout * \see t_cmmsg.itpmsg * \see t_kmmsg.klimsg * * \date 900518: Added logic to test for an empty string. * This corrects a problem with VAX VMS version. * \date 890104: Added automatic output mode coding. * \date 830916: Original version. * \date 890104: Documented/Reviewed */ void apcmsg(char *kalpha, int kalpha_s) { int isave, nalpha, nchmax; char *s1; /* - Determine length of string without trailing blanks. */ nalpha = indexb( kalpha,kalpha_s ); /* - Decrease maximum length of first line of message to * allow room for a prefix to be added later when written. */ nchmax = MCMSG; if( cmmsg.nlimsg == 1 ) nchmax = nchmax - 10; /* - Start new line of message if there is not enough room. */ if( (cmmsg.nchmsg + nalpha + 1) > nchmax ){ if( cmmsg.nlimsg < MLIMSG ){ cmmsg.nlimsg = cmmsg.nlimsg + 1; } else if( cmmsg.autoout ){ outmsg(); isave = cmmsg.itpmsg; clrmsg(); cmmsg.itpmsg = isave; } else{ fstrncpy( kmmsg.klimsg[cmmsg.nlimsg - 1], MCMSG, " ", 1 ); } cmmsg.nchmsg = 0; } /* - Append alphanumeric string to current message line. * Include one trailing blank. Update character counter. */ if( nalpha > 0 ){ s1 = strcut(kalpha, 1, nalpha); subscpy( kmmsg.klimsg[cmmsg.nlimsg - 1], cmmsg.nchmsg, cmmsg.nchmsg + nalpha + 1, MCMSG, s1); free(s1); } cmmsg.nchmsg = cmmsg.nchmsg + nalpha + 1; return; }
void ColorHistogramLab<Mesh>::extract(const Mesh&m,arma::vec&hist) { hist = arma::vec( (NL_+ 1)*(Na_+1)*(Nb_+1) ,arma::fill::ones); arma::Mat<uint8_t> rgb_mat((uint8_t*)m.vertex_colors(),3,m.n_vertices(),false,true); arma::fmat Lab_mat; ColorArray::RGB2Lab(rgb_mat,Lab_mat); for( size_t index = 0 ; index < Lab_mat.n_cols ; ++index ) { arma::fvec Lab = Lab_mat.col(index); hist[( indexL(Lab(0))*Na_ + indexa(Lab(1)) )*Nb_ + indexb(Lab(2))] += 1.0 ; } hist /= arma::accu(hist); hist *= hist.size(); }
void ColorHistogramRGB<Mesh>::extract(const Mesh&m,std::vector<double>&hist) { hist.resize(Nr_*Ng_*Nb_ ,1.0); arma::Mat<uint8_t> rgb_mat((uint8_t*)m.vertex_colors(),3,m.n_vertices(),false,true); arma::fmat frgb_mat = arma::conv_to<arma::fmat>::from(rgb_mat); double sum = .0; for( size_t index = 0 ; index < frgb_mat.n_cols ; ++index ) { arma::fvec rgb = frgb_mat.col(index); hist[( indexr(rgb(0))*Ng_ + indexg(rgb(1)) )*Nb_ + indexb(rgb(2))] += 1.0 ; sum += 1.0; } #pragma omp parallel for for(int i=0; i<hist.size(); ++i) { hist[i] *= (hist.size()/sum); } }
/** * Read a vars list from disk to memory * * @param fullvars * Full (absolute) name of the vars disk file * @param fullvars_s * Length of \p fullvars * @param node * Output vars storage system node number * @param nerr * Error Return Flag * - 0 on Success * - Non-Zero on Error * * @date 890227: Changed argument list. * @date 881115: Added output of node number. * @date 880321: Included logic to find and save nil index after read. * @date 870916: Original version. * @date 870916: Documented/Reviewed * */ void readvfile(char *fullvars, int fullvars_s, int *node, int *nerr) { char *s1; *nerr = 0; *node = 0; s1 = strcut(fullvars, 1, indexb(fullvars, fullvars_s)); if((*nerr = sac_vars_read(s1))) { error(*nerr, "%s", s1); } free(s1); return; }
void ColorHistogramLab<Mesh>::extract(const Mesh&m,std::vector<double>&hist) { hist.resize((NL_+ 1)*(Na_+1)*(Nb_+1),1.0); arma::Mat<uint8_t> rgb_mat((uint8_t*)m.vertex_colors(),3,m.n_vertices(),false,true); arma::fmat Lab_mat; ColorArray::RGB2Lab(rgb_mat,Lab_mat); double sum = 0.0; for( size_t index = 0 ; index < Lab_mat.n_cols ; ++index ) { arma::fvec Lab = Lab_mat.col(index); hist[( indexL(Lab(0))*Na_ + indexa(Lab(1)) )*Nb_ + indexb(Lab(2))]+= 1.0 ; sum += 1.0; } #pragma omp parallel for for(int i=0; i<hist.size(); ++i) { hist[i] *= (hist.size()/sum); } }
/** * Add a line of text to a run file * * @param text * Text to add to run file * @param text_s Length of \p text * @param nfun * File Descriptor * @param nerr * Error Return Flag * - 0 on Success * * @date 871014: Original version. * */ void zruntext(char *text, int text_s, FILE *nfun, int *nerr) { int nctext; char *strtemp; *nerr = 0; /* - Write line to the file. */ nctext = max( 1, indexb( text,text_s ) ); strtemp = malloc(nctext+1); strncpy(strtemp,text,nctext); strtemp[nctext] = '\0'; fprintf(nfun,"%s\n",strtemp); free(strtemp); return; }
void xp1(int *nerr) { int n; char *kptext, kret[9]; int l1dttm, lany, lbotaxsave, lbottcsave, lframesave, ltitlsave, ltoptcsave, lwait, lxgrdsave, lxlabsave, lxlims, lylabsave, lprint = FALSE , ltry = FALSE ; int i, jdfl, jdfl1, jdfl2, jfr, jperfr, n1dttm[6], ncret, nfr, nlcx, nlcy, nperfr, num, notused; float tmax, tmaxj, tmin, tminj, toff[MDFL], ypdel, ypmxsave; static int lrel = FALSE; static int lperpl = FALSE; static int nperpl = 3; static char kwait[9] = "Waiting$"; float *const Toff = &toff[0] - 1; /*===================================================================== * PURPOSE: To execute the action command P1. * This command makes a multi-trace, multi-window plot. *===================================================================== * OUTPUT ARGUMENTS: * nerr: Error return flag. Set to 0 if no error occurred. * Potential error numbers: 1001, 1504. *===================================================================== * MODULE/LEVEL: gam/2 *===================================================================== * GLOBAL INPUT: * mach: * dfm: ndfl, sacmem * hdr: begin, ennd, delta * gem: lbotax, lbottc, ltopax, ltoptc, lxlab, lylab, ltitl, * lxgrd, ypmn, ypmx, chht, tsdef * gam: kgddef *===================================================================== * SUBROUTINES CALLED: *===================================================================== * MODIFICATION HISTORY: * 970908: Modified response to ddttm. maf * 970723: Commented out an if statement to fix a bug which kept * p1 relative from functioning when xlim was set. maf * 970130: Added arguments to dispid() to plot file number. maf * 910607: Move stmt label 8888 back to where it was. * Changed gots to goto plrest after call to plsave. * Error condition before lframesave goes to return. (wct). * 910607: Added call to zgetgd when no graphics device specified. * Changed call to begindevice to begindevices. (wct) * 910220: Move stmt label 8888, so lframe etc. are restored on err exit * 880411: Axes annotation now controlled by GEM variables. * 850321: Now displaying REL offset below FILEID. * 821228: Added calls to DISPID, DISPPK and PLHOME. * 821122: Added check for bad date fields. * Fixed bug involving titles and PP option. * 820823: Fixed bug involving extra x axes when using PP option. * 820721: Changed to newest set of parsing and checking functions. * 811228: Deleted call to ZCLIP. * 810120: Changed to output message retrieval from disk. * 800920: Added PERPLOT option. * Fixed bug in REL/ABS option. * 800905: Pick and file id options to new DISPLAY command. * 800618: Added pick display capability to this plot. *===================================================================== * DOCUMENTED/REVIEWED: *===================================================================== */ /* PROCEDURE: */ /* Errors before plsave have to avoid going to execute plrest. */ *nerr = 0; /* PARSING PHASE: */ /* - Loop on each token in command: */ while ( lcmore( nerr ) ){ /* -- "PERPLOT ON/OFF/n": change number of files plotted per frame. */ if( lklogi( "PERPLOT$",9, &lperpl, &nperpl ) ) { /* do nothing */ } /* -- "RELATIVE/ABSOLUTE": change method of displaying time on x axis. */ else if( lclog2( "RELATIVE$",10, "ABSOLUTE$",10, &lrel ) ) { /* do nothing */ } /* if PRINT option is tried, get printer name */ else if ( ltry ) { lcchar ( MAXPRNTRNAMELEN , kmgem.kptrName , MAXPRNTRNAMELEN+1 , ¬used ) ; terminate ( kmgem.kptrName ) ; if ( !lprint ) kmgem.kptrName[0] = '\0' ; ltry = FALSE ; } /* -- "PRINT": print the final product */ else if( lckey( "PRINT#$", 8 ) ) { ltry = TRUE ; if ( cmgdm.lbegf ) { setmsg ( "WARNING" , 2403 ) ; outmsg () ; clrmsg () ; } else { lprint = TRUE ; } } /* -- Bad syntax. */ else{ cfmt( "ILLEGAL OPTION:",17 ); cresp(); } } /* end while */ /* - The above loop is over when one of two conditions has been met: * (1) An error in parsing has occurred. In this case NERR is > 0 . * (2) All the tokens in the command have been successfully parsed. */ if( *nerr != 0 ) goto L_8888; /* CHECKING PHASE: */ /* - Check for null data file list. */ vflist( nerr ); if( *nerr != 0 ) goto L_8888; /* - Check to make sure all files are time series files. */ vftime( nerr ); if( *nerr != 0 ){ aplmsg( "Use PLOTSP command to plot spectral data.",42 ); goto L_8888; } /* - If no graphics device is open, try to open the default device. */ getstatus( "ANY", &lany ); if( !lany ){ zgetgd( kmgam.kgddef,9 ); begindevices( kmgam.kgddef,9, 1, nerr ); if( *nerr != 0 ) goto L_8888; } /* EXECUTION PHASE: */ /* - Save current plot and x limit attributes. * - Error after plsave have to go to execute plrest. */ plsave(); /* initialize plot offsets */ for ( i=0; i<MDFL; i++) toff[i] = 0.0; /* - Set up specific options that apply only to this plot. */ lbotaxsave = cmgem.axis[BOTTOM].annotate; lbottcsave = cmgem.axis[BOTTOM].ticks; ltoptcsave = cmgem.axis[TOP].ticks; cmgem.axis[BOTTOM].ticks = FALSE; cmgem.axis[BOTTOM].annotate = FALSE; lxlabsave = cmgem.xlabel.on; lylabsave = cmgem.ylabel.on; ltitlsave = cmgem.title.on; lxgrdsave = cmgem.lxgrd; cmgem.xlabel.on = FALSE; cmgem.ylabel.on = FALSE; cmgem.title.on = FALSE; cmgem.lxgrd = FALSE; /* - Set up y window for each subplot. */ if( lperpl ){ nfr = (cmdfm.ndfl - 1)/nperpl + 1; nperfr = nperpl; } else{ nfr = 1; nperfr = cmdfm.ndfl; } ypdel = (cmgem.plot.ymax - cmgem.plot.ymin)/(float)( nperfr ); /* - Check WAIT option. This is on when: * -- A wait request has been made. * -- An active device (normally the user's terminal) is on. */ if( cmgam.lwaitr ) getstatus( "ACTIVE", &lwait ); else lwait = FALSE; /* - Loop on number of frames: */ jdfl1 = 1; ypmxsave = cmgem.plot.ymax; lframesave = cmgem.lframe; for( jfr = 1; jfr <= nfr; jfr++ ){ /* set cmgem.lframe FALSE for each pass through loop, because endframe() sets it back to TRUE for the next pass. */ cmgem.lframe = FALSE; /* -- No wait after last frame. */ if( jfr == nfr && !cmgam.lwaite ) lwait = FALSE; /* -- Loop on data files in each frame: */ jdfl2 = min( cmdfm.ndfl, jdfl1 + nperfr - 1 ); /* -- Determine time limits for x axis of this frame. * (Correct for any differences in GMT reference time.) */ getfil( jdfl1, TRUE, &num, &nlcy, &nlcx, nerr ); if( *nerr != 0 ) goto L_7777; jperfr = 1; getxlm( &lxlims, &tmin, &tmax ); /* if( !lxlims ){ commented out to allow relative mode when xlim is set. maf 970723 */ if( lrel ){ tmax = tmax - tmin; Toff[jperfr] = -tmin; tmin = 0.; } else{ copyi( nzdttm, n1dttm, 6 ); l1dttm = ldttm( n1dttm ); Toff[jperfr] = 0.; } for( jdfl = jdfl1 + 1; jdfl <= jdfl2; jdfl++ ){ jperfr = jperfr + 1; getfil( jdfl, TRUE, &num, &nlcy, &nlcx, nerr ); if( *nerr != 0 ) goto L_7777; getxlm( &lxlims, &tminj, &tmaxj ); if( lrel ){ tmax = fmax( tmax, tmaxj - tminj ); Toff[jperfr] = -tminj; } else{ if( l1dttm && ldttm( nzdttm ) ){ ddttm( nzdttm, n1dttm, &Toff[jperfr] ); /* if it starts 2 days after the first file, plot relative. maf 970908 */ if ( fabs ( Toff[jperfr] ) > TWODAYS ) Toff[jperfr] = 0 ; } else{ Toff[jperfr] = 0.; } tmin = fmin( tmin, tminj + Toff[jperfr] ); tmax = fmax( tmax, tmaxj + Toff[jperfr] ); } /* end else associated with if ( lrel ) */ } /* end for( jdfl = jdfl1 + 1; jdfl <= jdfl2; jdfl++ ) */ /* } end if ( !lxlims ) commented out to allow relative mode when xlim is set. maf 970723 */ /* - Check range of time limits to avoid errors that could occur * later during plotting. * if( fabs( tmax - tmin ) > (float)( MLARGE ) ){ *nerr = 1504; setmsg( "ERROR", *nerr ); goto L_7777; } */ /* - Set x axis plot limits. */ cmgem.lxlim = TRUE; cmgem.ximn = tmin; cmgem.ximx = tmax; if( lframesave ){ beginframe( lprint , nerr ); if( *nerr != 0 ) goto L_7777; getvspace( &cmgem.view.xmin, &cmgem.view.xmax, &cmgem.view.ymin, &cmgem.view.ymax ); } jperfr = 0; cmgem.tsdef = fmin( cmgem.tsdef, (cmgem.view.ymax - cmgem.view.ymin)/(8.0* (float)( nperfr )) ); cmgam.tsfid = cmgem.tsdef; cmgam.tspk = cmgem.tsdef; cmgem.tsaxis = cmgem.tsdef; for( jdfl = jdfl1; jdfl <= jdfl2; jdfl++ ){ jperfr = jperfr + 1; cmgem.plot.ymin = cmgem.plot.ymax - ypdel; /* --- Get pointers to this file's location in memory. */ getfil( jdfl, TRUE, &num, &nlcy, &nlcx, nerr ); if( *nerr != 0 ) goto L_7777; /* --- Set up x axis data values. */ if( *leven ){ cmgem.xgen.on = TRUE; cmgem.xgen.delta = *delta; cmgem.xgen.first = *begin + Toff[jperfr]; } else{ cmgem.xgen.on = FALSE; } /* --- Set up y axis plot limits. */ getylm( &cmgem.lylim, &cmgem.yimn, &cmgem.yimx ); /* --- Plot this file. */ pl2d( cmmem.sacmem[nlcx], cmmem.sacmem[nlcy], num, 1, 1, nerr ); if( *nerr != 0 ) goto L_7777; /* --- Plot picks and fileid. */ disppk( Toff[jperfr] ); /* --- Add a label with offset time if this is a REL plot. */ kptext = NULL; n = 0; if( lrel && cmgam.lfidrq ){ asprintf(&kptext, "OFFSET: %10.3e", -Toff[jperfr] ); n = 1; } dispid( cmgam.lfinorq , jdfl, n, &kptext ); if(kptext) { free(kptext); kptext = NULL; } cmgem.plot.ymax = cmgem.plot.ymin; } /* -- Draw bottom x axis. */ cmgem.axis[BOTTOM].annotate = lbotaxsave; cmgem.axis[BOTTOM].ticks = lbottcsave; cmgem.axis[TOP].ticks = ltoptcsave; cmgem.lxgrd = lxgrdsave; cmgem.uplot.ymax = ypmxsave*cmgem.view.ymax; cmgem.chht = cmgem.tsaxis; cmgem.chwid = cmgem.txrat*cmgem.chht; settextsize( cmgem.chwid, cmgem.chht ); if( cmgem.ixint == AXIS_LINEAR ){ xlinax(); } else if( cmgem.ixint == AXIS_LOG ){ xlogax(); } /* -- Draw axes labels and title. */ if( lxlabsave ) centxt( kmgem.kxlab,145, cmgem.xlabel.len, cmgem.xlabel.pos, cmgem.xlabel.text_size ); if( lylabsave ) centxt( kmgem.kylab,145, cmgem.ylabel.len, cmgem.ylabel.pos, cmgem.ylabel.text_size ); if( ltitlsave ) centxt( kmgem.ktitl,145, cmgem.title.len, cmgem.title.pos, cmgem.title.text_size ); /* -- Home cursor, advance frame and restore some GEM parameters. */ plhome(); if( lframesave ) endframe( FALSE , nerr ); else flushbuffer( nerr ); cmgem.plot.ymax = ypmxsave; cmgem.axis[BOTTOM].annotate = FALSE; cmgem.axis[BOTTOM].ticks = FALSE; /* -- Wait for user prompt before plotting next frame if appropriate. */ if( lwait ){ zgpmsg( kwait,9, kret,9 ); ncret = indexb( kret,9 ); upcase( kret, ncret, kret,9 ); if( kret[0] == 'K' ) goto L_7777; if( kret[0] == 'G' ) lwait = FALSE; } jdfl1 = jdfl2 + 1; } /* end for ( jfr ) */ /* - Restore plot and x limit attributes. Return. */ L_7777: plrest(); cmgam.tsfid = cmgem.tsdef; cmgam.tspk = cmgem.tsdef; cmgem.tsaxis = cmgem.tsdef; cmgem.plot.ymax = ypmxsave; cmgem.axis[BOTTOM].annotate = lbotaxsave; cmgem.axis[BOTTOM].ticks = lbottcsave; cmgem.lframe = lframesave; L_8888: return; } /* end of function */
/** * Write a File to disk * * @param lsdd * Set the Output to be a SDD file * @param nerr * Error Return Flag * - 0 on Success * * @date 970702: Changed lckey and lkchar to lckeyExact and lkcharExact * throughout xw.c. This will allow files to begin with * the same string as the various options (eg. sacxz.021.z) * maf. * @date 910731: Bug fixed in options PREPEND, DELETE, CHANGE. * @date 900904: Added SDD as a format for write. * @date 881228: Added four new options for generating write file list * from data file list: APPEND, PREPEND, CHANGE, DELETE. * @date 880204: Fixed logic involving use of DIR option in READ and WRITE * by adding an ON/OFF flag as well as a directory name. * @date 880115: Deleted call that forced default directory to lowercase. * @date 870626: Added default directory option. * @date 860917: Changed to character lists for storing data file names. * @date 850730: Deleted SOCKITTOME format. * @date 830120: Added SOCK and CI output formats. * @date 820721: Changed to newest set of parsing and checking functions. * @date 810120: Changed to output message retrieval from disk. * @date 810203: Fixed bug in file overwrite option. * */ void xw(int lsdd, int *nerr) { int i; char delimiter[2], kcdir[9], kchange[MCPFN+1], kdirpart[MCPFN+1]; char kfile[MCPFN+1], kpdir[9], kstring[MCPFN+1], ktemp[9]; int lexpnd; int jdfl, nchange, nchar, nchg, ndx1, ndx2; int nlen, nstr, nstring, nwrdir; static int lwrdir = FALSE; char *cattemp; char *strtemp1, *strtemp2, *strtemp3; char *file; string_list *list, *files; kschan[12]='\0'; kschdr[80]='\0'; ksclas[4]='\0'; kscom[40]='\0'; ksevnm[8]='\0'; ksfrmt[8]='\0'; ksstnm[8]='\0'; memset(kfile, 0, sizeof(kfile)); memset(kdirpart, 0, sizeof(kdirpart)); memset(kchange, 0, sizeof(kchange)); memset(ktemp, 0, sizeof(ktemp)); memset(kstring, 0, sizeof(kstring)); memset(kpdir, 0, sizeof(kpdir)); memset(kcdir, 0, sizeof(kcdir)); memset(delimiter, 0, sizeof(delimiter)); lexpnd = FALSE; *nerr = 0; files = string_list_init(); list = NULL; if( lsdd ) cmdfm.iwfmt = 3; /* PARSING PHASE: */ /* - Loop on each token in command: */ while ( lcmore( nerr ) ){ /* -- "SAC|ALPHA": set format to be used in writing files. */ if( lckeyExact( "SAC#$",6 ) ) cmdfm.iwfmt = 1; else if( lckeyExact( "ALPHA#$",8 ) ) cmdfm.iwfmt = 2; else if( lckeyExact( "CI#$",5 ) ) cmdfm.iwfmt = 2; else if( lckeyExact( "SDD#$",6 ) ) cmdfm.iwfmt = 3; else if( lckeyExact( "XDR#$",6 ) ) { cmdfm.iwfmt = 4; } else if( lckeyExact( "SEGY#$", 7 ) ) cmdfm.iwfmt = 5; /* -- "OVER": overwrite files from previous READ command. */ else if( lckeyExact( "OVER#$",7 ) ){ cmdfm.lovrrq = TRUE; lexpnd = FALSE; string_list_extend(files, datafiles); } /* generate names from the KSTCMP header field */ else if( lckeyExact( "KSTCMP#$",9 ) ){ lexpnd = FALSE; gennames("KSTCMP ",7,files,string_list_length(datafiles),nerr); if(*nerr != 0) goto L_8888; } /* -- "APPEND string": append string to filenames from READ command. */ else if( lkcharExact( "APPEND#$",9, MCPFN, kstring,MCPFN+1, &nstring ) ){ for(i = 0; i < cmdfm.ndfl; i++) { strtemp1 = string_list_get(datafiles, i); appendstring( kstring,MCPFN+1, strtemp1, strlen(strtemp1)+2, kfile,MCPFN+1 ); string_list_put(files, kfile, MCPFN+1); if( *nerr != 0 ) goto L_8888; } cmdfm.lovrrq = FALSE; lexpnd = TRUE; } /* -- "PREPEND string": prepend string to filenames from READ command. */ else if( lkcharExact( "PREPEND#$",10, MCPFN, kstring,MCPFN+1, &nstring ) ){ for(i = 0; i < cmdfm.ndfl; i++) { strtemp1 = malloc(nstring+1); strncpy(strtemp1,kstring,nstring); strtemp1[nstring] = '\0'; strtemp2 = string_list_get(datafiles, i); prependstring( strtemp1, nstring+1, strtemp2, strlen(strtemp2)+2, kfile,MCPFN+1); free(strtemp1); string_list_put(files, kfile, MCPFN+1); if( *nerr != 0 ) goto L_8888; } cmdfm.lovrrq = FALSE; lexpnd = TRUE; } /* -- "DELETE string": delete string from filenames from READ command. */ else if( lkcharExact( "DELETE#$",9, MCPFN, kstring,MCPFN+1, &nstring ) ){ for(i = 0; i < cmdfm.ndfl; i++) { strtemp1 = malloc(nstring+1); strncpy(strtemp1,kstring,nstring); strtemp1[nstring] = '\0'; strtemp2 = string_list_get(datafiles, i); deletestring( strtemp1, nstring+1, strtemp2, strlen(strtemp2)+2, kfile,MCPFN+1); free(strtemp1); string_list_put(files, kfile, MCPFN+1); if( *nerr != 0 ) goto L_8888; } cmdfm.lovrrq = FALSE; lexpnd = TRUE; } /* -- "CHANGE string1 string2": change string1 to string2 in READ filenames. */ else if( lkcharExact( "CHANGE#$",9, MCPFN, kstring,MCPFN+1, &nstring ) ){ lcchar( MCPFN, kchange,MCPFN+1, &nchange ); for(i = 0; i < cmdfm.ndfl; i++) { nstr = indexb( kstring,MCPFN+1 ); nchg = indexb( kchange,MCPFN+1 ); strtemp1 = malloc(nstr+1); strtemp2 = malloc(nchg+1); strncpy(strtemp1,kstring,nstr); strncpy(strtemp2,kchange,nchg); strtemp1[nstr] = '\0'; strtemp2[nchg] = '\0'; strtemp3 = string_list_get(datafiles, i); changestring( strtemp1, nstr+1, strtemp2, nchg+1, strtemp3, strlen(strtemp3)+2, kfile,MCPFN+1 ); free(strtemp1); free(strtemp2); string_list_put(files, kfile, MCPFN+1); if( *nerr != 0 ) goto L_8888; } cmdfm.lovrrq = FALSE; lexpnd = TRUE; } /* -- "DIR ON|OFF|CURRENT|name": set the name of the default subdirectory. */ else if( lkcharExact( "DIR#$",6, MCPFN, kmdfm.kwrdir,MCPFN+1, &nchar ) ){ modcase( TRUE, kmdfm.kwrdir, MCPW, ktemp ); if( strncmp(ktemp,"OFF ",8) == 0 ) { lwrdir = FALSE; } else if( strncmp(ktemp,"CURRENT ",8) == 0 ){ lwrdir = TRUE; fstrncpy( kmdfm.kwrdir, MCPFN, " ", 1); } else if( kmdfm.kwrdir[nchar - 1] != KDIRDL ){ /* If the string is mising the "/" path separator */ lwrdir = TRUE; delimiter[0] = KDIRDL; delimiter[1] = '\0'; subscpy( kmdfm.kwrdir, nchar, -1, MCPFN, delimiter ); } else { /* Path is not OFF, CURRENT and has the "/" at the end */ lwrdir = TRUE; } } /* -- "COMMIT|RECALLTRACE|ROLLBACK": how to treat existing data */ else if ( lckeyExact ( "COMMIT" , 7 ) ) cmdfm.icomORroll = COMMIT ; else if (lckeyExact ( "RECALLTRACE" , 12 ) ) cmdfm.icomORroll = RECALL ; else if ( lckeyExact ( "RECALL" , 7 ) ) cmdfm.icomORroll = RECALL ; else if ( lckeyExact ( "ROLLBACK" , 9 ) ) cmdfm.icomORroll = ROLLBACK ; /* -- "filelist": write files using names in new filelist. */ else if( ( list = lcdfl() ) ){ cmdfm.lovrrq = FALSE; lexpnd = FALSE; } /* -- Bad syntax. */ else{ cfmt( "ILLEGAL OPTION:",17 ); cresp(); } } /* end while ( lcmore( nerr ) ) */ /* - The above loop is over when one of two conditions has been met: * (1) An error in parsing has occurred. In this case NERR is > 0 . * (2) All the tokens in the command have been successfully parsed. */ if( *nerr != 0 ) goto L_8888; /* CHECKING PHASE: */ if(!list) { list = files; } else { /* List + Modifiers :: Use List */ string_list_free(files); files = NULL; } /* - Check for null write filelist. */ if( string_list_length(list) <= 0 ){ *nerr = 1311; setmsg( "ERROR", *nerr ); goto L_8888; } /* - Make sure the write filelist has as many entries as read filelist. */ if( string_list_length(list) != cmdfm.ndfl ){ *nerr = 1312; error(1312, "%d %d", string_list_length(list), cmdfm.ndfl); goto L_8888; } /* EXECUTION PHASE: */ /* - Commit or rollback data according to cmdfm.icomORroll */ alignFiles ( nerr ) ; if ( *nerr ) return ; /* - Echo expanded filelist if requested. */ if( cmdfm.lechof && lexpnd ){ setmsg( "OUTPUT", 0 ); for(i = 0; i < string_list_length(list); i++) { file = string_list_get(list, i); getdir( file, strlen(file)+1, kcdir,9, kfile,MCPFN+1 ); /* -- Echo the filename part if there is no directory part. */ if( strcmp(kcdir," ") == 0 ) apcmsg( kfile,MCPFN+1 ); /* -- Prepend the filename part with some special characters if * directory part is same as that of the previous file. */ else if( memcmp(kcdir,kpdir,min(strlen(kcdir),strlen(kpdir))) == 0 ){ cattemp = malloc(3+strlen(kfile)+1); strcpy(cattemp, "..."); strcat(cattemp,kfile); apcmsg( cattemp, 3+strlen(kfile)+1 ); free(cattemp); } /* -- Echo complete pathname if directory part is different. */ else{ apcmsg2(file, strlen(file)+1); strcpy( kpdir, kcdir ); } } wrtmsg( MUNOUT ); } /* - Write each file in memory to disk. */ nwrdir = indexb( kmdfm.kwrdir,MCPFN+1 ); for( jdfl = 1; jdfl <= cmdfm.ndfl; jdfl++ ){ /* -- Get file from memory manager. */ file = string_list_get(list, jdfl-1); getfil( jdfl, TRUE, &nlen, &ndx1, &ndx2, nerr ); if( *nerr != 0 ) goto L_8888; /* isolate file name */ file = string_list_get(list, jdfl-1); /* -- Check overwrite-protect flag in header record. */ if( cmdfm.lovrrq && !*lovrok ){ *nerr = 1303; setmsg( "ERROR", *nerr ); apcmsg2(file, strlen(file)+1); outmsg () ; clrmsg () ; goto L_8888; } /* -- Prepare output file name: * --- If directory option is ON (lwrdir=.TRUE. and nwrdir>0), * concatenate directory name with file name part of write file list. * --- If directory option is CURRENT (lwrdir=.TRUE. and nwrdir=0), * use file name part of write file list. * --- If directory option is OFF, use write file list. */ if( lwrdir ){ if( nwrdir > 0 ){ fstrncpy( kfile, MCPFN, kmdfm.kwrdir,min(nwrdir,MCPFN)); strtemp1 = file; strtemp2 = malloc(130-(nwrdir+1)); strncpy(strtemp2,kfile+nwrdir,MCPFN+1-(nwrdir + 1)); strtemp2[MCPFN+1-(nwrdir+1)] = '\0'; getdir( strtemp1, strlen(strtemp1)+1, kdirpart, MCPFN+1, strtemp2,-(nwrdir+1)+130); subscpy(kfile,nwrdir,-1,MCPFN,strtemp2); free(strtemp2); } else{ fstrncpy( kfile, MCPFN, " ", 1); getdir( file, strlen(file)+1, kdirpart,MCPFN+1, kfile,MCPFN+1 ); } } else { fstrncpy( kfile, MCPFN, file, strlen(file)); } /* -- Write file in appropriate format. */ if( cmdfm.iwfmt == 2 ) wrci( jdfl, kfile,MCPFN+1, "%#15.7g", nerr ); else if( cmdfm.iwfmt == 3 ) wrsdd( jdfl, kfile,MCPFN+1, TRUE, nerr ); else if( cmdfm.iwfmt == 4 ) wrxdr( jdfl, kfile,MCPFN+1, TRUE, nerr ); else if( cmdfm.iwfmt == 5 ) wrsegy( jdfl , kfile , nerr ) ; else wrsac( jdfl, kfile,MCPFN+1, TRUE, nerr ); if( *nerr != 0 ) goto L_8888; } /* end for ( jdfl ) */ L_8888: return; }
/** * Get an enumerated header value from the current SAC file * * @param kname * Name of the header field to get * @param kvalue * Value of heade field from the current SAC data file * Each value represents a specific condition * @param nerr * Error Return Flag * - 0 on Success * - ERROR_UNDEFINED_HEADER_FIELD_VALUE * - 1337 * @param kname_s * Length of \p kname * @param kvalue_s * Length of \p kvalye * * @date 870902: Original version. * */ void getihv(char *kname, char *kvalue, int *nerr, int kname_s, int kvalue_s) { char ktest[9]; int index, ivalue, ntest; char *kname_c; int callFromC = 0; if(kname_s < 0) { callFromC = 1; } kname_c = fstrdup(kname, kname_s); kname_s = strlen(kname_c) + 1; *nerr = 0; /* - Convert input name to uppercase and * check versus list of legal names. */ ntest = min( indexb( kname_c,kname_s ), SAC_HEADER_STRING_LENGTH_FILE ); strcpy( ktest, " " ); modcase( TRUE, kname_c, ntest, ktest ); index = nequal( ktest, (char*)kmlhf.kihdr,9, SAC_HEADER_ENUMS ); /* - If legal name, return current value. * Otherwise, set error condition. */ if( index > 0 ){ ivalue = Ihdr[index]; if( ivalue == cmhdr.iundef ){ fstrncpy( kvalue, kvalue_s-1, "UNDEFINED", 9); *nerr = ERROR_UNDEFINED_HEADER_FIELD_VALUE; } else{ fstrncpy( kvalue, kvalue_s-1, kmlhf.kiv[ivalue - 1], strlen(kmlhf.kiv[ivalue - 1]) ); } } else{ fstrncpy( kvalue, kvalue_s-1, "ILLEGAL", 7); *nerr = 1337; } /* - Create error message and write to terminal. */ if( *nerr != 0 ){ setmsg( "WARNING", *nerr ); apcmsg( kname_c,kname_s ); outmsg(); clrmsg(); } if(callFromC) { /* C String Termination */ kvalue[ max(0,min(kvalue_s,8))] = 0; } else { /* Fortran String Non-Termination by Spaces */ if(kvalue_s > 8) { memset(kvalue + 8, ' ', kvalue_s - 8); } } free(kname_c); return; }
/** * Execute the command LISTHDR (LH) which lists header values * * @param nerr * Error Return Flag * - 0 on Success * * @date 970425: Fix bug so display fits in the window. maf * @date 970129: Print file number (jdfl). maf * @date 961212: All of the header variables are now in the default list. * Added INCLUSIVE option to show headers whether they are * defined or not. maf * @date 900507: Fixed bug with an odd number of items being listed with * the two-column output option. (VAX/VMS bug fix.) * @date 890104: Now sending output to message handling system. * @date 860930: Added a wait mechanism after each full screen. * @date 841026: Extensive modifications made to entire subroutine. * @date 820806: Changed to newest set of parsing and checking functions. * Updated line formatting using F77 character constructs. * @date 820119: Fixed bug in listing KHDR values. * @date 811029: Changed floating point output to G8.1 format. * @date 810528: Added option to list only first file in dfl. * @date 810223: Added check for null data file list. * @date 810120: Changed to output message retrieval from disk. * */ void xlh(int *nerr) { char kerase[41], kline[MCMSG+1], kresp[9], krpttx[MRPT][41], ktok[9], kwait[9]; int lwait; int j, j_, jdfl, jrpt, jrpt_, jrpttx, jrpttx_, jsprpt, junk1, junk2, junk3, nc1, nc2, nc3, nc4, nctx[MRPT], nctxm, nferr, nlscrn, nlw, nrpttx, ntused; static int iform = 1; static char kblank[41] = " "; char *cattemp; char *strtemp1, *strtemp2, *strtemp3, *strtemp4, *strtemp5; int idx, ldef ; char *tmp; int *const Nctx = &nctx[0] - 1; *nerr = 0; ldef = FALSE; for( idx = 0 ; idx < 8 ; idx++ ) ktok[idx] = ' ' ; ktok[ 8 ] = '\0' ; /* currently executing listhdr command. maf 961212 */ cmhdr.llh = TRUE ; for( idx = 0 ; idx < MCMSG ; idx++ ) kline[ idx ] = ' ' ; kline[ MCMSG ] = '\0' ; jsprpt = 0; /* - Loop on each token in command: */ while ( lcmore( nerr ) ){ /* -- "DEFAULT/PICKS/SPECIAL": change type of header report. */ if( lclist( (char*)kmlhf.krpttp,9, cmlhf.nrpttp, &cmlhf.irpttp ) ){ if( cmlhf.irpttp == 1 || cmlhf.irpttp == 4 ){ for( j = 1; j <= cmlhf.nstrpt; j++ ){ j_ = j - 1; strcpy( kmlhf.krpt[j_], kmlhf.kstrpt[j_] ); } cmlhf.nrpt = cmlhf.nstrpt; } else if( cmlhf.irpttp == 2 ){ for( j = 1; j <= cmlhf.npkrpt; j++ ){ j_ = j - 1; strcpy( kmlhf.krpt[j_], kmlhf.kpkrpt[j_] ); } cmlhf.nrpt = cmlhf.npkrpt; } else if( cmlhf.irpttp == 3 ){ for( j = 1; j <= cmlhf.nsprpt; j++ ){ j_ = j - 1; strcpy( kmlhf.krpt[j_], kmlhf.ksprpt[j_] ); } cmlhf.nrpt = cmlhf.nsprpt; } } /* -- "FILES ALL/nlist": print all headers or only a subset. */ else if( lckey( "FILES#$",8 ) ){ if( lckey( "ALL$",5 ) ){ cmlhf.lstall = TRUE; } else if( lckey( "NONE$",6 ) ){ ldef = TRUE; } else if( lcia( 1, cmdfm.ndfl, cmlhf.ilhlst, &cmlhf.nlhlst ) ){ cmlhf.lstall = FALSE; } } /* -- "INCLUSIVE": print headers even if they are undefined.*/ else if ( lklog( "INC#LUSIVE$", 12, &cmhdr.linc ) ) { /* do nothing */ } /* -- "COLUMNS n": change number of output columns. */ else if( lkirc( "COLUMNS#$",10, 1, 2, &cmlhf.nlhcol ) ) { /* do nothing */ } /* -- "FIRST": Obsolete keyword for first file only. */ else if( lckey( "FIRST#$",8 ) ){ cmlhf.lstall = FALSE; cmlhf.nlhlst = 1; Ilhlst[1] = 1; } else if( lcchar( MCPW, ktok,9, &ntused ) ){ if( jsprpt < MSPRPT ){ jsprpt = jsprpt + 1; strcpy( kmlhf.ksprpt[jsprpt - 1], ktok ); cmlhf.nrpt = jsprpt; strcpy( kmlhf.krpt[cmlhf.nrpt - 1], ktok ); } else{ *nerr = 1309; setmsg( "ERROR", *nerr ); apimsg( jsprpt ); } } else{ /* -- Bad syntax. */ cfmt( "ILLEGAL OPTION:",17 ); cresp(); } } if( *nerr != 0 ) { /* no longer executing xlh() */ cmhdr.llh = FALSE ; return; } /* - Save length of special report if needed. */ if( jsprpt > 0 ) cmlhf.nsprpt = jsprpt; if( ldef ) { /* no longer executing xlh(). */ cmhdr.llh = FALSE; return; } /* CHECKING PHASE: */ /* - Check for null data file list. */ vflist( nerr ); if( *nerr != 0 ) { /* no longer executing xlh().*/ cmhdr.llh = FALSE ; return; } /* EXECUTION PHASE: */ /* - Get screen attributes (number of lines per screen and * text to send to erase screen, if any.) */ getalphainfo( &nlscrn, kerase,41 ); if( nlscrn <= 0 ) nlscrn = 23; if( cmlhf.lstall ){ setinputmode( "ALL" ); } else{ setinputmode( "SELECT" ); selectinputfiles( cmlhf.ilhlst, cmlhf.nlhlst ); } nlw = 0; gettextwait( kwait,9 ); lwait = memcmp(kwait,"ON",2) == 0; autooutmsg( TRUE ); setmsg( "OUTPUT", 99 ); if(!use_tty()) { lwait = FALSE; } jdfl = 0; L_4000: if( nextinputfile( &jdfl ) ){ getfil( jdfl, FALSE, &junk1, &junk2, &junk3, nerr ); if( *nerr != 0 ) { autooutmsg( FALSE ); /* no longer executing xlh(). */ cmhdr.llh = FALSE ; return ; } if((tmp = string_list_get(datafiles, jdfl-1))) { aplmsg( " ",2 ); cattemp = malloc(7+strlen(tmp)+7); sprintf(cattemp, " FILE: %s - %d", tmp, jdfl); aplmsg( cattemp, strlen ( cattemp ) + 1 ); free(cattemp); memset(kline,'-',strlen(tmp)+6); kline[strlen(tmp)+6]='\n'; kline[strlen(tmp)+7]='\0'; aplmsg( kline,MCMSG+1 ); nlw = nlw + 4; } nrpttx = 0; nctxm = 0; for( jrpt = 1; jrpt <= cmlhf.nrpt; jrpt++ ){ jrpt_ = jrpt - 1; nrpttx = nrpttx + 1; formhv( (char*)kmlhf.krpt[jrpt_],9, iform, (char*)krpttx[nrpttx - 1], 41, &nferr ); if( nferr == 0 ){ Nctx[nrpttx] = indexc((char*)krpttx[nrpttx - 1], 41, '=' ); nctxm = max( nctxm, Nctx[nrpttx] ); } else if ( !cmhdr.linc ) { nrpttx = nrpttx - 1; } } if( cmlhf.nlhcol == 1 ){ for( jrpttx = 1; jrpttx <= nrpttx; jrpttx++ ){ jrpttx_ = jrpttx - 1; nc1 = 2 + nctxm - Nctx[jrpttx]; nc2 = indexb( (char*)krpttx[jrpttx_],41 ); strtemp1 = malloc(nc1+1); strtemp2 = malloc(nc2+1); strncpy(strtemp1,kblank,nc1); strncpy(strtemp2,krpttx[jrpttx_],nc2); strtemp1[nc1] = '\0'; strtemp2[nc2] = '\0'; sprintf(kline," %s %s",strtemp1,strtemp2); free(strtemp1); free(strtemp2); aplmsg( kline,MCMSG+1 ); nlw = nlw + 1; if( lwait && (nlw >= (nlscrn - 2)) ){ outmsg(); clrmsg(); setmsg( "OUTPUT", 99 ); zgpmsg( "Waiting $",10, kresp,9 ); upcase( kresp, 1, kresp,9 ); nlw = 0; if( kresp[0] == 'K' || kresp[0] == 'Q' ) { autooutmsg( FALSE ); /* no longer executing xlh(). */ cmhdr.llh = FALSE ; return ; } else if( kresp[0] == 'G' ){ if( strcmp(kerase," ") != 0 ) { fprintf(MUNOUT," %s\n",kerase); } lwait = FALSE; } else if( kresp[0] == 'N' ){ if( strcmp(kerase," ") != 0 ) { fprintf(MUNOUT," %s\n",kerase); } goto L_4000; } } } } else { strcpy( krpttx[nrpttx], " " ); for( jrpttx = 1; jrpttx <= nrpttx; jrpttx += 2 ){ jrpttx_ = jrpttx - 1; nc1 = 2 + nctxm - Nctx[jrpttx]; nc2 = indexb( (char*)krpttx[jrpttx_],41 ); nc3 = 2 + nctxm - Nctx[jrpttx + 1]; nc4 = indexb( (char*)krpttx[jrpttx_ + 1],41 ); if( nc4 > 0 ){ strtemp1 = malloc(nc1+1); strtemp2 = malloc(nc2+1); strtemp3 = malloc(nc3+1); strtemp4 = malloc(nc4+1); strncpy(strtemp1,kblank,nc1); strtemp1[nc1] = '\0'; strncpy(strtemp2,krpttx[jrpttx_],nc2); strtemp2[nc2] = '\0'; strncpy(strtemp3,kblank,nc3); strtemp3[nc3] = '\0'; strncpy(strtemp4,krpttx[jrpttx_ + 1],nc4); strtemp4[nc4] = '\0'; if ((nc1+nc2) < 40 ) { strtemp5 = malloc(40-(nc1+nc2)+1); memset(strtemp5,' ',40-(nc1+nc2)); strtemp5[40-(nc1+nc2)] = '\0'; sprintf(kline," %s%s%s%s%s", strtemp1,strtemp2,strtemp5,strtemp3,strtemp4); free(strtemp5); } else { sprintf(kline," %s%s%s%s", strtemp1,strtemp2,strtemp3,strtemp4); } free(strtemp1); free(strtemp2); free(strtemp3); free(strtemp4); } else{ strtemp1 = malloc(nc1+1); strtemp2 = malloc(nc2+1); strncpy(strtemp1,kblank,nc1); strtemp1[nc1] = '\0'; strncpy(strtemp2,krpttx[jrpttx_],nc2); strtemp2[nc2] = '\0'; sprintf(kline," %s%s",strtemp1,strtemp2); free(strtemp1); free(strtemp2); } aplmsg( kline,MCMSG+1 ); nlw = nlw + 1; if( lwait && (nlw >= (nlscrn - 1)) ){ outmsg(); clrmsg(); setmsg( "OUTPUT", 99 ); nlw = 0; zgpmsg( "Waiting $",10, kresp,9 ); upcase( kresp, 1, kresp,9 ); if( kresp[0] == 'K' || kresp[0] == 'Q' ) { autooutmsg( FALSE ); /* no longer executing xlh(). */ cmhdr.llh = FALSE ; return ; } else if( kresp[0] == 'G' ){ if( strcmp(kerase," ") != 0 ) { fprintf(MUNOUT," %s\n",kerase); } lwait = FALSE; } else if( kresp[0] == 'N' ){ if( strcmp(kerase," ") != 0 ) { fprintf(MUNOUT," %s\n",kerase); } goto L_4000; } } } } /* -- Loop on entries in input dfl. */ goto L_4000; } /* - Turn automatic output mode off before returning. */ autooutmsg( FALSE ); /* no longer executing xlh() */ cmhdr.llh = FALSE ; return; }
/** * Destroy a family of file names given the base name. A two (2) digit * integer is appended to the base name. * * @param kbase * Base name * @param kbase_s * Length of \p kbase * @param nerr * Error Return Flag * - 0 on Success * - ERROR_ILLEGAL_BASE_NAME * * @date 860818: Changed to new message system. * @date 810120: Changed to output message retrieval from disk. * @date 800906: Fixed bug in determining correct base name. * @date 800823: Added tree name capability [Prime]. * Allowed a lower as well as upper range to be specified. * @date 800103: Original version. * * @bug Only used by co/zquit() for destroy "ZDLF" files, which may * not exist anymore. * */ void zdestf(char *kbase, int kbase_s, int *nerr) { char kname[MCPFN+1]; int j, jdig, jten, nbase; static char kint[10]={'0','1','2','3','4','5','6','7','8','9'}; char *const Kint = &kint[0] - 1; *nerr = 0; /* - Make sure basename is legitimate. */ if( memcmp(kbase," ",1) == 0 ){ *nerr = ERROR_ILLEGAL_BASE_NAME; setmsg( "ERROR", *nerr ); apcmsg( kname,MCPFN+1 ); goto L_8888; } else{ /* - Determine number of characters in base name. */ nbase = indexb( kbase,kbase_s ); if( nbase <= 0 ){ nbase = MCPFN - 2; } else if( nbase > MCPFN - 2 ){ nbase = MCPFN - 2; } /* - Destroy files with basename staring at "01" * until an error occurs. ASSUME this error means * that there are no more files with basename. */ jten = 1; jdig = 2; for( j = 1; j <= 99; j++ ){ /* -- Create file name. */ memset(kname,(int)' ',MCPFN); kname[MCPFN] = '\0'; memcpy(kname,kbase,nbase); kname[nbase] = Kint[jten]; kname[nbase + 1] = Kint[jdig]; /* -- Try to destroy it. Return on error. * This should normally be "File does not exist." */ zdest( kname,MCPFN+1, nerr ); if( *nerr != 0 ) goto L_8888; /* -- Increment numbers appended to basename. */ if( jdig < 10 ){ jdig = jdig + 1; } else{ jten = jten + 1; jdig = 1; } } } /* - Clear error condition for "File does not exist." */ L_8888: if( *nerr == ERROR_FILE_DOES_NOT_EXIST ){ *nerr = 0; clrmsg(); } return; } /* end of function */