struct node * insert_ele(struct node *root) { struct node *temp=NULL,*ptr=NULL; int v1,v2; char s1[30],s2[30]; printf("enter v1,v2 values"); scanf("%d%d",&v1,&v2); printf("enter strings s1,s2"); scanf("%s%s",s1,s2); temp=getNode(); temp->v1=v1; temp->v2=v2; insert_str(temp->s1,s1); insert_str(temp->s2,s2); if(root==NULL) { root=temp; } else { temp->next=root; root=temp; } return root; }
int check_ext_menu( char **tcl_lines ) { int eax; int idx = find_pos( "\"&Xtns\" all options 1", tcl_lines, ebp_32 ); if ( idx == -1 ) { idx = find_pos( "\"&Help\" all options", tcl_lines, 0 ); if ( idx == -1 ) { idx = find_pos( "}]", tcl_lines, 0 ); if ( idx == -1 ) print_error( -21, "could not parse 'menu.tcl'.\n" ); insert_str( " \"&Xtns\" all options 1 {\n", idx, tcl_lines ); idx++; insert_str( " }\n", idx, tcl_lines ); return idx; } else { insert_str( " \"&Xtns\" all options 1 {\n", idx, tcl_lines ); idx++; insert_str( " }\n", idx, tcl_lines ); } } }
/*** Join two lines and strip spaces on the next ***/ void join_strip( Project p ) { LINE *ln; if((ln = p->edited->next) != NULL) { STRPTR data; ULONG i; inv_curs(p, FALSE); p->nbc = p->edited->size; for(i=0, data=ln->stream; TypeChar[*data] == SPACE && i<ln->size; i++, data++); reg_group_by(&p->undo); if(i != ln->size) { /* Do not add a blank if there is already one */ if( p->nbc > 0 && TypeChar[ p->edited->stream[ p->nbc-1 ] ] != SPACE ) add_char(&p->undo, p->edited, p->nbc, ' '); if( insert_str(&p->undo, p->edited, p->edited->size, data, ln->size-i) == 0 ) ThrowError(Wnd, ErrMsg(ERR_NOMEM)); } /* ln can't be the first */ del_line(&p->undo, NULL, ln); p->max_lines--; reg_group_by(&p->undo); prop_adj(p); /* Refresh screen */ p->nbrc = p->nbrwc = x2pos(p->edited, p->nbc); REDRAW_CURLINE( p ); draw_info( p ); scroll_up(p, p->edited->next, p->ycurs, center_horiz(p)); inv_curs(p,TRUE); } }
int main() { // char *str1; // str1 = (char *)malloc(1024); // char *str2; // str2 = (char *)malloc(1024); // bzero(str2, 1024); // int n1 = read(0, str1, 1024); // printf("%s", str1); char str1[5] = {'I', ' ', 'm', ' ', 'u'}; char str2[10] = {'I', ' ', 'l','o','v','e', ' ', 'y','o','u'}; printf("RESULT %s\n", insert_str(str1, 5)); printf("RESULT %s\n", insert_str(str2, 10)); ; }
void known1(char *object_str) { /*{ Remove 'Secret' symbol for identity of object }*/ insert_str(object_str, "|", ""); };
int main() { char source[100] = "abcdefghijkl"; char *dest = "kkeidcnf"; insert_str(source,dest); return 0; }
void NameParser::parse (const std::string& imagename, size_t max_num_sequences) { specification = imagename; if (Path::is_dir (imagename)) { array.resize (1); array[0].set_str (imagename); return; } folder_name = Path::dirname (specification); try { std::string::size_type pos; std::string basename = Path::basename (specification); size_t num = 0; while ( (pos = basename.find_last_of (']')) < std::string::npos && num < max_num_sequences) { insert_str (basename.substr (pos+1)); basename = basename.substr (0, pos); if ( (pos = basename.find_last_of ('[')) == std::string::npos) throw Exception ("malformed image sequence specifier for image \"" + specification + "\""); insert_seq (basename.substr (pos+1)); num++; basename = basename.substr (0, pos); } insert_str (basename); for (size_t i = 0; i < array.size(); i++) if (array[i].is_sequence()) if (array[i].sequence().size()) for (size_t n = 0; n < array[i].sequence().size()-1; n++) for (size_t m = n+1; m < array[i].sequence().size(); m++) if (array[i].sequence() [n] == array[i].sequence() [m]) throw Exception ("malformed image sequence specifier for image \"" + specification + "\" (duplicate indices)"); } catch (...) { array.resize (1); array[0].set_str (imagename); throw; } }
void identify(treasure_type *item) { /*{ Something has been identified }*/ integer i1,x1,x2; treas_ptr curse; x1 = item->tval; x2 = item->subval; if (strstr(item->name,"|") != NULL) { for (i1 = 0; i1 < MAX_TALLOC; i1++) { //with t_list[i1] do; if ((t_list[i1].tval == x1) && (t_list[i1].subval == x2)) { unquote(t_list[i1].name); known1(t_list[i1].name); } } for (i1 = Equipment_min; i1 <= Equipment_secondary; i1++) { //with equipment[i1] do; if ((equipment[i1].tval == x1) && (equipment[i1].subval == x2)) { unquote(equipment[i1].name); known1(equipment[i1].name); } } for(curse = inventory_list; curse != nil; curse = curse->next) { //with curse^.data do; if ((curse->data.tval == x1) && (curse->data.subval == x2)) { unquote(curse->data.name); known1(curse->data.name); } } i1 = 0; do { i1++; //with object_list[i1] do; if ((object_list[i1].tval == x1) && (object_list[i1].subval == x2)) { if (strstr(object_list[i1].name,"%T") != NULL) { insert_str(object_list[i1].name," %T|",""); object_ident[i1] = true; } else { unquote(object_list[i1].name); known1(object_list[i1].name); object_ident[i1] = true; } } } while (i1 != MAX_OBJECTS); } /* end if | */ };
int main(int argc, char *argv[]) { p_node root = node_init(); int i = 0; printf("Please input pattern number:"); int num = 0; scanf("%d",&num); char tmp_str[MAX_SIZE]; printf("Please input patterns:\n"); while(num) { scanf("%s", tmp_str); insert_str(root, tmp_str); num --; } node_get_count(root, &i); node_init_status(root, status, &status_count); ac_create(); printf("base:"); for (i = 0; i < status_count; i++) { printf("%d ", ac_base[i]); } printf("\nnext:"); for (i = 0; i < status_count; i++) { printf("%d ", ac_next[i]); } printf("\ncheck:"); for (i = 0; i < status_count; i++) { printf("%d ", ac_check[i]); } printf("\nPlease input txt:"); scanf("%s", tmp_str); run(tmp_str); return 0; }
owerror_t osens_desc_receive(OpenQueueEntry_t* msg, coap_header_iht* coap_header, coap_option_iht* coap_options) { owerror_t outcome = E_FAIL; uint8_t n = 0; static uint8_t buf[128]; uint8_t *pbuf = &buf[0]; switch (coap_header->Code) { case COAP_CODE_REQ_GET: // reset packet payload msg->payload = &(msg->packet[127]); msg->length = 0; // /d if (((coap_options[1].length == 0) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH)) || (coap_options[1].type != COAP_OPTION_NUM_URIPATH)) { osens_brd_id_t board_info; if(osens_get_brd_desc(&board_info)) { pbuf = insert_str(pbuf, (uint8_t*)"{\"v\":", 5,0); pbuf = insert_uint(pbuf,board_info.hardware_revision); pbuf = insert_str(pbuf, (uint8_t*)",\"m\":", 5,0); pbuf = insert_str(pbuf, board_info.model, strlen((char *) board_info.model),1); pbuf = insert_str(pbuf, (uint8_t*)",\"id\":", 6,0); pbuf = insert_uint(pbuf,board_info.sensor_id); pbuf = insert_str(pbuf, (uint8_t*)",\"npts\":", 8,0); pbuf = insert_uint(pbuf,board_info.num_of_points); pbuf = insert_str(pbuf, (uint8_t*)"}", 1,0); } else pbuf = insert_str(pbuf,(uint8_t*)"{}",2,0); outcome = E_SUCCESS; } // /d/pt/1 or /d/pt/12 else if (coap_options[1].length == 2 && coap_options[1].pValue[0] == 'p' && coap_options[1].pValue[1] == 't' && (coap_options[2].length == 1 || coap_options[2].length == 2)) { osens_point_desc_t pt_desc; uint8_t index; if(coap_options[2].length == 2) index = (coap_options[2].pValue[0] - 0x30) * 10 + (coap_options[2].pValue[1] - 0x30); else index = coap_options[2].pValue[0] - 0x30; if(osens_get_pdesc(index,&pt_desc)) { pbuf = insert_str(pbuf, (uint8_t*)"{\"n\":", 5, 0); pbuf = insert_str(pbuf, pt_desc.name, strlen((char*) pt_desc.name), 1); pbuf = insert_str(pbuf, (uint8_t*)",\"t\":", 5, 0); pbuf = insert_uint(pbuf, pt_desc.type); pbuf = insert_str(pbuf, (uint8_t*)",\"u\":", 5, 0); pbuf = insert_uint(pbuf, pt_desc.unit); pbuf = insert_str(pbuf, (uint8_t*)",\"ar\":", 6, 0); pbuf = insert_uint(pbuf, pt_desc.access_rights); pbuf = insert_str(pbuf, (uint8_t*)",\"s\":", 5, 0); pbuf = insert_uint(pbuf, pt_desc.sampling_time_x250ms); pbuf = insert_str(pbuf, (uint8_t*)"}", 1, 0); } else pbuf = insert_str(pbuf,(uint8_t*)"{}",2,0); outcome = E_SUCCESS; } if(outcome == E_SUCCESS) { n = ((uint32_t)pbuf - (uint32_t)buf); packetfunctions_reserveHeaderSize(msg, 1 + n); msg->payload[0] = COAP_PAYLOAD_MARKER; memcpy(&msg->payload[1], buf, n); coap_header->Code = COAP_CODE_RESP_CONTENT; } break; case COAP_CODE_REQ_PUT: // reset packet payload msg->payload = &(msg->packet[127]); msg->length = 0; // set the CoAP header coap_header->Code = COAP_CODE_RESP_CHANGED; outcome = E_SUCCESS; break; default: outcome = E_FAIL; break; } return outcome; }
owerror_t osens_val_receive( OpenQueueEntry_t* msg, coap_header_iht* coap_header, coap_option_iht* coap_options ) { owerror_t outcome = E_FAIL; uint8_t n; static uint8_t buf[128]; uint8_t *pbuf = &buf[0]; uint8_t index; switch (coap_header->Code) { case COAP_CODE_REQ_GET: // reset packet payload msg->payload = &(msg->packet[127]); msg->length = 0; // /s if (((coap_options[1].length == 0) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH)) || (coap_options[1].type != COAP_OPTION_NUM_URIPATH)) { } // /s/1 or /s/12 else if(((coap_options[1].length == 1 || coap_options[1].length == 2)) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH)) { osens_point_t pt; #if (MYLINKXS_LIGHT_CONTROL == 0) if(coap_options[1].length == 2) index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30); else index = coap_options[1].pValue[0] - 0x30; if(osens_get_point(index,&pt)) { pbuf = insert_str(pbuf,(uint8_t*)"{\"v\":",5,0); pbuf = insert_point_val(pbuf,&pt); pbuf = insert_str(pbuf,(uint8_t*)"}",1,0); #if (ENABLE_DEBUG_RFF == 1) && (DBG_APP_1 == 1) uint8_t pos=0; uint8_t *paux; rffbuf[pos++]= 0x85; rffbuf[pos++]= index; paux = (uint8_t*) &pt.value.fp32; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; paux = (uint8_t*) &pbuf[0]; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; openserial_printStatus(STATUS_RFF,(uint8_t*)&rffbuf,pos); #endif } else pbuf = insert_str(pbuf,(uint8_t*)"{}",2,0); #else //QUANDO TRABALHANDO COM A LAMPADA ESTAVA ESTE OUTRO CODIGO //TODO!!! DEIXAR O CODIGO UNICO pt.type = OSENS_DT_U8; pt.value.u8 = light_get_value(); pbuf = insert_str(pbuf,(uint8_t*)"{\"v\":",5,0); pbuf = insert_point_val(pbuf,&pt); pbuf = insert_str(pbuf,(uint8_t*)"}",1,0); #endif outcome = E_SUCCESS; } if(outcome == E_SUCCESS) { n = ((uint32_t)pbuf - (uint32_t)buf); packetfunctions_reserveHeaderSize(msg, 1 + n); msg->payload[0] = COAP_PAYLOAD_MARKER; memcpy(&msg->payload[1], buf, n); coap_header->Code = COAP_CODE_RESP_CONTENT; } break; case COAP_CODE_REQ_PUT: // reset packet payload msg->payload = &(msg->packet[127]); msg->length = 0; #if (DEBUG_LOG_RIT == 1) { uint8_t pos=0; rffbuf[pos++]= RFF_COMPONENT_STORMCOAP_TX; rffbuf[pos++]= 0x01; rffbuf[pos++]= coap_options[1].length; rffbuf[pos++]= coap_options[2].length; rffbuf[pos++]= coap_options[1].type; rffbuf[pos++]= coap_options[2].type; //rffbuf[pos++]= sensor_points.points[0].value.value.u8; openserial_printStatus(STATUS_RFF,(uint8_t*)&rffbuf,pos); } #endif // /s/2/-12.45 or /s/12/12.45 if((coap_options[1].length == 1 || coap_options[1].length == 2) && (coap_options[2].length > 0) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH) && (coap_options[2].type == COAP_OPTION_NUM_URIPATH)) { #if 0 uint8_t index; double number; osens_point_t pt; if(coap_options[1].length == 2) index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30); else index = coap_options[1].pValue[0] - 0x30; number = decode_number(coap_options[2].pValue,coap_options[2].length); pt.type = osens_get_ptype(index); if(pt.type >= 0) { set_point_val(&pt,number); if(osens_set_pvalue(index,&pt)) { // set the CoAP header coap_header->Code = COAP_CODE_RESP_CHANGED; outcome = E_SUCCESS; } } #else // switch on the light pulse (50 ms) light_on(); opentimers_start(1000,TIMER_ONESHOT,TIME_MS,light_timer); #endif } break; default: outcome = E_FAIL; break; } return outcome; }
owerror_t osens_val_receive( OpenQueueEntry_t* msg, coap_header_iht* coap_header, coap_option_iht* coap_options ) { owerror_t outcome = E_FAIL; uint8_t n; static uint8_t buf[128]; uint8_t *pbuf = &buf[0]; switch (coap_header->Code) { case COAP_CODE_REQ_GET: // reset packet payload msg->payload = &(msg->packet[127]); msg->length = 0; // /s if (((coap_options[1].length == 0) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH)) || (coap_options[1].type != COAP_OPTION_NUM_URIPATH)) { // WE DO NOT HAVE SPACE FOR A FULL FRAME WITH ALL PARAMETERS // at ~80 bytes we have a overflow /* uint8_t m; osens_point_t pt; uint8_t num_points = osens_get_num_points(); pbuf = insert_str(pbuf,(uint8_t*)"[",1,0); if(num_points == 0) { pbuf = insert_str(pbuf,(uint8_t*)"{}",2,0); } else { for(m = 0 ; m < num_points ; m++) { if(osens_get_point(m,&pt)) { pbuf = insert_str(pbuf, (uint8_t*)"{\"idx\":", 7,0); pbuf = insert_uint(pbuf, m); pbuf = insert_str(pbuf, (uint8_t*)",\"v\":", 5,0); pbuf = insert_point_val(pbuf, &pt); if (m < (num_points - 1)) pbuf = insert_str(pbuf, (uint8_t*)"},", 2,0); else pbuf = insert_str(pbuf, (uint8_t*)"}", 1,0); } } } pbuf = insert_str(pbuf,(uint8_t*)"]",1,0); outcome = E_SUCCESS; */ } // /s/1 or /s/12 else if(((coap_options[1].length == 1 || coap_options[1].length == 2)) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH)) { uint8_t index; osens_point_t pt; if(coap_options[1].length == 2) index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30); else index = coap_options[1].pValue[0] - 0x30; if(osens_get_point(index,&pt)) { pbuf = insert_str(pbuf,(uint8_t*)"{\"v\":",5,0); pbuf = insert_point_val(pbuf,&pt); pbuf = insert_str(pbuf,(uint8_t*)"}",1,0); } else pbuf = insert_str(pbuf,(uint8_t*)"{}",2,0); outcome = E_SUCCESS; } if(outcome == E_SUCCESS) { n = ((uint32_t)pbuf - (uint32_t)buf); packetfunctions_reserveHeaderSize(msg, 1 + n); msg->payload[0] = COAP_PAYLOAD_MARKER; memcpy(&msg->payload[1], buf, n); coap_header->Code = COAP_CODE_RESP_CONTENT; } break; case COAP_CODE_REQ_PUT: // reset packet payload msg->payload = &(msg->packet[127]); msg->length = 0; // /s/2/-12.45 or /s/12/12.45 if((coap_options[1].length == 1 || coap_options[1].length == 2) && (coap_options[2].length > 0) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH) && (coap_options[2].type == COAP_OPTION_NUM_URIPATH)) { uint8_t index; double number; osens_point_t pt; if(coap_options[1].length == 2) index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30); else index = coap_options[1].pValue[0] - 0x30; number = decode_number(coap_options[2].pValue,coap_options[2].length); pt.type = osens_get_ptype(index); //DBG_LOG(0,("App I:%x P:%x L:%x T:%x \n",index,coap_options[2].pValue[0],coap_options[2].length,pt.type)); if(pt.type >= 0) { set_point_val(&pt,number); //DBG_LOG(1,("WrApp=I:%x T:%x V:%x\n",index,pt.type,pt.value.u16)); #if (MYLINKXS_SENSORS == 1) && (MYLINKXS_REMOTE_CONTROL == 1) simula_envio_cmd(&pt); #endif if(osens_set_pvalue(index,&pt)) { // set the CoAP header coap_header->Code = COAP_CODE_RESP_CHANGED; outcome = E_SUCCESS; } } } break; default: outcome = E_FAIL; break; } return outcome; }
void magic_init(unsigned long random_seed) { /* { Initialize all potions, wands, staves, scrolls, etc... }*/ integer i1,tmpv; vtype tmps; set_seed(random_seed); randes(); for (i1 = 1; i1 <= MAX_OBJECTS; i1++) { /* * The arrays of the object materals all start at 0. * Object subvals start at 1. When doing the lookup * subtract one from subval! */ tmpv = (0xFF & object_list[i1].subval); switch (object_list[i1].tval) { case potion1: case potion2: if (tmpv <= MAX_COLORS) { insert_str(object_list[i1].name,"%C",colors[tmpv-1]); } break; case scroll1: case scroll2: rantitle(tmps); insert_str(object_list[i1].name,"%T",tmps); break; case ring: if (tmpv <= MAX_ROCKS) { insert_str(object_list[i1].name,"%R",rocks[tmpv-1]); } break; case valuable_gems: if (tmpv <= MAX_ROCKS) { insert_str(object_list[i1].name,"%R",rocks[tmpv-1]); } break; case valuable_gems_wear: if (tmpv <= MAX_ROCKS) { insert_str(object_list[i1].name,"%R",rocks[tmpv-1]); } break; case amulet: if (tmpv <= MAX_AMULETS) { insert_str(object_list[i1].name,"%A",amulets[tmpv-1]); } break; case wand: if (tmpv <= MAX_METALS) { insert_str(object_list[i1].name,"%M",metals[tmpv-1]); } break; case chime: if (tmpv <= MAX_METALS) { insert_str(object_list[i1].name,"%M",metals[tmpv-1]); } break; case horn: if (tmpv <= MAX_HORNS) { insert_str(object_list[i1].name,"%H",horns[tmpv-1]); } break; case staff: if (tmpv <= MAX_WOODS) { insert_str(object_list[i1].name,"%W",woods[tmpv-1]); } break; case Food: if (tmpv <= MAX_MUSH) { insert_str(object_list[i1].name,"%M",mushrooms[tmpv-1]); } break; case rod : /* what happened to the rods? */ /* if (tmpv <= MAX_RODS) { insert_str(object_list[i1].name,"%D",rods[tmpv-1]); } */ break; case bag_or_sack: if (tmpv <= MAX_CLOTHS) { insert_str(object_list[i1].name,"%N",cloths[tmpv-1]); } break; case misc_usable: if (tmpv <= MAX_ROCKS) { insert_str(object_list[i1].name,"%R",rocks[tmpv-1]); } if (tmpv <= MAX_WOODS) { insert_str(object_list[i1].name,"%W",woods[tmpv-1]); } if (tmpv <= MAX_METALS) { insert_str(object_list[i1].name,"%M",metals[tmpv-1]); } if (tmpv <= MAX_AMULETS) { insert_str(object_list[i1].name,"%A",amulets[tmpv-1]); } break; default: break; } /* end switch */ } /* end for */ #if DO_DEBUG && 0 for (i1 = 1; i1 <= MAX_OBJECTS; i1++) { fprintf(debug_file,": object_list[%ld] = %s\n", i1, object_list[i1].name); } fflush(debug_file); #endif };
void objdes(char *out_val,treas_ptr ptr,boolean pref) { /*{ Returns a description of item for inventory }*/ char *cpos; vtype tmp_val; ENTER("objdes","i"); //with ptr->data. do; strcpy(tmp_val, ptr->data.name); // fprintf(debug_file,": obj start: >%s<\n",tmp_val); cpos = strstr(tmp_val,"|"); if (cpos != NULL) { *cpos = 0; } // fprintf(debug_file,": obj thmp1: >%s<\n",tmp_val); cpos = strstr(tmp_val,"^"); if (cpos != NULL) { *cpos = 0; } // fprintf(debug_file,": obj thmp2: >%s<\n",tmp_val); if (!(pref)) { cpos = strstr(tmp_val," ("); if (cpos != NULL) { *cpos = 0; } } // fprintf(debug_file,": obj thmp3: >%s<\n",tmp_val); insert_num(tmp_val,"%P1",ptr->data.p1,true); insert_num(tmp_val,"%P2",ptr->data.tohit,true); insert_num(tmp_val,"%P3",ptr->data.todam,true); insert_num(tmp_val,"%P4",ptr->data.toac,true); insert_num(tmp_val,"%P5",ptr->data.p1,false); insert_num(tmp_val,"%P6",ptr->data.ac,false); // fprintf(debug_file,": obj thmp4: >%s<\n",tmp_val); if (ptr->data.number != 1) { insert_str(tmp_val,"ch~","ches"); insert_str(tmp_val,"y~","ies"); insert_str(tmp_val,"~","s"); } else { insert_str(tmp_val,"~",""); } // fprintf(debug_file,": obj thmp5: >%s<\n",tmp_val); if (pref) { if (strstr(tmp_val,"&") != NULL) { insert_str(tmp_val,"&",""); if (ptr->data.number > 1) { sprintf(out_val,"%d%s",ptr->data.number,tmp_val); } else if (ptr->data.number < 1) { sprintf(out_val,"no more%s",tmp_val); } else if (is_vowel(tmp_val[1])) { sprintf(out_val,"an%s",tmp_val); } else { sprintf(out_val,"a%s",tmp_val); } } else { if (ptr->data.number > 0 ) { strcpy(out_val, tmp_val); } else { sprintf(out_val,"no more %s",tmp_val); } } } else { insert_str(tmp_val,"& ",""); strcpy(out_val, tmp_val); } #if DO_DEBUG fprintf(debug_file,": obj final: >%s<\n",out_val); #endif LEAVE("objdes","i"); };
void known2(char *object_str) { /*{ Remove 'Secret' symbol for identity of pluses }*/ insert_str(object_str, "^", ""); };
int new_submenu( char *pkg_short_name, char *menu, char **tcl_lines ) { int eax; char tmp[2048]; char tmp2[2048]; char searchstr[2048]; int idx = find_pos( "\"&Xtns\" all options", tcl_lines, 0 ), idx2; int insert_here; int last = find_pos( "\" all options", tcl_lines, idx + 1 ) + -1; char *first_quote; char *second_quote; int len; int terminator; if ( last == -1 ) { last = find_pos( "}]", tcl_lines, 0 ); } if ( is_submenu( menu ) == 0 ) { print_warning( "first line not a submenu specifier in 'entries-gisman'.\n" ); } else { len = strrchr( menu, ']' ) - strchr( menu, '[' ); strncpy( tmp, strchr( menu, '[' ) + 1, len ); tmp[ len + -1 ] = 0; sprintf( searchstr, "{cascad \"%s\"", tmp ); idx2 = find_pos( searchstr, tcl_lines, idx ); if ( idx2 != -1 && idx2 < last ) { print_warning( "submenu '%s' exists in GIS Manager's Xtns menu.\n", tmp[0] ); } else { insert_here = idx + 1; idx2 = find_pos( "{cascad ", tcl_lines, idx ); for ( ; idx2 != -1 && idx2 < last; ) { first_quote = strchr( tcl_lines[ idx2 ], '"' ); second_quote = strchr( &first_quote[1], '"' ); len = second_quote - first_quote; strncpy( tmp2, &first_quote[1], len ); tmp2[ len + -1 ] = 0; if ( strcmp( tmp, tmp2 ) < 0 ) { insert_here = idx2; break; } else { idx++; idx2 = find_pos( "{cascad ", tcl_lines, idx ); } } sprintf( tmp, " \t\t\t%s {} \"\" 1 {\n", searchstr ); insert_str( tmp, insert_here, tcl_lines ); insert_str( " \t\t\t}}\n", insert_here + 1, tcl_lines ); terminator = find_pos( "}]", tcl_lines, 0 ); sprintf( tmp, "#(DO_NOT_REMOVE_THIS_COMMENT) <%s> %s {} \"\" 1 {\n", pkg_short_name, searchstr ); insert_str( tmp, terminator + 1, tcl_lines ); } } return insert_here + 1; }
int main(int argc, char* argv[]) { int randnum = 0; char* nvram = NULL, *value = NULL; char* delimiter = NULL, *tmp, *del; int position=0, c, i = 0, func = 0, val; char help_msg[2048] = "Usage: xobjconf [-s | -x <nvram variable>] {[-a | -m <values> -p <position>] | [ -n <to get # of digits>] | [-i <position>] | [-v <value>] | [-e <value>] | [ -r <position>] | [ -o <new delimiter>]} [-d delimiter]\n\n"; init_gen( ); strcat(help_msg, "xobjconf command summary\n"); strcat(help_msg, "\txobjconf is a function to insert/delete/modify/view nvram variable by delimiter(s).\n"); strcat(help_msg, "\t<nvram variable>:input a nvram variable.\n"); strcat(help_msg, "\tdelimiter:a delimiter which is a seperator.\n"); strcat(help_msg, "\t-s : to specify a nvram variable.\n"); strcat(help_msg, "\t-x : to get total counts of token by specified delimiter.\n"); strcat(help_msg, "\t-d : to specify a delimiter.\n"); strcat(help_msg, "\t-a:insert a value to the nvram variable by delimiter.\n"); strcat(help_msg, "\t-r : remove a value from a nvram variable by specfied position.\n"); strcat(help_msg, "\t-v : remove a value from a nvram variable by specfied value.\n"); strcat(help_msg, "\t-e : to check a value in a nvram variable is exist or not.\n"); strcat(help_msg, "\t-o : to replace delimiters in a token list by new delimiters.\n"); strcat(help_msg, "\t-n : to get digits in a nvram variable by speficied counts.\n"); strcat(help_msg, "\t-m : to change a value by spcified position from a nvram variable.\n"); strcat(help_msg, "\t-i : to return the value which is at the specified position from a nvram variable by delimiter.\n\n"); if(argc <= 1 || ((isgraph(*argv[1]) || ispunct(*argv[1])) && *argv[1]!='-')){ fprintf(stderr, "%s", help_msg); exit(0); } while ((c = getopt(argc, argv, "a:d:e:i:m:n:o:p:r:v:s:x:h")) != -1){ switch (c) { case 'a': func = 1; value = optarg; break; case 'r': func = 2; position = atoi(optarg); break; case 'm': func = 3; value = optarg; break; case 's': nvram = optarg; break; case 'i': func = 4; position = atoi(optarg); break; case 'v': func = 5; value = optarg; position = 1; break; case 'x': func = 6; nvram = optarg; break; case 'e': func = 7; value = optarg; position = 1; break; case 'n': func = 8; val = atoi(optarg); position = 1; break; case 'o': func = 9; value = optarg; break; case 'p': position = atoi(optarg); break; case 'd': delimiter = optarg; break; case 'h': fprintf(stderr, "%s", help_msg); exit(0); break; default: fprintf(stderr, "%s", help_msg); exit(0); break; } } if(nvram_get(nvram) == NULL && delimiter != NULL && nvram != NULL){ if(func == 1 && value != NULL){ nvram_set(nvram, ""); //printf("Inserting '%s' at position 1 ...\n", value); //tmp = StrDup(nvram_get(nvram)); //value = insert_str(tmp, value, delimiter, 1); //tmp = StrDup(insert_str(nvram_get(nvram), value, delimiter, 1)); //nvram_set(nvram, value); nvram_set(nvram, StrDup(insert_str(nvram_get(nvram), value, delimiter, 1))); printf("%s\n", nvram_get(nvram)); } else{ fprintf(stderr, "%s", help_msg); exit(0); } } else if(delimiter != NULL && position > 0 && nvram != NULL){ if(func == 1 && value != NULL){ //printf("Inserting %s at position %d ...\n", value, position); //tmp = StrDup(nvram_get(nvram)); //value = insert_str(tmp, value, delimiter, 1); //nvram_set(nvram, value); nvram_set(nvram, insert_str(nvram_get(nvram), value, delimiter, position)); printf("%s\n", nvram_get(nvram)); } else if(func == 2){ //printf("Deleting position %d of %s ... \n", position, nvram); //tmp = StrDup(nvram_get(nvram)); //value = delete_str(nvram_get(nvram), delimiter, position); //nvram_set(nvram, value); nvram_set(nvram, delete_str(nvram_get(nvram), delimiter, position)); printf("%s\n", nvram_get(nvram)); } else if(func == 3 && value != NULL){ //printf("Modifying position %d by %s ... \n", position, value); //tmp = StrDup(nvram_get(nvram)); //value = modify_str(nvram_get(nvram), value, delimiter, position); //nvram_set(nvram, value); nvram_set(nvram, StrDup(modify_str(nvram_get(nvram), value, delimiter, position))); printf("%s\n", nvram_get(nvram)); } else if(func == 4){ //printf("\nReading the values from nvram variable %s ... \n", nvram); tmp = StrDup(nvram_get(nvram)); printf("%s\n", index_str(tmp, delimiter, position)); } else if(func == 5){ /*c = matchStrPosAt(delimiter, StrDup(nvram_get(nvram)), -1) + 1; for (i = 1; i <= c ; i++) { tmp = StrDup(nvram_get(nvram)); printf("tmp = %s\n", tmp); del = StrDup(index_str(tmp, delimiter, i)); printf("%s[%d] = %s\n", nvram, i, del); if(!strcmp(del, value)){ printf("value %s is matched in %s\n", value, nvram_get(nvram)); nvram_set(nvram, delete_str(nvram_get(nvram), delimiter, i)); printf("delete '%s' which is spcified at position %d\n", value, i); break; } }*/ nvram_set(nvram, delete_val(nvram_get(nvram), value, delimiter)); printf("%s\n", nvram_get(nvram)); } else if(func == 7){ tmp = StrDup(nvram_get(nvram)); if(val_exist(tmp, value, delimiter)) printf("%s is exist\n", value); else printf("%s is not exist\n", value); } else if(func == 8){ tmp = StrDup(nvram_get(nvram)); printf("%s\n", str2digits(tmp, delimiter, val)); } else{ fprintf(stderr, "%s", help_msg); exit(0); } } else if(func == 6 && delimiter != NULL && nvram != NULL){ position = matchStrPosAt(delimiter, nvram_get(nvram), -1) + 1; printf("%d\n", position); /*printf("Number of token counts is %d\n", position); for(i = 1; i <= position; i++){ tmp = StrDup(nvram_get(nvram)); printf("\t%s\n", index_str(tmp, delimiter, i)); }*/ } else if(func == 9 && delimiter != NULL && nvram != NULL && value != NULL){ /* this code section is fix the old delimiter(s) is a subset of new delimiter(s) issue */ randnum = number_range(6, 16); tmp = StrDup(nvram_get(nvram)); if(strstr(value, delimiter) && strlen(value) > strlen(delimiter)){ char temp_deli[]="olddeliisasubsetofnewdeli"; random_string(temp_deli, randnum); nvram_set(nvram, replaceall(tmp, delimiter, temp_deli, -2, matchStrPosAt(delimiter, tmp, -1))); strcpy(tmp, nvram_get(nvram)); nvram_set(nvram, replaceall(tmp, temp_deli, value, -2, matchStrPosAt(temp_deli, tmp, -1))); } else nvram_set(nvram, replaceall(tmp, delimiter, value, -2, matchStrPosAt(delimiter, tmp, -1))); printf("%s\n", nvram_get(nvram)); } else{ fprintf(stderr, "%s", help_msg); exit(0); } //StrFree(tmp); return 0; }
void new_ext_html(char *ext, char *gisbase, char **html, int major, int minor, int revision) { int pos1, pos2, pos3; int start, end; int insert_here; char *first_char; char *last_char; char item[MAXSTR]; int len; pos1 = find_pos("<b>Drivers sections:</b>", html, 0); /* first go to section on "Drivers" */ if (pos1 < 0) { /* we have a new version of the HTML docs that does not have a "Drivers" section anymore */ /* let's check for the special GEM comment */ pos1 = find_pos ("<!-- GEM Extensions StartHTML. Do not delete or change this comment! -->", html, 0); if (pos1 < 0) { /* sorry, I can't handle these HTML docs */ print_warning ("Unknown format of index.html. Unable to register HTML man pages.\n"); return; } } pos2 = find_pos("<hr>", html, pos1); /* the horizontal ruler marks the end of the HTML text */ if (find_pos("<h3>Installed extensions:</h3>", html, pos1) == -1) { /* Extensions section does not yet exist: create it now */ insert_str("<h3>Installed extensions:</h3>\n", pos2, html); insert_str("<ul>\n", pos2 + 1, html); insert_str("</ul>\n", pos2 + 2, html); insert_str("<p>\n", pos2 + 3, html); } start = find_pos("<h3>Installed extensions:</h3>", html, pos1); end = find_pos("</ul>", html, start); insert_here = start + 2; /* check if this entry already exists and if so: bail out or overwrite, if force mode */ sprintf(item, "\">%s", ext); pos3 = find_pos(item, html, insert_here); if (pos3 != -1) { /* exists: */ print_warning("list item '%s' exists in index.html.\n", ext); if ((FORCE) && (UPGRADE)) { sprintf(item, "<li><a href=\"../extensions/%s/index.html\">%s (%i.%i.%i)</a>\n", ext, ext, major, minor, revision); strcpy(html[pos3], item); } return; } /* now go through all links in the Extensions section and insert this one in the right alphabetical position */ pos3 = find_pos("<li><a href=", html, start); while ((pos3 != -1) && (pos3 < end)) { /* extract name of extension at this position */ first_char = strrchr(html[pos3], '"'); last_char = strrchr(html[pos3], '<'); len = (last_char - first_char) / sizeof(char); strncpy(item, first_char + 2 * sizeof(char), len); item[len - 1] = '\0'; /* get rid of '<' */ if (strcmp(ext, item) < 0) { insert_here = pos3; break; /* found our position: let's quit this! */ } /* look for next item */ start++; pos3 = find_pos("<li><a href=", html, start); } /* now insert new entry for this extension */ sprintf(item, "<li><a href=\"../extensions/%s/index.html\">%s (%i.%i.%i)</a>\n", ext, ext, major, minor, revision); insert_str(item, insert_here, html); }