init
This commit is contained in:
44
libnut/Makefile
Normal file
44
libnut/Makefile
Normal file
@@ -0,0 +1,44 @@
|
||||
#
|
||||
# Makefile for libnut (NCSA Unix Tools Library)
|
||||
#
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-g -O
|
||||
ODIR=./objs
|
||||
OBJDIR=objs
|
||||
LIB=libnut.a
|
||||
####Set in main Mosaic Makefile -- uncomment if not compiled under Mosaic
|
||||
#RANLIB=ranlib
|
||||
OBJ=$(ODIR)/mm.o \
|
||||
$(ODIR)/str-tools.o \
|
||||
$(ODIR)/system.o \
|
||||
$(ODIR)/url-utils.o \
|
||||
$(ODIR)/ellipsis.o
|
||||
|
||||
all: objs $(LIB)
|
||||
|
||||
$(LIB): $(OBJ)
|
||||
-rm -f $(LIB)
|
||||
ar rv $(LIB) $(OBJ)
|
||||
$(RANLIB) $(LIB)
|
||||
|
||||
$(ODIR)/mm.o: mm.c mm.h
|
||||
$(CC) $(CFLAGS) -c mm.c -o $(ODIR)/mm.o
|
||||
|
||||
$(ODIR)/str-tools.o: str-tools.c
|
||||
$(CC) $(CFLAGS) -c str-tools.c -o $(ODIR)/str-tools.o
|
||||
|
||||
$(ODIR)/system.o: system.c system.h
|
||||
$(CC) $(CFLAGS) -c system.c -o $(ODIR)/system.o
|
||||
|
||||
$(ODIR)/url-utils.o: url-utils.c url-utils.h
|
||||
$(CC) $(CFLAGS) -c url-utils.c -o $(ODIR)/url-utils.o
|
||||
|
||||
$(ODIR)/ellipsis.o: ellipsis.c
|
||||
$(CC) $(CFLAGS) -c ellipsis.c -o $(ODIR)/ellipsis.o
|
||||
|
||||
objs:
|
||||
mkdir objs
|
||||
|
||||
clean:
|
||||
rm -f $(LIB) $(OBJ)
|
53
libnut/Makefile.in
Normal file
53
libnut/Makefile.in
Normal file
@@ -0,0 +1,53 @@
|
||||
# @configure_output@
|
||||
# This file is used by Autoconf to make the real Makefile.
|
||||
# DO NOT EDIT THIS FILE!
|
||||
# If you want to change something do it to the Makefile autoconf
|
||||
# creates. You should never have to edit this file.
|
||||
|
||||
CC= @CC@
|
||||
LIBS = @LIBS@
|
||||
CFLAGS = @CFLAGS@
|
||||
RANLIB = @RANLIB@
|
||||
|
||||
#
|
||||
# Makefile for libnut (NCSA Unix Tools Library)
|
||||
#
|
||||
|
||||
ODIR=./objs
|
||||
OBJDIR=objs
|
||||
LIB=libnut.a
|
||||
####Set in main Mosaic Makefile -- uncomment if not compiled under Mosaic
|
||||
|
||||
OBJ=$(ODIR)/mm.o \
|
||||
$(ODIR)/str-tools.o \
|
||||
$(ODIR)/system.o \
|
||||
$(ODIR)/url-utils.o \
|
||||
$(ODIR)/ellipsis.o
|
||||
|
||||
all: objs $(LIB)
|
||||
|
||||
$(LIB): $(OBJ)
|
||||
-rm -f $(LIB)
|
||||
ar rv $(LIB) $(OBJ)
|
||||
$(RANLIB) $(LIB)
|
||||
|
||||
$(ODIR)/mm.o: mm.c mm.h
|
||||
$(CC) $(CFLAGS) -c mm.c -o $(ODIR)/mm.o
|
||||
|
||||
$(ODIR)/str-tools.o: str-tools.c
|
||||
$(CC) $(CFLAGS) -c str-tools.c -o $(ODIR)/str-tools.o
|
||||
|
||||
$(ODIR)/system.o: system.c system.h
|
||||
$(CC) $(CFLAGS) -c system.c -o $(ODIR)/system.o
|
||||
|
||||
$(ODIR)/url-utils.o: url-utils.c url-utils.h
|
||||
$(CC) $(CFLAGS) -c url-utils.c -o $(ODIR)/url-utils.o
|
||||
|
||||
$(ODIR)/ellipsis.o: ellipsis.c
|
||||
$(CC) $(CFLAGS) -c ellipsis.c -o $(ODIR)/ellipsis.o
|
||||
|
||||
objs:
|
||||
mkdir objs
|
||||
|
||||
clean:
|
||||
rm -f $(LIB) $(OBJ)
|
44
libnut/Makefile.orig
Normal file
44
libnut/Makefile.orig
Normal file
@@ -0,0 +1,44 @@
|
||||
#
|
||||
# Makefile for libnut (NCSA Unix Tools Library)
|
||||
#
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-g -O
|
||||
ODIR=./objs
|
||||
OBJDIR=objs
|
||||
LIB=libnut.a
|
||||
####Set in main Mosaic Makefile -- uncomment if not compiled under Mosaic
|
||||
#RANLIB=ranlib
|
||||
OBJ=$(ODIR)/mm.o \
|
||||
$(ODIR)/str-tools.o \
|
||||
$(ODIR)/system.o \
|
||||
$(ODIR)/url-utils.o \
|
||||
$(ODIR)/ellipsis.o
|
||||
|
||||
all: objs $(LIB)
|
||||
|
||||
$(LIB): $(OBJ)
|
||||
-rm -f $(LIB)
|
||||
ar rv $(LIB) $(OBJ)
|
||||
$(RANLIB) $(LIB)
|
||||
|
||||
$(ODIR)/mm.o: mm.c mm.h
|
||||
$(CC) $(CFLAGS) -c mm.c -o $(ODIR)/mm.o
|
||||
|
||||
$(ODIR)/str-tools.o: str-tools.c
|
||||
$(CC) $(CFLAGS) -c str-tools.c -o $(ODIR)/str-tools.o
|
||||
|
||||
$(ODIR)/system.o: system.c system.h
|
||||
$(CC) $(CFLAGS) -c system.c -o $(ODIR)/system.o
|
||||
|
||||
$(ODIR)/url-utils.o: url-utils.c url-utils.h
|
||||
$(CC) $(CFLAGS) -c url-utils.c -o $(ODIR)/url-utils.o
|
||||
|
||||
$(ODIR)/ellipsis.o: ellipsis.c
|
||||
$(CC) $(CFLAGS) -c ellipsis.c -o $(ODIR)/ellipsis.o
|
||||
|
||||
objs:
|
||||
mkdir objs
|
||||
|
||||
clean:
|
||||
rm -f $(LIB) $(OBJ)
|
66
libnut/descrip.mms
Executable file
66
libnut/descrip.mms
Executable file
@@ -0,0 +1,66 @@
|
||||
! MMS description file for libnut (NCSA Unix Tools Library)
|
||||
! George E. Cook, WVNET, 14-Feb-1996
|
||||
! Mosaic 2.6-2
|
||||
!
|
||||
! You may have to use the /IGNORE=WARNING qualifier to make MMS run all
|
||||
! the way through if you get (acceptable) compilation warnings.
|
||||
!
|
||||
|
||||
WDIR = [.$(WORK)]
|
||||
|
||||
LIBTARGET = $(WDIR)libnut.olb
|
||||
|
||||
.IFDEF DECC
|
||||
.IFDEF PATHWAY
|
||||
.INCLUDE [-.TWG]DECC_PREFIX_RULES.MMS
|
||||
CQUALC=/DECC $(CC_PREFIX_NO_SIN)
|
||||
.ELSE
|
||||
.IFDEF MULTINET
|
||||
CQUALC=/DECC/Prefix=ANSI/Define=(MULTINET)
|
||||
.ELSE
|
||||
CQUALC=/DECC/Prefix=ALL
|
||||
.ENDIF
|
||||
.ENDIF
|
||||
.ELSE ! Not DEC C
|
||||
.IFDEF DECCVAXC
|
||||
CQUALC=/VAXC
|
||||
.ELSE
|
||||
CQUALC=
|
||||
.ENDIF
|
||||
.ENDIF
|
||||
|
||||
.IFDEF DEBUG
|
||||
CFLAGS = $(CQUALC)/NoOpt/Debug
|
||||
.ELSE
|
||||
CFLAGS = $(CQUALC)
|
||||
.ENDIF
|
||||
|
||||
OBJECTS = Odir:mm.obj Odir:str-tools.obj Odir:system.obj Odir:url-utils.obj \
|
||||
Odir:ellipsis.obj
|
||||
|
||||
.FIRST
|
||||
@ If F$Search("$(LIBTARGET)") .EQS. "" Then Library/Create $(LIBTARGET)
|
||||
@ Define/NoLog Odir $(WDIR)
|
||||
.IFDEF PATHWAY
|
||||
@ @[-.TWG]def
|
||||
.ENDIF
|
||||
|
||||
$(LIBTARGET) : $(LIBTARGET)($(OBJECTS))
|
||||
@ Write SYS$Output "Library libnut.olb built."
|
||||
|
||||
Odir:mm.obj : mm.c
|
||||
Odir:str-tools.obj : str-tools.c
|
||||
Odir:system.obj : system.c
|
||||
Odir:url-utils.obj : url-utils.c
|
||||
Odir:ellipsis.obj : ellipsis.c
|
||||
|
||||
.c.obj
|
||||
$(CC)$(CFLAGS)/OBJECT=$@ $<
|
||||
|
||||
.obj.olb
|
||||
$(LIBR) $(LIBRFLAGS) $(MMS$TARGET) $(MMS$SOURCE)
|
||||
|
||||
clean :
|
||||
Delete/Log $(WDIR)*.OBJ;*
|
||||
Delete/Log $(LIBTARGET);*
|
||||
|
181
libnut/ellipsis.c
Normal file
181
libnut/ellipsis.c
Normal file
@@ -0,0 +1,181 @@
|
||||
#include "../config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
#define ELLIPSIS_TEST
|
||||
*/
|
||||
|
||||
#ifdef ELLIPSIS_TEST
|
||||
void usage_statement(void);
|
||||
#endif
|
||||
int compact_string(char *main_string, char *ellipsis_string,
|
||||
int num_chars, int mode, int eLength);
|
||||
|
||||
#ifdef ELLIPSIS_TEST
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
char *main_string;
|
||||
char *ellipsis_string;
|
||||
int num_chars;
|
||||
int mode;
|
||||
int result;
|
||||
int ellipsisLength=3;
|
||||
|
||||
int i,j;
|
||||
|
||||
/* Check number of args */
|
||||
if(argc != 4) {
|
||||
usage_statement();
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* get args */
|
||||
main_string = argv[1];
|
||||
num_chars = atoi(argv[2]);
|
||||
mode = atoi(argv[3]);
|
||||
|
||||
/* allocate ellipsis_string */
|
||||
ellipsis_string = (char *)calloc(num_chars,1);
|
||||
|
||||
result = compact_string(main_string, ellipsis_string, num_chars, mode, ellipsisLength);
|
||||
|
||||
if(result == 1) {
|
||||
printf("The original string is:\n");
|
||||
printf("\t|%s|\n\n", main_string);
|
||||
printf("And the compacted string is:\n");
|
||||
printf("\t|%s|\n\n", ellipsis_string);
|
||||
}
|
||||
else
|
||||
printf("you screwed something up...\n");
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int compact_string(char *main_string, char *ellipsis_string,
|
||||
int num_chars, int mode, int eLength) {
|
||||
|
||||
int string_len;
|
||||
int feem, puff, i;
|
||||
|
||||
num_chars--;
|
||||
|
||||
string_len = strlen(main_string);
|
||||
if(string_len <= num_chars) {
|
||||
strcpy(ellipsis_string, main_string);
|
||||
return(1);
|
||||
}
|
||||
|
||||
switch(mode) {
|
||||
|
||||
case 1: {
|
||||
|
||||
puff = num_chars - eLength;
|
||||
feem = string_len - puff;
|
||||
|
||||
strcpy(ellipsis_string,".");
|
||||
/*
|
||||
i=1;
|
||||
while (i<eLength) {
|
||||
strcat(ellipsis_string, ".");
|
||||
i++;
|
||||
}
|
||||
*/
|
||||
|
||||
for (i = 0; i < eLength; i++) {
|
||||
ellipsis_string [i] = '.';
|
||||
}
|
||||
ellipsis_string [i] = '\0';
|
||||
|
||||
strncat(ellipsis_string, main_string + feem, puff);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case 2: {
|
||||
|
||||
int right_side, left_side;
|
||||
|
||||
/*
|
||||
puff = num_chars - eLength;
|
||||
right_side = puff >> 1;
|
||||
left_side = puff - right_side;
|
||||
|
||||
strncpy(ellipsis_string, main_string, right_side);
|
||||
ellipsis_string[right_side]='\0';
|
||||
i=0;
|
||||
while (i<eLength) {
|
||||
strcat(ellipsis_string, ".");
|
||||
i++;
|
||||
}
|
||||
strncat(ellipsis_string, main_string+(string_len-left_side), left_side);
|
||||
*/
|
||||
|
||||
puff = num_chars - eLength;
|
||||
left_side = puff >> 1;
|
||||
right_side = puff - left_side;
|
||||
|
||||
strncpy (ellipsis_string, main_string, left_side);
|
||||
for (i = left_side; i < num_chars-right_side; i++) {
|
||||
ellipsis_string [i] = '.';
|
||||
}
|
||||
ellipsis_string [num_chars - right_side] = '\0';
|
||||
strncat (ellipsis_string,
|
||||
main_string + (string_len - right_side),
|
||||
right_side);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case 3: {
|
||||
|
||||
puff = num_chars - eLength;
|
||||
feem = string_len - puff;
|
||||
|
||||
strncpy(ellipsis_string, main_string, puff);
|
||||
/*
|
||||
ellipsis_string[puff]='\0';
|
||||
i=0;
|
||||
while (i<eLength) {
|
||||
strcat(ellipsis_string, ".");
|
||||
i++;
|
||||
}
|
||||
*/
|
||||
|
||||
for (i = puff; i < num_chars; i++) {
|
||||
ellipsis_string [i] = '.';
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
default: {
|
||||
#ifdef ELLIPSIS_TEST
|
||||
usage_statement();
|
||||
exit(0);
|
||||
#else
|
||||
return(-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ellipsis_string[num_chars]='\0';
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
#ifdef ELLIPSIS_TEST
|
||||
void usage_statement(void) {
|
||||
|
||||
printf("Usage: main <initial_string> num_chars mode; where mode is:\n");
|
||||
printf(" 1=cut off start, 2=cut off middle, 3=cut off end\n");
|
||||
|
||||
}
|
||||
#endif
|
364
libnut/mm.c
Normal file
364
libnut/mm.c
Normal file
@@ -0,0 +1,364 @@
|
||||
/****************************************************************************
|
||||
* NCSA Mosaic for the X Window System *
|
||||
* Software Development Group *
|
||||
* National Center for Supercomputing Applications *
|
||||
* University of Illinois at Urbana-Champaign *
|
||||
* 605 E. Springfield, Champaign IL 61820 *
|
||||
* mosaic@ncsa.uiuc.edu *
|
||||
* *
|
||||
* Copyright (C) 1993, Board of Trustees of the University of Illinois *
|
||||
* *
|
||||
* NCSA Mosaic software, both binary and source (hereafter, Software) is *
|
||||
* copyrighted by The Board of Trustees of the University of Illinois *
|
||||
* (UI), and ownership remains with the UI. *
|
||||
* *
|
||||
* The UI grants you (hereafter, Licensee) a license to use the Software *
|
||||
* for academic, research and internal business purposes only, without a *
|
||||
* fee. Licensee may distribute the binary and source code (if released) *
|
||||
* to third parties provided that the copyright notice and this statement *
|
||||
* appears on all copies and that no charge is associated with such *
|
||||
* copies. *
|
||||
* *
|
||||
* Licensee may make derivative works. However, if Licensee distributes *
|
||||
* any derivative work based on or derived from the Software, then *
|
||||
* Licensee will (1) notify NCSA regarding its distribution of the *
|
||||
* derivative work, and (2) clearly notify users that such derivative *
|
||||
* work is a modified version and not the original NCSA Mosaic *
|
||||
* distributed by the UI. *
|
||||
* *
|
||||
* Any Licensee wishing to make commercial use of the Software should *
|
||||
* contact the UI, c/o NCSA, to negotiate an appropriate license for such *
|
||||
* commercial use. Commercial use includes (1) integration of all or *
|
||||
* part of the source code into a product for sale or license by or on *
|
||||
* behalf of Licensee to third parties, or (2) distribution of the binary *
|
||||
* code or source code to third parties that need it to utilize a *
|
||||
* commercial product sold or licensed by or on behalf of Licensee. *
|
||||
* *
|
||||
* UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR *
|
||||
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED *
|
||||
* WARRANTY. THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE *
|
||||
* USERS OF THIS SOFTWARE. *
|
||||
* *
|
||||
* By using or copying this Software, Licensee agrees to abide by the *
|
||||
* copyright law and all other applicable laws of the U.S. including, but *
|
||||
* not limited to, export control laws, and the terms of this license. *
|
||||
* UI shall have the right to terminate this license immediately by *
|
||||
* written notice upon Licensee's breach of, or non-compliance with, any *
|
||||
* of its terms. Licensee may be held legally responsible for any *
|
||||
* copyright infringement that is caused or encouraged by Licensee's *
|
||||
* failure to abide by the terms of this license. *
|
||||
* *
|
||||
* Comments and questions are welcome and can be sent to *
|
||||
* mosaic-x@ncsa.uiuc.edu. *
|
||||
****************************************************************************/
|
||||
#include "../config.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "mm.h"
|
||||
|
||||
|
||||
/*#define MM_TEST /**/
|
||||
|
||||
|
||||
#ifndef MM_TEST
|
||||
#ifndef DISABLE_TRACE
|
||||
extern int nutTrace;
|
||||
#endif
|
||||
#else
|
||||
#ifndef DISABLE_TRACE
|
||||
int nutTrace=1;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
void freeBlock(mem_block *block) {
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"freeBlock: Called\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (block) {
|
||||
if (block->memory) {
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"freeBlock: Freeing block->memory\n");
|
||||
}
|
||||
#endif
|
||||
free(block->memory);
|
||||
block->memory=NULL;
|
||||
}
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"freeBlock: Freeing block\n");
|
||||
}
|
||||
#endif
|
||||
free(block);
|
||||
block=NULL;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"freeBlock: Leaving\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
mem_block *allocateBlock(int type) {
|
||||
|
||||
mem_block *block;
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"allocateBlock: Called\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
block=(mem_block *)calloc(1,sizeof(mem_block));
|
||||
if (!block) {
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
perror("allocateBlock_block");
|
||||
}
|
||||
#endif
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"allocateBlock: block(%d)\n",sizeof(block));
|
||||
}
|
||||
#endif
|
||||
|
||||
memset(block, 0, sizeof(mem_block));
|
||||
|
||||
if (type>=MEM_MAX_ENTRY) {
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"allocateBlock_type: Invalid type\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
block->memoryType=type;
|
||||
block->sizeCnt=1;
|
||||
block->size=memSize[block->memoryType];
|
||||
block->fullSize=block->size*block->sizeCnt;
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"allocateBlock: block->memoryType(%d), block->sizeCnt(%d)\n",block->memoryType,block->sizeCnt);
|
||||
fprintf(stderr,"allocateBlock: block->size(%d), block->fullSize(%d)\n",block->size,block->fullSize);
|
||||
}
|
||||
#endif
|
||||
|
||||
block->memory=(char *)calloc((block->fullSize),sizeof(char));
|
||||
if (!block->memory) {
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
perror("allocateBlock_block->memory");
|
||||
}
|
||||
#endif
|
||||
freeBlock(block);
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"allocateBlock: block->memory(%d)\n",sizeof(block->memory));
|
||||
}
|
||||
#endif
|
||||
|
||||
block->nextFree=0;
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"allocateBlock: block->nextFree(%d)\n",block->nextFree);
|
||||
fprintf(stderr,"allocateBlock: Leaving\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return(block);
|
||||
}
|
||||
|
||||
|
||||
int reallocateBlock(mem_block *block) {
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"reallocateBlock: Called\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
block->sizeCnt++;
|
||||
block->fullSize+=block->size;
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"reallocateBlock: block->sizeCnt(%d), block->fullSize(%d)\n",block->sizeCnt,block->fullSize);
|
||||
}
|
||||
#endif
|
||||
|
||||
block->memory=realloc(block->memory,(block->fullSize*sizeof(char)));
|
||||
if (!block->memory) {
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
perror("reallocateBlock_block->memory");
|
||||
}
|
||||
#endif
|
||||
freeBlock(block);
|
||||
|
||||
return(MEM_FAIL);
|
||||
}
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"reallocateBlock: block->memory(%d)\n",sizeof(block->memory));
|
||||
fprintf(stderr,"reallocateBlock: Leaving\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return(MEM_SUCCEED);
|
||||
}
|
||||
|
||||
|
||||
void clearBlock(mem_block *block) {
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"clearBlock: Called\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
block->nextFree=0;
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"clearBlock: block->nextFree(%d)\n",block->nextFree);
|
||||
fprintf(stderr,"clearBlock: Leaving\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void *balloc(mem_block *block, int size) {
|
||||
|
||||
void *ptr=NULL;
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"balloc: Called\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!block) {
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"balloc_block: Block not allocated\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (size<=0) {
|
||||
if (size==0) {
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"balloc_size: Size is zero\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"balloc_size: Size is negative\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"balloc: size(%d), (block->fullSize{%d}-block->nextFree{%d})(%d)\n",size,block->fullSize,block->nextFree,(block->fullSize-block->nextFree));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (size>(block->fullSize-block->nextFree)) {
|
||||
/*need to reallocate*/
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"balloc: Need to reallocateBlock\n");
|
||||
}
|
||||
#endif
|
||||
if (reallocateBlock(block)!=MEM_SUCCEED) {
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
ptr = &(block->memory[block->nextFree]);
|
||||
block->nextFree+=(size+(MEM_ALIGN-(size%MEM_ALIGN)));
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"balloc: ptr(%d), block->nextFree(%d)\n",sizeof(ptr),block->nextFree);
|
||||
fprintf(stderr,"balloc: Leaving\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return(ptr);
|
||||
}
|
||||
|
||||
|
||||
int blockSize(mem_block *block) {
|
||||
|
||||
#ifndef DISABLE_TRACE
|
||||
if (nutTrace) {
|
||||
fprintf(stderr,"blockSize: Calling\n");
|
||||
fprintf(stderr,"blockSize: block->fullSize(%d)\n",block->fullSize);
|
||||
fprintf(stderr,"blockSize: Leaving\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return(block->fullSize);
|
||||
}
|
||||
|
||||
|
||||
#ifdef MM_TEST
|
||||
|
||||
int main() {
|
||||
|
||||
mem_block *b;
|
||||
char *ptr1;
|
||||
int *iptr;
|
||||
|
||||
b=allocateBlock(MEM_LEX);
|
||||
|
||||
ptr1=balloc(b,4095);
|
||||
ptr1=balloc(b,1);
|
||||
ptr1=balloc(b,1);
|
||||
iptr=balloc(b,sizeof(int));
|
||||
|
||||
*iptr=50;
|
||||
|
||||
sprintf(ptr1,"1234567890123456789 (%d)",*iptr);
|
||||
|
||||
printf("[%s]\n",ptr1);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif
|
96
libnut/mm.h
Normal file
96
libnut/mm.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
* NCSA Mosaic for the X Window System *
|
||||
* Software Development Group *
|
||||
* National Center for Supercomputing Applications *
|
||||
* University of Illinois at Urbana-Champaign *
|
||||
* 605 E. Springfield, Champaign IL 61820 *
|
||||
* mosaic@ncsa.uiuc.edu *
|
||||
* *
|
||||
* Copyright (C) 1993, Board of Trustees of the University of Illinois *
|
||||
* *
|
||||
* NCSA Mosaic software, both binary and source (hereafter, Software) is *
|
||||
* copyrighted by The Board of Trustees of the University of Illinois *
|
||||
* (UI), and ownership remains with the UI. *
|
||||
* *
|
||||
* The UI grants you (hereafter, Licensee) a license to use the Software *
|
||||
* for academic, research and internal business purposes only, without a *
|
||||
* fee. Licensee may distribute the binary and source code (if released) *
|
||||
* to third parties provided that the copyright notice and this statement *
|
||||
* appears on all copies and that no charge is associated with such *
|
||||
* copies. *
|
||||
* *
|
||||
* Licensee may make derivative works. However, if Licensee distributes *
|
||||
* any derivative work based on or derived from the Software, then *
|
||||
* Licensee will (1) notify NCSA regarding its distribution of the *
|
||||
* derivative work, and (2) clearly notify users that such derivative *
|
||||
* work is a modified version and not the original NCSA Mosaic *
|
||||
* distributed by the UI. *
|
||||
* *
|
||||
* Any Licensee wishing to make commercial use of the Software should *
|
||||
* contact the UI, c/o NCSA, to negotiate an appropriate license for such *
|
||||
* commercial use. Commercial use includes (1) integration of all or *
|
||||
* part of the source code into a product for sale or license by or on *
|
||||
* behalf of Licensee to third parties, or (2) distribution of the binary *
|
||||
* code or source code to third parties that need it to utilize a *
|
||||
* commercial product sold or licensed by or on behalf of Licensee. *
|
||||
* *
|
||||
* UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR *
|
||||
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED *
|
||||
* WARRANTY. THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE *
|
||||
* USERS OF THIS SOFTWARE. *
|
||||
* *
|
||||
* By using or copying this Software, Licensee agrees to abide by the *
|
||||
* copyright law and all other applicable laws of the U.S. including, but *
|
||||
* not limited to, export control laws, and the terms of this license. *
|
||||
* UI shall have the right to terminate this license immediately by *
|
||||
* written notice upon Licensee's breach of, or non-compliance with, any *
|
||||
* of its terms. Licensee may be held legally responsible for any *
|
||||
* copyright infringement that is caused or encouraged by Licensee's *
|
||||
* failure to abide by the terms of this license. *
|
||||
* *
|
||||
* Comments and questions are welcome and can be sent to *
|
||||
* mosaic-x@ncsa.uiuc.edu. *
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
typedef struct memory_struct {
|
||||
int memoryType; /*type of chunk to use*/
|
||||
char *memory; /*chunk(s) of memory*/
|
||||
int sizeCnt; /*the number of chunks of size*/
|
||||
int size; /*the size of _1_ chunk*/
|
||||
int fullSize; /*the size * sizeCnt*/
|
||||
int nextFree; /*the next free location (end of last allocation)*/
|
||||
} mem_block;
|
||||
|
||||
int memSize[] = {
|
||||
4096, /*Lex Tree*/
|
||||
8192 /*Parse Tree*/
|
||||
};
|
||||
|
||||
|
||||
#define MEM_LEX 0
|
||||
#define MEM_PARSE 1
|
||||
#define MEM_MAX_ENTRY 2
|
||||
|
||||
#define MEM_ALIGN_2 2
|
||||
#define MEM_ALIGN_4 4
|
||||
|
||||
#if defined(VMS) && defined(__DECC) && defined(__alpha) /* PGE */
|
||||
#define MEM_ALIGN_8 8
|
||||
#define MEM_ALIGN MEM_ALIGN_8
|
||||
#else
|
||||
#define MEM_ALIGN MEM_ALIGN_4
|
||||
#endif
|
||||
|
||||
#define MEM_FAIL 0
|
||||
#define MEM_SUCCEED 1
|
||||
|
||||
#define MEM_INDEX_SIZE(block) ((block)->fullSize/4) /*1/4 chunk size*/
|
||||
|
||||
|
||||
void freeBlock(mem_block *block);
|
||||
mem_block *allocateBlock(int type);
|
||||
int reallocateBlock(mem_block *block);
|
||||
void clearBlock(mem_block *block);
|
||||
void *balloc(mem_block *block, int size);
|
||||
int blockSize(mem_block *block);
|
460
libnut/str-tools.c
Normal file
460
libnut/str-tools.c
Normal file
@@ -0,0 +1,460 @@
|
||||
/****************************************************************************
|
||||
* NCSA Mosaic for the X Window System *
|
||||
* Software Development Group *
|
||||
* National Center for Supercomputing Applications *
|
||||
* University of Illinois at Urbana-Champaign *
|
||||
* 605 E. Springfield, Champaign IL 61820 *
|
||||
* mosaic@ncsa.uiuc.edu *
|
||||
* *
|
||||
* Copyright (C) 1993, Board of Trustees of the University of Illinois *
|
||||
* *
|
||||
* NCSA Mosaic software, both binary and source (hereafter, Software) is *
|
||||
* copyrighted by The Board of Trustees of the University of Illinois *
|
||||
* (UI), and ownership remains with the UI. *
|
||||
* *
|
||||
* The UI grants you (hereafter, Licensee) a license to use the Software *
|
||||
* for academic, research and internal business purposes only, without a *
|
||||
* fee. Licensee may distribute the binary and source code (if released) *
|
||||
* to third parties provided that the copyright notice and this statement *
|
||||
* appears on all copies and that no charge is associated with such *
|
||||
* copies. *
|
||||
* *
|
||||
* Licensee may make derivative works. However, if Licensee distributes *
|
||||
* any derivative work based on or derived from the Software, then *
|
||||
* Licensee will (1) notify NCSA regarding its distribution of the *
|
||||
* derivative work, and (2) clearly notify users that such derivative *
|
||||
* work is a modified version and not the original NCSA Mosaic *
|
||||
* distributed by the UI. *
|
||||
* *
|
||||
* Any Licensee wishing to make commercial use of the Software should *
|
||||
* contact the UI, c/o NCSA, to negotiate an appropriate license for such *
|
||||
* commercial use. Commercial use includes (1) integration of all or *
|
||||
* part of the source code into a product for sale or license by or on *
|
||||
* behalf of Licensee to third parties, or (2) distribution of the binary *
|
||||
* code or source code to third parties that need it to utilize a *
|
||||
* commercial product sold or licensed by or on behalf of Licensee. *
|
||||
* *
|
||||
* UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR *
|
||||
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED *
|
||||
* WARRANTY. THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE *
|
||||
* USERS OF THIS SOFTWARE. *
|
||||
* *
|
||||
* By using or copying this Software, Licensee agrees to abide by the *
|
||||
* copyright law and all other applicable laws of the U.S. including, but *
|
||||
* not limited to, export control laws, and the terms of this license. *
|
||||
* UI shall have the right to terminate this license immediately by *
|
||||
* written notice upon Licensee's breach of, or non-compliance with, any *
|
||||
* of its terms. Licensee may be held legally responsible for any *
|
||||
* copyright infringement that is caused or encouraged by Licensee's *
|
||||
* failure to abide by the terms of this license. *
|
||||
* *
|
||||
* Comments and questions are welcome and can be sent to *
|
||||
* mosaic-x@ncsa.uiuc.edu. *
|
||||
****************************************************************************/
|
||||
#include "../config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef VMS /* PGE */
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
#ifndef DEBUG
|
||||
|
||||
/* Use builtin strdup when appropriate -- code duplicated in tcp.h. */
|
||||
#if defined(ultrix) || defined(VMS) || defined(NeXT)
|
||||
extern char *strdup(char *str);
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#include "str-tools.h"
|
||||
|
||||
/* Copied from mo-www.c PGE */
|
||||
#if defined(ultrix) || defined(VMS) || defined(NeXT) || defined(M4310) || defined(vax)
|
||||
char *strdup(char *str) {
|
||||
char *dup;
|
||||
|
||||
if(!str)
|
||||
return NULL;
|
||||
|
||||
dup = (char *)malloc(strlen (str) + 1);
|
||||
if(!dup)
|
||||
return NULL;
|
||||
|
||||
dup = strcpy(dup, str);
|
||||
|
||||
return dup;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
|
||||
char *bob,*newstr;
|
||||
|
||||
bob=strdup("This is test %d.");
|
||||
newstr=strstrdup(bob,"%d","1");
|
||||
|
||||
printf("bob[%s]\nnew[%s]\n\n",bob,newstr);
|
||||
|
||||
free(bob);
|
||||
free(newstr);
|
||||
|
||||
bob=strdup("%d) This is test %d.");
|
||||
newstr=strstrdup(bob,"%d","2");
|
||||
|
||||
printf("bob[%s]\nnew[%s]\n\n",bob,newstr);
|
||||
|
||||
free(bob);
|
||||
free(newstr);
|
||||
|
||||
bob=strdup("This is test %d.");
|
||||
newstr=strstrdup(bob,"%d","003");
|
||||
|
||||
printf("bob[%s]\nnew[%s]\n\n",bob,newstr);
|
||||
|
||||
bob=strdup("%d) This is test %d.");
|
||||
newstr=strstrdup(bob,"%d","004");
|
||||
|
||||
printf("bob[%s]\nnew[%s]\n\n",bob,newstr);
|
||||
|
||||
bob=strdup("qwerty");
|
||||
printf("src[%s]\n",bob);
|
||||
newstr=my_chop (bob);
|
||||
printf("chopped[%s]\n\n",newstr);
|
||||
|
||||
bob=strdup("qwerty ");
|
||||
printf("src[%s]\n",bob);
|
||||
newstr=my_chop (bob);
|
||||
printf("chopped[%s]\n\n",newstr);
|
||||
|
||||
bob=strdup(" qwerty ");
|
||||
printf("src[%s]\n",bob);
|
||||
newstr=my_chop (bob);
|
||||
printf("chopped[%s]\n\n",newstr);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
char *getFileName(char *file_src) {
|
||||
|
||||
char *ptr;
|
||||
|
||||
if (!file_src || !*file_src) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ptr=strrchr(file_src,'/');
|
||||
|
||||
if (!ptr || !*ptr) {
|
||||
return(file_src);
|
||||
}
|
||||
|
||||
if (*ptr=='/' && *(ptr+1)) {
|
||||
ptr++;
|
||||
}
|
||||
|
||||
#ifdef VMS /* GEC */
|
||||
/* I don't understand this, it can never happen. PGE */
|
||||
if (*ptr=='/') {
|
||||
return("\0");
|
||||
}
|
||||
#endif
|
||||
|
||||
return(ptr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Will casefully search forward through a string for a character.
|
||||
*
|
||||
* Must be a null-terminated string.
|
||||
*
|
||||
* SWP
|
||||
*/
|
||||
char *strcasechr(char *src, char srch) {
|
||||
|
||||
char *ptr=NULL;
|
||||
char tmp;
|
||||
|
||||
if (!src || !*src) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
tmp=toupper(srch);
|
||||
|
||||
for (ptr=src; (*ptr && toupper(*ptr)!=tmp); ptr++);
|
||||
|
||||
/*
|
||||
* At this point, either *ptr == \0 (failure) or toupper(*ptr) is
|
||||
* == to tmp (success). Return accordingly.
|
||||
*/
|
||||
if (*ptr) {
|
||||
return(ptr);
|
||||
}
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Will casefully search backward through a string for a character.
|
||||
*
|
||||
* Must be a null-terminated string.
|
||||
*
|
||||
* SWP
|
||||
*/
|
||||
char *strrcasechr(char *src, char srch) {
|
||||
|
||||
char *ptr=NULL;
|
||||
char tmp;
|
||||
|
||||
if (!src || !*src) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
tmp=toupper(srch);
|
||||
|
||||
for (ptr=(src+strlen(src)-1); (ptr>src && toupper(*ptr)!=tmp); ptr--);
|
||||
|
||||
/*
|
||||
* At this point we have either found toupper(*ptr) == to tmp, or we
|
||||
* are at the very begining of the string. So, if ptr is != to src,
|
||||
* we found a match...or...we need to test to make sure the first
|
||||
* char in the string is not the match. Return accordingly.
|
||||
*/
|
||||
if (ptr!=src || toupper(*ptr)==tmp) {
|
||||
return(ptr);
|
||||
}
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
char *strstrdup(char *src, char *srch, char *rplc) {
|
||||
|
||||
char *dest=NULL,*local=NULL,*start=NULL,*found=NULL,*next=NULL;
|
||||
int rplcLen=0,i,srchLen;
|
||||
|
||||
if (!src || !*src || !srch || !*srch) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (rplc && *rplc) {
|
||||
rplcLen=strlen(rplc);
|
||||
}
|
||||
srchLen=strlen(srch);
|
||||
|
||||
if (rplcLen>srchLen) {
|
||||
dest=(char *)calloc(1,sizeof(char));
|
||||
}
|
||||
else {
|
||||
dest=strdup(src);
|
||||
}
|
||||
*dest='\0';
|
||||
|
||||
local=strdup(src);
|
||||
start=local;
|
||||
while (*start) {
|
||||
if (!(found=strstr(start,srch))) {
|
||||
if (rplcLen>srchLen) {
|
||||
realloc((void *)dest,((strlen(dest)+strlen(start)+4)*sizeof(char)));
|
||||
strcat(dest,start);
|
||||
}
|
||||
else {
|
||||
strcat(dest,start);
|
||||
}
|
||||
free(local);
|
||||
|
||||
return(dest);
|
||||
}
|
||||
|
||||
for (i=0,next=found; i<srchLen; i++,next++);
|
||||
*found='\0';
|
||||
if (rplcLen>srchLen) {
|
||||
realloc((void *)dest,((rplcLen+strlen(dest)+strlen(start)+4)*sizeof(char)));
|
||||
strcat(dest,start);
|
||||
if (rplcLen) {
|
||||
strcat(dest,rplc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
strcat(dest,start);
|
||||
strcat(dest,rplc);
|
||||
}
|
||||
start=next;
|
||||
}
|
||||
|
||||
return(dest);
|
||||
}
|
||||
|
||||
|
||||
char **string_to_token_array(char *str, char *delimiter)
|
||||
{
|
||||
char **array, *tmp;
|
||||
int num=0, i=0;
|
||||
|
||||
if(!str || !*str || !delimiter || !*delimiter)
|
||||
return NULL;
|
||||
|
||||
/* first get number of tokens */
|
||||
tmp = strstr(str, delimiter);
|
||||
num++; tmp++;
|
||||
while((tmp = strstr(tmp, delimiter)) != NULL)
|
||||
{
|
||||
tmp++; num++;
|
||||
}
|
||||
|
||||
array = malloc(sizeof(char *) * (num+2));
|
||||
array[0] = strdup(strtok(str, delimiter));
|
||||
|
||||
i++;
|
||||
while((array[i++] = strdup(strtok((char *) NULL, delimiter))) != NULL);
|
||||
|
||||
|
||||
free(str);
|
||||
return array;
|
||||
}
|
||||
|
||||
char *my_strndup(char *str, int num)
|
||||
{
|
||||
char *nstr = NULL;
|
||||
|
||||
if(!str || !*str)
|
||||
return NULL;
|
||||
|
||||
nstr = malloc(sizeof(char) * (num + 1));
|
||||
|
||||
strncpy(nstr, str, num);
|
||||
nstr[num] = '\0'; /* shouldn't strcpy do this ?? */
|
||||
return nstr;
|
||||
}
|
||||
|
||||
char *my_chop(char *str)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
if(!str || !*str)
|
||||
return str;
|
||||
|
||||
/*
|
||||
while(isspace(str[0]))
|
||||
str++;
|
||||
|
||||
while(isspace(str[strlen(str)-1]) || isspace(str[strlen(str)-1]))
|
||||
{
|
||||
str[strlen(str)-1] = '\0';
|
||||
}
|
||||
*/
|
||||
|
||||
/* Remove blank space from end of string. */
|
||||
ptr = str + strlen(str) - 1;
|
||||
while((ptr >= str) && isspace(*ptr))
|
||||
{
|
||||
*ptr = '\0';
|
||||
ptr--;
|
||||
}
|
||||
|
||||
/* Remove blank space from start of string. */
|
||||
ptr = str;
|
||||
while(isspace(ptr[0]))
|
||||
ptr++;
|
||||
|
||||
/*
|
||||
** If there was blank space at start of string then move string back to the
|
||||
** beginning. This prevents memory freeing problems later if pointer is
|
||||
** moved. memmove is used because it is safe for overlapping regions.
|
||||
*/
|
||||
if (ptr != str)
|
||||
memmove (str, ptr, strlen (ptr) + 1);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
int my_strcasecmp(char *str1, char *str2)
|
||||
{
|
||||
int i, min, offset1, offset2;
|
||||
|
||||
if(!str1 || !str2 || !*str1 || !*str2)
|
||||
return 1;
|
||||
|
||||
/* find shortest to string to make sure we don't go past null */
|
||||
min = strlen(str1);
|
||||
if(strlen(str2) < min)
|
||||
min = strlen(str2);
|
||||
|
||||
for(i=0;i<min;i++)
|
||||
{
|
||||
/* use offsets to make everything lower case */
|
||||
|
||||
if(str1[i]>='A' && str1[i]<='Z')
|
||||
offset1=32;
|
||||
else
|
||||
offset1=0;
|
||||
|
||||
if(str2[i]>='A' && str2[i]<='Z')
|
||||
offset2=32;
|
||||
else
|
||||
offset2=0;
|
||||
|
||||
if(str1[i]+offset1<str2[i]+offset2)
|
||||
return -1;
|
||||
if(str1[i]+offset1>str2[i]+offset2)
|
||||
return 1;
|
||||
/*
|
||||
if (toupper(str1[i])<toupper(str2[i])) {
|
||||
return(-1);
|
||||
}
|
||||
if (toupper(str1[i])>toupper(str2[i])) {
|
||||
return(1);
|
||||
}*/
|
||||
}
|
||||
/* they're equal */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int my_strncasecmp(char *str1, char *str2, int n)
|
||||
{
|
||||
int i, min, offset1, offset2;
|
||||
|
||||
if(!str1 || !str2 || !*str1 || !*str2 || !n)
|
||||
return 1;
|
||||
|
||||
min = n;
|
||||
|
||||
if(strlen(str1) < min)
|
||||
min = strlen(str1);
|
||||
|
||||
if(strlen(str2) < min)
|
||||
min = strlen(str2);
|
||||
|
||||
for(i=0;i<min;i++)
|
||||
{
|
||||
if(str1[i]>='A' && str1[i]<='Z')
|
||||
offset1=32;
|
||||
else
|
||||
offset1=0;
|
||||
|
||||
if(str2[i]>='A' && str2[i]<='Z')
|
||||
offset2=32;
|
||||
else
|
||||
offset2=0;
|
||||
|
||||
if(str1[i]+offset1<str2[i]+offset2)
|
||||
return -1;
|
||||
if(str1[i]+offset1>str2[i]+offset2)
|
||||
return 1;
|
||||
/*
|
||||
if (toupper(str1[i])<toupper(str2[i])) {
|
||||
return(-1);
|
||||
}
|
||||
if (toupper(str1[i])>toupper(str2[i])) {
|
||||
return(1);
|
||||
}*/
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
9
libnut/str-tools.h
Normal file
9
libnut/str-tools.h
Normal file
@@ -0,0 +1,9 @@
|
||||
char *getFileName(char *file_src);
|
||||
char *strcasechr(char *src, char srch);
|
||||
char *strrcasechr(char *src, char srch);
|
||||
char *strstrdup(char *src, char *srch, char *rplc);
|
||||
char **string_to_token_array(char *str, char *delimiter);
|
||||
char *my_strndup(char *str, int num);
|
||||
char *my_chop(char *str);
|
||||
int my_strcasecmp(char *, char *);
|
||||
int my_strncasecmp(char *, char *, int);
|
1040
libnut/system.c
Normal file
1040
libnut/system.c
Normal file
File diff suppressed because it is too large
Load Diff
23
libnut/system.h
Normal file
23
libnut/system.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#define SYS_SUCCESS 0
|
||||
#define SYS_NO_COMMAND 1
|
||||
#define SYS_FORK_FAIL 2
|
||||
#define SYS_PROGRAM_FAILED 3
|
||||
#define SYS_NO_RETBUF 4
|
||||
#define SYS_FCNTL_FAILED 5
|
||||
#define SYS_NO_SRC_FILE 6
|
||||
#define SYS_NO_DEST_FILE 7
|
||||
#define SYS_DEST_EXISTS 8
|
||||
#define SYS_NO_MEMORY 9
|
||||
#define SYS_SRC_OPEN_FAIL 10
|
||||
#define SYS_DEST_OPEN_FAIL 11
|
||||
#define SYS_READ_FAIL 12
|
||||
#define SYS_WRITE_FAIL 13
|
||||
#define SYS_INTERNAL_FAIL 14
|
||||
|
||||
int my_system(char *cmd, char *retBuf, int bufsize);
|
||||
int my_move(char *src, char *dest, char *retBuf, int bufsize, int overwrite);
|
||||
char *my_strerror(int errornum);
|
||||
char **buildArgv(char *cmd, int *new_argc);
|
||||
int my_copy(char *, char *, char *, int, int);
|
||||
int file_exists(char *);
|
||||
int get_home(char **);
|
204
libnut/url-utils.c
Executable file
204
libnut/url-utils.c
Executable file
@@ -0,0 +1,204 @@
|
||||
/****************************************************************************
|
||||
* NCSA Mosaic for the X Window System *
|
||||
* Software Development Group *
|
||||
* National Center for Supercomputing Applications *
|
||||
* University of Illinois at Urbana-Champaign *
|
||||
* 605 E. Springfield, Champaign IL 61820 *
|
||||
* mosaic@ncsa.uiuc.edu *
|
||||
* *
|
||||
* Copyright (C) 1993, Board of Trustees of the University of Illinois *
|
||||
* *
|
||||
* NCSA Mosaic software, both binary and source (hereafter, Software) is *
|
||||
* copyrighted by The Board of Trustees of the University of Illinois *
|
||||
* (UI), and ownership remains with the UI. *
|
||||
* *
|
||||
* The UI grants you (hereafter, Licensee) a license to use the Software *
|
||||
* for academic, research and internal business purposes only, without a *
|
||||
* fee. Licensee may distribute the binary and source code (if released) *
|
||||
* to third parties provided that the copyright notice and this statement *
|
||||
* appears on all copies and that no charge is associated with such *
|
||||
* copies. *
|
||||
* *
|
||||
* Licensee may make derivative works. However, if Licensee distributes *
|
||||
* any derivative work based on or derived from the Software, then *
|
||||
* Licensee will (1) notify NCSA regarding its distribution of the *
|
||||
* derivative work, and (2) clearly notify users that such derivative *
|
||||
* work is a modified version and not the original NCSA Mosaic *
|
||||
* distributed by the UI. *
|
||||
* *
|
||||
* Any Licensee wishing to make commercial use of the Software should *
|
||||
* contact the UI, c/o NCSA, to negotiate an appropriate license for such *
|
||||
* commercial use. Commercial use includes (1) integration of all or *
|
||||
* part of the source code into a product for sale or license by or on *
|
||||
* behalf of Licensee to third parties, or (2) distribution of the binary *
|
||||
* code or source code to third parties that need it to utilize a *
|
||||
* commercial product sold or licensed by or on behalf of Licensee. *
|
||||
* *
|
||||
* UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR *
|
||||
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED *
|
||||
* WARRANTY. THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE *
|
||||
* USERS OF THIS SOFTWARE. *
|
||||
* *
|
||||
* By using or copying this Software, Licensee agrees to abide by the *
|
||||
* copyright law and all other applicable laws of the U.S. including, but *
|
||||
* not limited to, export control laws, and the terms of this license. *
|
||||
* UI shall have the right to terminate this license immediately by *
|
||||
* written notice upon Licensee's breach of, or non-compliance with, any *
|
||||
* of its terms. Licensee may be held legally responsible for any *
|
||||
* copyright infringement that is caused or encouraged by Licensee's *
|
||||
* failure to abide by the terms of this license. *
|
||||
* *
|
||||
* Comments and questions are welcome and can be sent to *
|
||||
* mosaic-x@ncsa.uiuc.edu. *
|
||||
****************************************************************************/
|
||||
|
||||
/* Note that this code is taken almost straight from the httpd cgi-src
|
||||
directory.*/
|
||||
|
||||
#include "../config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifndef LF
|
||||
#define LF 10
|
||||
#endif
|
||||
#ifndef CR
|
||||
#define CR 13
|
||||
#endif
|
||||
|
||||
|
||||
void getword(char *word, char *line, char stop) {
|
||||
int x = 0,y;
|
||||
|
||||
for(x=0;((line[x]) && (line[x] != stop));x++)
|
||||
word[x] = line[x];
|
||||
|
||||
word[x] = '\0';
|
||||
if(line[x]) ++x;
|
||||
y=0;
|
||||
|
||||
while(line[y++] = line[x++]);
|
||||
}
|
||||
|
||||
|
||||
char *makeword(char *line, char stop) {
|
||||
int x = 0,y;
|
||||
char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1));
|
||||
|
||||
for(x=0;((line[x]) && (line[x] != stop));x++)
|
||||
word[x] = line[x];
|
||||
|
||||
word[x] = '\0';
|
||||
if(line[x]) ++x;
|
||||
y=0;
|
||||
|
||||
while(line[y++] = line[x++]);
|
||||
return word;
|
||||
}
|
||||
|
||||
|
||||
char *fmakeword(FILE *f, char stop, int *cl) {
|
||||
int wsize;
|
||||
char *word;
|
||||
int ll;
|
||||
|
||||
wsize = 102400;
|
||||
ll=0;
|
||||
word = (char *) malloc(sizeof(char) * (wsize + 1));
|
||||
|
||||
while(1) {
|
||||
word[ll] = (char)fgetc(f);
|
||||
if(ll==wsize) {
|
||||
word[ll+1] = '\0';
|
||||
wsize+=102400;
|
||||
word = (char *)realloc(word,sizeof(char)*(wsize+1));
|
||||
}
|
||||
--(*cl);
|
||||
if((word[ll] == stop) || (feof(f)) || (!(*cl))) {
|
||||
if(word[ll] != stop) ll++;
|
||||
word[ll] = '\0';
|
||||
return word;
|
||||
}
|
||||
++ll;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char x2c(char *what) {
|
||||
register char digit;
|
||||
|
||||
digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
|
||||
digit *= 16;
|
||||
digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
|
||||
return(digit);
|
||||
}
|
||||
|
||||
|
||||
void unescape_url(char *url) {
|
||||
register int x,y;
|
||||
|
||||
for(x=0,y=0;url[y];++x,++y) {
|
||||
if((url[x] = url[y]) == '%') {
|
||||
url[x] = x2c(&url[y+1]);
|
||||
y+=2;
|
||||
}
|
||||
}
|
||||
url[x] = '\0';
|
||||
}
|
||||
|
||||
|
||||
void plustospace(char *str) {
|
||||
register int x;
|
||||
|
||||
for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' ';
|
||||
}
|
||||
|
||||
|
||||
int rind(char *s, char c) {
|
||||
register int x;
|
||||
for(x=strlen(s) - 1;x != -1; x--)
|
||||
if(s[x] == c) return x;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void send_fd(FILE *f, FILE *fd)
|
||||
{
|
||||
int num_chars=0;
|
||||
char c;
|
||||
|
||||
while (1) {
|
||||
c = fgetc(f);
|
||||
if(feof(f))
|
||||
return;
|
||||
fputc(c,fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ind(char *s, char c) {
|
||||
register int x;
|
||||
|
||||
for(x=0;s[x];x++)
|
||||
if(s[x] == c) return x;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void escape_shell_cmd(char *cmd) {
|
||||
register int x,y,l;
|
||||
|
||||
l=strlen(cmd);
|
||||
for(x=0;cmd[x];x++) {
|
||||
if(ind("&;`'\"|*?~<>^()[]{}$\\",cmd[x]) != -1){
|
||||
for(y=l+1;y>x;y--)
|
||||
cmd[y] = cmd[y-1];
|
||||
l++; /* length has been increased */
|
||||
cmd[x] = '\\';
|
||||
x++; /* skip the character */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
libnut/url-utils.h
Normal file
11
libnut/url-utils.h
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
void getword(char *word, char *line, char stop);
|
||||
char *makeword(char *line, char stop);
|
||||
char *fmakeword(FILE *f, char stop, int *cl);
|
||||
char x2c(char *what);
|
||||
void unescape_url(char *url);
|
||||
void plustospace(char *str);
|
||||
int rind(char *s, char c);
|
||||
void send_fd(FILE *f, FILE *fd);
|
||||
int ind(char *s, char c);
|
||||
void escape_shell_cmd(char *cmd);
|
Reference in New Issue
Block a user