Lines Matching refs:cut
26 * cut fields or columns from fields from a file
30 "[-?\n@(#)$Id: cut (AT&T Research) 2009-12-04 $\n]"
32 "[+NAME?cut - cut out selected columns or fields of each line of a file]"
140 Cut_t* cut;
142 if (!(cut = (Cut_t*)stakalloc(sizeof(Cut_t) + strlen(cp) * sizeof(int))))
144 if (cut->mb = mbwide())
146 memset(cut->space, 0, sizeof(cut->space) / 2);
147 memset(cut->space + sizeof(cut->space) / 2, SP_WIDE, sizeof(cut->space) / 2);
150 memset(cut->space, 0, sizeof(cut->space));
151 cut->wdelim = *wdelim;
153 cut->space[wdelim->chr] = SP_WORD;
154 cut->ldelim = *ldelim;
155 cut->eob = (ldelim->len == 1) ? ldelim->chr : 0;
156 cut->space[cut->eob] = SP_LINE;
157 cut->cflag = (mode&C_CHARS) && cut->mb;
158 cut->nosplit = (mode&(C_BYTES|C_NOSPLIT)) == (C_BYTES|C_NOSPLIT) && cut->mb;
159 cut->sflag = (mode&C_SUPRESS) != 0;
160 cut->nlflag = (mode&C_NONEWLINE) != 0;
161 cut->reclen = reclen;
162 lp = cut->list;
190 n = 1 + (lp-cut->list)/2;
191 qsort(lp=cut->list,n,2*sizeof(*lp),mycomp);
220 lp = cut->list;
228 return cut;
250 * cut each line of file <fdin> and put results to <fdout> using list <list>
254 cutcols(Cut_t* cut, Sfio_t* fdin, Sfio_t* fdout)
259 register const int* lp = cut->list;
268 if (len = cut->reclen)
277 if (!(ncol = skip = *(lp = cut->list)))
282 if (cut->nosplit)
313 else if (cut->cflag)
352 if (!cut->nlflag && (skip || must || cut->reclen))
354 if (cut->ldelim.len > 1)
355 sfwrite(fdout, cut->ldelim.str, cut->ldelim.len);
357 sfputc(fdout, cut->ldelim.chr);
363 * cut each line of file <fdin> and put results to <fdout> using list <list>
368 cutfields(Cut_t* cut, Sfio_t* fdin, Sfio_t* fdout)
370 register unsigned char *sp = cut->space;
374 register const int *lp = cut->list;
389 if((lastchar = cp[c]) != cut->eob)
390 *ep = cut->eob;
399 if (nfields = *(lp = cut->list))
410 if (cut->mb)
428 if (lastchar != cut->eob)
446 if ((lastchar = cp[c]) != cut->eob)
447 *ep = cut->eob;
461 if (w == cut->ldelim.chr)
462 lastchar = cut->ldelim.chr;
463 else if (w != cut->wdelim.chr)
481 if (c == cut->wdelim.chr)
486 if (c == cut->ldelim.chr)
508 if (lastchar == cut->ldelim.chr)
510 /* restore cut->last character */
511 if (lastchar != cut->eob)
538 if (!cut->sflag)
554 if (copy && (c=cp-copy)>0 && (!nodelim || !cut->sflag) && sfwrite(fdout,(char*)copy,c)< 0)
558 if(inword && nodelim && !cut->sflag && (c=cp-first)>0)
579 Cut_t* cut;
682 cut = cutinit(mode, cp, &wdelim, &ldelim, reclen);
695 cutfields(cut,fp,sfstdout);
697 cutcols(cut,fp,sfstdout);