1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/* --------------------------------------------------------------------
Project: Communication package Linux-HPx00LX Filer
Module: lxdel.c
Author: A. Garzotto
Started: 30. Nov. 95
Subject: Delete a file on the LX
-------------------------------------------------------------------- */
/* --------------------------------------------------------------------
includes
-------------------------------------------------------------------- */
#include <stdio.h>
#include <stdlib.h>
/* --------------------------------------------------------------------
local includes
-------------------------------------------------------------------- */
#include "pal.h"
#include "palpriv.h"
#include "config.h"
/* --------------------------------------------------------------------
display help
-------------------------------------------------------------------- */
static void help(void)
{
fprintf(stderr, "USAGE: lxdel [options] <file name>\n");
fprintf(stderr, " options: -<n> sets comm port <n>\n");
fprintf(stderr, " -b <baud> sets baud rate to <baud>\n");
exit(1);
}
/* --------------------------------------------------------------------
make DOS directory string
-------------------------------------------------------------------- */
static void makedir(char *dir)
{
char *p = dir;
while (*p)
{
if (*p == '/') *p = '\\';
p++;
}
}
/* --------------------------------------------------------------------
M A I N
-------------------------------------------------------------------- */
int main (int argc, char **argv)
{
int stat;
int port = 1;
int speed = DEF_BAUD;
int ret = 0;
FILERCOM *pFiler;
char file[256] = "";
int i = 1, num = 0;
fprintf(stderr, "LXDEL %s by A. Garzotto\n\n", VERSION);
while (i < argc)
{
if (argv[i][0] == '-')
{
switch (argv[i][1])
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8': port = argv[i][1] - '0'; break;
case 'B':
case 'b': speed = atoi(argv[++i]); break;
default: help(); break;
}
}
else
strcpy(file, argv[i]);
i++;
}
if (!*file) help();
makedir(file);
if(!(pFiler = FilerConnect(port, speed, &FlCb))) {
fprintf(stderr, "\nUnable to connect to palmtop!\n");
exit(3);
}
stat = FilerAskDir(pFiler, file);
if(stat== NO_RESPONSE) fprintf(stderr, "\nServer Not responding.\n");
while (1)
{
if (FilerGetDir(pFiler) == CANNOT_GET_ENTRY) break;
if (!(pFiler->Attribute & 0x10)) num++;
}
if (!num)
{
fprintf(stderr, "File not found: '%s'.\n", file);
ret = 1;
}
else if (num > 1)
{
fprintf(stderr, "Can only delete one file at once.\n");
ret = 1;
}
else
{
stat = FilerDelFile(pFiler, file);
if(stat==CANNOT_DELETE)fprintf(stderr, "\nCould not delete file!\n");
ret = 1;
}
FilerDisconnect(pFiler);
exit(ret);
}
|