void main(int argc, char *argv[]) { int f; argv0 = argv[0]; bsize = SIZE; b1 = malloc(bsize); b2 = malloc(bsize); f = 0; while(argc > 1) { if(*argv[1] == '-') { if(isdigit(argv[1][1])) fields = atoi(&argv[1][1]); else mode = argv[1][1]; argc--; argv++; continue; } if(*argv[1] == '+') { letters = atoi(&argv[1][1]); argc--; argv++; continue; } f = open(argv[1], 0); if(f < 0) sysfatal("cannot open %s", argv[1]); break; } if(argc > 2) sysfatal("unexpected argument %s", argv[2]); Binit(&fin, f, OREAD); Binit(&fout, 1, OWRITE); if(gline(b1)) exits(0); for(;;) { linec++; if(gline(b2)) { pline(b1); exits(0); } if(!equal(b1, b2)) { pline(b1); linec = 0; do { linec++; if(gline(b1)) { pline(b2); exits(0); } } while(equal(b2, b1)); pline(b2); linec = 0; } } }
void bounds_line(float *X, float *Y, int nsegs, int color, int ltype, int lwidth) { static char navigate[]="M"; int lhw = 0; int whw = 0; int iret; gsline (<ype,&lhw,&lwidth,&whw,&iret); gscolr (&color,&iret); if(iret != 0) printf("iret 3 %d\n",iret); gline (navigate,&nsegs,X,Y,&iret,strlen(navigate)); }
main() { int len; char line[MAXLINE]; while((len = gline(line, MAXLINE)) > 0) { if (len > FOLD) { fold(line, len); } else { printf("%s", line); } } }
int main() { int length; char string[MAX_SIZE]; while ((length = gline(string, MAX_SIZE)) != 0) { if (length > MIN_SIZE) printf("String with length %d > %d -> %s", length, MIN_SIZE, string); if (length >= MAX_SIZE) putchar('\n'); } return 0; }
int readlines(char *lineptr[], int maxlines, char *linestore) { int len, nlines; char line[MAXLEN]; char *p = linestore; char *linestop = linestore + MAXSTORE; nlines = 0; while ((len = gline(line, MAXLEN)) > 0) if (nlines >= maxlines || p + len > linestop) return -1; else { line[len - 1] = '\0'; strcpy(p, line); lineptr[nlines++] = p; p += len; } return nlines; }
// Print longest input line main() { int len; // Current line length int max; // Maximum length seen so far char line[MAXLINE]; // Current input line char longest[MAXLINE]; // Longest line saved here max = 0; while ((len = gline(line, MAXLINE)) > 0) { if (len > max) { max = len; copy(longest, line); } } if (max > 0) { // There was a line printf("%s", longest); } return 0; }
void wgem_gline( char *sys, int *np, float *x, float *y, int *iret ) /************************************************************************ * wgem_gline * * * * This function is a wrapper for gline. * * * * void wgem_gline( sys, np, x, y, iret ) * * * * Input parameters: * * *sys char coordinate system * * *np int number of points * * *x float X coordinates / lats * * *y float Y coordinates / lons * * * * Output parameters: * * *iret int return code * ** * * Log: * * E. Safford/SAIC 11/07 initial coding * ***********************************************************************/ { gline( sys, np, x, y, iret, strlen( sys ) ); }
void render_layer(int clayer, float alpha) { char *s = layer[clayer].index; char *e = layer[clayer].index + layer[clayer].size; float G = NAN, X = NAN, Y = NAN, E = NAN, Z = NAN, lastX = NAN, lastY = NAN, lastE = NAN; uint32_t seen = 0; for (X = 0; X < 201.0; X += 10.0) { gline(X, 0, X, 200, ((((int) X) % 50) == 0)?1:0.2, 0, 0, 0, 16); gline(0, X, 200, X, ((((int) X) % 50) == 0)?1:0.2, 0, 0, 0, 16); } //printf("render layer %d (%g)\n", clayer + 1, alpha); lastX = layer[clayer].startX; lastY = layer[clayer].startY; Z = layer[clayer].height; lastE = layer[clayer].startE; while (s < e) { seen = scanline(s, e - s, linewords, &s, LMASK('G') | LMASK('X') | LMASK('Y') | LMASK('Z') | LMASK('E')); if (SEEN('G') && (LW('G') == 0.0 || LW('G') == 1.0)) { G = LW('G'); if (SEEN('X')) X = LW('X'); if (SEEN('Y')) Y = LW('Y'); if (SEEN('Z')) Z = LW('Z'); if (SEEN('E')) E = LW('E'); //if (clayer == 2) // printf("SEEN %c%c%c%c X%g Y%g Z%g E%g\n", SEEN('X')?'X':' ', SEEN('Y')?'Y':' ', SEEN('Z')?'Z':' ', SEEN('E')?'E':' ', X, Y, Z, E); if (SEEN('X') || SEEN('Y')) { // draw uint8_t r = 0, g = 0, b = 0, a = 160; if (SEEN('E')) { r = 0; g = 0; b = 0; a = 224; } else if (Z > layer[clayer].height) { r = 224; g = 64; b = 64; a = 160; } else if (Z < layer[clayer].height) { r = 128; g = 0; b = 128; a = 160; } else { r = 0; g = 128; b = 64; a = 160; } if ((lastX != X || lastY != Y) && !isnan(X) && !isnan(Y) && lastX <= 200.0) gline(lastX, lastY, X, Y, extrusionWidth, r, g, b, a * alpha); } if (SEEN('X')) lastX = X; if (SEEN('Y')) lastY = Y; if (SEEN('E')) lastE = E; } } }
void Meta::replay (void *ps, int clip) /* Redraw the graphics as noted in notespace */ { Active=0; char *p=Start; double c,r,c1,r1,cc[16],hue; int col,st,width,n,i,co[16]; while (p<End) { int command=nextcommand(p); switch(command) { case 1 : gclear(p); break; case 2 : c=nextlong(p); r=nextlong(p); c1=nextlong(p); r1=nextlong(p); if (clip) gclip(ps,c,r,c1,r1); break; case 10 : c=nextlong(p); r=nextlong(p); c1=nextlong(p); r1=nextlong(p); col=nextint(p); st=nextint(p); width=nextint(p); gline(ps,c,r,c1,r1,col,st,width); break; case 20 : c=nextlong(p); r=nextlong(p); col=nextint(p); st=nextint(p); gmarker(ps,c,r,col,st); break; case 30 : n=nextint(p); for (i=0; i<n; i++) { cc[2*i]=nextlong(p); cc[2*i+1]=nextlong(p); co[i]=nextint(p); } st=nextint(p); gfill(ps,cc,st,n,co); break; case 31 : for (i=0; i<8; i++) cc[i]=nextlong(p); hue=nextlong(p); col=nextint(p); st=nextint(p); gfillh(ps,cc,hue,col,st); break; case 32 : c=nextlong(p); r=nextlong(p); c1=nextlong(p); r1=nextlong(p); hue=nextlong(p); col=nextint(p); st=nextint(p); gbar(ps,c,r,c1,r1,hue,col,st); break; case 33 : c=nextlong(p); r=nextlong(p); c1=nextlong(p); r1=nextlong(p); col=nextint(p); st=nextint(p); gbar1(ps,c,r,c1,r1,col,st); break; case 40 : c=nextlong(p); r=nextlong(p); col=nextint(p); st=nextint(p); gtext(ps,c,r,p,col,st); p+=strlen(p)+1; break; case 41 : c=nextlong(p); r=nextlong(p); col=nextint(p); st=nextint(p); gvtext(ps,c,r,p,col,st); p+=strlen(p)+1; break; case 42 : c=nextlong(p); r=nextlong(p); col=nextint(p); st=nextint(p); gvutext(ps,c,r,p,col,st); p+=strlen(p)+1; break; case 50 : nextlong(p); break; default : Active=1; return; } } Active=1; }
// -- Compresses low color pixmap. void cpaldjvu(ByteStream *ibs, GURL &urlout, const cpaldjvuopts &opts) { GP<GPixmap> ginput=GPixmap::create(*ibs); int w = ginput->columns(); int h = ginput->rows(); int dpi = MAX(200, MIN(900, opts.dpi)); int largesize = MIN(500, MAX(64, dpi)); int smallsize = MAX(2, dpi/150); // Compute optimal palette and quantize input pixmap GP<DjVuPalette> gpal=DjVuPalette::create(); DjVuPalette &pal=*gpal; GPixel bgcolor; int bgindex = -1; if (! opts.bgwhite) { bgindex = pal.compute_pixmap_palette(*ginput, opts.ncolors); pal.index_to_color(bgindex, bgcolor); } else { bgcolor = GPixel::WHITE; pal.histogram_clear(); for (int j=0; j<h; j++) { const GPixel *p = (*ginput)[j]; for (int i=0; i<w; i++) if (p[i] != GPixel::WHITE) pal.histogram_add(p[i], 1); } pal.compute_palette(opts.ncolors); } if (opts.verbose) DjVuFormatErrorUTF8( "%s\t%d\t%d\t%d", ERR_MSG("cpaldjvu.quantizied"), w, h, pal.size()); if (opts.verbose && !opts.bgwhite) DjVuPrintErrorUTF8("cpaldjvu: background color is #%02x%02x%02x.\n", bgcolor.r, bgcolor.g, bgcolor.b); // Fill CCImage with color runs int xruncount=0,yruncount=0; CCImage rimg(w, h); int *line; GPBuffer<int> gline(line,w); int *prevline; GPBuffer<int> gprevline(prevline,w); for (int x=0;x<w;x++) { prevline[x]=bgindex; } for (int y=0; y<h; y++) { int x; const GPixel *row = (*ginput)[y]; for(x=0;x<w;x++) { line[x] = pal.color_to_index(row[x]); if (opts.bgwhite && row[x]==GPixel::WHITE) line[x] = bgindex; } for(x=0;x<w;) { int x1 = x; int index = line[x++]; while (x<w && line[x]==index) { x++; } if (index != bgindex) { xruncount++; rimg.add_single_run(y, x1, x-1, index); } } for(x=0;x<w;x++) if(prevline[x] != line[x]) yruncount++; gprevline.swap(gline); } ginput = 0; //save memory if (opts.verbose) DjVuFormatErrorUTF8( "%s\t%d", ERR_MSG("cpaldjvu.color_runs"), rimg.runs.size()); // Perform Color Connected Component Analysis rimg.make_ccids_by_analysis(); // Obtain ccids rimg.make_ccs_from_ccids(); // Compute cc descriptors if (opts.verbose) DjVuFormatErrorUTF8( "%s\t%d", ERR_MSG("cpaldjvu.ccs_before"), rimg.ccs.size()); rimg.merge_and_split_ccs(smallsize,largesize); // Eliminates gross ccs if (opts.verbose) DjVuFormatErrorUTF8( "%s\t%d", ERR_MSG("cpaldjvu.ccs_after"), rimg.ccs.size()); rimg.sort_in_reading_order(); // Sort cc descriptors // Create JB2Image and fill colordata GP<JB2Image> gjimg=JB2Image::create(); JB2Image &jimg=*gjimg; jimg.set_dimension(w, h); int nccs = rimg.ccs.size(); for (int ccid=0; ccid<nccs; ccid++) { JB2Shape shape; JB2Blit blit; shape.parent = -1; shape.userdata = 0; if (ccid >= rimg.nregularccs) shape.userdata |= JB2SHAPE_SPECIAL; shape.bits = rimg.get_bitmap_for_cc(ccid); shape.bits->compress(); CC& cc = rimg.ccs[ccid]; blit.shapeno = jimg.add_shape(shape); blit.left = cc.bb.xmin; blit.bottom = cc.bb.ymin; int blitno = jimg.add_blit(blit); pal.colordata.touch(blitno); pal.colordata[blitno] = cc.color; } // Organize JB2Image tune_jb2image_lossless(&jimg); if (opts.verbose) { int nshape=0, nrefine=0; for (int i=0; i<jimg.get_shape_count(); i++) { if (!jimg.get_shape(i).bits) continue; if (jimg.get_shape(i).parent >= 0) nrefine++; nshape++; } DjVuFormatErrorUTF8( "%s\t%d\t%d", ERR_MSG("cpaldjvu.cross_code"), nshape, nrefine); } // Create background image #ifdef BACKGROUND_SUBSAMPLING_FACTOR // -- we may create the background by masking and subsampling GP<GPixmap> ginputsub=GPixmap::create(); GPixmap &inputsub=*ginputsub; GP<GBitmap> mask = jimg.get_bitmap(BACKGROUND_SUBSAMPLING_FACTOR); inputsub.downsample(&input, BACKGROUND_SUBSAMPLING_FACTOR); GP<IW44Image> iwimage=IW44Image::create(inputsub, mask); #else // -- but who cares since the background is uniform. GP<GPixmap> ginputsub=GPixmap::create((h+11)/12, (w+11)/12, &bgcolor); GPixmap &inputsub=*ginputsub; GP<IW44Image> iwimage=IW44Image::create_encode(inputsub); #endif // Assemble DJVU file GP<ByteStream> obs=ByteStream::create(urlout, "wb"); GP<IFFByteStream> giff=IFFByteStream::create(obs); IFFByteStream &iff=*giff; // -- main composite chunk iff.put_chunk("FORM:DJVU", 1); // -- ``INFO'' chunk iff.put_chunk("INFO"); GP<DjVuInfo> ginfo=DjVuInfo::create(); DjVuInfo info=*ginfo; info.height = h; info.width = w; info.dpi = opts.dpi; info.encode(*iff.get_bytestream()); iff.close_chunk(); // -- ``Sjbz'' chunk iff.put_chunk("Sjbz"); jimg.encode(iff.get_bytestream()); iff.close_chunk(); // -- ``FGbz'' chunk iff.put_chunk("FGbz"); pal.encode(iff.get_bytestream()); iff.close_chunk(); // -- ``BG44'' chunk IWEncoderParms iwparms; #ifdef PROGRESSIVE_BACKGROUND // ----- we may use several chunks to enable progressive rendering ... iff.put_chunk("BG44"); iwparms.slices = 74; iwimage->encode_chunk(iff, iwparms); iff.close_chunk(); iff.put_chunk("BG44"); iwparms.slices = 87; iwimage->encode_chunk(iff, iwparms); iff.close_chunk(); #endif // ----- but who cares when the background is so small. iff.put_chunk("BG44"); iwparms.slices = 97; iwimage->encode_chunk(iff.get_bytestream(), iwparms); iff.close_chunk(); // -- terminate main composite chunk iff.close_chunk(); // Finished! }
void cds_ccf ( VG_DBStruct *el, int indx, int *iret ) /************************************************************************ * cds_ccf * * * * This function displays CCFs to the output device. * * * * cds_ccf (el, indx, iret) * * * * Input parameters: * * *el VG_DBStruct Pointer to VG record structure * * indx int Index into user attribute table * * * * Output parameters: * * *iret int Return code * * * ** * * Log: * * D.W.Plummer/NCEP 7/99 Copied from cds_sig * * S. Law/GSC 02/00 added smoothing * * S. Law/GSC 05/00 added fill, moved color setting to pgen * * A. Hardy/GSC 11/00 renamed output coord. system declaration* * J. Wu/GSC 02/01 Modified 'unused1' in VG to 'smooth' * * D.W.Plummer/NCEP 5/01 Added check for cdsColor * * M. Li/SAIC 01/03 delete vgstruct.h * * H. Zeng/SAIC 02/05 assigned iftyp with a new value * * L. Hinson/AWC 07/09 Add Setting/Uattrib tbl functionality * * Add Connector, if needed, from text box * * to polygon. Add motion vector/speed * * L. Hinson/AWC 02/10 Fix uninitialized 'ifilled' on Lines * ***********************************************************************/ { int ii, np, ier, istyp, width, lintyp, lthw, lwhw; int iltypx, ilthwx, iwidthx, iwhwx, icolrx, iftypx; int ifilled, iftyp; float szfilx, szfil, lat[MAX_SIGMET], lon[MAX_SIGMET]; int idx; VG_DBStruct el_tmp; CCFType *pccf; int npts, npls, *inout; float *xpt, *ypt, *xpl, *ypl; float areadir, areaspd, xcent, ycent, minangle, V1x, V1y, V2u, V2v; float angle, latmv[2], lonmv[2]; int i, motionvertexnum, foundmotionvertex; char textLayoutStr[256]; Boolean textLayoutNIL = False; /*---------------------------------------------------------------------*/ *iret = 0; /* * Save plot attributes. */ gqcolr (&icolrx, &ier); gqline (&iltypx, &ilthwx, &iwidthx, &iwhwx, &ier); gqfill (&szfilx, &iftypx, &ier); /* * setup basic information */ lintyp = 1; lthw = 0; width = 3; lwhw = 0; gsline (&lintyp, <hw, &width, &lwhw, &ier); pccf = &(el->elem.ccf); np = pccf->info.npts; /* * Set the color for the feature. */ if (cdsColor == 0) { if ( cdsUattr[indx].maj_col == 0 ) { if (pccf->info.prob == (CCFLVL_HIGH + 1)) { /*1 = High, 2= Low */ gscolr ( &(el->hdr.maj_col), &ier); } else { gscolr ( &(el->hdr.min_col), &ier); } } else { /* Use the Uattrib table */ if (pccf->info.prob == (CCFLVL_HIGH + 1)) { gscolr ( &cdsUattr[indx].maj_col, &ier); el->hdr.maj_col = cdsUattr[indx].maj_col; /* Colors everything else */ } else { gscolr ( &cdsUattr[indx].min_col, &ier); el->hdr.maj_col = cdsUattr[indx].min_col; /* Colors everything else */ } } } else { gscolr ( &cdsColor, &ier); } /* * Set the smoothing level_tmp */ ii = (cdsUattr[indx].smooth == -1) ? (int) el->hdr.smooth : cdsUattr[indx].smooth; istyp = (ii == 0) ? 0 : 2; gssmth (&istyp, &cdsSmthDens[ii], &ier); /* * If fill is set, fill the polygon. */ ifilled=0; if (cdsUattr[indx].filled == 0) { ifilled = (int) el->hdr.filled; } else { if (pccf->info.subtype == SIGTYP_AREA) { if (pccf->info.cover == CCFLVL_HIGH + 1) { ifilled = cdsUattr[indx].info.ccf->fillhi; } if (pccf->info.cover == CCFLVL_MEDIUM + 1) { ifilled = cdsUattr[indx].info.ccf->fillmed; } if (pccf->info.cover == CCFLVL_LOW + 1) { ifilled = cdsUattr[indx].info.ccf->filllow; } } } if (ifilled >= 1 && cdsFill == 1) { iftyp = ifilled; szfil = 1.0F; gsfill (&szfil, &iftyp, &ier); gfill (sys_M, &np, pccf->latlon, &(pccf->latlon[np]), &ier, strlen (sys_M)); iftyp = 1; gsfill (&szfil, &iftyp, &ier); } if (cdsUattr[indx].info.ccf->linetype == 0) { lintyp = el->elem.ccf.info.linetype; } else { lintyp = cdsUattr[indx].info.ccf->linetype; } switch (pccf->info.subtype) { case SIGTYP_LINE_HIGH: /* line */ gsline (&lintyp, <hw, &width, &lwhw, &ier); for (ii = 0; ii < np; ii++) { lat[ii] = pccf->latlon[ii]; lon[ii] = pccf->latlon[ii+np]; } gline (sys_M, &np, lat, lon, &ier, strlen (sys_M)); break; case SIGTYP_LINE_MED: /* line */ gsline (&lintyp, <hw, &width, &lwhw, &ier); for (ii = 0; ii < np; ii++) { lat[ii] = pccf->latlon[ii]; lon[ii] = pccf->latlon[ii+np]; } gline (sys_M, &np, lat, lon, &ier, strlen (sys_M)); break; case SIGTYP_AREA: /* area */ gsline (&lintyp, <hw, &width, &lwhw, &ier); for ( ii = 0; ii < np; ii++ ) { lat[ii] = pccf->latlon[ii]; lon[ii] = pccf->latlon[ii+np]; } lat[np] = pccf->latlon[0]; lon[np] = pccf->latlon[np]; np++; gline (sys_M, &np, lat, lon, &ier, strlen (sys_M)); break; } /* Check to see if textLayoutString for CCF Text contains NIL */ /* If so, set the variable textLayoutNIL to TRUE. */ if ( cdsUattr[indx].info.ccf->textLayout[0] == '\0' ) { strcpy(textLayoutStr, el->elem.ccf.textLayout); } else { strcpy(textLayoutStr, cdsUattr[indx].info.ccf->textLayout); } if (strstr(textLayoutStr, "NIL") != NULL) { textLayoutNIL = True; } /* * Reset smooth level to 0 */ if (istyp > 0) { istyp = 0; gssmth (&istyp, &cdsSmthDens[0], &ier); } /* * Restore the saved plot attribute values */ gsline ( &iltypx, &ilthwx, &iwidthx, &iwhwx, &ier ); gscolr ( &icolrx, &ier ); gsfill (&szfilx, &iftypx, &ier); if (! (pccf->info.subtype == SIGTYP_LINE_HIGH || pccf->info.subtype == SIGTYP_LINE_MED)) { /* Create an arrow if the text box is outside the CCF polygon*/ cds_getinx( el, &idx, &ier); /* Get the idx to the arrow size */ npts = 1; G_MALLOC( xpt, float, npts, "cds_ccf: xpt" ); G_MALLOC( ypt, float, npts, "cds_ccf: ypt" ); G_MALLOC( inout, int, npts, "cds_ccf: inout" ); xpt[0] = el->elem.ccf.info.textlat; ypt[0] = el->elem.ccf.info.textlon; npls = el->elem.ccf.info.npts; G_MALLOC( xpl, float, npls, "cds_ccf: xpl" ); G_MALLOC( ypl, float, npls, "cds_ccf: ypl" ); for ( ii = 0; ii < npls; ii++ ) { xpl[ii] = el->elem.ccf.latlon[ii]; ypl[ii] = el->elem.ccf.latlon[ii+npls]; } cgr_inpoly ( sys_M, &npts, xpt, ypt, sys_M, &npls, xpl, ypl, inout, &ier ); /* * If the center of the text box is outside of GFA polygon, and TextLayoutNIL * not set display an arrowed line. */ if ( inout[0] == 0 && textLayoutNIL == False) { el_tmp.hdr.delete = 0; el_tmp.hdr.vg_type = SPLN_ELM; el_tmp.hdr.vg_class = (char)CLASS_LINES; el_tmp.hdr.filled = 0; el_tmp.hdr.closed = 0; el_tmp.hdr.smooth = 0; el_tmp.hdr.version = 0; el_tmp.hdr.grptyp = 0; el_tmp.hdr.grpnum = 0; el_tmp.hdr.maj_col = el->hdr.maj_col; el_tmp.hdr.min_col = el->hdr.min_col; el_tmp.hdr.recsz = 0; el_tmp.hdr.range_min_lat = 0; el_tmp.hdr.range_min_lon = 0; el_tmp.hdr.range_max_lat = 0; el_tmp.hdr.range_max_lon = 0; el_tmp.elem.spl.info.numpts = 2; el_tmp.elem.spl.info.spltyp = 4; el_tmp.elem.spl.info.splstr = 0.5; el_tmp.elem.spl.info.spldir = 1; el_tmp.elem.spl.info.splsiz = 1.0; el_tmp.elem.spl.info.splsiz = el->elem.ccf.info.szarrow; /* Set the Arrow Size from the settings table... */ if ( fabs (cdsUattr[idx].info.ccf->szarrow < 0.01) ) { el_tmp.elem.spl.info.splsiz = el->elem.ccf.info.szarrow; } else { el_tmp.elem.spl.info.splsiz = cdsUattr[idx].info.ccf->szarrow; } el_tmp.elem.spl.latlon[0] = el->elem.ccf.info.textlat; el_tmp.elem.spl.latlon[1] = el->elem.ccf.info.arrowlat; el_tmp.elem.spl.latlon[2] = el->elem.ccf.info.textlon; el_tmp.elem.spl.latlon[3] = el->elem.ccf.info.arrowlon; el_tmp.elem.spl.info.splwid = 3; el_tmp.hdr.maj_col = el_tmp.hdr.min_col = 31; cds_dspelm(&el_tmp, &ier); el_tmp.elem.spl.info.splwid = 1; el_tmp.hdr.maj_col = el_tmp.hdr.min_col = 32; cds_dspelm(&el_tmp, &ier); }
int main(int argc, char ** argv) { char * fn; int ix; if (3 > argc) return fprintf(stderr, "Specify library file name and copy file name(s).\n"), 1; if (openout(argv[1])) return 16; if (getdir(cards * 80)) return 20; for (ix = 2; argv[ix]; ix++) { char * dot; char * slash; char * name; int namelen; int ismacro = 1; /* Assume file is macro */ char * s; fn = argv[ix]; f = fopen(fn, "r"); if (!f) return fprintf(stderr, "Cannot open %s: %s\n", fn, strerror(errno)), 16; slash = strrchr(fn, '/'); name = slash ? slash + 1 : fn; namelen = strlen(name); dot = strrchr(name, '.'); if (dot) { namelen = dot - name; if (!strcmp(dot + 1, "copy")) ismacro = 0; } s = gline(); if (!s) continue; if (!ismacro && memcmp(s, "*COPY ", 6)) ismacro = 1; /* Not stacked copy */ if (ismacro) { loadname(name, namelen); if (doline(line)) return 20; } else if (newmember(s)) return 20; for (;;) { s = gline(); if (!s) break; if (!ismacro && !memcmp(s, "*COPY ", 6)) { if (eom()) return 20; if (newmember(s)) return 20; continue; } if (doline(line)) return 20; } if (eom()) return 20; } if (wrapup(dirs, dir)) return 16; printf("%s %d files %d members.\n", fno, ix - 2, members); return 0; }
void execute(uchar *file) { uchar *p1, *p2; union reptr *ipc; int c; long l; uchar *execp; if (file) { if ((f = open((char*)file, O_RDONLY)) < 0) { fprintf(stderr, "sed: Can't open %s\n", file); } } else f = 0; ebp = ibuf; cbp = ibuf; if(pending) { ipc = pending; pending = 0; goto yes; } for(;;) { if((execp = gline(linebuf)) == badp) { close(f); return; } spend = execp; for(ipc = ptrspace; ipc->r1.command; ) { p1 = ipc->r1.ad1; p2 = ipc->r1.ad2; if(p1) { if(ipc->r1.inar) { if(*p2 == CEND) { p1 = 0; } else if(*p2 == CLNUM) { l = p2[1]&0377 | ((p2[2]&0377)<<8) | ((p2[3]&0377)<<16) | ((p2[4]&0377)<<24); if(lnum > l) { ipc->r1.inar = 0; if(ipc->r1.negfl) goto yes; ipc++; continue; } if(lnum == l) { ipc->r1.inar = 0; } } else if(match(p2, 0)) { ipc->r1.inar = 0; } } else if(*p1 == CEND) { if(!dolflag) { if(ipc->r1.negfl) goto yes; ipc++; continue; } } else if(*p1 == CLNUM) { l = p1[1]&0377 | ((p1[2]&0377)<<8) | ((p1[3]&0377)<<16) | ((p1[4]&0377)<<24); if(lnum != l) { if(ipc->r1.negfl) goto yes; ipc++; continue; } if(p2) ipc->r1.inar = 1; } else if(match(p1, 0)) { if(p2) ipc->r1.inar = 1; } else { if(ipc->r1.negfl) goto yes; ipc++; continue; } } if(ipc->r1.negfl) { ipc++; continue; } yes: command(ipc); if(delflag) break; if(jflag) { jflag = 0; if((ipc = ipc->r2.lb1) == 0) { ipc = ptrspace; break; } } else ipc++; } if(!nflag && !delflag) { for(p1 = linebuf; p1 < spend; p1++) putc(*p1, stdout); putc('\n', stdout); } if(aptr > abuf) { arout(); } delflag = 0; } }
void command(union reptr *ipc) { int i; uchar *p1, *p2; uchar *execp; switch(ipc->r1.command) { case ACOM: *aptr++ = ipc; if(aptr >= &abuf[ABUFSIZE]) { fprintf(stderr, "sed: Too many appends after line %ld\n", lnum); } *aptr = 0; break; case CCOM: delflag = 1; if(!ipc->r1.inar || dolflag) { for(p1 = ipc->r1.re1; *p1; ) putc(*p1++, stdout); putc('\n', stdout); } break; case DCOM: delflag++; break; case CDCOM: p1 = p2 = linebuf; while(*p1 != '\n') { if(*p1++ == 0) { delflag++; return; } } p1++; while(*p2++ = *p1++); spend = p2-1; jflag++; break; case EQCOM: fprintf(stdout, "%ld\n", lnum); break; case GCOM: p1 = linebuf; p2 = holdsp; while(*p1++ = *p2++); spend = p1-1; break; case CGCOM: *spend++ = '\n'; p1 = spend; p2 = holdsp; while(*p1++ = *p2++) if(p1 >= lbend) break; spend = p1-1; break; case HCOM: p1 = holdsp; p2 = linebuf; while(*p1++ = *p2++); hspend = p1-1; break; case CHCOM: *hspend++ = '\n'; p1 = hspend; p2 = linebuf; while(*p1++ = *p2++) if(p1 >= hend) break; hspend = p1-1; break; case ICOM: for(p1 = ipc->r1.re1; *p1; ) putc(*p1++, stdout); putc('\n', stdout); break; case BCOM: jflag = 1; break; case LCOM: p1 = linebuf; p2 = genbuf; while(*p1) { p2 = lformat(*p1++ & 0377, p2); if(p2>lcomend && *p1) { *p2 = 0; fprintf(stdout, "%s\\\n", genbuf); p2 = genbuf; } } if(p2>genbuf && (p1[-1]==' '||p1[-1]=='\n')) p2 = lformat('\n', p2); *p2 = 0; fprintf(stdout, "%s\n", genbuf); break; case NCOM: if(!nflag) { for(p1 = linebuf; p1 < spend; p1++) putc(*p1, stdout); putc('\n', stdout); } if(aptr > abuf) arout(); if((execp = gline(linebuf)) == badp) { pending = ipc; delflag = 1; break; } spend = execp; break; case CNCOM: if(aptr > abuf) arout(); *spend++ = '\n'; if((execp = gline(spend)) == badp) { pending = ipc; delflag = 1; break; } spend = execp; break; case PCOM: for(p1 = linebuf; p1 < spend; p1++) putc(*p1, stdout); putc('\n', stdout); break; case CPCOM: cpcom: for(p1 = linebuf; *p1 != '\n' && *p1 != '\0'; ) putc(*p1++, stdout); putc('\n', stdout); break; case QCOM: if(!nflag) { for(p1 = linebuf; p1 < spend; p1++) putc(*p1, stdout); putc('\n', stdout); } if(aptr > abuf) arout(); fclose(stdout); lseek(f,(long)(cbp-ebp),2); exit(0); case RCOM: *aptr++ = ipc; if(aptr >= &abuf[ABUFSIZE]) fprintf(stderr, "sed: Too many reads after line%ld\n", lnum); *aptr = 0; break; case SCOM: i = substitute(ipc); if(ipc->r1.pfl && i) if(ipc->r1.pfl == 1) { for(p1 = linebuf; p1 < spend; p1++) putc(*p1, stdout); putc('\n', stdout); } else goto cpcom; if(i && ipc->r1.fcode) goto wcom; break; case TCOM: if(sflag == 0) break; sflag = 0; jflag = 1; break; wcom: case WCOM: fprintf(ipc->r1.fcode, "%s\n", linebuf); fflush(ipc->r1.fcode); break; case XCOM: p1 = linebuf; p2 = genbuf; while(*p2++ = *p1++); p1 = holdsp; p2 = linebuf; while(*p2++ = *p1++); spend = p2 - 1; p1 = genbuf; p2 = holdsp; while(*p2++ = *p1++); hspend = p2 - 1; break; case YCOM: p1 = linebuf; p2 = ipc->r1.re1; while(*p1 = p2[*p1]) p1++; break; } }
void cds_sig ( VG_DBStruct *el, int indx, int *iret ) /************************************************************************ * cds_sig * * * * This function displays SIGMETs to the output device. * * * * cds_sig (el, indx, iret) * * * * Input parameters: * * *el VG_DBStruct Pointer to VG record structure * * indx int Index into user attribute table * * * * Output parameters: * * *iret int Return code * * * ** * * Log: * * D.W.Plummer/NCEP 7/99 Copied from cds_line * * D.W.Plummer/NCEP 9/99 Compute circle from element distance; * * Compute line extension area * * H. Zeng/EAI 9/99 Preserve plot attributes * * F. J. Yen/NCEP 10/99 Handled user attribute table * * M. Li/GSC 10/99 Modified clo_direct and clo_dltln codes * * D.W.Plummer/NCEP 12/99 Added plotting of sequence number * * M. Li/GSC 1/00 Used string variables in gtrans * * S. Law/GSC 05/00 changed to use MAX_SIGMET for lat/lon * * H. Zeng/EAI 06/00 increased the sizes of lat&lon arrays * * A. Hardy/GSC 11/00 renamed coordinate system declarations * * M. Li/SAIC 01/03 delete vgstruct.h * * T. Piper/SAIC 12/05 redone with new Setting_t structure * ***********************************************************************/ { int ii, kk, npts, np, intrsct, ier; int mtype, color, width, lintyp, lthw, lwhw, mkhw, two; int iltypx, ilthwx, iwidthx, iwhwx, icolrx, imarkx, imkhwx, imkwidx; char str[4]; float lat[MAX_SIGMET*2+3], lon[MAX_SIGMET*2+3]; float size, dist, dir, ang1, ang2; float dirs[]={ 0.0F, 180.0F, 90.0F, 270.0F }; float s1lat[2], s1lon[2], s2lat[2], s2lon[2]; float x1[2], y1[2], x2[2], y2[2]; float xint, yint; float szmarkx; float lbllat, lbllon, rotat=0.0F; int ixoff=0, iyoff=2; int itxfn_s, itxhw_s, itxwid_s, ibrdr_s, irrotn_s, ijust_s; float sztext_s; int itxfn, itxhw, itxwid, ibrdr, irrotn, ijust; float sztext; SigmetType *psig; /*---------------------------------------------------------------------*/ *iret = 0; /* * Save plot attributes. */ gqcolr ( &icolrx, &ier ); gqline ( &iltypx, &ilthwx, &iwidthx, &iwhwx, &ier ); gqmrkr ( &imarkx, &imkhwx, &szmarkx, &imkwidx, &ier ); /* * setup basic information */ psig = &(el->elem.sig); width = (int) (( ( cdsUattr[indx].info.sig->linwid == 0 ) ? (float)psig->info.linwid : (float)cdsUattr[indx].info.sig->linwid) * cdsLineWdth); lintyp = ( cdsUattr[indx].info.sig->lintyp == 0 ) ? psig->info.lintyp : cdsUattr[indx].info.sig->lintyp; lthw = 0; lwhw = 0; mtype = 1; mkhw = 0; size = 1.0F; np = psig->info.npts; gsline (&lintyp, <hw, &width, &lwhw, &ier); color = (cdsColor == 0) ? ( ( cdsUattr[indx].maj_col == 0 ) ? el->hdr.maj_col : cdsUattr[indx].maj_col ) : cdsColor; gscolr (&color, &ier); switch ( psig->info.subtype ) { case SIGTYP_ISOL: /* isolated */ /* * Plot marker w/ surrounding circle */ lat[0] = psig->latlon[0]; lon[0] = psig->latlon[np]; gsmrkr ( &mtype, &mkhw, &size, &width, &ier ); gmark ( sys_M, &np, lat, lon, &ier, strlen(sys_M) ); if ( !G_DIFF(psig->info.distance, 0.0F ) ) { dir = ( lat[0] >= 0.F ) ? 180.F : 0.F; dist = psig->info.distance * NM2M; clo_dltln ( &lat[0], &lon[0], &dist, &dir, &(lat[1]), &(lon[1]), &ier ); np = 18; gcircl ( sys_M, lat, lon, &(lat[1]), &(lon[1]), &np, &ier, strlen(sys_M) ); } break; case SIGTYP_LINE: /* line */ for ( ii = 0; ii < np; ii++ ) { lat[ii] = psig->latlon[ii]; lon[ii] = psig->latlon[ii+np]; } gline ( sys_M, &np, lat, lon, &ier, strlen(sys_M) ); if ( !G_DIFF(psig->info.distance, 0.0F) ) { lintyp = 2; gsline (&lintyp, <hw, &width, &lwhw, &ier); dist = psig->info.distance * NM2M; switch ( psig->info.sol ) { case SIGLINE_NOF: case SIGLINE_SOF: case SIGLINE_EOF: case SIGLINE_WOF: npts = 1; for ( ii = 0; ii < np; ii++ ) { clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[ii+np]), &dist, &(dirs[psig->info.sol-1]), &(lat[npts]), &(lon[npts]), &ier ); npts++; } lat[npts] = psig->latlon[np-1]; lon[npts] = psig->latlon[2*np-1]; npts++; gline ( sys_M, &npts, lat, lon, &ier, strlen(sys_M) ); break; case SIGLINE_ESOL: lat[0] = psig->latlon[0]; lon[0] = psig->latlon[np]; clo_direct ( &(psig->latlon[1]), &(psig->latlon[np+1]), &(psig->latlon[0]), &(psig->latlon[np ]), &ang1, &ier ); ang1 -= 90.0F; clo_dltln ( &(psig->latlon[0]), &(psig->latlon[np]), &dist, &ang1, &(lat[2*np+1]), &(lon[2*np+1]), &ier ); ang1 = ang1 - 180.0F; clo_dltln ( &(psig->latlon[0]), &(psig->latlon[np]), &dist, &ang1, &(lat[1]), &(lon[1]), &ier ); ang2 = ang1; two = 2; for ( ii = 1; ii < np-1; ii++ ) { clo_direct ( &(psig->latlon[ii-1]), &(psig->latlon[np+ii-1]), &(psig->latlon[ii]), &(psig->latlon[np+ii]), &ang1, &ier ); ang1 = (float)fmod ( ((double)ang1+270.0), 360.0); clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]), &dist, &ang1, &(s1lat[1]), &(s1lon[1]), &ier ); clo_direct ( &(psig->latlon[ii+1]), &(psig->latlon[np+ii+1]), &(psig->latlon[ii]), &(psig->latlon[np+ii]), &ang2, &ier ); ang2 = (float)fmod ( ((double)ang2+90.0), 360.0); clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]), &dist, &ang2, &(s2lat[0]), &(s2lon[0]), &ier ); if ( G_ABS(ang1-ang2) > 1.F ) { clo_dltln ( &(psig->latlon[ii-1]), &(psig->latlon[np+ii-1]), &dist, &ang1, &(s1lat[0]), &(s1lon[0]), &ier ); clo_dltln ( &(psig->latlon[ii+1]), &(psig->latlon[np+ii+1]), &dist, &ang2, &(s2lat[1]), &(s2lon[1]), &ier ); gtrans ( sys_M, sys_N, &two, s1lat, s1lon, x1, y1, &ier, strlen(sys_M), strlen(sys_N) ); gtrans ( sys_M, sys_N, &two, s2lat, s2lon, x2, y2, &ier, strlen(sys_M), strlen(sys_N) ); cgr_segint( sys_N, x1, y1, sys_N, x2, y2, sys_M, &xint, &yint, &intrsct, &ier ); } else { xint = (s1lat[1] + s2lat[0]) / 2.0F; yint = (s1lon[1] + s2lon[0]) / 2.0F; } kk = ii + 1; lat[kk] = xint; lon[kk] = yint; ang1 = (float)fmod ( ((double)ang1+180.0), 360.0 ); ang2 = (float)fmod ( ((double)ang2+180.0), 360.0 ); clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]), &dist, &ang1, &(s1lat[1]), &(s1lon[1]), &ier ); clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]), &dist, &ang2, &(s2lat[0]), &(s2lon[0]), &ier ); if ( G_ABS(ang1-ang2) > 1.F ) { clo_dltln ( &(psig->latlon[ii-1]), &(psig->latlon[np+ii-1]), &dist, &ang1, &(s1lat[0]), &(s1lon[0]), &ier ); clo_dltln ( &(psig->latlon[ii+1]), &(psig->latlon[np+ii+1]), &dist, &ang2, &(s2lat[1]), &(s2lon[1]), &ier ); gtrans ( sys_M, sys_N, &two, s1lat, s1lon, x1, y1, &ier, strlen(sys_M), strlen(sys_N) ); gtrans ( sys_M, sys_N, &two, s2lat, s2lon, x2, y2, &ier, strlen(sys_M), strlen(sys_N) ); cgr_segint( sys_N, x1, y1, sys_N, x2, y2, sys_M, &xint, &yint, &intrsct, &ier ); } else { xint = (s1lat[1] + s2lat[0]) / 2.0F; yint = (s1lon[1] + s2lon[0]) / 2.0F; } kk = 2*np - ii + 1; lat[kk] = xint; lon[kk] = yint; ang1 = (float)fmod ( ((double)ang1+180.0), 360.0 ); ang2 = (float)fmod ( ((double)ang2+180.0), 360.0 ); ang1 = ang2; } clo_direct ( &(psig->latlon[np-2]), &(psig->latlon[2*np-2]), &(psig->latlon[np-1]), &(psig->latlon[2*np-1]), &ang2, &ier ); ang2 -= 90.0F; clo_dltln ( &(psig->latlon[np-1]), &(psig->latlon[2*np-1]), &dist, &ang2, &(lat[np]), &(lon[np]), &ier ); ang2 = (float)fmod ( ((double)ang2+180.0), 360.0); clo_dltln ( &(psig->latlon[np-1]), &(psig->latlon[2*np-1]), &dist, &ang2, &(lat[np+2]), &(lon[np+2]), &ier ); lat[np+1] = psig->latlon[np-1]; lon[np+1] = psig->latlon[2*np-1]; lat[2*np+2] = lat[0]; lon[2*np+2] = lon[0]; npts = 2*np + 3; gline ( sys_M, &npts, lat, lon, &ier, strlen(sys_M) ); break; } } break; case SIGTYP_AREA: /* area */ for ( ii = 0; ii < np; ii++ ) { lat[ii] = psig->latlon[ii]; lon[ii] = psig->latlon[ii+np]; } lat[np] = psig->latlon[0]; lon[np] = psig->latlon[np]; np++; gline ( sys_M, &np, lat, lon, &ier, strlen(sys_M) ); break; } if ( el->hdr.vg_type == SIGCONV_ELM || el->hdr.vg_type == SIGOUTL_ELM ) { if ( el->hdr.vg_type == SIGCONV_ELM ) sprintf( str, "%d%c", psig->info.seqnum, psig->info.msgid[0] ); else if ( el->hdr.vg_type == SIGOUTL_ELM ) sprintf( str, "%d", psig->info.seqnum ); np = psig->info.npts; lbllat = psig->latlon[0]; lbllon = psig->latlon[np]; for ( ii = 1; ii < np; ii++ ) { if ( psig->latlon[ii] > lbllat ) { lbllat = psig->latlon[ii]; lbllon = psig->latlon[ii+np]; } } gqtext( &itxfn_s, &itxhw_s, &sztext_s, &itxwid_s, &ibrdr_s, &irrotn_s, &ijust_s, &ier ); itxfn = 0; itxhw = 0; sztext = 1.5F; itxwid = 0; ibrdr = 0; irrotn = 0; ijust = 2; gstext( &itxfn, &itxhw, &sztext, &itxwid, &ibrdr, &irrotn, &ijust, &ier ); gtext( sys_M, &lbllat, &lbllon, str, &rotat, &ixoff, &iyoff, &ier, strlen(sys_M), strlen(str) ); gstext( &itxfn_s, &itxhw_s, &sztext_s, &itxwid_s, &ibrdr_s, &irrotn_s, &ijust_s, &ier ); } /* * Restore the saved plot attribute values */ gsmrkr ( &imarkx, &imkhwx, &szmarkx, &imkwidx, &ier ); gsline ( &iltypx, &ilthwx, &iwidthx, &iwhwx, &ier ); gscolr ( &icolrx, &ier ); }