home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / compiler / small_c / cb / sources / fmt2.c < prev    next >
Encoding:
Text File  |  1985-08-11  |  2.3 KB  |  105 lines

  1. /*
  2. ** fmt2.c -- text formatter part 2
  3. */
  4.  
  5. /*
  6. ** getval -- evaluate optional numeric argument
  7. */
  8. getval(buf, argtyp) char buf[]; int *argtyp; {
  9.   int i;
  10.   i=0;
  11.   while((buf[i]!=' ')&(buf[i]!='\t')&(buf[i]!=NULL)) ++i;
  12.   skipbl(buf, &i);
  13.   *argtyp=buf[i];
  14.   if((*argtyp=='+')|(*argtyp=='-')) ++i;
  15.   if(utoi(buf+i, &i) < 0) {
  16.     fputs("\7error: ", stderr);
  17.     fputs(inbuf, stderr);
  18.     fputc('\n', stderr);
  19.     return 0;
  20.     }
  21.   return i;
  22.   }
  23.  
  24. /*
  25. ** skipbl -- skip blanks and tabs
  26. */
  27. skipbl(lin, i) char lin[]; int *i; {
  28.   while((lin[*i]==' ')|(lin[*i]=='\t')) *i = *i + 1;
  29.   }
  30.  
  31. /*
  32. ** setvalue -- set parameter and check range
  33. */
  34. setvalue(param, val, argtyp, defval, minval, maxval)
  35.   int *param, val, argtyp, defval, minval, maxval; {
  36.   if(argtyp==NULL) *param=defval;
  37.   else if(argtyp=='+') *param=*param+val;
  38.   else if(argtyp=='-') *param=*param-val;
  39.   else *param=val;
  40.   if(*param > maxval) *param=maxval;
  41.   if(*param < minval) *param=minval;
  42.   }
  43.  
  44. /*
  45. ** text -- process text lines
  46. */
  47. text(inbuf) char inbuf[]; {
  48.   int i;
  49.   char c1, c2;
  50.   if((inbuf[0]==' ')|(inbuf[0]==NULL)) leadbl(inbuf);
  51.   if(bfval > 0) {
  52.     bold(inbuf, wrdbuf, INSIZE);
  53.     --bfval;
  54.     }
  55.   dwact = NO;
  56.   if(dwval > 0) {
  57.     if(!ttymode) {
  58.       dwact = YES;
  59.       double(inbuf, wrdbuf, INSIZE);
  60.       }
  61.     --dwval;
  62.     }
  63.   if(ulval > 0) {
  64.     if(itsub) italic(inbuf, wrdbuf, INSIZE);
  65.     else      underl(inbuf, wrdbuf, INSIZE);
  66.     --ulval;
  67.     }
  68.   if(itval > 0) {
  69.     if(ulsub) underl(inbuf, wrdbuf, INSIZE);
  70.     else      italic(inbuf, wrdbuf, INSIZE);
  71.     --itval;
  72.     }
  73.   supersub(inbuf, wrdbuf, INSIZE);
  74.   if(ceval > 0) {
  75.     center(inbuf);
  76.     put(inbuf);
  77.     --ceval;
  78.     }
  79.   else if(inbuf[0]==NULL) put(inbuf);
  80.   else if(fill==NO) put(inbuf);
  81.   else {
  82.     i=0;
  83.     wrdbuf[0]=' ';
  84.     while(getwrd(inbuf, &i, wrdbuf+1) > 0) {
  85.       if((sentend==YES)&(isupper(wrdbuf[1])==YES)&(wrdbuf[2]!='.'))
  86.         putwrd(wrdbuf);  /** leading space **/
  87.       else putwrd(wrdbuf+1);
  88.       if(inbuf[i-1]=='"') {
  89.         c1=inbuf[i-3];
  90.         c2=inbuf[i-2];
  91.         }
  92.       else {
  93.         c1=inbuf[i-2];
  94.         c2=inbuf[i-1];
  95.         }
  96.       if((inbuf[i]!='\t')&(isupper(c1)==NO)&
  97.          ((c2=='.')|(c2=='?')|(c2=='!'))) sentend=YES;
  98.       else sentend=NO;
  99.       }
  100.     }
  101.   if(ulval==0) cuact=0;
  102.   }
  103.  
  104.  
  105.