void CheckExec(char *argv[]) { char *bufptr; strcpy(oldfilename,argv[execargn]); strcpy(newfilename,argv[execargn]); bufptr=(char *)strchr(newfilename,'.'); if(bufptr!=NULL) strset(bufptr,0); if(bind==TRUE) strcat(newfilename,".exe"); else strcat(newfilename,".lc"); if(CheckIfExists(oldfilename)==TRUE) return; bufptr=(char *)strchr(oldfilename,'.'); if(bufptr!=NULL) return; strcat(oldfilename,".exe"); if(CheckIfExists(oldfilename)==TRUE) return; bufptr=(char *)strchr(oldfilename,'.'); if(bufptr!=NULL) strset(bufptr,0); strcat(oldfilename,".le"); if(CheckIfExists(oldfilename)==TRUE) return; bufptr=(char *)strchr(oldfilename,'.'); if(bufptr!=NULL) strset(bufptr,0); strcat(oldfilename,".lx"); if(CheckIfExists(oldfilename)==TRUE) return; strcpy(oldfilename,argv[execargn]); }
void h_user(struct context *ctx, char *arg) { char *host; DebugIn(DEBUG_COMMAND); if (ctx->state == ST_conn) { ctx->state = ST_user; host = strchr(arg, '@'); if (host) { *host++ = 0; strset(&ctx->vhost, host); } if (!strcasecmp(arg, "ftp") || !strcasecmp(arg, "anonymous")) { reply(ctx, MSG_331_anon); strset(&ctx->user, "ftp"); ctx->anonymous = 1; } else { reply(ctx, MSG_331_user); strset(&ctx->user, arg); ctx->anonymous = 0; } } else reply(ctx, MSG_503_Already_logged_in); DebugOut(DEBUG_COMMAND); }
/************************************************* Function: CreatMyList(n) Description: 建立链表 Calls:none Called By: Loading() Input: 文件指针,指向一个存字母的文件的指针 Output: // 对输出参数的说明。 Return: 返回头指针 Others: *************************************************/ WorData *CreatMyList(FILE *open) { char readin='\0'; //第一次没加此语句造成readin的值无法确定 int i,j,flag; int k=0; WorData *p=NULL,*head=NULL,*q=NULL; while (1) { if ((p=(WorData *)malloc(sizeof(WorData)))==NULL) { printf("\nBuild Error 002"); return NULL; } else { strset(p->english,'\0'); //5.23 add strset(p->chinese,'\0'); p->next=NULL; } readin=fgetc(open); if (readin=='@') break; //未加该行,第二while将死循环 i=0; j=0; flag=0; //未赋初值错误 while (readin!='#') { while (flag!=1) { if (readin >=20) p->english[i++]=readin; //add if (readin >=20) 控制字符不加入到单词中 readin=fgetc(open); if(readin==' ') flag=1; } p->chinese[j++]=readin; readin=fgetc(open); } readin=fgetc(open); //由于在#号后还有一个换行符,未加该行,在第一个readin将读入换行符导致第二个while死循环 p->english[i]='\0'; p->chinese[j]='\0'; //写入结束 if (k==0) { head=p; q=p; } else { q->next=p; q=p; } k++; } fclose(open); return head; }
void RestoreConfig() { int n; char *envname; char envbuf[256]; char *name; char *ptr; char buf[80]; SetColor(LIGHTWHITE); SetBackColor(BLUE); OpenWindow(10,10,3,60); SetColor(YELLOW); Print_At(10,13," Restore Predefined Configuration "); SetColor(LIGHTWHITE); Print_At(11,12,"Enter file name:"); name=InputString(11,30,37,cfgfilename); if(name!=NULL && name[0]!=0) { strcpy(buf,name); ptr=(char *)strchr(buf,'.'); if(ptr!=NULL) strset(ptr,0); strcpy(cfgfilename,buf); strcat(buf,".d32"); n=open(buf,O_RDONLY | O_BINARY); if(n==-1) { envname=getenv("DOS32A"); if(envname!=NULL) { ptr=strchr(envname,' '); if(ptr==NULL) ptr=strchr(envname,0); memset(envbuf,0,256); strncpy(envbuf,envname,(dword)ptr-(dword)envname); strcat(envbuf,"\\D32\\"); strcat(envbuf,buf); n=open(envbuf,O_RDWR | O_BINARY); } } if(n!=-1) { read(n,&id32,24); close(n); SetColor(LIGHTWHITE); SetBackColor(BLUE); strupr(buf); for(n=0; n<13; n++) { SetPos(24,66+n); PrintC(' '); } Print_At(24,66,"%.13s",buf); } else DiskError(); } ValidateConfig(); CloseWindow(); if(mainmenu_sel==1) ShowBannerStatus(); }
int main() { char tab[99]="abc"; char tab2[99]="abc"; strcat(tab,tab2);//³¹czy ³añcuchy printf("strcat = %s\n",tab); strcpy(tab,"abc");strcpy(tab2,"def"); printf("strcmp = %d\n",strcmp(tab,tab2));//potuwnuje ³añcuchy 0 jak takie same -1 jak ró¿ne strcpy(tab,"abc");strcpy(tab2,"def"); printf("strchr = %d\n",strchr(tab,"b"));//zwraca adres pierwszej litery b strrchr ostatniej strset(tab,'x');//wype³nia znekiem x ca³¹ tablicê lib od któregoœ jej momentu printf("strset = %s\n",tab); strcpy(tab,"abc"); strupr(tab);//na du¿e printf("strupr = %s\n",tab); strlwr(tab);//na ma³e printf("strlwr = %s\n",tab); //i wiele wiele innych system("PAUSE"); return 0; }
char * hl72str (struct hl7_part_t *message){ char separators[7]; /* list of separators in proper order */ char *msg_string; /* points to the message string */ int length; msg_string=strset(""); /* build the seperators string */ separators[0] = '\n'; separators[1] = '\n'; separators[2] = '\r'; separators[3] = message->lower->lower->lower->next->lower->lower->lower->data[0]; separators[4] = message->lower->lower->lower->next->next->lower->lower->lower->data[3]; separators[5] = message->lower->lower->lower->next->next->lower->lower->lower->data[0]; separators[6] = message->lower->lower->lower->next->next->lower->lower->lower->data[1]; separators[7] = '\000'; /* turn the message into a string */ msg_string = hl7join(message, msg_string, separators); /* fix the field separator field */ length=strlen(msg_string); strncpy(&msg_string[4], &msg_string[6], length-5); if (!(msg_string=(char *) realloc(msg_string, length-2))){ /* not enough memory, die */ exit(1); } return msg_string; } /* end hl72str */
void send_channel_users_info(User *user, Node *users, char *query, char *send_line) { Node *first = users; Node *p = first; int sent = 0; User *u = (User *) p->payload; if(strcmp(u->current_channel, query) == 0) { send_user_info(user, u, send_line); sent += 1; }; p = p->next; while(p != first) { u = (User *) p->payload; if(strcmp(u->current_channel, query) == 0) { send_user_info(user, u, send_line); sent += 1; }; p = p->next; }; if(sent > 0) { send_line = strset(":"); send_line = stradd(send_line, SERVER_NAME); send_line = stradd(send_line, " "); send_line = stradd(send_line, RPL_ENDOFWHO); send_line = stradd(send_line, " "); send_line = stradd(send_line, user->name); send_line = stradd(send_line, " #"); send_line = stradd(send_line, user->current_channel); send_line = stradd(send_line, ENDOFWHO); write(user->socket, send_line, strlen(send_line)); }; };
int main( int argc, char *argv[] ) { FILE *f; char buf[256]; line *head, *curr; int linenum = 0; if( argc < 2 ) { puts( "line: Usage line filename" ); return 0; } f = fopen( argv[1], "r" ); head = new_line("", ' ', 0 ); curr = head; do { strset( buf, 0 ); fgets( buf, 255, f ); chop( buf ); trim( buf ); puts( buf ); if( strcmp(buf, "") ) { curr->next = (struct line *)new_line( buf, 'Q', ++linenum ); curr = (line *)curr->next; } } while( !feof(f) ); print_line_list( head ); return 0; }
static int mavis_parse_in(mavis_ctx * mcx, struct sym *sym) { while (1) { switch (sym->code) { case S_script: mavis_script_parse(mcx, sym); continue; case S_chroot: sym_get(sym); parse(sym, S_equal); mcx->ftp_chroot = parse_bool(sym); continue; case S_service: sym_get(sym); parse(sym, S_equal); strset(&mcx->service, sym->buf); sym_get(sym); continue; case S_eof: case S_closebra: return MAVIS_CONF_OK; default: parse_error_expect(sym, S_script, S_service, S_chroot, S_closebra, S_unknown); } } }
void send_user_info(User *user, User *target, char *send_line) { send_line = strset(":"); send_line = stradd(send_line, SERVER_NAME); send_line = stradd(send_line, " "); send_line = stradd(send_line, RPL_WHOREPLY); send_line = stradd(send_line, " "); send_line = stradd(send_line, target->name); send_line = stradd(send_line, " "); if(strcmp(target->current_channel, DUMMY_CHANNEL) == 0) { send_line = stradd(send_line, DUMMY_CHANNEL); } else { send_line = stradd(send_line, "#"); send_line = stradd(send_line, target->current_channel); }; send_line = stradd(send_line, " "); send_line = stradd(send_line, target->name); send_line = stradd(send_line, " "); send_line = stradd(send_line, target->hostname); send_line = stradd(send_line, " "); send_line = stradd(send_line, SERVER_NAME); send_line = stradd(send_line, " "); send_line = stradd(send_line, target->name); send_line = stradd(send_line, " H :0 "); send_line = stradd(send_line, target->name); send_line = stradd(send_line, "\n"); write(user->socket, send_line, strlen(send_line)); };
void TestBounded( void ) { char bufA[80] = "FoO baR gOoBeR bLaH"; char bufB[80]; char *bufPtr; int status; size_t len; len = strlcpy( bufB, "FoO baR", sizeof( bufB ) ); /* copy string */ VERIFY( len == strlen( "FoO baR" ) ); len = strlcat( bufB, " gOoBeR bLaH", sizeof( bufB ) ); /* append rest */ VERIFY( len == strlen( bufA ) ); status = strcmp( bufA, bufB ); /* check result */ VERIFY( status == 0 ); bufPtr = strset( bufB, 0x00 ); /* zero out buffer */ VERIFY( bufPtr == bufB ); len = strlcpy( bufB, "ABCDEFGHIJ", 3 ); /* copy two chars */ VERIFY( len == strlen( "ABCDEFGHIJ" ) ); len = strlcat( bufB, "CDEFGHIJ", 6 ); /* copy three more */ VERIFY( len == strlen( "ABCDEFGHIJ" ) ); status = strcmp( bufB, "ABCDE" ); /* ensure only five chars */ VERIFY( status == 0 ); len = strlcat( bufB, "junk", 3 ); /* ensure no running off */ VERIFY( len == 3 ); bufPtr = strnset( bufB, 0x00, 10 ); /* blank string */ VERIFY( bufPtr == bufB ); }
char * hl7get (struct hl7_part_t *message, struct hl7_location_t *given_location){ struct hl7_part_t *hl7_part; struct hl7_location_t *location; char *msg_string; /* points to the message string */ char separators[7]; /* list of separators in proper order */ int i, depth = 0; /* initialize the pointer to the string that is returning the value */ msg_string = strset(""); /* Traverse the tree */ hl7_part = message->lower; for (location = given_location ; location->next ; location=location->next){ /*next for the count */ for(i=location->count; i ; i--) { if(hl7_part->next){ hl7_part=hl7_part->next; } else { return msg_string; } } /* lower each level */ if(hl7_part->lower){ depth++; hl7_part=hl7_part->lower; } else { /* return msg_string; */ } } /* this needs to be a subroutine because we just did it twice */ /* build the seperators string */ separators[0] = '\n'; separators[1] = '\n'; separators[2] = '\r'; separators[3] = message->lower->lower->lower->next->lower->lower->lower->data[0]; separators[4] = message->lower->lower->lower->next->next->lower->lower->lower->data[3]; separators[5] = message->lower->lower->lower->next->next->lower->lower->lower->data[0]; separators[6] = message->lower->lower->lower->next->next->lower->lower->lower->data[1]; separators[7] = '\000'; printf("The depth is >%d<\n", depth); hl7printlocation(given_location); /* Call the join function, */ msg_string=hl7join(hl7_part, msg_string, &separators[depth+1]); /* return the string that we found */ return msg_string; } /* end hl7rawget */
void main () { int i; for (i=0; i < 4; i++) strset (a[i],'Z'); for (i=0; i < 4; i++) PR (a[i]); getch(); }
void clrcmdline(char * const str, const unsigned orgx, const unsigned orgy) { if(str) { goxy(orgx, orgy); fputmc(' ', strlen(str) + 1, stdout); strset(str, 0); } goxy(orgx, orgy); }
void CLevel::ClearLevelInfo() { int a; strset(iGeneralLevelInfo.iComment,0); iGeneralLevelInfo.iTimeLimit=0; iRandomCratesDM.clear(); iRandomCratesNormal.clear(); for (a=0;a<EEnemyAmount;a++) iGeneralLevelInfo.iEnemies[a]=0; }
int main() { elemento **mat; int ntestes; char sequencia1[100]; char sequencia2[100]; char novaseq1[200]= ""; char novaseq2[200]= ""; //tamanho = quantidade de elementos iguais int tamanho; //n = tamanho sequencia 1 int n; //m = tamanho sequencia 2 int m; //ntestes é a quantidade de testes que terei no meu programa scanf("%d", &ntestes); // esse for pega as 2 proximas sequencias e resolve o problema pra elas, e assim para todo o par de sequencias for(int i=0;i<ntestes;i++) { scanf("%s", sequencia1); scanf("%s", sequencia2); n = strlen(sequencia1); m = strlen(sequencia2); //funcao que cria a matriz alinhamento(sequencia1,sequencia2,&mat); //funcao recursiva que pega o resultado e coloca tamanho = resposta(mat,sequencia1,sequencia2,novaseq1,novaseq2,m,n,0); printf("Tamanho: %d",tamanho); printf("\nAlinhamento: \n"); printf("%s \n",novaseq1); printf("%s \n",novaseq2); strset(novaseq1,0); strset(novaseq2,0); free(&mat); printf("\n"); } return 0; }
static void handle_element_text_packet(Simply *simply, Packet *data) { ElementTextPacket *packet = (ElementTextPacket*) data; SimplyElementText *element = (SimplyElementText*) simply_stage_get_element(simply->stage, packet->id); if (!element) { return; } if (element->time_units != packet->time_units) { element->time_units = packet->time_units; simply_stage_update_ticker(simply->stage); } strset(&element->text, packet->text); simply_stage_update(simply->stage); }
// add a text line to the end, unless it's an empty line void Text::add_line (c_char t) { if (t == NULL) return; if (lines == NULL) // if it's empty { lines = new line_type; lines->text = NULL; strset (&lines->text, t, MSG_SIZE); lines->next = NULL; } else { line_type *l_buf = lines; while (l_buf->next != NULL) // else find the last l_buf = l_buf->next; l_buf->next = new line_type; l_buf->next->text = NULL; strset (&l_buf->next->text, t, MSG_SIZE); l_buf->next->next = NULL; } line_num++; }
void TestMove( void ) { char bufA[80] = "FoO baR gOoBeR bLaH"; char bufB[80]; char *bufPtr; char *newBuf; int status; bufPtr = strcpy( bufB, "FoO baR" ); /* copy string */ VERIFY( bufPtr == bufB ); bufPtr = strcat( bufB, " gOoBeR bLaH" ); /* append the rest */ VERIFY( bufPtr == bufB ); status = strcmp( bufA, bufB ); /* check result */ VERIFY( status == 0 ); bufPtr = strset( bufB, 0x00 ); /* zero out buffer */ VERIFY( bufPtr == bufB ); bufPtr = strncpy( bufB, "ABCDEFGHIJ", 2 ); /* copy two bytes */ VERIFY( bufPtr == bufB ); bufPtr = strncat( bufB, "CDEFGHIJ", 3 ); /* copy three more */ VERIFY( bufPtr == bufB ); status = strcmp( bufB, "ABCDE" ); /* ensure only five bytes */ VERIFY( status == 0 ); bufPtr = strnset( bufB, 0x00, 10 ); /* blank string */ VERIFY( bufPtr == bufB ); status = strcmp( bufB, "" ); /* verify empty */ VERIFY( status == 0 ); bufPtr = strcpy( bufB, "abcdefghij" ); /* copy string */ VERIFY( bufPtr == bufB ); bufPtr = strrev( bufB ); /* reverse it */ VERIFY( bufPtr == bufB ); status = strcmp( bufB, "jihgfedcba" ); /* ensure reversed ok */ VERIFY( status == 0 ); newBuf = strdup( bufA ); /* duplicate string */ status = strcmp( bufA, newBuf ); VERIFY( status == 0 ); }
long _stdcall ping(char *error, char *host) { IPAddr ip; WORD w = MAKEWORD(1,1); WSADATA wsadata; strset(error, 0); WSAStartup(w, &wsadata); hostent* phostent; if( host[0] <= '9') ip = (IPAddr)inet_addr(host); else { phostent = gethostbyname(host); if(!phostent) { strcpy(error, "Unable to resolve host name."); return -1; } ip = *(DWORD*)(*phostent->h_addr_list); } HANDLE icmphandle = IcmpCreateFile(); char reply[sizeof(icmp_echo_reply)+8]; icmp_echo_reply* iep = (icmp_echo_reply*)&reply; iep->RoundTripTime = 0xffffffff; IcmpSendEcho(icmphandle,ip,0,0,NULL,reply,sizeof(icmp_echo_reply)+8,PING_TIMEOUT); IcmpCloseHandle(icmphandle); WSACleanup(); if(iep->RoundTripTime == PING_TIMEOUT) { strcpy(error, "Timeout."); return -1; } return iep->RoundTripTime; }
void send_names(User *user, Node *users, char *send_line) { Node *first = users; Node *p = users; User *target = (User *) p->payload; send_line = strset(":"); send_line = stradd(send_line, SERVER_NAME); send_line = stradd(send_line, " "); send_line = stradd(send_line, RPL_NAMREPLY); send_line = stradd(send_line, " "); send_line = stradd(send_line, user->name); send_line = stradd(send_line, " @ #"); send_line = stradd(send_line, user->current_channel); send_line = stradd(send_line, " :"); if(strcmp(target->current_channel, user->current_channel) == 0) { send_line = stradd(send_line, target->name); send_line = stradd(send_line, " "); }; p = p->next; target = (User *) p->payload; while(p != first) { if(strcmp(target->current_channel, user->current_channel) == 0) { send_line = stradd(send_line, target->name); send_line = stradd(send_line, " "); }; p = p->next; target = (User *) p->payload; }; send_line = stradd(send_line, "\n"); send_line = stradd(send_line, ":"); send_line = stradd(send_line, SERVER_NAME); send_line = stradd(send_line, " "); send_line = stradd(send_line, RPL_ENDOFNAMES); send_line = stradd(send_line, " "); send_line = stradd(send_line, user->name); send_line = stradd(send_line, " #"); send_line = stradd(send_line, user->current_channel); send_line = stradd(send_line, ENDOFNAMES); send_line = stradd(send_line, "\n"); send_all(user->current_channel, send_line, users); };
void CreateConfig() { int n; char *name; char *ptr; char buf[80]; SetColor(LIGHTWHITE); SetBackColor(BLUE); OpenWindow(10,10,3,60); SetColor(YELLOW); Print_At(10,13," Create Predefined Configuration "); SetColor(LIGHTWHITE); Print_At(11,12,"Enter file name:"); name=InputString(11,30,37,cfgfilename); if(name!=NULL && name[0]!=0) { strcpy(buf,name); ptr=(char *)strchr(buf,'.'); if(ptr!=NULL) strset(ptr,0); strcpy(cfgfilename,buf); strcat(buf,".D32"); n=open(buf,O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU); if(n!=-1) { write(n,&id32,24); close(n); SetColor(LIGHTWHITE); SetBackColor(BLUE); strupr(buf); for(n=0; n<13; n++) { SetPos(24,66+n); PrintC(' '); } Print_At(24,66,"%.13s",buf); } else DiskError(); } CloseWindow(); }
main() { int f=TRUE; clrscr(); fpt = fopen("library.dat","w"); printf("Enter today's date in this format (dd/mm/yy) : "); scanf("%d/%d/%d",&library.now.day, &library.now.month, &library.now.year); while (f) { printf("\nwrite name of the book (write \' END \' when finished) : "); scanf(" %[^\n]",&library.nob); if (strcmp(library.nob,"END") == 0 ) break; library=read(library); fwrite(&library , sizeof(record) , 1 , fpt); strset(library.nob,' '); } fclose(fpt); getch(); }
struct hl7_part_t * str2hl7 (char *message_string) { struct hl7_part_t *message; /* Message structure being worked on */ char delimiters[5], /* list of delimiters from the message */ separators[6], /* list of separators in proper order */ temp[5]; /* used to set the correct delimiters in the final message structure */ /* probably should check that the message begins with MSH and is longer than a minimum length... */ if (!(message=(struct hl7_part_t *)malloc(sizeof(struct hl7_part_t)))){ /* If we don't have enough memory, quit.*/ /* This is kind of abrupt and needs to be more elegant. */ exit (1); } /* put some sane values into the clean new structure */ message->lower=(struct hl7_part_t *)0; message->next=(struct hl7_part_t *)0; /* put copy of hl7_string into the proper place in message structure */ message->data = strset (message_string); /* copy the hl7 delimiters to a string to hold them for processing */ strncpy (delimiters, &message->data[3], 5); /* close end of string with a terminator so that we don't dump core */ delimiters[5] = '\000'; /* reorder the delimiters into the proper order for seperation */ separators[0] = '\n'; separators[1] = '\r'; separators[2] = delimiters[0]; separators[3] = delimiters[4]; separators[4] = delimiters[1]; separators[5] = delimiters[2]; separators[6] = '\000'; /* remove the delimiters from the message so that we don't get confused */ message->data[4] = 'X'; message->data[5] = '|'; message->data[6] = 'Z'; message->data[7] = ' '; /* recursively call split to split the message on each seperator */ message->lower = hl7split (message, separators); /* put the delimiters into the proper place in the message structure */ /* replace this with the hl7set as quickly as possible. */ free (message->lower->lower->lower->next->lower->lower->lower->data); strncpy (temp, &delimiters[0], 1); temp[1] = '\000'; message->lower->lower->lower->next->lower->lower->lower->data = strset (temp); free (message->lower->lower->lower->next->next->lower->lower->lower->data); strncpy (temp, &delimiters[1], 4); temp[4] = '\000'; message->lower->lower->lower->next->next->lower->lower->lower->data = strset (temp); /* we are done, return the results */ return message; } /* end str2hl7 */
void simply_ui_set_text(SimplyUi *self, SimplyUiTextfieldId textfield_id, const char *str) { SimplyUiTextfield *textfield = &self->ui_layer.textfields[textfield_id]; char **str_field = &textfield->text; strset(str_field, str); mark_dirty(self); }
struct hl7_part_t * hl7split (struct hl7_part_t *hl7_part, char *separators) { struct hl7_part_t *head, /* begining of the data list */ *current; /* tail of the data list */ int begin = 0, /* start of the current string */ scan = 0; /* current position in string */ /* if list of separators is empty, we have reached a leaf, return null */ if (separators[0] == '\000'){ return (struct hl7_part_t *) 0; } /* setup structure for current level of operations */ if (!(current = head = (struct hl7_part_t *) malloc (sizeof (struct hl7_part_t)))) exit (1); /* initialize the structure to some sane values */ current->data = (char *) 0; current->next = (struct hl7_part_t *) 0; current->lower = (struct hl7_part_t *) 0; /* start looking thru the string for current seperator */ for (; hl7_part->data[scan]; scan++) { /* when we find the current seperator */ if (hl7_part->data[scan] == separators[0]) { /* replace the seperator with a NULL */ hl7_part->data[scan] = '\000'; /* copy string that we found to current data element */ current->data = strset (&hl7_part->data[begin]); /* split the string into substrings */ /* this is a little tricky */ /* send the seperator string starting with its _second_ element */ current->lower = hl7split (current, &separators[1]); /* setup for the next string that we find */ if (!(current->next =(struct hl7_part_t *)malloc(sizeof(struct hl7_part_t)))) exit (1); /* move the current pointer to the node that we just created */ current = current->next; /* initialize the data to some sane values */ current->data = (char *) 0; current->next = (struct hl7_part_t *) 0; current->lower = (struct hl7_part_t *) 0; /* set the begining of the string to follow the found string */ begin = scan + 1; } } /* We reached the end of the string without finding (another) seperator. But there is still a string that we need to take care of. */ /* put a copy of the string in the current data element */ current->data = strset (&hl7_part->data[begin]); /* split the data element into substrings */ /* this is a little tricky */ /* I send the seperator string starting with its _second_ element */ current->lower = hl7split (current, &separators[1]); /* get rid of string from parent, we stored it safely at this level */ free (hl7_part->data); /* set the parent data element to the null pointer so that it won't be pointing to the place where the string used to be. */ hl7_part->data = (char *) 0; /* return the list of substrings found to the parent. */ return head; } /* end split */
static int mavis_parse_in(mavis_ctx * mcx, struct sym *sym) { while (1) { switch (sym->code) { case S_script: mavis_script_parse(mcx, sym); continue; case S_chroot: sym_get(sym); parse(sym, S_equal); mcx->ftp_chroot = parse_bool(sym); continue; case S_passwd: sym_get(sym); parse(sym, S_file); parse(sym, S_equal); strset(&mcx->passwordfile, sym->buf); sym_get(sym); continue; case S_ftpusers: sym_get(sym); parse(sym, S_file); parse(sym, S_equal); strset(&mcx->ftpuserspath, sym->buf); sym_get(sym); continue; case S_shells: sym_get(sym); parse(sym, S_file); parse(sym, S_equal); strset(&mcx->shellpath, sym->buf); sym_get(sym); continue; case S_sslusers: sym_get(sym); parse(sym, S_file); parse(sym, S_equal); strset(&mcx->ssluserspath, sym->buf); sym_get(sym); continue; case S_check: sym_get(sym); switch (sym->code) { case S_ftpusers: sym_get(sym); parse(sym, S_equal); mcx->honour_ftpusers = parse_bool(sym); break; case S_shells: sym_get(sym); parse(sym, S_equal); mcx->require_valid_shell = parse_bool(sym); break; case S_sslusers: sym_get(sym); parse(sym, S_equal); mcx->lookup_sslusers = parse_bool(sym); break; default: parse_error_expect(sym, S_ftpusers, S_shells, S_sslusers, S_unknown); } continue; case S_eof: case S_closebra: return MAVIS_CONF_OK; default: parse_error_expect(sym, S_script, S_userid, S_groupid, S_path, S_mode, S_closebra, S_unknown); } } }
static int mavis_parse_in(mavis_ctx * mcx, struct sym *sym) { while (1) { switch (sym->code) { case S_script: mavis_script_parse(mcx, sym); continue; case S_userid: parse_userid(sym, &mcx->uid, &mcx->gid); continue; case S_groupid: parse_groupid(sym, &mcx->gid); continue; case S_home: sym_get(sym); parse(sym, S_equal); strset(&mcx->home, sym->buf); sym_get(sym); continue; case S_root: sym_get(sym); parse(sym, S_equal); strset(&mcx->root, sym->buf); sym_get(sym); continue; case S_upload: sym_get(sym); parse(sym, S_equal); strset(&mcx->incoming, sym->buf); sym_get(sym); continue; case S_eof: case S_closebra: { int bye = 0; if (!mcx->uid || !mcx->gid || !mcx->root) { struct passwd *pw; pw = getpwnam("ftp"); if (pw) { if (!mcx->uid) mcx->uid = pw->pw_uid; if (!mcx->gid) mcx->gid = pw->pw_gid; if (!mcx->root) mcx->root = Xstrdup(pw->pw_dir); } } if (!mcx->uid) { logmsg("%s: Fatal: anonymous ftp uid not set!", MAVIS_name); bye++; } if (!mcx->gid) { logmsg("%s: Fatal: anonymous ftp gid not set!", MAVIS_name); bye++; } if (!mcx->root) { logmsg("%s: Fatal: anonymous ftp root not set!", MAVIS_name); bye++; } if (bye) return -1; if (!mcx->home) mcx->home = Xstrdup("/"); return MAVIS_CONF_OK; } default: parse_error_expect(sym, S_script, S_userid, S_groupid, S_path, S_mode, S_closebra, S_unknown); } } }
int main(int argc, char *argv[]) { int ch, debug, i, magic, n, nargs, rval; char buf[4], *cmd, *p; if (pledge("stdio proc exec", NULL) == -1) err(1, "pledge"); debug = 0; magic = '%'; /* Default magic char is `%'. */ nargs = -1; while ((ch = getopt(argc, argv, "a:d0123456789")) != -1) switch (ch) { case 'a': if (optarg[0] == '\0' || optarg[1] != '\0') errx(1, "illegal magic character specification."); magic = optarg[0]; break; case 'd': debug = 1; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (nargs != -1) errx(1, "only one -# argument may be specified."); nargs = ch - '0'; break; default: usage(); } argc -= optind; argv += optind; if (argc < 2) usage(); /* * The command to run is argv[0], and the args are argv[1..]. * Look for %digit references in the command, remembering the * largest one. */ for (n = 0, p = argv[0]; *p != '\0'; ++p) if (ISMAGICNO(p)) { ++p; if (p[0] - '0' > n) n = p[0] - '0'; } /* * If there were any %digit references, then use those, otherwise * build a new command string with sufficient %digit references at * the end to consume (nargs) arguments each time round the loop. * Allocate enough space to hold the maximum command. */ strset(argv[0]); if (n == 0) { /* If nargs not set, default to a single argument. */ if (nargs == -1) nargs = 1; for (i = 1; i <= nargs; i++) { snprintf(buf, sizeof(buf), " %c%d", magic, i); stradd(buf); } /* * If nargs set to the special value 0, eat a single * argument for each command execution. */ if (nargs == 0) nargs = 1; } else nargs = n; if ((cmd = strdup(str)) == NULL) err(1, "strdup"); /* * (argc) and (argv) are still offset by one to make it simpler to * expand %digit references. At the end of the loop check for (argc) * equals 1 means that all the (argv) has been consumed. */ for (rval = 0; argc > nargs; argc -= nargs, argv += nargs) { strset("exec "); /* Expand command argv references. */ for (p = cmd; *p != '\0'; ++p) if (ISMAGICNO(p)) stradd(argv[*(++p) - '0']); else { strlcpy(buf, p, 2); stradd(buf); } /* Run the command. */ if (debug) (void)printf("%s\n", str); else if (mysystem(str)) rval = 1; } if (argc != 1) errx(1, "expecting additional argument%s after \"%s\"", (nargs - argc) ? "s" : "", argv[argc - 1]); exit(rval); }
/* * MarkDlgProc - handle messages from the mark dialog */ INT_PTR CALLBACK MarkDlgProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) { char buf[MARK_LEN]; char boxbuf[MARK_LEN]; int ret; HWND hdl; lparam = lparam; switch( msg ) { case WM_INITDIALOG: SendDlgItemMessage( hwnd, MARK_BOXED, BM_SETCHECK, 1, 0L ); hdl = GetDlgItem( hwnd, MARK_EDIT ); SetFocus( hdl ); return( FALSE ); // strcpy( buf, "---------" ); // SendDlgItemMessage( hwnd, MARK_EDIT, WM_SETTEXT, 0, (LPARAM)buf ); break; #ifndef NOUSE3D case WM_SYSCOLORCHANGE: CvrCtl3dColorChange(); break; #endif case WM_COMMAND: switch( wparam ) { case MARK_OK: ret = GetDlgItemText( hwnd, MARK_EDIT, buf, MARK_LEN ); if( ret == 0 ) { buf[0] = '\0'; } if( IsDlgButtonChecked( hwnd, MARK_BOXED ) ) { if( *buf == '\0' ) { WriteFn( "*" ); } else { strcpy( boxbuf, buf ); if( ret < MARK_LEN - 5 ) { strcpy( boxbuf, "* " ); strcpy( boxbuf + 2, buf ); strcpy( boxbuf + ret + 2, " *" ); } strcpy( buf, boxbuf ); strset( boxbuf, '*' ); WriteFn( boxbuf ); WriteFn( buf ); WriteFn( boxbuf ); } } else { WriteFn( buf ); } EndDialog( hwnd, -1 ); break; case MARK_CANCEL: EndDialog( hwnd, -1 ); break; default: return( FALSE ); } break; default: return( FALSE ); } return( TRUE ); } /* MarkDlgProc */