static void _reply_XML(Web_t self, HttpRequest_t httpRequest, socket_t * clientSock){ const char * uri = HttpRequest_getURI(httpRequest); HTTP_REQUEST_METHOD method = HttpRequest_getMethod(httpRequest); char child1[128], child2[128]; getTok(uri, 1, "/", child1); getTok(uri, 2, "/", child2); if (!strcmp(child1, "investors")) { if(!strcmp(child2, "")){ if (method == HTTP_GET){ char * charP = HttpRequest_getArgsVal(httpRequest, "gtinvestment"); double minInvestment = !strcmp(charP, "[empty]") ? MIN_DOUBLE : atof(charP); charP = HttpRequest_getArgsVal(httpRequest, "ltinvestment"); double maxInvestment = !strcmp(charP, "[empty]") ? MAX_DOUBLE : atof(charP); charP = HttpRequest_getArgsVal(httpRequest, "gtprojects"); int minProjectsNumber = !strcmp(charP, "[empty]") ? MIN_INT : atoi(charP); charP = HttpRequest_getArgsVal(httpRequest, "ltprojects"); int maxProjectsNumber = !strcmp(charP, "[empty]") ? MAX_INT : atoi(charP); _validateArgsVals(&minInvestment, &maxInvestment, &minProjectsNumber, &maxProjectsNumber); _writeInvestors_XML(self, clientSock, minInvestment, maxInvestment, minProjectsNumber, maxProjectsNumber); }else if (method == HTTP_POST){ _addInvestorIfPossible(self, clientSock, httpRequest); }else{ _replyInvalidMethod(clientSock); } }else if (isNonNegatInteger(child2)){ int index = atoi(child2); if(_checkIndex(self, index) == SERVER_INDEX_ERROR){ _replyInvalidIndex(clientSock, index); }else{ if (method == HTTP_GET){ _writeInvestor_XML(self, clientSock, index); } else if(method == HTTP_OPTIONS){ _optionsOkReply(clientSock); } else if (method == HTTP_DELETE){ DataHandler_deleteInvestor(self->dataHandler, index); _successDeleteReply(clientSock, index); }else{ _replyInvalidMethod(clientSock); } } }else{ _replyInvalidUri(clientSock); } }else{ _replyInvalidUri(clientSock); } }
void DataValue::parseFont(const ustring &text, void *value) { int l = text.bytes(); char *buf = new char[l+1], *sb = buf; strcpy(buf, text.c_str()); buf++; ((FontRecord*)value)->name = getTok(&buf, ','); ((FontRecord*)value)->size = atoi(getTok(&buf, ',')); ((FontRecord*)value)->style = atoi(getTok(&buf, ',')); ((FontRecord*)value)->color = atoi(getTok(&buf, ',')); ((FontRecord*)value)->charset = atoi(getTok(&buf, ']')); delete sb; }
static void _reply_HTML(server_t self, http_t httpRequest, socket_t * clientSock){ const char * uri = http_getURI(httpRequest); HTTP_REQUEST_TYPE type = http_getType(httpRequest); char child0[128], child1[128]; getTok(uri, 0, "/", child0); getTok(uri, 1, "/", child1); if (!strcmp(child0, "")) { if (type == HTTP_GET){ _replyHomepage_HTML(self, clientSock); }else{ _replyInvalidMethod(clientSock); } }else if (!strcmp(child0, "patients")){ if(!strcmp(child1, "")){ if (type == HTTP_GET){ _writePatients_HTML(self, clientSock); }else if (type == HTTP_POST){ _addPatientIfPossible(self, clientSock, httpRequest); }else{ _replyInvalidMethod(clientSock); } }else if(isNonNegatInteger(child1)){ int index = atoi(child1); if(_checkIndex(self, index) == SERVER_INDEX_ERROR){ _replyInvalidIndex(clientSock, index); }else{ if (type == HTTP_GET){ _writePatient_HTML(self, clientSock, index); }else if(type == HTTP_OPTIONS){ _optionsOkReply(clientSock); }else if (type == HTTP_DELETE){ DataHandler_deletePatient(self->dataHandler, index); _successDeleteReply(clientSock, index); }else{ _replyInvalidMethod(clientSock); } } }else{ _replyInvalidUri(clientSock); } }else if (!strcmp(child0, "new-patient")){ if (type == HTTP_GET){ _replyNewPatient_HTML(self, clientSock); }else{ _replyInvalidMethod(clientSock); } }else{ _replyInvalidUri(clientSock); } }
void getXMLCharset(const char *buf, char *charset) { const char *next, *p; charset[0] = '\0'; next = buf; p = getTok(&next); if (matchkey(p, next, "text")) strcpy(charset, "us-ascii"); else if (!matchkey(p, next, "application")) return; p = getTok(&next); if (!p || *p != '/') return; p = getTok(&next); #if 0 if (!matchkey(p, next, "xml") && charset[0] == '\0') return; #endif p = getTok(&next); while (p) { if (*p == ';') { p = getTok(&next); if (matchkey(p, next, "charset")) { p = getTok(&next); if (p && *p == '=') { p = getTok(&next); if (p) { char *s = charset; if (*p == '"') { while (++p != next - 1) { if (*p == '\\') ++p; if (s == charset + CHARSET_MAX - 1) { charset[0] = '\0'; break; } *s++ = *p; } *s++ = '\0'; } else { if (next - p > CHARSET_MAX - 1) break; while (p != next) *s++ = *p++; *s = 0; break; } } } break; } } else p = getTok(&next); } }
void runLexer() { token tkn; do { tkn = getTok(); fprintf(out, "%5d %5d %.15s", tkn.indLine, tkn.indCol, &"End_of_input Op_multiply Op_divide Op_mod Op_add " "Op_subtract Op_negate Op_not Op_less Op_lessequal " "Op_greater Op_greaterequal Op_equal Op_notequal Op_assign " "Op_and Op_or Keyword_if Keyword_else Keyword_while " "Keyword_print Keyword_putc LeftParen RightParen LeftBrace " "RightBrace Semicolon Comma Identifier Integer " "String " [tkn.tok * 16]); if (tkn.tok == tk_Integer) fprintf(out, " %6d", tkn.n); if (tkn.tok == tk_String) fprintf(out, " \"%s\"", tkn.text); if (tkn.tok == tk_Ident) fprintf(out, " %s", tkn.text); fprintf(out, "\n"); } while (tkn.tok != tk_EOI); if (out != stdout) fclose(out); }
void DataValue::parseStrList(const ustring &text, void *value) { int l = text.bytes(); char *buf = new char[l+1], *sb = buf; strcpy(buf, text.c_str()); if(*buf == '#') { buf++; if(*buf) { StringList list; do { int n = atoi(getTok(&buf, ':')); ustring s = ustring(buf, n); list << s; buf += s.bytes(); // data buf ++; // | delimiter } while(*buf); *(ustring *)value = list; } else *(ustring *)value = ""; } else { *(ustring *)value = buf; } delete sb; }
int isDate(const char * str){ if(strlen(str) > 15) return 0; char buff[16]; getTok(str, 0, "-", buff); if(!isNonNegatInteger(buff) || strlen(buff) != 4) return 0; getTok(str, 1, "-", buff); if(!isNonNegatInteger(buff) || strlen(buff) != 2 || atoi(buff) > 12) return 0; getTok(str, 2, "-", buff); if(!isNonNegatInteger(buff) || strlen(buff) != 2 || atoi(buff) > 31) return 0; getTok(str, 3, "-", buff); if(strlen(buff) != 0) return 0; return 1; }
static token divOrCmt(int indLine, int indCol) { if (ch == '/') { next_ch(); while (ch != EOF && ch != '\n') next_ch(); if (ch == EOF) return (token){tk_EOI, indLine, indCol, 0, NULL}; if (ch == '\n') { next_ch(); return getTok(); } } if (ch != '*') return (token){tk_Div, indLine, indCol, 0, NULL}; /* comment detected */ while (TRUE) { switch (ch) { case '*': next_ch(); if (ch == '/') { next_ch(); return getTok(); } break; case EOF: error(indLine, indCol, "EOF in comment"); } next_ch(); } }
static void _reply(Web_t self, HttpRequest_t httpRequest, socket_t * clientSock){ const char * uri = HttpRequest_getURI(httpRequest); char root[128]; getTok(uri, 0, "/", root); if (!strcmp(root, "api")) { _reply_XML(self, httpRequest, clientSock); } else if (!strcmp(root, "favicon.ico")){ _emptySuccessReply(clientSock); }else{ _reply_HTML(self, httpRequest, clientSock); } }
int otherFor(char* direccion, char* dir) { char nombre[6]; char found = 0; char sectorNumber; char otro[6]; int indexx; int n; int y; int b=0; int w=0; int z = 0; char token [10]; int toks = CountTokens(direccion); sectorNumber = 0x01; for (b=0; b<10; b++) token[b]=0x0; while(w < toks) { z = getTok(direccion,token,z); found = 0; for(n=0;n<6;n++) { nombre[n] = token[n]; } for (indexx=0;indexx<15;indexx++) { for(y=0;y<6;y++) { otro[y] = dir[indexx*0x20+y]; //si existe o no el directorio } if(cmp(otro,nombre,6)==1) //si encontramos el directorio { sectorNumber = dir[indexx*0x20+6]; readsector(BASEOFFSET+sectorNumber,dir); w++; found = 1; break; } } if(found == 1) { continue; } w++; } return sectorNumber; }
void strTok(char* path) { int y = CountTokens(path); int i=0; int x=0,w=0; int z = 0; char token [10]; for (i=0; i<10; i++) token[i]=0x0; while(w < y) { z = getTok(path,token,z); w++; } }
void cmd_path(tok_t arg[]){ char *path = getenv("PATH"); char cmCopy[256]; strcpy(cmCopy,cm); tok_t *t; t=getTok(path); int i=0; while(sizeof(t)>i){ strcpy(cm,t[i]); strcat(cm,"/"); strcat(cm,cmCopy); p2(cm); i++; } return 0; }
static void command_process(int fd, char* command, size_t commandLength) { int err = 0; /* syntax or other error, true or false */ int emptyLine = 0; char *token; int i; uint32_t ui[3]; uint8_t comm_node = 0xFF; /* undefined */ char resp[STRING_BUFFER_SIZE]; int respLen = 0; respErrorCode_t respErrorCode = respErrorNone; uint32_t sequence = 0; /* parse mandatory token '"["<sequence>"]"' */ if((token = getTok(command, spaceDelim, &err)) == NULL) { /* If empty line, respond with empty line. */ emptyLine = 1; } if(err == 0) { if(token[0] != '[' || token[strlen(token)-1] != ']') { err = 1; if(token[0] == '#') { /* If comment, respond with empty line. */ emptyLine = 1; } } else { token[strlen(token)-1] = '\0'; sequence = getU32(token+1, 0, 0xFFFFFFFF, &err); } } /* parse optional tokens '[[<net>] <node>]', both numerical. Then follows * mandatory token <command>, which is not numerical. */ if(err == 0) { for(i=0; i<3; i++) { if((token = getTok(NULL, spaceDelim, &err)) == NULL) { break; } if(isdigit(token[0]) == 0) { break; } ui[i] = getU32(token, 0, 0xFFFFFFFF, &err); } } if(err == 0) { switch(i) { case 0: /* only <command> (pointed by token) */ comm_node = comm_node_default; /* may be undefined */ break; case 1: /* <node> and <command> tokens */ if(ui[0] < 0 || ui[0] > 127) { err = 1; respErrorCode = respErrorUnsupportedNode; } else { comm_node = (uint8_t) ui[0]; } break; case 2: /* <net>, <node> and <command> tokens */ if(ui[0] < 1 || ui[0] > 1) { err = 1; respErrorCode = respErrorUnsupportedNet; } else if(ui[1] < 0 || ui[1] > 127) { err = 1; respErrorCode = respErrorUnsupportedNode; } else { comm_net = (uint16_t) ui[0]; comm_node = (uint8_t) ui[1]; } break; case 3: /* <command> token contains digit */ err = 1; break; } } /* Execute command */ if(err == 0) { /* Upload SDO command - 'r[ead] <index> <subindex> <datatype>' */ if(strcmp(token, "r") == 0 || strcmp(token, "read") == 0) { uint16_t idx; uint8_t subidx; const dataType_t *datatype; /* optional token */ int errTokDt = 0; int errDt = 0; uint32_t SDOabortCode = 1; uint8_t dataRx[CO_COMMAND_SDO_BUFFER_SIZE]; /* SDO receive buffer */ uint32_t dataRxLen; /* Length of received data */ token = getTok(NULL, spaceDelim, &err); idx = (uint16_t)getU32(token, 0, 0xFFFF, &err); token = getTok(NULL, spaceDelim, &err); subidx = (uint8_t)getU32(token, 0, 0xFF, &err); token = getTok(NULL, spaceDelim, &errTokDt); datatype = getDataType(token, &errDt); /* Datatype must be correct, if present. */ if(errTokDt == 0 && errDt != 0) { err = 1; } lastTok(NULL, spaceDelim, &err); if(err == 0 && (comm_node < 1 || comm_node > 127)) { err = 1; if(comm_node == 0xFF) { respErrorCode = respErrorNoDefaultNodeSet; } else { respErrorCode = respErrorUnsupportedNode; } } /* Make CANopen SDO transfer */ if(err == 0) { err = sdoClientUpload( CO->SDOclient, comm_node, idx, subidx, dataRx, sizeof(dataRx), &dataRxLen, &SDOabortCode, SDOtimeoutTime, blockTransferEnable); if(err != 0){ respErrorCode = respErrorInternalState; } } /* output result */ if(err == 0){ if(SDOabortCode == 0) { respLen = sprintf(resp, "[%d] ", sequence); if(datatype == NULL || (datatype->length != 0 && datatype->length != dataRxLen)) { respLen += dtpHex(resp+respLen, sizeof(resp)-respLen, (char*)dataRx, dataRxLen); } else { respLen += datatype->dataTypePrint( resp+respLen, sizeof(resp)-respLen, (char*)dataRx, dataRxLen); } } else{ respLen = sprintf(resp, "[%d] ERROR: 0x%08X", sequence, SDOabortCode); } } } /* Download SDO command - w[rite] <index> <subindex> <datatype> <value> */ else if(strcmp(token, "w") == 0 || strcmp(token, "write") == 0) { uint16_t idx; uint8_t subidx; const dataType_t *datatype; uint32_t SDOabortCode = 1; uint8_t dataTx[CO_COMMAND_SDO_BUFFER_SIZE]; /* SDO transmit buffer */ uint32_t dataTxLen = 0; /* Length of data to transmit. */ token = getTok(NULL, spaceDelim, &err); idx = (uint16_t)getU32(token, 0, 0xFFFF, &err); token = getTok(NULL, spaceDelim, &err); subidx = (uint8_t)getU32(token, 0, 0xFF, &err); token = getTok(NULL, spaceDelim, &err); datatype = getDataType(token, &err); if(err == 0) { /* take whole string or single token, depending on datatype. Comment may follow. */ token = getTok(NULL, (datatype->length == 0) ? "\n\r\f" : spaceDelim, &err); } if(err == 0) { dataTxLen = datatype->dataTypeScan((char*)dataTx, sizeof(dataTx), token); /* Length must match and must not be zero. */ if((datatype->length != 0 && datatype->length != dataTxLen) || dataTxLen == 0) { err = 1; } } lastTok(NULL, spaceDelim, &err); if(err == 0 && (comm_node < 1 || comm_node > 127)) { err = 1; if(comm_node == 0xFF) { respErrorCode = respErrorNoDefaultNodeSet; } else { respErrorCode = respErrorUnsupportedNode; } } /* Make CANopen SDO transfer */ if(err == 0) { err = sdoClientDownload( CO->SDOclient, comm_node, idx, subidx, dataTx, dataTxLen, &SDOabortCode, SDOtimeoutTime, blockTransferEnable); if(err != 0){ respErrorCode = respErrorInternalState; } } /* output result */ if(err == 0){ if(SDOabortCode == 0) { respLen = sprintf(resp, "[%d] OK", sequence); } else{ respLen = sprintf(resp, "[%d] ERROR: 0x%08X", sequence, SDOabortCode); } } } /* NMT start node */ else if(strcmp(token, "start") == 0) { lastTok(NULL, spaceDelim, &err); if(err == 0 && comm_node > 127) { err = 1; respErrorCode = respErrorNoDefaultNodeSet; } if(err == 0) { err = CO_sendNMTcommand(CO, CO_NMT_ENTER_OPERATIONAL, comm_node) ? 1:0; if(err == 0) respLen = sprintf(resp, "[%d] OK", sequence); } } /* NMT stop node */ else if(strcmp(token, "stop") == 0) { lastTok(NULL, spaceDelim, &err); if(err == 0 && comm_node > 127) { err = 1; respErrorCode = respErrorNoDefaultNodeSet; } if(err == 0) { err = CO_sendNMTcommand(CO, CO_NMT_ENTER_STOPPED, comm_node) ? 1:0; if(err == 0) respLen = sprintf(resp, "[%d] OK", sequence); } } /* NMT Set node to pre-operational */ else if(strcmp(token, "preop") == 0 || strcmp(token, "preoperational") == 0) { lastTok(NULL, spaceDelim, &err); if(err == 0 && comm_node > 127) { err = 1; respErrorCode = respErrorNoDefaultNodeSet; } if(err == 0) { err = CO_sendNMTcommand(CO, CO_NMT_ENTER_PRE_OPERATIONAL, comm_node) ? 1:0; if(err == 0) respLen = sprintf(resp, "[%d] OK", sequence); } } /* NMT reset (node or communication) */ else if(strcmp(token, "reset") == 0) { token = getTok(NULL, spaceDelim, &err); if(err == 0 && comm_node > 127) { err = 1; respErrorCode = respErrorNoDefaultNodeSet; } if(err == 0) { if(strcmp(token, "node") == 0) { lastTok(NULL, spaceDelim, &err); if(err == 0) { err = CO_sendNMTcommand(CO, CO_NMT_RESET_NODE, comm_node) ? 1:0; if(err == 0) respLen = sprintf(resp, "[%d] OK", sequence); } } else if(strcmp(token, "comm") == 0 || strcmp(token, "communication") == 0) { lastTok(NULL, spaceDelim, &err); if(err == 0) { err = CO_sendNMTcommand(CO, CO_NMT_RESET_COMMUNICATION, comm_node) ? 1:0; if(err == 0) respLen = sprintf(resp, "[%d] OK", sequence); } } else { err = 1; } } } /* set command - multiple settings */ else if(strcmp(token, "set") == 0) { token = getTok(NULL, spaceDelim, &err); if(err == 0) { /* sdo_timeout <value> */ if(strcmp(token, "sdo_timeout") == 0) { uint16_t tmout; token = getTok(NULL, spaceDelim, &err); tmout = (uint16_t)getU32(token, 0, 10000, &err); lastTok(NULL, spaceDelim, &err); /* Write to variable */ if(err == 0) { SDOtimeoutTime = tmout; respLen = sprintf(resp, "[%d] OK", sequence); } } /* sdo_block <value> */ else if(strcmp(token, "sdo_block") == 0) { uint8_t blk; token = getTok(NULL, spaceDelim, &err); blk = (uint8_t)getU32(token, 0, 1, &err); lastTok(NULL, spaceDelim, &err); /* Write to variable */ if(err == 0) { blockTransferEnable = blk; respLen = sprintf(resp, "[%d] OK", sequence); } } /* node <value> */ else if(strcmp(token, "node") == 0) { uint16_t node; token = getTok(NULL, spaceDelim, &err); node = (uint16_t)getU32(token, 1, 127, &err); lastTok(NULL, spaceDelim, &err); /* Write to variable */ if(err == 0) { comm_node_default = node; respLen = sprintf(resp, "[%d] OK", sequence); } } /* Unknown command */ else { err = 1; } } } /* Unknown command */ else { respErrorCode = respErrorReqNotSupported; err = 1; } } /* Generate error response (or leave empty line response) */ if(err != 0 && emptyLine == 0) { if(respErrorCode == respErrorNone) { respErrorCode = respErrorSyntax; } respLen = sprintf(resp, "[%d] ERROR: %d", sequence, respErrorCode); } /* Terminate string and send response */ resp[respLen++] = '\r'; resp[respLen++] = '\n'; resp[respLen++] = '\0'; if(write(fd, resp, respLen) != respLen) { CO_error(0x15200000L); } }
void mkdir(char* path) { int b=0; int w=0; int z = 0; char token [10]; int toks = CountTokens(path); int k; char r; char mapa[512]; char dir[512]; char nombre[6]; char found = 0; char sectorNumber; char comparar[6]; int x; int n; int y; int sectorLibre = 0; int entrada = 0; int dirindex = 0; int sectcount; readsector(BASEOFFSET,mapa); readsector(BASEOFFSET +1,dir); sectorNumber = 0x01; for (b=0; b<10; b++) token[b]=0x0; while(w < toks) { z = getTok(path,token,z); found = 0; for(n=0;n<6;n++) { nombre[n] = token[n]; } for (x=0;x<15;x++) { for(y=0;y<6;y++) { comparar[y] = dir[x*0x20+y]; //si existe o no el directorio } if(cmp(comparar,nombre,6)==1) //si encontramos el directorio { sectorNumber = dir[x*0x20+6]; readsector(BASEOFFSET+sectorNumber,dir); w++; found = 1; break; } } if(found == 1) { continue; } for (entrada=0; entrada<256; entrada++) if (mapa[entrada]==0) break; if (entrada==256) { printstring("Not enough room for file\n"); return; } mapa[entrada]=0x44; for (x=0;x<15;x++) { dirindex = x*0x20; sectorLibre = dir[dirindex]; //buscamos la primera entrada libre if(sectorLibre==0) { for (k=0; k<6; k++) dir[dirindex+k]=0x20; for (k=0; k<6; k++) { if(nombre[k]==0) break; dir[dirindex+k]=nombre[k]; } dir[dirindex+6] = entrada; break; } } writesector(BASEOFFSET+sectorNumber,dir); writesector(BASEOFFSET,mapa); readsector(BASEOFFSET+entrada,dir); sectorNumber = entrada; w++; } }
void Remove(char* path) { int i; char r; char map[512]; char dir[512]; char nombre[6]; char found = 0; char sectorNumber; char prevSectorNumber; char comparar[6]; int x; int n; int y; int sectorLibre = 0; int entradaMapa = 0; int dirindex = 0; int sectcount; int b=0; int w=0; int z = 0; char token [10]; int toks = CountTokens(path);//cantidad de subdirectorios readsector(BASEOFFSET,map); readsector(BASEOFFSET +1,dir); sectorNumber = 0x01; prevSectorNumber = 0x01; for (b=0; b<10; b++) token[b]=0x0; while(w < toks) { z = getTok(path,token,z); found = 0; for(n=0;n<6;n++) { nombre[n] = token[n]; } for (x=0;x<15;x++) { for(y=0;y<6;y++) { comparar[y] = dir[x*0x20+y]; //copiando el nombre del directorio } if(cmp(comparar,nombre,6)==1) //si encontramos el directorio { prevSectorNumber = sectorNumber; sectorNumber = dir[x*0x20+6]; readsector(BASEOFFSET+sectorNumber,dir); found = 1; break; } } w++; } if(found == 1) { readsector(BASEOFFSET + prevSectorNumber,dir); for(y=0;y<7;y++) { dir[x*0x20+y] = 0; } writesector(BASEOFFSET + prevSectorNumber,dir); }else { printstring("Directorio no Encontrando"); } }
void guardarArchivo(char* direccion, char* content, int size) { int i; char r; int sect; char map[512]; char dir[512]; char nombre[6]; char found = 0; char sectorNumber; char otro[6]; int indexx; int n; int y; int sectorLibre = 0; int entradaMapa = 0; int dirindex = 0; int sectcount; int b=0; int w=0; int z = 0; char token [10]; int toks = CountTokens(direccion); readsector(BASEOFFSET,map); readsector(BASEOFFSET +1,dir); //sectorNumber = otherFor(direccion, dir); sectorNumber = 0x01; for (b=0; b<10; b++) token[b]=0x0; while(w < toks) { z = getTok(direccion,token,z); found = 0; for(n=0;n<6;n++) { nombre[n] = token[n]; } for (indexx=0;indexx<15;indexx++) { for(y=0;y<6;y++) { otro[y] = dir[indexx*0x20+y]; //si existe o no el directorio } if(cmp(otro,nombre,6)==1) //si encontramos el directorio { sectorNumber = dir[indexx*0x20+6]; readsector(BASEOFFSET+sectorNumber,dir); w++; found = 1; break; } } if(found == 1) { continue; } w++; }//busca que es el ultimo token no me acuerdo que hace for (indexx=0;indexx<15;indexx++) { dirindex = indexx*0x20; sectorLibre = dir[dirindex]; //buscamos la primera entrada libre if(sectorLibre==0) { for (i=0; i<6; i++) dir[dirindex+i]=0x20; for (i=0; i<6; i++) { if(nombre[i]==0) break; dir[dirindex+i]=nombre[i]; } break; } } sect = (div(size,512)+1); for(indexx=0;indexx<sect;indexx++) { printnumber(dirindex); entradaM(sect,map,dir,dirindex,content,indexx); } writesector(BASEOFFSET+sectorNumber,dir); writesector(BASEOFFSET,map); return; }
void getXMLCharset(const char *buf, char *charset) { const char *next, *p; charset[0] = '\0'; next = buf; p = getTok(&next); if (matchkey(p, next, "text")) strcpy(charset, "us-ascii"); else if (!matchkey(p, next, "application")) return; p = getTok(&next); if (!p || *p != '/') return; p = getTok(&next); if (matchkey(p, next, "xml")) isXml = 1; p = getTok(&next); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while (p) { if (*p == ';') { p = getTok(&next); if (matchkey(p, next, "charset")) { p = getTok(&next); if (p && *p == '=') { p = getTok(&next); if (p) { char *s = charset; if (*p == '"') { #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while (++p != next - 1) { if (*p == '\\') ++p; if (s == charset + CHARSET_MAX - 1) { charset[0] = '\0'; break; } *s++ = *p; } *s++ = '\0'; } else { if (next - p > CHARSET_MAX - 1) break; #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while (p != next) *s++ = *p++; *s = 0; break; } } } } } else p = getTok(&next); } }
/** load body's parts */ void Body::loadBodyParts(FILE *f) { char *l, jpline[256], tex[128]; tex[0] = '\0'; // alloc bodyparts and joint-points arrays bodyparts = new sBodyParts[MAX_PARTS]; jp.x = new float[MAX_PARTS]; jp.y = new float[MAX_PARTS]; jp.z = new float[MAX_PARTS]; // init bodyparts for (int i=0; i < MAX_PARTS; i++) { bodyparts[i].loaded = false; bodyparts[i].scale = 1; for (int j=0; j<3 ; j++) bodyparts[i].scales[j] = 1; for (int j=0; j<3 ; j++) bodyparts[i].color[j] = cloth[j]; bodyparts[i].texid = 0; bodyparts[i].off = NULL; bodyparts[i].obj = NULL; bodyparts[i].url[0] = '\0'; bodyparts[i].texurl[0] = '\0'; } // set default color for (int j=0; j<3 ; j++) { bodyparts[HEAD].color[j] = skin[j]; bodyparts[NECK].color[j] = skin[j]; bodyparts[L_FOREARM].color[j] = skin[j]; bodyparts[R_FOREARM].color[j] = skin[j]; bodyparts[L_HAND].color[j] = skin[j]; bodyparts[R_HAND].color[j] = skin[j]; } // parse first line of <body ...> if (! fgets(jpline, sizeof(jpline), f)) return; jpline[strlen(jpline) - 1] = '\0'; if (! stringcmp(jpline, "<body")) { l = strtok(jpline, SEP); // tokenize jpline l = strtok(NULL, SEP); // next token while (l) { if (! stringcmp(l, "scale=")) l = wobject->parse()->parseFloat(l, &bscale, "scale"); else if (! stringcmp(l, "tex=")) l = wobject->parse()->parseString(l, tex, "tex"); } } if (*tex) { for (int i=0; i < MAX_PARTS; i++) strcpy(bodyparts[i].texurl, tex); } // get body joint points and urls for (int i=0; i < MAX_PARTS; i++) { if (! fgets(jpline, sizeof(jpline), f)) break; jpline[strlen(jpline) - 1] = '\0'; trace(DBG_MAN, "loadBodyParts: %s", jpline); int bpindex = 0; char *p = jpline; //if ((p = strstr(jpline, "</body>"))) continue; if (jpline[0] == '#') continue; else if ((p = strchr(jpline, '<'))) { l = strtok(p, SEP); l = getTok(l, &bpindex); if (bpindex < 0) goto endparse; // eof l = strtok(NULL, SEP); // parse others lines of <body ...> ... </body> begin_while_parse(l) { if (! stringcmp(l, "jp=")) { l = skipEqual(l); l++; // " jp.x[bpindex] = (float)atof(l) / bscale; l = strtok(NULL, SEP); jp.y[bpindex] = (float)atof(l) / bscale; l = strtok(NULL, SEP); jp.z[bpindex] = (float)atof(l) / bscale; l = strtok(NULL, SEP); } else if (*l == '/') break; // eol else if (! stringcmp(l, "url=")) { l = wobject->parse()->parseString(l, bodyparts[i].url, "url"); drawparts++; } else if (! stringcmp(l, "scale=")) { l = wobject->parse()->parseFloat(l, &bodyparts[i].scale, "scale"); bodyparts[i].scales[0] = bodyparts[i].scale; bodyparts[i].scales[1] = bodyparts[i].scale; bodyparts[i].scales[2] = bodyparts[i].scale; } else if (! stringcmp(l, "scalex=")) l = wobject->parse()->parseFloat(l, &bodyparts[i].scales[0],"scalex"); else if (! stringcmp(l, "scaley=")) l = wobject->parse()->parseFloat(l, &bodyparts[i].scales[1],"scaley"); else if (! stringcmp(l, "scalez=")) l = wobject->parse()->parseFloat(l, &bodyparts[i].scales[2],"scalez"); else if (! stringcmp(l, "color=")) l = wobject->parse()->parseVector3f(l, bodyparts[i].color, "color"); else if (! stringcmp(l, "tex=")) l = wobject->parse()->parseString(l, bodyparts[i].texurl, "tex"); } end_while_parse(l); } }