/*------------------------------------------------------------------ * *------------------------------------------------------------------*/ int main(void) { Hash *iHash; int i; int counter; iHash = HashCreate(sizeof(int),3,compareFunc,hashFunc,NULL); for (i= 1; i<10; i++) HashAdd(iHash,&i); for (i=20; i>10; i--) HashAdd(iHash,&i); for (i=0; i<=21; i++) if (!HashFind(iHash,&i)) printf("didn't find %d\n",i); counter = 1; HashIterate(iHash,iterateFunc,&counter); for (i=-1; i<5; i++) HashDelete(iHash,&i); for (i=21; i>15; i--) HashDelete(iHash,&i); counter = 1; HashIterate(iHash,iterateFunc,&counter); HashDestroy(iHash); return 0; }
ClientManager* ClientManagerCreate(char* _ip, int _port) { ClientManager* clientManager = NULL; if (! _ip) { return NULL; } if (!(clientManager = malloc(sizeof(ClientManager)))) { return NULL; } if (ERR_OK != TcpCreateClientConnection (_ip,_port,&clientManager->m_socket)) { return NULL; } if (! (clientManager->m_groups = HashCreate(MAX_NUM_OF_GROUPS,StringHashFunction,strCompare))) { free(clientManager); return NULL; } LogCreate(LOG_MODE, LOG_NAME); FD_ZERO(&clientManager->m_fd); FD_SET(0, &clientManager->m_fd); FD_SET(clientManager->m_socket, &clientManager->m_fd); return clientManager; }
static void g_detect_domain_init(void) { //int size; HashConfigure conf = {0}; conf.name = "detect_domain_init"; conf.total = (2<<16)+1; conf.GetKey = DetectOriginIndexGetKey; conf.IsEqual = DetectOriginIndexIsEqual; conf.IsNull = NULL; conf.DoFree = (HashDoFree)DetectDomainIndexDoFree; g_detect_domain_table = HashCreate( &conf ); }
static void g_detect_tasks_init(void) { int size; HashConfigure conf = {0}; conf.name = "detect_tasks_init"; conf.total = (2<<16)+1; conf.GetKey = DetectOriginIndexGetKey; conf.IsEqual = DetectOriginIndexIsEqual; conf.IsNull = DetectOriginIndexIsNull; conf.DoFree = (HashDoFree)free; g_detect_tasks_index = HashCreate( &conf ); size = sizeof(struct DetectOrigin *) * max_tasks_capacity; g_detect_tasks = cc_malloc(size); assert(g_detect_tasks != NULL); memset(g_detect_tasks, 0, size); }
OperatorDB* OperatorDBCreate(ADTErr* _err) { char errMsg[ERR_MSG_SIZE]; OperatorDB* odb = malloc(sizeof(OperatorDB)); if (NULL == odb) { if (NULL != _err) { *_err = ERR_ALLOCATION_FAILED; } GetError(errMsg, ERR_ALLOCATION_FAILED); LOG_ERROR_PRINT("%s", errMsg); return NULL; } odb->m_map = HashCreate(NUM_OF_BUCKETS, DJB2, CompareOperators); if (NULL == odb->m_map) { if (NULL != _err) { *_err = ERR_ALLOCATION_FAILED; } GetError(errMsg, ERR_ALLOCATION_FAILED); LOG_ERROR_PRINT("%s", errMsg); free(odb); return NULL; } if (NULL != _err) { *_err = ERR_OK; } LOG_DEBUG_PRINT("%s", "Successfully created operator database."); return odb; }
/*------------------------------------------------------------------ * main program *------------------------------------------------------------------*/ int main( int argc, char *argv[] ) { int i; char dateStr[30]; struct tm *tm; time_t t; char *origParms; /*--------------------------------------------------------------- * check for help *---------------------------------------------------------------*/ if ((1 == argc) || ('?' == *(argv[1]))) Usage(); /*--------------------------------------------------------------- * get original parms *---------------------------------------------------------------*/ origParms = malloc(1); *origParms = 0; for (i=0; i<argc; i++) { origParms = realloc(origParms,2 + strlen(origParms) + strlen(argv[i])); strcat(origParms," "); strcat(origParms,argv[i]); } /*--------------------------------------------------------------- * zero out info *---------------------------------------------------------------*/ memset(&info,0,sizeof(info)); /*--------------------------------------------------------------- * get options *---------------------------------------------------------------*/ GetOptions(&argc,argv,&info); /*--------------------------------------------------------------- * buffer output *---------------------------------------------------------------*/ /* setvbuf(info.oFile,NULL,_IOFBF,32000); */ /*--------------------------------------------------------------- * put filenames in a list *---------------------------------------------------------------*/ info.fileList = ListCreate(sizeof(File), (ListCompareFunc *)FileNameCompare, cPostNoMem); if (!info.fileList) cPostError(1,"error creating list of files"); for (i=1; i<argc; i++) FileSpecAdd(&info,info.fileList,argv[i]); /*--------------------------------------------------------------- * check for no files to process *---------------------------------------------------------------*/ if (!ListCount(info.fileList)) cPostError(1,"no files to process"); /*--------------------------------------------------------------- * intialize rest of info structure *---------------------------------------------------------------*/ info.funcTree = ListCreate(sizeof(Function), (ListCompareFunc *)FunctionNameCompare, cPostNoMem); if (!info.fileList) cPostError(1,"error creating list of functions"); info.identHash = HashCreate(sizeof(char *), 1000, (HashFunc *)IdentHash, (ListCompareFunc *)IdentCompare, cPostNoMem); if (!info.identHash) cPostError(1,"error creating global hash table"); /*--------------------------------------------------------------- * setup error termination processing *---------------------------------------------------------------*/ atexit(RunAtExit); signal(SIGINT, SignalHandler); signal(SIGTERM, SignalHandler); #if defined(OPSYS_OS2) || defined(OPSYS_OS2V2) signal(SIGBREAK,SignalHandler); #endif /*--------------------------------------------------------------- * print header *---------------------------------------------------------------*/ fprintf(info.oFile,"%%! PostScript file generated by %s %s\n\n", PROGRAM_NAME,PROGRAM_VERS); /*------------------------------------------------------------------ * a macro to write a line to the output file *------------------------------------------------------------------*/ #define p(x) fprintf(info.oFile,"%s\n",x); /*--------------------------------------------------------------- * write command line and environment variable setting *---------------------------------------------------------------*/ #if defined(ECHO_COMMAND_LINE) { p("%%-----------------------------------------------------------------") fprintf(info.oFile,"%%%% this file created with the command:\n"); fprintf(info.oFile,"%%%% %s\n",origParms); fprintf(info.oFile,"%%%% the CPOST environment variable "); if (!getenv(PROGRAM_ENVV)) fprintf(info.oFile,"is not set.\n"); else { fprintf(info.oFile,"is set to:\n"); fprintf(info.oFile,"%%%% %s\n",getenv(PROGRAM_ENVV)); } p("%%-----------------------------------------------------------------") p(""); } #endif /*--------------------------------------------------------------- * write wrapper prefix *---------------------------------------------------------------*/ if (info.oWrapB && strlen(info.oWrapB)) processImbedFile(info.oWrapB); /*--------------------------------------------------------------- * get the time *---------------------------------------------------------------*/ t = time(NULL); tm = localtime(&t); strftime(dateStr,sizeof(dateStr)-1,"%m/%d/%y %H:%M:%S",tm); p("%%-----------------------------------------------------------------") p("%% runtime options and values") p("%%-----------------------------------------------------------------") p("") fprintf(info.oFile,"/printDate (%s) def\n",dateStr); fprintf(info.oFile,"/oSpace %d def\n",info.oSpace); fprintf(info.oFile,"/oXlate { %d %d translate } def\n",info.oXlateX,info.oXlateY); fprintf(info.oFile,"/oDuplex 1 %d eq def\n",info.oDuplex); fprintf(info.oFile,"/oNumber 0 %d ne def\n",info.oSpace); p("") /*--------------------------------------------------------------- * write replaced header ... *---------------------------------------------------------------*/ if (info.oRepHdr && strlen(info.oRepHdr)) { processImbedFile(info.oImbed); p(""); processImbedFile(info.oRepHdr); p(""); } /*--------------------------------------------------------------- * or default stuff *---------------------------------------------------------------*/ else { for (i=0; i< sizeof(Header_1)/sizeof(char *); i++) p(Header_1[i]); p(""); processImbedFile(info.oImbed); p(""); for (i=0; i< sizeof(Header_2)/sizeof(char *); i++) p(Header_2[i]); p(""); } /*--------------------------------------------------------------- * read the files. make copies *---------------------------------------------------------------*/ fprintf(stderr,"Pass 1\n"); ListIterate(info.fileList,(ListIterateFunc *)Pass1,&info); /*--------------------------------------------------------------- * read the copies. write the output file *---------------------------------------------------------------*/ fprintf(stderr,"Pass 2\n"); ListIterate(info.fileList,(ListIterateFunc *)Pass2,&info); /*---------------------------------------------------------------* * print trailing line feed *---------------------------------------------------------------*/ fprintf(info.oFile,"\n"); /*--------------------------------------------------------------- * write wrapper suffix *---------------------------------------------------------------*/ if (info.oWrapA && strlen(info.oWrapA)) processImbedFile(info.oWrapA); /*--------------------------------------------------------------- * close file (another line feed for luck!) *---------------------------------------------------------------*/ fprintf(info.oFile,"\n"); fclose(info.oFile); AllDone = 1; return 0; }
/*------------------------------------------------------------------ * add default key words to reserved hash *------------------------------------------------------------------*/ void InitializeReservedHash( Info *info, char *keyList ) { int i; char *part; /*--------------------------------------------------------------- * create hash table *---------------------------------------------------------------*/ info->reservedHash = HashCreate(sizeof(char *), 30, (HashFunc *)IdentHash, (ListCompareFunc *)IdentCompare, cPostNoMem); if (!info->reservedHash) cPostError(1,"error creating reserved word hash table"); for (i=0; i<sizeof(ReservedTokens)/sizeof(char *); i++) if (!HashAdd(info->reservedHash,&(ReservedTokens[i]))) cPostError(1,"error adding reserved word '%s' to hash table", ReservedTokens[i]); /*--------------------------------------------------------------- * loop through the comma separated keys ... *---------------------------------------------------------------*/ part = strtok(keyList,","); while (part) { /*------------------------------------------------------------ * special c++ token *------------------------------------------------------------*/ if (!Stricmp("c++",part)) { for (i=0; i<sizeof(CppReservedTokens)/sizeof(char *); i++) if (!HashAdd(info->reservedHash,&(CppReservedTokens[i]))) cPostError(1,"error adding reserved word '%s' to hash table", CppReservedTokens[i]); } /*------------------------------------------------------------ * use Java tokens *------------------------------------------------------------*/ if (!Stricmp("java",part)) { /*------------------------------------------------------------ * remove default C tokens *------------------------------------------------------------*/ for (i=0; i<sizeof(ReservedTokens)/sizeof(char *); i++) HashDelete(info->reservedHash,&(ReservedTokens[i])); /*------------------------------------------------------------ * add Java tokens *------------------------------------------------------------*/ for (i=0; i<sizeof(JavaReservedTokens)/sizeof(char *); i++) if (!HashAdd(info->reservedHash,&(JavaReservedTokens[i]))) cPostError(1,"error adding reserved word '%s' to hash table", JavaReservedTokens[i]); } /*------------------------------------------------------------ * file name *------------------------------------------------------------*/ else if (('@' == part[0]) && (1 != strlen(part))) { TokFileInfo tfi; char *key; part++; tfi = TokFileOpen(part); if (!tfi) cPostError(0,"error opening file '%s' for reading",part); else { while (NULL != (part = TokFileNext(tfi))) { key = malloc(1 + strlen(part)); if (!key) cPostError(1,"out of memory!!"); strcpy(key,part); if (!HashAdd(info->reservedHash,&key)) cPostError(0,"error adding reserved word '%s' to hash table; word ignored", key); } } } /*------------------------------------------------------------ * plain old token *------------------------------------------------------------*/ else if (!HashAdd(info->reservedHash,&part)) { cPostError(0,"error adding reserved word '%s' to hash table; word ignored",part); } part = strtok(NULL,","); } }
//============================================================== static int objTask(sTaskBody *body, int msg, int lParam, int rParam) //-------------------------------------------------------------- // タスク処理 //-------------------------------------------------------------- // in: body = ハンドル // msg = メッセージ // lParam, rParam = 汎用パラメータ //-------------------------------------------------------------- // out: 実行結果 //============================================================== { int res = 0; switch(msg) { case MSG_CREATE: { param_hash = HashCreate("obj"); obj_link = ObjLinkCreate(sizeof(sOBJ), OBJ_NUM, MEM_SYS, FALSE); SYSINFO(".... object initialize"); } break; case MSG_KILL: { ObjDeleteParamAll(); HashKill(param_hash); ObjLinkDestroy(obj_link); SYSINFO(".... object finish"); } break; case MSG_PREPROC: { { sOBJ *obj; obj = ObjGetNext(NULL, OBJ_TYPE_ALL, NULL); while(obj) { obj->create = FALSE; obj = ObjGetNext(obj, OBJ_TYPE_ALL, NULL); } } ObjPostMsgAll(OBJ_TYPE_ALL, msg, FALSE, 0, 0); } break; case MSG_STEP: { ObjPostMsgAll(OBJ_TYPE_ALL, msg, FALSE, 0, 0); { sOBJ *obj; obj = ObjGetNext(NULL, OBJ_TYPE_ALL, NULL); while(obj) { sOBJ *next; next = ObjGetNext(obj, OBJ_TYPE_ALL, NULL); if(obj->kill_req) objDelete(obj); obj = next; } } } break; case MSG_UPDATE: { ObjPostMsgAll(OBJ_TYPE_ALL, msg, FALSE, 0, 0); } break; case MSG_DRAW: { ObjPostMsgAll(OBJ_TYPE_ALL, msg, FALSE, 0, 0); } break; default: { ObjPostMsgAll(OBJ_TYPE_ALL, msg, FALSE, lParam, rParam); } break; } return res; }