static void printAttrs( xmlAttrPtr pAttr ) { while (pAttr != NULL) { char* pzCont = (char*)pAttr->children->content; emitIndentation(); fputs( (char*)(void*)pAttr->name, outFp ); fputs( " = ", outFp ); if (pAttr->children->children == NULL) fprintf( outFp, "'%s';\n", TRIM( pzCont, NULL )); else { fputs( "{\n", outFp ); level++; if (pzCont != NULL) { emitIndentation(); fprintf( outFp, zTextFmt, TRIM( pzCont, NULL )); } printChildren( pAttr->children->children ); level--; emitIndentation(); fputs( "};\n", outFp ); } pAttr = pAttr->next; } }
static xmlNodePtr printHeader( xmlDocPtr pDoc ) { tSCC zDef[] = "AutoGen Definitions %s%s;\n"; char const* pzSfx = ".tpl"; xmlNodePtr pRootNode = xmlDocGetRootElement( pDoc ); xmlChar* pTpl = NULL; xmlChar* pzTpl; if (pRootNode == NULL) { fprintf( stderr, "Root node not found\n" ); exit( EXIT_FAILURE ); } if (HAVE_OPT( OVERRIDE_TPL )) { if (strchr( OPT_ARG( OVERRIDE_TPL ), '.' ) != NULL) pzSfx = ""; pzTpl = (xmlChar*)(void*)OPT_ARG( OVERRIDE_TPL ); } else { pTpl = xmlGetProp( pRootNode, (xmlChar*)(void*)"template" ); if (pTpl == NULL) { fprintf( stderr, "No template was specified.\n" ); exit( EXIT_FAILURE ); } pzTpl = pTpl; if (strchr( (char*)pzTpl, '.' ) != NULL) pzSfx = ""; } fprintf( outFp, zDef, pzTpl, pzSfx ); if (pTpl != NULL) free( pTpl ); if (pDoc->name != NULL) fprintf( outFp, "XML-name = '%s';\n", TRIM( pDoc->name, NULL )); if (pDoc->version != NULL) fprintf( outFp, "XML-version = '%s';\n", TRIM( pDoc->version, NULL )); if (pDoc->encoding != NULL) fprintf( outFp, "XML-encoding = '%s';\n", TRIM( pDoc->encoding, NULL )); if (pDoc->URL != NULL) fprintf( outFp, "XML-URL = '%s';\n", TRIM( pDoc->URL, NULL )); if (pDoc->standalone) fputs( "XML-standalone = true;\n", outFp ); return pRootNode; }
static void shell_cmd_config(char *args, void *data) { struct ch_switch *cfg = &config.tab_sw; struct shell_argval argval[SHELL_CMD_CONFIG_ARGS+1], *p; unsigned char t, i; unsigned int w; t = shell_arg_parser(args, argval, SHELL_CMD_CONFIG_ARGS); if (t < 1) { shell_printf("Tab switch config:\n"); shell_printf(" Mode: %d (0:ch percent; 1:flight mode; 2:ch toggle)\n", cfg->mode); shell_printf(" Ch: CH%d\n", cfg->ch + 1); shell_printf(" Min: %d\n", cfg->ch_min); shell_printf(" Max: %d\n", cfg->ch_max); shell_printf(" Time: %d00ms\n", cfg->time); shell_printf("\noptions: -m <mode> -c <ch> -l <min> -h <max> -t <time>\n"); } else { p = shell_get_argval(argval, 'm'); if (p != NULL) { i = atoi(p->val); if (i < SW_MODE_END) cfg->mode = i; } p = shell_get_argval(argval, 'c'); if (p != NULL) { i = atoi(p->val); i = TRIM(i, 0, 17); cfg->ch = i; } p = shell_get_argval(argval, 'l'); if (p != NULL) { w = atoi(p->val); w = TRIM(w, 900, 2100); cfg->ch_min = w; } p = shell_get_argval(argval, 'h'); if (p != NULL) { w = atoi(p->val); w = TRIM(w, 900, 2100); cfg->ch_max = w; } p = shell_get_argval(argval, 't'); if (p != NULL) { w = atoi(p->val); w = w / 100; cfg->time = w; } } }
///============================================================================= const std::vector<std::string> Tokenize(const std::string s, const char *delim) { std::vector<std::string> v; std::string tok; bool b=false; int p=0, pp=0; v.clear(); if (s.length() == 0) return v; p = s.find(delim, pp); while (!b) { if (p == (int) std::string::npos) { tok = s.substr(pp); b=true; } else { tok = s.substr(pp, p-pp); pp = p+1; p = s.find(delim, pp); } TRIM(tok," \""); v.push_back(tok); } return v; }
const char *acl_split_nameval(char *buf, char **name, char **value) { char *np; /* name substring */ char *vp; /* value substring */ char *cp; char *ep; /* * Ugly macros to make complex expressions less unreadable. */ #define SKIP(start, var, cond) \ for (var = start; *var && (cond); var++); #define TRIM(s) { \ char *p; \ for (p = (s) + strlen(s); p > (s) && ACL_ISSPACE(p[-1]); p--); \ *p = 0; \ } SKIP(buf, np, ACL_ISSPACE(*np)); /* find name begin */ if (*np == 0) return ("missing attribute name"); SKIP(np, ep, !ACL_ISSPACE(*ep) && *ep != '='); /* find name end */ SKIP(ep, cp, ACL_ISSPACE(*cp)); /* skip blanks before '=' */ if (*cp != '=') /* need '=' */ return ("missing '=' after attribute name"); *ep = 0; /* terminate name */ cp++; /* skip over '=' */ SKIP(cp, vp, ACL_ISSPACE(*vp)); /* skip leading blanks */ TRIM(vp); /* trim trailing blanks */ *name = np; *value = vp; return (NULL); }
static PyObject * deque_extendleft(dequeobject *deque, PyObject *iterable) { PyObject *it, *item; it = PyObject_GetIter(iterable); if (it == NULL) return NULL; while ((item = PyIter_Next(it)) != NULL) { deque->state++; if (deque->leftindex == 0) { block *b = newblock(NULL, deque->leftblock, deque->len); if (b == NULL) { Py_DECREF(item); Py_DECREF(it); return NULL; } assert(deque->leftblock->leftlink == NULL); deque->leftblock->leftlink = b; deque->leftblock = b; deque->leftindex = BLOCKLEN; } deque->len++; deque->leftindex--; deque->leftblock->data[deque->leftindex] = item; TRIM(deque, deque_pop); } Py_DECREF(it); if (PyErr_Occurred()) return NULL; Py_RETURN_NONE; }
/* * Check for the valid forms of command input which are: * * <command> [<arg1> <arg2> ... <argN>] * <name>=<value> */ static int parse(void) { TRIM(cmd); #ifdef LSH_ENABLE_USERVARS regex_t regex; const int cflags = REG_EXTENDED|REG_NEWLINE; int rc; regmatch_t pmatch[4]; // Look for patterns of the form: <name>=<value> (void)regcomp(®ex, "([a-zA-Z]+[a-zA-Z0-9]*)=(.*)", cflags); rc = regexec(®ex, cmd, SZ(pmatch), pmatch, 0); if (rc == 0) { int count = 0; token_t **tokens = tokenise_fetch(cmd, &count); symtab = symtab_set(symtab, tokens[0]->value, SYM_VAR, tokens[2]->value); tokenise_free(tokens, count); } else { /* * Not a variable setting so assume it's a command */ #endif dispatch(); #ifdef LSH_ENABLE_USERVARS } #endif RESET(cmd); // FIXME return 0; }
String auxiliary::permute(String P) { String Result; std::sort(P.begin(), P.end()); do { Result+=P+' '; } while(std::next_permutation(P.begin(),P.end())); TRIM(Result); return Result; }
int patt_copy_col(T_PkgType * dest,T_PkgType * src,const char *choose,char *idxcol) { int i,num; T_PkgType *tp,*dp; char buf[100]; const char *cp; int colnum; if(!src || !dest) return 0; tp=src; dp=dest; if(!choose||!*choose) { // 没有选择,全部加入 for(i=0;tp[i].type>=0;i++,dp++) { tp_cp(dp,tp,i); } tp_cp(dp,tp,i); return i; } num=0; cp=choose; colnum=set_offset(src); do { char *p; *buf=0; cp=stptok(skipblk((char *)cp),buf,sizeof(buf),",|"); //可以用的分隔符 p=buf; TRIM(p); if(!*p) continue; if(isdigit(*p)) { //数字选择,字段号范围 int ret,beg,end; end=beg=-1; ret=sscanf(buf,"%d - %d",&beg,&end); if(!ret) continue; if(ret==1) end=beg; if(end<beg) end=beg; for(ret=beg;ret<=end;ret++,dp++) { tp_cp(dp,tp,ret); num++; } } else { //字母,字段名 i=index_col(idxcol,colnum,p,src); if(src[i].type<0) continue; tp_cp(dp,tp,i); dp++; num++; } } while(*cp++); tp_cp(dp,tp,colnum); return num; }
static PyObject * deque_extendleft(dequeobject *deque, PyObject *iterable) { PyObject *it, *item; /* Handle case where id(deque) == id(iterable) */ if ((PyObject *)deque == iterable) { PyObject *result; PyObject *s = PySequence_List(iterable); if (s == NULL) return NULL; result = deque_extendleft(deque, s); Py_DECREF(s); return result; } it = PyObject_GetIter(iterable); if (it == NULL) return NULL; if (deque->maxlen == 0) return consume_iterator(it); while ((item = PyIter_Next(it)) != NULL) { deque->state++; if (deque->leftindex == 0) { block *b = newblock(NULL, deque->leftblock, deque->len); if (b == NULL) { Py_DECREF(item); Py_DECREF(it); return NULL; } assert(deque->leftblock->leftlink == NULL); deque->leftblock->leftlink = b; deque->leftblock = b; deque->leftindex = BLOCKLEN; } deque->len++; deque->leftindex--; deque->leftblock->data[deque->leftindex] = item; TRIM(deque, deque_pop); } Py_DECREF(it); if (PyErr_Occurred()) return NULL; Py_RETURN_NONE; }
static PyObject * deque_append(dequeobject *deque, PyObject *item) { deque->state++; if (deque->rightindex == BLOCKLEN-1) { block *b = newblock(deque->rightblock, NULL, deque->len); if (b == NULL) return NULL; assert(deque->rightblock->rightlink == NULL); deque->rightblock->rightlink = b; deque->rightblock = b; deque->rightindex = -1; } Py_INCREF(item); deque->len++; deque->rightindex++; deque->rightblock->data[deque->rightindex] = item; TRIM(deque, deque_popleft); Py_RETURN_NONE; }
static PyObject * deque_appendleft(dequeobject *deque, PyObject *item) { deque->state++; if (deque->leftindex == 0) { block *b = newblock(NULL, deque->leftblock, deque->len); if (b == NULL) return NULL; assert(deque->leftblock->leftlink == NULL); deque->leftblock->leftlink = b; deque->leftblock = b; deque->leftindex = BLOCKLEN; } Py_INCREF(item); deque->len++; deque->leftindex--; deque->leftblock->data[deque->leftindex] = item; TRIM(deque, deque_pop); Py_RETURN_NONE; }
static char *read_param_from_file(const char *path) { VSTRING *why = vstring_alloc(100); VSTRING *buf = vstring_alloc(100); VSTREAM *fp; char *bp; char *result; /* * Ugly macros to make complex expressions less unreadable. */ #define SKIP(start, var, cond) do { \ for (var = start; *var && (cond); var++) \ /* void */; \ } while (0) #define TRIM(s) do { \ char *p; \ for (p = (s) + strlen(s); p > (s) && ISSPACE(p[-1]); p--) \ /* void */; \ *p = 0; \ } while (0) fp = safe_open(path, O_RDONLY, 0, (struct stat *) 0, -1, -1, why); if (fp == 0) msg_fatal("%s: %s", path, vstring_str(why)); vstring_get_nonl(buf, fp); if (vstream_ferror(fp)) /* FIX 20070501 */ msg_fatal("%s: read error: %m", path); vstream_fclose(fp); SKIP(vstring_str(buf), bp, ISSPACE(*bp)); TRIM(bp); result = mystrdup(bp); vstring_free(why); vstring_free(buf); return (result); }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void SJ_ReloadConfiguration( ) { swprintf_s( g_txt, L"%s/%s", g_skin, CONFIG_FILE ); FILE* f = _wfopen( g_txt, L"rt" ); if ( !f ) return; wchar_t* ptr; int skip = 0; float* tgtKey; while ( !feof(f) ) { fgetws( g_txt, sizeof(g_txt)/sizeof(wchar_t), f ); ptr = g_txt; SKIP_BLANKS(ptr); // skip line starting blanks if ( *ptr == COMMENT_TOKEN ) continue; // comments TRIM(ptr); // right trim tgtKey = NULL; if ( _wcsnicmp( ptr, L"topBounce", 9 ) == 0 ) { tgtKey=&g_topBounce; skip=9; } else if ( _wcsnicmp( ptr, L"lateralBounce", 13 ) == 0 ) { tgtKey=&g_lateralBounce; skip=13; } else if ( _wcsnicmp( ptr, L"bottomBounce", 12 ) == 0 ) { tgtKey=&g_bottomBounce; skip=12; } else if ( _wcsnicmp( ptr, L"boostForce", 10 ) == 0 ) { tgtKey=&g_boostForce; skip=10; } else if ( _wcsnicmp( ptr, L"lateralForce", 12 ) == 0 ) { tgtKey=&g_lateralForce; skip=12; } else if ( _wcsnicmp( ptr, L"lateralFriction", 15 ) == 0){ tgtKey=&g_lateralFriction; skip=15; } else if ( _wcsnicmp( ptr, L"gravityFactor", 13 ) == 0 ) { tgtKey=&g_gravTimeFactor; skip=13; } else if ( _wcsnicmp( ptr, L"gravity", 7 ) == 0 ) { tgtKey=&g_gravity; skip=7; } else if ( _wcsnicmp( ptr, L"lives", 5 ) == 0 ) { ptr+=5; SKIP_BLANKS(ptr); g_livesMax = (char)::_wtol(ptr); } // else if ( _wcsnicmp( ptr, L"players", 7 ) == 0 ) { ptr+=7; SKIP_BLANKS(ptr); g_nPlayers = (char)::_wtol(ptr); } else if ( _wcsnicmp( ptr, L"fontName", 8) == 0 ) { ptr+=8; SKIP_BLANKS(ptr); wcscpy_s( g_fontName, ptr ); } else if ( _wcsnicmp( ptr, L"fontSize", 8) == 0 ) { ptr+=8; SKIP_BLANKS(ptr); g_fontSize = (char)::_wtol(ptr); } if ( tgtKey ) { ptr+=skip; // jump to value SKIP_BLANKS(ptr); *tgtKey = (float)::_wtof(ptr); } } }
/*! \param String */ char * xbExpn::RTRIM( const char * String ) { return TRIM( String ); }
JSON_OBJECT stu_to_json(JSON_OBJECT json,void *data,T_PkgType * typ,const char *choose,char *colidx) { int i,colnum,n; T_PkgType *tp; char buf[100]; const char *cp; if(!json) return json; colnum=set_offset(typ); tp=typ; if(!choose||!*choose) { // 没有选择,全部加入 for(i=0;tp->type>=0;i++,tp++) { if(tp->bindtype & NOSELECT) continue; if(choose&&isnull((char *)data+tp->offset,tp->type)) continue; if(tp->type==CH_STRUCT) { JSON_OBJECT sub=json_object_new_object(); stu_to_json(sub,(char *)data+tp->offset, (T_PkgType *)tp->format,0,0); json_object_object_add(json,plain_name(tp->name),sub); continue; } add_field_to_object(json,data,tp); } return json; } cp=choose; do { char *p; *buf=0; cp=stptok(skipblk((char *)cp),buf,sizeof(buf),",|"); //可以用的分隔符 p=buf; TRIM(p); if(!*p) continue; if(isdigit(*p)) { //数字选择,字段号范围:"1-3,6-11" int ret,beg,end; end=beg=-1; ret=sscanf(buf,"%d - %d",&beg,&end); if(!ret) continue; if(ret==1) end=beg; if(end<beg) end=beg; for(ret=beg;ret<=end;ret++) { if(typ[ret].type==CH_STRUCT) { JSON_OBJECT sub=json_object_new_object(); stu_to_json(sub,(char *)data+typ[ret].offset, (T_PkgType *)typ[ret].format,0,0); json_object_object_add(json,plain_name(typ[ret].name),sub); continue; } add_field_to_object(json,data,&typ[ret]); } } else { //字母,字段名 :"colname1,colname2,..." n=index_col(colidx,colnum,p,typ); if(n<0) continue; if(typ[n].type==CH_STRUCT) { JSON_OBJECT sub=json_object_new_object(); stu_to_json(sub,(char *)data+typ[n].offset, (T_PkgType *)typ[n].format,0,0); json_object_object_add(json,plain_name(typ[n].name),sub); continue; } add_field_to_object(json,data,typ+n); } } while(*cp++); return json; }
int login(T_Connect *conn,T_NetHead *NetHead) { int ret,crc; char tmp[200]; char *cp,*key; char tmp1[1024],cliaddr[20]; DWS dw; struct login_s logrec; ENIGMA egm; FILE *fd; T_SRV_Var *up; GDA *gp; //u_int e[RSALEN],m[RSALEN]; up=(T_SRV_Var *)conn->Var; gp=(GDA *)up->var; StrAddr(NetHead->O_NODE,cliaddr); ShowLog(5,"%s:TCB:%d Client IP Addr=%s,Net_login %s",__FUNCTION__,up->TCB_no,cliaddr,NetHead->data); net_dispack(&logrec,NetHead->data,login_type); strcpy(gp->devid,logrec.devid); sprintf(gp->ShowID,"%s:%s:%d",logrec.devid,cliaddr,up->TCB_no); mthr_showid_add(up->tid,gp->ShowID); conn->MTU=NetHead->ERRNO1; cp=getenv("KEYFILE"); if(!cp||!*cp) { strcpy(tmp1,"缺少环境变量 KEYFILE"); errret: ShowLog(1,"%s:Error %s",__FUNCTION__,tmp1); NetHead->ERRNO1=-1; NetHead->ERRNO2=-1; NetHead->PKG_REC_NUM=0; NetHead->data=tmp1; NetHead->PKG_LEN=strlen(NetHead->data); SendPack(conn,NetHead); return 0; // fail } /* read key */ crc=0; reopen: ret=initdw(cp,&dw); if(ret) { if((errno==24)&& (++crc<5)) { sleep(15); goto reopen; } sprintf(tmp1,"Init dw error %d",ret); goto errret; } crc=ssh_crc32((unsigned char *)logrec.devid,strlen(logrec.devid)); key=getdw(crc,&dw); if(!key) { freedw(&dw); sprintf(tmp1,"无效的 DEVID"); goto errret; } //ShowLog(5,"getdw key=%s",key); enigma1_init(egm,key); /* check CA */ memset(gp->operid,0,sizeof(gp->operid)); cp=getenv("CADIR"); if(!cp||!*cp) cp="."; if(strcmp(gp->devid,"REGISTER")) { strncpy(gp->operid,logrec.uid,sizeof(gp->operid)-1); sprintf(tmp,"%s/%s.CA",cp,logrec.devid); //ShowLog(5,"CAfile=%s,key=%s",tmp,key); fd=fopen(tmp,"r"); if(!fd) { if(errno==2) { crc=strlen(logrec.CA); frenz_encode(egm,logrec.CA,crc); byte_a64(tmp1,logrec.CA,crc); //ShowLog(5,"CA=%s",tmp1); fd=fopen(tmp,"w"); if(!fd) { sprintf(tmp1,"write %s err=%d",tmp,errno); err1: freedw(&dw); goto errret; } fprintf(fd,"%s\n",tmp1); fclose(fd); } else { sprintf(tmp1,"open CAfile %s err=%d",tmp,errno); goto err1; } } else { fgets(tmp1,sizeof(logrec.CA),fd); fclose(fd); TRIM(tmp1); ret=a64_byte(tmp,tmp1); frenz_decode(egm,tmp,ret); tmp[ret]=0; if(strcmp(tmp,logrec.CA)) { sprintf(tmp1,"CA 错误"); ShowLog(1,"%s:%s CA=%s log=%s len=%d",__FUNCTION__,tmp1,tmp,logrec.CA,ret); goto err1; } } } else { //未注册客户端注册 char *p; char *keyD; /* REGISTER label|CA|devfile|CHK_Code| */ ShowLog(2,"REGISTER %s",logrec.uid); if(!*logrec.uid) { sprintf(tmp1,"REGSTER is empty!"); goto err1; } //uid=devfile crc=0xFFFF&gencrc((unsigned char *)logrec.uid,strlen(logrec.uid)); //pwd=CHK_Code sscanf(logrec.pwd,"%04X",&ret); ret &= 0xFFFF; if(ret != crc) { sprintf(tmp1,"REGISTER:devfile CHK Code error! ");//, crc,ret); goto err1; } p=stptok(logrec.uid,logrec.devid,sizeof(logrec.devid),".");//logrec.devid=准备注册的DEVID crc=ssh_crc32((unsigned char *)logrec.devid,strlen(logrec.devid)); keyD=getdw(crc,&dw); if(!keyD) { sprintf(tmp1,"注册失败,%s:没有这个设备!", logrec.devid); goto err1; } enigma1_init(egm,keyD); sprintf(tmp,"%s/%s.CA",cp,logrec.devid); ShowLog(5,"REGISTER:%s",tmp); if(0!=(fd=fopen(tmp,"r"))) { fgets(tmp1,81,fd); fclose(fd); TRIM(tmp1); ret=a64_byte(tmp,tmp1); frenz_decode(egm,tmp,ret); tmp[ret]=0; if(strcmp(tmp,logrec.CA)) { sprintf(tmp1,"注册失败,%s 已被注册,使用中。", logrec.devid); goto err1; } } else if(errno != 2) { sprintf(tmp1,"CA 错误"); goto err1; } /*把设备特征码写入文件*/ fd=fopen(tmp,"w"); if(fd) { int len=strlen(logrec.CA); frenz_encode(egm,logrec.CA,len); byte_a64(tmp1,logrec.CA,len); fprintf(fd,"%s\n",tmp1); fclose(fd); } else ShowLog(1,"net_login:REGISTER open %s for write,err=%d,%s", tmp,errno,strerror(errno)); freedw(&dw); sprintf(tmp,"%s/%s",cp,logrec.uid); fd=fopen(tmp,"r"); if(!fd) { sprintf(tmp1,"REGISTER 打不开文件 %s err=%d,%s", logrec.CA,errno,strerror(errno)); goto errret; } fgets(logrec.uid,sizeof(logrec.uid),fd); TRIM(logrec.uid); ShowLog(2,"REGISTER open %s",tmp); fclose(fd); cp=tmp1; cp+=sprintf(cp,"%s|%s|", logrec.devid,logrec.uid); cp+=sprintf(cp,"%s|",rsecstrfmt(tmp,now_sec(),YEAR_TO_SEC)); NetHead->data=tmp1; NetHead->PKG_LEN=strlen(NetHead->data); NetHead->ERRNO1=0; NetHead->ERRNO2=0; NetHead->PKG_REC_NUM=0; SendPack(conn,NetHead); return -1; } //未注册客户端注册完成 freedw(&dw); up->poolno=get_scpool_no(NetHead->D_NODE); if(up->poolno<0) { sprintf(tmp1,"非法的D_NODE %d",NetHead->D_NODE); goto errret; } ret=get_s_connect(up->TCB_no,up->poolno,&gp->server,login_finish); if(ret==0) return login_finish(conn,NetHead); else if(ret==1) return -5; sprintf(tmp1,"错误的参数"); goto errret; }
/* Create a triple store from a file */ int ocdodsrc_read(char* basename, char* path) { char line0[MAXRCLINESIZE]; FILE *in_file = NULL; int linecount = 0; struct OCTriplestore* ocdodsrc = ocglobalstate.ocdodsrc; if(ocdodsrc == NULL) { ocdodsrc = (struct OCTriplestore*)malloc(sizeof(struct OCTriplestore)); if(ocdodsrc == NULL) { oclog(OCLOGERR,"ocdodsrc_read: out of memory"); return 0; } ocglobalstate.ocdodsrc = ocdodsrc; } ocdodsrc->ntriples = 0; in_file = fopen(path, "r"); /* Open the file to read it */ if (in_file == NULL) { oclog(OCLOGERR, "Could not open configuration file: %s",basename); return OC_EPERM; } for(;;) { char *line,*key,*value; if(!rcreadline(in_file,line0,sizeof(line0))) break; linecount++; if(linecount >= MAXRCLINES) { oclog(OCLOGERR, ".dodsrc has too many lines"); return 0; } line = line0; /* check for comment */ if (line[0] == '#') continue; /* trim leading blanks */ line = rctrimleft(line,TRIMCHARS); if(strlen(line) >= MAXRCLINESIZE) { oclog(OCLOGERR, "%s line too long: %s",basename,line0); return 0; } /* parse the line */ ocdodsrc->triples[ocdodsrc->ntriples].url[0] = '\0'; /*assume no url*/ if(line[0] == LTAG) { char* url = ++line; char* rtag = strchr(line,RTAG); if(rtag == NULL) { oclog(OCLOGERR, "Malformed [url] in %s entry: %s",basename,line); continue; } line = rtag + 1; *rtag = '\0'; /* trim again */ line = rctrimleft(line,TRIMCHARS); /* save the url */ strncpy(ocdodsrc->triples[ocdodsrc->ntriples].url,TRIM(url),strlen(url)); } if(strlen(line)==0) continue; /* empty line */ /* split off key and value */ key=line; value = strchr(line, '='); if(value == NULL) { /* add fake '=1' */ if(strlen(line) + strlen("=1") >= MAXRCLINESIZE) { oclog(OCLOGERR, "%s entry too long: %s",basename,line); continue; } strcat(line,"=1"); value = strchr(line,'='); } *value = '\0'; value++; strncpy(ocdodsrc->triples[ocdodsrc->ntriples].key,TRIM(key),strlen(key)); strncpy(ocdodsrc->triples[ocdodsrc->ntriples].value,TRIM(value),strlen(value)); ocdodsrc->ntriples++; } fclose(in_file); sorttriplestore(); return 1; }
/* str: local_filename remodt_filename */ void putlist(T_Connect *conn,char *str) { char lpath[512],*dir,*rmtp; char *filename; DIR *dirp; struct dirent *direp; regex_t reg; regmatch_t pmatch[2]; int ret; char errbuf[1024],rmtbuf[1024]; TRIM(str); if(!*str) return; rmtp=stptok(str,lpath,sizeof(lpath)," "); substitute_env(lpath); if(*rmtp) rmtp=skipblk(rmtp); if(!*rmtp) rmtp="$/"; // filename=basename(lpath); filename=strrchr(lpath,'/'); if(filename) { *filename++=0; dir=lpath; if(!*dir) dir="/"; if(!*filename) strcpy(filename,"*"); } else { filename=lpath; dir="."; } ShowLog(5,"dir=%s,name=%s:\n",dir,filename); ret=sh2reg(filename); if(0!=(ret=regcomp(®,filename,REG_NOSUB))) { regerror(ret,®,errbuf,sizeof(errbuf)); ShowLog(1,"filename %s regcomp err=%s",filename,errbuf); return; } if(!(dirp=opendir(dir))) { ShowLog(1,"putls opendir %s err %d",dir,errno); regfree(®); return; } while(NULL != (direp=readdir(dirp))) { strcpy(errbuf,dir); ret=regexec(®,direp->d_name,1,pmatch,0); if(!ret) { /* send file to server */ if(dir[strlen(dir)-1]=='/') sprintf(errbuf,"%s%s",dir,direp->d_name); else sprintf(errbuf,"%s/%s",dir,direp->d_name); if(isrfile(errbuf)>0){ if(rmtp[strlen(rmtp)-1]=='/') sprintf(rmtbuf,"%s%s", rmtp,basename(direp->d_name)); else sprintf(rmtbuf,"%s/%s", rmtp,basename(direp->d_name)); ret=NZ_Put_File(conn,errbuf,rmtbuf); if(ret) ShowLog(1,"putlist:%s %s,ret=%d", errbuf,rmtbuf,ret); else { printf("%s\n",errbuf); ShowLog(2,"NZ_PutFile %s to %s succeed!", errbuf,rmtbuf); } if(ret<0) break; } } } /* if(errno) { ShowLog(1,"putlist %s err=%d",errbuf,errno); } */ closedir(dirp); regfree(®); return; }
static void printNode( xmlNodePtr pNode ) { switch (pNode->type) { case XML_ELEMENT_NODE: { size_t sz; char* pzTxt; emitIndentation(); fputs( (char*)(void*)pNode->name, outFp ); pzTxt = TRIM( pNode->content, &sz ); if ( (pNode->properties == NULL) && (pNode->children == NULL)) { if (sz == 0) fputs( ";\n", outFp ); else fprintf( outFp, " = '%s';\n", pzTxt ); break; } fputs( " = {\n", outFp ); level++; emitIndentation(); fprintf( outFp, "content = '%s';\n", pzTxt ); printAttrs( pNode->properties ); printChildren( pNode->children ); level--; emitIndentation(); fputs( "};\n", outFp ); break; } case XML_ATTRIBUTE_NODE: fputs( "Misplaced attribute\n", outFp ); exit( EXIT_FAILURE ); case XML_TEXT_NODE: { size_t sz; char* pzTxt = TRIM( pNode->content, &sz ); if (sz == 0) break; emitIndentation(); fprintf( outFp, zTextFmt, pzTxt ); break; } case XML_COMMENT_NODE: { size_t sz; char* pzTxt = TRIM( pNode->content, &sz ); if (sz == 0) break; emitIndentation(); fputs( "/* ", outFp ); for (;;) { char* pz = strstr( pzTxt, "*/" ); if (pz == NULL) break; fwrite(pzTxt, (size_t)((pz - pzTxt) + 1), (size_t)1, outFp); pzTxt = pz+1; fputc( ' ', outFp ); } fprintf( outFp, "%s */\n", pzTxt ); break; } case XML_CDATA_SECTION_NODE: case XML_ENTITY_REF_NODE: case XML_ENTITY_NODE: case XML_PI_NODE: case XML_DOCUMENT_NODE: case XML_HTML_DOCUMENT_NODE: case XML_DOCUMENT_TYPE_NODE: case XML_DOCUMENT_FRAG_NODE: case XML_NOTATION_NODE: case XML_DTD_NODE: case XML_ELEMENT_DECL: case XML_ATTRIBUTE_DECL: case XML_ENTITY_DECL: case XML_NAMESPACE_DECL: case XML_XINCLUDE_START: case XML_XINCLUDE_END: emitIndentation(); fprintf( outFp, "/* Unsupported XML node type: %s */\n", typeName[ pNode->type ]); break; default: emitIndentation(); fprintf( outFp, "/* Unknown XML node type %d */\n", pNode->type ); break; } }
int ocdodsrc_process(OCstate* state) { int stat = 0; char* value; char* url = ocuribuild(state->uri,NULL,NULL,OCURIENCODE); struct OCTriplestore* ocdodsrc = ocglobalstate.ocdodsrc; if(ocdodsrc == NULL) goto done; value = curllookup("DEFLATE",url); if(value != NULL) { if(atoi(value)) state->curlflags.compress = 1; if(ocdebug > 0) oclog(OCLOGNOTE,"Compression: %ld", state->curlflags.compress); } if((value = curllookup("VERBOSE",url)) != NULL) { if(atoi(value)) state->curlflags.verbose = 1; if(ocdebug > 0) oclog(OCLOGNOTE,"curl.verbose: %ld", state->curlflags.verbose); } if((value = curllookup("TIMEOUT",url)) != NULL) { if(atoi(value)) state->curlflags.timeout = atoi(value); if(ocdebug > 0) oclog(OCLOGNOTE,"curl.timeout: %ld", state->curlflags.timeout); } if((value = curllookup("USERAGENT",url)) != NULL) { if(atoi(value)) state->curlflags.useragent = strdup(TRIM(value)); if(!state->curlflags.useragent) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"USERAGENT: %s", state->curlflags.useragent); } if((value = curllookup("COOKIEFILE",url)) != NULL) { state->curlflags.cookiefile = strdup(TRIM(value)); if(!state->curlflags.cookiefile) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"COOKIEFILE: %s", state->curlflags.cookiefile); } if((value = curllookup("COOKIEJAR",url)) || (value = curllookup("COOKIE_JAR",url))) { state->curlflags.cookiejar = strdup(TRIM(value)); if(!state->curlflags.cookiejar) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"COOKIEJAR: %s", state->curlflags.cookiejar); } /* Some servers (e.g. thredds) appear to require a place to put cookies in order for some security functions to work */ if(state->curlflags.cookiejar == NULL && state->curlflags.cookiefile == NULL) { state->curlflags.cookiefile = strdup(""); } if((value = curllookup("PROXY_SERVER",url)) != NULL) { stat = parseproxy(state,TRIM(value)); if(stat != OC_NOERR) goto done; } if((value = curllookup("SSL.VALIDATE",url)) != NULL) { if(atoi(value)) state->ssl.validate = 1; if(ocdebug > 0) oclog(OCLOGNOTE,"CURL.SSL.VALIDATE: %ld", state->ssl.validate); } if((value = curllookup("SSL.CERTIFICATE",url)) != NULL) { state->ssl.certificate = strdup(TRIM(value)); if(!state->ssl.certificate) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"CREDENTIALS.SSL.CERTIFICATE: %s", state->ssl.certificate); } if((value = curllookup("SSL.KEY",url)) != NULL) { state->ssl.key = strdup(TRIM(value)); if(!state->ssl.key) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"CREDENTIALS.SSL.KEY: %s", state->ssl.key); } if((value = curllookup("SSL.KEYPASSWORD",url)) != NULL) { state->ssl.keypasswd = strdup(TRIM(value)); if(!state->ssl.keypasswd) {stat = OC_ENOMEM; goto done;} #ifdef INSECURE if(ocdebug > 0) oclog(OCLOGNOTE,"CREDENTIALS.SSL.KEYPASSWORD: %s", state->ssl.keypasswd); #endif } if((value = curllookup("SSL.CAINFO",url)) != NULL) { state->ssl.cainfo = strdup(TRIM(value)); if(!state->ssl.cainfo) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"SSL.CAINFO: %s", state->ssl.cainfo); } if((value = curllookup("SSL.CAPATH",url)) != NULL) { state->ssl.capath = strdup(TRIM(value)); if(!state->ssl.capath) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"SSL.CAPATH: %s", state->ssl.capath); } if((value = curllookup("SSL.VERIFYPEER",url)) != NULL) { char* s = strdup(TRIM(value)); int tf = 0; if(s == NULL || strcmp(s,"0")==0 || strcasecmp(s,"false")==0) tf = 0; else if(strcmp(s,"1")==0 || strcasecmp(s,"true")==0) tf = 1; else tf = 1; /* default if not null */ state->ssl.verifypeer = tf; if(ocdebug > 0) oclog(OCLOGNOTE,"SSL.VERIFYPEER: %d", state->ssl.verifypeer); } if((value = curllookup("CREDENTIALS.USER",url)) != NULL) { state->creds.username = strdup(TRIM(value)); if(!state->creds.username) {stat = OC_ENOMEM; goto done;} if(ocdebug > 0) oclog(OCLOGNOTE,"CREDENTIALS.USER: %s", state->creds.username); } if((value = curllookup("CREDENTIALS.PASSWORD",url)) != NULL) { state->creds.password = strdup(TRIM(value)); if(!state->creds.password) {stat = OC_ENOMEM; goto done;} } /* else ignore */ done: if(url != NULL) free(url); return stat; }
/*! \param Func */ xbShort xbExpn::ProcessFunction( char * Func ) { /* 1 - pop function from stack 2 - verify function name and get no of parms needed 3 - verify no of parms >= remainder of stack 4 - pop parms off stack 5 - execute function 6 - push result back on stack */ char *buf = 0; xbExpNode *p1, *p2, *p3, *WorkNode, *FuncNode; xbShort ParmsNeeded,len; char ptype = 0; /* process type s=string, l=logical, d=double */ xbDouble DoubResult = 0; xbLong IntResult = 0; FuncNode = (xbExpNode *) Pop(); ParmsNeeded = GetFuncInfo( Func, 1 ); if( ParmsNeeded == -1 ) { return XB_INVALID_FUNCTION; } else { ParmsNeeded = 0; if( FuncNode->Sibling1 ) ParmsNeeded++; if( FuncNode->Sibling2 ) ParmsNeeded++; if( FuncNode->Sibling3 ) ParmsNeeded++; } if( ParmsNeeded > GetStackDepth()) return XB_INSUFFICIENT_PARMS; p1 = p2 = p3 = NULL; if( ParmsNeeded > 2 ) p3 = (xbExpNode *) Pop(); if( ParmsNeeded > 1 ) p2 = (xbExpNode *) Pop(); if( ParmsNeeded > 0 ) p1 = (xbExpNode *) Pop(); memset( WorkBuf, 0x00, WorkBufMaxLen+1); if( strncmp( Func, "ABS", 3 ) == 0 ) { ptype = 'd'; DoubResult = ABS( GetDoub( p1 )); } else if( strncmp( Func, "ASC", 3 ) == 0 ) { ptype = 'd'; DoubResult = ASC( p1->StringResult ); } else if( strncmp( Func, "AT", 2 ) == 0 ) { ptype = 'd'; DoubResult = AT( p1->StringResult, p2->StringResult ); } else if( strncmp( Func, "CDOW", 4 ) == 0 ) { ptype = 's'; buf = CDOW( p1->StringResult ); } else if( strncmp( Func, "CHR", 3 ) == 0 ) { ptype = 's'; buf = CHR( GetInt( p1 )); } else if( strncmp( Func, "CMONTH", 6 ) == 0 ) { ptype = 's'; buf = CMONTH( p1->StringResult ); } else if( strncmp( Func, "CTOD", 4 ) == 0 ) { ptype = 's'; buf = CTOD( p1->StringResult ); } else if( strncmp( Func, "DATE", 4 ) == 0 ) { ptype = 's'; buf = DATE(); } else if( strncmp( Func, "DAY", 3 ) == 0 ) { ptype = 'd'; DoubResult = DAY( p1->StringResult ); } else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'C' ) { ptype = 's'; buf = DESCEND( p1->StringResult.c_str() ); } else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'N' ) { ptype = 'd'; DoubResult = DESCEND( GetDoub( p1 )); } else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'D' ) { xbDate d( p1->StringResult ); ptype = 'd'; DoubResult = DESCEND( d ); } else if( strncmp( Func, "DOW", 3 ) == 0 ) { ptype = 'd'; DoubResult = DOW( p1->StringResult ); } else if( strncmp( Func, "DTOC", 4 ) == 0 ) { ptype = 's'; buf = DTOC( p1->StringResult ); } else if( strncmp( Func, "DTOS", 4 ) == 0 ) { ptype = 's'; buf = DTOS( p1->StringResult ); } else if( strncmp( Func, "EXP", 3 ) == 0 ) { ptype = 'd'; DoubResult = EXP( GetDoub( p1 )); } else if( strncmp( Func, "IIF", 3 ) == 0 ){ ptype = 's'; buf = IIF( p1->IntResult, p2->StringResult, p3->StringResult ); } else if( strncmp( Func, "INT", 3 ) == 0 ) { ptype = 'd'; DoubResult = INT( GetDoub( p1 )); } else if( strncmp( Func, "ISALPHA", 7 ) == 0 ) { ptype = 'l'; IntResult = ISALPHA( p1->StringResult ); } else if( strncmp( Func, "ISLOWER", 7 ) == 0 ) { ptype = 'l'; IntResult = ISLOWER( p1->StringResult ); } else if( strncmp( Func, "ISUPPER", 7 ) == 0 ) { ptype = 'l'; IntResult = ISUPPER( p1->StringResult ); } else if( strncmp( Func, "LEN", 3 ) == 0 ) { ptype = 'd'; DoubResult = LEN( p1->StringResult ); } else if( strncmp( Func, "LEFT", 4 ) == 0 ) { ptype = 's'; buf = LEFT( p1->StringResult, INT( p2->DoubResult )); } else if( strncmp( Func, "LTRIM", 5 ) == 0 ) { ptype = 's'; buf = LTRIM( p1->StringResult ); } else if( strncmp( Func, "LOG", 3 ) == 0 ) { ptype = 'd'; DoubResult = LOG( GetDoub( p1 )); } else if( strncmp( Func, "LOWER", 5 ) == 0 ) { ptype = 's'; buf = LOWER( p1->StringResult ); } else if( strncmp( Func, "MAX", 3 ) == 0 ) { ptype = 'd'; DoubResult = MAX( GetDoub( p1 ), GetDoub( p2 )); } else if( strncmp( Func, "MIN", 3 ) == 0 ) { ptype = 'd'; DoubResult = MIN( GetDoub( p1 ), GetDoub( p2 )); } else if( strncmp( Func, "MONTH", 5 ) == 0 ) { ptype = 'd'; DoubResult = MONTH( p1->StringResult ); } else if( strncmp( Func, "RECNO", 5 ) == 0 ) { ptype = 'd'; DoubResult = RECNO( FuncNode->dbf ); } else if( strncmp( Func, "REPLICATE", 9 ) == 0 ) { ptype = 's'; buf = REPLICATE( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "RIGHT", 5 ) == 0 ) { ptype = 's'; buf = RIGHT( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "RTRIM", 5 ) == 0 ) { ptype = 's'; buf = RTRIM( p1->StringResult ); } else if( strncmp( Func, "SPACE", 5 ) == 0 ) { ptype = 's'; buf = SPACE( INT( GetDoub( p1 ))); } else if( strncmp( Func, "SQRT", 4 ) == 0 ) { ptype = 'd'; DoubResult = SQRT( GetDoub( p1 )); } else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 1 ) { ptype = 's'; buf = STRZERO( p1->StringResult ); } else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 2 ) { ptype = 's'; buf = STRZERO( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 3 ) { ptype = 's'; buf = STRZERO( p1->StringResult, GetInt( p2 ), GetInt( p3 )); } else if( strncmp( Func, "STR", 3 ) == 0 && p3 ) { ptype = 's'; if(p1->ExpressionType == 'N') buf = STR( p1->DoubResult, GetInt( p2 ), GetInt( p3 )); else buf = STR( p1->StringResult, GetInt( p2 ), GetInt( p3 )); } else if( strncmp( Func, "STR", 3 ) == 0 && p2 ) { ptype = 's'; buf = STR( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "STR", 3 ) == 0 && p1 ) { ptype = 's'; buf = STR( p1->StringResult ); } else if( strncmp( Func, "SUBSTR", 6 ) == 0 ) { ptype = 's'; buf = SUBSTR( p1->StringResult, GetInt( p2 ), GetInt( p3 )); } else if( strncmp( Func, "TRIM", 4 ) == 0 ) { ptype = 's'; buf = TRIM( p1->StringResult ); } else if( strncmp( Func, "UPPER", 5 ) == 0 ) { ptype = 's'; buf = UPPER( p1->StringResult ); } else if( strncmp( Func, "VAL", 3 ) == 0 ) { ptype = 'd'; DoubResult = VAL( p1->StringResult ); } else if( strncmp( Func, "YEAR", 4 ) == 0 ) { ptype = 'd'; DoubResult = YEAR( p1->StringResult ); } if( p1 && !p1->InTree ) delete p1; if( p2 && !p2->InTree ) delete p2; if( p3 && !p3->InTree ) delete p3; if( !FuncNode->InTree ) delete FuncNode; if( buf ){ len = strlen( buf ); WorkNode = new xbExpNode; if( !WorkNode ) return XB_NO_MEMORY; WorkNode->ResultLen = len + 1; } else { len = 0; WorkNode = new xbExpNode; if( !WorkNode ) return XB_NO_MEMORY; WorkNode->ResultLen = 0; } switch( ptype ){ case 's': /* string or char result */ WorkNode->DataLen = len; WorkNode->ExpressionType = 'C'; WorkNode->Type = 's'; WorkNode->StringResult = buf; break; case 'd': /* numeric result */ WorkNode->DataLen = 0; WorkNode->ExpressionType = 'N'; WorkNode->Type = 'd'; WorkNode->DoubResult = DoubResult; break; case 'l': /* logical result */ WorkNode->DataLen = 0; WorkNode->ExpressionType = 'L'; WorkNode->Type = 'l'; WorkNode->IntResult = IntResult; break; default: std::cout << "\nInternal error. " << ptype; break; } Push(WorkNode); return XB_NO_ERROR; }
int AmConfigReader::loadString(const char* cfg_lines, size_t cfg_len) { int lc = 0; int ls = 0; char lb[MAX_CONFIG_LINE] = {'\0'}; char *c,*key_beg,*key_end,*val_beg,*val_end,*inc_beg,*inc_end; const char* cursor = cfg_lines; const char* cfg_end = cursor + cfg_len; c=key_beg=key_end=val_beg=val_end=inc_beg=inc_end=0; while((cursor < cfg_end) && ((ls = str_get_line(&cursor, cfg_end, lb, MAX_CONFIG_LINE)) != -1)){ c=key_beg=key_end=val_beg=val_end=0; lc++; c = lb; TRIM(c); if(IS_EOL(*c)) continue; key_beg = c; while( (*c != '=') && !IS_SPACE(*c) ) c++; key_end = c; if(IS_SPACE(*c)) TRIM(c); else if( !(c - key_beg) ) goto syntax_error; if(*c != '=') goto syntax_error; c++; TRIM(c); if(*c == '"'){ char last_c = ' '; val_beg = ++c; while( ((*c != '"') || (last_c == '\\')) && (*c != '\0') ) { last_c = *c; c++; } if(*c == '\0') goto syntax_error; val_end = c; } else { val_beg = c; while( !IS_EOL(*c) && !IS_SPACE(*c) ) c++; val_end = c; } if((key_beg < key_end) && (val_beg <= val_end)) { string keyname = string(key_beg,key_end-key_beg); string val = string(val_beg,val_end-val_beg); if (hasParameter(keyname)) { WARN("while loading string: overwriting configuration " "'%s' value '%s' with '%s'\n", keyname.c_str(), getParameter(keyname).c_str(), val.c_str()); } keys[keyname] = val; } else goto syntax_error; } return 0; syntax_error: ERROR("syntax error line %i\n",lc); return -1; }
int open_file(struct input_data_hdr *data_hdr) { char outfname[MAXPATHLEN]; char s[32]; char n[32]; char l[32]; char c[32]; strncpy(s, data_hdr->station, sizeof(data_hdr->station)); s[sizeof(data_hdr->station)] = 0; TRIM(s); strncpy(c, data_hdr->channel, sizeof(data_hdr->channel)); c[sizeof(data_hdr->channel)] = 0; TRIM(c); strncpy(n, data_hdr->network, sizeof(data_hdr->network)); n[2] = 0; TRIM(n); strncpy(l, data_hdr->location, sizeof(data_hdr->location)); l[2] = 0; TRIM(l); /* give the user some indication as to what we are doing. */ printf("Writing: Net/Stn/Loc/Chn %.2s:%.5s:%.2s:%.3s at %04d.%03d.%02d.%02d.%02d.%04d to disk\n", n, s, l, c, data_hdr->time.year, data_hdr->time.day, data_hdr->time.hour, data_hdr->time.minute, data_hdr->time.second, data_hdr->time.fracsec); sprintf (outfname, "%04d.%03d.%02d.%02d.%02d.%04d.%s.%s.%s.%s.OPAQUE", data_hdr->time.year, data_hdr->time.day, data_hdr->time.hour, data_hdr->time.minute, data_hdr->time.second, data_hdr->time.fracsec, n, s, l, c); if ((outfile = fopen(outfname, "a")) == NULL) { fprintf(stderr, "Error, output_b2k(): Unable to open file!\n"); perror("output_b2k"); file_open = FALSE; return 0; } file_open = TRUE; }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- bool SJ_NextLevel( const wchar_t* filename /*= LEVEL_NEXT*/ ) { // reset player variables for ( char i = 0; i < g_nPlayers; ++i ) SJ_ResetPlayer( g_player[i] ); // reset level variables g_remainBlocks=0; g_levelName[0] = 0; memset( g_sprites, 0, sizeof(sSprite)*MAX_SPRITES ); if ( wcscmp( filename, LEVEL_NEXT ) == 0 ) // get next from folder { swprintf_s( g_txt, L"%s/levels/%s/Level_%03d.txt", g_skin, g_difficulty, g_nextLevel ); }else // a real filename provided { wcscpy_s( g_txt, filename ); } // performs open FILE* f = _wfopen( g_txt, L"rt" ); if ( !f ) { g_nextLevel = 0; return false; } // read from file int bcount = g_nPlayers; int line = 0; while ( ! feof(f) && line < TILES_HEIGHT && bcount < MAX_SPRITES ) { fgetws( g_txt, sizeof(g_txt)/sizeof(wchar_t), f ); for ( int c = 0; c < TILES_WIDTH && g_txt[c] != L'\0'; ++c ) { int spr = -1; char texId = IDT_JUMPING; switch ( g_txt[c] ) { case TILE_BLOCK: spr = bcount; texId = IDT_BLOCK; ++bcount; break; case TILE_SPAWN0: case TILE_SPAWN1: case TILE_SPAWN2: case TILE_SPAWN3: { const char ispawn = char(g_txt[c] - TILE_SPAWN0); spr = ispawn < g_nPlayers ? ispawn : -1; }break; } if ( spr != -1 ) { g_sprites[spr].x = (c*g_blDim[0]); g_sprites[spr].y = (line*g_blDim[1]); g_sprites[spr].active = 1; g_sprites[spr].texId = texId; g_sprites[spr].alpha = 1.0f; } } ++line; } // level params wchar_t* ptr = NULL; while ( ! feof(f) ) { fgetws( g_txt, sizeof(g_txt)/sizeof(wchar_t), f ); ptr = g_txt; SKIP_BLANKS(ptr); if ( *ptr == COMMENT_TOKEN ) continue; // comments TRIM(ptr); if ( _wcsnicmp( ptr, L"levelName", 9 ) == 0 ) { ptr+=9; SKIP_BLANKS(ptr); wcsncpy_s( g_levelName, ptr, 64 ); g_levelName[63]=0; }else if ( _wcsnicmp( ptr, L"boosts", 6 ) == 0 ) { ptr+=6; SKIP_BLANKS(ptr); const char b = (char)::_wtol(ptr); for ( char i = 0; i < g_nPlayers; ++i ) g_player[i].levelBoosts = b; }else if ( _wcsnicmp( ptr, L"time", 4 ) == 0 ) { ptr+=4; SKIP_BLANKS(ptr); g_levelTime = ::_wtof(ptr); } } fclose(f); // counting remaining blocks for ( int i = 0; i < MAX_SPRITES; ++i ) { if ( i < g_nPlayers || g_sprites[i].active == 0 ) continue; ++g_remainBlocks; } // correcting init for players for ( char i = 0; i < g_nPlayers; ++i ) { sSprite& plSpr = g_sprites[ g_player[i].sprId ]; // center in tile plSpr.x += g_blDim[0]/2.0f-g_plDim[0]/2.0f; plSpr.y += g_blDim[1]/2.0f-g_plDim[1]/2.0f; } return true; }
//初始化连接池 int scpool_init() { int n,i,ret; char *p,buf[512]; INT64 now; FILE *fd; JSON_OBJECT cfg,json; SCPOOL_stu node; if(scpool) return 0; p=getenv("SCPOOLCFG"); if(!p||!*p) { ShowLog(1,"%s:缺少环境变量SCPOOLCFG!",__FUNCTION__); return -1; } fd=fopen((const char *)p,"r"); if(!fd) { ShowLog(1,"%s:CFGFILE %s open err=%d,%s",__FUNCTION__, p,errno,strerror(errno)); return -2; } cfg=json_object_new_array(); while(!ferror(fd)) { fgets(buf,sizeof(buf),fd); if(feof(fd)) break; TRIM(buf); if(!*buf || *buf=='#') continue; ret=net_dispack(&node,buf,SCPOOL_tpl); if(ret<=0) continue; json=json_object_new_object(); struct_to_json(json,&node,SCPOOL_tpl,0); json_object_array_add(cfg,json); } fclose(fd); SCPOOLNUM=json_object_array_length(cfg); if(SCPOOLNUM <=0 ) { json_object_put(cfg); ShowLog(1,"%s:empty SCPOOL",__FUNCTION__); return -3; } scpool=(pool *)malloc(SCPOOLNUM * sizeof(pool)); if(!scpool) { json_object_put(cfg); SCPOOLNUM=0; return MEMERR; } p=getenv("SCPOOL_LOGLEVEL"); if(p && isdigit(*p)) log_level=atoi(p); now=now_usec(); for(n=0;n<SCPOOLNUM;n++) { if(0!=(i=pthread_mutex_init(&scpool[n].mut,NULL))) { ShowLog(1,"%s:mutex_init err %s",__FUNCTION__, strerror(i)); json_object_put(cfg); return -12; } if(0!=(i=pthread_cond_init(&scpool[n].cond,NULL))) { ShowLog(1,"%s:cond init err %s",__FUNCTION__, strerror(i)); json_object_put(cfg); return -13; } json=json_object_array_get_idx(cfg,n); json_to_struct(&scpool[n].log,json,SCPOOL_tpl); scpool[n].d_node=scpool[n].log.d_node; scpool[n].resource_num=scpool[n].log.NUM>0?scpool[n].log.NUM:1; scpool[n].lnk=(resource *)malloc(scpool[n].resource_num * sizeof(resource)); if(!scpool[n].lnk) { ShowLog(1,"%s:malloc lnk error!",__FUNCTION__); scpool[n].resource_num=0; continue; } scpool[n].free_q=scpool[n].resource_num-1; for(i=0;i<scpool[n].resource_num;i++) { int j; pthread_mutex_init(&scpool[n].lnk[i].mut,NULL); Init_CLI_Var(&scpool[n].lnk[i].cli); scpool[n].lnk[i].cli.Errno=-1; initconnect(&scpool[n].lnk[i].Conn); strcpy(scpool[n].lnk[i].Conn.Host,scpool[n].log.HOST); strcpy(scpool[n].lnk[i].Conn.Service,scpool[n].log.PORT); scpool[n].lnk[i].Conn.timeout=-1; if(*scpool[n].log.family) str_a64n(32,scpool[n].log.family,scpool[n].family); scpool[n].lnk[i].tcb_num=0; if(i<scpool[n].resource_num-1) scpool[n].lnk[i].next=i+1; else scpool[n].lnk[i].next=0; for(j=0;j<TCBNUM;j++) { scpool[n].lnk[i].TCB_q[j]=-1; } scpool[n].lnk[i].timestamp=now; } ShowLog(2,"scpool[%d],link num=%d",n,scpool[n].resource_num); } json_object_put(cfg); return SCPOOLNUM; }
int AmConfigReader::loadFile(const string& path) { FILE* fp = fopen(path.c_str(),"r"); if(!fp){ WARN("could not open configuration file '%s': %s\n", path.c_str(),strerror(errno)); return -1; } int lc = 0; int ls = 0; char lb[MAX_CONFIG_LINE] = {'\0'}; char *c,*key_beg,*key_end,*val_beg,*val_end,*inc_beg,*inc_end; c=key_beg=key_end=val_beg=val_end=inc_beg=inc_end=0; while(!feof(fp) && ((ls = fifo_get_line(fp, lb, MAX_CONFIG_LINE)) != -1)){ c=key_beg=key_end=val_beg=val_end=0; lc++; c = lb; TRIM(c); if(IS_EOL(*c)) continue; if (*c == '@') { /* process included config file */ c++; TRIM(c); inc_beg = c++; while( !IS_EOL(*c) && !IS_SPACE(*c) ) c++; inc_end = c; string fname = string(inc_beg,inc_end-inc_beg); if (fname.length() && fname[0] != '/') fname = AmConfig::ModConfigPath + fname; if(loadFile(fname)) goto error; continue; } key_beg = c; while( (*c != '=') && !IS_SPACE(*c) ) c++; key_end = c; if(IS_SPACE(*c)) TRIM(c); else if( !(c - key_beg) ) goto syntax_error; if(*c != '=') goto syntax_error; c++; TRIM(c); if(*c == '"'){ char last_c = ' '; val_beg = ++c; while( ((*c != '"') || (last_c == '\\')) && (*c != '\0') ) { last_c = *c; c++; } if(*c == '\0') goto syntax_error; val_end = c; } else { val_beg = c; while( !IS_EOL(*c) && !IS_SPACE(*c) ) c++; val_end = c; } if((key_beg < key_end) && (val_beg <= val_end)) { string keyname = string(key_beg,key_end-key_beg); string val = string(val_beg,val_end-val_beg); if (hasParameter(keyname)) { WARN("while loading '%s': overwriting configuration " "'%s' value '%s' with '%s'\n", path.c_str(), keyname.c_str(), getParameter(keyname).c_str(), val.c_str()); } keys[keyname] = val; // small hack to make include work with right path if (keyname == "plugin_config_path") AmConfig::ModConfigPath = val; } else goto syntax_error; } fclose(fp); return 0; syntax_error: ERROR("syntax error line %i in %s\n",lc,path.c_str()); error: fclose(fp); return -1; }
int main(int ac,char *av[]) { char buf[131702]; int len,i,len1; ENIGMA t; ENIGMA2 egm; struct timeval beg,end; enigma_init(t,"abcdefg",0); printf("t1:"); for(i=0;i<256;i++) { if(!(i&7)) putchar('\n'); printf("%3d:%02X\t",i,255&t[0][i]); } printf("\nt3:"); for(i=0;i<256;i++) { if(!(i&7)) putchar('\n'); printf("%3d:%02X\t",i,255&t[2][i]); } putchar('\n'); enigma2_init(&egm,"abcdefg",0); printf("\ncrc=%d\n",egm.crc); // enigma2_init(&egm,"\x01\xff\x35\xf8\xef\x97\x22\x14\x80\x7f\t\b\r\n\377\177\225",17); memset(buf,'B',sizeof(buf)); buf[sizeof(buf)-1]=0; #ifndef TEST_SPEED while(!ferror(stdin)) { fgets(buf,sizeof(buf),stdin); if(feof(stdin)) break; TRIM(buf); #endif len=strlen(buf); gettimeofday(&beg,0); enigma(t,buf,len); gettimeofday(&end,0); len1=len>32?32:len; printf("enigma encode :"); for(i=0;i<len1;i++) printf("%02X ",buf[i]&255); printf("\nenigma encode 64K:"); for(i=0;i<len1;i++) printf("%02X ",buf[i+65536]&255); printf("\ntimeval=%ld\n",interval(&beg,&end)); enigma(t,buf,len); printf("enigma decode:\n%.100s\n",buf); //test frenz gettimeofday(&beg,0); enigma_encrypt(t,buf,len); gettimeofday(&end,0); printf("\nencrypt :"); for(i=0;i<len1;i++) printf("%02X ",buf[i]&255); printf("\nencrypt 64K:"); for(i=0;i<len1;i++) printf("%02X ",buf[i+65536]&255); printf("\ntimeval=%ld\n",interval(&beg,&end)); enigma_decrypt(t,buf,len); printf("decrypt :\n%.100s\n",buf); //test enigma2 gettimeofday(&beg,0); enigma2_encrypt(&egm,buf,len); gettimeofday(&end,0); printf("enigma2 encode :"); for(i=0;i<len1;i++) printf("%02X ",buf[i]&255); printf("\nenigma2 encode 64K:"); for(i=0;i<len1;i++) printf("%02X ",buf[i+65536]&255); printf("\ntimeval=%ld\n",interval(&beg,&end)); enigma2_decrypt(&egm,buf,len); printf("enigma2 decode:\n%.100s\n",buf); #ifndef TEST_SPEED } #endif return 0; }