int main(int argc, char **argv) { if (argc != 3) { usage(argv[0]); return 127; } char* fin_name = argv[1]; char* fout_name = argv[2]; // Make sure we have an input and output file if (fin_name == NULL || fout_name == NULL) { usage(argv[0]); return 127; } // Open the input and output files srt_file* fin = srt_open_read(fin_name); if (fin == NULL) { fprintf(stderr, "Error opening input file %s: %s\n", fin_name, strerror(errno)); return 1; } srt_file* fout = srt_open_write(fout_name); if (fout == NULL) { fprintf(stderr, "Error opening output file %s: %s\n", fout_name, strerror(errno)); return 1; } sub_text sub; sub.text = NULL; sub.buf_len = 0; int error = srt_read(fin, &sub); fout->delimiter = fin->delimiter; int id = 1; while (!error) { sub.id = id++; if ((error = srt_write(fout, &sub))) break; error = srt_read(fin, &sub); } srt_close(fin); srt_close(fout); if (sub.text != NULL) { free(sub.text); } if (error != SRT_EOF) { fprintf(stderr, "Error at input line %u: %s\n", fin->line_no, srt_strerror(error)); return 2; } return 0; }
int main( int argc, char** argv ) { if (argc < 3) { fprintf(stderr, "Usage: %s <remote host> <remote port>\n", argv[0]); return 1; } int ss, st; struct sockaddr_in sa; int yes = 1; const char message [] = "This message should be sent to the other side"; srt_startup(); ss = srt_create_socket(); if ( ss == SRT_ERROR ) { fprintf(stderr, "srt_socket: %s\n", srt_getlasterror_str()); return 1; } sa.sin_port = htons(atoi(argv[2])); if ( inet_pton(AF_INET, argv[1], &sa.sin_addr) != 1) { return 1; } // This is obligatory only in live mode, if you predict to connect // to a peer with SRT version 1.2.0 or older. Not required since // 1.3.0, and all older versions support only live mode. //srt_setsockflag(ss, SRTO_SENDER, &yes, sizeof yes); // // In order to make sure that the client supports non-live message // mode, let's require this. int minversion = SRT_VERSION_FEAT_HSv5; srt_setsockflag(ss, SRTO_MINVERSION, &minversion, sizeof minversion); // Require also non-live message mode. int file_mode = SRTT_FILE; srt_setsockflag(ss, SRTO_TRANSTYPE, &file_mode, sizeof file_mode); srt_setsockflag(ss, SRTO_MESSAGEAPI, &yes, sizeof yes); // Note that the other side will reject the connection if the // listener didn't set the same mode. st = srt_connect(ss, (struct sockaddr*)&sa, sizeof sa); if ( st == SRT_ERROR ) { fprintf(stderr, "srt_connect: %s\n", srt_getlasterror_str()); return 1; } st = srt_send(ss, message, sizeof message); if ( st == SRT_ERROR ) { fprintf(stderr, "srt_sendmsg: %s\n", srt_getlasterror_str()); return 1; } st = srt_close(ss); if ( st == SRT_ERROR ) { fprintf(stderr, "srt_close: %s\n", srt_getlasterror_str()); return 1; } srt_cleanup(); return 0; }