void GetGroupCText(int Code, char * str) { char st[21]; st[20]=0; switch(Code){ // C11~ C13 속도지령 방법 외 case ADDR_CMD_INPUT_SET : strcpy(st,"Select CMD In Type") ; break; case ADDR_CTRL_TYPE_SET : strcpy(st,"Select CTRL Type") ; break; case ADDR_CHANGE_DIRECTION : strcpy(st,"Direction Change") ; break; // C21~C24 가감속 시간 설정 case ADDR_ACCEL1_TIME : srtcpy(st,"Accel Ramp1 sec") ; break; case ADDR_DECEL1_TIME : strcpy(st,"Decel Ramp1 sec") ; break; case ADDR_ACCEL2_TIME : strcpy(st,"Accel Ramp2 sec") ; break; case ADDR_DECEL2_TIME : strcpy(st,"Decel Ramp2 sec") ; break; // C31~C38 다단 속도 설정 case ADDR_JOG_SPEED : strcpy(st,"Jog Speed Hz") ; break; case ADDR_DIN_SPEED2 : strcpy(st,"DIN Speed2 Hz") ; break; case ADDR_DIN_SPEED3 : strcpy(st,"DIN Speed3 Hz") ; break; case ADDR_DIN_SPEED4 : strcpy(st,"DIN Speed4 Hz") ; break; case ADDR_DIN_SPEED5 : strcpy(st,"DIN Speed5 Hz") ; break; case ADDR_DIN_SPEED6 : strcpy(st,"DIN Speed6 Hz") ; break; case ADDR_DIN_SPEED7 : strcpy(st,"DIN Speed7 Hz") ; break; case ADDR_DIN_SPEED8 : strcpy(st,"DIN Speed8 Hz") ; break; } strcopy(str,st); }
void buscar(char buscar[5]){ int i; char bus[5]; char nom[50]; srtcpy(bus,buscar); printf("ingrese el nombre a buscar: \n"); fgets(nom,50,stdin); for(i=0;i<2;i++){ if (strcmp(nom, Contacto.nombre)<= 0){// compara dos string si nom el string nom esta dentro de contacto.nombre lo muestra printf( "Nombre : %s", Contacto.nombre);// si se coloca el vallor a comparar == 0 busca la coincidencia exacta printf( "Apellido : %s", Contacto.apellido); printf( "Direccion : %s",Contacto.direccion); printf( "Ciudad : %s",Contacto.ciudad); printf( "Identificador : %s\n\n", Contacto.telefono); } } }
int main(int argc, char* argv[]) { // a global variable defined in errno.h that's "set by system // calls and some library functions [to a nonzero value] // in the event of an error to indicate what went wrong" errno = 0; // default to a random port int port = 0; // usage const char* usage = "Usage: server [-p port] /path/to/root"; // parse command-line arguments int opt; while ((opt = getopt(argc, argv, "hp:")) != -1) { switch (opt) { // -h case 'h': printf("%s\n", usage); return 0; // -p port case 'p': port = atoi(optarg); break; } } // ensure port is a non-negative short and path to server's root is specified if (port < 0 || port > SHRT_MAX || argv[optind] == NULL || strlen(argv[optind]) == 0) { // announce usage printf("%s\n", usage); // return 2 just like bash's builtins return 2; } // start server start(port, argv[optind]); // listen for SIGINT (aka control-c) signal(SIGINT, handler); // accept connections one at a time while (true) { // reset server's state reset(); // wait until client is connected if (connected()) { // parse client's HTTP request ssize_t octets = parse(); if (octets == -1) { continue; } // extract request's request-line // http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html const char* haystack = request; char* needle = strstr(haystack, "\r\n"); if (needle == NULL) { error(400); continue; } else if (needle - haystack + 2 > LimitRequestLine) { error(414); continue; } char line[needle - haystack + 2 + 1]; strncpy(line, haystack, needle - haystack + 2); line[needle - haystack + 2] = '\0'; // log request-line printf("%s", line); // devide line in: method, request target and http-version // method char* tok = strtok(line, " "); char met[strlen(token) + 1]; memset(met, '\0', sizeof(met)); strcpy(met, tok); //request-target tok = strtok(NULL, " "); char request_target[strlen(tok) + 1]; memset(request_target, '\0', sizeof(request_target)); strcpy(request_target, tok); //http-version tok = strtok(NULL, " "); char http[strlen(tok) - 1]; memset(http, '\0', sizeof(http)); strcpy(http, tok, 8); //valid check if(strtok(NULL, " ") != NULL) error(400); if(request_target[0] != '/') error(501); if(strchr(request_target, '"') != 0) error(400); if(strcmp(met, "GET") != 0) error(405); if(strcasecmp(http, "HTTP/1.1") != 0) error(505); const char dot = '.'; const char question = '?'; if(strcmp(request_target, dot) == 0) error(501); char* qquery; char query[100]; qquery = strchr(request_target, question); memset(query, '\0', sizeof(query)); if(qquery != 0) { if(strcmp(qquery, question) == 0) { char buff[1]; buff[0] = '\0'; strcpy(query, buff); } else { char buff[strlen(qquery)]; memset(buff, '\0', sizeof(buff)); srtcpy(buff, qquery + 1); strcpy(query, buff); } } else { char buff[1]; buff[0] = '\0'; strcpy(query, buff); } int queryLength; if(qquery != NULL) queryLength = strlen(qquery); else queryLength = 0; int aLen = strlen(request_target) - queryLength; char absolute_path[aLen + 1]; memset(absolute_path, '\0', sizeof(absolute_path)); strcpy(absolute_path, request_target, aLen); char root_path[strlen(root) + 1]; memset(root_path, '\0', sizeof(root_path)); strcpy(root_path, root); char full_path[strlen(root_path) + strlen(absolute_path) + 1]; memset(full_path, '\0', sizeof(full_path)); strcpy(full_path, root_path); strcat(full_path, absolute_path); // path is find if(access(full_path, F_OK) != 0) error(404); //path is readable if(access(full_path, R_OK) != 0) error(403); //path extention including dot char* dotExtension; char query_path[queryLength + 1]; memset(query_path, '\0', sizeof(query_path)); strcpy(query_path, request_target, queryLength); dotExtension = strchr(query_path, '.'); //path's extension char extension[strlen(dotExtenson) - 1]; memset(extension, '\0', sizeof(extension)); strcpy(extension, dotExtension + 1); // dynamic content if (strcasecmp("php", extension) == 0) { // open pipe to PHP interpreter char* format = "QUERY_STRING=\"%s\" REDIRECT_STATUS=200 SCRIPT_FILENAME=\"%s\" php-cgi"; char command[strlen(format) + (strlen(path) - 2) + (strlen(query) - 2) + 1]; sprintf(command, format, query, path); file = popen(command, "r"); if (file == NULL) { error(500); continue; } // load file ssize_t size = load(); if (size == -1) { error(500); continue; } // subtract php-cgi's headers from body's size to get content's length haystack = body; needle = memmem(haystack, size, "\r\n\r\n", 4); if (needle == NULL) { error(500); continue; } size_t length = size - (needle - haystack + 4); // respond to client if (dprintf(cfd, "HTTP/1.1 200 OK\r\n") < 0) { continue; } if (dprintf(cfd, "Connection: close\r\n") < 0) { continue; } if (dprintf(cfd, "Content-Length: %i\r\n", length) < 0) { continue; } if (write(cfd, body, size) == -1) { continue; } } // static content else { // look up file's MIME type const char* type = lookup(extension); if (type == NULL) { error(501); continue; } // open file file = fopen(path, "r"); if (file == NULL) { error(500); continue; } // load file ssize_t length = load(); if (length == -1) { error(500); continue; } //respond to client if (dprintf(cfd, "HTTP/1.1 200 OK\r\n") < 0) continue; if (dprintf(cfd, "Connection: close\r\n") < 0) continue; if (dprintf(cfd, "Content-Length: %i\r\n", length) < 0) continue; if (dprintf(cfd, "Content-Type: %s\r\n\r\n", type) < 0) continue; if (write(cfd, body, size) == -1) continue; } // announce OK printf("\033[32m"); printf("HTTP/1.1 200 OK"); printf("\033[39m\n"); } } }