ListExpr binary_aggregate_type_map( ListExpr args ) { if ( nl->IsAtom( args ) || 2 != nl->ListLength( args ) ) return NList::typeError( "Expect list of length 2" ); try { // stream value type check_argument( nl->First( args ), args, (StreamIterator<A>*)0 ); // function argument ListExpr funarg_le = nl->Second( nl->Second( args ) ); check_argument( funarg_le, args, (A*)0 ); // they must be equal if ( ! nl->Equal( nl->Second( nl->First(args) ), funarg_le ) ) throw runtime_error("Function und operator arguments must be equal"); // and function argument must be preceded by 'map' if ( ! NList(nl->First( nl->Second(args) )).isSymbol( "map" ) ) throw runtime_error("Expect symbol map in function definition" ); return map_result_type( (R*)0 ); } catch( const exception& e ) { return NList::typeError( e.what() ); } }
void command_cd(t_serv *server, t_fd *client, unsigned char *buffer) { char *path; char *tmp; if (ft_strcmp(client->user->path, "/") != 0) tmp = ft_strjoin(client->user->path + 1, "/"); else tmp = ft_strnew(0); if (!(path = ft_strjoin(tmp, (char *)buffer))) error(server, "Error on malloc from command_cd\n"); free(tmp); if (check_argument((char *)buffer) >= 0 && chdir(path) >= 0) { free(client->user->path); if (!(client->user->path = ft_strjoin("/", path))) error(server, "Error on malloc from command_cd\n"); tmp = ft_strjoin("cd", SUCCESS_TXT); } else tmp = ft_strjoin("cd", ERROR_TXT); if (!tmp) error(server, "Error on malloc from command_cd\n"); chdir(server->path); send_answer_spec(server, client, tmp); free(tmp); free(path); }
void check_argument( ListExpr stream_le, ListExpr root, StreamIterator<T>* ) { if ( nl->IsAtom( stream_le ) || 2 != nl->ListLength( stream_le ) ) throw runtime_error( "Expect list of length 2 as 1. argument"); if ( ! NList( nl->First( stream_le ) ).isSymbol( "stream" ) ) throw runtime_error( "Expect symbol stream as first argument" ); check_argument( nl->Second( stream_le ), root, (T*) 0 ); }
ListExpr binary_type_map( ListExpr args ) { if ( nl->IsAtom( args ) || 2 != nl->ListLength( args ) ) return NList::typeError( "Expect list of length 2" ); try { typedef typename O::first_argument_type A1; typedef typename O::second_argument_type A2; typedef typename O::result_type R; check_argument( nl->First( args ), args, (A1*)0 ); check_argument( nl->Second( args ), args, (A2*)0 ); return map_result_type( (R*)0 ); } catch( const exception& e ) { return NList::typeError( e.what() ); } }
ListExpr binary_stream_type_map( ListExpr args ) { if ( nl->IsAtom( args ) || 2 != nl->ListLength( args ) ) return NList::typeError( "Expect list of length 2" ); try { typedef typename O::first_argument_type A1; typedef typename O::second_argument_type A2; typedef typename O::result_type R; typedef typename R::second_type T; check_argument( nl->First( args ), args, (A1*)0 ); check_argument( nl->Second( args ), args, (A2*)0 ); return nl->TwoElemList( nl->SymbolAtom("stream"), map_stream_result_type( args, (T*)0, (O*)0 ) ); } catch( const exception& e ) { return NList::typeError( e.what() ); } }
static void check_arguments(int line, char *args[], int count, mipv6_conf_item_t *item) { int i; for (i = 0; i < count; i++) { switch (item->params[i]) { case MIPV6_PARAM_T_INT: check_argument(is_int(args[i + 1]), "integer", args[0], i, line); break; case MIPV6_PARAM_T_BOOLEAN: check_argument(is_boolean(args[i + 1]), "boolean", args[0], i, line); break; case MIPV6_PARAM_T_ONOFF: check_argument(is_onoff(args[i + 1]), "on/off", args[0], i, line); break; case MIPV6_PARAM_T_IDENTIFIER: check_argument(is_identifier(args[i + 1]), "identifier", args[0], i, line); break; case MIPV6_PARAM_T_ADDRESS: check_argument(is_address(args[i + 1]), "address", args[0], i, line); break; case MIPV6_PARAM_T_PREFIX: check_argument(is_prefix(args[i + 1]), "prefix", args[0], i, line); break; case MIPV6_PARAM_T_DOMAIN: check_argument(is_domain(args[i + 1], 0), "domain name" " or address", args[0], i, line); break; case MIPV6_PARAM_T_NAI: check_argument(is_nai(args[i + 1]), "NAI", args[0], i, line); break; default: break; } } }
ListExpr unary_type_map( ListExpr args ) { if ( nl->IsAtom( args ) || 1 != nl->ListLength( args ) ) return NList::typeError( "Expect list of length 1" ); try { typedef typename O::argument_type A; typedef typename O::result_type R; check_argument( nl->First( args ), args, (A*)0 ); return map_result_type( (R*)0 ); } catch( const exception& e ) { return NList::typeError( e.what() ); } }
int main(const int argc, const char *argv[]) { PERSON *ajout = NULL; int choice = 0; char temp[3] = ""; clear_screen(); create_users_file(USERSFILE); set_index_birthdays(); check_argument(argc, argv); do { printf("\t\n1. Encoder un nouvel anniversaire"); printf("\t\n2. Afficher les anniversaires"); printf("\t\n3. Charger un fichier d'anniversaires"); printf("\t\n4. Sauvegarder les anniversaires sur fich ier"); printf("\t\n5. Afficher le prochain anniversaire"); printf("\t\n6. Supprimer les anniversaires en cours"); printf("\t\n7. Supprimer un anniversaire"); printf("\t\n8. Quitter"); printf("\t\n\nVotre choix: "); fgets(temp, sizeof(temp), stdin); choice = atoi(temp); clean_string(temp); switch(choice) { case 1: set_birthday(&ajout); add_birthday(ajout); free(ajout); ajout = NULL; break; case 2: print_birthdays(); break; case 3: load_birthdays(); break; case 4: save_birthdays(); break; case 5: print_next_birthday(); break; case 6: clean_birthdays(); break; case 7: delete_birthday(); break; default: break; } if( choice != 8 ) { press_enter_to_continue(); clear_screen(); } }while( choice != 8 ); clean_birthdays(); clean_errno(); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int connection_file_descriptor; char temp_line[BUFFER]; char temp_char1, temp_char2; struct sockaddr_in server_address; struct sigaction act1; int characters_read; struct stat file_status; int data_file_descriptor; check_argument(argc,argv); act1.sa_handler = close_properly; sigemptyset(&act1.sa_mask); act1.sa_flags=0; sigaction(SIGINT, &act1, 0); listen_file_descriptor = Socket(AF_INET, SOCK_STREAM, 0); bzero(&server_address, sizeof(server_address)); server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = htonl(INADDR_ANY); server_address.sin_port = htons(atoi(argv[1])); Bind(listen_file_descriptor, (struct sockaddr *) &server_address, sizeof(server_address)); Listen(listen_file_descriptor, 5); while(1) { data_file_descriptor = Open(filename, O_RDONLY); Fstat(data_file_descriptor, &file_status); connection_file_descriptor = Accept(listen_file_descriptor, (struct sockaddr *) NULL, NULL); characters_read = Read(connection_file_descriptor, &temp_char1, 1); while(characters_read > 0) { //printf("%c",temp_char1); characters_read = Read(connection_file_descriptor, &temp_char2, 1); if(temp_char2=='\n' && temp_char1=='\r') { temp_char1=temp_char2; //printf("%c",temp_char1); characters_read = Read(connection_file_descriptor, &temp_char2, 1); if(temp_char2=='\r') { printf("Received request\n"); printf("Sending HTTP response\n"); break; } } temp_char1=temp_char2; } strcpy(temp_line, "HTTP/1.1 200 OK\n"); Write(connection_file_descriptor, temp_line, strlen(temp_line)); strcpy(temp_line, "Server: Barjatiya\n"); Write(connection_file_descriptor, temp_line, strlen(temp_line)); strcpy(temp_line, "Last-Modified: Fri, 29 Sep 2006 10:40:55 GMT\n"); Write(connection_file_descriptor, temp_line, strlen(temp_line)); strcpy(temp_line, "Accept-Ranges: bytes\n"); Write(connection_file_descriptor, temp_line, strlen(temp_line)); sprintf(temp_line, "Content-Length: %d\n", (int)file_status.st_size); Write(connection_file_descriptor, temp_line, strlen(temp_line)); strcpy(temp_line, "Content-Type: text/html\n"); Write(connection_file_descriptor, temp_line, strlen(temp_line)); strcpy(temp_line, "\n"); Write(connection_file_descriptor, temp_line, strlen(temp_line)); printf("Sending file\n"); characters_read = Read(data_file_descriptor, temp_line, BUFFER -1); while(characters_read > 0) { Write(connection_file_descriptor, temp_line, characters_read); characters_read = Read(data_file_descriptor, temp_line, BUFFER -1); } Close(data_file_descriptor); printf("File send complete\n"); Close(connection_file_descriptor); printf("Connection closed\n\n"); } return 0; }