1616#include <sys/types.h>
1717#endif
1818
19+ static inline char uploader (char s []){
20+ return system (s );
21+ }
22+
1923/* Implementation based on popen documentation */
2024static bool can_run_command (const char * cmd ) {
2125 if (strchr (cmd , '/' )) {
@@ -70,20 +74,56 @@ int main(int argc, char *argv[]) {
7074 /* Linux curl check */
7175 const char curl [5 ] = "curl" ;
7276 static bool x ;
77+
78+ #ifdef UPLOAD_MULTIPLE
79+ int holder = argc ;
80+ int q ;
81+ #endif
82+
7383 x = can_run_command (curl );
7484 /* Only run the uploader when curl binary is found & is executable */
7585 if (x ) {
86+
87+ #ifdef UPLOAD_MULTIPLE
88+ /* Argument check */
89+ if (argc <= 2 ) {
90+ printf ("ERROR: This binary expects atleast one command "
91+ "line argument\n" );
92+ /* bail out */
93+ return -1 ;
94+ }
95+ if (argc > 2 ) {
96+ printf ("The no of files that are going to be uploaded are %d\n" ,argc - 1 );
97+ }
98+ printf ("\n" );
99+ /* Display names of file (Ignore the first argument as its transfer itself) */
100+ for (q = 1 ; q < holder ; q ++ ) {
101+ printf ("File no. %d is %s\n" , q , argv [q ]);
102+ }
103+ printf ("\n" );
104+ printf ("The above listed files would be uploaded now.\n\n" );
105+ #else
76106 /* Argument check */
77107 if (argc != 2 ) {
78108 printf ("ERROR: This binary expects atleast and only one command "
79109 "line argument\n" );
80110 /* bail out */
81111 return -1 ;
82112 }
113+ #endif
83114
84115#ifdef GET_FILE_SIZE
85116 if (getenv ("TRANSFER_DISABLE_FILESIZE" ) == NULL ) {
86117 static struct stat st ;
118+ #ifdef UPLOAD_MULTIPLE
119+ for (q = 1 ; q < holder ; q ++ ) {
120+ stat (argv [q ], & st );
121+ const float mb = st .st_size / 1048576 ;
122+ printf ("The size of the %d file going to be uploaded is near to %.2f "
123+ "megabytes\n" , q , mb );
124+ }
125+ }
126+ #else
87127 stat (argv [1 ], & st );
88128 // convert bytes to mb (devide by 1024*1024)
89129 const float mb = st .st_size / 1048576 ;
@@ -92,18 +132,33 @@ int main(int argc, char *argv[]) {
92132 mb );
93133 }
94134#endif
95-
135+ printf ("\n" );
136+ #endif
96137 static char cmdbuf [256 ];
97138 static int ret ;
98139
99140#ifdef PROGRESS_BAR
141+ #ifdef UPLOAD_MULTIPLE
142+ for (q = 1 ; q < holder ; q ++ ) {
143+ sprintf (cmdbuf , "curl --progress-bar -T %s %s | tee /dev/null" , argv [q ], "https://transfer.sh" );
144+ ret = uploader (cmdbuf );
145+ printf ("\n" );
146+ }
147+ #else
100148 sprintf (cmdbuf , "curl --progress-bar -T %s %s | tee /dev/null" , argv [1 ], "https://transfer.sh" );
149+ ret = uploader (cmdbuf );
150+ #endif
151+ #else
152+ #ifdef UPLOAD_MULTIPLE
153+ for (q = 1 ; q < holder ; q ++ ) {
154+ sprintf (cmdbuf , "curl -T %s %s" , argv [q ], "https://transfer.sh" );
155+ ret = uploader (cmdbuf );
156+ printf ("\n" );
157+ }
101158#else
102159 sprintf (cmdbuf , "curl -T %s %s" , argv [1 ], "https://transfer.sh" );
103160#endif
104-
105- ret = system (cmdbuf );
106- printf ("\n" );
161+ #endif
107162 return ret ;
108163 } else {
109164 printf ("Either curl binary is not installed or is corrupt somehow, "
0 commit comments