Changeset View
Changeset View
Standalone View
Standalone View
contrib/less/main.c
Show First 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | #endif | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Copy a string to a "safe" place | * Copy a string to a "safe" place | ||||
* (that is, to a buffer allocated by calloc). | * (that is, to a buffer allocated by calloc). | ||||
*/ | */ | ||||
public char * | public char * | ||||
save(s) | save(constant char *s) | ||||
char *s; | |||||
{ | { | ||||
register char *p; | char *p; | ||||
p = (char *) ecalloc(strlen(s)+1, sizeof(char)); | p = (char *) ecalloc(strlen(s)+1, sizeof(char)); | ||||
strcpy(p, s); | strcpy(p, s); | ||||
return (p); | return (p); | ||||
} | } | ||||
/* | /* | ||||
* Allocate memory. | * Allocate memory. | ||||
* Like calloc(), but never returns an error (NULL). | * Like calloc(), but never returns an error (NULL). | ||||
*/ | */ | ||||
public VOID_POINTER | public VOID_POINTER | ||||
ecalloc(count, size) | ecalloc(int count, unsigned int size) | ||||
int count; | |||||
unsigned int size; | |||||
{ | { | ||||
register VOID_POINTER p; | VOID_POINTER p; | ||||
p = (VOID_POINTER) calloc(count, size); | p = (VOID_POINTER) calloc(count, size); | ||||
if (p != NULL) | if (p != NULL) | ||||
return (p); | return (p); | ||||
error("Cannot allocate memory", NULL_PARG); | error("Cannot allocate memory", NULL_PARG); | ||||
quit(QUIT_ERROR); | quit(QUIT_ERROR); | ||||
/*NOTREACHED*/ | /*NOTREACHED*/ | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
/* | /* | ||||
* Skip leading spaces in a string. | * Skip leading spaces in a string. | ||||
*/ | */ | ||||
public char * | public char * | ||||
skipsp(s) | skipsp(char *s) | ||||
emaste: drop `register`? | |||||
register char *s; | |||||
{ | { | ||||
while (*s == ' ' || *s == '\t') | while (*s == ' ' || *s == '\t') | ||||
s++; | s++; | ||||
return (s); | return (s); | ||||
} | } | ||||
/* | /* | ||||
* See how many characters of two strings are identical. | * See how many characters of two strings are identical. | ||||
* If uppercase is true, the first string must begin with an uppercase | * If uppercase is true, the first string must begin with an uppercase | ||||
* character; the remainder of the first string may be either case. | * character; the remainder of the first string may be either case. | ||||
*/ | */ | ||||
public int | public int | ||||
sprefix(ps, s, uppercase) | sprefix(char *ps, char *s, int uppercase) | ||||
char *ps; | |||||
char *s; | |||||
int uppercase; | |||||
{ | { | ||||
register int c; | int c; | ||||
register int sc; | int sc; | ||||
register int len = 0; | int len = 0; | ||||
for ( ; *s != '\0'; s++, ps++) | for ( ; *s != '\0'; s++, ps++) | ||||
{ | { | ||||
c = *ps; | c = *ps; | ||||
if (uppercase) | if (uppercase) | ||||
{ | { | ||||
if (len == 0 && ASCII_IS_LOWER(c)) | if (len == 0 && ASCII_IS_LOWER(c)) | ||||
return (-1); | return (-1); | ||||
Show All 9 Lines | sprefix(char *ps, char *s, int uppercase) | ||||
} | } | ||||
return (len); | return (len); | ||||
} | } | ||||
/* | /* | ||||
* Exit the program. | * Exit the program. | ||||
*/ | */ | ||||
public void | public void | ||||
quit(status) | quit(int status) | ||||
int status; | |||||
{ | { | ||||
static int save_status; | static int save_status; | ||||
/* | /* | ||||
* Put cursor at bottom left corner, clear the line, | * Put cursor at bottom left corner, clear the line, | ||||
* reset the terminal modes, and exit. | * reset the terminal modes, and exit. | ||||
*/ | */ | ||||
if (status < 0) | if (status < 0) | ||||
Show All 26 Lines |
drop register?