File: util.c

package info (click to toggle)
ncdt 1.5-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 80 kB
  • ctags: 29
  • sloc: ansic: 260; makefile: 49
file content (38 lines) | stat: -rw-r--r-- 742 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * NcdT -- directory tree printer with extended capabilities
 * (C) 1999 by Pawel Wiecek <coven@vmh.net>
 * See Copying file for licence.
 * 
 * Utility functions
 */

#include <stdio.h>
#include <string.h>
#include "ncdt.h"

int endswith(char *s, char *e) {
 return !strcmp(s+strlen(s)-strlen(e),e);
}

char *nicenum(unsigned long n) {
 static char buf[1024];
 char tmp[5];
 
 if(n>999) {
  nicenum(n/1000);
  sprintf(tmp,",%03ld",n%1000);
  strcat(buf,tmp);
 } else {
  sprintf(buf,"%ld",n);
 }
 return buf;
}

char *nicetime(unsigned long n) {
 static char buf[1024];
 
 if(n>3600) sprintf(buf,"%d:%02d:%02d",(int)(n/3600),(int)((n/60)%60),
		    (int)(n%60));
       else sprintf(buf,"%d:%02d",(int)(n/60),(int)(n%60));
 return buf;
}