static int a_encode(const char *file1, const char *file2, const char *file3) { #ifdef IDENT_PGP_ENCODE char gbuf[128]; #endif if (mycp(file1, file2) == -1) return -1; #ifdef IDENT_PGP_ENCODE #ifdef NSYSUBBS sprintf(gbuf, "%s -e %s \"%s\"", BIN_PGP, file2, PUBLIC_KEY); system(gbuf); sprintf(gbuf, "%s.pgp", file2); if (isfile(gbuf)) { if (rename(gbuf, file3) == 0) { unlink(file2); return 0; } } #endif #endif if (rename(file2, file3) == -1) { unlink(file2); return -1; } return 0; }
int main(int argc, char *argv[]) { if (argc!=3) { printf("mycp src dest\n"); exit(1); } mycp(argv[1],argv[2]); printf("success\n"); return 0; }
int main(int argc, const char *argv[]) { int error; error= mycp(argv[1], argv[2]); if(error == -1) { perror("no crear new file"); exit(0); } return 0; }
int walk(const char *source, const struct stat *sb, int flag, struct FTW *ftw) { struct stat st; char final_dest[512] = ""; char *trim = strstr(source, "/"); strcat(final_dest, dest); stat(final_dest, &st); if(S_ISDIR(st.st_mode) && true_r && trim) strcat(final_dest, trim); if(S_ISDIR(sb->st_mode)) { mkdir(final_dest, sb->st_mode); } else { mycp(final_dest, source); } return 0; }
static int do_article(const char *fname, const char *path, const char *owner, const char *title) { char *p, mypath[PATHLEN]; struct fileheader fh; if (mycp(fname, path)) return -1; strcpy(mypath, path); p = strrchr(mypath, '/') + 1; bzero(&fh, sizeof(fh)); strcpy(fh.filename, p); strcpy(fh.owner, owner); strcpy(fh.title, title); strcpy(p, DIR_REC); if (append_record(mypath, &fh, sizeof(fh)) == 0) return 0; return -1; }
void main(int argc, char *argv[]) { char aha[] = "0abcdefghijklmnopqrstuvwxyz"; DIR *dirp; struct dirent *de; char path[PATHLEN], path2[PATHLEN]; struct useridx uidx[MAXUSERS]; USEREC user; char id[IDLEN + 2]; int uid; FILE *rptfile; int fdidx, fdidxn, fdpw, fdpwn; int cnt=0; int total_user=0, total_missed=0, total_mismatch=0; time_t strtime, curtime; int i; if (argc != 2) { printf("usage: %s all_user | userid\n", argv[0]); printf(" * all_user 重建所有使用者\n"); printf(" * userid 重建單一使用者(uncompleted)\n"); return; } init_bbsenv(); if (strcmp(argv[1], "all_user")) { /* specified user id */ strcpy(id, argv[1]); if (id[0] >= 'a') i = id[0] - 'a' + 1; else if ( id[0] >= 'A') i = id[0] - 'A' + 1; else if ( id[0] >= '0') i = 0; sprintf(path, "%s", USERIDX); sprintf(path2, "%s.old", USERIDX); if ((fdidx = open(path, O_RDONLY)) < 0) { printf("%s: conf/.USERIDX does not exist\n", argv[0]); printf("%s: Recreate a new index file...\n", argv[0]); } else { close(fdidx); mycp(path, path2); } sprintf(path, "%s", USERIDX); if ((fdidxn = open(path, O_RDWR | O_CREAT, 0600)) < 0) { printf("%s: cannot update new .USERIDX!\n", argv[0]); return; } sprintf(path, "home/%c/%s/passwds", aha[i], id); if ((fdpw = open(path, O_RDONLY)) < 0) { printf("Error:[%s] passwd file open fail.\n", id); } else { if (read(fdpw, &user, sizeof(user)) != sizeof(user)) { printf("Error:[%s] passwd file size mismatch.\n", id); } else { uid=user.uid; sprintf(path, "home/%c/%s/passwds.new", aha[i], id); if ((fdpwn = open(path, O_WRONLY | O_CREAT, 0600)) < 0) { printf("Error:[%s] new passwd file cannot be built!\n", id); } else { flock(fdidxn, LOCK_EX); /* first clean up old existing names */ for (cnt = 1; read(fdidxn, uidx, sizeof(struct useridx)) == sizeof(struct useridx); cnt++) { if (!strcmp(uidx[0].userid, id)) { memset(uidx, 0, sizeof(struct useridx)); if (lseek(fdidxn, ((off_t) ((cnt - 1) * sizeof(struct useridx))), SEEK_SET) != -1) { if (write(fdidxn, uidx, sizeof(struct useridx)) == sizeof(struct useridx)) { printf("user '%s' found in user index: %10d, cleaned.\n", id, cnt); } else { printf("%s: FATAL ERROR UPDATING USERIDX! -- at %d\n", argv[0], cnt); flock(fdidxn, LOCK_UN); close(fdidxn); return; } } else { printf("%s: FATAL ERROR SEEKING USERIDX! -- at %d\n", argv[0], cnt); flock(fdidxn, LOCK_UN); close(fdidxn); return; } } } if (lseek(fdidxn, 0, SEEK_SET) == -1) { printf("%s: FATAL ERROR REWINDING USERIDX!\n", argv[0]); flock(fdidxn, LOCK_UN); close(fdidxn); return; } /* find a empty slot in the user index file */ for (cnt = 1; read(fdidxn, uidx, sizeof(struct useridx)) == sizeof(struct useridx); cnt++) { if (uidx[0].userid[0] == '\0') { break; } } if (lseek(fdidxn, ((off_t) ((cnt - 1) * sizeof(struct useridx))), SEEK_SET) != -1) { memset(uidx, 0, sizeof(struct useridx)); strcpy(uidx[0].userid, id); if (write(fdidxn, uidx, sizeof(struct useridx)) == sizeof(struct useridx)) { flock(fdidxn, LOCK_UN); close(fdidxn); flock(fdpwn, LOCK_EX); user.uid=cnt; write(fdpwn, &user, sizeof(user)); flock(fdpwn, LOCK_UN); close(fdpwn); /* reserve old file */ sprintf(path, "home/%c/%s/passwds", aha[i], id); sprintf(path2, "home/%c/%s/passwds.old", aha[i], id); rename(path, path2); sprintf(path, "home/%c/%s/passwds.new", aha[i], id); sprintf(path2, "home/%c/%s/passwds", aha[i], id); rename(path, path2); printf("user '%s's uid: %10d --> %10d\n", user.userid, uid, user.uid); return; } else { printf("%s: FATAL ERROR UPDATING USERIDX!\n", argv[0]); } } else { printf("%s: FATAL ERROR SEARCHING USERIDX!\n", argv[0]); } flock(fdidxn, LOCK_UN); close(fdidxn); close(fdpw); sprintf(path, "home/%c/%s/passwds.new", aha[i], id); unlink(path); } } } return; } /* process of all users begin here */ sprintf(path, "%s", USERIDX); if ((fdidx = open(path, O_RDONLY)) < 0) { printf("%s: conf/.USERIDX does not exist\n", argv[0]); return; } close(fdidx); sprintf(path, "%s.new", USERIDX); if ((fdidxn = open(path, O_RDWR | O_CREAT, 0600)) < 0) { printf("%s: cannot create new .USERIDX!\n", argv[0]); return; } sprintf(path, "home/backup"); if (mkdir(path, 0755) != 0) { if (errno!=EEXIST) { printf("%s: cannot create backup directory %s/home/backup", argv[0], HOMEBBS); return; } } if ((rptfile=fopen("rebuild_useridx_report", "w"))==NULL) { printf("%s: cannot create report file!\n", argv[0]); return; } strtime=time(NULL); fprintf(rptfile, "Date: %s", ctime(&strtime)); fprintf(rptfile, "----------------------------------\n"); for (i = 0; i < 27; i++) { sprintf(path, "home/%c", aha[i]); if (!(dirp = opendir(path))) continue; readdir(dirp); /* skip . & .. */ readdir(dirp); while ((de = readdir(dirp)) != NULL) { if (de->d_name[0] == '\0') continue; memset(id, '\0', sizeof(id)); strncpy(id, de->d_name, sizeof(id) - 1); sprintf(path, "home/%c/%s/passwds", aha[i], id); if ((fdpw = open(path, O_RDONLY)) < 0) { fprintf(rptfile, "Error:[%s] passwd file missed.\n", id); total_missed++; } else { if (read(fdpw, &user, sizeof(user)) != sizeof(user)) { fprintf(rptfile, "Error:[%s] passwd file size mismatch.\n", id); total_mismatch++; } else { sprintf(path, "home/%c/%s/passwds.new", aha[i], id); if ((fdpwn = open(path, O_RDWR | O_CREAT, 0600)) < 0) { fprintf(rptfile, "Error:[%s] passwd file cannot build!\n", id); } else { close(fdpw); flock(fdpwn, LOCK_EX); cnt++; user.uid=cnt; /* for performance, primary index using write-back method... */ //write(fdidx, &uidx, sizeof(uidx)); write(fdpwn, &user, sizeof(user)); total_user++; flock(fdpwn, LOCK_UN); close(fdpwn); sprintf(path, "home/%c/%s/passwds", aha[i], id); sprintf(path2, "home/backup/%s", id); rename(path, path2); sprintf(path, "home/%c/%s/passwds.new", aha[i], id); sprintf(path2, "home/%c/%s/passwds", aha[i], id); rename(path, path2); strcpy(uidx[cnt-1].userid, user.userid); fprintf(rptfile, "%10d %s\n", user.uid, user.userid); } } close(fdpw); } } closedir(dirp); } flock(fdidxn, LOCK_EX); write(fdidxn, uidx, sizeof(struct useridx)*cnt); flock(fdidxn, LOCK_UN); close(fdidxn); sprintf(path, "%s", USERIDX); sprintf(path2, "%s.old", USERIDX); rename(path, path2); sprintf(path, "%s.new", USERIDX); sprintf(path2, "%s", USERIDX); rename(path, path2); curtime=time(NULL); fprintf(rptfile, "\n########## ENTIRE USERS ##########\n"); fprintf(rptfile, "# total users: %d\n", total_user); fprintf(rptfile, "# passwd missed: %d\n", total_missed); fprintf(rptfile, "# passwd size mismatch: %d\n", total_mismatch); fprintf(rptfile, "##################################\n"); fprintf(rptfile, "# finished time: %s\n", ctime(&curtime)); fprintf(rptfile, "# elapsed time: %d\n", curtime-strtime); fclose(rptfile); return; }
main(int argc, char *argv[ ]) { //*Lab 5 CODE char *tok; char cmdArgs[2][MAX] = {'\0'}; char cwd[128]; int cmdCount = 0; //LAB 5 CODE* char temp[MAX]; int n; char line[MAX], ans[MAX]; //*Lab 5 CODE getcwd(cwd, 128); // get CWD pathname // Lab 5 CODE* printf("cwd: %s\n", cwd); if (argc < 3){ printf("Usage : client ServerName ServerPort\n"); exit(1); } client_init(argv); // sock <---> server printf("******** processing loop *********\n"); while (1){ //printf("input two numbers to add : "); //bzero(line, MAX); // zero out line[ ] // *LAB 5 CODE cmdCount = 0; strcpy(cmdArgs[0],""); strcpy(cmdArgs[1],""); printf("Input a command: "); // LAB 5 CODE* fgets(line, MAX, stdin); // get a line (end with \n) from stdin //printf("line: %s\n", line); line[strlen(line)-1] = 0; // kill \n at end //printf("line[0]: %c\n", line[0]); //if(line[0]==0) // exit if NULL line //{exit(0);} // *Lab 5 CODE strcpy(temp, line); //printf("temp: %s\n", temp); tok = strtok(line, " "); cmdCount++; //printf("temp: %s\n", temp); //printf("cmdArgs[0] = %s\n", cmdArgs[0]); //printf("cmdCount: %d\n", cmdCount); while(tok != NULL) { strcpy(cmdArgs[cmdCount-1], tok); tok = strtok(NULL, " "); cmdCount++; //printf("cmdCount: %d\n", cmdCount); } //printf("cmdCount: %d\n", cmdCount); //printf("line: %s\n", line); //printf("cmdArgs[0] = %s\n", cmdArgs[0]); if(strcmp(cmdArgs[0], "lcat") == 0) { if(strcmp(cmdArgs[1],"") != 0) {mycat(cmdArgs[1]);} else {printf("ERROR: pathname not given");} } else if (strcmp(cmdArgs[0], "lpwd") == 0) { mypwd(cwd); } else if (strcmp(cmdArgs[0], "lls") == 0) { printf("args: %s\n", cmdArgs[1]); if(strcmp(cmdArgs[1],"") != 0) {myls(cmdArgs[1]);} else { printf("cwd: %s\n", cwd); myls(cwd); } } else if (strcmp(cmdArgs[0], "lcd") == 0) { if(strcmp(cmdArgs[1],"") != 0) {mycd(cmdArgs[1]);} else {mycd(cwd);} } else if (strcmp(cmdArgs[0], "lmkdir") == 0) { if(strcmp(cmdArgs[1],"") != 0) {mymkdir(cmdArgs[1]);} else {printf("ERROR: pathname not given");} } else if (strcmp(cmdArgs[0], "lrmdir") == 0) { if(strcmp(cmdArgs[1],"") != 0) {myrmdir(cmdArgs[1]);} else {printf("ERROR: pathname not given");} } else if (strcmp(cmdArgs[0], "lrm") == 0) { if(strcmp(cmdArgs[1],"") != 0) {myrm(cmdArgs[1]);} else {printf("ERROR: pathname not given");} } else if (strcmp(cmdArgs[0], "get") == 0) { if(strcmp(cmdArgs[1],"") != 0) {mycp(cmdArgs[1], cwd);} else {printf("ERROR: pathname not given");} } else if (strcmp(cmdArgs[0], "quit") == 0) { printf("Goodbye!\n"); return 0; } else // Not a local command, work with the sever { // Send command to server n = write(server_sock, temp, MAX); printf("client: wrote n=%d bytes; line=(%s)\n", n, temp); // Send command pathname //n = write(server_sock, cmdArgs[0], MAX); //printf("client: wrote n=%d bytes; line=(%s)\n", n, line); // Now read the Reply and Results in from the Server... //REPLY //n = read(server_sock, ans, MAX); //printf("client: read n=%d bytes; echo=(%s)\n",n, ans); //RESULTS //n = read(server_sock, ans, MAX); //printf("client: read n=%d bytes; echo=(%s)\n",n, ans); readData(ans); } // Lab 5 CODE* // // Send ENTIRE line to server //n = write(server_sock, line, MAX); //printf("client: wrote n=%d bytes; line=(%s)\n", n, line); // Read a line from sock and show it //n = read(server_sock, ans, MAX); //printf("client: read n=%d bytes; echo=(%s)\n",n, ans); } }
int callInternal(command* C, char* homeDir) { if (C->argc == 0) return 0; else if (strcmp(C->argv[0],"exit") == 0) return 1; else if (strcmp(C->argv[0],"mycat") == 0) { if (C->argc == 2) mycat(C->argv[1]); else if (C->argc == 1) printf("Argument missing\n"); else if (C->argc > 2) printf("Incorrect usage of mycat\n"); } else if (strcmp(C->argv[0],"mycp") == 0) { if (C->argc == 3) mycp(C->argv[1],C->argv[2]); else if (C->argc == 2) printf("Destination needed\n"); else if (C->argc == 1) printf("Source & destination needed\n"); else printf("Incorrect usage of mycp\n"); } else if (strcmp(C->argv[0],"mypwd") == 0) { if (C->argc > 1) printf("Incorrect usage of mypwd\n"); else { char* pwd = mypwd(); printf("%s\n",pwd); free(pwd); } } else if (strcmp(C->argv[0],"mymkdir") == 0) { if (C->argc < 2) printf("missing argument\n"); else if (C->argc > 2) printf("Incorrect usage of mymkdir\n"); else mymkdir(C->argv[1]); } else if (strcmp(C->argv[0],"myrmdir") == 0) { if (C->argc < 2) printf("missing argument\n"); else if (C->argc > 2) printf("Incorrect usage of mymkdir\n"); else myrmdir(C->argv[1]); } else if (strcmp(C->argv[0],"mycd") == 0) { if (C->argc >2) printf("Incorrect usage of mycd\n"); else if (C->argc == 2) mycd(C->argv[1]); else mycd(homeDir); } else if (strcmp(C->argv[0],"myls") == 0) { if (C->argc == 1) myls(NULL,0); else if (C->argc == 2) if (strcmp(C->argv[1],"-l") == 0) myls(NULL,1); else myls(C->argv[1],0); else if (C->argc == 3) if (strcmp(C->argv[1],"-l") == 0) myls(C->argv[2],1); else printf("Incorrect usage of myls\n"); else printf("Incorrect usage of myls\n"); } else if (strcmp(C->argv[0],"myrm") == 0) { if (C->argc == 2) myrm(C->argv[1]); else if (C->argc == 1) printf("missing argument\n"); else printf("Incorrect usage of myrm\n"); } else printf("command not found: %s\n",C->argv[0]); return 0; }
int main(int argc, char** argv) { int count=0, i=0, cmp, j, valid=0; char key[MAX]; //run the shell till user inputs 'quit' or Ctrl-C while(strcmp(cmdline, "quit") != 0) { count = 0; //our shell's prompt printf("afreen@myShell $ "); //get command line input gets(cmdline); //tokenize the CL input delimited by " " using strtok() into args args[count++] = strtok(cmdline, " "); //tokenize the entire string till the next token encountered //does not have a NULL pointer while((args[count++] = strtok(NULL, " "))); count--; //no of arguments (argc) //if user wants to clear screen if(strcmp(args[0], "clear") == 0) { myclear(); } //checking for the input command strcpy(key, args[0]); for(i=0; i<18; i++) //look through our check array for command { if(strcmp(check[i], key) == 0) { valid = -1; switch(i) { case 0: mycat(count, args); break; case 1: mycd(count, args); break; case 2: mycp(count, args); break; case 3: mydate(count, args); break; case 4: myhead(count, args); break; case 5: myls(count, args); break; case 6: myll(count, args); break; case 7: myln(count, args); break; case 8: myld(count, args); break; case 9: mymkdir(count, args); break; case 10: mymv(count, args); break; case 11: mypwd(count, args); break; case 12: myrm(count, args); break; case 13: myrmdir(count, args); break; case 14: mytail(count, args); break; case 15: mytime(count, args); break; case 16: mytouch(count, args); break; case 17: myuname(count, args); break; default: printf("%s: Command not found\n", key); break; } break; } } } return 0; }
int vedit(const char *filename, const char *saveheader, char *bname) { int ch, foo; int lastcharindent = -1; BOOL firstkey = TRUE; char bakfile[PATHLEN]; int old_rows = t_lines, old_columns = t_columns; sethomefile(bakfile, curuser.userid, UFNAME_EDIT); if ((saveheader || uinfo.mode == EDITPLAN || uinfo.mode == EDITBMWEL) && isfile(bakfile) /* lthuang */ #ifdef GUEST && strcmp(curuser.userid, GUEST) #endif ) { clear(); outs(_msg_edit_8); if (getkey() != '2') mycp(bakfile, filename); } if (!isfile(filename)) unlink(bakfile); if (saveheader) do_article_sig(filename); read_file(filename); top_of_win = firstline; currline = firstline; curr_window_line = 0; currpnt = 0; ansi_mode = FALSE; clear(); display_buffer(); move(curr_window_line, currpnt); while ((ch = getkey()) != EOF) { if (firstkey) { firstkey = FALSE; show_help_msg(); } if (talkrequest) /* lthuang */ { backup_file(bakfile); talkreply(); pressreturn(); ch = CTRL('G'); /* redraw screen */ } else if (msqrequest) /* lthuang */ { msqrequest = FALSE; msq_reply(); #if 0 ch = CTRL('G'); #endif } if (old_rows != t_lines || old_columns != t_columns) { static const char *msg_resized = "[1;34;47m螢幕大小已改變, 按(Ctrl-G)回到頁首![m"; old_rows = t_lines; old_columns = t_columns; top_of_win = firstline; currline = top_of_win; curr_window_line = 0; currpnt = 0; shift = 0; redraw_everything = TRUE; move(t_lines / 2, (t_columns - strlen(msg_resized)) / 2); outs(msg_resized); while (getkey() != CTRL('G')); } else if (ch < 0x100 && isprint2(ch)) { insert_char(ch); lastcharindent = -1; } else switch (ch) { case KEY_UP: if (lastcharindent == -1) lastcharindent = currpnt; if (!currline->prev) { bell(); break; } curr_window_line--; currline = currline->prev; currpnt = (currline->len > lastcharindent) ? lastcharindent : currline->len; break; case KEY_DOWN: if (lastcharindent == -1) lastcharindent = currpnt; if (!currline->next) { bell(); break; } curr_window_line++; currline = currline->next; currpnt = (currline->len > lastcharindent) ? lastcharindent : currline->len; break; default: lastcharindent = -1; switch (ch) { case CTRL('T'): top_of_win = back_line(lastline, b_lines - 2); currline = lastline; curr_window_line = getlineno(); currpnt = 0; redraw_everything = TRUE; break; case CTRL('S'): top_of_win = firstline; currline = top_of_win; curr_window_line = 0; currpnt = 0; redraw_everything = TRUE; break; case '\t': do { insert_char(' '); } while (currpnt & 0x7); break; case CTRL('U'): case CTRL('V'): insert_char(0x1b); break; case CTRL('C'): insert_char(0x1b); insert_char('['); insert_char('m'); break; case KEY_RIGHT: case CTRL('F'): if (currline->len == currpnt) { if (!currline->next) bell(); else { currpnt = 0; curr_window_line++; currline = currline->next; } } else currpnt++; break; case KEY_LEFT: case CTRL('B'): if (currpnt == 0) { if (!currline->prev) bell(); else { currline = currline->prev; currpnt = currline->len; curr_window_line--; } } else currpnt--; break; case CTRL('G'): clear(); redraw_everything = TRUE; break; case CTRL('Z'): vedit_help(); break; case KEY_PGUP: case CTRL('P'): top_of_win = back_line(top_of_win, b_lines - 2); currline = top_of_win; currpnt = 0; curr_window_line = 0; redraw_everything = TRUE; break; case KEY_PGDN: case CTRL('N'): top_of_win = forward_line(top_of_win, b_lines - 2); currline = top_of_win; currpnt = 0; curr_window_line = 0; redraw_everything = TRUE; break; case KEY_HOME: case CTRL('A'): currpnt = 0; break; case KEY_END: case CTRL('E'): currpnt = currline->len; break; case CTRL('R'): #if 0 backup_file(bakfile); #endif msq_reply(); #if 0 redraw_everything = TRUE; /* lthuang */ #endif break; case CTRL('Q'): ansi_mode = TRUE; display_buffer(); pressreturn(); ansi_mode = FALSE; display_buffer(); break; case CTRL('X'): case CTRL('W'): backup_file(bakfile); clear(); foo = write_file(filename, saveheader, bname); if (foo == BACKUP_EDITING) return foo; else if (foo != KEEP_EDITING) { unlink(bakfile); return foo; } redraw_everything = TRUE; /* lthuang */ break; case '\r': case '\n': split(currline, currpnt); /* lthuang: reduce the times of backup */ if (total_num_of_line % 7 == 0) backup_file(bakfile); break; case '\177': case CTRL('H'): if (currpnt == 0) { if (!currline->prev) { bell(); break; } curr_window_line--; currline = currline->prev; currpnt = currline->len; if (*killsp(currline->next->data) == '\0') { delete_line(currline->next); redraw_everything = TRUE; } else { join_currline(); } if (curr_window_line == -1) { curr_window_line = 0; top_of_win = currline; rscroll(); } break; } currpnt--; delete_char(); break; case CTRL('D'): if (currline->len == currpnt) join_currline(); else delete_char(); break; case CTRL('Y'): currpnt = 0; currline->len = 0; delete_currline(); break; case CTRL('K'): if (currline->len == 0) delete_currline(); else if (currline->len == currpnt) join_currline(); else { currline->len = currpnt; currline->data[currpnt] = '\0'; } break; default: break; } break; } if (curr_window_line == -1) { curr_window_line = 0; if (!top_of_win->prev) { indigestion(6); bell(); } else { top_of_win = top_of_win->prev; rscroll(); } } if (curr_window_line == t_lines - 1) { curr_window_line = t_lines - 2; if (!top_of_win->next) { indigestion(7); bell(); } else { top_of_win = top_of_win->next; scroll(); } } /* lthuang: 99/07 */ if (currpnt - shift >= t_columns - 1) { shift = (currpnt / (t_columns - 1)) * (t_columns - 1) - 1; redraw_everything = TRUE; } else if (currpnt - shift < 0) { shift = 0; redraw_everything = TRUE; } if (redraw_everything) { display_buffer(); redraw_everything = FALSE; } else { move(curr_window_line, 0); clrtoeol(); /* lthuang */ vedit_outs(currline->data); } move(curr_window_line, currpnt - shift); /* lthuang: 99/07 */ } if (uinfo.mode == POSTING || uinfo.mode == SMAIL) unlink(filename); return ABORT_EDITING; }
int append_article(char *fname, char *path, char *author, char *title, char ident, char *stamp, int artmode, int flag, char *fromhost) #endif { char dotdir[PATHLEN], fn_stamp[PATHLEN]; char stampbuf[64]; /* M.0987654321.[A-Z]+ */ FILEHEADER fhbuf, *fhr = &fhbuf; struct stat st; char buffer[256]; /* check if directory exists for 'path' */ if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) return -1; /* create unique filename from time & store in stampbuf,'path' unmodified */ get_only_name(path, stampbuf); sprintf(fn_stamp, "%s/%s", path, stampbuf); /* actually copy the file into where the post finally resides */ if (mycp(fname, fn_stamp) == -1) { unlink(fn_stamp); /* debug */ return -1; } /* append 'Origin:' line at the end of post if 'fromhost' was specified */ if (fromhost) { #ifdef USE_IDENT sprintf(buffer, "--\n* Origin: %s * From: %s [%s通過認證]\n", BBSTITLE, fromhost, (ident == 7) ? "已" : "未"); #else sprintf(buffer, "--\n* Origin: %s * From: %s\n", BBSTITLE, fromhost); #endif append_record(fn_stamp, buffer, strlen(buffer)); } chmod(fn_stamp, 0600); /* lthuang */ /* now adding index to .DIR file */ memset(fhr, 0, FH_SIZE); xstrncpy(fhr->filename, stampbuf, sizeof(fhr->filename)); xstrncpy(fhr->owner, author, sizeof(fhr->owner)); xstrncpy(fhr->title, title, sizeof(fhr->title)); fhr->ident = ident; /* add by asuka */ fhr->accessed |= flag; sprintf(dotdir, "%s/%s", path, DIR_REC); /* get next valid postno from .DIR file if in the article mode */ /* 精華區 / 信箱 不需要用到 postno */ if (artmode && get_only_postno(dotdir, 0, fhr)) return -1; if (stamp) strcpy(stamp, stampbuf); #ifdef USE_THREADING /* syhu */ update_threadinfo( fhr, path, thrheadpos, thrpostidx ); /* syhu */ #endif /* do the acutal update in .DIR file by writing to it */ /* 'dotdir' is opened twice. First is in get_only_post() */ if (append_record(dotdir, fhr, FH_SIZE) == -1) { unlink(fn_stamp); /* lthuang */ return -1; } if (artmode) { return fhr->postno; } return 0; }