STR convarg4(STR a, STR s) { int i; s = newstr(s); if(is_empty(a)){ clrstr(a); return(s); } for(i=0;a[i];i++){ if(a[i] == '/'){ s = basestr(s); continue; } if(a[i] == '.'){ s = dotstr(s); continue; } clrstr(s); s = newstr("{"); s = catstr(s, a); s = catstr(s, "}"); clrstr(a); return(s); } clrstr(a); return(s); }
STR convarg(STR a, MTNJOB *j) { int i; STR p; STR q; if(!a){ return(NULL); } if(!j){ return(a); } i = 0; p = newstr(a); while(*(p + i)){ if(*(p + i) == '{'){ *(p + i) = 0; i++; q = newstr(p + i); q = convarg2(q, j); a = modstr(a, p); a = catstr(a, q); p = modstr(p, a); q = clrstr(q); continue; } i++; } clrstr(p); return(a); }
STR convarg2(STR a, MTNJOB *j) { int i; STR p; STR q; STR r; i = 0; p = newstr(a); while(*(p + i)){ if(*(p + i) == '}'){ *(p + i) = 0; i++; q = newstr(p); r = newstr(p + i); q = convarg3(q, j); a = modstr(a, q); a = catstr(a, r); clrstr(q); clrstr(r); break; } i++; } clrstr(p); return(a); }
int mtnfile_console_cd(int argc, ARG args) { STR path; int r = 1; MTNSTAT *rst; MTNSTAT *kst; if(argc == 1){ ctx->remote_path = modstr(ctx->remote_path, "/"); return(0); } path = mtnfile_console_path(args[1]); rst = mtn_stat(mtn, path); for(kst=rst;kst;kst=kst->next){ if(S_ISDIR(kst->stat.st_mode)){ ctx->remote_path = modstr(ctx->remote_path, path); r = 0; break; } } if(r){ mtnlogger(mtn, 0, "error: %s: not directory.\n", args[1]); } path = clrstr(path); rst = clrstat(rst); return(r); }
int mtnfile_console_ls(int argc, ARG args) { STR path = mtnfile_console_path(args[1]); mtnfile_list(path); path = clrstr(path); return(0); }
int mtnfile_console_cat(int argc, ARG args) { STR path = mtnfile_console_path(args[1]); mtnfile_get(path, "-"); path = clrstr(path); return(0); }
STR convarg3(STR a, MTNJOB *j) { int m; int n; STR s; char *b; if(!strcmp(a, "H")){ if(j->svr){ a = modstr(a, j->svr->host); }else{ a = modstr(a, "local"); } return(a); } b = malloc(ctx->arg_max); a = strnum(a, b); if(!strlen(b)){ s = joinarg(j->argl, ctx->delim); }else{ n = atoi(b); m = cntarg(j->argl); s = newstr((n < m) ? j->argl[n] : ""); } free(b); b = NULL; a = convarg4(a, s); clrstr(s); return(a); }
STR strnum(STR a, char *n) { int i; STR s; for(i=0;a[i];i++){ if(a[i]>='0' && a[i]<='9'){ n[i] = a[i]; }else{ break; } } n[i] = 0; s = newstr(a + i); clrstr(a); return(s); }
void BuildDataBase (art *articles, int num_of_articles, char *newsgroup) { MYSQL mysql, *con; MYSQL_RES *res; MYSQL_ROW row; char query[MAX_QUERY]; int x; char *table_name; table_name = (char *) malloc (1024); strcpy (table_name, newsgroup); Substitute (&table_name, ".", "", 1, 1); Substitute (&table_name, "/", "", 1, 1); /* printf ("(((%s))))", table_name); */ /* ---- Connect to database server. ---- */ if( !(con = mysql_connect(&mysql, HOSTNAME, USERNAME,PASSWORD)) ) { error("Could not connect."); } /* ---- Select DataBase. ---- */ if (mysql_select_db(con, DATABASE)){ error("Could not select DataBase."); } /* ---- Drop the students table ----<<<<<<<<<<<<<<<<<< DELETE */ strcpy (query, "drop table "); strcat (query, table_name); if(mysql_query(con,query)) { } /* ----- Form Query for creating table --- */ clrstr (query); strcat (query, "create table "); strcat (query, table_name); strcat (query, " ("); strcat (query, "filename char(10),"); strcat (query, "threadposn int,"); strcat (query, "messageid char(100) not null,"); strcat (query, "reference char(100),"); strcat (query, "date char(40),"); strcat (query, "subject char(100),"); strcat (query, "msg_from char(100),"); strcat (query, "nlines int,"); strcat (query, "primary key(messageid) )"); /* ----- Create table. ----- */ if(mysql_query(con, query)){ error("could not create table"); } /* ----- insert records into the table --- */ for (x = 0; x < num_of_articles; x++) { clrstr(query); if (articles[x].reference_field == NULL) { strcat (query, BuildInsertQuerySpecial (articles, x, table_name)); } else { strcat (query, BuildInsertQuery (articles, x, table_name)); } if (mysql_query (con, query)) { printf ("Could not insert record!!!! "); printf ("Failure to insert: %s\n", query); } } /* ---- Let us look at what we inserted ---- */ clrstr(query); strcpy(query, "select * from "); strcat(query, table_name); strcat(query, " where threadposn = 1 order by messageid"); if(mysql_query(con, query)) { error("! select 1"); } /* ---- Store results from query into res structure. ---- */ if (!(res = mysql_store_result(con))){ error("! store 1"); } while ((row = mysql_fetch_row(res))) { printf("%s %s %s %s\n", row[2], row[4], row[5], row[6]); } /* ---- Drop the students table ---- */ strcpy (query, "drop table "); strcat (query, table_name); /* ================== dropping table ===================== if(mysql_query(con,query)) { error("! drop 1"); } =================== dropping table ===================== */ /* ---- Finally close connection to server ---- */ mysql_close(con); }