Category : C Source Code
Archive   : SMALLC.ZIP
Filename : FORMAT4.C

 
Output of file : FORMAT4.C contained in archive : SMALLC.ZIP
/* text formatter: general utilities
*
* text formatter transcribed from the book
* Software Tools by Kernighan and Plauger
*
* Source: format4.c
* Version: Dec. 31, 1980.
*/




/* convert character buffer to numeric */


ctoi(buf,index) char *buf; int index;
{
int k;
while ( (buf[index]==' ') +
(buf[index]==TAB) ) {
index++;
}
k=0;
while ((buf[index]>='0')*(buf[index]<='9')) {
k=(k*10)+buf[index]-'0';
index++;
}
return(k);
}




/* return maximum of m,n */


max(m,n) int m,n;
{
if (m>=n) {
return(m);
}
else {
return(n);
}
}


/* return minimum of m,n */


min(m,n) int m,n;
{
if (m<=n) {
return(m);
}
else {
return(n);
}
}


/* put decimal integer n in field width >= w */
/* call putout(c) instead of putc(c) */


putdec(n,w) int n,w;
{
char chars[10];
int i,nd;
nd=itoc(n,chars,10);
i=nd;
while (i++ putout(' ');
}
i=0;
while (i putout(chars[i++]);
}
}


/* convert integer n to character string in str */


itoc(n,str,size) int n; char *str; int size;
{
int absval;
int len;
int i,j,k;
absval=abs(n);
/* generate digits */
str[0]=EOS;
i=1;
while (i str[i++]=(absval%10)+'0';
absval=absval/10;
if (absval==0) {
break;
}
}
/* generate sign */
if ((i str[i++]='-';
}
len=i-1;
/* reverse sign, digits */
i--;
j=0;
while (j k=str[i];
str[i]=str[j];
str[j]=k;
i--;
j++;
}
return(len);
}


/* return absolute value of n */


abs(n) int n;
{
if (n<0) {
return(-n);
}
else {
return(n);
}
}


/* copy string at from[i] to to[j] */


scopy(from,i,to,j)
char *from; int i; char *to; int j;
{
while ((to[j++]=from[i++])!=EOS) {
;
}
}


/* return length of string */


length(str) char *str;
{
int len;
len=0;
while (str[len]!=EOS) {
len++;
}
return(len);
}




  3 Responses to “Category : C Source Code
Archive   : SMALLC.ZIP
Filename : FORMAT4.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/